From nobody Fri Apr 19 19:50:38 2024 Delivered-To: importer@patchew.org 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; 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=1557321932; cv=none; d=zoho.com; s=zohoarc; b=N9UFPsAJpKeJu6BTjL2T3hxh+LHh4H4YZew/6SlVeIE7I++jXWwTA/DkYEONfArlKR8yJ74c7XWinGbhSL7rtSJrfFKUbIdKh41Yr/rX5N2oSP7o4CGIOBwtBMWvickWT4KVAJloVZPGjl3MAghnZnZwsy9O5VwOwhA5WgCZsqQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557321932; 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=EvpDjqNMXT36ypJy87++YQ8e+Ax6P5Ep01NpBQGlj5g=; b=GBu6us12jnKdTb0qPi3+NDNdfesgwqHiASOYesEggS5z9cpPIC5l9+7Ba+wFObYXfh2oOr36NhswY/YjGeaJi0r59B+7ewz2Vt8DL6A4zZNVOYU6hcLpVRR8uwoG76tOXg5Clwf++oSg9JxSfWUxqSupXEmb51QqflFc1PcETZU= 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 1557321932092191.7680192440115; Wed, 8 May 2019 06:25:32 -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 1hOMYT-0000eY-Jw; Wed, 08 May 2019 13:24:17 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hOMYS-0000dg-5Z for xen-devel@lists.xenproject.org; Wed, 08 May 2019 13:24:16 +0000 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 914d4ca2-7194-11e9-9c8f-03198498a28f; Wed, 08 May 2019 13:24:12 +0000 (UTC) X-Inumbo-ID: 914d4ca2-7194-11e9-9c8f-03198498a28f X-IronPort-AV: E=Sophos;i="5.60,446,1549929600"; d="scan'208";a="85265426" From: Paul Durrant To: Date: Wed, 8 May 2019 14:24:03 +0100 Message-ID: <20190508132403.1454-6-paul.durrant@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190508132403.1454-1-paul.durrant@citrix.com> References: <20190508132403.1454-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 5/5] 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 relevant iommu_group and walking the membership list. Signed-off-by: Paul Durrant --- Cc: Jan Beulich --- xen/drivers/passthrough/iommu.c | 65 +++++++++++++++++++++++++++++++++++++= ++++ xen/drivers/passthrough/pci.c | 47 ----------------------------- xen/include/xen/iommu.h | 2 ++ 3 files changed, 67 insertions(+), 47 deletions(-) diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iomm= u.c index 11319fbaae..49140c652e 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -729,6 +729,71 @@ int iommu_group_assign(struct pci_dev *pdev) return 0; } =20 +static struct iommu_group *iommu_group_lookup(uint16_t seg, uint8_t bus, + uint8_t devfn) +{ + unsigned int id =3D 0; + struct iommu_group *grp; + + while ( radix_tree_gang_lookup(&iommu_groups, (void **)&grp, id, 1) ) + { + struct pci_dev *pdev; + + list_for_each_entry ( pdev, &grp->devs_list, grpdevs_list ) + if ( pdev->seg =3D=3D seg && pdev->bus =3D=3D bus && + pdev->devfn =3D=3D devfn ) + return grp; + + id =3D grp->id + 1; + } + + return NULL; +} + +int iommu_get_device_group(struct domain *d, u16 seg, u8 bus, u8 devfn, + XEN_GUEST_HANDLE_64(uint32) buf, int max_sdevs) +{ + struct iommu_group *grp; + struct pci_dev *pdev; + int i =3D 0; + + pcidevs_lock(); + + grp =3D iommu_group_lookup(seg, bus, devfn); + if ( !grp ) + { + pcidevs_unlock(); + return 0; + } + + list_for_each_entry ( pdev, &grp->devs_list, grpdevs_list ) + { + uint32_t sbdf; + + if ( i >=3D max_sdevs ) + break; + + if ( pdev->domain !=3D d ) + continue; + + sbdf =3D PCI_SBDF3(pdev->seg, pdev->bus, pdev->devfn); + + if ( xsm_get_device_group(XSM_HOOK, sbdf) ) + continue; + + if ( unlikely(copy_to_guest_offset(buf, i, &sbdf, 1)) ) + { + pcidevs_unlock(); + return -1; + } + i++; + } + + pcidevs_unlock(); + + return i; +} + #endif /* CONFIG_HAS_PCI */ =20 /* diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 6210409741..68b2883ed6 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1554,53 +1554,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(); diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 6d6aa12314..c4e1604bb8 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -319,6 +319,8 @@ extern struct page_list_head iommu_pt_cleanup_list; =20 void iommu_groups_init(void); int iommu_group_assign(struct pci_dev *pdev); +int iommu_get_device_group(struct domain *d, u16 seg, u8 bus, u8 devfn, + 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