[libvirt PATCH] qemu: fix hotplug for multiqueue vdpa net device

Jonathon Jongsma posted 1 patch 2 years, 7 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20220329201935.2587146-1-jjongsma@redhat.com
src/qemu/qemu_command.c                                       | 4 ++++
src/qemu/qemu_hotplug.c                                       | 3 +++
tests/qemuxml2argvdata/net-vdpa-multiqueue.x86_64-latest.args | 2 +-
3 files changed, 8 insertions(+), 1 deletion(-)
[libvirt PATCH] qemu: fix hotplug for multiqueue vdpa net device
Posted by Jonathon Jongsma 2 years, 7 months ago
While commit a5e659f0 removed the restriction against multiple queues
for the vdpa net device, there were some missing pieces. Configuring a
device statically and then starting the domain worked as expected, but
hotplugging a device didn't have the expected multiqueue support
enabled. Add the missing bits.

Consider the following device xml:
    <interface type="vdpa">
      <mac address="00:11:22:33:44:03" />
      <source dev="/dev/vhost-vdpa-0" />
      <model type="virtio" />
      <driver queues='2' />
    </interface>

Without this patch, hotplugging the above XML description resulted in
the following:
    {"execute":"netdev_add","arguments":{"type":"vhost-vdpa","vhostdev":"/dev/fdset/0","id":"hostnet1"},"id":"libvirt-392"}
    {"execute":"device_add","arguments":{"driver":"virtio-net-pci","netdev":"hostnet1","id":"net1","mac":"00:11:22:33:44:03","bus":"pci.5","addr":"0x0"},"id":"libvirt-393"}

With the patch, hotplugging results in the following:
    {"execute":"netdev_add","arguments":{"type":"vhost-vdpa","vhostdev":"/dev/fdset/0","queues":2,"id":"hostnet1"},"id":"libvirt-392"}
    {"execute":"device_add","arguments":{"driver":"virtio-net-pci","mq":true,"vectors":6,"netdev":"hostnet1","id":"net1","mac":"00:11:22:33:44:03","bus":"pci.5","addr":"0x0"},"id":"libvirt-393"}

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2024406

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
---
 src/qemu/qemu_command.c                                       | 4 ++++
 src/qemu/qemu_hotplug.c                                       | 3 +++
 tests/qemuxml2argvdata/net-vdpa-multiqueue.x86_64-latest.args | 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 453891a725..f7f55b20ef 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4346,6 +4346,10 @@ qemuBuildHostNetProps(virDomainNetDef *net,
         if (virJSONValueObjectAdd(&netprops, "s:type", "vhost-vdpa", NULL) < 0 ||
             virJSONValueObjectAppendString(netprops, "vhostdev", vdpadev) < 0)
             return NULL;
+
+        if (net->driver.virtio.queues > 1 &&
+            virJSONValueObjectAppendNumberUlong(netprops, "queues", net->driver.virtio.queues) < 0)
+            return NULL;
         break;
 
     case VIR_DOMAIN_NET_TYPE_HOSTDEV:
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 3d1bb1be2a..d9ba0b7abe 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1386,6 +1386,9 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
         break;
 
     case VIR_DOMAIN_NET_TYPE_VDPA:
+        queueSize = net->driver.virtio.queues;
+        if (!queueSize)
+            queueSize = 1;
         if (qemuDomainAdjustMaxMemLock(vm, false) < 0)
             goto cleanup;
         adjustmemlock = true;
diff --git a/tests/qemuxml2argvdata/net-vdpa-multiqueue.x86_64-latest.args b/tests/qemuxml2argvdata/net-vdpa-multiqueue.x86_64-latest.args
index 26ef666036..4cb805451a 100644
--- a/tests/qemuxml2argvdata/net-vdpa-multiqueue.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/net-vdpa-multiqueue.x86_64-latest.args
@@ -29,7 +29,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
 -boot strict=on \
 -device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
 -add-fd set=0,fd=1732,opaque=net0-vdpa \
--netdev vhost-vdpa,vhostdev=/dev/fdset/0,id=hostnet0 \
+-netdev vhost-vdpa,vhostdev=/dev/fdset/0,queues=2,id=hostnet0 \
 -device '{"driver":"virtio-net-pci","mq":true,"vectors":6,"netdev":"hostnet0","id":"net0","mac":"52:54:00:95:db:c0","bus":"pci.0","addr":"0x2"}' \
 -audiodev '{"id":"audio1","driver":"none"}' \
 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
-- 
2.35.1
Re: [libvirt PATCH] qemu: fix hotplug for multiqueue vdpa net device
Posted by Ján Tomko 2 years, 7 months ago
On a Tuesday in 2022, Jonathon Jongsma wrote:
>While commit a5e659f0 removed the restriction against multiple queues
>for the vdpa net device, there were some missing pieces. Configuring a
>device statically and then starting the domain worked as expected, but
>hotplugging a device didn't have the expected multiqueue support
>enabled. Add the missing bits.
>
>Consider the following device xml:
>    <interface type="vdpa">
>      <mac address="00:11:22:33:44:03" />
>      <source dev="/dev/vhost-vdpa-0" />
>      <model type="virtio" />
>      <driver queues='2' />
>    </interface>
>
>Without this patch, hotplugging the above XML description resulted in
>the following:
>    {"execute":"netdev_add","arguments":{"type":"vhost-vdpa","vhostdev":"/dev/fdset/0","id":"hostnet1"},"id":"libvirt-392"}
>    {"execute":"device_add","arguments":{"driver":"virtio-net-pci","netdev":"hostnet1","id":"net1","mac":"00:11:22:33:44:03","bus":"pci.5","addr":"0x0"},"id":"libvirt-393"}
>
>With the patch, hotplugging results in the following:
>    {"execute":"netdev_add","arguments":{"type":"vhost-vdpa","vhostdev":"/dev/fdset/0","queues":2,"id":"hostnet1"},"id":"libvirt-392"}
>    {"execute":"device_add","arguments":{"driver":"virtio-net-pci","mq":true,"vectors":6,"netdev":"hostnet1","id":"net1","mac":"00:11:22:33:44:03","bus":"pci.5","addr":"0x0"},"id":"libvirt-393"}
>
>Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2024406
>
>Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
>---
> src/qemu/qemu_command.c                                       | 4 ++++
> src/qemu/qemu_hotplug.c                                       | 3 +++
> tests/qemuxml2argvdata/net-vdpa-multiqueue.x86_64-latest.args | 2 +-
> 3 files changed, 8 insertions(+), 1 deletion(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano