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

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