[PATCH v2 0/2] qemu: add support for vhost-net when using the mshv accelerator
Currently vhost-net is dropped for everything but KVM, this change enables it also for the MSHV accelerator (HYPERV). Changes since v1: - The dedicated unit test has been dropped - Test fixtures and mock have been extended to test a vhost net device Magnus Kulke (2): tests: Add vhost network interface to mshv config qemu: Consider vhost-net for mshv accelerator src/qemu/qemu_interface.c | 6 +++--- tests/qemuxml2argvmock.c | 3 ++- ...86_64-q35-headless.x86_64-latest+mshv.args | 11 +++++++---- ...x86_64-q35-headless.x86_64-latest+mshv.xml | 19 +++++++++++++++---- .../mshv-x86_64-q35-headless.xml | 5 +++++ 5 files changed, 32 insertions(+), 12 deletions(-) -- 2.34.1
We need this to assert that vhost is enabled in a QEMU cmdline for HYPERV (mshv) guests. Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com> --- ...86_64-q35-headless.x86_64-latest+mshv.args | 11 +++++++---- ...x86_64-q35-headless.x86_64-latest+mshv.xml | 19 +++++++++++++++---- .../mshv-x86_64-q35-headless.xml | 5 +++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/tests/qemuxmlconfdata/mshv-x86_64-q35-headless.x86_64-latest+mshv.args b/tests/qemuxmlconfdata/mshv-x86_64-q35-headless.x86_64-latest+mshv.args index 28e3e3f..10684b3 100644 --- a/tests/qemuxmlconfdata/mshv-x86_64-q35-headless.x86_64-latest+mshv.args +++ b/tests/qemuxmlconfdata/mshv-x86_64-q35-headless.x86_64-latest+mshv.args @@ -32,17 +32,20 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-qemu_mshv/.config \ -device '{"driver":"pcie-root-port","port":10,"chassis":3,"id":"pci.3","bus":"pcie.0","addr":"0x1.0x2"}' \ -device '{"driver":"pcie-root-port","port":11,"chassis":4,"id":"pci.4","bus":"pcie.0","addr":"0x1.0x3"}' \ -device '{"driver":"pcie-root-port","port":12,"chassis":5,"id":"pci.5","bus":"pcie.0","addr":"0x1.0x4"}' \ --device '{"driver":"qemu-xhci","id":"usb","bus":"pci.1","addr":"0x0"}' \ +-device '{"driver":"pcie-root-port","port":13,"chassis":6,"id":"pci.6","bus":"pcie.0","addr":"0x1.0x5"}' \ +-device '{"driver":"qemu-xhci","id":"usb","bus":"pci.2","addr":"0x0"}' \ -blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/test.qcow2","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"qcow2","file":"libvirt-1-storage"}' \ --device '{"driver":"virtio-blk-pci","bus":"pci.2","addr":"0x0","drive":"libvirt-1-format","id":"virtio-disk0","bootindex":1}' \ +-device '{"driver":"virtio-blk-pci","bus":"pci.3","addr":"0x0","drive":"libvirt-1-format","id":"virtio-disk0","bootindex":1}' \ +-netdev '{"type":"tap","fds":"XXXXXXX","id":"hostnet0"}' \ +-device '{"driver":"virtio-net-pci","ioeventfd":true,"mq":true,"vectors":12,"netdev":"hostnet0","id":"net0","mac":"52:54:00:e5:48:5a","bus":"pci.1","addr":"0x0"}' \ -chardev pty,id=charserial0 \ -device '{"driver":"isa-serial","chardev":"charserial0","id":"serial0","index":0}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -global ICH9-LPC.noreboot=off \ -watchdog-action reset \ --device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.3","addr":"0x0"}' \ +-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.4","addr":"0x0"}' \ -object '{"qom-type":"rng-random","id":"objrng0","filename":"/dev/urandom"}' \ --device '{"driver":"virtio-rng-pci","rng":"objrng0","id":"rng0","bus":"pci.4","addr":"0x0"}' \ +-device '{"driver":"virtio-rng-pci","rng":"objrng0","id":"rng0","bus":"pci.5","addr":"0x0"}' \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ -msg timestamp=on diff --git a/tests/qemuxmlconfdata/mshv-x86_64-q35-headless.x86_64-latest+mshv.xml b/tests/qemuxmlconfdata/mshv-x86_64-q35-headless.x86_64-latest+mshv.xml index a183a3d..747d250 100644 --- a/tests/qemuxmlconfdata/mshv-x86_64-q35-headless.x86_64-latest+mshv.xml +++ b/tests/qemuxmlconfdata/mshv-x86_64-q35-headless.x86_64-latest+mshv.xml @@ -30,10 +30,10 @@ <driver name='qemu' type='qcow2'/> <source file='/var/lib/libvirt/images/test.qcow2'/> <target dev='vda' bus='virtio'/> - <address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/> + <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/> </disk> <controller type='usb' index='0' model='qemu-xhci'> - <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/> + <address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/> </controller> <controller type='sata' index='0'> <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/> @@ -64,6 +64,17 @@ <target chassis='5' port='0xc'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x4'/> </controller> + <controller type='pci' index='6' model='pcie-root-port'> + <model name='pcie-root-port'/> + <target chassis='6' port='0xd'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x5'/> + </controller> + <interface type='ethernet'> + <mac address='52:54:00:e5:48:5a'/> + <model type='virtio'/> + <driver name='vhost' ioeventfd='on' queues='5'/> + <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/> + </interface> <serial type='pty'> <target type='isa-serial' port='0'> <model name='isa-serial'/> @@ -77,11 +88,11 @@ <audio id='1' type='none'/> <watchdog model='itco' action='reset'/> <memballoon model='virtio'> - <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/> + <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/> </memballoon> <rng model='virtio'> <backend model='random'>/dev/urandom</backend> - <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/> + <address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/> </rng> </devices> </domain> diff --git a/tests/qemuxmlconfdata/mshv-x86_64-q35-headless.xml b/tests/qemuxmlconfdata/mshv-x86_64-q35-headless.xml index d8fc60a..41bfcaa 100644 --- a/tests/qemuxmlconfdata/mshv-x86_64-q35-headless.xml +++ b/tests/qemuxmlconfdata/mshv-x86_64-q35-headless.xml @@ -31,5 +31,10 @@ <rng model='virtio'> <backend model='random'>/dev/urandom</backend> </rng> + <interface type='ethernet'> + <mac address='52:54:00:e5:48:5a'/> + <model type='virtio'/> + <driver name='vhost' ioeventfd='on' queues='5'/> + </interface> </devices> </domain> -- 2.34.1
Currently vhost-net is dropped for everything but KVM, this change enables it also for the MSHV accelerator (HYPERV) in the generator code and the mock. Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com> --- src/qemu/qemu_interface.c | 6 +++--- tests/qemuxml2argvmock.c | 3 ++- .../mshv-x86_64-q35-headless.x86_64-latest+mshv.args | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index edc53d5..61bcbc6 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -162,9 +162,9 @@ qemuInterfaceOpenVhostNet(virDomainObj *vm, if (!vhostnet_path) vhostnet_path = "/dev/vhost-net"; - /* If running a plain QEMU guest, or - * if the config says explicitly to not use vhost, return now */ - if (vm->def->virtType != VIR_DOMAIN_VIRT_KVM || + /* Only enable vhost for KVM and MSHV guests, unless explicitly disabled. */ + if ((vm->def->virtType != VIR_DOMAIN_VIRT_KVM && + vm->def->virtType != VIR_DOMAIN_VIRT_HYPERV) || net->driver.virtio.name == VIR_DOMAIN_NET_DRIVER_TYPE_QEMU) return 0; diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c index 414b7ea..dd7209d 100644 --- a/tests/qemuxml2argvmock.c +++ b/tests/qemuxml2argvmock.c @@ -227,12 +227,13 @@ qemuInterfaceOpenVhostNet(virDomainObj *vm, { qemuDomainNetworkPrivate *netpriv = QEMU_DOMAIN_NETWORK_PRIVATE(net); size_t vhostfdSize = net->driver.virtio.queues; + int vType = vm->def->virtType; size_t i; if (!vhostfdSize) vhostfdSize = 1; - if (vm->def->virtType != VIR_DOMAIN_VIRT_KVM || + if ((vType != VIR_DOMAIN_VIRT_KVM && vType != VIR_DOMAIN_VIRT_HYPERV) || net->driver.virtio.name == VIR_DOMAIN_NET_DRIVER_TYPE_QEMU) { return 0; } diff --git a/tests/qemuxmlconfdata/mshv-x86_64-q35-headless.x86_64-latest+mshv.args b/tests/qemuxmlconfdata/mshv-x86_64-q35-headless.x86_64-latest+mshv.args index 10684b3..5816610 100644 --- a/tests/qemuxmlconfdata/mshv-x86_64-q35-headless.x86_64-latest+mshv.args +++ b/tests/qemuxmlconfdata/mshv-x86_64-q35-headless.x86_64-latest+mshv.args @@ -37,7 +37,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-qemu_mshv/.config \ -blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/test.qcow2","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"qcow2","file":"libvirt-1-storage"}' \ -device '{"driver":"virtio-blk-pci","bus":"pci.3","addr":"0x0","drive":"libvirt-1-format","id":"virtio-disk0","bootindex":1}' \ --netdev '{"type":"tap","fds":"XXXXXXX","id":"hostnet0"}' \ +-netdev '{"type":"tap","fds":"XXXXXXX","vhost":true,"vhostfds":"XXXXXXX","id":"hostnet0"}' \ -device '{"driver":"virtio-net-pci","ioeventfd":true,"mq":true,"vectors":12,"netdev":"hostnet0","id":"net0","mac":"52:54:00:e5:48:5a","bus":"pci.1","addr":"0x0"}' \ -chardev pty,id=charserial0 \ -device '{"driver":"isa-serial","chardev":"charserial0","id":"serial0","index":0}' \ -- 2.34.1
On 10/16/26 11:57, Magnus Kulke wrote:
Currently vhost-net is dropped for everything but KVM, this change enables it also for the MSHV accelerator (HYPERV) in the generator code and the mock.
Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com> --- src/qemu/qemu_interface.c | 6 +++--- tests/qemuxml2argvmock.c | 3 ++- .../mshv-x86_64-q35-headless.x86_64-latest+mshv.args | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index edc53d5..61bcbc6 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -162,9 +162,9 @@ qemuInterfaceOpenVhostNet(virDomainObj *vm, if (!vhostnet_path) vhostnet_path = "/dev/vhost-net";
- /* If running a plain QEMU guest, or - * if the config says explicitly to not use vhost, return now */ - if (vm->def->virtType != VIR_DOMAIN_VIRT_KVM || + /* Only enable vhost for KVM and MSHV guests, unless explicitly disabled. */ + if ((vm->def->virtType != VIR_DOMAIN_VIRT_KVM && + vm->def->virtType != VIR_DOMAIN_VIRT_HYPERV) || net->driver.virtio.name == VIR_DOMAIN_NET_DRIVER_TYPE_QEMU) return 0;
We could take this opportunity and wrap the if() body in curly braces to honor our coding style.
diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c index 414b7ea..dd7209d 100644 --- a/tests/qemuxml2argvmock.c +++ b/tests/qemuxml2argvmock.c @@ -227,12 +227,13 @@ qemuInterfaceOpenVhostNet(virDomainObj *vm, { qemuDomainNetworkPrivate *netpriv = QEMU_DOMAIN_NETWORK_PRIVATE(net); size_t vhostfdSize = net->driver.virtio.queues; + int vType = vm->def->virtType; size_t i;
if (!vhostfdSize) vhostfdSize = 1;
- if (vm->def->virtType != VIR_DOMAIN_VIRT_KVM || + if ((vType != VIR_DOMAIN_VIRT_KVM && vType != VIR_DOMAIN_VIRT_HYPERV) || net->driver.virtio.name == VIR_DOMAIN_NET_DRIVER_TYPE_QEMU) { return 0; }
Here, we should just copy the very same lines from the above hunk to make it more obvious that these two need to be kept in sync. Michal
On 10/16/26 11:57, Magnus Kulke wrote:
Currently vhost-net is dropped for everything but KVM, this change enables it also for the MSHV accelerator (HYPERV).
Changes since v1:
- The dedicated unit test has been dropped - Test fixtures and mock have been extended to test a vhost net device
Magnus Kulke (2): tests: Add vhost network interface to mshv config qemu: Consider vhost-net for mshv accelerator
src/qemu/qemu_interface.c | 6 +++--- tests/qemuxml2argvmock.c | 3 ++- ...86_64-q35-headless.x86_64-latest+mshv.args | 11 +++++++---- ...x86_64-q35-headless.x86_64-latest+mshv.xml | 19 +++++++++++++++---- .../mshv-x86_64-q35-headless.xml | 5 +++++ 5 files changed, 32 insertions(+), 12 deletions(-)
Reviewed-by: Michal Privoznik <mprivozn@redhat.com> and merged. Congratulations on your first libvirt contribution! Michal
participants (2)
-
Magnus Kulke -
Michal Prívozník