diff options
| author | Andrew Morton <akpm@linux-foundation.org> | 2007-11-14 20:00:41 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-11-14 21:45:44 -0500 |
| commit | 35d5d08a085c56f153458c3f5d8ce24123617faf (patch) | |
| tree | 2db6e598e87809bc1ce7838861b2cff18e5fe60d /arch/x86/lib | |
| parent | 7eea436433b7b18045f272562e256976f593f7c0 (diff) | |
x86: disable preemption in delay_tsc()
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 <ak@suse.de>
Cc: Marin Mitov <mitov@issp.bas.bg>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/x86/lib')
| -rw-r--r-- | arch/x86/lib/delay_32.c | 3 | ||||
| -rw-r--r-- | arch/x86/lib/delay_64.c | 11 |
2 files changed, 10 insertions, 4 deletions
diff --git a/arch/x86/lib/delay_32.c b/arch/x86/lib/delay_32.c index 952e7a89c2..aad9d95469 100644 --- a/arch/x86/lib/delay_32.c +++ b/arch/x86/lib/delay_32.c | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | 12 | ||
| 13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
| 14 | #include <linux/sched.h> | 14 | #include <linux/sched.h> |
| 15 | #include <linux/preempt.h> | ||
| 15 | #include <linux/delay.h> | 16 | #include <linux/delay.h> |
| 16 | 17 | ||
| 17 | #include <asm/processor.h> | 18 | #include <asm/processor.h> |
| @@ -42,11 +43,13 @@ static void delay_tsc(unsigned long loops) | |||
| 42 | { | 43 | { |
| 43 | unsigned long bclock, now; | 44 | unsigned long bclock, now; |
| 44 | 45 | ||
| 46 | preempt_disable(); /* TSC's are per-cpu */ | ||
| 45 | rdtscl(bclock); | 47 | rdtscl(bclock); |
| 46 | do { | 48 | do { |
| 47 | rep_nop(); | 49 | rep_nop(); |
| 48 | rdtscl(now); | 50 | rdtscl(now); |
| 49 | } while ((now-bclock) < loops); | 51 | } while ((now-bclock) < loops); |
| 52 | preempt_enable(); | ||
| 50 | } | 53 | } |
| 51 | 54 | ||
| 52 | /* | 55 | /* |
diff --git a/arch/x86/lib/delay_64.c b/arch/x86/lib/delay_64.c index 0ebbfb9e7c..45cdd3fbd9 100644 --- a/arch/x86/lib/delay_64.c +++ b/arch/x86/lib/delay_64.c | |||
| @@ -10,7 +10,9 @@ | |||
| 10 | 10 | ||
| 11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
| 12 | #include <linux/sched.h> | 12 | #include <linux/sched.h> |
| 13 | #include <linux/preempt.h> | ||
| 13 | #include <linux/delay.h> | 14 | #include <linux/delay.h> |
| 15 | |||
| 14 | #include <asm/delay.h> | 16 | #include <asm/delay.h> |
| 15 | #include <asm/msr.h> | 17 | #include <asm/msr.h> |
| 16 | 18 | ||
| @@ -27,14 +29,15 @@ int read_current_timer(unsigned long *timer_value) | |||
| 27 | void __delay(unsigned long loops) | 29 | void __delay(unsigned long loops) |
| 28 | { | 30 | { |
| 29 | unsigned bclock, now; | 31 | unsigned bclock, now; |
| 30 | 32 | ||
| 33 | preempt_disable(); /* TSC's are pre-cpu */ | ||
| 31 | rdtscl(bclock); | 34 | rdtscl(bclock); |
| 32 | do | 35 | do { |
| 33 | { | ||
| 34 | rep_nop(); | 36 | rep_nop(); |
| 35 | rdtscl(now); | 37 | rdtscl(now); |
| 36 | } | 38 | } |
| 37 | while((now-bclock) < loops); | 39 | while ((now-bclock) < loops); |
| 40 | preempt_enable(); | ||
| 38 | } | 41 | } |
| 39 | EXPORT_SYMBOL(__delay); | 42 | EXPORT_SYMBOL(__delay); |
| 40 | 43 | ||
