[PATCH 0/3] hyperv: Add support for detecting nested virtualization capability
In order to support migrating hyperv vms to kubevirt, MTV needs to detect whether the vm has a nested virtualization capabilities. This series adds basic support for identifying this scenario by exposing cpu features on the libvirt domain xml. https://redhat.atlassian.net/browse/RHEL-147662 Jonathon Jongsma (3): hyperv: fix error handling of hypervGetProcessorsByName() hyperv: Rename hypervGetProcessorsByName() to hypervGetProcessorList() hyperv: report nested virtualization setting in domain XML src/hyperv/hyperv_driver.c | 48 +++++++++++++++++++++------ src/hyperv/hyperv_wmi_generator.input | 5 +++ 2 files changed, 43 insertions(+), 10 deletions(-) -- 2.54.0
We were checking the output pointer for NULL rather than checking the dereferenced value for NULL. So the case where no processors were returned would not have returned an error as expected. --- src/hyperv/hyperv_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index f80433693e..1031076a28 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -69,7 +69,7 @@ hypervGetProcessorsByName(hypervPrivate *priv, const char *name, if (hypervGetWmiClass(Win32_Processor, processorList) < 0) return -1; - if (!processorList) { + if (!*processorList) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not look up processor(s) on '%1$s'"), name); -- 2.54.0
Make the 'name' parameter optional and return all processors from the host if name is not specified. --- src/hyperv/hyperv_driver.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 1031076a28..7cd83e7565 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -56,15 +56,20 @@ VIR_LOG_INIT("hyperv.hyperv_driver"); */ static int -hypervGetProcessorsByName(hypervPrivate *priv, const char *name, - Win32_Processor **processorList) +hypervGetProcessorList(hypervPrivate *priv, const char *computer_name, + Win32_Processor **processorList) { g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER; - virBufferEscapeSQL(&query, - "ASSOCIATORS OF {Win32_ComputerSystem.Name='%s'} " - "WHERE AssocClass = Win32_ComputerSystemProcessor " - "ResultClass = Win32_Processor", - name); + if (computer_name) { + virBufferEscapeSQL(&query, + "ASSOCIATORS OF {Win32_ComputerSystem.Name='%s'} " + "WHERE AssocClass = Win32_ComputerSystemProcessor " + "ResultClass = Win32_Processor", + computer_name); + + } else { + virBufferAddLit(&query, WIN32_PROCESSOR_WQL_SELECT); + } if (hypervGetWmiClass(Win32_Processor, processorList) < 0) return -1; @@ -72,7 +77,7 @@ hypervGetProcessorsByName(hypervPrivate *priv, const char *name, if (!*processorList) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not look up processor(s) on '%1$s'"), - name); + computer_name); return -1; } @@ -1933,7 +1938,7 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) if (hypervGetPhysicalSystemList(priv, &computerSystem) < 0) return -1; - if (hypervGetProcessorsByName(priv, computerSystem->data->Name, &processorList) < 0) { + if (hypervGetProcessorList(priv, computerSystem->data->Name, &processorList) < 0) { return -1; } -- 2.54.0
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 <jjongsma@redhat.com> --- 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
On 6/2/26 18:44, Jonathon Jongsma via Devel wrote:
In order to support migrating hyperv vms to kubevirt, MTV needs to detect whether the vm has a nested virtualization capabilities. This series adds basic support for identifying this scenario by exposing cpu features on the libvirt domain xml.
https://redhat.atlassian.net/browse/RHEL-147662
Jonathon Jongsma (3): hyperv: fix error handling of hypervGetProcessorsByName() hyperv: Rename hypervGetProcessorsByName() to hypervGetProcessorList() hyperv: report nested virtualization setting in domain XML
src/hyperv/hyperv_driver.c | 48 +++++++++++++++++++++------ src/hyperv/hyperv_wmi_generator.input | 5 +++ 2 files changed, 43 insertions(+), 10 deletions(-)
Reviewed-by: Michal Privoznik <mprivozn@redhat.com> BUT, please add your sign off to all patches and fix your git config to drop "via Devel" suffix to your name (though since you will be pushing patches yourself it's not that problematic). This is what I have in ~/.gitconfig (among other things): [format] thread = yes pretty = fuller forceInBodyFrom = true from = "Michal Privoznik <mprivozn@redhat.com>" Michal
participants (2)
-
Jonathon Jongsma -
Michal Prívozník