mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [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

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