When Hyper-V is configured to expose virtualization extensions to a
guest, report this in the domain XML by adding the vendor-appropriate
CPU feature flag:

- Intel hosts: <feature policy='require' name='vmx'/>
- AMD hosts: <feature policy='require' name='svm'/>

This requires adding ExposeVirtualizationExtensions and several other
fields introduced in Windows 10 to the Msvm_ProcessorSettingData WMI
class definition.

Signed-off-by: Jonathon Jongsma <[email protected]>
---
 src/hyperv/hyperv_driver.c            | 23 +++++++++++++++++++++++
 src/hyperv/hyperv_wmi_generator.input |  5 +++++
 2 files changed, 28 insertions(+)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 7cd83e7565..68b2e7fa67 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -44,6 +44,7 @@
 #include "snapshot_conf.h"
 #include "virfdstream.h"
 #include "virfile.h"
+#include "cpu_conf.h"
 
 #define VIR_FROM_THIS VIR_FROM_HYPERV
 
@@ -2766,6 +2767,28 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int 
flags)
     if (virDomainDefSetVcpus(def, processorSettingData->data->VirtualQuantity) 
< 0)
         return NULL;
 
+    if (processorSettingData->data->ExposeVirtualizationExtensions) {
+        g_autoptr(Win32_Processor) processors = NULL;
+        const char *cpuFeature = NULL;
+
+        if (hypervGetProcessorList(priv, NULL, &processors) < 0)
+            return NULL;
+
+        if (STREQ_NULLABLE(processors->data->Manufacturer, "GenuineIntel"))
+            cpuFeature = "vmx";
+        else if (STREQ_NULLABLE(processors->data->Manufacturer, 
"AuthenticAMD"))
+            cpuFeature = "svm";
+
+        if (cpuFeature) {
+            def->cpu = virCPUDefNew();
+            def->cpu->mode = VIR_CPU_MODE_HOST_PASSTHROUGH;
+            def->cpu->type = VIR_CPU_TYPE_GUEST;
+
+            if (virCPUDefAddFeature(def->cpu, cpuFeature, 
VIR_CPU_FEATURE_REQUIRE) < 0)
+                return NULL;
+        }
+    }
+
     def->os.type = VIR_DOMAIN_OSTYPE_HVM;
 
     /* Generation 2 VMs use UEFI firmware */
diff --git a/src/hyperv/hyperv_wmi_generator.input 
b/src/hyperv/hyperv_wmi_generator.input
index fccbe9009f..94685e4428 100644
--- a/src/hyperv/hyperv_wmi_generator.input
+++ b/src/hyperv/hyperv_wmi_generator.input
@@ -174,9 +174,14 @@ class Msvm_ProcessorSettingData
     string  AddressOnParent
     string  VirtualQuantityUnits
     boolean LimitCPUID
+    uint64  HwThreadsPerCore
     boolean LimitProcessorFeatures
     uint64  MaxProcessorsPerNumaNode
     uint64  MaxNumaNodesPerSocket
+    boolean EnableHostResourceProtection
+    string  CpuGroupId
+    boolean HideHypervisorPresent
+    boolean ExposeVirtualizationExtensions
 end
 
 
-- 
2.54.0

Reply via email to