x86, tsc: Fix tsc ratio calibration to avoid broken mdelay
Subsystems (2)
PATCH 1/1 x86, tsc: Fix tsc ratio calibration to avoid broken mdelay
From: Chen Yu <[email protected]>
Currently we fetch the tsc radio by:
ratio = (lo >> 8) & 0x1f;
thus get bit8~bit12 of the MSR_PLATFORM_INFO, however according to Intel 64 and IA-32 Architectures Software Developer Manual 35.5, the ratio bit should be bit8~bit15, otherwise we might get incorrect tsc ratio and cause system hang later(mdelay corrupted).
Fix this problem by masking 0xff instead.
--- arch/x86/kernel/tsc_msr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/tsc_msr.c +1 -1
@@ -92,7 +92,7 @@ unsigned long try_msr_calibrate_tsc(void)if (freq_desc_tables[cpu_index].msr_plat) {rdmsr (MSR_PLATFORM_INFO , lo, hi); - ratio = (lo >>8 ) &0x1f ; + ratio = (lo >>8 ) &0xff ; }else {rdmsr (MSR_IA32_PERF_STATUS , lo, hi); ratio = (hi >>8 ) &0x1f ;
Signature · 1 line
2.7.4
Quoted 8 lines · On Fri, 6 May 2016, [email protected] wrote:
From: Chen Yu <[email protected]>
Currently we fetch the tsc radio by:
ratio = (lo >> 8) &0x1f;
thus get bit8~bit12 of theMSR_PLATFORM_INFO, however according to Intel 64 and IA-32 Architectures Software Developer Manual 35.5, the ratio bit should be bit8~bit15, otherwise we might get incorrect tsc ratio and cause system hang later(mdelay corrupted).
The resulting issue is that both TSC frequency, which is used for udelay, and the lapic timer frequency are wrong. mdelay is just the visible damage caused by that.
Thanks,
tglx
tip-bot for Chen Yu
merge bot[tip:x86/urgent] x86/tsc: Read all ratio bits from MSR_PLATFORM_INFO
In reply to [email protected]x86/tsc: Read all ratio bits from MSR_PLATFORM_INFO
Commit-ID: 886123fb3a8656699dff40afa0573df359abeb18 Gitweb: http://git.kernel.org/tip/886123fb3a8656699dff40afa0573df359abeb18 Author: Chen Yu <[email protected]> AuthorDate: Fri, 6 May 2016 11:33:39 +0800 Committer: Thomas Gleixner <[email protected]> CommitDate: Fri, 6 May 2016 11:50:50 +0200
x86/tsc: Read all ratio bits from MSR_PLATFORM_INFO
Currently we read the tsc radio: ratio = (MSR_PLATFORM_INFO >> 8) & 0x1f;
Thus we get bit 8-12 of MSR_PLATFORM_INFO, however according to the SDM (35.5), the ratio bits are bit 8-15.
Ignoring the upper bits can result in an incorrect tsc ratio, which causes the TSC calibration and the Local APIC timer frequency to be incorrect.
Fix this problem by masking 0xff instead.
[ tglx: Massaged changelog ]
--- arch/x86/kernel/tsc_msr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/tsc_msr.c +1 -1
@@ -92,7 +92,7 @@ unsigned long try_msr_calibrate_tsc(void)if (freq_desc_tables[cpu_index].msr_plat) {rdmsr (MSR_PLATFORM_INFO , lo, hi); - ratio = (lo >>8 ) &0x1f ; + ratio = (lo >>8 ) &0xff ; }else {rdmsr (MSR_IA32_PERF_STATUS , lo, hi); ratio = (hi >>8 ) &0x1f ;
Quoted 10 lines · Thomas Gleixner
Quoted 8 lines · On Fri, 6 May 2016, [email protected] wrote:
From: Chen Yu <[email protected]>
Currently we fetch the tsc radio by:
ratio = (lo >> 8) &0x1f;
thus get bit8~bit12 of theMSR_PLATFORM_INFO, however according to Intel 64 and IA-32 Architectures Software Developer Manual 35.5, the ratio bit should be bit8~bit15, otherwise we might get incorrect tsc ratio and cause system hang later(mdelay corrupted).
Quoted 3 lines
The resulting issue is that both TSC frequency, which is used for udelay, and the lapic timer frequency are wrong. mdelay is just the visible damage caused by that.
Aside of that:
Quoted 1 line
Cc 3.14+ <[email protected]> # 3.14+
Please use:
next time, which identifies the kernel version to which this needs to be backported and gives a reference to the commit which caused the issue.
Thanks,
tglx
Quoted 28 lines
-----Original Message-----
From: Thomas Gleixner [mailto:[email protected]]
Sent: Friday, May 06, 2016 5:53 PM
To: Chen, Yu C
Cc: [email protected]; [email protected]; Ingo Molnar; H. Peter Anvin; Gao, Bin; Len Brown; Rafael J. Wysocki; 3 . 14+ # 3 . 14+
Subject: Re: [PATCH] x86, tsc: Fix tsc ratio calibration to avoid broken mdelayQuoted 10 lines · Thomas Gleixner
Quoted 8 lines · On Fri, 6 May 2016, [email protected] wrote:
From: Chen Yu <[email protected]>
Currently we fetch the tsc radio by:
ratio = (lo >> 8) &0x1f;
thus get bit8~bit12 of theMSR_PLATFORM_INFO, however according to Intel 64 and IA-32 Architectures Software Developer Manual 35.5, the ratio bit should be bit8~bit15, otherwise we might get incorrect tsc ratio and cause system hang later(mdelay corrupted).Quoted 3 lines
The resulting issue is that both TSC frequency, which is used for udelay, and the lapic timer frequency are wrong. mdelay is just the visible damage caused by that.
Aside of that:
Quoted 9 lines
Quoted 1 line
Cc 3.14+ <[email protected]> # 3.14+Please use:
Fixes commit '....'next time, which identifies the kernel version to which this needs to be backported and gives a reference to the commit which caused the issue.
OK, thanks!