From nobody Sat Feb 7 10:16:16 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1563194304; cv=none; d=zoho.com; s=zohoarc; b=cXnmeg2dqdXavgG36IvCBqm1kxJJaKkPRAcsVYubmRDcpThc4v466UD0lbPm+JI15fDajW2XhHGS8TNqz+XsbOZuSMhpLXIsZT7yiu35OLzY7I3vGPLffofRnr0x5b/ZujlAVr8w96l2CPrCloySHLG/heK7wigNT+6qXxZk2N0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563194304; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=kTGYlHiUsuYn4L/lUH0W/5g0tbDUkPKpJb4HdlRypvA=; b=F1xpY/d6dW650YKKNMvk4qgge7l1dnzz92r6RnKpx+3fp8DroZMZwVBJIo0rjqUmXGhAYGA3xbCRKyfSdFL+ir9Ib7nYvhahvEfVygXRIYKTprEehl+w8Ltm5UObDeTyMsMK40Lzk7Db8dhT4s+fAgjyIW0RNdhCIC3s8b6h1bI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1563194304544763.7677413945102; Mon, 15 Jul 2019 05:38:24 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hn0EI-0003hi-MY; Mon, 15 Jul 2019 12:37:18 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hn0EG-0003gr-Li for xen-devel@lists.xenproject.org; Mon, 15 Jul 2019 12:37:16 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 466b9e26-a6fd-11e9-8980-bc764e045a96; Mon, 15 Jul 2019 12:37:15 +0000 (UTC) X-Inumbo-ID: 466b9e26-a6fd-11e9-8980-bc764e045a96 Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=paul.durrant@citrix.com; spf=Pass smtp.mailfrom=Paul.Durrant@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of paul.durrant@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="paul.durrant@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of Paul.Durrant@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="Paul.Durrant@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: TFV180RhliG9CrBpWLmcMBWcvQgHNJgKLVRateFs1KbOIOuinIEKqmKhqFdBPI+qRw/mDmoSbk k1oMOsp93LEHnBXVJ3XgocjkgcTtJzpGJD3REgmzygPGQOesngf2tcMUIv63CYiaDQyC2lXQr8 FJu8pX7chfIlsUO69qekOtYaAe3roS2L/HCpyG11HY2NFvvMTWTFv8HNepPpPfH8cSx0zFynD8 KjrJMneZgPtbrS3XqTIbwin+tps7dTpozweToZYQMGfMpQJT1endVOGwy9541D9PXfk5wXm2Fe Smo= X-SBRS: 2.7 X-MesageID: 2995665 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.63,493,1557201600"; d="scan'208";a="2995665" From: Paul Durrant To: Date: Mon, 15 Jul 2019 13:37:10 +0100 Message-ID: <20190715123710.1780-5-paul.durrant@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190715123710.1780-1-paul.durrant@citrix.com> References: <20190715123710.1780-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 4/4] iommu / pci: re-implement XEN_DOMCTL_get_device_group... X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Paul Durrant , Jan Beulich Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" ... using the new iommu_group infrastructure. Because 'sibling' devices are now members of the same iommu_group, implement the domctl by looking up the iommu_group of the pdev with the matching SBDF and then finding all the assigned pdevs that are in the group. Signed-off-by: Paul Durrant --- Cc: Jan Beulich v2: - Re-implement in the absence of a per-group devs list. - Make use of pci_sbdf_t. --- xen/drivers/passthrough/groups.c | 44 ++++++++++++++++++++++++++++++++++ xen/drivers/passthrough/pci.c | 51 ++----------------------------------= ---- xen/include/xen/iommu.h | 2 ++ 3 files changed, 48 insertions(+), 49 deletions(-) diff --git a/xen/drivers/passthrough/groups.c b/xen/drivers/passthrough/gro= ups.c index 1a2f461c87..6d8064e4f4 100644 --- a/xen/drivers/passthrough/groups.c +++ b/xen/drivers/passthrough/groups.c @@ -12,8 +12,12 @@ * GNU General Public License for more details. */ =20 +#include #include +#include #include +#include +#include =20 struct iommu_group { unsigned int id; @@ -81,6 +85,46 @@ int iommu_group_assign(struct pci_dev *pdev, void *arg) return 0; } =20 +int iommu_get_device_group(struct domain *d, pci_sbdf_t sbdf, + XEN_GUEST_HANDLE_64(uint32) buf, int max_sdevs) +{ + struct iommu_group *grp =3D NULL; + struct pci_dev *pdev; + unsigned int i =3D 0; + + pcidevs_lock(); + + for_each_pdev ( d, pdev ) + { + if ( pdev->sbdf.sbdf =3D=3D sbdf.sbdf ) + { + grp =3D pdev->grp; + break; + } + } + + if ( !grp ) + goto out; + + for_each_pdev ( d, pdev ) + { + if ( xsm_get_device_group(XSM_HOOK, pdev->sbdf.sbdf) || + pdev->grp !=3D grp ) + continue; + + if ( unlikely(copy_to_guest_offset(buf, i++, &pdev->sbdf.sbdf, 1))= ) + { + pcidevs_unlock(); + return -EFAULT; + } + } + + out: + pcidevs_unlock(); + + return i; +} + /* * Local variables: * mode: C diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 179cb7e17e..3a5e90c176 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1563,53 +1563,6 @@ int deassign_device(struct domain *d, u16 seg, u8 bu= s, u8 devfn) return ret; } =20 -static int iommu_get_device_group( - struct domain *d, u16 seg, u8 bus, u8 devfn, - XEN_GUEST_HANDLE_64(uint32) buf, int max_sdevs) -{ - const struct domain_iommu *hd =3D dom_iommu(d); - struct pci_dev *pdev; - int group_id, sdev_id; - u32 bdf; - int i =3D 0; - const struct iommu_ops *ops =3D hd->platform_ops; - - if ( !iommu_enabled || !ops || !ops->get_device_group_id ) - return 0; - - group_id =3D ops->get_device_group_id(seg, bus, devfn); - - pcidevs_lock(); - for_each_pdev( d, pdev ) - { - if ( (pdev->seg !=3D seg) || - ((pdev->bus =3D=3D bus) && (pdev->devfn =3D=3D devfn)) ) - continue; - - if ( xsm_get_device_group(XSM_HOOK, (seg << 16) | (pdev->bus << 8)= | pdev->devfn) ) - continue; - - sdev_id =3D ops->get_device_group_id(seg, pdev->bus, pdev->devfn); - if ( (sdev_id =3D=3D group_id) && (i < max_sdevs) ) - { - bdf =3D 0; - bdf |=3D (pdev->bus & 0xff) << 16; - bdf |=3D (pdev->devfn & 0xff) << 8; - - if ( unlikely(copy_to_guest_offset(buf, i, &bdf, 1)) ) - { - pcidevs_unlock(); - return -1; - } - i++; - } - } - - pcidevs_unlock(); - - return i; -} - void iommu_dev_iotlb_flush_timeout(struct domain *d, struct pci_dev *pdev) { pcidevs_lock(); @@ -1666,11 +1619,11 @@ int iommu_do_pci_domctl( max_sdevs =3D domctl->u.get_device_group.max_sdevs; sdevs =3D domctl->u.get_device_group.sdev_array; =20 - ret =3D iommu_get_device_group(d, seg, bus, devfn, sdevs, max_sdev= s); + ret =3D iommu_get_device_group(d, PCI_SBDF3(seg, bus, devfn), sdev= s, + max_sdevs); if ( ret < 0 ) { dprintk(XENLOG_ERR, "iommu_get_device_group() failed!\n"); - ret =3D -EFAULT; domctl->u.get_device_group.num_sdevs =3D 0; } else diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index c93f580fdc..ac764b41f9 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -321,6 +321,8 @@ extern struct page_list_head iommu_pt_cleanup_list; =20 void iommu_groups_init(void); int iommu_group_assign(struct pci_dev *pdev, void *arg); +int iommu_get_device_group(struct domain *d, pci_sbdf_t sbdf, + XEN_GUEST_HANDLE_64(uint32) buf, int max_sdevs); =20 #endif /* CONFIG_HAS_PCI */ =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel