From nobody Sun Apr 28 16:19:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 149485022591178.97463841811089; Mon, 15 May 2017 05:10:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 597C880E7C; Mon, 15 May 2017 12:10:23 +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 29A1E4DA31; Mon, 15 May 2017 12:10:23 +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 C4E485ED65; Mon, 15 May 2017 12:10:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4FCA5hd011839 for ; Mon, 15 May 2017 08:10:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9C5877D4F4; Mon, 15 May 2017 12:10:05 +0000 (UTC) Received: from beluga.usersys.redhat.com (dhcp129-94.brq.redhat.com [10.34.129.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C5CC7D4E4; Mon, 15 May 2017 12:10:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 597C880E7C Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 597C880E7C From: Erik Skultety To: libvir-list@redhat.com Date: Mon, 15 May 2017 14:10:17 +0200 Message-Id: <9d1c91a6910a31cedfe1efe455e682c5774c1736.1494849510.git.eskultet@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v4 1/6] mdev: Pass a uuidstr rather than an mdev object to some util functions 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 15 May 2017 12:10:24 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Namely, this patch is about virMediatedDeviceGetIOMMUGroup{Dev,Num} functions. There's no compelling reason why these functions should take an object, on the contrary, having to create an object every time one needs to query the IOMMU group number, discarding the object afterwards, seems odd. Signed-off-by: Erik Skultety Reviewed-by: John Ferlan --- src/qemu/qemu_domain.c | 8 +------- src/security/security_apparmor.c | 10 +--------- src/security/security_dac.c | 20 ++------------------ src/security/security_selinux.c | 20 ++------------------ src/util/virmdev.c | 21 +++++++++++++-------- src/util/virmdev.h | 4 ++-- 6 files changed, 21 insertions(+), 62 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index cc02c801e..76acb1c3f 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7181,7 +7181,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, virUSBDevicePtr usb =3D NULL; virSCSIDevicePtr scsi =3D NULL; virSCSIVHostDevicePtr host =3D NULL; - virMediatedDevicePtr mdev =3D NULL; char *tmpPath =3D NULL; bool freeTmpPath =3D false; bool includeVFIO =3D false; @@ -7282,11 +7281,7 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, } =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: - if (!(mdev =3D virMediatedDeviceNew(mdevsrc->uuidstr, - mdevsrc->model))) - goto cleanup; - - if (!(tmpPath =3D virMediatedDeviceGetIOMMUGroupDev(mdev))) + if (!(tmpPath =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->u= uidstr))) goto cleanup; =20 freeTmpPath =3D true; @@ -7342,7 +7337,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, virUSBDeviceFree(usb); virSCSIDeviceFree(scsi); virSCSIVHostDeviceFree(host); - virMediatedDeviceFree(mdev); if (freeTmpPath) VIR_FREE(tmpPath); return ret; diff --git a/src/security/security_apparmor.c b/src/security/security_appar= mor.c index fc5581526..62672b0af 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -905,21 +905,13 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr= mgr, =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { char *vfiodev =3D NULL; - virMediatedDevicePtr mdev =3D virMediatedDeviceNew(mdevsrc->uuidst= r, - mdevsrc->model); =20 - if (!mdev) + if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuids= tr))) goto done; =20 - if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdev))) { - virMediatedDeviceFree(mdev); - goto done; - } - ret =3D AppArmorSetSecurityHostdevLabelHelper(vfiodev, ptr); =20 VIR_FREE(vfiodev); - virMediatedDeviceFree(mdev); break; } =20 diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 922e48494..7dcf4c15f 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -968,21 +968,13 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr m= gr, =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { char *vfiodev =3D NULL; - virMediatedDevicePtr mdev =3D virMediatedDeviceNew(mdevsrc->uuidst= r, - mdevsrc->model); =20 - if (!mdev) + if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuids= tr))) goto done; =20 - if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdev))) { - virMediatedDeviceFree(mdev); - goto done; - } - ret =3D virSecurityDACSetHostdevLabelHelper(vfiodev, &cbdata); =20 VIR_FREE(vfiodev); - virMediatedDeviceFree(mdev); break; } =20 @@ -1144,21 +1136,13 @@ virSecurityDACRestoreHostdevLabel(virSecurityManage= rPtr mgr, =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { char *vfiodev =3D NULL; - virMediatedDevicePtr mdev =3D virMediatedDeviceNew(mdevsrc->uuidst= r, - mdevsrc->model); =20 - if (!mdev) + if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuids= tr))) goto done; =20 - if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdev))) { - virMediatedDeviceFree(mdev); - goto done; - } - ret =3D virSecurityDACRestoreFileLabel(virSecurityManagerGetPrivat= eData(mgr), vfiodev); VIR_FREE(vfiodev); - virMediatedDeviceFree(mdev); break; } =20 diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index df7c96833..c7a2dfe98 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1843,21 +1843,13 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurity= ManagerPtr mgr, =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { char *vfiodev =3D NULL; - virMediatedDevicePtr mdev =3D virMediatedDeviceNew(mdevsrc->uuidst= r, - mdevsrc->model); =20 - if (!mdev) + if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuids= tr))) goto done; =20 - if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdev))) { - virMediatedDeviceFree(mdev); - goto done; - } - ret =3D virSecuritySELinuxSetHostdevLabelHelper(vfiodev, &data); =20 VIR_FREE(vfiodev); - virMediatedDeviceFree(mdev); break; } =20 @@ -2092,21 +2084,13 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecu= rityManagerPtr mgr, =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { char *vfiodev =3D NULL; - virMediatedDevicePtr mdev =3D virMediatedDeviceNew(mdevsrc->uuidst= r, - mdevsrc->model); =20 - if (!mdev) + if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuids= tr))) goto done; =20 - if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdev))) { - virMediatedDeviceFree(mdev); - goto done; - } - ret =3D virSecuritySELinuxRestoreFileLabel(mgr, vfiodev); =20 VIR_FREE(vfiodev); - virMediatedDeviceFree(mdev); break; } =20 diff --git a/src/util/virmdev.c b/src/util/virmdev.c index bd8e3f8de..a5f52d10f 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -209,43 +209,48 @@ virMediatedDeviceGetPath(virMediatedDevicePtr dev) * for freeing the result. */ char * -virMediatedDeviceGetIOMMUGroupDev(virMediatedDevicePtr dev) +virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr) { - char *resultpath =3D NULL; + char *result_path =3D NULL; char *iommu_path =3D NULL; char *vfio_path =3D NULL; + char *dev_path =3D virMediatedDeviceGetSysfsPath(uuidstr); =20 - if (virAsprintf(&iommu_path, "%s/iommu_group", dev->path) < 0) + if (!dev_path) return NULL; =20 + if (virAsprintf(&iommu_path, "%s/iommu_group", dev_path) < 0) + goto cleanup; + if (!virFileExists(iommu_path)) { virReportSystemError(errno, _("failed to access '%s'"), iommu_path= ); goto cleanup; } =20 - if (virFileResolveLink(iommu_path, &resultpath) < 0) { + if (virFileResolveLink(iommu_path, &result_path) < 0) { virReportSystemError(errno, _("failed to resolve '%s'"), iommu_pat= h); goto cleanup; } =20 - if (virAsprintf(&vfio_path, "/dev/vfio/%s", last_component(resultpath)= ) < 0) + if (virAsprintf(&vfio_path, "/dev/vfio/%s", last_component(result_path= )) < 0) goto cleanup; =20 cleanup: - VIR_FREE(resultpath); + VIR_FREE(result_path); VIR_FREE(iommu_path); + VIR_FREE(dev_path); return vfio_path; } =20 =20 int -virMediatedDeviceGetIOMMUGroupNum(virMediatedDevicePtr dev) +virMediatedDeviceGetIOMMUGroupNum(const char *uuidstr) { char *vfio_path =3D NULL; char *group_num_str =3D NULL; unsigned int group_num =3D -1; =20 - if (!(vfio_path =3D virMediatedDeviceGetIOMMUGroupDev(dev))) + if (!(vfio_path =3D virMediatedDeviceGetIOMMUGroupDev(uuidstr))) return -1; =20 group_num_str =3D last_component(vfio_path); diff --git a/src/util/virmdev.h b/src/util/virmdev.h index 8bb46b9c5..0b8e830f4 100644 --- a/src/util/virmdev.h +++ b/src/util/virmdev.h @@ -65,10 +65,10 @@ virMediatedDeviceSetUsedBy(virMediatedDevicePtr dev, const char *domname); =20 char * -virMediatedDeviceGetIOMMUGroupDev(virMediatedDevicePtr dev); +virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr); =20 int -virMediatedDeviceGetIOMMUGroupNum(virMediatedDevicePtr dev); +virMediatedDeviceGetIOMMUGroupNum(const char *uuidstr); =20 char * virMediatedDeviceGetSysfsPath(const char *uuidstr); --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 16:19:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 149485021207935.68512674795704; Mon, 15 May 2017 05:10:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 429D63D955; Mon, 15 May 2017 12:10:10 +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 041EF17C49; Mon, 15 May 2017 12:10:10 +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 D46F24BB74; Mon, 15 May 2017 12:10:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4FCA6Hd011847 for ; Mon, 15 May 2017 08:10:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id C418B7D4EE; Mon, 15 May 2017 12:10:06 +0000 (UTC) Received: from beluga.usersys.redhat.com (dhcp129-94.brq.redhat.com [10.34.129.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0BDA7D4FB; Mon, 15 May 2017 12:10:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 429D63D955 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 429D63D955 From: Erik Skultety To: libvir-list@redhat.com Date: Mon, 15 May 2017 14:10:18 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v4 2/6] nodedev: conf: Split PCI sub-capability parsing to separate methods 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 15 May 2017 12:10:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since there's at least SRIOV and MDEV sub-capabilities to be parsed, let's make the code more readable by splitting it to several logical blocks. Signed-off-by: Erik Skultety Reviewed-by: John Ferlan --- src/conf/node_device_conf.c | 142 ++++++++++++++++++++++++++--------------= ---- 1 file changed, 83 insertions(+), 59 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 85cfd8396..7aab2e03c 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -1286,76 +1286,102 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, =20 =20 static int +virNodeDevPCICapSRIOVPhysicalParseXML(xmlXPathContextPtr ctxt, + virNodeDevCapPCIDevPtr pci_dev) +{ + xmlNodePtr address =3D virXPathNode("./address[1]", ctxt); + + if (VIR_ALLOC(pci_dev->physical_function) < 0) + return -1; + + if (!address) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Missing address in 'phys_function' capability")); + return -1; + } + + if (virPCIDeviceAddressParseXML(address, + pci_dev->physical_function) < 0) + return -1; + + pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION; + + return 0; +} + + +static int +virNodeDevPCICapSRIOVVirtualParseXML(xmlXPathContextPtr ctxt, + virNodeDevCapPCIDevPtr pci_dev) +{ + int ret =3D -1; + xmlNodePtr *addresses =3D NULL; + int naddresses =3D virXPathNodeSet("./address", ctxt, &addresses); + char *maxFuncsStr =3D virXPathString("string(./@maxCount)", ctxt); + size_t i; + + if (naddresses < 0) + goto cleanup; + + if (maxFuncsStr && + virStrToLong_uip(maxFuncsStr, NULL, 10, + &pci_dev->max_virtual_functions) < 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Malformed 'maxCount' parameter")); + goto cleanup; + } + + if (VIR_ALLOC_N(pci_dev->virtual_functions, naddresses) < 0) + goto cleanup; + + for (i =3D 0; i < naddresses; i++) { + virPCIDeviceAddressPtr addr =3D NULL; + + if (VIR_ALLOC(addr) < 0) + goto cleanup; + + if (virPCIDeviceAddressParseXML(addresses[i], addr) < 0) { + VIR_FREE(addr); + goto cleanup; + } + + if (VIR_APPEND_ELEMENT(pci_dev->virtual_functions, + pci_dev->num_virtual_functions, + addr) < 0) + goto cleanup; + } + + pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION; + ret =3D 0; + cleanup: + VIR_FREE(addresses); + VIR_FREE(maxFuncsStr); + return ret; +} + + +static int virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, xmlNodePtr node, virNodeDevCapPCIDevPtr pci_dev) { - char *maxFuncsStr =3D virXMLPropString(node, "maxCount"); char *type =3D virXMLPropString(node, "type"); - xmlNodePtr *addresses =3D NULL; xmlNodePtr orignode =3D ctxt->node; int ret =3D -1; - size_t i =3D 0; =20 ctxt->node =3D node; =20 if (!type) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing capability type= ")); - goto out; + goto cleanup; } =20 - if (STREQ(type, "phys_function")) { - xmlNodePtr address =3D virXPathNode("./address[1]", ctxt); - - if (VIR_ALLOC(pci_dev->physical_function) < 0) - goto out; - - if (!address) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Missing address in 'phys_function' capabilit= y")); - goto out; - } - - if (virPCIDeviceAddressParseXML(address, - pci_dev->physical_function) < 0) - goto out; - - pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION; - } else if (STREQ(type, "virt_functions")) { - int naddresses; - - if ((naddresses =3D virXPathNodeSet("./address", ctxt, &addresses)= ) < 0) - goto out; - - if (maxFuncsStr && - virStrToLong_uip(maxFuncsStr, NULL, 10, - &pci_dev->max_virtual_functions) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Malformed 'maxCount' parameter")); - goto out; - } - - if (VIR_ALLOC_N(pci_dev->virtual_functions, naddresses) < 0) - goto out; - - for (i =3D 0; i < naddresses; i++) { - virPCIDeviceAddressPtr addr =3D NULL; - - if (VIR_ALLOC(addr) < 0) - goto out; - - if (virPCIDeviceAddressParseXML(addresses[i], addr) < 0) { - VIR_FREE(addr); - goto out; - } - - if (VIR_APPEND_ELEMENT(pci_dev->virtual_functions, - pci_dev->num_virtual_functions, - addr) < 0) - goto out; - } - - pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION; + if (STREQ(type, "phys_function") && + virNodeDevPCICapSRIOVPhysicalParseXML(ctxt, pci_dev) < 0) { + goto cleanup; + } else if (STREQ(type, "virt_functions") && + virNodeDevPCICapSRIOVVirtualParseXML(ctxt, pci_dev) < 0) { + goto cleanup; } else { int hdrType =3D virPCIHeaderTypeFromString(type); =20 @@ -1364,9 +1390,7 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ct= xt, } =20 ret =3D 0; - out: - VIR_FREE(addresses); - VIR_FREE(maxFuncsStr); + cleanup: VIR_FREE(type); ctxt->node =3D orignode; return ret; --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 16:19:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1494850228157978.2332930652495; Mon, 15 May 2017 05:10:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 46CB380F96; Mon, 15 May 2017 12:10:23 +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 15DB417F4D; Mon, 15 May 2017 12:10:23 +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 B6C7A5ED67; Mon, 15 May 2017 12:10:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4FCA7H3011854 for ; Mon, 15 May 2017 08:10:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id D6EBE7D4E8; Mon, 15 May 2017 12:10:07 +0000 (UTC) Received: from beluga.usersys.redhat.com (dhcp129-94.brq.redhat.com [10.34.129.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E4F45C6EC; Mon, 15 May 2017 12:10:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 46CB380F96 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 46CB380F96 From: Erik Skultety To: libvir-list@redhat.com Date: Mon, 15 May 2017 14:10:19 +0200 Message-Id: <011fcf5724e0d647cc326a4110014a3fbda788ee.1494849511.git.eskultet@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v4 3/6] nodedev: Introduce new mdev_types and mdev nodedev capabilities 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 15 May 2017 12:10:25 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The reason for introducing two capabilities, one for the device itself (cap 'mdev') and one for the parent device listing the available types ('mdev_types'), is that we should be able to do 'virsh nodedev-list --cap' not only for existing mdev devices but also for devices that support creation of mdev devices, since one day libvirt might be actually able to create the mdev devices in an automated way (just like we do for NPIV/vHBA). Signed-off-by: Erik Skultety Reviewed-by: John Ferlan --- include/libvirt/libvirt-nodedev.h | 2 ++ src/conf/node_device_conf.c | 10 +++++++++- src/conf/node_device_conf.h | 6 +++++- src/conf/virnodedeviceobj.c | 4 +++- src/libvirt-nodedev.c | 2 ++ src/node_device/node_device_driver.c | 2 ++ src/node_device/node_device_udev.c | 3 +++ tools/virsh-nodedev.c | 6 ++++++ 8 files changed, 32 insertions(+), 3 deletions(-) diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 85003903d..1e3043787 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -79,6 +79,8 @@ typedef enum { VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS =3D 1 << 10, /* Capabl= e of vport */ VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC =3D 1 << 11, /* Capabl= e of scsi_generic */ VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM =3D 1 << 12, /* DRM de= vice */ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES =3D 1 << 13, /* Capabl= e of mediated devices */ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV =3D 1 << 14, /* Mediat= ed device */ } virConnectListAllNodeDeviceFlags; =20 int virConnectListAllNodeDevices (virConnectPtr conn, diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 7aab2e03c..40d71f277 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -60,7 +60,9 @@ VIR_ENUM_IMPL(virNodeDevCap, VIR_NODE_DEV_CAP_LAST, "fc_host", "vports", "scsi_generic", - "drm") + "drm", + "mdev_types", + "mdev") =20 VIR_ENUM_IMPL(virNodeDevNetCap, VIR_NODE_DEV_CAP_NET_LAST, "80203", @@ -540,6 +542,8 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def) case VIR_NODE_DEV_CAP_DRM: virBufferEscapeString(&buf, "%s\n", virNodeDevDRM= TypeToString(data->drm.type)); break; + case VIR_NODE_DEV_CAP_MDEV: + case VIR_NODE_DEV_CAP_MDEV_TYPES: case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: case VIR_NODE_DEV_CAP_LAST: @@ -1612,6 +1616,8 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, case VIR_NODE_DEV_CAP_DRM: ret =3D virNodeDevCapDRMParseXML(ctxt, def, node, &caps->data.drm); break; + case VIR_NODE_DEV_CAP_MDEV: + case VIR_NODE_DEV_CAP_MDEV_TYPES: case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: case VIR_NODE_DEV_CAP_SCSI_GENERIC: @@ -1930,6 +1936,8 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps) case VIR_NODE_DEV_CAP_SCSI_GENERIC: VIR_FREE(data->sg.path); break; + case VIR_NODE_DEV_CAP_MDEV: + case VIR_NODE_DEV_CAP_MDEV_TYPES: case VIR_NODE_DEV_CAP_DRM: case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index a5d5cdd2a..273d49f76 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -64,6 +64,8 @@ typedef enum { VIR_NODE_DEV_CAP_VPORTS, /* HBA which is capable of vports */ VIR_NODE_DEV_CAP_SCSI_GENERIC, /* SCSI generic device */ VIR_NODE_DEV_CAP_DRM, /* DRM device */ + VIR_NODE_DEV_CAP_MDEV_TYPES, /* Device capable of mediated device= s */ + VIR_NODE_DEV_CAP_MDEV, /* Mediated device */ =20 VIR_NODE_DEV_CAP_LAST } virNodeDevCapType; @@ -351,7 +353,9 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps); VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST | \ VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS | \ VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC | \ - VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM) + VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM | \ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES | \ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV) =20 char * virNodeDeviceGetParentName(virConnectPtr conn, diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 4f47b4e41..181d2efe1 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -550,7 +550,9 @@ virNodeDeviceMatch(virNodeDeviceObjPtr devobj, MATCH(FC_HOST) || MATCH(VPORTS) || MATCH(SCSI_GENERIC) || - MATCH(DRM))) + MATCH(DRM) || + MATCH(MDEV_TYPES) || + MATCH(MDEV))) return false; } =20 diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index 83376b0d9..44e2b4efd 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -98,6 +98,8 @@ virNodeNumOfDevices(virConnectPtr conn, const char *cap, = unsigned int flags) * VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS * VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC * VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM + * VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES + * VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV * * Returns the number of node devices found or -1 and sets @devices to NUL= L in * case of error. On success, the array stored into @devices is guarantee= d to diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index c3997c922..ba3da6288 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -82,6 +82,8 @@ static int update_caps(virNodeDeviceObjPtr dev) case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: case VIR_NODE_DEV_CAP_SCSI_GENERIC: + case VIR_NODE_DEV_CAP_MDEV_TYPES: + case VIR_NODE_DEV_CAP_MDEV: case VIR_NODE_DEV_CAP_LAST: break; } diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 6e706a10b..1ddb55c80 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -43,6 +43,7 @@ #include "virpci.h" #include "virstring.h" #include "virnetdev.h" +#include "virmdev.h" =20 #define VIR_FROM_THIS VIR_FROM_NODEDEV =20 @@ -1060,6 +1061,8 @@ static int udevGetDeviceDetails(struct udev_device *d= evice, return udevProcessSCSIGeneric(device, def); case VIR_NODE_DEV_CAP_DRM: return udevProcessDRMDevice(device, def); + case VIR_NODE_DEV_CAP_MDEV: + case VIR_NODE_DEV_CAP_MDEV_TYPES: case VIR_NODE_DEV_CAP_SYSTEM: case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index c69144021..ad96dda1f 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -454,6 +454,12 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd = ATTRIBUTE_UNUSED) case VIR_NODE_DEV_CAP_DRM: flags |=3D VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM; break; + case VIR_NODE_DEV_CAP_MDEV_TYPES: + flags |=3D VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES; + break; + case VIR_NODE_DEV_CAP_MDEV: + flags |=3D VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV; + break; case VIR_NODE_DEV_CAP_LAST: break; } --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 16:19:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1494850217747625.7240334671204; Mon, 15 May 2017 05:10:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 80AA380C27; Mon, 15 May 2017 12:10:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4DB855C6F3; Mon, 15 May 2017 12:10:13 +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 DD9311868CA3; Mon, 15 May 2017 12:10:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4FCABAC011870 for ; Mon, 15 May 2017 08:10:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 036845C6EC; Mon, 15 May 2017 12:10:11 +0000 (UTC) Received: from beluga.usersys.redhat.com (dhcp129-94.brq.redhat.com [10.34.129.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 561175C6F3; Mon, 15 May 2017 12:10:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 80AA380C27 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 80AA380C27 From: Erik Skultety To: libvir-list@redhat.com Date: Mon, 15 May 2017 14:10:20 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v4 4/6] nodedev: Introduce the mdev capability to a PCI parent device 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 15 May 2017 12:10:14 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The parent device needs to report the generic stuff about the supported mediated devices types, like device API, available instances, type name, etc. Therefore this patch introduces a new nested capability element of type 'mdev_types' with the resulting XML of the following format: ... ... optional_vendor_supplied_codename vfio-pci NUM ... ... ... Signed-off-by: Erik Skultety Reviewed-by: John Ferlan --- docs/schemas/nodedev.rng | 26 +++++ src/conf/node_device_conf.c | 97 +++++++++++++++++ src/conf/node_device_conf.h | 15 +++ src/conf/virnodedeviceobj.c | 7 ++ src/libvirt_private.syms | 1 + src/node_device/node_device_udev.c | 119 +++++++++++++++++= ++++ .../pci_0000_02_10_7_mdev_types.xml | 32 ++++++ tests/nodedevxml2xmltest.c | 1 + 8 files changed, 298 insertions(+) create mode 100644 tests/nodedevschemadata/pci_0000_02_10_7_mdev_types.xml diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng index 0f90a73c8..e0a2c5032 100644 --- a/docs/schemas/nodedev.rng +++ b/docs/schemas/nodedev.rng @@ -205,6 +205,32 @@ =20 + + + mdev_types + + + + + + + + + + + + vfio-pci + + + + + + + + + + + diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 40d71f277..f26b1ffc7 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -89,6 +89,19 @@ virNodeDevCapsDefParseString(const char *xpath, =20 =20 void +virNodeDevCapMdevTypeFree(virNodeDevCapMdevTypePtr type) +{ + if (!type) + return; + + VIR_FREE(type->id); + VIR_FREE(type->name); + VIR_FREE(type->device_api); + VIR_FREE(type); +} + + +void virNodeDeviceDefFree(virNodeDeviceDefPtr def) { virNodeDevCapsDefPtr caps; @@ -265,6 +278,27 @@ virNodeDeviceCapPCIDefFormat(virBufferPtr buf, virBufferAsprintf(buf, "\n", virPCIHeaderTypeToString(data->pci_dev.hdrType)); } + if (data->pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCI_MDEV) { + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + for (i =3D 0; i < data->pci_dev.nmdev_types; i++) { + virNodeDevCapMdevTypePtr type =3D data->pci_dev.mdev_types[i]; + virBufferEscapeString(buf, "\n", type->id); + virBufferAdjustIndent(buf, 2); + if (type->name) + virBufferEscapeString(buf, "%s\n", + type->name); + virBufferEscapeString(buf, "%s\n", + type->device_api); + virBufferAsprintf(buf, + "%u= \n", + type->available_instances); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + } + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + } if (data->pci_dev.nIommuGroupDevices) { virBufferAsprintf(buf, "\n", data->pci_dev.iommuGroupNumber); @@ -1365,6 +1399,63 @@ virNodeDevPCICapSRIOVVirtualParseXML(xmlXPathContext= Ptr ctxt, =20 =20 static int +virNodeDevPCICapMdevTypesParseXML(xmlXPathContextPtr ctxt, + virNodeDevCapPCIDevPtr pci_dev) +{ + int ret =3D -1; + xmlNodePtr orignode =3D NULL; + xmlNodePtr *nodes =3D NULL; + int nmdev_types =3D virXPathNodeSet("./type", ctxt, &nodes); + virNodeDevCapMdevTypePtr type =3D NULL; + size_t i; + + orignode =3D ctxt->node; + for (i =3D 0; i < nmdev_types; i++) { + ctxt->node =3D nodes[i]; + + if (VIR_ALLOC(type) < 0) + goto cleanup; + + if (!(type->id =3D virXPathString("string(./@id[1])", ctxt))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing 'id' attribute for mediated device's= " + " element")); + goto cleanup; + } + + if (!(type->device_api =3D virXPathString("string(./deviceAPI[1])"= , ctxt))) { + virReportError(VIR_ERR_XML_ERROR, + _("missing device API for mediated device type = '%s'"), + type->id); + goto cleanup; + } + + if (virXPathUInt("number(./availableInstances)", ctxt, + &type->available_instances) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("missing number of available instances for " + "mediated device type '%s'"), + type->id); + goto cleanup; + } + + type->name =3D virXPathString("string(./name)", ctxt); + + if (VIR_APPEND_ELEMENT(pci_dev->mdev_types, + pci_dev->nmdev_types, type) < 0) + goto cleanup; + } + + pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_MDEV; + ret =3D 0; + cleanup: + virNodeDevCapMdevTypeFree(type); + ctxt->node =3D orignode; + return ret; +} + + +static int virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, xmlNodePtr node, virNodeDevCapPCIDevPtr pci_dev) @@ -1386,6 +1477,9 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ct= xt, } else if (STREQ(type, "virt_functions") && virNodeDevPCICapSRIOVVirtualParseXML(ctxt, pci_dev) < 0) { goto cleanup; + } else if (STREQ(type, "mdev_types") && + virNodeDevPCICapMdevTypesParseXML(ctxt, pci_dev) < 0) { + goto cleanup; } else { int hdrType =3D virPCIHeaderTypeFromString(type); =20 @@ -1899,6 +1993,9 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps) VIR_FREE(data->pci_dev.iommuGroupDevices[i]); VIR_FREE(data->pci_dev.iommuGroupDevices); virPCIEDeviceInfoFree(data->pci_dev.pci_express); + for (i =3D 0; i < data->pci_dev.nmdev_types; i++) + virNodeDevCapMdevTypeFree(data->pci_dev.mdev_types[i]); + VIR_FREE(data->pci_dev.mdev_types); break; case VIR_NODE_DEV_CAP_USB_DEV: VIR_FREE(data->usb_dev.product_name); diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 273d49f76..629f732e6 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -95,6 +95,7 @@ typedef enum { VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION =3D (1 << 0), VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION =3D (1 << 1), VIR_NODE_DEV_CAP_FLAG_PCIE =3D (1 << 2), + VIR_NODE_DEV_CAP_FLAG_PCI_MDEV =3D (1 << 3), } virNodeDevPCICapFlags; =20 typedef enum { @@ -133,6 +134,15 @@ struct _virNodeDevCapSystem { virNodeDevCapSystemFirmware firmware; }; =20 +typedef struct _virNodeDevCapMdevType virNodeDevCapMdevType; +typedef virNodeDevCapMdevType *virNodeDevCapMdevTypePtr; +struct _virNodeDevCapMdevType { + char *id; + char *name; + char *device_api; + unsigned int available_instances; +}; + typedef struct _virNodeDevCapPCIDev virNodeDevCapPCIDev; typedef virNodeDevCapPCIDev *virNodeDevCapPCIDevPtr; struct _virNodeDevCapPCIDev { @@ -156,6 +166,8 @@ struct _virNodeDevCapPCIDev { int numa_node; virPCIEDeviceInfoPtr pci_express; int hdrType; /* enum virPCIHeaderType or -1 */ + virNodeDevCapMdevTypePtr *mdev_types; + size_t nmdev_types; }; =20 typedef struct _virNodeDevCapUSBDev virNodeDevCapUSBDev; @@ -340,6 +352,9 @@ virNodeDeviceDefFree(virNodeDeviceDefPtr def); void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps); =20 +void +virNodeDevCapMdevTypeFree(virNodeDevCapMdevTypePtr type); + # define VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP \ (VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM | \ VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV | \ diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 181d2efe1..fc5f3708f 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -468,6 +468,13 @@ virNodeDeviceCapMatch(virNodeDeviceObjPtr devobj, VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS)) return true; } + + if (cap->data.type =3D=3D VIR_NODE_DEV_CAP_PCI_DEV) { + if (type =3D=3D VIR_NODE_DEV_CAP_MDEV_TYPES && + (cap->data.pci_dev.flags & + VIR_NODE_DEV_CAP_FLAG_PCI_MDEV)) + return true; + } } =20 return false; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index bbe283529..a2a30bd58 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -668,6 +668,7 @@ virNetDevIPRouteParseXML; =20 =20 # conf/node_device_conf.h +virNodeDevCapMdevTypeFree; virNodeDevCapsDefFree; virNodeDevCapTypeFromString; virNodeDevCapTypeToString; diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 1ddb55c80..4c75dec2b 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -314,6 +314,119 @@ static int udevTranslatePCIIds(unsigned int vendor, } =20 =20 +static int +udevFillMdevType(struct udev_device *device, + const char *dir, + virNodeDevCapMdevTypePtr type) +{ + int ret =3D -1; + char *attrpath =3D NULL; + +#define MDEV_GET_SYSFS_ATTR(attr_name, cb, ...) = \ + do { = \ + if (virAsprintf(&attrpath, "%s/%s", dir, #attr_name) < 0) = \ + goto cleanup; = \ + = \ + if (cb(device, attrpath, __VA_ARGS__) < 0) = \ + goto cleanup; = \ + = \ + VIR_FREE(attrpath); = \ + } while (0) = \ + + if (VIR_STRDUP(type->id, last_component(dir)) < 0) + goto cleanup; + + /* query udev for the attributes under subdirectories using the relati= ve + * path stored in @dir, i.e. 'mdev_supported_types/' + */ + MDEV_GET_SYSFS_ATTR(name, udevGetStringSysfsAttr, &type->name); + MDEV_GET_SYSFS_ATTR(device_api, udevGetStringSysfsAttr, &type->device_= api); + MDEV_GET_SYSFS_ATTR(available_instances, udevGetUintSysfsAttr, + &type->available_instances, 10); + +#undef MDEV_GET_SYSFS_ATTR + + ret =3D 0; + cleanup: + VIR_FREE(attrpath); + return ret; +} + + +static int +udevPCIGetMdevTypesCap(struct udev_device *device, + virNodeDevCapPCIDevPtr pcidata) +{ + int ret =3D -1; + int dirret =3D -1; + DIR *dir =3D NULL; + struct dirent *entry; + char *path =3D NULL; + char *tmppath =3D NULL; + virNodeDevCapMdevTypePtr type =3D NULL; + virNodeDevCapMdevTypePtr *types =3D NULL; + size_t ntypes =3D 0; + size_t i; + + if (virAsprintf(&path, "%s/mdev_supported_types", + udev_device_get_syspath(device)) < 0) + return -1; + + if ((dirret =3D virDirOpenIfExists(&dir, path)) < 0) + goto cleanup; + + if (dirret =3D=3D 0) { + ret =3D 0; + goto cleanup; + } + + if (VIR_ALLOC(types) < 0) + goto cleanup; + + /* UDEV doesn't report attributes under subdirectories by default but = is + * able to query them if the path to the attribute is relative to the + * device's base path, e.g. /sys/devices/../0000:00:01.0/ is the devic= e's + * base path as udev reports it, but we're interested in attributes un= der + * /sys/devices/../0000:00:01.0/mdev_supported_types//. So, we n= eed to + * scan the subdirectories ourselves. + */ + while ((dirret =3D virDirRead(dir, &entry, path)) > 0) { + if (VIR_ALLOC(type) < 0) + goto cleanup; + + /* construct the relative mdev type path bit for udev */ + if (virAsprintf(&tmppath, "mdev_supported_types/%s", entry->d_name= ) < 0) + goto cleanup; + + if (udevFillMdevType(device, tmppath, type) < 0) + goto cleanup; + + if (VIR_APPEND_ELEMENT(types, ntypes, type) < 0) + goto cleanup; + + VIR_FREE(tmppath); + } + + if (dirret < 0) + goto cleanup; + + VIR_STEAL_PTR(pcidata->mdev_types, types); + pcidata->nmdev_types =3D ntypes; + pcidata->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_MDEV; + ntypes =3D 0; + ret =3D 0; + cleanup: + virNodeDevCapMdevTypeFree(type); + for (i =3D 0; i < ntypes; i++) + virNodeDevCapMdevTypeFree(types[i]); + VIR_FREE(types); + VIR_FREE(path); + VIR_FREE(tmppath); + VIR_DIR_CLOSE(dir); + return ret; +} + + static int udevProcessPCI(struct udev_device *device, virNodeDeviceDefPtr def) { @@ -400,6 +513,12 @@ static int udevProcessPCI(struct udev_device *device, } } =20 + /* check whether the device is mediated devices framework capable, if = so, + * process it + */ + if (udevPCIGetMdevTypesCap(device, pci_dev) < 0) + goto cleanup; + ret =3D 0; =20 cleanup: diff --git a/tests/nodedevschemadata/pci_0000_02_10_7_mdev_types.xml b/test= s/nodedevschemadata/pci_0000_02_10_7_mdev_types.xml new file mode 100644 index 000000000..a2d57569a --- /dev/null +++ b/tests/nodedevschemadata/pci_0000_02_10_7_mdev_types.xml @@ -0,0 +1,32 @@ + + pci_0000_02_10_7 + pci_0000_00_04_0 + + 0 + 2 + 16 + 7 + 82576 Virtual Function + Intel Corporation + + + bar1 + vfio-pci + 1 + + + bar2 + vfio-pci + 2 + + + +
+ + + + + + + + diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c index f023d8a13..e3a77646c 100644 --- a/tests/nodedevxml2xmltest.c +++ b/tests/nodedevxml2xmltest.c @@ -101,6 +101,7 @@ mymain(void) DO_TEST("pci_0000_02_10_7_sriov_pf_vfs_all"); DO_TEST("pci_0000_02_10_7_sriov_pf_vfs_all_header_type"); DO_TEST("drm_renderD129"); + DO_TEST("pci_0000_02_10_7_mdev_types"); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 16:19:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1494850229468325.21809245445866; Mon, 15 May 2017 05:10:29 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A878368A7; Mon, 15 May 2017 12:10:27 +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 825FF17C49; Mon, 15 May 2017 12:10:27 +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 31A575ED6B; Mon, 15 May 2017 12:10:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4FCACkj011878 for ; Mon, 15 May 2017 08:10:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7E6AC5C6E9; Mon, 15 May 2017 12:10:12 +0000 (UTC) Received: from beluga.usersys.redhat.com (dhcp129-94.brq.redhat.com [10.34.129.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A6966031D; Mon, 15 May 2017 12:10:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A878368A7 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A878368A7 From: Erik Skultety To: libvir-list@redhat.com Date: Mon, 15 May 2017 14:10:21 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v4 5/6] nodedev: Introduce mdev capability for mediated devices 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 15 May 2017 12:10:28 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Start discovering the mediated devices on the host system and format the attributes for the mediated device into the XML. Compared to the parent device which reports generic information about the abstract mediated devices types, a child device only reports the type name it has been instantiated from and the IOMMU group number, since that's device specific compared to the rest of the info that can be gathered about mediated devices at the moment. This patch introduces both the formatting and parsing routines, updates nodedev.rng schema, adding a testcase as well. The resulting mdev child device XML: mdev_4b20d080_1b54_4048_85b3_a6a62d165c01 /sys/devices/.../4b20d080-1b54-4048-85b3-a6a62d165c01 pci_0000_06_00_0 vfio_mdev Signed-off-by: Erik Skultety Reviewed-by: John Ferlan --- docs/schemas/nodedev.rng | 17 +++++++++ src/conf/node_device_conf.c | 41 ++++++++++++++++++= +++ src/conf/node_device_conf.h | 8 ++++ src/node_device/node_device_udev.c | 43 ++++++++++++++++++= +++- .../mdev_3627463d_b7f0_4fea_b468_f1da537d301b.xml | 8 ++++ tests/nodedevxml2xmltest.c | 1 + 6 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 tests/nodedevschemadata/mdev_3627463d_b7f0_4fea_b468_f1= da537d301b.xml diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng index e0a2c5032..924f73861 100644 --- a/docs/schemas/nodedev.rng +++ b/docs/schemas/nodedev.rng @@ -83,6 +83,7 @@ + @@ -580,6 +581,22 @@ =20 + + + mdev + + + + + + + + + + + + + diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index f26b1ffc7..bdb6c9cf7 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -577,6 +577,10 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def) virBufferEscapeString(&buf, "%s\n", virNodeDevDRM= TypeToString(data->drm.type)); break; case VIR_NODE_DEV_CAP_MDEV: + virBufferEscapeString(&buf, "\n", data->mdev.= type); + virBufferAsprintf(&buf, "\n", + data->mdev.iommuGroupNumber); + break; case VIR_NODE_DEV_CAP_MDEV_TYPES: case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: @@ -1643,6 +1647,39 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, } =20 =20 +static int +virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapMdevPtr mdev) +{ + xmlNodePtr orignode; + int ret =3D -1; + + orignode =3D ctxt->node; + ctxt->node =3D node; + + if (!(mdev->type =3D virXPathString("string(./type[1]/@id)", ctxt))) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("missing type id attribute for '%s'"), def->name); + goto out; + } + + if (virNodeDevCapsDefParseULong("number(./iommuGroup[1]/@number)", ctx= t, + &mdev->iommuGroupNumber, def, + _("missing iommuGroup number atribute = for " + "'%s'"), + _("invalid iommuGroup number attribute= for " + "'%s'")) < 0) + goto out; + + ret =3D 0; + out: + ctxt->node =3D orignode; + return ret; +} + + static virNodeDevCapsDefPtr virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, @@ -1711,6 +1748,8 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, ret =3D virNodeDevCapDRMParseXML(ctxt, def, node, &caps->data.drm); break; case VIR_NODE_DEV_CAP_MDEV: + ret =3D virNodeDevCapMdevParseXML(ctxt, def, node, &caps->data.mde= v); + break; case VIR_NODE_DEV_CAP_MDEV_TYPES: case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: @@ -2034,6 +2073,8 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps) VIR_FREE(data->sg.path); break; case VIR_NODE_DEV_CAP_MDEV: + VIR_FREE(data->mdev.type); + break; case VIR_NODE_DEV_CAP_MDEV_TYPES: case VIR_NODE_DEV_CAP_DRM: case VIR_NODE_DEV_CAP_FC_HOST: diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 629f732e6..cea9247d2 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -143,6 +143,13 @@ struct _virNodeDevCapMdevType { unsigned int available_instances; }; =20 +typedef struct _virNodeDevCapMdev virNodeDevCapMdev; +typedef virNodeDevCapMdev *virNodeDevCapMdevPtr; +struct _virNodeDevCapMdev { + char *type; + unsigned int iommuGroupNumber; +}; + typedef struct _virNodeDevCapPCIDev virNodeDevCapPCIDev; typedef virNodeDevCapPCIDev *virNodeDevCapPCIDevPtr; struct _virNodeDevCapPCIDev { @@ -276,6 +283,7 @@ struct _virNodeDevCapData { virNodeDevCapStorage storage; virNodeDevCapSCSIGeneric sg; virNodeDevCapDRM drm; + virNodeDevCapMdev mdev; }; }; =20 diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 4c75dec2b..8288be1cb 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1069,6 +1069,42 @@ udevProcessSCSIGeneric(struct udev_device *dev, } =20 static int +udevProcessMediatedDevice(struct udev_device *dev, + virNodeDeviceDefPtr def) +{ + int ret =3D -1; + const char *uuidstr =3D NULL; + int iommugrp =3D -1; + char *linkpath =3D NULL; + char *realpath =3D NULL; + virNodeDevCapMdevPtr data =3D &def->caps->data.mdev; + + if (virAsprintf(&linkpath, "%s/mdev_type", udev_device_get_syspath(dev= )) < 0) + goto cleanup; + + if (virFileResolveLink(linkpath, &realpath) < 0) + goto cleanup; + + if (VIR_STRDUP(data->type, last_component(realpath)) < 0) + goto cleanup; + + uuidstr =3D udev_device_get_sysname(dev); + if ((iommugrp =3D virMediatedDeviceGetIOMMUGroupNum(uuidstr)) < 0) + goto cleanup; + + if (udevGenerateDeviceName(dev, def, NULL) !=3D 0) + goto cleanup; + + data->iommuGroupNumber =3D iommugrp; + + ret =3D 0; + cleanup: + VIR_FREE(linkpath); + VIR_FREE(realpath); + return ret; +} + +static int udevGetDeviceNodes(struct udev_device *device, virNodeDeviceDefPtr def) { @@ -1136,12 +1172,16 @@ udevGetDeviceType(struct udev_device *device, if (udevHasDeviceProperty(device, "INTERFACE")) *type =3D VIR_NODE_DEV_CAP_NET; =20 - /* SCSI generic device doesn't set DEVTYPE property */ + /* Neither SCSI generic devices nor mediated devices set DEVTYPE + * property, therefore we need to rely on the SUBSYSTEM property */ if (udevGetStringProperty(device, "SUBSYSTEM", &subsystem) < 0) return -1; =20 if (STREQ_NULLABLE(subsystem, "scsi_generic")) *type =3D VIR_NODE_DEV_CAP_SCSI_GENERIC; + else if (STREQ_NULLABLE(subsystem, "mdev")) + *type =3D VIR_NODE_DEV_CAP_MDEV; + VIR_FREE(subsystem); } =20 @@ -1181,6 +1221,7 @@ static int udevGetDeviceDetails(struct udev_device *d= evice, case VIR_NODE_DEV_CAP_DRM: return udevProcessDRMDevice(device, def); case VIR_NODE_DEV_CAP_MDEV: + return udevProcessMediatedDevice(device, def); case VIR_NODE_DEV_CAP_MDEV_TYPES: case VIR_NODE_DEV_CAP_SYSTEM: case VIR_NODE_DEV_CAP_FC_HOST: diff --git a/tests/nodedevschemadata/mdev_3627463d_b7f0_4fea_b468_f1da537d3= 01b.xml b/tests/nodedevschemadata/mdev_3627463d_b7f0_4fea_b468_f1da537d301b= .xml new file mode 100644 index 000000000..470e5917e --- /dev/null +++ b/tests/nodedevschemadata/mdev_3627463d_b7f0_4fea_b468_f1da537d301b.xml @@ -0,0 +1,8 @@ + + mdev_3627463d_b7f0_4fea_b468_f1da537d301b + computer + + + + + diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c index e3a77646c..a2aad518d 100644 --- a/tests/nodedevxml2xmltest.c +++ b/tests/nodedevxml2xmltest.c @@ -102,6 +102,7 @@ mymain(void) DO_TEST("pci_0000_02_10_7_sriov_pf_vfs_all_header_type"); DO_TEST("drm_renderD129"); DO_TEST("pci_0000_02_10_7_mdev_types"); + DO_TEST("mdev_3627463d_b7f0_4fea_b468_f1da537d301b"); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 16:19:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1494850232087828.1472819241652; Mon, 15 May 2017 05:10:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68895C054C52; Mon, 15 May 2017 12:10:27 +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 2C8677EBE5; Mon, 15 May 2017 12:10:27 +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 CBE9E5ED67; Mon, 15 May 2017 12:10:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4FCADKA011885 for ; Mon, 15 May 2017 08:10:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 82FAE6031D; Mon, 15 May 2017 12:10:13 +0000 (UTC) Received: from beluga.usersys.redhat.com (dhcp129-94.brq.redhat.com [10.34.129.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id CBBA85C6E9; Mon, 15 May 2017 12:10:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 68895C054C52 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 68895C054C52 From: Erik Skultety To: libvir-list@redhat.com Date: Mon, 15 May 2017 14:10:22 +0200 Message-Id: <428a22b317ca76a080d87981e89738cb523301e0.1494849511.git.eskultet@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v4 6/6] docs: Document the mediated devices within the nodedev driver 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 15 May 2017 12:10:28 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Erik Skultety Reviewed-by: John Ferlan --- docs/drvnodedev.html.in | 168 ++++++++++++++++++++++++++++++++++++++++++++= +++- tools/virsh.pod | 7 +- 2 files changed, 171 insertions(+), 4 deletions(-) diff --git a/docs/drvnodedev.html.in b/docs/drvnodedev.html.in index 0a3870343..26c52dd0d 100644 --- a/docs/drvnodedev.html.in +++ b/docs/drvnodedev.html.in @@ -9,7 +9,7 @@ (historically also referred to as node devices) like USB, PCI, SCSI,= and network devices. This also includes various virtualization capabilit= ies which the aforementioned devices provide for utilization, for example - SR-IOV, NPIV, DRM, etc. + SR-IOV, NPIV, MDEV, DRM, etc.

=20

@@ -75,6 +75,7 @@ storage (Since 1.0.4), scsi_generic (Since 1.0.7), drm (Since 3.1.0), and + mdev (Since 3.4.0). This element can be nested in which case it further specifies a device's capability. Refer to specific device types to see more = values for the type attribute which are exclusive. @@ -185,5 +186,170 @@ ... <device> =20 +

MDEV capability

+

+ A PCI device capable of creating mediated devices will include a nes= ted + capability mdev_types which enumerates all supported md= ev + types on the physical device, along with the type attributes availab= le + through sysfs: +

+ +
+
type
+
+ This element describes a mediated device type which acts as an + abstract template defining a resource allocation for instances of = this + device type. The element has one attribute id which h= olds + an official vendor-supplied identifier for the type. + Since 3.4.0 +
+ +
name
+
+ The name element holds a vendor-supplied code name for + the given mediated device type. This is an optional element. + Since 3.4.0 +
+ +
deviceAPI
+
+ The value of this element describes how an instance of the given t= ype + will be presented to the guest by the VFIO framework. + Since 3.4.0 +
+ +
availableInstances
+
+ This element reports the current state of resource allocation. In = other + words, how many instances of the given type can still be successfu= lly + created on the physical device. + Since 3.4.0 +
+
+ +

+ For a more info about mediated devices, refer to the + paragraph below. +

+ +
+<device>
+...
+  <driver>
+    <name>nvidia</name>
+  </driver>
+  <capability type=3D'pci'>
+...
+    <capability type=3D'mdev_types'>
+      <type id=3D'nvidia-11'>
+        <name>GRID M60-0B</name>
+        <deviceAPI>vfio-pci</deviceAPI>
+        <availableInstances>16</availableInstances>
+      </type>
+      <!-- Here would come the rest of the available mdev types -->
+    </capability>
+...
+  </capability>
+</device>
+ +

Mediated devices (MDEVs)

+

+ Mediated devices (Since 3.2.0) are soft= ware + devices defining resource allocation on the backing physical device = which + in turn allows the parent physical device's resources to be divided = into + several mediated devices, thus sharing the physical device's perform= ance + among multiple guests. Unlike SR-IOV however, where a PCIe device ap= pears + as multiple separate PCIe devices on the host's PCI bus, mediated de= vices + only appear on the mdev virtual bus. Therefore, no detach/reattach + procedure from/to the host driver procedure is involved even though + mediated devices are used in a direct device assignment manner. +

+ +

+ The following sub-elements and attributes are exposed within the + capability element: +

+ +
+
type
+
+ This element describes a mediated device type which acts as an + abstract template defining a resource allocation for instances of = this + device type. The element has one attribute id which h= olds + an official vendor-supplied identifier for the type. + Since 3.4.0 +
+ +
iommuGroup
+
+ This element supports a single attribute number which= holds + the IOMMU group number the mediated device belongs to. + Since 3.4.0 +
+
+ +

Example of a mediated device

+
+<device>
+  <name>mdev_4b20d080_1b54_4048_85b3_a6a62d165c01</name>
+  <path>/sys/devices/pci0000:00/0000:00:02.0/4b20d080-1b54-4048-85b3=
-a6a62d165c01</path>
+  <parent>pci_0000_06_00_0</parent>
+  <driver>
+    <name>vfio_mdev</name>
+  </driver>
+  <capability type=3D'mdev'>
+    <type id=3D'nvidia-11'/>
+    <iommuGroup number=3D'12'/>
+  <capability/>
+<device/>
+ +

+ The support of mediated device's framework in libvirt's node device = driver + covers the following features: +

+ +
    +
  • + list available mediated devices on the host + (Since 3.4.0) +
  • +
  • + display device details + (Since 3.4.0) +
  • +
+ +

+ Because mediated devices are instantiated from vendor specific templ= ates, + simply called 'types', information describing these types is contain= ed + within the parent device's capabilities + (see the example in PCI host devices). +

+ +

+ To see the supported mediated device types on a specific physical de= vice + use the following: +

+ +
+$ ls /sys/class/mdev_bus/<device>/mdev_supported_types
+ +

+ To manually instantiate a mediated device, use one of the following = as a + reference: +

+ +
+$ uuidgen > /sys/class/mdev_bus/<device>/mdev_supported_types/<=
;type>/create
+...
+$ echo <UUID> > /sys/class/mdev_bus/<device>/mdev_supported=
_types/<type>/create
+ +

+ Manual removal of a mediated device is then performed as follows: +

+ +
+$ echo 1 > /sys/bus/mdev/devices/<uuid>/remove
+ diff --git a/tools/virsh.pod b/tools/virsh.pod index 727acf6e6..d69c8d87f 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3177,10 +3177,11 @@ for HBA). =20 List all of the devices available on the node that are known by libvirt. I is used to filter the list by capability types, the types must be -separated by comma, e.g. --cap pci,scsi, valid capability types include +separated by comma, e.g. --cap pci,scsi. Valid capability types include 'system', 'pci', 'usb_device', 'usb', 'net', 'scsi_host', 'scsi_target', -'scsi', 'storage', 'fc_host', 'vports', 'scsi_generic', 'drm'.If I<--tree> -is used, the output is formatted in a tree representing parents of each +'scsi', 'storage', 'fc_host', 'vports', 'scsi_generic', 'drm', 'mdev', +'mdev_types'. +If I<--tree> is used, the output is formatted in a tree representing paren= ts of each node. I and I<--tree> are mutually exclusive. =20 =3Ditem B I --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list