* [PATCH] x86/tsc: fix 64bit divisor be truncated in calc_hpet_ref
@ 2018-04-13 9:48 Xiaoming Gao
2018-04-17 9:24 ` Thomas Gleixner
2018-04-17 9:56 ` [tip:x86/urgent] x86/tsc: Prevent 32bit truncation in calc_hpet_ref() tip-bot for Xiaoming Gao
0 siblings, 2 replies; 3+ messages in thread
From: Xiaoming Gao @ 2018-04-13 9:48 UTC (permalink / raw)
To: x86, linux-kernel, mingo, peterz, tglx, hpa
[-- Attachment #1: Type: text/plain, Size: 1068 bytes --]
From ba3d2fb699c4d8ee61b05d7e70be48b9c4e22baf Mon Sep 17 00:00:00 2001
From: Xiaoming Gao <newtongao@tencent.com>
Date: Fri, 13 Apr 2018 17:05:18 +0800
Subject: [PATCH] x86/tsc: fix 64bit divisor be truncated in calc_hpet_ref
the HPET frequency got larger on intel skylake, thus could cause tmp to
exceed 32bits.
do_div will truncate 64bits tmp to 32bits, so the frequency calced via
HPET will be wrong, use div64_u64 can fix it.
Signed-off-by: Xiaoming Gao <newtongao@tencent.com>
---
arch/x86/kernel/tsc.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 9714a7a..8700269 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -160,7 +160,7 @@ static unsigned long calc_hpet_ref(u64 deltatsc, u64
hpet1, u64 hpet2)
hpet2 -= hpet1;
tmp = ((u64)hpet2 * hpet_readl(HPET_PERIOD));
do_div(tmp, 1000000);
- do_div(deltatsc, tmp);
+ deltatsc = div64_u64(deltatsc, tmp);
return (unsigned long) deltatsc;
}
--
1.7.1
[-- Attachment #2: 0001-x86-tsc-fix-64bit-divisor-be-truncated-in-calc_hpet_.patch --]
[-- Type: text/plain, Size: 1013 bytes --]
From ba3d2fb699c4d8ee61b05d7e70be48b9c4e22baf Mon Sep 17 00:00:00 2001
From: Xiaoming Gao <newtongao@tencent.com>
Date: Fri, 13 Apr 2018 17:05:18 +0800
Subject: [PATCH] x86/tsc: fix 64bit divisor be truncated in calc_hpet_ref
the HPET frequency got larger on intel skylake, thus could cause tmp to
exceed 32bits.
do_div will truncate 64bits tmp to 32bits, so the frequency calced via
HPET will be wrong, use div64_u64 can fix it.
Signed-off-by: Xiaoming Gao <newtongao@tencent.com>
---
arch/x86/kernel/tsc.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 9714a7a..8700269 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -160,7 +160,7 @@ static unsigned long calc_hpet_ref(u64 deltatsc, u64 hpet1, u64 hpet2)
hpet2 -= hpet1;
tmp = ((u64)hpet2 * hpet_readl(HPET_PERIOD));
do_div(tmp, 1000000);
- do_div(deltatsc, tmp);
+ deltatsc = div64_u64(deltatsc, tmp);
return (unsigned long) deltatsc;
}
--
1.7.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/tsc: fix 64bit divisor be truncated in calc_hpet_ref
2018-04-13 9:48 [PATCH] x86/tsc: fix 64bit divisor be truncated in calc_hpet_ref Xiaoming Gao
@ 2018-04-17 9:24 ` Thomas Gleixner
2018-04-17 9:56 ` [tip:x86/urgent] x86/tsc: Prevent 32bit truncation in calc_hpet_ref() tip-bot for Xiaoming Gao
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Gleixner @ 2018-04-17 9:24 UTC (permalink / raw)
To: Xiaoming Gao; +Cc: x86, linux-kernel, mingo, peterz, hpa
[-- Attachment #1: Type: text/plain, Size: 1460 bytes --]
On Fri, 13 Apr 2018, Xiaoming Gao wrote:
> From ba3d2fb699c4d8ee61b05d7e70be48b9c4e22baf Mon Sep 17 00:00:00 2001
> From: Xiaoming Gao <newtongao@tencent.com>
> Date: Fri, 13 Apr 2018 17:05:18 +0800
> Subject: [PATCH] x86/tsc: fix 64bit divisor be truncated in calc_hpet_ref
>
> the HPET frequency got larger on intel skylake, thus could cause tmp to
> exceed 32bits.
> do_div will truncate 64bits tmp to 32bits, so the frequency calced via
> HPET will be wrong, use div64_u64 can fix it.
>
> Signed-off-by: Xiaoming Gao <newtongao@tencent.com>
> ---
> arch/x86/kernel/tsc.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
> index 9714a7a..8700269 100644
> --- a/arch/x86/kernel/tsc.c
> +++ b/arch/x86/kernel/tsc.c
> @@ -160,7 +160,7 @@ static unsigned long calc_hpet_ref(u64 deltatsc, u64
> hpet1, u64 hpet2)
> hpet2 -= hpet1;
> tmp = ((u64)hpet2 * hpet_readl(HPET_PERIOD));
> do_div(tmp, 1000000);
> - do_div(deltatsc, tmp);
> + deltatsc = div64_u64(deltatsc, tmp);
>
> return (unsigned long) deltatsc;
Please fix your MUA so it does not whitespace damage
patches. Documentation/process/email-clients.rst tells you how to teach
thunderbird to do the right thing.
Attaching the patch does not help either as it breaks the workflow. I've
fixed it up manually this time, but please be more careful next time.
Thanks,
tglx
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip:x86/urgent] x86/tsc: Prevent 32bit truncation in calc_hpet_ref()
2018-04-13 9:48 [PATCH] x86/tsc: fix 64bit divisor be truncated in calc_hpet_ref Xiaoming Gao
2018-04-17 9:24 ` Thomas Gleixner
@ 2018-04-17 9:56 ` tip-bot for Xiaoming Gao
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Xiaoming Gao @ 2018-04-17 9:56 UTC (permalink / raw)
To: linux-tip-commits
Cc: tglx, hpa, gxm.linux.kernel, linux-kernel, newtongao, mingo
Commit-ID: d3878e164dcd3925a237a20e879432400e369172
Gitweb: https://git.kernel.org/tip/d3878e164dcd3925a237a20e879432400e369172
Author: Xiaoming Gao <gxm.linux.kernel@gmail.com>
AuthorDate: Fri, 13 Apr 2018 17:48:08 +0800
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Tue, 17 Apr 2018 11:50:42 +0200
x86/tsc: Prevent 32bit truncation in calc_hpet_ref()
The TSC calibration code uses HPET as reference. The conversion normalizes
the delta of two HPET timestamps:
hpetref = ((tshpet1 - tshpet2) * HPET_PERIOD) / 1e6
and then divides the normalized delta of the corresponding TSC timestamps
by the result to calulate the TSC frequency.
tscfreq = ((tstsc1 - tstsc2 ) * 1e6) / hpetref
This uses do_div() which takes an u32 as the divisor, which worked so far
because the HPET frequency was low enough that 'hpetref' never exceeded
32bit.
On Skylake machines the HPET frequency increased so 'hpetref' can exceed
32bit. do_div() truncates the divisor, which causes the calibration to
fail.
Use div64_u64() to avoid the problem.
[ tglx: Fixes whitespace mangled patch and rewrote changelog ]
Signed-off-by: Xiaoming Gao <newtongao@tencent.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Cc: peterz@infradead.org
Cc: hpa@zytor.com
Link: https://lkml.kernel.org/r/38894564-4fc9-b8ec-353f-de702839e44e@gmail.com
---
arch/x86/kernel/tsc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index ef32297ff17e..91e6da48cbb6 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -317,7 +317,7 @@ static unsigned long calc_hpet_ref(u64 deltatsc, u64 hpet1, u64 hpet2)
hpet2 -= hpet1;
tmp = ((u64)hpet2 * hpet_readl(HPET_PERIOD));
do_div(tmp, 1000000);
- do_div(deltatsc, tmp);
+ deltatsc = div64_u64(deltatsc, tmp);
return (unsigned long) deltatsc;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-04-17 9:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-13 9:48 [PATCH] x86/tsc: fix 64bit divisor be truncated in calc_hpet_ref Xiaoming Gao
2018-04-17 9:24 ` Thomas Gleixner
2018-04-17 9:56 ` [tip:x86/urgent] x86/tsc: Prevent 32bit truncation in calc_hpet_ref() tip-bot for Xiaoming Gao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome