]> www.infradead.org Git - users/jedix/linux-maple.git/commit
x86/mm: Fix LAM inconsistency during context switch
authorYosry Ahmed <yosryahmed@google.com>
Tue, 2 Jul 2024 13:21:38 +0000 (13:21 +0000)
committerDave Hansen <dave.hansen@linux.intel.com>
Tue, 2 Jul 2024 18:32:16 +0000 (11:32 -0700)
commitec225f8c255fd0f256c282cc73d211550cb08b34
treeb41b8f80702d136d22861ae379cb7d6749ba4d31
parent3b299b99556c1753923f8d9bbd9304bcd139282f
x86/mm: Fix LAM inconsistency during context switch

LAM can only be enabled when a process is single-threaded.  But _kernel_
threads can temporarily use a single-threaded process's mm.  That means
that a context-switching kernel thread can race and observe the mm's LAM
metadata (mm->context.lam_cr3_mask) change.

The context switch code does two logical things with that metadata:
populate CR3 and populate 'cpu_tlbstate.lam'.  If it hits this race,
'cpu_tlbstate.lam' and CR3 can end up out of sync.

This de-synchronization is currently harmless.  But it is confusing and
might lead to warnings or real bugs.

Update set_tlbstate_lam_mode() to take in the LAM mask and untag mask
instead of an mm_struct pointer, and while we are at it, rename it to
cpu_tlbstate_update_lam(). This should also make it clearer that we are
updating cpu_tlbstate. In switch_mm_irqs_off(), read the LAM mask once
and use it for both the cpu_tlbstate update and the CR3 update.

Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Link: https://lore.kernel.org/all/20240702132139.3332013-3-yosryahmed%40google.com
arch/x86/include/asm/mmu_context.h
arch/x86/include/asm/tlbflush.h
arch/x86/kernel/process_64.c
arch/x86/mm/tlb.c