From nobody Sat Oct 24 20:21:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) client-ip=38.145.34.151; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [38.145.34.151]) by mx.zohomail.com with SMTPS id 1791804209799231.21707301089373; Mon, 12 Oct 2026 04:23:29 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id A6DF441A3E; Mon, 12 Oct 2026 07:23:27 -0400 (EDT) Received: from [172.19.199.16] (unknown [10.16.107.18]) by lists.libvirt.org (Postfix) with ESMTP id 7266441957; Mon, 12 Oct 2026 07:21:42 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id DAF7D3F340; Mon, 12 Oct 2026 07:20:13 -0400 (EDT) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lists.libvirt.org (Postfix) with ESMTP id 7EA1B41869 for ; Mon, 12 Oct 2026 07:20:12 -0400 (EDT) Received: from DESKTOP-TUU1E5L.localdomain (unknown [167.220.208.79]) by linux.microsoft.com (Postfix) with ESMTPSA id 9BFBB20B7168; Mon, 12 Oct 2026 04:20:07 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 9BFBB20B7168 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1791804008; bh=zkvyMRMdszCY+af+dgWnL7IoKF39LPQI9xlcZm2U6pA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U1TGZANIOxYD86aoolYgesvWII3/0vL1EeIdGllOfqyYdyUW85GhD6qVtfHbaMkl/ Ffb7XmMF5/dzKSl8L+FlqPXNnrtf2uAKbjB4gMV06wEEaaQVhYtXgrqeHcx9n+yHYy xrx/kYT9SawMIhqPDpqfQdjExkXOpTU5ruTQKYF4= From: Magnus Kulke To: devel@lists.libvirt.org Subject: [PATCH 1/2] qemu: Consider vhost-net for mshv accelerator Date: Mon, 12 Oct 2026 13:20:04 +0200 Message-Id: <20261012112005.21584-2-magnuskulke@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261012112005.21584-1-magnuskulke@linux.microsoft.com> References: <20261012112005.21584-1-magnuskulke@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MailFrom: magnuskulke@linux.microsoft.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation Message-ID-Hash: L6HEKJVJZATPG42YAGH4VIFKYSOJEK7T X-Message-ID-Hash: L6HEKJVJZATPG42YAGH4VIFKYSOJEK7T X-Mailman-Approved-At: Mon, 12 Oct 2026 11:21:29 +0000 CC: Magnus Kulke , =?UTF-8?q?Ji=C5=99=C3=AD=20Denmark?= X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1791804212950158500 Content-Type: text/plain; charset="utf-8" Currently vhost-net is dropped for everything but KVM, this change enables it also for the MSHV accelerator (HYPERV). Signed-off-by: Magnus Kulke --- src/qemu/qemu_interface.c | 6 +++--- 1 file changed, 3 insertions(+), 3 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 =3D "/dev/vhost-net"; =20 - /* If running a plain QEMU guest, or - * if the config says explicitly to not use vhost, return now */ - if (vm->def->virtType !=3D VIR_DOMAIN_VIRT_KVM || + /* Only enable vhost for KVM and MSHV guests, unless explicitly disabl= ed. */ + if ((vm->def->virtType !=3D VIR_DOMAIN_VIRT_KVM && + vm->def->virtType !=3D VIR_DOMAIN_VIRT_HYPERV) || net->driver.virtio.name =3D=3D VIR_DOMAIN_NET_DRIVER_TYPE_QEMU) return 0; =20 --=20 2.34.1 From nobody Sat Oct 24 20:21:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) client-ip=38.145.34.151; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [38.145.34.151]) by mx.zohomail.com with SMTPS id 1791804310055421.6827390158488; Mon, 12 Oct 2026 04:25:10 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 261D4418C8; Mon, 12 Oct 2026 07:25:08 -0400 (EDT) Received: from [172.19.199.16] (unknown [10.16.107.18]) by lists.libvirt.org (Postfix) with ESMTP id E8A7F41AFB; Mon, 12 Oct 2026 07:21:47 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id B1EB43F359; Mon, 12 Oct 2026 07:20:17 -0400 (EDT) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lists.libvirt.org (Postfix) with ESMTP id 4CDAE41892 for ; Mon, 12 Oct 2026 07:20:16 -0400 (EDT) Received: from DESKTOP-TUU1E5L.localdomain (unknown [167.220.208.79]) by linux.microsoft.com (Postfix) with ESMTPSA id 1BD7C20B7169; Mon, 12 Oct 2026 04:20:08 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1BD7C20B7169 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1791804009; bh=zX2sfZpnjm8dOOCbcKu6N1ipogtdnJdQhNoadX/vxmw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c8zQiO8+bFDjS6m4j13ph1wd54QI+LKovqjxJLmaDxRxnOv2A7DdsgHsyj+qE9fBZ qjby/UeKCUxsea9XPIx1H5ZQwBjuNVB5UsnH5zyxFSKcOd5g14Ko9FcXaOljAEGtFx zvXf2tAH6OMNY3iFdY5RXEygjaEuwmU+hjGcGDPQ= From: Magnus Kulke To: devel@lists.libvirt.org Subject: [PATCH 2/2] test: vhost-net qemu commandline generation Date: Mon, 12 Oct 2026 13:20:05 +0200 Message-Id: <20261012112005.21584-3-magnuskulke@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261012112005.21584-1-magnuskulke@linux.microsoft.com> References: <20261012112005.21584-1-magnuskulke@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MailFrom: magnuskulke@linux.microsoft.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation Message-ID-Hash: GMFY4ZTQP5VJGHO23WSYVNNM343VHRQ5 X-Message-ID-Hash: GMFY4ZTQP5VJGHO23WSYVNNM343VHRQ5 X-Mailman-Approved-At: Mon, 12 Oct 2026 11:21:29 +0000 CC: Magnus Kulke , =?UTF-8?q?Ji=C5=99=C3=AD=20Denmark?= X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1791804312759158500 Content-Type: text/plain; charset="utf-8" This test asserts that the vhost-net commandline is generated for KVM and MSHV accelerator options. $ VIR_TEST_RANGE=3D2-10 VIR_TEST_DEBUG=3D1 meson test -C build \ --verbose qemucommandutiltest TEST: qemucommandutiltest 2) KVM vhost ... OK 3) KVM vhost multiqueue ... OK 4) MSHV vhost ... OK 5) MSHV vhost multiqueue ... OK 6) MSHV default ... OK 7) MSHV qemu backend ... OK 8) TCG vhost ... OK 9) MSHV vhost unavailable ... OK 10) MSHV default unavailable ... OK Signed-off-by: Magnus Kulke --- tests/qemucommandutiltest.c | 128 ++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/tests/qemucommandutiltest.c b/tests/qemucommandutiltest.c index 58493c7..f499d42 100644 --- a/tests/qemucommandutiltest.c +++ b/tests/qemucommandutiltest.c @@ -19,9 +19,15 @@ =20 #include =20 +#include + #include "util/virjson.h" #include "util/virqemu.h" #include "testutils.h" +#include "qemu/qemu_command.h" +#include "qemu/qemu_domain.h" +#include "qemu/qemu_interface.h" +#include "virfile.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 @@ -64,6 +70,111 @@ testQemuCommandBuildFromJSON(const void *opaque) return 0; } =20 +struct testVhostNetInfo { + virDomainVirtType virtType; + virDomainNetDriverType driver; + unsigned int queues; + unsigned int expectedVhostFDs; + bool unavailable; + int expectedResult; +}; + +static int +testOpenVhostNet(const void *opaque) +{ + const struct testVhostNetInfo *info =3D opaque; + g_autoptr(virDomainXMLOption) xmlopt =3D NULL; + g_autoptr(virDomainDef) def =3D virDomainDefNew(NULL); + virDomainObj vm =3D { .def =3D def }; + g_autoptr(virDomainNetDef) net =3D NULL; + g_autoptr(virJSONValue) props =3D NULL; + g_autoptr(virCommand) cmd =3D virCommandNew("/bin/true"); + g_auto(virBuffer) expected =3D VIR_BUFFER_INITIALIZER; + g_autofree char *expectedFDs =3D NULL; + qemuDomainNetworkPrivate *netpriv; + GSList *n; + bool vhost =3D false; + unsigned int queues =3D info->queues ? info->queues : 1; + size_t i; + int rc; + + if (!def || + !(xmlopt =3D virDomainXMLOptionNew(NULL, + &virQEMUDriverPrivateDataCallback= s, + NULL, NULL, NULL, NULL)) || + !(net =3D virDomainNetDefNew(xmlopt))) + return -1; + + def->name =3D g_strdup("vhost-test"); + def->virtType =3D info->virtType; + def->os.arch =3D VIR_ARCH_X86_64; + net->type =3D VIR_DOMAIN_NET_TYPE_ETHERNET; + net->model =3D VIR_DOMAIN_NET_MODEL_VIRTIO; + net->info.alias =3D g_strdup("net0"); + net->driver.virtio.name =3D info->driver; + net->driver.virtio.queues =3D info->queues; + /* Exercise the real device-opening code without requiring vhost suppo= rt. */ + net->backend.vhost =3D g_strdup(info->unavailable ? + abs_builddir "/missing-vhost-net" : "/dev= /null"); + netpriv =3D QEMU_DOMAIN_NETWORK_PRIVATE(net); + + rc =3D qemuInterfaceOpenVhostNet(&vm, net); + if (virTestCompareToULL(info->expectedResult !=3D 0, rc !=3D 0) < 0 || + virTestCompareToULL(info->expectedVhostFDs, + g_slist_length(netpriv->vhostfds)) < 0) + return -1; + + if (rc < 0) { + virResetLastError(); + return 0; + } + + for (i =3D 0; i < queues; i++) { + VIR_AUTOCLOSE fd =3D open("/dev/null", O_RDWR); + g_autofree char *name =3D g_strdup_printf("tapfd-net0%zu", i); + + if (fd < 0) { + virReportSystemError(errno, "%s", "Unable to open /dev/null"); + return -1; + } + netpriv->tapfds =3D g_slist_append(netpriv->tapfds, + qemuFDPassDirectNew(name, &fd)); + } + + for (n =3D netpriv->tapfds; n; n =3D n->next) + qemuFDPassDirectTransferCommand(n->data, cmd); + + for (n =3D netpriv->vhostfds; n; n =3D n->next) { + qemuFDPassDirectTransferCommand(n->data, cmd); + virBufferAsprintf(&expected, "%s:", qemuFDPassDirectGetPath(n->dat= a)); + } + virBufferTrim(&expected, ":"); + expectedFDs =3D virBufferContentAndReset(&expected); + + if (!(props =3D qemuBuildHostNetProps(&vm, net))) + return -1; + + if (!info->expectedVhostFDs) { + if (virJSONValueObjectHasKey(props, "vhost") || + virJSONValueObjectHasKey(props, "vhostfd") || + virJSONValueObjectHasKey(props, "vhostfds")) { + fprintf(stderr, "Unexpected vhost properties\n"); + return -1; + } + return 0; + } + + if (virJSONValueObjectGetBoolean(props, "vhost", &vhost) < 0 || !vhost= ) { + fprintf(stderr, "Missing vhost=3Dtrue\n"); + return -1; + } + + return virTestCompareToString(expectedFDs, + virJSONValueObjectGetString(props, + queues > 1 ? + "vhostfds" : "= vhostfd")); +} + static int mymain(void) { @@ -110,6 +221,23 @@ mymain(void) "server.2.type=3Dtcp," "server.2.host=3Dexample.com"); =20 +#define DO_TEST_VHOST_NET(name, virt, driver, queues, nfds, unavailable, r= esult) \ + do { \ + const struct testVhostNetInfo info =3D { virt, driver, queues, nfd= s, unavailable, result }; \ + if (virTestRun(name, testOpenVhostNet, &info) < 0) \ + ret =3D -1; \ + } while (0) + + DO_TEST_VHOST_NET("KVM vhost", VIR_DOMAIN_VIRT_KVM, VIR_DOMAIN_NET_DRI= VER_TYPE_VHOST, 0, 1, false, 0); + DO_TEST_VHOST_NET("KVM vhost multiqueue", VIR_DOMAIN_VIRT_KVM, VIR_DOM= AIN_NET_DRIVER_TYPE_VHOST, 8, 8, false, 0); + DO_TEST_VHOST_NET("MSHV vhost", VIR_DOMAIN_VIRT_HYPERV, VIR_DOMAIN_NET= _DRIVER_TYPE_VHOST, 0, 1, false, 0); + DO_TEST_VHOST_NET("MSHV vhost multiqueue", VIR_DOMAIN_VIRT_HYPERV, VIR= _DOMAIN_NET_DRIVER_TYPE_VHOST, 8, 8, false, 0); + DO_TEST_VHOST_NET("MSHV default", VIR_DOMAIN_VIRT_HYPERV, VIR_DOMAIN_N= ET_DRIVER_TYPE_DEFAULT, 8, 8, false, 0); + DO_TEST_VHOST_NET("MSHV qemu backend", VIR_DOMAIN_VIRT_HYPERV, VIR_DOM= AIN_NET_DRIVER_TYPE_QEMU, 8, 0, false, 0); + DO_TEST_VHOST_NET("TCG vhost", VIR_DOMAIN_VIRT_QEMU, VIR_DOMAIN_NET_DR= IVER_TYPE_VHOST, 8, 0, false, 0); + DO_TEST_VHOST_NET("MSHV vhost unavailable", VIR_DOMAIN_VIRT_HYPERV, VI= R_DOMAIN_NET_DRIVER_TYPE_VHOST, 8, 0, true, -1); + DO_TEST_VHOST_NET("MSHV default unavailable", VIR_DOMAIN_VIRT_HYPERV, = VIR_DOMAIN_NET_DRIVER_TYPE_DEFAULT, 8, 0, true, 0); + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 --=20 2.34.1