@@ -172,6 +172,28 @@ struct tlb_state_shared {
172172};
173173DECLARE_PER_CPU_SHARED_ALIGNED (struct tlb_state_shared , cpu_tlbstate_shared );
174174
175+ /*
176+ * Please ignore the name of this function. It should be called
177+ * switch_to_kernel_thread().
178+ *
179+ * enter_lazy_tlb() is a hint from the scheduler that we are entering a
180+ * kernel thread or other context without an mm. Acceptable implementations
181+ * include doing nothing whatsoever, switching to init_mm, or various clever
182+ * lazy tricks to try to minimize TLB flushes.
183+ *
184+ * The scheduler reserves the right to call enter_lazy_tlb() several times
185+ * in a row. It will notify us that we're going back to a real mm by
186+ * calling switch_mm_irqs_off().
187+ */
188+ #define enter_lazy_tlb enter_lazy_tlb
189+ static __always_inline void enter_lazy_tlb (struct mm_struct * mm , struct task_struct * tsk )
190+ {
191+ if (this_cpu_read (cpu_tlbstate .loaded_mm ) == & init_mm )
192+ return ;
193+
194+ this_cpu_write (cpu_tlbstate_shared .is_lazy , true);
195+ }
196+
175197bool nmi_uaccess_okay (void );
176198#define nmi_uaccess_okay nmi_uaccess_okay
177199
@@ -480,6 +502,10 @@ static inline void cpu_tlbstate_update_lam(unsigned long lam, u64 untag_mask)
480502{
481503}
482504#endif
505+ #else /* !MODULE */
506+ #define enter_lazy_tlb enter_lazy_tlb
507+ extern void enter_lazy_tlb (struct mm_struct * mm , struct task_struct * tsk )
508+ __compiletime_error ("enter_lazy_tlb() should not be used in modules" );
483509#endif /* !MODULE */
484510
485511static inline void __native_tlb_flush_global (unsigned long cr4 )
0 commit comments