chiark / gitweb /
basic: detect_vm_cpuid: fix hypervisor detection
authorMike Gilbert <floppym@gentoo.org>
Sat, 30 Dec 2017 17:48:20 +0000 (12:48 -0500)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:49:46 +0000 (07:49 +0200)
The __get_cpuid() function only calls __cpuid() if __get_cpuid_max()
returns a value that is less than or equal to the leaf value.

In QEMU/KVM, I found that the special hypervisor leaf value (0x40000000U)
is always larger than the value retured by __get_cpuid_max().

Avoid this problem by calling the __cpuid() macro directly once we have
checked the hypervisor bit from leaf 1.

Fixes: d31b0033b7743393562a2e9d3c1e74afea981c13
src/basic/virt.c

index 15dc860ad830a1ac97d8614ef5a760939ec2959b..21e11b6988b06d9869e6d805177b05800196b24e 100644 (file)
@@ -79,8 +79,7 @@ static int detect_vm_cpuid(void) {
                 unsigned j;
 
                 /* There is a hypervisor, see what it is */
-                if (__get_cpuid(0x40000000U, &eax, &ebx, &ecx, &edx) == 0)
-                        return VIRTUALIZATION_NONE;
+                __cpuid(0x40000000U, eax, ebx, ecx, edx);
 
                 sig.sig32[0] = ebx;
                 sig.sig32[1] = ecx;