]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
x86/mm, sched/core: Turn off IRQs in switch_mm()
authorAndy Lutomirski <luto@kernel.org>
Tue, 26 Apr 2016 16:39:09 +0000 (09:39 -0700)
committerBen Hutchings <ben@decadent.org.uk>
Sun, 7 Jan 2018 01:46:48 +0000 (01:46 +0000)
commit 078194f8e9fe3cf54c8fd8bded48a1db5bd8eb8a upstream.

Potential races between switch_mm() and TLB-flush or LDT-flush IPIs
could be very messy.  AFAICT the code is currently okay, whether by
accident or by careful design, but enabling PCID will make it
considerably more complicated and will no longer be obviously safe.

Fix it with a big hammer: run switch_mm() with IRQs off.

To avoid a performance hit in the scheduler, we take advantage of
our knowledge that the scheduler already has IRQs disabled when it
calls switch_mm().

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Reviewed-by: Borislav Petkov <bp@suse.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/f19baf759693c9dcae64bbff76189db77cb13398.1461688545.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
arch/x86/include/asm/mmu_context.h
arch/x86/mm/tlb.c

index 4a5d9b52d4f8b01c8a654c9ded5af702ad041beb..d21af0363abe9107c9af5b24ed3cf8452e534937 100644 (file)
@@ -78,6 +78,10 @@ static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
 extern void switch_mm(struct mm_struct *prev, struct mm_struct *next,
                      struct task_struct *tsk);
 
+extern void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
+                              struct task_struct *tsk);
+#define switch_mm_irqs_off switch_mm_irqs_off
+
 #define activate_mm(prev, next)                        \
 do {                                           \
        paravirt_activate_mm((prev), (next));   \
index 96481dad7532318b35eb78b135fbd7ba881fe1fc..847ef7c11099aa07eedef0a532795edd9ea502e2 100644 (file)
@@ -75,6 +75,16 @@ EXPORT_SYMBOL_GPL(leave_mm);
 
 void switch_mm(struct mm_struct *prev, struct mm_struct *next,
               struct task_struct *tsk)
+{
+       unsigned long flags;
+
+       local_irq_save(flags);
+       switch_mm_irqs_off(prev, next, tsk);
+       local_irq_restore(flags);
+}
+
+void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
+                       struct task_struct *tsk)
 {
        unsigned cpu = smp_processor_id();