lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1536228203-18701-1-git-send-email-chuanhua.lei@linux.intel.com>
Date:   Thu,  6 Sep 2018 18:03:23 +0800
From:   Chuanhua Lei <chuanhua.lei@...ux.intel.com>
To:     yixin.zhu@...ux.intel.com, chuanhua.lei@...ux.intel.com
Cc:     "H. Peter Anvin" <hpa@...or.com>,
        Peter Zijlstra <peterz@...radead.org>, x86@...nel.org,
        linux-kernel@...r.kernel.org, Thomas Gleixner <tglx@...utronix.de>,
        Len Brown <len.brown@...el.com>,
        Pavel Tatashin <pasha.tatashin@...cle.com>,
        Rajvi Jingar <rajvi.jingar@...el.com>,
        Ingo Molnar <mingo@...hat.com>,
        Dou Liyang <douly.fnst@...fujitsu.com>
Subject: [PATCH] x86/tsc: Fix 32bit mode issue in get_loops_per_jiffy()

lpj returns as zero which is not expected in 32 bit mode
After disassembling the code,
0xc1239a9e <+199>:   imul   $0x3e8,0xc12296e4,%edx
0xc1239aa8 <+209>:   xor    %ecx,%ecx
0xc1239aaa <+211>:   test   %edx,%edx
0xc1239aac <+213>:   mov    %eax,%ebx
0xc1239aae <+215>:   je     0xc1239abd <tsc_init+230>
0xc1239ab0 <+217>:   mov    $0x64,%ecx
0xc1239ab5 <+222>:   mov    %edx,%eax
0xc1239ab7 <+224>:   xor    %edx,%edx
0xc1239ab9 <+226>:   div    %ecx
0xc1239abb <+228>:   mov    %eax,%ecx
0xc1239abd <+230>:   mov    %ebx,%eax
0xc1239abf <+232>:   mov    $0x64,%ebx
0xc1239ac4 <+237>:   div    %ebx
0xc1239ac6 <+239>:   mov    %ecx,%edx

imul will load the result into %edx, %edx supposed to be high 32 bit
which is not zero. It should be zero in this case. Both lpj and tsc_khz
should be u64 to work properly for both 32 bit and 64 bit mode.

Signed-off-by: Chuanhua Lei <chuanhua.lei@...ux.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 1463468..b346e3f 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;
-- 
2.7.5

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ