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-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1260850127-9766-17-git-send-email-zamsden@redhat.com>
Date:	Mon, 14 Dec 2009 18:08:43 -1000
From:	Zachary Amsden <zamsden@...hat.com>
To:	kvm@...r.kernel.org
Cc:	Zachary Amsden <zamsden@...hat.com>, Avi Kivity <avi@...hat.com>,
	Marcelo Tosatti <mtosatti@...hat.com>,
	Joerg Roedel <joerg.roedel@....com>,
	linux-kernel@...r.kernel.org, Dor Laor <dlaor@...hat.com>
Subject: [PATCH RFC: kvm tsc virtualization 16/20] Fix 32-bit mult_precise

Turns out it wasn't very precise; it needs to work on 64-bit values.

Signed-off-by: Zachary Amsden <zamsden@...hat.com>
---
 arch/x86/kvm/x86.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 7e2ba3e..792c895 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -803,15 +803,27 @@ static void compute_best_multiplier(unsigned long a, unsigned long b,
 	*s = shift;
 }
 
-static inline unsigned long mult_precise(unsigned long val, unsigned long mult,
-	int shift)
+static inline u64 mult_precise(u64 val, unsigned long mult, int shift)
 {
+#if (BITS_PER_LONG == 64)
 	unsigned long top, bot;
 
-	__asm__ ( "mul %3; shrd %1, %0" :
+	__asm__ ( "mulq %3; shrdq %1, %0" :
 		 "=&a" (bot), "=&d" (top) :
 		 "0" (mult), "rm" (val), "c" (shift));
 	return bot;
+#else
+	unsigned long ltop, lbot;
+	unsigned long htop, hbot;
+
+	__asm__ ( "mull %3; shrd %1, %0" :
+		 "=&a" (lbot), "=&d" (ltop) :
+		 "0" (mult), "rm" (long)(val), "c" (shift));
+	__asm__ ( "mull %3; shrd %1, %0" :
+		 "=&a" (hbot), "=&d" (htop) :
+		 "0" (mult), "rm" (long)(val >> 32), "c" (shift));
+	return (u64)lbot + ((u64)ltop + (u64)hbot) << 32;
+#endif
 }
 
 static inline u64 compute_ref_tsc(void)
-- 
1.6.5.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ