Skip to content

Commit decab08

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
x86/mm: Remove preempt_disable/enable() from __native_flush_tlb()
The preempt_disable/enable() pair in __native_flush_tlb() was added in commit: 5cf0791 ("x86/mm: Disable preemption during CR3 read+write") ... to protect the UP variant of flush_tlb_mm_range(). That preempt_disable/enable() pair should have been added to the UP variant of flush_tlb_mm_range() instead. The UP variant was removed with commit: ce4a4e5 ("x86/mm: Remove the UP asm/tlbflush.h code, always use the (formerly) SMP code") ... but the preempt_disable/enable() pair stayed around. The latest change to __native_flush_tlb() in commit: 6fd166a ("x86/mm: Use/Fix PCID to optimize user/kernel switches") ... added an access to a per CPU variable outside the preempt disabled regions, which makes no sense at all. __native_flush_tlb() must always be called with at least preemption disabled. Remove the preempt_disable/enable() pair and add a WARN_ON_ONCE() to catch bad callers independent of the smp_processor_id() debugging. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: <stable@vger.kernel.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Dominik Brodowski <linux@dominikbrodowski.net> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Linus Torvalds <torvalds@linuxfoundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20171230211829.679325424@linutronix.de Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 322f8b8 commit decab08

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

arch/x86/include/asm/tlbflush.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,15 +345,17 @@ static inline void invalidate_user_asid(u16 asid)
345345
*/
346346
static inline void __native_flush_tlb(void)
347347
{
348-
invalidate_user_asid(this_cpu_read(cpu_tlbstate.loaded_mm_asid));
349348
/*
350-
* If current->mm == NULL then we borrow a mm which may change
351-
* during a task switch and therefore we must not be preempted
352-
* while we write CR3 back:
349+
* Preemption or interrupts must be disabled to protect the access
350+
* to the per CPU variable and to prevent being preempted between
351+
* read_cr3() and write_cr3().
353352
*/
354-
preempt_disable();
353+
WARN_ON_ONCE(preemptible());
354+
355+
invalidate_user_asid(this_cpu_read(cpu_tlbstate.loaded_mm_asid));
356+
357+
/* If current->mm == NULL then the read_cr3() "borrows" an mm */
355358
native_write_cr3(__native_read_cr3());
356-
preempt_enable();
357359
}
358360

359361
/*

0 commit comments

Comments
 (0)