From nobody Fri May 3 16:30:51 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 1493218553599465.96207426319427; Wed, 26 Apr 2017 07:55:53 -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 9E575811AC; Wed, 26 Apr 2017 14:55:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6593596556; Wed, 26 Apr 2017 14:55: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 10E5D5EC66; Wed, 26 Apr 2017 14:55:46 +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 v3QEtTYX017122 for ; Wed, 26 Apr 2017 10:55:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7131288851; Wed, 26 Apr 2017 14:55:29 +0000 (UTC) Received: from beluga.usersys.redhat.com.com (dhcp129-94.brq.redhat.com [10.34.129.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id A10988884E; Wed, 26 Apr 2017 14:55:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9E575811AC 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 9E575811AC From: Erik Skultety To: libvir-list@redhat.com Date: Wed, 26 Apr 2017 16:55:28 +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 v3 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 26 Apr 2017 14:55:52 +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 --- There's more than this, e.g. all hostdevs do it like that, but that's a refactor for another day. 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 00b0b4ac4..73c7447d7 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7102,7 +7102,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; @@ -7203,11 +7202,7 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, } 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; freeTmpPath =3D true; @@ -7263,7 +7258,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, case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { char *vfiodev =3D NULL; - virMediatedDevicePtr mdev =3D virMediatedDeviceNew(mdevsrc->uuidst= r, - mdevsrc->model); - if (!mdev) + if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuids= tr))) goto done; - if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdev))) { - virMediatedDeviceFree(mdev); - goto done; - } - ret =3D AppArmorSetSecurityHostdevLabelHelper(vfiodev, ptr); VIR_FREE(vfiodev); - virMediatedDeviceFree(mdev); break; } 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, case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { char *vfiodev =3D NULL; - virMediatedDevicePtr mdev =3D virMediatedDeviceNew(mdevsrc->uuidst= r, - mdevsrc->model); - if (!mdev) + if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuids= tr))) goto done; - if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdev))) { - virMediatedDeviceFree(mdev); - goto done; - } - ret =3D virSecurityDACSetHostdevLabelHelper(vfiodev, &cbdata); VIR_FREE(vfiodev); - virMediatedDeviceFree(mdev); break; } @@ -1144,21 +1136,13 @@ virSecurityDACRestoreHostdevLabel(virSecurityManage= rPtr mgr, case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { char *vfiodev =3D NULL; - virMediatedDevicePtr mdev =3D virMediatedDeviceNew(mdevsrc->uuidst= r, - mdevsrc->model); - if (!mdev) + if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuids= tr))) goto done; - if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdev))) { - virMediatedDeviceFree(mdev); - goto done; - } - ret =3D virSecurityDACRestoreFileLabel(virSecurityManagerGetPrivat= eData(mgr), vfiodev); VIR_FREE(vfiodev); - virMediatedDeviceFree(mdev); break; } 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, case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { char *vfiodev =3D NULL; - virMediatedDevicePtr mdev =3D virMediatedDeviceNew(mdevsrc->uuidst= r, - mdevsrc->model); - if (!mdev) + if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuids= tr))) goto done; - if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdev))) { - virMediatedDeviceFree(mdev); - goto done; - } - ret =3D virSecuritySELinuxSetHostdevLabelHelper(vfiodev, &data); VIR_FREE(vfiodev); - virMediatedDeviceFree(mdev); break; } @@ -2092,21 +2084,13 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecu= rityManagerPtr mgr, case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { char *vfiodev =3D NULL; - virMediatedDevicePtr mdev =3D virMediatedDeviceNew(mdevsrc->uuidst= r, - mdevsrc->model); - if (!mdev) + if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuids= tr))) goto done; - if (!(vfiodev =3D virMediatedDeviceGetIOMMUGroupDev(mdev))) { - virMediatedDeviceFree(mdev); - goto done; - } - ret =3D virSecuritySELinuxRestoreFileLabel(mgr, vfiodev); VIR_FREE(vfiodev); - virMediatedDeviceFree(mdev); break; } diff --git a/src/util/virmdev.c b/src/util/virmdev.c index 2a1ade739..85a3fec16 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); - if (virAsprintf(&iommu_path, "%s/iommu_group", dev->path) < 0) + if (!dev_path) return NULL; + 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; } - if (virFileResolveLink(iommu_path, &resultpath) < 0) { + if (virFileResolveLink(iommu_path, &result_path) < 0) { virReportSystemError(errno, _("failed to resolve '%s'"), iommu_pat= h); goto cleanup; } - 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; cleanup: - VIR_FREE(resultpath); + VIR_FREE(result_path); VIR_FREE(iommu_path); + VIR_FREE(dev_path); return vfio_path; } 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; - if (!(vfio_path =3D virMediatedDeviceGetIOMMUGroupDev(dev))) + if (!(vfio_path =3D virMediatedDeviceGetIOMMUGroupDev(uuidstr))) return -1; group_num_str =3D last_component(vfio_path); diff --git a/src/util/virmdev.h b/src/util/virmdev.h index 2f3d6bb84..e2da8f5ab 100644 --- a/src/util/virmdev.h +++ b/src/util/virmdev.h @@ -65,10 +65,10 @@ virMediatedDeviceSetUsedBy(virMediatedDevicePtr dev, const char *domname); char * -virMediatedDeviceGetIOMMUGroupDev(virMediatedDevicePtr dev); +virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr); int -virMediatedDeviceGetIOMMUGroupNum(virMediatedDevicePtr dev); +virMediatedDeviceGetIOMMUGroupNum(const char *uuidstr); char * virMediatedDeviceGetSysfsPath(const char *uuidstr); -- 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 16:30:51 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 14932185520151020.4640448770576; Wed, 26 Apr 2017 07:55:52 -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 8DCC2C04BD28; Wed, 26 Apr 2017 14:55:50 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 65F77871D1; Wed, 26 Apr 2017 14:55:50 +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 202CA5EC69; Wed, 26 Apr 2017 14:55:50 +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 v3QEtUGq017130 for ; Wed, 26 Apr 2017 10:55:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 808F68884E; Wed, 26 Apr 2017 14:55:30 +0000 (UTC) Received: from beluga.usersys.redhat.com.com (dhcp129-94.brq.redhat.com [10.34.129.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id D950188857; Wed, 26 Apr 2017 14:55:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8DCC2C04BD28 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.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 8DCC2C04BD28 From: Erik Skultety To: libvir-list@redhat.com Date: Wed, 26 Apr 2017 16:55:29 +0200 Message-Id: <4878a847278a551d04487edb21ffa083650816e8.1493218185.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 v3 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.31]); Wed, 26 Apr 2017 14:55:51 +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 --- src/conf/node_device_conf.c | 130 ++++++++++++++++++++++++++--------------= ---- 1 file changed, 77 insertions(+), 53 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 85cfd8396..d70d9942c 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 -virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, - xmlNodePtr node, - virNodeDevCapPCIDevPtr pci_dev) +virNodeDevPCICapSRIOVPhysicalParseXML(xmlXPathContextPtr ctxt, + 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; - - ctxt->node =3D node; - - if (!type) { - virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing capability type= ")); - goto out; - } - - if (STREQ(type, "phys_function")) { - xmlNodePtr address =3D virXPathNode("./address[1]", ctxt); + xmlNodePtr address =3D virXPathNode("./address[1]", ctxt); =20 if (VIR_ALLOC(pci_dev->physical_function) < 0) - goto out; + return -1; =20 if (!address) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing address in 'phys_function' capabilit= y")); - goto out; + return -1; } =20 if (virPCIDeviceAddressParseXML(address, pci_dev->physical_function) < 0) - goto out; + return -1; =20 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; - } =20 - if (VIR_ALLOC_N(pci_dev->virtual_functions, naddresses) < 0) - goto out; + 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; =20 - for (i =3D 0; i < naddresses; i++) { - virPCIDeviceAddressPtr addr =3D NULL; + if (naddresses < 0) + goto cleanup; =20 - if (VIR_ALLOC(addr) < 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 cleanup; + } =20 - if (virPCIDeviceAddressParseXML(addresses[i], addr) < 0) { - VIR_FREE(addr); - goto out; - } + if (VIR_ALLOC_N(pci_dev->virtual_functions, naddresses) < 0) + goto cleanup; =20 - if (VIR_APPEND_ELEMENT(pci_dev->virtual_functions, - pci_dev->num_virtual_functions, - addr) < 0) - goto out; + 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; } =20 - pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION; + 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 *type =3D virXMLPropString(node, "type"); + xmlNodePtr orignode =3D ctxt->node; + int ret =3D -1; + + ctxt->node =3D node; + + if (!type) { + virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing capability type= ")); + goto cleanup; + } + + 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.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 16:30:51 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 1493218556171320.45587496330313; Wed, 26 Apr 2017 07:55:56 -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 4813579360; Wed, 26 Apr 2017 14:55:54 +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 1F693871D8; Wed, 26 Apr 2017 14:55:54 +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 BF9E518523D6; Wed, 26 Apr 2017 14:55:53 +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 v3QEtVHS017137 for ; Wed, 26 Apr 2017 10:55:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 749438884E; Wed, 26 Apr 2017 14:55:31 +0000 (UTC) Received: from beluga.usersys.redhat.com.com (dhcp129-94.brq.redhat.com [10.34.129.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC4F688849; Wed, 26 Apr 2017 14:55:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4813579360 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.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 4813579360 From: Erik Skultety To: libvir-list@redhat.com Date: Wed, 26 Apr 2017 16:55:30 +0200 Message-Id: <3dae9fccdca5bc5cc611dcdd9063953e255f86cd.1493218185.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 v3 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 26 Apr 2017 14:55:55 +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 --- 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 d70d9942c..24cb6d66f 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.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 16:30:51 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 149321853971070.70270536319072; Wed, 26 Apr 2017 07:55:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1025EC04B926; Wed, 26 Apr 2017 14:55:38 +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 D361F88644; Wed, 26 Apr 2017 14:55:37 +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 41DE218523D3; Wed, 26 Apr 2017 14:55:37 +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 v3QEtWD3017145 for ; Wed, 26 Apr 2017 10:55:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id AD2288884E; Wed, 26 Apr 2017 14:55:32 +0000 (UTC) Received: from beluga.usersys.redhat.com.com (dhcp129-94.brq.redhat.com [10.34.129.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF48388849; Wed, 26 Apr 2017 14:55:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1025EC04B926 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.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 1025EC04B926 From: Erik Skultety To: libvir-list@redhat.com Date: Wed, 26 Apr 2017 16:55:31 +0200 Message-Id: <8408f71309f69aa467e5ee7f7897523c05257146.1493218185.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 v3 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 26 Apr 2017 14:55:39 +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 --- docs/schemas/nodedev.rng | 26 +++++ src/conf/node_device_conf.c | 104 ++++++++++++++++++ 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, 305 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 24cb6d66f..b3012821a 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -88,6 +88,26 @@ virNodeDevCapsDefParseString(const char *xpath, } =20 =20 +static void +virNodeDevCapMdevTypeClear(virNodeDevCapMdevTypePtr type) +{ + VIR_FREE(type->id); + VIR_FREE(type->name); + VIR_FREE(type->device_api); +} + + +void +virNodeDevCapMdevTypeFree(virNodeDevCapMdevTypePtr type) +{ + if (!type) + return; + + virNodeDevCapMdevTypeClear(type); + VIR_FREE(type); +} + + void virNodeDeviceDefFree(virNodeDeviceDefPtr def) { @@ -265,6 +285,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) + virBufferAsprintf(buf, "%s\n", + type->name); + virBufferAsprintf(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 +1406,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 +1484,9 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ct= xt, } else if (STREQ(type, "virt_functions") && virNodeDevPCICapSRIOVVirtualParseXML(ctxt, pci_dev) < 0) { goto cleanup; + } if (STREQ(type, "mdev_types") && + virNodeDevPCICapMdevTypesParseXML(ctxt, pci_dev)) { + goto cleanup; } else { int hdrType =3D virPCIHeaderTypeFromString(type); =20 @@ -1899,6 +2000,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 83e979a2b..b22952960 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -665,6 +665,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.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 16:30:51 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 1493218560190310.4667359845598; Wed, 26 Apr 2017 07:56:00 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A92F43DBC8; Wed, 26 Apr 2017 14:55:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7FD218882E; Wed, 26 Apr 2017 14:55:58 +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 1B2BB5EC69; Wed, 26 Apr 2017 14:55:58 +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 v3QEtXH1017155 for ; Wed, 26 Apr 2017 10:55:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7EC7F5C46F; Wed, 26 Apr 2017 14:55:33 +0000 (UTC) Received: from beluga.usersys.redhat.com.com (dhcp129-94.brq.redhat.com [10.34.129.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id D741988858; Wed, 26 Apr 2017 14:55:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A92F43DBC8 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 A92F43DBC8 From: Erik Skultety To: libvir-list@redhat.com Date: Wed, 26 Apr 2017 16:55:32 +0200 Message-Id: <04c38ad235419650c66c2cfe3598cafb19666b7a.1493218185.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 v3 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 26 Apr 2017 14:55:59 +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 --- 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 b3012821a..01b48324c 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -584,6 +584,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: @@ -1650,6 +1654,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, @@ -1718,6 +1755,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: @@ -2041,6 +2080,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.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 16:30:51 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 1493218549026766.7755600903137; Wed, 26 Apr 2017 07:55:49 -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 CC2DE23E6D4; Wed, 26 Apr 2017 14:55:46 +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 9BD3888D62; Wed, 26 Apr 2017 14:55: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 435D318523D6; Wed, 26 Apr 2017 14:55:46 +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 v3QEtYMv017165 for ; Wed, 26 Apr 2017 10:55:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 88C8384DB3; Wed, 26 Apr 2017 14:55:34 +0000 (UTC) Received: from beluga.usersys.redhat.com.com (dhcp129-94.brq.redhat.com [10.34.129.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0FA85C46F; Wed, 26 Apr 2017 14:55:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CC2DE23E6D4 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.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 CC2DE23E6D4 From: Erik Skultety To: libvir-list@redhat.com Date: Wed, 26 Apr 2017 16:55:33 +0200 Message-Id: <70612ed83253b74c0aaed27f44fa0baedd6948aa.1493218185.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 v3 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 26 Apr 2017 14:55:48 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Erik Skultety --- docs/drvnodedev.html.in | 164 ++++++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 163 insertions(+), 1 deletion(-) diff --git a/docs/drvnodedev.html.in b/docs/drvnodedev.html.in index 0a3870343..8f820cca1 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.3.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,166 @@ ... <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.3.0 +
+ +
name
+
+ The name element holds a vendor-supplied code name for + the given mediated device type. This is an optional element. + Since 3.3.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.3.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.3.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.3.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.3.0 +
+ +
iommuGroup
+
+ This element supports a single attribute number which= holds + the IOMMU group number the mediated device belongs to. + Since 3.3.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.3.0) +
  • +
  • + display device details + (Since 3.3.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
+ --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list