From: Andrew Morton Date: Thu, 15 Nov 2007 01:00:41 +0000 (-0800) Subject: x86: disable preemption in delay_tsc() X-Git-Tag: v2.6.23.9~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=778b656e0e63efe0437fe337b9556bec73dc2f9d;p=thirdparty%2Fkernel%2Fstable.git x86: disable preemption in delay_tsc() patch 35d5d08a085c56f153458c3f5d8ce24123617faf in mainline. Marin Mitov points out that delay_tsc() can misbehave if it is preempted and rescheduled on a different CPU which has a skewed TSC. Fix it by disabling preemption. (I assume that the worst-case behaviour here is a stall of 2^32 cycles) Cc: Andi Kleen Cc: Marin Mitov Cc: Thomas Gleixner Cc: Ingo Molnar Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- diff --git a/arch/i386/lib/delay.c b/arch/i386/lib/delay.c index f6edb11364dfe..66595edcd7b6d 100644 --- a/arch/i386/lib/delay.c +++ b/arch/i386/lib/delay.c @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -42,11 +43,13 @@ static void delay_tsc(unsigned long loops) { unsigned long bclock, now; + preempt_disable(); /* TSC's are per-cpu */ rdtscl(bclock); do { rep_nop(); rdtscl(now); } while ((now-bclock) < loops); + preempt_enable(); } /* diff --git a/arch/x86_64/lib/delay.c b/arch/x86_64/lib/delay.c index 2dbebd308347f..4d3f1f6413366 100644 --- a/arch/x86_64/lib/delay.c +++ b/arch/x86_64/lib/delay.c @@ -10,7 +10,9 @@ #include #include +#include #include + #include #include @@ -27,14 +29,15 @@ int read_current_timer(unsigned long *timer_value) void __delay(unsigned long loops) { unsigned bclock, now; - + + preempt_disable(); /* TSC's are pre-cpu */ rdtscl(bclock); - do - { + do { rep_nop(); rdtscl(now); } - while((now-bclock) < loops); + while ((now-bclock) < loops); + preempt_enable(); } EXPORT_SYMBOL(__delay);