Skip to content

Commit 078194f

Browse files
amlutoIngo Molnar
authored andcommitted
x86/mm, sched/core: Turn off IRQs in switch_mm()
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 <[email protected]> Reviewed-by: Borislav Petkov <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/f19baf759693c9dcae64bbff76189db77cb13398.1461688545.git.luto@kernel.org Signed-off-by: Ingo Molnar <[email protected]>
1 parent 69c0319 commit 078194f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

arch/x86/include/asm/mmu_context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ static inline void destroy_context(struct mm_struct *mm)
118118
extern void switch_mm(struct mm_struct *prev, struct mm_struct *next,
119119
struct task_struct *tsk);
120120

121+
extern void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
122+
struct task_struct *tsk);
123+
#define switch_mm_irqs_off switch_mm_irqs_off
121124

122125
#define activate_mm(prev, next) \
123126
do { \

arch/x86/mm/tlb.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ EXPORT_SYMBOL_GPL(leave_mm);
6363

6464
void switch_mm(struct mm_struct *prev, struct mm_struct *next,
6565
struct task_struct *tsk)
66+
{
67+
unsigned long flags;
68+
69+
local_irq_save(flags);
70+
switch_mm_irqs_off(prev, next, tsk);
71+
local_irq_restore(flags);
72+
}
73+
74+
void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
75+
struct task_struct *tsk)
6676
{
6777
unsigned cpu = smp_processor_id();
6878

0 commit comments

Comments
 (0)