Skip to content

Commit 62627be

Browse files
John StultzKAGA-KOKO
authored andcommitted
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 <[email protected]> Tested-by: Konrad Rzeszutek Wilk <[email protected]> Signed-off-by: John Stultz <[email protected]> LKML-Reference: <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]>
1 parent 9378b63 commit 62627be

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/x86/kernel/tsc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ unsigned long native_calibrate_tsc(void)
464464
tsc_pit_min = min(tsc_pit_min, tsc_pit_khz);
465465

466466
/* hpet or pmtimer available ? */
467-
if (!hpet && !ref1 && !ref2)
467+
if (ref1 == ref2)
468468
continue;
469469

470470
/* Check, whether the sampling was disturbed by an SMI */
@@ -935,7 +935,7 @@ static void tsc_refine_calibration_work(struct work_struct *work)
935935
tsc_stop = tsc_read_refs(&ref_stop, hpet);
936936

937937
/* hpet or pmtimer available ? */
938-
if (!hpet && !ref_start && !ref_stop)
938+
if (ref_start == ref_stop)
939939
goto out;
940940

941941
/* Check, whether the sampling was disturbed by an SMI */

0 commit comments

Comments
 (0)