Blame SOURCES/0025-Simplify-and-fix-invocation-of-cpuid.patch

08d0b2
From 88eb2b7fbd7e6af1cd1860c3f2023ee7b9125d37 Mon Sep 17 00:00:00 2001
e10a2d
From: "Richard W.M. Jones" <rjones@redhat.com>
e10a2d
Date: Tue, 13 Apr 2021 09:35:07 +0100
08d0b2
Subject: [PATCH 25/25] Simplify and fix invocation of cpuid.
e10a2d
e10a2d
Fixes a crash on some platforms identified by Yongkui Guo in
e10a2d
https://bugzilla.redhat.com/show_bug.cgi?id=1756381#c15
08d0b2
08d0b2
(cherry picked from commit 60d903fbb7653bc9754228bdab4c6933fcda1e72)
e10a2d
---
e10a2d
 virt-what-cpuid-helper.c | 24 ++++++++++++++++--------
e10a2d
 1 file changed, 16 insertions(+), 8 deletions(-)
e10a2d
e10a2d
diff --git a/virt-what-cpuid-helper.c b/virt-what-cpuid-helper.c
e10a2d
index 9c6cdb2..fdceb62 100644
e10a2d
--- a/virt-what-cpuid-helper.c
e10a2d
+++ b/virt-what-cpuid-helper.c
e10a2d
@@ -47,17 +47,25 @@ known_signature (const char *sig)
e10a2d
     0;
e10a2d
 }
e10a2d
 
e10a2d
+/* Copied from the Linux kernel definition in
e10a2d
+ * arch/x86/include/asm/processor.h
e10a2d
+ */
e10a2d
+static inline void
e10a2d
+cpuid (uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
e10a2d
+{
e10a2d
+  asm volatile ("cpuid"
e10a2d
+                : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
e10a2d
+                : "0" (*eax), "2" (*ecx)
e10a2d
+                : "memory");
e10a2d
+}
e10a2d
+
e10a2d
 static uint32_t
e10a2d
-cpuid (uint32_t eax, char *sig)
e10a2d
+cpuid_leaf (uint32_t eax, char *sig)
e10a2d
 {
e10a2d
   uint32_t *sig32 = (uint32_t *) sig;
e10a2d
 
e10a2d
-  asm volatile (
e10a2d
-        "xchgl %%ebx,%1; xor %%ebx,%%ebx; cpuid; xchgl %%ebx,%1"
e10a2d
-        : "=a" (eax), "+r" (sig32[0]), "=c" (sig32[1]), "=d" (sig32[2])
e10a2d
-        : "0" (eax));
e10a2d
-  sig[12] = 0;
e10a2d
-
e10a2d
+  cpuid (&eax, &sig32[0], &sig32[1], &sig32[2]);
e10a2d
+  sig[12] = 0; /* \0-terminate the string to make string comparison possible */
e10a2d
   return eax;
e10a2d
 }
e10a2d
 
e10a2d
@@ -87,7 +95,7 @@ cpu_sig (void)
e10a2d
    */
e10a2d
   for (leaf = base + 0xff00; leaf >= base; leaf -= 0x100) {
e10a2d
     memset (sig, 0, sizeof sig);
e10a2d
-    cpuid (leaf, sig);
e10a2d
+    cpuid_leaf (leaf, sig);
e10a2d
     if (known_signature (sig)) {
e10a2d
       puts (sig);
e10a2d
       break;
e10a2d
-- 
08d0b2
2.18.4
e10a2d