[PATCH v3 0/2] Implement paeg-per-vq to virtio devices

Diff from v2: - Remove the code of qemu capabilities since the least supported QEMU version is over the version introducing paeg-per-vq. - Rebase to latest upstream v2: https://listman.redhat.com/archives/libvir-list/2021-October/msg00489.html Han Han (2): conf: Add page_per_vq for driver element qemu: Add support for virtio device option page-per-vq docs/formatdomain.rst | 9 +++++++ docs/schemas/domaincommon.rng | 5 ++++ src/conf/domain_conf.c | 16 ++++++++++++ src/conf/domain_conf.h | 1 + src/conf/domain_validate.c | 6 +++++ src/qemu/qemu_command.c | 1 + src/qemu/qemu_hotplug.c | 3 ++- src/qemu/qemu_validate.c | 1 + .../virtio-options.x86_64-latest.args | 24 ++++++++--------- tests/qemuxml2argvdata/virtio-options.xml | 26 +++++++++---------- 10 files changed, 66 insertions(+), 26 deletions(-) -- 2.31.1

Signed-off-by: Han Han <hhan@redhat.com> Signed-off-by: Gavi Teitz <gavi@nvidia.com> --- docs/formatdomain.rst | 9 +++++++++ docs/schemas/domaincommon.rng | 5 +++++ src/conf/domain_conf.c | 16 ++++++++++++++++ src/conf/domain_conf.h | 1 + src/conf/domain_validate.c | 6 ++++++ 5 files changed, 37 insertions(+) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 80aaf4b033..9bf59936e5 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -3577,6 +3577,15 @@ virtqueues are actually used depends on the feature negotiation between QEMU, vhost backends and guest drivers. Possible values are ``on`` or ``off``. :since:`Since 6.3.0 (QEMU and KVM only)` +This optional attribute ``page_per_vq`` controls the layout of the notification +capabilities exposed to the guest. When enabled, each virtio queue will have a +dedicated page on the device BAR exposed to the guest. It is recommended to be +used when vDPA is enabled on the hypervisor, as it enables mapping the +notification area to the physical device, which is only supported in page +granularity. The default is determined by QEMU. :since:`Since 7.8.0 (QEMU 2.8)` +Note: In general you should leave this option alone, unless you are very certain +you know what you are doing. + :anchor:`<a id="elementsVirtioTransitional"/>` Virtio transitional devices diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 6f33d1e774..26990c4d6d 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -6825,6 +6825,11 @@ <ref name="virOnOff"/> </attribute> </optional> + <optional> + <attribute name="page_per_vq"> + <ref name="virOnOff"/> + </attribute> + </optional> </define> <define name="usbmaster"> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 818c177e72..6fcf86ba58 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1636,6 +1636,10 @@ virDomainVirtioOptionsParseXML(xmlNodePtr driver, &(*virtio)->packed) < 0) return -1; + if (virXMLPropTristateSwitch(driver, "page_per_vq", VIR_XML_PROP_NONE, + &(*virtio)->page_per_vq) < 0) + return -1; + return 0; } @@ -6321,6 +6325,10 @@ virDomainVirtioOptionsFormat(virBuffer *buf, virBufferAsprintf(buf, " packed='%s'", virTristateSwitchTypeToString(virtio->packed)); } + if (virtio->page_per_vq != VIR_TRISTATE_SWITCH_ABSENT) { + virBufferAsprintf(buf, " page_per_vq='%s'", + virTristateSwitchTypeToString(virtio->page_per_vq)); + } } @@ -20816,6 +20824,14 @@ virDomainVirtioOptionsCheckABIStability(virDomainVirtioOptions *src, virTristateSwitchTypeToString(src->packed)); return false; } + if (src->page_per_vq != dst->page_per_vq) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target device page_per_vq option '%s' does not " + "match source '%s'"), + virTristateSwitchTypeToString(dst->page_per_vq), + virTristateSwitchTypeToString(src->page_per_vq)); + return false; + } return true; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index e9a9298d86..1ac802feca 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2740,6 +2740,7 @@ struct _virDomainVirtioOptions { virTristateSwitch iommu; virTristateSwitch ats; virTristateSwitch packed; + virTristateSwitch page_per_vq; }; diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index f023d22f23..80401cf8c7 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -135,6 +135,12 @@ virDomainCheckVirtioOptionsAreAbsent(virDomainVirtioOptions *virtio) "for virtio devices")); return -1; } + + if (virtio->page_per_vq != VIR_TRISTATE_SWITCH_ABSENT) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("page_per_vq option is only supported for virtio devices")); + return -1; + } return 0; } -- 2.31.1

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1925363 Signed-off-by: Han Han <hhan@redhat.com> --- src/qemu/qemu_command.c | 1 + src/qemu/qemu_hotplug.c | 3 ++- src/qemu/qemu_validate.c | 1 + .../virtio-options.x86_64-latest.args | 24 ++++++++--------- tests/qemuxml2argvdata/virtio-options.xml | 26 +++++++++---------- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 3b2f88bcb9..dba877a740 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1122,6 +1122,7 @@ qemuBuildVirtioDevProps(virDomainDeviceType devtype, "T:iommu_platform", virtioOptions->iommu, "T:ats", virtioOptions->ats, "T:packed", virtioOptions->packed, + "T:page-per-vq", virtioOptions->page_per_vq, NULL) < 0) return NULL; } diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index af49e58f8e..a7b432b6f5 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3797,7 +3797,8 @@ qemuDomainChangeNet(virQEMUDriver *driver, (olddev->virtio && newdev->virtio && (olddev->virtio->iommu != newdev->virtio->iommu || olddev->virtio->ats != newdev->virtio->ats || - olddev->virtio->packed != newdev->virtio->packed))) { + olddev->virtio->packed != newdev->virtio->packed || + olddev->virtio->page_per_vq != newdev->virtio->page_per_vq))) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("cannot modify virtio network device driver options")); goto cleanup; diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 75dc9edb7d..4a82b512d1 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -1592,6 +1592,7 @@ qemuValidateDomainVirtioOptions(const virDomainVirtioOptions *virtio, "QEMU binary")); return -1; } + return 0; } diff --git a/tests/qemuxml2argvdata/virtio-options.x86_64-latest.args b/tests/qemuxml2argvdata/virtio-options.x86_64-latest.args index d6dcbdd90f..6a55134ee8 100644 --- a/tests/qemuxml2argvdata/virtio-options.x86_64-latest.args +++ b/tests/qemuxml2argvdata/virtio-options.x86_64-latest.args @@ -27,26 +27,26 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ -no-acpi \ -boot strict=on \ -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ --device virtio-scsi-pci,iommu_platform=on,ats=on,packed=on,id=scsi0,bus=pci.0,addr=0x8 \ --device virtio-serial-pci,iommu_platform=on,ats=on,packed=on,id=virtio-serial0,bus=pci.0,addr=0x9 \ +-device virtio-scsi-pci,iommu_platform=on,ats=on,packed=on,page-per-vq=on,id=scsi0,bus=pci.0,addr=0x8 \ +-device virtio-serial-pci,iommu_platform=on,ats=on,packed=on,page-per-vq=on,id=virtio-serial0,bus=pci.0,addr=0x9 \ -blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/img1","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw","file":"libvirt-1-storage"}' \ --device virtio-blk-pci,iommu_platform=on,ats=on,packed=on,bus=pci.0,addr=0xa,drive=libvirt-1-format,id=virtio-disk0,bootindex=1 \ +-device virtio-blk-pci,iommu_platform=on,ats=on,packed=on,page-per-vq=on,bus=pci.0,addr=0xa,drive=libvirt-1-format,id=virtio-disk0,bootindex=1 \ -fsdev local,security_model=passthrough,id=fsdev-fs0,path=/export/fs1 \ --device virtio-9p-pci,iommu_platform=on,ats=on,packed=on,id=fs0,fsdev=fsdev-fs0,mount_tag=fs1,bus=pci.0,addr=0x3 \ +-device virtio-9p-pci,iommu_platform=on,ats=on,packed=on,page-per-vq=on,id=fs0,fsdev=fsdev-fs0,mount_tag=fs1,bus=pci.0,addr=0x3 \ -fsdev local,security_model=mapped,writeout=immediate,id=fsdev-fs1,path=/export/fs2 \ --device virtio-9p-pci,iommu_platform=on,ats=on,packed=on,id=fs1,fsdev=fsdev-fs1,mount_tag=fs2,bus=pci.0,addr=0x4 \ +-device virtio-9p-pci,iommu_platform=on,ats=on,packed=on,page-per-vq=on,id=fs1,fsdev=fsdev-fs1,mount_tag=fs2,bus=pci.0,addr=0x4 \ -netdev user,id=hostnet0 \ --device virtio-net-pci,iommu_platform=on,ats=on,packed=on,netdev=hostnet0,id=net0,mac=52:54:56:58:5a:5c,bus=pci.0,addr=0x6 \ --device virtio-mouse-pci,iommu_platform=on,ats=on,packed=on,id=input0,bus=pci.0,addr=0xe \ --device virtio-keyboard-pci,iommu_platform=on,ats=on,packed=on,id=input1,bus=pci.0,addr=0x10 \ --device virtio-tablet-pci,iommu_platform=on,ats=on,packed=on,id=input2,bus=pci.0,addr=0x11 \ --device virtio-input-host-pci,iommu_platform=on,ats=on,packed=on,id=input3,evdev=/dev/input/event1234,bus=pci.0,addr=0x12 \ +-device virtio-net-pci,iommu_platform=on,ats=on,packed=on,page-per-vq=on,netdev=hostnet0,id=net0,mac=52:54:56:58:5a:5c,bus=pci.0,addr=0x6 \ +-device virtio-mouse-pci,iommu_platform=on,ats=on,packed=on,page-per-vq=on,id=input0,bus=pci.0,addr=0xe \ +-device virtio-keyboard-pci,iommu_platform=on,ats=on,packed=on,page-per-vq=on,id=input1,bus=pci.0,addr=0x10 \ +-device virtio-tablet-pci,iommu_platform=on,ats=on,packed=on,page-per-vq=on,id=input2,bus=pci.0,addr=0x11 \ +-device virtio-input-host-pci,iommu_platform=on,ats=on,packed=on,page-per-vq=on,id=input3,evdev=/dev/input/event1234,bus=pci.0,addr=0x12 \ -audiodev id=audio1,driver=none \ -chardev socket,id=chr-vu-video0,fd=1729 \ -device vhost-user-vga,id=video0,max_outputs=1,chardev=chr-vu-video0,bus=pci.0,addr=0x2 \ --device virtio-balloon-pci,iommu_platform=on,ats=on,packed=on,id=balloon0,bus=pci.0,addr=0xc \ +-device virtio-balloon-pci,iommu_platform=on,ats=on,packed=on,page-per-vq=on,id=balloon0,bus=pci.0,addr=0xc \ -object '{"qom-type":"rng-random","id":"objrng0","filename":"/dev/random"}' \ --device virtio-rng-pci,iommu_platform=on,ats=on,packed=on,rng=objrng0,id=rng0,bus=pci.0,addr=0xd \ +-device virtio-rng-pci,iommu_platform=on,ats=on,packed=on,page-per-vq=on,rng=objrng0,id=rng0,bus=pci.0,addr=0xd \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ -msg timestamp=on diff --git a/tests/qemuxml2argvdata/virtio-options.xml b/tests/qemuxml2argvdata/virtio-options.xml index 9c9b80d5c4..59e293d8e9 100644 --- a/tests/qemuxml2argvdata/virtio-options.xml +++ b/tests/qemuxml2argvdata/virtio-options.xml @@ -18,7 +18,7 @@ <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> <disk type='file' device='disk'> - <driver name='qemu' type='raw' iommu='on' ats='on' packed='on'/> + <driver name='qemu' type='raw' iommu='on' ats='on' packed='on' page_per_vq='on'/> <source file='/var/lib/libvirt/images/img1'/> <target dev='vda' bus='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/> @@ -30,22 +30,22 @@ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> </controller> <controller type='scsi' index='0' model='virtio-scsi'> - <driver iommu='on' ats='on' packed='on'/> + <driver iommu='on' ats='on' packed='on' page_per_vq='on'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/> </controller> <controller type='pci' index='0' model='pci-root'/> <controller type='virtio-serial' index='0'> - <driver iommu='on' ats='on' packed='on'/> + <driver iommu='on' ats='on' packed='on' page_per_vq='on'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/> </controller> <filesystem type='mount' accessmode='passthrough'> - <driver iommu='on' ats='on' packed='on'/> + <driver iommu='on' ats='on' packed='on' page_per_vq='on'/> <source dir='/export/fs1'/> <target dir='fs1'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </filesystem> <filesystem type='mount' accessmode='mapped'> - <driver type='path' wrpolicy='immediate' iommu='on' ats='on' packed='on'/> + <driver type='path' wrpolicy='immediate' iommu='on' ats='on' packed='on' page_per_vq='on'/> <source dir='/export/fs2'/> <target dir='fs2'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> @@ -53,23 +53,23 @@ <interface type='user'> <mac address='52:54:56:58:5a:5c'/> <model type='virtio'/> - <driver iommu='on' ats='on' packed='on'/> + <driver iommu='on' ats='on' packed='on' page_per_vq='on'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> </interface> <input type='mouse' bus='virtio'> - <driver iommu='on' ats='on' packed='on'/> + <driver iommu='on' ats='on' packed='on' page_per_vq='on'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x0e' function='0x0'/> </input> <input type='keyboard' bus='virtio'> - <driver iommu='on' ats='on' packed='on'/> + <driver iommu='on' ats='on' packed='on' page_per_vq='on'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x10' function='0x0'/> </input> <input type='tablet' bus='virtio'> - <driver iommu='on' ats='on' packed='on'/> + <driver iommu='on' ats='on' packed='on' page_per_vq='on'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x11' function='0x0'/> </input> <input type='passthrough' bus='virtio'> - <driver iommu='on' ats='on' packed='on'/> + <driver iommu='on' ats='on' packed='on' page_per_vq='on'/> <source evdev='/dev/input/event1234'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x12' function='0x0'/> </input> @@ -77,7 +77,7 @@ <input type='keyboard' bus='ps2'/> <audio id='1' type='none'/> <video> - <driver iommu='on' ats='on' packed='on' name='vhostuser'/> + <driver iommu='on' ats='on' packed='on' page_per_vq='on' name='vhostuser'/> <model type='virtio' heads='1' primary='yes'> <acceleration accel3d='yes' rendernode='/dev/dri/test'/> </model> @@ -85,11 +85,11 @@ </video> <memballoon model='virtio'> <address type='pci' domain='0x0000' bus='0x00' slot='0x0c' function='0x0'/> - <driver iommu='on' ats='on' packed='on'/> + <driver iommu='on' ats='on' packed='on' page_per_vq='on'/> </memballoon> <rng model='virtio'> <backend model='random'>/dev/random</backend> - <driver iommu='on' ats='on' packed='on'/> + <driver iommu='on' ats='on' packed='on' page_per_vq='on'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x0d' function='0x0'/> </rng> </devices> -- 2.31.1

On 10/15/21 8:09 AM, Han Han wrote:
Diff from v2: - Remove the code of qemu capabilities since the least supported QEMU version is over the version introducing paeg-per-vq. - Rebase to latest upstream
v2: https://listman.redhat.com/archives/libvir-list/2021-October/msg00489.html
Han Han (2): conf: Add page_per_vq for driver element qemu: Add support for virtio device option page-per-vq
docs/formatdomain.rst | 9 +++++++ docs/schemas/domaincommon.rng | 5 ++++ src/conf/domain_conf.c | 16 ++++++++++++ src/conf/domain_conf.h | 1 + src/conf/domain_validate.c | 6 +++++ src/qemu/qemu_command.c | 1 + src/qemu/qemu_hotplug.c | 3 ++- src/qemu/qemu_validate.c | 1 + .../virtio-options.x86_64-latest.args | 24 ++++++++--------- tests/qemuxml2argvdata/virtio-options.xml | 26 +++++++++---------- 10 files changed, 66 insertions(+), 26 deletions(-)
Reviewed-by: Michal Privoznik <mprivozn@redhat.com> and pushed. Michal
participants (2)
-
Han Han
-
Michal Prívozník