Re: [PATCH 2/3] x86/mm: Fix LAM inconsistency during context switch

From: Yosry Ahmed
Date: Tue Mar 12 2024 - 11:35:07 EST


On Tue, Mar 12, 2024 at 02:35:46PM +0200, Kirill A. Shutemov wrote:
> On Tue, Mar 12, 2024 at 03:59:50AM +0000, Yosry Ahmed wrote:
> > diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
> > index 76e91fc68c5f3..748d2b3bdb985 100644
> > --- a/arch/x86/kernel/process_64.c
> > +++ b/arch/x86/kernel/process_64.c
> > @@ -753,10 +753,12 @@ static long prctl_map_vdso(const struct vdso_image *image, unsigned long addr)
> > static void enable_lam_func(void *__mm)
> > {
> > struct mm_struct *mm = __mm;
> > + unsigned long lam = mm_lam_cr3_mask(mm);
> > + u64 untag_mask = mm_untag_mask(mm);
> >
>
> Maybe push these mm dereferences inside the if block below?
> I am not sure if compiler can re-order operations past this_cpu_read().

I am not sure either, so I will push them inside. Better safe than
sorry. Will send a v2 shortly, thanks for the reviews!

>
> > if (this_cpu_read(cpu_tlbstate.loaded_mm) == mm) {
> > - write_cr3(__read_cr3() | mm->context.lam_cr3_mask);
> > - set_tlbstate_lam_mode(mm);
> > + write_cr3(__read_cr3() | lam);
> > + cpu_tlbstate_update_lam(lam, untag_mask);
> > }
> > }
> >
>
> --
> Kiryl Shutsemau / Kirill A. Shutemov