Skip to content

Commit 5f0e030

Browse files
committed
x86, tsc: Fallback to normal calibration if fast MSR calibration fails
If we cannot calibrate TSC via MSR based calibration try_msr_calibrate_tsc() stores zero to fast_calibrate and returns that to the caller. This value gets then propagated further to clockevents code resulting division by zero oops like the one below: divide error: 0000 [#1] PREEMPT SMP Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Tainted: G W 3.13.0+ #47 task: ffff880075508000 ti: ffff880075506000 task.ti: ffff880075506000 RIP: 0010:[<ffffffff810aec14>] [<ffffffff810aec14>] clockevents_config.part.3+0x24/0xa0 RSP: 0000:ffff880075507e58 EFLAGS: 00010246 RAX: ffffffffffffffff RBX: ffff880079c0cd80 RCX: 0000000000000000 RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffffffffffff RBP: ffff880075507e70 R08: 0000000000000001 R09: 00000000000000be R10: 00000000000000bd R11: 0000000000000003 R12: 000000000000b008 R13: 0000000000000008 R14: 000000000000b010 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff880079c00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b CR2: ffff880079fff000 CR3: 0000000001c0b000 CR4: 00000000001006f0 Stack: ffff880079c0cd80 000000000000b008 0000000000000008 ffff880075507e88 ffffffff810aecb0 ffff880079c0cd80 ffff880075507e98 ffffffff81030168 ffff880075507ed8 ffffffff81d1104f 00000000000000c3 0000000000000000 Call Trace: [<ffffffff810aecb0>] clockevents_config_and_register+0x20/0x30 [<ffffffff81030168>] setup_APIC_timer+0xc8/0xd0 [<ffffffff81d1104f>] setup_boot_APIC_clock+0x4cc/0x4d8 [<ffffffff81d0f5de>] native_smp_prepare_cpus+0x3dd/0x3f0 [<ffffffff81d02ee9>] kernel_init_freeable+0xc3/0x205 [<ffffffff8177c910>] ? rest_init+0x90/0x90 [<ffffffff8177c91e>] kernel_init+0xe/0x120 [<ffffffff8178deec>] ret_from_fork+0x7c/0xb0 [<ffffffff8177c910>] ? rest_init+0x90/0x90 Prevent this from happening by: 1) Modifying try_msr_calibrate_tsc() to return calibration value or zero if it fails. 2) Check this return value in native_calibrate_tsc() and in case of zero fallback to use normal non-MSR based calibration. [mw: Added subject and changelog] Reported-and-tested-by: Mika Westerberg <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: Bin Gao <[email protected]> Cc: One Thousand Gnomes <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: H. Peter Anvin <[email protected]> Link: http://lkml.kernel.org/r/1392810750-18660-1-git-send-email-mika.westerberg@linux.intel.com Signed-off-by: Mika Westerberg <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]>
1 parent 805937c commit 5f0e030

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

arch/x86/include/asm/tsc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ extern void tsc_save_sched_clock_state(void);
6666
extern void tsc_restore_sched_clock_state(void);
6767

6868
/* MSR based TSC calibration for Intel Atom SoC platforms */
69-
int try_msr_calibrate_tsc(unsigned long *fast_calibrate);
69+
unsigned long try_msr_calibrate_tsc(void);
7070

7171
#endif /* _ASM_X86_TSC_H */

arch/x86/kernel/tsc.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -653,13 +653,10 @@ unsigned long native_calibrate_tsc(void)
653653

654654
/* Calibrate TSC using MSR for Intel Atom SoCs */
655655
local_irq_save(flags);
656-
i = try_msr_calibrate_tsc(&fast_calibrate);
656+
fast_calibrate = try_msr_calibrate_tsc();
657657
local_irq_restore(flags);
658-
if (i >= 0) {
659-
if (i == 0)
660-
pr_warn("Fast TSC calibration using MSR failed\n");
658+
if (fast_calibrate)
661659
return fast_calibrate;
662-
}
663660

664661
local_irq_save(flags);
665662
fast_calibrate = quick_pit_calibrate();

arch/x86/kernel/tsc_msr.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,18 @@ static int match_cpu(u8 family, u8 model)
7777

7878
/*
7979
* Do MSR calibration only for known/supported CPUs.
80-
* Return values:
81-
* -1: CPU is unknown/unsupported for MSR based calibration
82-
* 0: CPU is known/supported, but calibration failed
83-
* 1: CPU is known/supported, and calibration succeeded
80+
*
81+
* Returns the calibration value or 0 if MSR calibration failed.
8482
*/
85-
int try_msr_calibrate_tsc(unsigned long *fast_calibrate)
83+
unsigned long try_msr_calibrate_tsc(void)
8684
{
87-
int cpu_index;
8885
u32 lo, hi, ratio, freq_id, freq;
86+
unsigned long res;
87+
int cpu_index;
8988

9089
cpu_index = match_cpu(boot_cpu_data.x86, boot_cpu_data.x86_model);
9190
if (cpu_index < 0)
92-
return -1;
93-
94-
*fast_calibrate = 0;
91+
return 0;
9592

9693
if (freq_desc_tables[cpu_index].msr_plat) {
9794
rdmsr(MSR_PLATFORM_INFO, lo, hi);
@@ -103,7 +100,7 @@ int try_msr_calibrate_tsc(unsigned long *fast_calibrate)
103100
pr_info("Maximum core-clock to bus-clock ratio: 0x%x\n", ratio);
104101

105102
if (!ratio)
106-
return 0;
103+
goto fail;
107104

108105
/* Get FSB FREQ ID */
109106
rdmsr(MSR_FSB_FREQ, lo, hi);
@@ -112,16 +109,19 @@ int try_msr_calibrate_tsc(unsigned long *fast_calibrate)
112109
pr_info("Resolved frequency ID: %u, frequency: %u KHz\n",
113110
freq_id, freq);
114111
if (!freq)
115-
return 0;
112+
goto fail;
116113

117114
/* TSC frequency = maximum resolved freq * maximum resolved bus ratio */
118-
*fast_calibrate = freq * ratio;
119-
pr_info("TSC runs at %lu KHz\n", *fast_calibrate);
115+
res = freq * ratio;
116+
pr_info("TSC runs at %lu KHz\n", res);
120117

121118
#ifdef CONFIG_X86_LOCAL_APIC
122119
lapic_timer_frequency = (freq * 1000) / HZ;
123120
pr_info("lapic_timer_frequency = %d\n", lapic_timer_frequency);
124121
#endif
122+
return res;
125123

126-
return 1;
124+
fail:
125+
pr_warn("Fast TSC calibration using MSR failed\n");
126+
return 0;
127127
}

0 commit comments

Comments
 (0)