[PATCH] x86-64: Fix race in exit_idle

When another interrupt happens in exit_idle the exit idle notifier
could be called an incorrect number of times.

Add a test_and_clear_bit_pda and use it handle the bit
atomically against interrupts to avoid this.

Pointed out by Stephane Eranian

Signed-off-by: Andi Kleen <ak@suse.de>

authored by Andi Kleen and committed by Andi Kleen 9446868b 8c131af1

+10 -2
+1 -2
arch/x86_64/kernel/process.c
··· 88 88 89 89 static void __exit_idle(void) 90 90 { 91 - if (read_pda(isidle) == 0) 91 + if (test_and_clear_bit_pda(0, isidle) == 0) 92 92 return; 93 - write_pda(isidle, 0); 94 93 atomic_notifier_call_chain(&idle_notifier, IDLE_END, NULL); 95 94 } 96 95
+9
include/asm-x86_64/pda.h
··· 109 109 #define sub_pda(field,val) pda_to_op("sub",field,val) 110 110 #define or_pda(field,val) pda_to_op("or",field,val) 111 111 112 + /* This is not atomic against other CPUs -- CPU preemption needs to be off */ 113 + #define test_and_clear_bit_pda(bit,field) ({ \ 114 + int old__; \ 115 + asm volatile("btr %2,%%gs:%c3\n\tsbbl %0,%0" \ 116 + : "=r" (old__), "+m" (_proxy_pda.field) \ 117 + : "dIr" (bit), "i" (pda_offset(field)) : "memory"); \ 118 + old__; \ 119 + }) 120 + 112 121 #endif 113 122 114 123 #define PDA_STACKOFFSET (5*8)