Re: [PATCH v6 RESEND 1/3] x86/mm/tlb: Make enter_lazy_tlb() always inline on x86
From: Xie Yuanbin
Date: Tue Feb 10 2026 - 10:32:40 EST
On Mon, 9 Feb 2026 11:24:06 -0800, Dave Hansen wrote:
> On 2/9/26 08:23, Xie Yuanbin wrote:
>> +/*
>> + * Please ignore the name of this function. It should be called
>> + * switch_to_kernel_thread().
>> + *
>> + * enter_lazy_tlb() is a hint from the scheduler that we are entering a
>> + * kernel thread or other context without an mm. Acceptable implementations
>> + * include doing nothing whatsoever, switching to init_mm, or various clever
>> + * lazy tricks to try to minimize TLB flushes.
>> + *
>> + * The scheduler reserves the right to call enter_lazy_tlb() several times
>> + * in a row. It will notify us that we're going back to a real mm by
>> + * calling switch_mm_irqs_off().
>> + */
>> +#ifndef MODULE
>
> What's with the #ifndef? Is this to avoid use spreading to modules and
> then making us export some other gunk? That seems like a generally good
> thing, but it's also totally random, different from the existing
> 'extern' declaration of enter_lazy_tlb(), and unique in the header.
This was just to fix a compilation error:
'cpu_tlbstate' is defined in 'include/asm/tlbflush.h' inside of
'#ifndef MODULE'. So if the '#ifndef MODULE' is not added here,
the compilation error will be triggered:
```log
arch/x86/include/asm/mmu_context.h: In function 'enter_lazy_tlb':
arch/x86/include/asm/mmu_context.h:155:27: error: 'cpu_tlbstate' undeclared (first use in this function); did you mean 'cpuhp_state'?
155 | if (this_cpu_read(cpu_tlbstate.loaded_mm) == &init_mm)
| ^~~~~~~~~~~~
```