diff --git a/SOURCES/0001-Missing-have_cpuinfo-check.patch b/SOURCES/0001-Missing-have_cpuinfo-check.patch index 2c2216e..e8fecb7 100644 --- a/SOURCES/0001-Missing-have_cpuinfo-check.patch +++ b/SOURCES/0001-Missing-have_cpuinfo-check.patch @@ -1,7 +1,7 @@ -From eefc1e7e3dd8fb422baf0f13aec1df9880541b83 Mon Sep 17 00:00:00 2001 +From 8f07f88aaf41f7609c9ba584ea0c291d566fa6e5 Mon Sep 17 00:00:00 2001 From: Jasper Lievisse Adriaanse Date: Thu, 10 Aug 2017 08:44:01 +0100 -Subject: [PATCH 1/4] Missing have_cpuinfo check. +Subject: [PATCH 1/8] Missing have_cpuinfo check. --- virt-what.in | 2 +- @@ -21,5 +21,5 @@ index 8c27b11..9050035 100644 fi fi -- -2.13.2 +2.32.0 diff --git a/SOURCES/0002-Remove-bashisms.patch b/SOURCES/0002-Remove-bashisms.patch index 7b88642..787c0d1 100644 --- a/SOURCES/0002-Remove-bashisms.patch +++ b/SOURCES/0002-Remove-bashisms.patch @@ -1,7 +1,7 @@ -From 9d90704a05dee7704470eff818a1c44aeef6c880 Mon Sep 17 00:00:00 2001 +From 43e99a03335b803384e241935e9c03ac000920c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Fri, 4 Aug 2017 12:02:08 -0300 -Subject: [PATCH 2/4] Remove bashisms +Subject: [PATCH 2/8] Remove bashisms Use [ instead of [[ so we fall back to test if necessary: @@ -44,5 +44,5 @@ index 9050035..a05e0db 100644 fi fi -- -2.13.2 +2.32.0 diff --git a/SOURCES/0003-As-xen-pv-guest-can-access-cpuid-from-Intel-CPUs-sta.patch b/SOURCES/0003-As-xen-pv-guest-can-access-cpuid-from-Intel-CPUs-sta.patch index bd42694..6a4e530 100644 --- a/SOURCES/0003-As-xen-pv-guest-can-access-cpuid-from-Intel-CPUs-sta.patch +++ b/SOURCES/0003-As-xen-pv-guest-can-access-cpuid-from-Intel-CPUs-sta.patch @@ -1,7 +1,7 @@ -From a821dc9961d457c086fffcc16a911cb6f9f8659a Mon Sep 17 00:00:00 2001 +From 777143e7b8f598ca16542923207e2874c1961acd Mon Sep 17 00:00:00 2001 From: xiliang Date: Sun, 18 Jun 2017 00:33:28 +0800 -Subject: [PATCH 3/4] As xen pv guest can access cpuid from Intel CPUs started +Subject: [PATCH 3/8] As xen pv guest can access cpuid from Intel CPUs started IvyBridge onwards have CPUID Faulting, added one more check in virt-what. --- @@ -31,5 +31,5 @@ index a05e0db..247348e 100644 # Check for AWS if echo "$dmi" | grep -q 'Version: [0-9]\.[0-9]\.amazon'; then -- -2.13.2 +2.32.0 diff --git a/SOURCES/0004-Recognize-ppc64le-little-endian-virtualization-RHBZ-.patch b/SOURCES/0004-Recognize-ppc64le-little-endian-virtualization-RHBZ-.patch index 98f0492..78c266e 100644 --- a/SOURCES/0004-Recognize-ppc64le-little-endian-virtualization-RHBZ-.patch +++ b/SOURCES/0004-Recognize-ppc64le-little-endian-virtualization-RHBZ-.patch @@ -1,7 +1,7 @@ -From 7db94c8fe63f2c7ec3ac27cc5ff54ec1e1686aeb Mon Sep 17 00:00:00 2001 +From d74be709e1d4ae1501a36fe7838ce13cdbc33773 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 17 Oct 2017 14:47:09 +0100 -Subject: [PATCH 4/4] Recognize ppc64le (little endian) virtualization +Subject: [PATCH 4/8] Recognize ppc64le (little endian) virtualization (RHBZ#1147876). Tested by Laurent Vivier, see: @@ -24,5 +24,5 @@ index 247348e..29b7b0d 100644 if grep -q 'model.*emulated by qemu' "${root}/proc/cpuinfo"; then echo ibm_power-kvm -- -2.13.2 +2.32.0 diff --git a/SOURCES/0005-Fix-virt-what-cpuid-helper.patch b/SOURCES/0005-Fix-virt-what-cpuid-helper.patch new file mode 100644 index 0000000..b2b5285 --- /dev/null +++ b/SOURCES/0005-Fix-virt-what-cpuid-helper.patch @@ -0,0 +1,119 @@ +From a4968db599321fe4178423c50874260a21885223 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Fri, 4 Oct 2019 15:57:42 +0300 +Subject: [PATCH 5/8] Fix virt-what-cpuid-helper. + +The value returned in %eax is the max_entry (eg. 0x40000000 +if there are no further leafs). However it is not reliable. +In addition if there are multiple leafs we should probably +only print the highest one. + +Also use uint32_t instead of unsigned int. + +Thanks: Paolo Bonzini. +(cherry picked from commit 0a0d9fa7c85c5474870cae37832d28ccd899d4ee) +--- + virt-what-cpuid-helper.c | 67 ++++++++++++++++++++++++++++------------ + 1 file changed, 48 insertions(+), 19 deletions(-) + +diff --git a/virt-what-cpuid-helper.c b/virt-what-cpuid-helper.c +index 7812545..0cd4a6f 100644 +--- a/virt-what-cpuid-helper.c ++++ b/virt-what-cpuid-helper.c +@@ -1,5 +1,5 @@ + /* virt-what-cpuid-helper: Are we running inside KVM or Xen HVM? +- * Copyright (C) 2008 Red Hat Inc. ++ * Copyright (C) 2008-2019 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by +@@ -21,14 +21,35 @@ + */ + + #include ++#include ++#include + #include + + #if defined(__i386__) || defined(__x86_64__) + +-static unsigned int +-cpuid (unsigned int eax, char *sig) ++/* Known x86 hypervisor signatures. Note that if you add a new test ++ * to virt-what.in you may need to update this list. The signature is ++ * always 12 bytes except in the case of KVM. ++ */ ++static int ++known_signature (char *sig) + { +- unsigned int *sig32 = (unsigned int *) sig; ++ return ++ strcmp (sig, "bhyve bhyve ") == 0 || ++ strcmp (sig, "KVMKVMKVM") == 0 || ++ strcmp (sig, "LKVMLKVMLKVM") == 0 || ++ strcmp (sig, "Microsoft Hv") == 0 || ++ strcmp (sig, "OpenBSDVMM58") == 0 || ++ strcmp (sig, "TCGTCGTCGTCG") == 0 || ++ strcmp (sig, "VMwareVMware") == 0 || ++ strcmp (sig, "XenVMMXenVMM") == 0 || ++ 0; ++} ++ ++static uint32_t ++cpuid (uint32_t eax, char *sig) ++{ ++ uint32_t *sig32 = (uint32_t *) sig; + + asm volatile ( + "xchgl %%ebx,%1; xor %%ebx,%%ebx; cpuid; xchgl %%ebx,%1" +@@ -43,24 +64,32 @@ static void + cpu_sig (void) + { + char sig[13]; +- unsigned int base = 0x40000000, leaf = base; +- unsigned int max_entries; ++ const uint32_t base = 0x40000000; ++ uint32_t leaf; + +- memset (sig, 0, sizeof sig); +- max_entries = cpuid (leaf, sig); +- puts (sig); +- +- /* Most hypervisors only have information in leaf 0x40000000, but +- * upstream Xen contains further leaf entries (in particular when +- * used with Viridian [HyperV] extensions). CPUID is supposed to +- * return the maximum leaf offset in %eax, so that's what we use, +- * but only if it looks sensible. ++ /* Most hypervisors only have information in leaf 0x40000000. ++ * ++ * Some hypervisors have "Viridian [HyperV] extensions", and those ++ * must appear in slot 0x40000000, but they will also have the true ++ * hypervisor in a higher slot. ++ * ++ * CPUID is supposed to return the maximum leaf offset in %eax, but ++ * this is not reliable. Instead we check the returned signatures ++ * against a known list (the others will be empty or garbage) and ++ * only print the ones we know about. This is OK because if we add ++ * a new test in virt-what we can update the list. ++ * ++ * By searching backwards we only print the highest entry, thus ++ * ignoring Viridian for Xen (and Nutanix). If we ever encounter a ++ * hypervisor that has more than 2 entries we may need to revisit ++ * this. + */ +- if (max_entries > 3 && max_entries < 0x10000) { +- for (leaf = base + 0x100; leaf <= base + max_entries; leaf += 0x100) { +- memset (sig, 0, sizeof sig); +- cpuid (leaf, sig); ++ for (leaf = base + 0xff00; leaf >= base; leaf -= 0x100) { ++ memset (sig, 0, sizeof sig); ++ cpuid (leaf, sig); ++ if (known_signature (sig)) { + puts (sig); ++ break; + } + } + } +-- +2.32.0 + diff --git a/SOURCES/0006-Add-support-for-Nutanix-Acropolis-Hypervisor-AHV-RHB.patch b/SOURCES/0006-Add-support-for-Nutanix-Acropolis-Hypervisor-AHV-RHB.patch new file mode 100644 index 0000000..9b6e113 --- /dev/null +++ b/SOURCES/0006-Add-support-for-Nutanix-Acropolis-Hypervisor-AHV-RHB.patch @@ -0,0 +1,66 @@ +From 7607348d0ea643a7ccaa154dca3c1721ac0e1385 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Fri, 4 Oct 2019 16:25:55 +0300 +Subject: [PATCH 6/8] Add support for Nutanix Acropolis Hypervisor (AHV) + (RHBZ#1756381). + +Thanks: Cristian Seres for providing access to a guest. + +Cherry picked from commit f317e788dd7c2a35c2ae0f64fa50ab720382ebf5 + +- Removed tests. + +- Removed changes to configure.ac which are not applicable to + virt-what 1.18. +--- + virt-what.in | 10 +++++++++- + virt-what.pod | 6 ++++++ + 2 files changed, 15 insertions(+), 1 deletion(-) + +diff --git a/virt-what.in b/virt-what.in +index 29b7b0d..0178eb1 100644 +--- a/virt-what.in ++++ b/virt-what.in +@@ -1,6 +1,6 @@ + #!/bin/sh - + # @configure_input@ +-# Copyright (C) 2008-2017 Red Hat Inc. ++# Copyright (C) 2008-2019 Red Hat Inc. + # + # This program is free software; you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by +@@ -213,6 +213,14 @@ if echo "$dmi" | grep -q 'Vendor: Parallels'; then + skip_qemu_kvm=true + fi + ++# Check for Nutanix AHV. ++# This is sufficiently different from KVM and has Viridian extensions, ++# so skip the KVM test. ++if echo "$dmi" | grep -q 'Manufacturer: Nutanix'; then ++ echo nutanix_ahv ++ skip_qemu_kvm=true ++fi ++ + # Check for oVirt/RHEV. + if echo "$dmi" | grep -q 'Manufacturer: oVirt'; then + echo ovirt +diff --git a/virt-what.pod b/virt-what.pod +index ebfc190..660c517 100644 +--- a/virt-what.pod ++++ b/virt-what.pod +@@ -173,6 +173,12 @@ is lkvm (a.k.a kvmtool). + + Status: contributed by Andrew Jones + ++=item B ++ ++The guest is running inside Nutanix Acropolis Hypervisor (AHV). ++ ++Status: confirmed by RWMJ. ++ + =item B + + The guest appears to be running inside an OpenVZ or Virtuozzo +-- +2.32.0 + diff --git a/SOURCES/0007-helper-Fix-KVM-signature.patch b/SOURCES/0007-helper-Fix-KVM-signature.patch new file mode 100644 index 0000000..110f336 --- /dev/null +++ b/SOURCES/0007-helper-Fix-KVM-signature.patch @@ -0,0 +1,39 @@ +From a4365b9dc13ecc0cad34599c7cbe466612436d8a Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Fri, 4 Oct 2019 18:30:01 +0100 +Subject: [PATCH 7/8] helper: Fix KVM signature. + +Thanks: Paolo Bonzini. +(cherry picked from commit 5cdf740942a4f443977344428dfe6c43f232f0eb) +--- + virt-what-cpuid-helper.c | 9 +++++---- + 1 file changed, 5 insertions(+), 4 deletions(-) + +diff --git a/virt-what-cpuid-helper.c b/virt-what-cpuid-helper.c +index 0cd4a6f..9c6cdb2 100644 +--- a/virt-what-cpuid-helper.c ++++ b/virt-what-cpuid-helper.c +@@ -28,15 +28,16 @@ + #if defined(__i386__) || defined(__x86_64__) + + /* Known x86 hypervisor signatures. Note that if you add a new test +- * to virt-what.in you may need to update this list. The signature is +- * always 12 bytes except in the case of KVM. ++ * to virt-what.in you may need to update this list. Note the ++ * signature is always 12 bytes long, plus we add \0 to the end to ++ * make it 13 bytes. + */ + static int +-known_signature (char *sig) ++known_signature (const char *sig) + { + return + strcmp (sig, "bhyve bhyve ") == 0 || +- strcmp (sig, "KVMKVMKVM") == 0 || ++ memcmp (sig, "KVMKVMKVM\0\0\0", 12) == 0 || + strcmp (sig, "LKVMLKVMLKVM") == 0 || + strcmp (sig, "Microsoft Hv") == 0 || + strcmp (sig, "OpenBSDVMM58") == 0 || +-- +2.32.0 + diff --git a/SOURCES/0008-Simplify-and-fix-invocation-of-cpuid.patch b/SOURCES/0008-Simplify-and-fix-invocation-of-cpuid.patch new file mode 100644 index 0000000..f236a8c --- /dev/null +++ b/SOURCES/0008-Simplify-and-fix-invocation-of-cpuid.patch @@ -0,0 +1,62 @@ +From de9ba1e23a8fb8098a23feaada017b1c689a5135 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Tue, 13 Apr 2021 09:35:07 +0100 +Subject: [PATCH 8/8] Simplify and fix invocation of cpuid. + +Fixes a crash on some platforms identified by Yongkui Guo in +https://bugzilla.redhat.com/show_bug.cgi?id=1756381#c15 + +(cherry picked from commit 60d903fbb7653bc9754228bdab4c6933fcda1e72) +--- + virt-what-cpuid-helper.c | 24 ++++++++++++++++-------- + 1 file changed, 16 insertions(+), 8 deletions(-) + +diff --git a/virt-what-cpuid-helper.c b/virt-what-cpuid-helper.c +index 9c6cdb2..fdceb62 100644 +--- a/virt-what-cpuid-helper.c ++++ b/virt-what-cpuid-helper.c +@@ -47,17 +47,25 @@ known_signature (const char *sig) + 0; + } + ++/* Copied from the Linux kernel definition in ++ * arch/x86/include/asm/processor.h ++ */ ++static inline void ++cpuid (uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) ++{ ++ asm volatile ("cpuid" ++ : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) ++ : "0" (*eax), "2" (*ecx) ++ : "memory"); ++} ++ + static uint32_t +-cpuid (uint32_t eax, char *sig) ++cpuid_leaf (uint32_t eax, char *sig) + { + uint32_t *sig32 = (uint32_t *) sig; + +- asm volatile ( +- "xchgl %%ebx,%1; xor %%ebx,%%ebx; cpuid; xchgl %%ebx,%1" +- : "=a" (eax), "+r" (sig32[0]), "=c" (sig32[1]), "=d" (sig32[2]) +- : "0" (eax)); +- sig[12] = 0; +- ++ cpuid (&eax, &sig32[0], &sig32[1], &sig32[2]); ++ sig[12] = 0; /* \0-terminate the string to make string comparison possible */ + return eax; + } + +@@ -87,7 +95,7 @@ cpu_sig (void) + */ + for (leaf = base + 0xff00; leaf >= base; leaf -= 0x100) { + memset (sig, 0, sizeof sig); +- cpuid (leaf, sig); ++ cpuid_leaf (leaf, sig); + if (known_signature (sig)) { + puts (sig); + break; +-- +2.32.0 + diff --git a/SPECS/virt-what.spec b/SPECS/virt-what.spec index e304000..3334358 100644 --- a/SPECS/virt-what.spec +++ b/SPECS/virt-what.spec @@ -1,6 +1,6 @@ Name: virt-what Version: 1.18 -Release: 4%{?dist} +Release: 4%{?dist}.1 Summary: Detect if we are running in a virtual machine License: GPLv2+ @@ -13,6 +13,12 @@ Patch0002: 0002-Remove-bashisms.patch Patch0003: 0003-As-xen-pv-guest-can-access-cpuid-from-Intel-CPUs-sta.patch Patch0004: 0004-Recognize-ppc64le-little-endian-virtualization-RHBZ-.patch +# Add Nutanix AHV support. +Patch0005: 0005-Fix-virt-what-cpuid-helper.patch +Patch0006: 0006-Add-support-for-Nutanix-Acropolis-Hypervisor-AHV-RHB.patch +Patch0007: 0007-helper-Fix-KVM-signature.patch +Patch0008: 0008-Simplify-and-fix-invocation-of-cpuid.patch + # This is provided by the build root, but we make it explicit # anyway in case this was dropped from the build root in future. BuildRequires: /usr/bin/pod2man @@ -108,6 +114,10 @@ fi %changelog +* Tue Jul 20 2021 Richard W.M. Jones - 1.18-4.1 +- Add Nutanix AHV support + resolves: rhbz#xxx + * Tue Oct 17 2017 Richard W.M. Jones - 1.18-4 - Add patch to recognize ppc64le virtualization. resolves: rhbz#1147876