From: tip-bot for Xiaoming Gao <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: tglx@linutronix.de, hpa@zytor.com, gxm.linux.kernel@gmail.com,
linux-kernel@vger.kernel.org, newtongao@tencent.com,
mingo@kernel.org
Subject: [tip:x86/urgent] x86/tsc: Prevent 32bit truncation in calc_hpet_ref()
Date: Tue, 17 Apr 2018 02:56:30 -0700 [thread overview]
Message-ID: <tip-d3878e164dcd3925a237a20e879432400e369172@git.kernel.org> (raw)
In-Reply-To: <38894564-4fc9-b8ec-353f-de702839e44e@gmail.com>
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;
}
prev parent reply other threads:[~2018-04-17 9:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-d3878e164dcd3925a237a20e879432400e369172@git.kernel.org \
--to=tipbot@zytor.com \
--cc=gxm.linux.kernel@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=newtongao@tencent.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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