virt: Fix the detection for Hyper-V VMs

Use product_version instead of product_name in DMI table and the string
"Hyper-V" to avoid misdetection.

Fixes: #21468

Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
This commit is contained in:
Boqun Feng
2021-11-23 15:09:26 +08:00
committed by Lennart Poettering
parent 244cab4a65
commit 76eec06499

View File

@@ -146,7 +146,8 @@ static int detect_vm_dmi_vendor(void) {
"/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"
"/sys/class/dmi/id/bios_vendor",
"/sys/class/dmi/id/product_version" /* For Hyper-V VMs test */
};
static const struct {
@@ -165,7 +166,7 @@ static int detect_vm_dmi_vendor(void) {
{ "Parallels", VIRTUALIZATION_PARALLELS },
/* https://wiki.freebsd.org/bhyve */
{ "BHYVE", VIRTUALIZATION_BHYVE },
{ "Microsoft", VIRTUALIZATION_MICROSOFT },
{ "Hyper-V", VIRTUALIZATION_MICROSOFT },
};
int r;