From 42685451ed0f1c422395a05820ee4328c352808f Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Tue, 3 Nov 2015 14:49:38 -0600 Subject: detect-virt: detect in best-heuristic order afaict, this will fix a regression caused by commit 75f86906c5. Where we used to report "kvm" before that patch, without this patch, we would only report "qemu". The reason is because cpuid detection must come before dmi detection. Also, both can safely come before other xen heuristics. Untested. --- src/basic/virt.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/basic/virt.c b/src/basic/virt.c index fb181e5b55..1e10fc755f 100644 --- a/src/basic/virt.c +++ b/src/basic/virt.c @@ -267,12 +267,7 @@ int detect_vm(void) { if (cached_found >= 0) return cached_found; - /* Try xen capabilities file first, if not found try - * high-level hypervisor sysfs file: - * - * https://bugs.freedesktop.org/show_bug.cgi?id=77271 */ - - r = detect_vm_xen(); + r = detect_vm_cpuid(); if (r < 0) return r; if (r != VIRTUALIZATION_NONE) @@ -284,7 +279,14 @@ int detect_vm(void) { if (r != VIRTUALIZATION_NONE) goto finish; - r = detect_vm_cpuid(); + /* x86 xen will most likely be detected by cpuid. If not (most likely + * because we're not an x86 guest), then we should try the xen capabilities + * file next. If that's not found, then we check for the high-level + * hypervisor sysfs file: + * + * https://bugs.freedesktop.org/show_bug.cgi?id=77271 */ + + r = detect_vm_xen(); if (r < 0) return r; if (r != VIRTUALIZATION_NONE) -- cgit v1.2.3-54-g00ecf From 2ef8a4c4399dcb7b6fcaecd41f27377b584e9a4b Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Tue, 3 Nov 2015 12:10:13 -0600 Subject: arm/aarch64: detect-virt: check dmi ARM/AArch64 guests now have SMBIOS tables populated (when boot with a late enough QEMU and a late enough AAVMF is used as the bootloader). Furthermore, when booting ARM/AArch64 guests with ACPI, the DT detection obviously no longer works, so we need dmi detection. --- src/basic/virt.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/basic/virt.c b/src/basic/virt.c index 1e10fc755f..42c54735d8 100644 --- a/src/basic/virt.c +++ b/src/basic/virt.c @@ -34,7 +34,7 @@ static int detect_vm_cpuid(void) { - /* Both CPUID and DMI are x86 specific interfaces... */ + /* CPUID is an x86 specific interface. */ #if defined(__i386__) || defined(__x86_64__) static const struct { @@ -144,9 +144,7 @@ static int detect_vm_device_tree(void) { } static int detect_vm_dmi(void) { - - /* Both CPUID and DMI are x86 specific interfaces... */ -#if defined(__i386__) || defined(__x86_64__) +#if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) static const char *const dmi_vendors[] = { "/sys/class/dmi/id/sys_vendor", -- cgit v1.2.3-54-g00ecf From 3728dcde4542b7b2792d9ef0baeb742d82983b03 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Tue, 3 Nov 2015 13:31:03 -0600 Subject: detect-virt: dmi: look for KVM Some guests (ARM, AArch64, x86-RHEL) have 'KVM' in the product name. Look for that first in order to more precisely report "kvm" when detecting a QEMU/KVM guest. Without this patch we report "qemu", even if KVM acceleration is in use on ARM/AArch64 guests. I've only tested a backported version of this and the previous patch on an AArch64 guest (which worked). Of course it would be nice to get regression testing on all guest types that depend on dmi done. --- src/basic/virt.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/basic/virt.c b/src/basic/virt.c index 42c54735d8..a211ea1f86 100644 --- a/src/basic/virt.c +++ b/src/basic/virt.c @@ -147,6 +147,7 @@ static int detect_vm_dmi(void) { #if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) static const char *const dmi_vendors[] = { + "/sys/class/dmi/id/product_name", /* Test this before sys_vendor to detect KVM over QEMU */ "/sys/class/dmi/id/sys_vendor", "/sys/class/dmi/id/board_vendor", "/sys/class/dmi/id/bios_vendor" @@ -156,6 +157,7 @@ static int detect_vm_dmi(void) { const char *vendor; int id; } dmi_vendor_table[] = { + { "KVM", VIRTUALIZATION_KVM }, { "QEMU", VIRTUALIZATION_QEMU }, /* http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1009458 */ { "VMware", VIRTUALIZATION_VMWARE }, -- cgit v1.2.3-54-g00ecf