281364
From e732bc987f2f779e89f30193bf694e0456ab7ce0 Mon Sep 17 00:00:00 2001
281364
From: Boqun Feng <boqun.feng@gmail.com>
281364
Date: Tue, 23 Nov 2021 15:09:26 +0800
281364
Subject: [PATCH] virt: Fix the detection for Hyper-V VMs
281364
281364
Use product_version instead of product_name in DMI table and the string
281364
"Hyper-V" to avoid misdetection.
281364
281364
Fixes: #21468
281364
281364
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
281364
(cherry picked from commit 76eec0649936d9ae2f9087769f463feaf0cf5cb4)
281364
281364
Related: #2158307
281364
---
281364
 src/basic/virt.c | 5 +++--
281364
 1 file changed, 3 insertions(+), 2 deletions(-)
281364
281364
diff --git a/src/basic/virt.c b/src/basic/virt.c
281364
index cc95097101..f750a0463f 100644
281364
--- a/src/basic/virt.c
281364
+++ b/src/basic/virt.c
281364
@@ -143,7 +143,8 @@ static int detect_vm_dmi_vendor(void) {
281364
                 "/sys/class/dmi/id/product_name", /* Test this before sys_vendor to detect KVM over QEMU */
281364
                 "/sys/class/dmi/id/sys_vendor",
281364
                 "/sys/class/dmi/id/board_vendor",
281364
-                "/sys/class/dmi/id/bios_vendor"
281364
+                "/sys/class/dmi/id/bios_vendor",
281364
+                "/sys/class/dmi/id/product_version" /* For Hyper-V VMs test */
281364
         };
281364
 
281364
         static const struct {
281364
@@ -162,7 +163,7 @@ static int detect_vm_dmi_vendor(void) {
281364
                 { "Parallels",     VIRTUALIZATION_PARALLELS },
281364
                 /* https://wiki.freebsd.org/bhyve */
281364
                 { "BHYVE",         VIRTUALIZATION_BHYVE     },
281364
-                { "Microsoft",           VIRTUALIZATION_MICROSOFT },
281364
+                { "Hyper-V",             VIRTUALIZATION_MICROSOFT },
281364
         };
281364
         unsigned i;
281364
         int r;