[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <tip-17f6bac2249356c795339e03a0742cd79be3cab8@git.kernel.org>
Date: Thu, 6 Sep 2018 05:25:01 -0700
From: tip-bot for Chuanhua Lei <tipbot@...or.com>
To: linux-tip-commits@...r.kernel.org
Cc: rajvi.jingar@...el.com, peterz@...radead.org,
linux-kernel@...r.kernel.org, hpa@...or.com,
douly.fnst@...fujitsu.com, tglx@...utronix.de,
chuanhua.lei@...ux.intel.com, mingo@...nel.org,
len.brown@...el.com, pasha.tatashin@...rosoft.com
Subject: [tip:x86/urgent] x86/tsc: Prevent result truncation on 32bit
Commit-ID: 17f6bac2249356c795339e03a0742cd79be3cab8
Gitweb: https://git.kernel.org/tip/17f6bac2249356c795339e03a0742cd79be3cab8
Author: Chuanhua Lei <chuanhua.lei@...ux.intel.com>
AuthorDate: Thu, 6 Sep 2018 18:03:23 +0800
Committer: Thomas Gleixner <tglx@...utronix.de>
CommitDate: Thu, 6 Sep 2018 14:22:01 +0200
x86/tsc: Prevent result truncation on 32bit
Loops per jiffy is calculated by multiplying tsc_khz with 1e3 and then
dividing it by HZ.
Both tsc_khz and the temporary variable holding the multiplication result
are of type unsigned long, so on 32bit the result is truncated to the lower
32bit.
Use u64 as type for the temporary variable and cast tsc_khz to it before
multiplying.
[ tglx: Massaged changelog and removed pointless braces ]
Fixes: cf7a63ef4e02 ("x86/tsc: Calibrate tsc only once")
Signed-off-by: Chuanhua Lei <chuanhua.lei@...ux.intel.com>
Signed-off-by: Thomas Gleixner <tglx@...utronix.de>
Cc: yixin.zhu@...ux.intel.com
Cc: "H. Peter Anvin" <hpa@...or.com>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Len Brown <len.brown@...el.com>
Cc: Pavel Tatashin <pasha.tatashin@...rosoft.com>
Cc: Rajvi Jingar <rajvi.jingar@...el.com>
Cc: Dou Liyang <douly.fnst@...fujitsu.com>
Link: https://lkml.kernel.org/r/1536228203-18701-1-git-send-email-chuanhua.lei@linux.intel.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 1463468ba9a0..6490f618e096 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -1415,7 +1415,7 @@ static bool __init determine_cpu_tsc_frequencies(bool early)
static unsigned long __init get_loops_per_jiffy(void)
{
- unsigned long lpj = tsc_khz * KHZ;
+ u64 lpj = (u64)tsc_khz * KHZ;
do_div(lpj, HZ);
return lpj;
Powered by blists - more mailing lists