1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-06 16:59:03 +03:00

basic: detect_vm_cpuid: fix hypervisor detection

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: d31b0033b7
This commit is contained in:
Mike Gilbert 2017-12-30 12:48:20 -05:00 committed by Lennart Poettering
parent ad552e587f
commit 8481e3e71e

View File

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