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

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