From nobody Tue Feb 10 10:55:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600983956; cv=none; d=zohomail.com; s=zohoarc; b=chF/OePim8RRDjxqptoX+r/Pvbsn8M+z+DP9nU6nrWS7MeTjHDQhip2RMQJaYwOyNEAjCE2JZ+W9NU9L/4hGKdIq5FBVdBApmHqKspXBfmRNrgmrupVQ94wEaoH9AkCKsftyTUmf79l+KQNMQ1YGmR+WQPI7kIoN+aMD1bk0GU0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600983956; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=y8bRlWa0ZNL4XvmLeemVo9a6yvYm4HJujMa4fYUHU1I=; b=bstLnlTfNKVp1A+b4oOUTVvY8nk4iuVswlgNIswEjwz46giCng/brXp0umwH1gl/TjOf2/mV1wxDVPqF8vUJNJ/3It2vMdPW2+3CsahAerGr2wyJUVXYeyO+ozQAGEuqPV+3gKja71OFoeK//Vk/sH2QS4vlQAtl1TrAB3iys/E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 160098395654297.09243948511244; Thu, 24 Sep 2020 14:45:56 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-403-GNtHLlVNOaGTv3mHXSH2IQ-1; Thu, 24 Sep 2020 17:45:52 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B5C8D81F03F; Thu, 24 Sep 2020 21:45:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 939B110013C1; Thu, 24 Sep 2020 21:45:46 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6081D79DD6; Thu, 24 Sep 2020 21:45:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08OLjPcN021342 for ; Thu, 24 Sep 2020 17:45:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 353A855771; Thu, 24 Sep 2020 21:45:25 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-36.phx2.redhat.com [10.3.114.36]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D8F465576B; Thu, 24 Sep 2020 21:45:24 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600983955; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=y8bRlWa0ZNL4XvmLeemVo9a6yvYm4HJujMa4fYUHU1I=; b=eKYVjhV22CB0P86xEsZd9dSdI8LlyrnmFcYSCTo7elGjanAQapGyRaamtjRPXxvua1NSsP bftrWcST2OJXognX4tPN4EMS61qYcSj0RPmCXmwQZAwqKSOTrbgPSS2qhVU01vkrD7GilS uBcJHXahX/5HL1WGSnoK525n5w4b5rI= X-MC-Unique: GNtHLlVNOaGTv3mHXSH2IQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v4 5/6] qemu: support hotplug of vdpa devices Date: Thu, 24 Sep 2020 16:45:15 -0500 Message-Id: <20200924214516.2348879-6-jjongsma@redhat.com> In-Reply-To: <20200924214516.2348879-1-jjongsma@redhat.com> References: <20200924214516.2348879-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: elic@nvidia.com, laine@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" By using the new qemu monitor functions to handle passing and removing file descriptors, we can support hotplug of vdpa devices. Signed-off-by: Jonathon Jongsma Reviewed-by: Laine Stump --- src/qemu/qemu_hotplug.c | 60 +++++++++++++++++-- tests/qemuhotplugmock.c | 9 +++ tests/qemuhotplugtest.c | 16 +++++ .../qemuhotplug-interface-vdpa.xml | 4 ++ .../qemuhotplug-base-live+interface-vdpa.xml | 57 ++++++++++++++++++ 5 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-interface-vdpa= .xml create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-base-live+inte= rface-vdpa.xml diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 0582b78f97..3a2aff607c 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1152,6 +1152,8 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, virErrorPtr originalError =3D NULL; g_autofree char *slirpfdName =3D NULL; int slirpfd =3D -1; + g_autofree char *vdpafdName =3D NULL; + int vdpafd =3D -1; char **tapfdName =3D NULL; int *tapfd =3D NULL; size_t tapfdSize =3D 0; @@ -1335,12 +1337,16 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, /* hostdev interfaces were handled earlier in this function */ break; =20 + case VIR_DOMAIN_NET_TYPE_VDPA: + if ((vdpafd =3D qemuInterfaceVDPAConnect(net)) < 0) + goto cleanup; + break; + case VIR_DOMAIN_NET_TYPE_SERVER: case VIR_DOMAIN_NET_TYPE_CLIENT: case VIR_DOMAIN_NET_TYPE_MCAST: case VIR_DOMAIN_NET_TYPE_INTERNAL: case VIR_DOMAIN_NET_TYPE_UDP: - case VIR_DOMAIN_NET_TYPE_VDPA: case VIR_DOMAIN_NET_TYPE_LAST: virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("hotplug of interface type of %s is not implement= ed yet"), @@ -1386,14 +1392,28 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, for (i =3D 0; i < vhostfdSize; i++) vhostfdName[i] =3D g_strdup_printf("vhostfd-%s%zu", net->info.alia= s, i); =20 + qemuDomainObjEnterMonitor(driver, vm); + + if (vdpafd > 0) { + /* vhost-vdpa only takes a filename for the dev, but we want to pa= ss an + * open fd to qemu. Passing -1 as the fdset-id will create a new f= dset + * and return the id of that fdset */ + qemuMonitorAddFdInfo fdinfo; + if (qemuMonitorAddFileHandleToSet(priv->mon, vdpafd, -1, + net->data.vdpa.devicepath, + &fdinfo) < 0) { + ignore_value(qemuDomainObjExitMonitor(driver, vm)); + goto cleanup; + } + vdpafdName =3D g_strdup_printf("/dev/fdset/%d", fdinfo.fdset); + } + if (!(netprops =3D qemuBuildHostNetStr(net, tapfdName, tapfdSize, vhostfdName, vhostfdSize, - slirpfdName, NULL))) + slirpfdName, vdpafdName))) goto cleanup; =20 - qemuDomainObjEnterMonitor(driver, vm); - if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_VHOSTUSER) { if (qemuMonitorAttachCharDev(priv->mon, charDevAlias, net->data.vh= ostuser) < 0) { ignore_value(qemuDomainObjExitMonitor(driver, vm)); @@ -1518,6 +1538,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, VIR_FREE(vhostfdName); virDomainCCWAddressSetFree(ccwaddrs); VIR_FORCE_CLOSE(slirpfd); + VIR_FORCE_CLOSE(vdpafd); =20 return ret; =20 @@ -4586,8 +4607,39 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver, * to just ignore the error and carry on. */ } + } else if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_VDPA) { + int vdpafdset =3D -1; + g_autoptr(qemuMonitorFdsets) fdsets =3D NULL; + + /* query qemu for which fdset is associated with the fd that we pa= ssed + * to qemu via 'add-fd' for this vdpa device. If we don't remove t= he + * fd, qemu will keep it open */ + if (qemuMonitorQueryFdsets(priv->mon, &fdsets) =3D=3D 0) { + for (i =3D 0; i < fdsets->nfdsets && vdpafdset < 0; i++) { + size_t j; + qemuMonitorFdsetInfoPtr set =3D &fdsets->fdsets[i]; + + for (j =3D 0; j < set->nfds; j++) { + qemuMonitorFdsetFdInfoPtr fdinfo =3D &set->fds[j]; + if (STREQ_NULLABLE(fdinfo->opaque, net->data.vdpa.devi= cepath)) { + vdpafdset =3D set->id; + break; + } + } + } + } + + if (vdpafdset < 0) { + VIR_WARN("Cannot determine fdset for vdpa device"); + } else { + if (qemuMonitorRemoveFdset(priv->mon, vdpafdset) < 0) { + /* if it fails, there's not much we can do... just carry o= n */ + VIR_WARN("failed to close vdpa device"); + } + } } =20 + if (qemuDomainObjExitMonitor(driver, vm) < 0) return -1; =20 diff --git a/tests/qemuhotplugmock.c b/tests/qemuhotplugmock.c index 29fac8a598..d2e32ecf7e 100644 --- a/tests/qemuhotplugmock.c +++ b/tests/qemuhotplugmock.c @@ -19,11 +19,13 @@ #include =20 #include "qemu/qemu_hotplug.h" +#include "qemu/qemu_interface.h" #include "qemu/qemu_process.h" #include "conf/domain_conf.h" #include "virdevmapper.h" #include "virutil.h" #include "virmock.h" +#include =20 static int (*real_virGetDeviceID)(const char *path, int *maj, int *min); static bool (*real_virFileExists)(const char *path); @@ -106,3 +108,10 @@ void qemuProcessKillManagedPRDaemon(virDomainObjPtr vm G_GNUC_UNUSED) { } + +int +qemuInterfaceVDPAConnect(virDomainNetDefPtr net G_GNUC_UNUSED) +{ + /* need a valid fd or sendmsg won't work. Just open /dev/null */ + return open("/dev/null", O_RDONLY); +} diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 2d12cacf28..b7cebfc0e7 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -89,6 +89,7 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt, virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_SPICE_FILE_XFER_DISABLE); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_PR_MANAGER_HELPER); virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_SCSI_BLOCK); + virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_NETDEV_VHOST_VDPA); =20 if (qemuTestCapsCacheInsert(driver.qemuCapsCache, priv->qemuCaps) < 0) return -1; @@ -140,6 +141,9 @@ testQemuHotplugAttach(virDomainObjPtr vm, case VIR_DOMAIN_DEVICE_HOSTDEV: ret =3D qemuDomainAttachHostDevice(&driver, vm, dev->data.hostdev); break; + case VIR_DOMAIN_DEVICE_NET: + ret =3D qemuDomainAttachNetDevice(&driver, vm, dev->data.net); + break; default: VIR_TEST_VERBOSE("device type '%s' cannot be attached", virDomainDeviceTypeToString(dev->type)); @@ -162,6 +166,7 @@ testQemuHotplugDetach(virDomainObjPtr vm, case VIR_DOMAIN_DEVICE_SHMEM: case VIR_DOMAIN_DEVICE_WATCHDOG: case VIR_DOMAIN_DEVICE_HOSTDEV: + case VIR_DOMAIN_DEVICE_NET: ret =3D qemuDomainDetachDeviceLive(vm, dev, &driver, async); break; default: @@ -823,6 +828,17 @@ mymain(void) DO_TEST_DETACH("pseries-base-live", "hostdev-pci", false, false, "device_del", QMP_DEVICE_DELETED("hostdev0") QMP_OK); =20 + DO_TEST_ATTACH("base-live", "interface-vdpa", false, true, + "add-fd", "{ \"return\": { \"fdset-id\": 1, \"fd\": 95 = }}", + "netdev_add", QMP_OK, "device_add", QMP_OK); + DO_TEST_DETACH("base-live", "interface-vdpa", false, false, + "device_del", QMP_DEVICE_DELETED("net0") QMP_OK, + "netdev_del", QMP_OK, + "query-fdsets", + "{ \"return\": [{\"fds\": [{\"fd\": 95, \"opaque\": \"/= dev/vhost-vdpa-0\"}], \"fdset-id\": 1}]}", + "remove-fd", QMP_OK + ); + DO_TEST_ATTACH("base-live", "watchdog", false, true, "watchdog-set-action", QMP_OK, "device_add", QMP_OK); diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-interface-vdpa.xml b/= tests/qemuhotplugtestdevices/qemuhotplug-interface-vdpa.xml new file mode 100644 index 0000000000..e42ca08d31 --- /dev/null +++ b/tests/qemuhotplugtestdevices/qemuhotplug-interface-vdpa.xml @@ -0,0 +1,4 @@ + + + + diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+interface-v= dpa.xml b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+interface-vdpa= .xml new file mode 100644 index 0000000000..066180bb3c --- /dev/null +++ b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+interface-vdpa.xml @@ -0,0 +1,57 @@ + + hotplug + d091ea82-29e6-2e34-3005-f02617b36e87 + 4194304 + 4194304 + 4 + + hvm + + + + + + + + + destroy + restart + restart + + /usr/bin/qemu-system-x86_64 + + +
+ + + +
+ + + +
+ + + + + + +
+ + + + + + +
+ + + + + + + + + + + --=20 2.26.2