[libvirt PATCH 00/10] Enable hyperv-passthrough

This series enables "hv-passthrough" in libvirt. See https://bugzilla.redhat.com/show_bug.cgi?id=1851249. Example usage in VM definition: <features> <hyperv mode='passthrough'/> </features> Tim Wiederhake (10): schema: Wrap hyperv element in choice and group schema: Add optional "mode" attribute to hyperv conf: domain: Define enum for HyperV mode virDomainFeaturesHyperVDefParse: Read attribute "mode" of element "hyperv" virDomainDefFormatFeatures: Write attribute "mode" of element "hyperv" docs: domain: Add documentation for "hyperv"'s new "mode" attribute conf: domain: Add hyperv passthrough mode schema: hyperv: Add mode "passthrough" tests: Add tests for hyperv-passthrough docs: domain: Add documentation for hyperv passthrough mode docs/formatdomain.rst | 13 +- docs/schemas/domaincommon.rng | 172 ++++++++++-------- src/conf/domain_conf.c | 23 ++- src/conf/domain_conf.h | 8 + src/qemu/qemu_command.c | 18 +- src/qemu/qemu_validate.c | 2 +- .../hyperv-passthrough.x86_64-6.1.0.args | 32 ++++ .../hyperv-passthrough.x86_64-latest.args | 32 ++++ tests/qemuxml2argvdata/hyperv-passthrough.xml | 27 +++ tests/qemuxml2argvtest.c | 2 + tests/qemuxml2xmloutdata/hyperv-off.xml | 2 +- .../qemuxml2xmloutdata/hyperv-passthrough.xml | 31 ++++ .../hyperv-stimer-direct.xml | 2 +- tests/qemuxml2xmloutdata/hyperv.xml | 2 +- tests/qemuxml2xmltest.c | 1 + 15 files changed, 277 insertions(+), 90 deletions(-) create mode 100644 tests/qemuxml2argvdata/hyperv-passthrough.x86_64-6.1.0.args create mode 100644 tests/qemuxml2argvdata/hyperv-passthrough.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/hyperv-passthrough.xml create mode 100644 tests/qemuxml2xmloutdata/hyperv-passthrough.xml -- 2.31.1

This does not change the schema, but will make upcoming changes easier. Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- docs/schemas/domaincommon.rng | 164 +++++++++++++++++----------------- 1 file changed, 84 insertions(+), 80 deletions(-) diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index f01b7a6470..3d57d417ca 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -7087,90 +7087,94 @@ <!-- Optional HyperV Enlightenment features --> <define name="hyperv"> <element name="hyperv"> - <interleave> - <optional> - <element name="relaxed"> - <ref name="featurestate"/> - </element> - </optional> - <optional> - <element name="vapic"> - <ref name="featurestate"/> - </element> - </optional> - <optional> - <element name="spinlocks"> - <ref name="featurestate"/> + <choice> + <group> + <interleave> <optional> - <attribute name="retries"> - <data type="unsignedInt"/> - </attribute> + <element name="relaxed"> + <ref name="featurestate"/> + </element> </optional> - </element> - </optional> - <optional> - <element name="vpindex"> - <ref name="featurestate"/> - </element> - </optional> - <optional> - <element name="runtime"> - <ref name="featurestate"/> - </element> - </optional> - <optional> - <element name="synic"> - <ref name="featurestate"/> - </element> - </optional> - <optional> - <element name="stimer"> - <ref name="stimer"/> - </element> - </optional> - <optional> - <element name="reset"> - <ref name="featurestate"/> - </element> - </optional> - <optional> - <element name="vendor_id"> - <ref name="featurestate"/> <optional> - <attribute name="value"> - <data type="string"> - <param name="pattern">[^,]{0,12}</param> - </data> - </attribute> + <element name="vapic"> + <ref name="featurestate"/> + </element> </optional> - </element> - </optional> - <optional> - <element name="frequencies"> - <ref name="featurestate"/> - </element> - </optional> - <optional> - <element name="reenlightenment"> - <ref name="featurestate"/> - </element> - </optional> - <optional> - <element name="tlbflush"> - <ref name="featurestate"/> - </element> - </optional> - <optional> - <element name="ipi"> - <ref name="featurestate"/> - </element> - </optional> - <optional> - <element name="evmcs"> - <ref name="featurestate"/> - </element> - </optional> - </interleave> + <optional> + <element name="spinlocks"> + <ref name="featurestate"/> + <optional> + <attribute name="retries"> + <data type="unsignedInt"/> + </attribute> + </optional> + </element> + </optional> + <optional> + <element name="vpindex"> + <ref name="featurestate"/> + </element> + </optional> + <optional> + <element name="runtime"> + <ref name="featurestate"/> + </element> + </optional> + <optional> + <element name="synic"> + <ref name="featurestate"/> + </element> + </optional> + <optional> + <element name="stimer"> + <ref name="stimer"/> + </element> + </optional> + <optional> + <element name="reset"> + <ref name="featurestate"/> + </element> + </optional> + <optional> + <element name="vendor_id"> + <ref name="featurestate"/> + <optional> + <attribute name="value"> + <data type="string"> + <param name="pattern">[^,]{0,12}</param> + </data> + </attribute> + </optional> + </element> + </optional> + <optional> + <element name="frequencies"> + <ref name="featurestate"/> + </element> + </optional> + <optional> + <element name="reenlightenment"> + <ref name="featurestate"/> + </element> + </optional> + <optional> + <element name="tlbflush"> + <ref name="featurestate"/> + </element> + </optional> + <optional> + <element name="ipi"> + <ref name="featurestate"/> + </element> + </optional> + <optional> + <element name="evmcs"> + <ref name="featurestate"/> + </element> + </optional> + </interleave> + </group> + </choice> </element> </define> -- 2.31.1

Allow for an optional attribute "mode", set to the string "custom". Later patches will introduce different modes. Omitting this attribute will default to "custom" for backwards compatibility. Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- docs/schemas/domaincommon.rng | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 3d57d417ca..14a4f528ab 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -7089,6 +7089,11 @@ <element name="hyperv"> <choice> <group> + <optional> + <attribute name="mode"> + <value>custom</value> + </attribute> + </optional> <interleave> <optional> <element name="relaxed"> -- 2.31.1

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/conf/domain_conf.c | 6 ++++++ src/conf/domain_conf.h | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f88405ab02..74d86a346a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -137,6 +137,12 @@ VIR_ENUM_IMPL(virDomainOS, "xenpvh", ); +VIR_ENUM_IMPL(virDomainHyperVMode, + VIR_DOMAIN_HYPERV_MODE_LAST, + "none", + "custom", +); + VIR_ENUM_IMPL(virDomainBoot, VIR_DOMAIN_BOOT_LAST, "fd", diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c4a8dcc2ea..169fc17039 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -155,6 +155,13 @@ typedef enum { } virDomainOSType; VIR_ENUM_DECL(virDomainOS); +typedef enum { + VIR_DOMAIN_HYPERV_MODE_NONE = 0, + VIR_DOMAIN_HYPERV_MODE_CUSTOM, + + VIR_DOMAIN_HYPERV_MODE_LAST +} virDomainHyperVMode; +VIR_ENUM_DECL(virDomainHyperVMode); struct _virDomainHostdevOrigStates { union { -- 2.31.1

Currently, this attribute may either have a value of "custom", or be absent (which defaults to "custom"), for backwards compatibility. Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/conf/domain_conf.c | 11 +++++++++-- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_validate.c | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 74d86a346a..0ea00955c5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -17453,7 +17453,14 @@ static int virDomainFeaturesHyperVDefParse(virDomainDef *def, xmlNodePtr node) { - def->features[VIR_DOMAIN_FEATURE_HYPERV] = VIR_TRISTATE_SWITCH_ON; + virDomainHyperVMode mode; + + if (virXMLPropEnumDefault(node, "mode", virDomainHyperVModeTypeFromString, + VIR_XML_PROP_NONZERO, &mode, + VIR_DOMAIN_HYPERV_MODE_CUSTOM) < 0) + return -1; + + def->features[VIR_DOMAIN_FEATURE_HYPERV] = mode; node = xmlFirstElementChild(node); while (node != NULL) { @@ -21703,7 +21710,7 @@ virDomainDefFeaturesCheckABIStability(virDomainDef *src, } /* hyperv */ - if (src->features[VIR_DOMAIN_FEATURE_HYPERV] == VIR_TRISTATE_SWITCH_ON) { + if (src->features[VIR_DOMAIN_FEATURE_HYPERV] != VIR_DOMAIN_HYPERV_MODE_NONE) { for (i = 0; i < VIR_DOMAIN_HYPERV_LAST; i++) { switch ((virDomainHyperv) i) { case VIR_DOMAIN_HYPERV_RELAXED: diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 7a185061d8..0d62a735f6 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6788,7 +6788,7 @@ qemuBuildCpuCommandLine(virCommand *cmd, VIR_TRISTATE_SWITCH_ON ? "on" : "off"); } - if (def->features[VIR_DOMAIN_FEATURE_HYPERV] == VIR_TRISTATE_SWITCH_ON) { + if (def->features[VIR_DOMAIN_FEATURE_HYPERV] != VIR_DOMAIN_HYPERV_MODE_NONE) { for (i = 0; i < VIR_DOMAIN_HYPERV_LAST; i++) { switch ((virDomainHyperv) i) { case VIR_DOMAIN_HYPERV_RELAXED: diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 397eea5ede..9dc8be02d4 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -273,7 +273,7 @@ qemuValidateDomainDefFeatures(const virDomainDef *def, break; case VIR_DOMAIN_FEATURE_HYPERV: - if (def->features[i] != VIR_TRISTATE_SWITCH_ABSENT && + if (def->features[i] != VIR_DOMAIN_HYPERV_MODE_NONE && !ARCH_IS_X86(def->os.arch) && !qemuDomainIsARMVirt(def)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Hyperv features are not supported for " -- 2.31.1

On Fri, Nov 26, 2021 at 03:34:56PM +0100, Tim Wiederhake wrote:
Currently, this attribute may either have a value of "custom", or be absent (which defaults to "custom"), for backwards compatibility.
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/conf/domain_conf.c | 11 +++++++++-- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_validate.c | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 74d86a346a..0ea00955c5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -17453,7 +17453,14 @@ static int virDomainFeaturesHyperVDefParse(virDomainDef *def, xmlNodePtr node) { - def->features[VIR_DOMAIN_FEATURE_HYPERV] = VIR_TRISTATE_SWITCH_ON; + virDomainHyperVMode mode; + + if (virXMLPropEnumDefault(node, "mode", virDomainHyperVModeTypeFromString, + VIR_XML_PROP_NONZERO, &mode, + VIR_DOMAIN_HYPERV_MODE_CUSTOM) < 0) + return -1; + + def->features[VIR_DOMAIN_FEATURE_HYPERV] = mode;
node = xmlFirstElementChild(node); while (node != NULL) { @@ -21703,7 +21710,7 @@ virDomainDefFeaturesCheckABIStability(virDomainDef *src, }
/* hyperv */ - if (src->features[VIR_DOMAIN_FEATURE_HYPERV] == VIR_TRISTATE_SWITCH_ON) { + if (src->features[VIR_DOMAIN_FEATURE_HYPERV] != VIR_DOMAIN_HYPERV_MODE_NONE) { for (i = 0; i < VIR_DOMAIN_HYPERV_LAST; i++) { switch ((virDomainHyperv) i) { case VIR_DOMAIN_HYPERV_RELAXED:
This change is not right. It is silently allowing the mode to be changed, which certainly affects ABI stability. It needs to validate src->features[VIR_DOMAIN_FEATURE_HYPERV] == dst->features[VIR_DOMAIN_FEATURE_HYPERV] Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/conf/domain_conf.c | 5 +++-- tests/qemuxml2xmloutdata/hyperv-off.xml | 2 +- tests/qemuxml2xmloutdata/hyperv-stimer-direct.xml | 2 +- tests/qemuxml2xmloutdata/hyperv.xml | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0ea00955c5..7d1edf14c3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27785,10 +27785,11 @@ virDomainDefFormatFeatures(virBuffer *buf, break; case VIR_DOMAIN_FEATURE_HYPERV: - if (def->features[i] != VIR_TRISTATE_SWITCH_ON) + if (def->features[i] == VIR_DOMAIN_HYPERV_MODE_NONE) break; - virBufferAddLit(&childBuf, "<hyperv>\n"); + virBufferAsprintf(&childBuf, "<hyperv mode='%s'>\n", + virDomainHyperVModeTypeToString(def->features[i])); virBufferAdjustIndent(&childBuf, 2); for (j = 0; j < VIR_DOMAIN_HYPERV_LAST; j++) { if (def->hyperv_features[j] == VIR_TRISTATE_SWITCH_ABSENT) diff --git a/tests/qemuxml2xmloutdata/hyperv-off.xml b/tests/qemuxml2xmloutdata/hyperv-off.xml index 20c7f653af..94288e2516 100644 --- a/tests/qemuxml2xmloutdata/hyperv-off.xml +++ b/tests/qemuxml2xmloutdata/hyperv-off.xml @@ -10,7 +10,7 @@ </os> <features> <acpi/> - <hyperv> + <hyperv mode='custom'> <relaxed state='off'/> <vapic state='off'/> <spinlocks state='off'/> diff --git a/tests/qemuxml2xmloutdata/hyperv-stimer-direct.xml b/tests/qemuxml2xmloutdata/hyperv-stimer-direct.xml index d49eb75b12..3710191d75 100644 --- a/tests/qemuxml2xmloutdata/hyperv-stimer-direct.xml +++ b/tests/qemuxml2xmloutdata/hyperv-stimer-direct.xml @@ -10,7 +10,7 @@ </os> <features> <acpi/> - <hyperv> + <hyperv mode='custom'> <vpindex state='on'/> <synic state='on'/> <stimer state='on'> diff --git a/tests/qemuxml2xmloutdata/hyperv.xml b/tests/qemuxml2xmloutdata/hyperv.xml index 00af005671..87f09257c7 100644 --- a/tests/qemuxml2xmloutdata/hyperv.xml +++ b/tests/qemuxml2xmloutdata/hyperv.xml @@ -10,7 +10,7 @@ </os> <features> <acpi/> - <hyperv> + <hyperv mode='custom'> <relaxed state='on'/> <vapic state='on'/> <spinlocks state='on' retries='12287'/> -- 2.31.1

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- docs/formatdomain.rst | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index eb8c973cf1..95ef2e0d05 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -1820,7 +1820,7 @@ Hypervisors may allow certain CPU / machine features to be toggled on/off. <apic/> <hap/> <privnet/> - <hyperv> + <hyperv mode='custom'> <relaxed state='on'/> <vapic state='on'/> <spinlocks state='on' retries='4096'/> @@ -1918,6 +1918,14 @@ are: evmcs Enable Enlightened VMCS on, off :since:`4.10.0 (QEMU 3.1)` =============== ====================================================================== ============================================ ======================================================= + :since:`Since 7.11.0` , the hypervisor can be configured further by setting + the ``mode`` attribute to one of the following values: + + ``custom`` + Set exactly the specified features. + + The ``mode`` attribute can be omitted and will default to ``custom``. + ``pvspinlock`` Notify the guest that the host supports paravirtual spinlocks for example by exposing the pvticketlocks mechanism. This feature can be explicitly disabled -- 2.31.1

On a Friday in 2021, Tim Wiederhake wrote:
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- docs/formatdomain.rst | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index eb8c973cf1..95ef2e0d05 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -1820,7 +1820,7 @@ Hypervisors may allow certain CPU / machine features to be toggled on/off. <apic/> <hap/> <privnet/> - <hyperv> + <hyperv mode='custom'> <relaxed state='on'/> <vapic state='on'/> <spinlocks state='on' retries='4096'/> @@ -1918,6 +1918,14 @@ are: evmcs Enable Enlightened VMCS on, off :since:`4.10.0 (QEMU 3.1)` =============== ====================================================================== ============================================ =======================================================
+ :since:`Since 7.11.0` , the hypervisor can be configured further by setting
The next libvirt release will be 8.0.0 mid-January. https://libvirt.org/downloads.html#numbering Jano

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- src/conf/domain_conf.c | 1 + src/conf/domain_conf.h | 1 + src/qemu/qemu_command.c | 16 ++++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7d1edf14c3..6c1d8e6353 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -141,6 +141,7 @@ VIR_ENUM_IMPL(virDomainHyperVMode, VIR_DOMAIN_HYPERV_MODE_LAST, "none", "custom", + "passthrough", ); VIR_ENUM_IMPL(virDomainBoot, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 169fc17039..abf7b37dc8 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -158,6 +158,7 @@ VIR_ENUM_DECL(virDomainOS); typedef enum { VIR_DOMAIN_HYPERV_MODE_NONE = 0, VIR_DOMAIN_HYPERV_MODE_CUSTOM, + VIR_DOMAIN_HYPERV_MODE_PASSTHROUGH, VIR_DOMAIN_HYPERV_MODE_LAST } virDomainHyperVMode; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 0d62a735f6..adbac46936 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6789,6 +6789,22 @@ qemuBuildCpuCommandLine(virCommand *cmd, } if (def->features[VIR_DOMAIN_FEATURE_HYPERV] != VIR_DOMAIN_HYPERV_MODE_NONE) { + switch ((virDomainHyperVMode) def->features[VIR_DOMAIN_FEATURE_HYPERV]) { + case VIR_DOMAIN_HYPERV_MODE_CUSTOM: + break; + + case VIR_DOMAIN_HYPERV_MODE_PASSTHROUGH: + virBufferAsprintf(&buf, ",hv-%s=on", "passthrough"); + break; + + case VIR_DOMAIN_HYPERV_MODE_NONE: + case VIR_DOMAIN_HYPERV_MODE_LAST: + default: + virReportEnumRangeError(virDomainHyperVMode, + def->features[VIR_DOMAIN_FEATURE_HYPERV]); + return -1; + } + for (i = 0; i < VIR_DOMAIN_HYPERV_LAST; i++) { switch ((virDomainHyperv) i) { case VIR_DOMAIN_HYPERV_RELAXED: -- 2.31.1

This mode will enable all enlightenments known to the hypervisor. See https://bugzilla.redhat.com/show_bug.cgi?id=1851249 Example: <features> <hyperv mode='passthrough'/> ... </features> Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- docs/schemas/domaincommon.rng | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 14a4f528ab..12e657269d 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -7088,6 +7088,9 @@ <define name="hyperv"> <element name="hyperv"> <choice> + <attribute name="mode"> + <value>passthrough</value> + </attribute> <group> <optional> <attribute name="mode"> -- 2.31.1

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- .../hyperv-passthrough.x86_64-6.1.0.args | 32 +++++++++++++++++++ .../hyperv-passthrough.x86_64-latest.args | 32 +++++++++++++++++++ tests/qemuxml2argvdata/hyperv-passthrough.xml | 27 ++++++++++++++++ tests/qemuxml2argvtest.c | 2 ++ .../qemuxml2xmloutdata/hyperv-passthrough.xml | 31 ++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 6 files changed, 125 insertions(+) create mode 100644 tests/qemuxml2argvdata/hyperv-passthrough.x86_64-6.1.0.args create mode 100644 tests/qemuxml2argvdata/hyperv-passthrough.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/hyperv-passthrough.xml create mode 100644 tests/qemuxml2xmloutdata/hyperv-passthrough.xml diff --git a/tests/qemuxml2argvdata/hyperv-passthrough.x86_64-6.1.0.args b/tests/qemuxml2argvdata/hyperv-passthrough.x86_64-6.1.0.args new file mode 100644 index 0000000000..87755b5042 --- /dev/null +++ b/tests/qemuxml2argvdata/hyperv-passthrough.x86_64-6.1.0.args @@ -0,0 +1,32 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-i386 \ +-name guest=QEMUGuest1,debug-threads=on \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc-i440fx-6.1,usb=off,dump-guest-core=off,memory-backend=pc.ram \ +-accel tcg \ +-cpu qemu64,hv-passthrough=on \ +-m 214 \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}' \ +-overcommit mem-lock=off \ +-smp 6,sockets=6,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-boot strict=on \ +-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/hyperv-passthrough.x86_64-latest.args b/tests/qemuxml2argvdata/hyperv-passthrough.x86_64-latest.args new file mode 100644 index 0000000000..aab8c09d71 --- /dev/null +++ b/tests/qemuxml2argvdata/hyperv-passthrough.x86_64-latest.args @@ -0,0 +1,32 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-i386 \ +-name guest=QEMUGuest1,debug-threads=on \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=off,dump-guest-core=off,memory-backend=pc.ram \ +-accel tcg \ +-cpu qemu64,hv-passthrough=on \ +-m 214 \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}' \ +-overcommit mem-lock=off \ +-smp 6,sockets=6,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-boot strict=on \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/hyperv-passthrough.xml b/tests/qemuxml2argvdata/hyperv-passthrough.xml new file mode 100644 index 0000000000..9d6a872a41 --- /dev/null +++ b/tests/qemuxml2argvdata/hyperv-passthrough.xml @@ -0,0 +1,27 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219100</memory> + <currentMemory unit='KiB'>219100</currentMemory> + <vcpu placement='static'>6</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='network'/> + </os> + <features> + <acpi/> + <hyperv mode='passthrough'/> + </features> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-i386</emulator> + <controller type='usb' index='0'/> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <memballoon model='none'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index b3fa676af7..94b0025281 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1217,6 +1217,8 @@ mymain(void) DO_TEST_CAPS_LATEST("hyperv-off"); DO_TEST_CAPS_VER("hyperv-panic", "4.0.0"); DO_TEST_CAPS_LATEST("hyperv-panic"); + DO_TEST_CAPS_VER("hyperv-passthrough", "6.1.0"); + DO_TEST_CAPS_LATEST("hyperv-passthrough"); DO_TEST_CAPS_LATEST("hyperv-stimer-direct"); DO_TEST_NOCAPS("kvm-features"); diff --git a/tests/qemuxml2xmloutdata/hyperv-passthrough.xml b/tests/qemuxml2xmloutdata/hyperv-passthrough.xml new file mode 100644 index 0000000000..f833860997 --- /dev/null +++ b/tests/qemuxml2xmloutdata/hyperv-passthrough.xml @@ -0,0 +1,31 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219100</memory> + <currentMemory unit='KiB'>219100</currentMemory> + <vcpu placement='static'>6</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='network'/> + </os> + <features> + <acpi/> + <hyperv mode='passthrough'> + </hyperv> + </features> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-i386</emulator> + <controller type='usb' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <audio id='1' type='none'/> + <memballoon model='none'/> + </devices> +</domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index b535cda187..b229fbb14f 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -260,6 +260,7 @@ mymain(void) DO_TEST_NOCAPS("hyperv"); DO_TEST_NOCAPS("hyperv-off"); DO_TEST_NOCAPS("hyperv-panic"); + DO_TEST_NOCAPS("hyperv-passthrough"); DO_TEST_NOCAPS("hyperv-stimer-direct"); DO_TEST_NOCAPS("kvm-features"); -- 2.31.1

Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- docs/formatdomain.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 95ef2e0d05..ec944f89db 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -1924,6 +1924,9 @@ are: ``custom`` Set exactly the specified features. + ``passthrough`` + Enable all features currently supported by the hypervisor. + The ``mode`` attribute can be omitted and will default to ``custom``. ``pvspinlock`` -- 2.31.1

On Fri, Nov 26, 2021 at 03:35:02PM +0100, Tim Wiederhake wrote:
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> --- docs/formatdomain.rst | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 95ef2e0d05..ec944f89db 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -1924,6 +1924,9 @@ are: ``custom`` Set exactly the specified features.
+ ``passthrough`` + Enable all features currently supported by the hypervisor.
This needs to note that this is not migration safe, similar to how 'host-passthrough' CPU is not migration safe. If you don't migrate to a homogeneous host, your VM is likely to break without warning. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On a Friday in 2021, Tim Wiederhake wrote:
This series enables "hv-passthrough" in libvirt. See https://bugzilla.redhat.com/show_bug.cgi?id=1851249.
Example usage in VM definition: <features> <hyperv mode='passthrough'/> </features>
Tim Wiederhake (10): schema: Wrap hyperv element in choice and group schema: Add optional "mode" attribute to hyperv conf: domain: Define enum for HyperV mode virDomainFeaturesHyperVDefParse: Read attribute "mode" of element "hyperv" virDomainDefFormatFeatures: Write attribute "mode" of element "hyperv" docs: domain: Add documentation for "hyperv"'s new "mode" attribute conf: domain: Add hyperv passthrough mode schema: hyperv: Add mode "passthrough" tests: Add tests for hyperv-passthrough docs: domain: Add documentation for hyperv passthrough mode
docs/formatdomain.rst | 13 +- docs/schemas/domaincommon.rng | 172 ++++++++++-------- src/conf/domain_conf.c | 23 ++- src/conf/domain_conf.h | 8 + src/qemu/qemu_command.c | 18 +- src/qemu/qemu_validate.c | 2 +- .../hyperv-passthrough.x86_64-6.1.0.args | 32 ++++ .../hyperv-passthrough.x86_64-latest.args | 32 ++++ tests/qemuxml2argvdata/hyperv-passthrough.xml | 27 +++ tests/qemuxml2argvtest.c | 2 + tests/qemuxml2xmloutdata/hyperv-off.xml | 2 +- .../qemuxml2xmloutdata/hyperv-passthrough.xml | 31 ++++ .../hyperv-stimer-direct.xml | 2 +- tests/qemuxml2xmloutdata/hyperv.xml | 2 +- tests/qemuxml2xmltest.c | 1 + 15 files changed, 277 insertions(+), 90 deletions(-) create mode 100644 tests/qemuxml2argvdata/hyperv-passthrough.x86_64-6.1.0.args create mode 100644 tests/qemuxml2argvdata/hyperv-passthrough.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/hyperv-passthrough.xml create mode 100644 tests/qemuxml2xmloutdata/hyperv-passthrough.xml
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (3)
-
Daniel P. Berrangé
-
Ján Tomko
-
Tim Wiederhake