On Tue, Mar 12, 2024 at 03:56:40PM +0000, Yosry Ahmed wrote: > 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@xxxxxxxxxx> Reviewed-by: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx> -- Kiryl Shutsemau / Kirill A. Shutemov