diff options
author | John Stultz <johnstul@us.ibm.com> | 2011-01-14 12:06:28 -0500 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2011-01-14 12:28:01 -0500 |
commit | 62627bec8a601c5679bf3d20a2096a1206d61b71 (patch) | |
tree | 5dbad3bd7811d8a98b24dc0e8ec9d8ecab6c0a21 /arch | |
parent | 9378b63ccb32b9c071dab155c96357ad1e52a709 (diff) |
x86: tsc: Fix calibration refinement conditionals to avoid divide by zero
Konrad Wilk reported that the new delayed calibration crashes with a
divide by zero on Xen. The reason is that Xen sets the pmtimer
address, but reading from it returns 0xffffff. That results in the
ref_start and ref_stop value being the same, so the delta is zero
which causes the divide by zero later in the calculation.
The conditional (!hpet && !ref_start && !ref_stop) which sanity checks
the calibration reference values doesn't really make sense. If the
refs are null, but hpet is on, we still want to break out.
The div by zero would be possible to trigger by chance if both reads
from the hardware provided the exact same value (due to hardware
wrapping).
So checking if both the ref values are the same should handle if we
don't have hardware (both null) or if they are the same value (either by
invalid hardware, or by chance), avoiding the div by zero issue.
[ tglx: Applied the same fix to native_calibrate_tsc() where this
check was copied from ]
Reported-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Tested-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: John Stultz <johnstul@us.ibm.com>
LKML-Reference: <1295024788-15619-1-git-send-email-johnstul@us.ibm.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/x86/kernel/tsc.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 463901efdba4..ae09f970e626 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c | |||
@@ -464,7 +464,7 @@ unsigned long native_calibrate_tsc(void) | |||
464 | tsc_pit_min = min(tsc_pit_min, tsc_pit_khz); | 464 | tsc_pit_min = min(tsc_pit_min, tsc_pit_khz); |
465 | 465 | ||
466 | /* hpet or pmtimer available ? */ | 466 | /* hpet or pmtimer available ? */ |
467 | if (!hpet && !ref1 && !ref2) | 467 | if (ref1 == ref2) |
468 | continue; | 468 | continue; |
469 | 469 | ||
470 | /* Check, whether the sampling was disturbed by an SMI */ | 470 | /* Check, whether the sampling was disturbed by an SMI */ |
@@ -935,7 +935,7 @@ static void tsc_refine_calibration_work(struct work_struct *work) | |||
935 | tsc_stop = tsc_read_refs(&ref_stop, hpet); | 935 | tsc_stop = tsc_read_refs(&ref_stop, hpet); |
936 | 936 | ||
937 | /* hpet or pmtimer available ? */ | 937 | /* hpet or pmtimer available ? */ |
938 | if (!hpet && !ref_start && !ref_stop) | 938 | if (ref_start == ref_stop) |
939 | goto out; | 939 | goto out; |
940 | 940 | ||
941 | /* Check, whether the sampling was disturbed by an SMI */ | 941 | /* Check, whether the sampling was disturbed by an SMI */ |