virt-what-cvm: support alternative cpuid leaf ordering
authorDaniel P. Berrangé <berrange@redhat.com>
Thu, 29 Jun 2023 16:51:03 +0000 (17:51 +0100)
committerRichard W.M. Jones <rjones@redhat.com>
Thu, 29 Jun 2023 17:17:19 +0000 (18:17 +0100)
The HyperV CPUID leaf for reporting the vendor string has an
alternative ordering of ecx/edx.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
virt-what-cvm.c

index f184768..1e7c50b 100644 (file)
@@ -209,11 +209,14 @@ cpuid (uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
 
 
 static uint32_t
-cpuid_leaf (uint32_t eax, char *sig)
+cpuid_leaf (uint32_t eax, char *sig, bool swapped)
 {
   uint32_t *sig32 = (uint32_t *) sig;
 
-  cpuid (&eax, &sig32[0], &sig32[2], &sig32[1]);
+  if (swapped)
+    cpuid (&eax, &sig32[0], &sig32[2], &sig32[1]);
+  else
+    cpuid (&eax, &sig32[0], &sig32[1], &sig32[2]);
   sig[12] = 0; /* \0-terminate the string to make string comparison possible */
   debug("CPUID sig %s\n", sig);
   return eax;
@@ -335,7 +338,7 @@ cpu_sig_intel (void)
     return;
 
   memset (sig, 0, sizeof sig);
-  cpuid_leaf (CPUID_INTEL_TDX_ENUMERATION, sig);
+  cpuid_leaf (CPUID_INTEL_TDX_ENUMERATION, sig, true);
 
   if (memcmp (sig, CPUID_SIG_INTEL_TDX, sizeof(sig)) == 0)
     puts ("intel-tdx");
@@ -368,7 +371,7 @@ cpu_sig (void)
     return;
 
   memset (sig, 0, sizeof sig);
-  cpuid_leaf (0, sig);
+  cpuid_leaf (0, sig, true);
 
   if (memcmp (sig, CPUID_SIG_AMD, sizeof(sig)) == 0)
     cpu_sig_amd ();