[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b778fcdd-5c20-e897-9d17-1a884172a826@intel.com>
Date: Mon, 7 Nov 2022 10:02:44 -0800
From: Dave Hansen <dave.hansen@...el.com>
To: "Kirill A. Shutemov" <kirill@...temov.name>,
Andy Lutomirski <luto@...nel.org>
Cc: "Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Peter Zijlstra <peterz@...radead.org>, x86@...nel.org,
Kostya Serebryany <kcc@...gle.com>,
Andrey Ryabinin <ryabinin.a.a@...il.com>,
Andrey Konovalov <andreyknvl@...il.com>,
Alexander Potapenko <glider@...gle.com>,
Taras Madan <tarasmadan@...gle.com>,
Dmitry Vyukov <dvyukov@...gle.com>,
"H . J . Lu" <hjl.tools@...il.com>,
Andi Kleen <ak@...ux.intel.com>,
Rick Edgecombe <rick.p.edgecombe@...el.com>,
Bharata B Rao <bharata@....com>,
Jacob Pan <jacob.jun.pan@...ux.intel.com>,
Ashok Raj <ashok.raj@...el.com>, linux-mm@...ck.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCHv11 04/16] x86/mm: Handle LAM on context switch
On 11/7/22 09:14, Kirill A. Shutemov wrote:
> --- a/arch/x86/mm/tlb.c
> +++ b/arch/x86/mm/tlb.c
> @@ -561,7 +561,15 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
> if (real_prev == next) {
> VM_WARN_ON(this_cpu_read(cpu_tlbstate.ctxs[prev_asid].ctx_id) !=
> next->context.ctx_id);
> - VM_WARN_ON(prev_lam != new_lam);
> +
> + /*
> + * 'prev_lam' does not necessary match 'new_lam' here. In case
> + * of race with LAM enabling, the updated 'lam_cr3_mask' can be
> + * been before LAM-enabling IPI kicks in.
> + *
> + * The race is harmless: it is okay to update CR3 with new LAM
> + * mode. The IPI will rewrite CR3 shortly.
> + */
So, let's do something like this in switch_mm_irqs_off():
/* Not actually switching mm's */
VM_WARN_ON(this_cpu_read(cpu_tlbstate....
/*
* If this races with another thread that enables
* lam, 'new_lam' might not match 'prev_lam'.
*/
Then, in enable_lam_func(), something like this:
/*
* Update CR3 to get LAM active on the CPU
*
* This might not actually need to update CR3 if a context
* switch happened between updating 'lam_cr3_mask' and
* running this IPI handler. Update it unconditionally for
* simplicity.
*/
cr3 = __read_cr3();
cr3 &= ~(X86_CR3_LAM_U48 | X86_CR3_LAM_U57);
cr3 |= lam_mask;
write_cr3(cr3);
set_tlbstate_cr3_lam_mask(lam_mask);
I'd much rather get folks thinking about IPI races in the IPI handler
rather than thinking about the IPI handler in the context switch path.
It's kinda silly to be describing the occasional superfluous
enable_lam_func() activity from switch_mm_irqs_off().
Powered by blists - more mailing lists