From nobody Wed Apr 24 11:54:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1684444107; cv=pass; d=zohomail.com; s=zohoarc; b=ODvALPW2KRfpCo+nYv8VcWLC54ynVMvsvJkJThJbpZFZu2u8eDbNpfH038yGOSejrsFBiEVLrLWszuQbvfyyAOjNulryGfKZyVgbWrRseXya0QXtYAVea0pDVCM5clO6FtEQX95bS2pyao2uS1ycnllJURjoqMI85wqjsZQ0qsI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684444107; 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; bh=t6nCWAuU2fluFwlRvvsBvDibEl+2/q0dSI5mIxYKxGc=; b=cz9CLrczfOfdbnnWQpufpRA+w6gTqU7ylNvZX9E5ej9DLTAUyfPqxaau02kL1VaASRrF7W0UaYyMhIlj/HBc9fa8KjLKjUZ+4zpzJGKEt8Blt8QCNEPiWnd4fjbotpuFWf6oFgYImnjJgTrX84LDJ8v6MAi3eUJfZzRwnM8Twso= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1684444107503620.2505698671753; Thu, 18 May 2023 14:08:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.536546.834968 (Exim 4.92) (envelope-from ) id 1pzkqt-0004Fx-TA; Thu, 18 May 2023 21:07:59 +0000 Received: by outflank-mailman (output) from mailman id 536546.834968; Thu, 18 May 2023 21:07:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pzkqt-0004Fq-Pn; Thu, 18 May 2023 21:07:59 +0000 Received: by outflank-mailman (input) for mailman id 536546; Thu, 18 May 2023 21:07:58 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pzkqs-000492-N3 for xen-devel@lists.xenproject.org; Thu, 18 May 2023 21:07:58 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20600.outbound.protection.outlook.com [2a01:111:f400:7eae::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0f9b8c6b-f5c0-11ed-b22d-6b7b168915f2; Thu, 18 May 2023 23:07:57 +0200 (CEST) Received: from BN9PR03CA0354.namprd03.prod.outlook.com (2603:10b6:408:f6::29) by SA1PR12MB8743.namprd12.prod.outlook.com (2603:10b6:806:37c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.19; Thu, 18 May 2023 21:07:54 +0000 Received: from BN8NAM11FT095.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f6:cafe::b1) by BN9PR03CA0354.outlook.office365.com (2603:10b6:408:f6::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.19 via Frontend Transport; Thu, 18 May 2023 21:07:53 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT095.mail.protection.outlook.com (10.13.176.206) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.21 via Frontend Transport; Thu, 18 May 2023 21:07:53 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 18 May 2023 16:07:52 -0500 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 18 May 2023 16:07:51 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0f9b8c6b-f5c0-11ed-b22d-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YZFTvqMGLiUa0SNDbBsOTvgT24ezFIHYn+7uMswT82PcUbZYQoa+so7RnvgF9QvGpt2A2Xq4jRmBOEOpWCDPv2vGaMcGQfRPVn1oG2yHTtkjRtUIo++lImM8kk3tLIl2ySOw/yCDBMrGJ2R2waQdDELaO0TWMyEC2zuGVuqIv4kTd2JzvvJxDOev1QfhXGqsLuhoOLsrw5GUTk8s2++OBMmeZFptXGR5tQqhdMFvGhnvr1VKF6pnh7P3XfhcqQT9KV8wQigprzyb958O2QpDLeePvPLZ91QP4mdKO6Yxv3EUO5wgJOgBtkQDiJY+OClcoECMjh/S/0eYwNmhuOvqbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=t6nCWAuU2fluFwlRvvsBvDibEl+2/q0dSI5mIxYKxGc=; b=ofIuCBFP2QblcQgRv2d9MK0AzOK383AgNbzCu8lyltTrS6pauMKu4nuJIp00m4byNSyfRbyXcaIRpceDAu2kBthvpC5tAAs3MI971JEi1+YZlB/qU6f588EJ7BWtz01/IyIk4CrWzSYltYsBKmnuopKopaEnopPPbq9c2LUvzNNGdFCfqG1wXfmkmnjWZ1jgZwIpkdCQzRznj+WYpaCG06CYBtGP8HMqQ0apoJhkfGwwACCdMCFta+i5fPSNlfCHQeOK7KT6nfg8TyWIM4Rmnzda+2PPDKa62srniKH5QR9iL9UshziYCuFiSHBptn//EMc97OW2w+W7LveJMc1aGw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=t6nCWAuU2fluFwlRvvsBvDibEl+2/q0dSI5mIxYKxGc=; b=vKxR2djAdcz0aPsRUZ9jETGOvhQ4zIRbxCRHuSSx8XLOqbBvJOueJPyZ/ysIu5oCGYxCvPdJCCT59ATkN9EMHtaVfrFq811r7/CXYxLXNSKcqK6sTUPQkRGMrHBUGjf0UpGHqnA/xD+GqFFlr+6g0sb4itMa3QO7CzYCMmSQ8+U= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Stewart Hildebrand To: CC: Oleksandr Tyshchenko , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Rahul Singh , Stewart Hildebrand Subject: [PATCH v3 1/6] xen/arm: Move is_protected flag to struct device Date: Thu, 18 May 2023 17:06:53 -0400 Message-ID: <20230518210658.66156-2-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230518210658.66156-1-stewart.hildebrand@amd.com> References: <20230518210658.66156-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT095:EE_|SA1PR12MB8743:EE_ X-MS-Office365-Filtering-Correlation-Id: 38bc38c3-3bf3-4b36-7e9c-08db57e3f248 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EkDFRbWlqmjXIt/yl+oExgRHuLcT6hA7yHEprxyGyPJTxgRBQyQoD9w6jhMRKku4Fx+ePAWjlqmKe4QAq/2ZClUq6i1Za93jO7cuP66rVAWrI+YYTK6hXNsowpU6it6Ufhvuyys0b5EMBhnaZB9Ln9PZdtRyx4V5grY+fwe5xhu2lG/8mRo3M9i8gYz11b6kwlvGs+e+4/Nsxhvf6v7r0y23DtsbxDu6R4VLvO9mfwHaSM9Zapb9mG7ujJdkQQepM9aji9lJdSvNwLVt2J/OBv2/ds16Oh/cFsxrpNkdiGGD6HP59skBl5n9vJ59x2kC18bAlxwW7S5bcm3r3ItldFMHPvZEtvi8feas38AXnvhOxj6Jaj3gSFGlejW6/HyEcxSqzNXPvUKfrSM3fOEosX2hstauqAaZCoKcyx7xRGa8ilW+DNV+AJfttTKxearHATFz1HWbV53mNiXpja9Hrzfo7n+TlVHO8QYO2tAXtsR3aTNVGhDb1OKO43Zp8gO/vGzkvyQXcLG8NbRza0FC4qVM3PjheMo867PI9VFlt514VG7U3L98wwGT0bs3v9z5NMZdQUmF2EB1mkxse3cgHzv4vSRJiquyoVfPpmiUhkHRePTLgyv0bJb7eoKg6cVYMrVapGJl7co+cWJWtiYf4CAqMoPkZrLAhlCMQwauKgdvDbl/RA1/hO2yVYvt9JLgP+2ho8n4o0Fyx9mMcQ5PxAaZiWYWIlZ42sLxAwIWXUDiLuOGD34nVlJsM17VTHgM X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(376002)(346002)(136003)(39860400002)(396003)(451199021)(46966006)(36840700001)(40470700004)(26005)(40460700003)(1076003)(966005)(36860700001)(36756003)(426003)(83380400001)(47076005)(40480700001)(336012)(86362001)(82310400005)(2616005)(356005)(81166007)(186003)(82740400003)(54906003)(44832011)(5660300002)(478600001)(2906002)(316002)(6916009)(4326008)(8676002)(8936002)(41300700001)(70206006)(70586007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2023 21:07:53.6618 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 38bc38c3-3bf3-4b36-7e9c-08db57e3f248 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT095.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8743 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1684444109425100001 Content-Type: text/plain; charset="utf-8" From: Oleksandr Tyshchenko This flag will be re-used for PCI devices by the subsequent patches. Signed-off-by: Oleksandr Tyshchenko Signed-off-by: Stewart Hildebrand --- v2->v3: * no change v1->v2: * no change downstream->v1: * rebase * s/dev_node->is_protected/dev_node->dev.is_protected/ in smmu.c * s/dt_device_set_protected(dev_to_dt(dev))/device_set_protected(dev)/ in s= mmu-v3.c * remove redundant device_is_protected checks in smmu-v3.c/ipmmu-vmsa.c (cherry picked from commit 59753aac77528a584d3950936b853ebf264b68e7 from the downstream branch poc/pci-passthrough from https://gitlab.com/xen-project/people/bmarquis/xen-arm-poc.git) --- xen/arch/arm/domain_build.c | 4 ++-- xen/arch/arm/include/asm/device.h | 13 +++++++++++++ xen/common/device_tree.c | 2 +- xen/drivers/passthrough/arm/ipmmu-vmsa.c | 8 +------- xen/drivers/passthrough/arm/smmu-v3.c | 7 +------ xen/drivers/passthrough/arm/smmu.c | 2 +- xen/drivers/passthrough/device_tree.c | 15 +++++++++------ xen/include/xen/device_tree.h | 13 ------------- 8 files changed, 28 insertions(+), 36 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 71f307a572e9..d228da641367 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2503,7 +2503,7 @@ static int __init handle_device(struct domain *d, str= uct dt_device_node *dev, return res; } =20 - if ( dt_device_is_protected(dev) ) + if ( device_is_protected(dt_to_dev(dev)) ) { dt_dprintk("%s setup iommu\n", dt_node_full_name(dev)); res =3D iommu_assign_dt_device(d, dev); @@ -3003,7 +3003,7 @@ static int __init handle_passthrough_prop(struct kern= el_info *kinfo, return res; =20 /* If xen_force, we allow assignment of devices without IOMMU protecti= on. */ - if ( xen_force && !dt_device_is_protected(node) ) + if ( xen_force && !device_is_protected(dt_to_dev(node)) ) return 0; =20 return iommu_assign_dt_device(kinfo->d, node); diff --git a/xen/arch/arm/include/asm/device.h b/xen/arch/arm/include/asm/d= evice.h index b5d451e08776..086dde13eb6b 100644 --- a/xen/arch/arm/include/asm/device.h +++ b/xen/arch/arm/include/asm/device.h @@ -1,6 +1,8 @@ #ifndef __ASM_ARM_DEVICE_H #define __ASM_ARM_DEVICE_H =20 +#include + enum device_type { DEV_DT, @@ -20,6 +22,7 @@ struct device #endif struct dev_archdata archdata; struct iommu_fwspec *iommu_fwspec; /* per-device IOMMU instance data */ + bool is_protected; /* Shows that device is protected by IOMMU */ }; =20 typedef struct device device_t; @@ -94,6 +97,16 @@ int device_init(struct dt_device_node *dev, enum device_= class class, */ enum device_class device_get_class(const struct dt_device_node *dev); =20 +static inline void device_set_protected(struct device *device) +{ + device->is_protected =3D true; +} + +static inline bool device_is_protected(const struct device *device) +{ + return device->is_protected; +} + #define DT_DEVICE_START(_name, _namestr, _class) \ static const struct device_desc __dev_desc_##_name __used \ __section(".dev.info") =3D { \ diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 6c9712ab7bda..1d5d7cb5f01b 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -1874,7 +1874,7 @@ static unsigned long __init unflatten_dt_node(const v= oid *fdt, /* By default dom0 owns the device */ np->used_by =3D 0; /* By default the device is not protected */ - np->is_protected =3D false; + np->dev.is_protected =3D false; INIT_LIST_HEAD(&np->domain_list); =20 if ( new_format ) diff --git a/xen/drivers/passthrough/arm/ipmmu-vmsa.c b/xen/drivers/passthr= ough/arm/ipmmu-vmsa.c index 091f09b21752..039212a3a990 100644 --- a/xen/drivers/passthrough/arm/ipmmu-vmsa.c +++ b/xen/drivers/passthrough/arm/ipmmu-vmsa.c @@ -1288,14 +1288,8 @@ static int ipmmu_add_device(u8 devfn, struct device = *dev) if ( !to_ipmmu(dev) ) return -ENODEV; =20 - if ( dt_device_is_protected(dev_to_dt(dev)) ) - { - dev_err(dev, "Already added to IPMMU\n"); - return -EEXIST; - } - /* Let Xen know that the master device is protected by an IOMMU. */ - dt_device_set_protected(dev_to_dt(dev)); + device_set_protected(dev); =20 dev_info(dev, "Added master device (IPMMU %s micro-TLBs %u)\n", dev_name(fwspec->iommu_dev), fwspec->num_ids); diff --git a/xen/drivers/passthrough/arm/smmu-v3.c b/xen/drivers/passthroug= h/arm/smmu-v3.c index 4ca55d400a7b..f5910e79922f 100644 --- a/xen/drivers/passthrough/arm/smmu-v3.c +++ b/xen/drivers/passthrough/arm/smmu-v3.c @@ -1521,13 +1521,8 @@ static int arm_smmu_add_device(u8 devfn, struct devi= ce *dev) */ arm_smmu_enable_pasid(master); =20 - if (dt_device_is_protected(dev_to_dt(dev))) { - dev_err(dev, "Already added to SMMUv3\n"); - return -EEXIST; - } - /* Let Xen know that the master device is protected by an IOMMU. */ - dt_device_set_protected(dev_to_dt(dev)); + device_set_protected(dev); =20 dev_info(dev, "Added master device (SMMUv3 %s StreamIds %u)\n", dev_name(fwspec->iommu_dev), fwspec->num_ids); diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/a= rm/smmu.c index 0a514821b336..5b6024d579a8 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -838,7 +838,7 @@ static int arm_smmu_dt_add_device_legacy(struct arm_smm= u_device *smmu, master->of_node =3D dev_node; =20 /* Xen: Let Xen know that the device is protected by an SMMU */ - dt_device_set_protected(dev_node); + device_set_protected(dev); =20 for (i =3D 0; i < fwspec->num_ids; ++i) { if (!(smmu->features & ARM_SMMU_FEAT_STREAM_MATCH) && diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthroug= h/device_tree.c index 1c32d7b50cce..b5bd13393b56 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -34,7 +34,7 @@ int iommu_assign_dt_device(struct domain *d, struct dt_de= vice_node *dev) if ( !is_iommu_enabled(d) ) return -EINVAL; =20 - if ( !dt_device_is_protected(dev) ) + if ( !device_is_protected(dt_to_dev(dev)) ) return -EINVAL; =20 spin_lock(&dtdevs_lock); @@ -65,7 +65,7 @@ int iommu_deassign_dt_device(struct domain *d, struct dt_= device_node *dev) if ( !is_iommu_enabled(d) ) return -EINVAL; =20 - if ( !dt_device_is_protected(dev) ) + if ( !device_is_protected(dt_to_dev(dev)) ) return -EINVAL; =20 spin_lock(&dtdevs_lock); @@ -87,7 +87,7 @@ static bool_t iommu_dt_device_is_assigned(const struct dt= _device_node *dev) { bool_t assigned =3D 0; =20 - if ( !dt_device_is_protected(dev) ) + if ( !device_is_protected(dt_to_dev(dev)) ) return 0; =20 spin_lock(&dtdevs_lock); @@ -141,12 +141,15 @@ int iommu_add_dt_device(struct dt_device_node *np) return -EINVAL; =20 /* - * The device may already have been registered. As there is no harm in - * it just return success early. + * This is needed in case a device has both the iommus property and + * also appears in the mmu-masters list. */ - if ( dev_iommu_fwspec_get(dev) ) + if ( device_is_protected(dev) ) return 0; =20 + if ( dev_iommu_fwspec_get(dev) ) + return -EEXIST; + /* * According to the Documentation/devicetree/bindings/iommu/iommu.txt * from Linux. diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 19a74909cece..c1e4751a581f 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -90,9 +90,6 @@ struct dt_device_node { struct dt_device_node *next; /* TODO: Remove it. Only use to know the = last children */ struct dt_device_node *allnext; =20 - /* IOMMU specific fields */ - bool is_protected; - /* HACK: Remove this if there is a need of space */ bool_t static_evtchn_created; =20 @@ -302,16 +299,6 @@ static inline domid_t dt_device_used_by(const struct d= t_device_node *device) return device->used_by; } =20 -static inline void dt_device_set_protected(struct dt_device_node *device) -{ - device->is_protected =3D true; -} - -static inline bool dt_device_is_protected(const struct dt_device_node *dev= ice) -{ - return device->is_protected; -} - static inline bool_t dt_property_name_is_equal(const struct dt_property *p= p, const char *name) { --=20 2.40.1 From nobody Wed Apr 24 11:54:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1684444136; cv=pass; d=zohomail.com; s=zohoarc; b=WSc/TVWhYPggUdtHA/UHb5mLNy22v2A2H8BLWnt67gkkKBhc5bjNBUuyE7Pr2PixW6F7AwRdV4M0hrcE4+2Dq9Dvd/OhQ6uNboJKMJuoUIivopN2gpIuM79mjcUTBULeiHJKLJ26eJR9ZwgZlfrzM61ezFY5/IeQSNGEm2UPCgU= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684444136; 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; bh=/Hf5r04d2nEr/v6wVdo3KW9S2VJ/PyaIu7QWgQPgol4=; b=aOrz5zj5rDt0fKJfH3MtLFL3dWNyXMzn6J6R1vKTs0NPUiqOXpjhel59Gt7qnbWGi8x98F8TKUuWE1h/bAgG3eKdVfkNMmErPP2O18l+iGT6Sxe22GUE/wVI5/1zop711+m+vHcLjltThrId7mxLaDs+8ph8nGI5xmhTYPp6ljM= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1684444136773207.00516917604477; Thu, 18 May 2023 14:08:56 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.536549.834978 (Exim 4.92) (envelope-from ) id 1pzkrK-0004my-6K; Thu, 18 May 2023 21:08:26 +0000 Received: by outflank-mailman (output) from mailman id 536549.834978; Thu, 18 May 2023 21:08:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pzkrK-0004mr-30; Thu, 18 May 2023 21:08:26 +0000 Received: by outflank-mailman (input) for mailman id 536549; Thu, 18 May 2023 21:08:24 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pzkrI-000492-8T for xen-devel@lists.xenproject.org; Thu, 18 May 2023 21:08:24 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20600.outbound.protection.outlook.com [2a01:111:f400:7eae::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1f5db55d-f5c0-11ed-b22d-6b7b168915f2; Thu, 18 May 2023 23:08:23 +0200 (CEST) Received: from DM6PR02CA0110.namprd02.prod.outlook.com (2603:10b6:5:1b4::12) by SJ2PR12MB7847.namprd12.prod.outlook.com (2603:10b6:a03:4d2::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.33; Thu, 18 May 2023 21:08:17 +0000 Received: from DM6NAM11FT029.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1b4:cafe::70) by DM6PR02CA0110.outlook.office365.com (2603:10b6:5:1b4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.19 via Frontend Transport; Thu, 18 May 2023 21:08:17 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT029.mail.protection.outlook.com (10.13.173.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.21 via Frontend Transport; Thu, 18 May 2023 21:08:16 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 18 May 2023 16:08:16 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 18 May 2023 16:08:15 -0500 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 18 May 2023 16:08:14 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1f5db55d-f5c0-11ed-b22d-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I0n8mSjsCLUvzwpfnyCjNOt/w0ECvPc9Mjz9ALSPVMuoZ1rT42YALSixsSPPWiA5MwxsdHjF4WlN9G3SoVQdK1hJ+NZ4d6jmz08t0OePvckvQe+K5WdkcHKNPmTDEsg7AqDvipP/1MBH1APYoCETssrJIkV8KGhCSR968hC9hyK+awCvnDRNtK7ItrdOWDGXb11tuLsgQwH4duUDwSsiXG3oR8mg4Gx/Nq7t27X2Uzli1pbytsDDWTdeFXAPKyzKiXspZp0D3/TBKYDCnQ/elZuMkDw0excAJxmL6FMvrRuGgFYSdvAOqHUS7qoyQawJnAfDej1EhavcrYAdRVpA5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/Hf5r04d2nEr/v6wVdo3KW9S2VJ/PyaIu7QWgQPgol4=; b=BhWtmRAA6/iGrPOtItTym1v/QeD4LUbXVzGpmDgnbd1BcfDRPbofQ08yUjpBXUWP2RkkZJ1EMQ8JshiFD4j67vPPnCgR6wh4vnZH9+xkapTcLcqGo19PqQyNeCYY9uqVUksMWwYYtfq3SWazUuU/ms1rwWFZ7bx1N/f4tyjFEQQFK6VBkFwxYAEtJRkFMXrf+QO02fEk8XoLwkIhsyMKI5jxiGss3/W3BOyIawFGvnP5BWnIpvWSNja5XpxykEWpEuKYsKAELPel1+ELaG/zCc7kR8WXatFl75phu/dKrOaiW9YF1jFyzbU707F3v3nSDGFjGtscFLAnK+7K9OWdpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/Hf5r04d2nEr/v6wVdo3KW9S2VJ/PyaIu7QWgQPgol4=; b=SQgIyjPyX/tBGZydXeEvDUluTeRuN7o9s3VyH964otcm3peO7NfK5q8/0TDI8wArk0pfY3GiidqaXkPYwciHKKxE/onzFLifWrPvYXR1uGUYjYK8XiA9tFtKcSgcuydhz/YxmF2ZD5C1qlj1kJFYw1iHle1AKYlvXa3W8oVHelI= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Stewart Hildebrand To: CC: Oleksandr Tyshchenko , Stefano Stabellini , Julien Grall , Rahul Singh , Bertrand Marquis , "Stewart Hildebrand" Subject: [PATCH v3 2/6] iommu/arm: Add iommu_dt_xlate() Date: Thu, 18 May 2023 17:06:54 -0400 Message-ID: <20230518210658.66156-3-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230518210658.66156-1-stewart.hildebrand@amd.com> References: <20230518210658.66156-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT029:EE_|SJ2PR12MB7847:EE_ X-MS-Office365-Filtering-Correlation-Id: 0b74e7f2-c0f4-4465-27e6-08db57e3fffd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9/9Dp4fyGn3rTnBq0fmg46tqP5tFLB3/f3krMVWGnpGB1GTRnk0kqvFpRzTadh2KvSNaGkM7+lSP894fkillaISxw/zSnFOnduiWw5C04UXDQJhJap02nQ0qJMYTS3ri31OM1hE5h7ePA1Z6F2Bk14cDzS+HA+Z3IBz+uOC86zdWlAEZYaF2MLPYgvM+TRARXEkl7ly4rV0U9CjF2YjHvESA/IRB9g3FtRSm1sDkXwtpN2+tukJYhJo/Lk8OTH/03rqUvmSUpJPceua3zpdSL1UF7rl1CEFhpzs6BqdOcECu+R0q+zJI2LKnBa0I+ItuVZucukbCD4Z4t+m0CyjMSmXpEkb0Cpq/Njpw5zfbA2bLIwnaSX5mcMXz4h+bbnpJwGShRedONr2/LAWhBtCX6SEAlYEE/iLQ4UqjR1Q0f69qkYjeeXYTAcgnCBtweSGu8rupyD4Dpl+bDCqg3uRn5sTTUI8WmrhVsbmWs+H1wcwFoRJkTk8YVWQulZlLqNYdwt3uvEh+Dq/PwV7h2lHrgJPZNvg0jSsFr9umLg+jNvKruqAxT2o5wh013008rneGZDiDnLCBgMrdOZOH0Sz391TpO/+AFH9t7FePOPOZXpZ1csS+OzbnZE0PCDC+BA+04eFMRIqzmmoSD2R5j8YMwo0bTTxLMX8s83sj3OR25v3aKvNShVnvO4QpMS77y8WX4/5QqIVIS1W3py0F2dUkPIvhi5iJLqjhMPCV0t680fEwzMAwhkq1X79w+aBCN4u5 X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(136003)(376002)(396003)(346002)(39860400002)(451199021)(46966006)(36840700001)(40470700004)(40460700003)(70586007)(316002)(966005)(36756003)(478600001)(70206006)(4326008)(54906003)(426003)(6916009)(86362001)(47076005)(83380400001)(36860700001)(1076003)(26005)(186003)(41300700001)(2616005)(8676002)(8936002)(5660300002)(336012)(44832011)(6666004)(82310400005)(40480700001)(2906002)(81166007)(356005)(82740400003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2023 21:08:16.6249 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0b74e7f2-c0f4-4465-27e6-08db57e3fffd X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT029.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB7847 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1684444137276100001 Content-Type: text/plain; charset="utf-8" From: Oleksandr Tyshchenko Move code for processing DT IOMMU specifier to a separate helper. This helper will be re-used for adding PCI devices by the subsequent patches as we will need exact the same actions for processing DT PCI-IOMMU specifier. While at it introduce NO_IOMMU to avoid magic "1". Signed-off-by: Oleksandr Tyshchenko Signed-off-by: Stewart Hildebrand # rename --- v2->v3: * no change v1->v2: * no change downstream->v1: * trivial rebase * s/dt_iommu_xlate/iommu_dt_xlate/ (cherry picked from commit c26bab0415ca303df86aba1d06ef8edc713734d3 from the downstream branch poc/pci-passthrough from https://gitlab.com/xen-project/people/bmarquis/xen-arm-poc.git) --- xen/drivers/passthrough/device_tree.c | 42 +++++++++++++++++---------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthroug= h/device_tree.c index b5bd13393b56..1b50f4670944 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -127,15 +127,39 @@ int iommu_release_dt_devices(struct domain *d) return 0; } =20 +/* This correlation must not be altered */ +#define NO_IOMMU 1 + +static int iommu_dt_xlate(struct device *dev, + struct dt_phandle_args *iommu_spec) +{ + const struct iommu_ops *ops =3D iommu_get_ops(); + int rc; + + if ( !dt_device_is_available(iommu_spec->np) ) + return NO_IOMMU; + + rc =3D iommu_fwspec_init(dev, &iommu_spec->np->dev); + if ( rc ) + return rc; + + /* + * Provide DT IOMMU specifier which describes the IOMMU master + * interfaces of that device (device IDs, etc) to the driver. + * The driver is responsible to decide how to interpret them. + */ + return ops->dt_xlate(dev, iommu_spec); +} + int iommu_add_dt_device(struct dt_device_node *np) { const struct iommu_ops *ops =3D iommu_get_ops(); struct dt_phandle_args iommu_spec; struct device *dev =3D dt_to_dev(np); - int rc =3D 1, index =3D 0; + int rc =3D NO_IOMMU, index =3D 0; =20 if ( !iommu_enabled ) - return 1; + return NO_IOMMU; =20 if ( !ops ) return -EINVAL; @@ -164,19 +188,7 @@ int iommu_add_dt_device(struct dt_device_node *np) if ( !ops->add_device || !ops->dt_xlate ) return -EINVAL; =20 - if ( !dt_device_is_available(iommu_spec.np) ) - break; - - rc =3D iommu_fwspec_init(dev, &iommu_spec.np->dev); - if ( rc ) - break; - - /* - * Provide DT IOMMU specifier which describes the IOMMU master - * interfaces of that device (device IDs, etc) to the driver. - * The driver is responsible to decide how to interpret them. - */ - rc =3D ops->dt_xlate(dev, &iommu_spec); + rc =3D iommu_dt_xlate(dev, &iommu_spec); if ( rc ) break; =20 --=20 2.40.1 From nobody Wed Apr 24 11:54:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1684444158; cv=pass; d=zohomail.com; s=zohoarc; b=b2eSSs0OYRHH7aZOzGHyAujf5dqpbqeOkBOzG6iyM09QldX+glFkrTGItv1AmjlY1gVX0x6faAd2ywfCp47/jrJt0TbGJU95PNymdHxg+ZGqEPFNPGkGHKj44ilZDD0GxQ7HThr/n+j45kZvpuOM1MOZQxnhikXiVAwYT6PLrsQ= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684444158; 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; bh=XSpUUbvq9wCcX8m7HccnIFgrdTbsnGWDdpMq97CInwY=; b=PgaR7Byt5OaBS29aybF199xPaKsC6fnBbeYPpwMgK43ubM+VZG1+u9yMKPX8ucb+V7ooxNQDyY5hvkCBGOd+CDKwyPC3zi7Aeh2X64GDPvL2hSCyjxmjnkMbWrzcdVl1ud3W1lNQyqC6EE505IJ/TWQ8QKHiOGoTh6nm+irDCyE= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1684444158553174.56207902828294; Thu, 18 May 2023 14:09:18 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.536552.834988 (Exim 4.92) (envelope-from ) id 1pzkrg-0005HR-GX; Thu, 18 May 2023 21:08:48 +0000 Received: by outflank-mailman (output) from mailman id 536552.834988; Thu, 18 May 2023 21:08:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pzkrg-0005HI-Cd; Thu, 18 May 2023 21:08:48 +0000 Received: by outflank-mailman (input) for mailman id 536552; Thu, 18 May 2023 21:08:47 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pzkrf-0003gZ-BP for xen-devel@lists.xenproject.org; Thu, 18 May 2023 21:08:47 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20612.outbound.protection.outlook.com [2a01:111:f400:fe5a::612]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2b72a6b1-f5c0-11ed-8611-37d641c3527e; Thu, 18 May 2023 23:08:44 +0200 (CEST) Received: from BN8PR07CA0016.namprd07.prod.outlook.com (2603:10b6:408:ac::29) by BN9PR12MB5081.namprd12.prod.outlook.com (2603:10b6:408:132::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.19; Thu, 18 May 2023 21:08:39 +0000 Received: from BN8NAM11FT081.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ac:cafe::8) by BN8PR07CA0016.outlook.office365.com (2603:10b6:408:ac::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.20 via Frontend Transport; Thu, 18 May 2023 21:08:38 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT081.mail.protection.outlook.com (10.13.177.233) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.19 via Frontend Transport; Thu, 18 May 2023 21:08:38 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 18 May 2023 16:08:38 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 18 May 2023 14:08:37 -0700 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 18 May 2023 16:08:35 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2b72a6b1-f5c0-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R6WW65et7SmaGgTg5sJM1Q8PstoYCaCDY3/JxtcnREc+YqnnQpeQFEVe6MvbTzEctfHmr48CYi2pvfhdPJbzr2fflTpyXXPRWiOG+un7yYLc7xTw/RrQ4ielcD+kfVDDPnq6C2Nxw804n+m72/2p+Pe3svrWFoedveQKnGWjgLXIGzboD4PezmniSqEaPH/IZEN4EXL3SzGdJ0ravY/T4nGNw8IGqCSZtxHPHJYqG2BJnvo3C5GAF8oCjehql4aUiHE4pH7Jx3zkLo2WNIm+wBB/973Djoep/QxnpMGMV6crGTcCOmyBKX89+Bh/Sd8S09VXDbLYFyloFAcimQNelg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XSpUUbvq9wCcX8m7HccnIFgrdTbsnGWDdpMq97CInwY=; b=I4fHFXAkiIC9utfHkR4Q3f68Hwg3tXaDiEJNCsal2dVHRIKX35XVtHAOTt5/h5RSeJJ0de3MTjlWFzwBrn/dGqBKK9YrYy47HbBVSuToOL2t35M2AQ2ie6U7Wk+x9cSdtobqxYKU6H+ZjvKctQuf8xpW1Jf6GMCKAaIvRa9pMazsQi0VO1WYa8wClcnFXVE0p7fA1xc9835ZEENxHKNnoxNtSdQrABd/xS1Do5jCva3Fj+YCsgB/VX+aJeDiUL0q+23KjVsGb2q9ZuXXjB/68f7DRzRefLTDrUXrP7yL+kRgnrtcfYrnBRjTQssUXbl1NexJAeqR2OlZgHo0StoijQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XSpUUbvq9wCcX8m7HccnIFgrdTbsnGWDdpMq97CInwY=; b=aUp4+jQxryUu9eTHHya1t3zNwGru+pGLp+GPoKHqCStNduirnAQpKsBfqfBLsqZAS/7J5tAr62AZbLOpFhI6vAK1/lHd1sohN3Zrpmnc3mLjVYlf2XJQn65tMQMX4eJVWCOSIlADCnyxRa/hYs4D2Vvqi5MxHHBNyxUnMBpT0yY= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Stewart Hildebrand To: CC: Oleksandr Tyshchenko , Stefano Stabellini , Julien Grall , Jan Beulich , Paul Durrant , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Rahul Singh , Bertrand Marquis , "Stewart Hildebrand" Subject: [PATCH v3 3/6] iommu/arm: Introduce iommu_add_dt_pci_sideband_ids API Date: Thu, 18 May 2023 17:06:55 -0400 Message-ID: <20230518210658.66156-4-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230518210658.66156-1-stewart.hildebrand@amd.com> References: <20230518210658.66156-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT081:EE_|BN9PR12MB5081:EE_ X-MS-Office365-Filtering-Correlation-Id: 28f549cc-d34e-43c8-f4dc-08db57e40cff X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eORbxfv7AXDuo/z6znZIQYxXHfgAxg1YA9IsHee/4OxDcYXq0JdgHfg9MSWjddNUCR10PET3GF8v40pgLw5aFLnf5QcFSvARi1B99WXETroOgFDDc91dF0HPLaBhIMO5Yx8yXz4s2OaeK/OjuvxJA6PdHdV6HJuXgTZDrfV5aOHsb3uTC3Xw0SGMy5DhO1fVVYr7cWr7zu/ZrY+v3jvcwljwAu41JJv8V1Bx1yDAdOaoIZMPkLEYXZcksN5jcrT8M+5zQdVHBHlFnIXzDlNkwuAQC6ZUJNugJPe5lIEulTt35WvTZ653cEpT1R1pS9rKea5qgj/iciXIPPLO9gqYvtPg8aVDwyodndVIHYvC+Pg9Bz+WPLdtmdvgO7qpHykexvxNk0hEBr1FG3BBBJ/raQrxPrSBZM5TKfjDQSpemcrb5s3+QEj+1oeF4230bScf+4MrWLOL3dmlLYNnklzU69l5ZhnQNQ1flpIBGCQe+5su/rOdW/DM5RJz6/31NedoH3H0iLOsd6C7CkbWVs6njK+K1UraZRG77rR+Ckgabzm5JI7768QVOfvkfwjppTuCHkrMicVXL1U73VZMJRlK8IAQ6cx6OlBomTypAuEpR+vbi8A89YvLjEddTGQ+n6fz4nGu3mAS8+9lgTJ/lNzKdiT4QV4LKkzY9Ug6tpi0yqTKwBxDjBbiBoApCfSRyzQbHLJbi7spGfM9G9gWO2kGkzVUDsimK4qb3MOIQiHvi024ZQbrdNKpITHWoiEfeT4xuhnk8YXmaFw1DsTXMeno0Iijos0Lf6dZU0JxGK51cmjvYIK+VR44RoNoLqS5kivTfBDoTYoH+h+J8oQKmkltXw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(396003)(136003)(376002)(346002)(451199021)(40470700004)(36840700001)(46966006)(316002)(2906002)(478600001)(41300700001)(6916009)(4326008)(8936002)(8676002)(54906003)(44832011)(6666004)(70586007)(70206006)(5660300002)(966005)(1076003)(26005)(40460700003)(82740400003)(356005)(186003)(40480700001)(2616005)(47076005)(36756003)(36860700001)(83380400001)(82310400005)(86362001)(81166007)(426003)(336012)(21314003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2023 21:08:38.4849 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 28f549cc-d34e-43c8-f4dc-08db57e40cff X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT081.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5081 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1684444159524100001 Content-Type: text/plain; charset="utf-8" From: Oleksandr Tyshchenko The main purpose of this patch is to add a way to register PCI device (which is behind the IOMMU) using the generic PCI-IOMMU DT bindings [1] before assigning that device to a domain. This behaves in almost the same way as existing iommu_add_dt_device API, the difference is in devices to handle and DT bindings to use. The function of_map_id to translate an ID through a downstream mapping (which is also suitable for mapping Requester ID) was borrowed from Linux (v5.10-rc6) and updated according to the Xen code base. XXX: I don't port pci_for_each_dma_alias from Linux which is a part of PCI-IOMMU bindings infrastucture as I don't have a good understanding for how it is expected to work in Xen environment. Also it is not completely clear whether we need to distinguish between different PCI types here (DEV_TYPE_PCI, DEV_TYPE_PCI_HOST_BRIDGE, etc). For example, how we should behave here if the host bridge doesn't have a stream ID (so not described in iommu-map property) just simple fail or bypasses translation? [1] https://www.kernel.org/doc/Documentation/devicetree/bindings/pci/pci-io= mmu.txt Signed-off-by: Oleksandr Tyshchenko Signed-off-by: Stewart Hildebrand --- v2->v3: * new patch title (was: iommu/arm: Introduce iommu_add_dt_pci_device API) * renamed function from: iommu_add_dt_pci_device to: iommu_add_dt_pci_sideband_ids * removed stale ops->add_device check * iommu.h: add empty stub iommu_add_dt_pci_sideband_ids for !HAS_DEVICE_TREE * iommu.h: add iommu_add_pci_sideband_ids helper * iommu.h: don't wrap prototype in #ifdef CONFIG_HAS_PCI * s/iommu_fwspec_free(pci_to_dev(pdev))/iommu_fwspec_free(dev)/ v1->v2: * remove extra devfn parameter since pdev fully describes the device * remove ops->add_device() call from iommu_add_dt_pci_device(). Instead, re= ly on the existing iommu call in iommu_add_device(). * move the ops->add_device and ops->dt_xlate checks earlier downstream->v1: * rebase * add const qualifier to struct dt_device_node *np arg in dt_map_id() * add const qualifier to struct dt_device_node *np declaration in iommu_add= _pci_device() * use stdint.h types instead of u8/u32/etc... * rename functions: s/dt_iommu_xlate/iommu_dt_xlate/ s/dt_map_id/iommu_dt_pci_map_id/ s/iommu_add_pci_device/iommu_add_dt_pci_device/ * add device_is_protected check in iommu_add_dt_pci_device * wrap prototypes in CONFIG_HAS_PCI (cherry picked from commit 734e3bf6ee77e7947667ab8fa96c25b349c2e1da from the downstream branch poc/pci-passthrough from https://gitlab.com/xen-project/people/bmarquis/xen-arm-poc.git) --- xen/drivers/passthrough/device_tree.c | 140 ++++++++++++++++++++++++++ xen/include/xen/device_tree.h | 25 +++++ xen/include/xen/iommu.h | 17 +++- 3 files changed, 181 insertions(+), 1 deletion(-) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthroug= h/device_tree.c index 1b50f4670944..d568166e19ec 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -151,6 +151,146 @@ static int iommu_dt_xlate(struct device *dev, return ops->dt_xlate(dev, iommu_spec); } =20 +#ifdef CONFIG_HAS_PCI +int iommu_dt_pci_map_id(const struct dt_device_node *np, uint32_t id, + const char *map_name, const char *map_mask_name, + struct dt_device_node **target, uint32_t *id_out) +{ + uint32_t map_mask, masked_id, map_len; + const __be32 *map =3D NULL; + + if ( !np || !map_name || (!target && !id_out) ) + return -EINVAL; + + map =3D dt_get_property(np, map_name, &map_len); + if ( !map ) + { + if ( target ) + return -ENODEV; + /* Otherwise, no map implies no translation */ + *id_out =3D id; + return 0; + } + + if ( !map_len || map_len % (4 * sizeof(*map)) ) + { + printk(XENLOG_ERR "%pOF: Error: Bad %s length: %d\n", np, + map_name, map_len); + return -EINVAL; + } + + /* The default is to select all bits. */ + map_mask =3D 0xffffffff; + + /* + * Can be overridden by "{iommu,msi}-map-mask" property. + * If of_property_read_u32() fails, the default is used. + */ + if ( map_mask_name ) + dt_property_read_u32(np, map_mask_name, &map_mask); + + masked_id =3D map_mask & id; + for ( ; (int)map_len > 0; map_len -=3D 4 * sizeof(*map), map +=3D 4 ) + { + struct dt_device_node *phandle_node; + uint32_t id_base =3D be32_to_cpup(map + 0); + uint32_t phandle =3D be32_to_cpup(map + 1); + uint32_t out_base =3D be32_to_cpup(map + 2); + uint32_t id_len =3D be32_to_cpup(map + 3); + + if ( id_base & ~map_mask ) + { + printk(XENLOG_ERR "%pOF: Invalid %s translation - %s-mask (0x%= x) ignores id-base (0x%x)\n", + np, map_name, map_name, map_mask, id_base); + return -EFAULT; + } + + if ( masked_id < id_base || masked_id >=3D id_base + id_len ) + continue; + + phandle_node =3D dt_find_node_by_phandle(phandle); + if ( !phandle_node ) + return -ENODEV; + + if ( target ) + { + if ( !*target ) + *target =3D phandle_node; + + if ( *target !=3D phandle_node ) + continue; + } + + if ( id_out ) + *id_out =3D masked_id - id_base + out_base; + + printk(XENLOG_DEBUG "%pOF: %s, using mask %08x, id-base: %08x, out= -base: %08x, length: %08x, id: %08x -> %08x\n", + np, map_name, map_mask, id_base, out_base, id_len, id, + masked_id - id_base + out_base); + return 0; + } + + printk(XENLOG_ERR "%pOF: no %s translation for id 0x%x on %pOF\n", + np, map_name, id, target && *target ? *target : NULL); + + /* + * NOTE: Linux bypasses translation without returning an error here, + * but should we behave in the same way on Xen? Restrict for now. + */ + return -EFAULT; +} + +int iommu_add_dt_pci_sideband_ids(struct pci_dev *pdev) +{ + const struct iommu_ops *ops =3D iommu_get_ops(); + struct dt_phandle_args iommu_spec =3D { .args_count =3D 1 }; + struct device *dev =3D pci_to_dev(pdev); + const struct dt_device_node *np; + int rc =3D NO_IOMMU; + + if ( !iommu_enabled ) + return NO_IOMMU; + + if ( !ops ) + return -EINVAL; + + if ( device_is_protected(dev) ) + return 0; + + if ( dev_iommu_fwspec_get(dev) ) + return -EEXIST; + + np =3D pci_find_host_bridge_node(pdev); + if ( !np ) + return -ENODEV; + + /* + * The driver which supports generic PCI-IOMMU DT bindings must have + * these callback implemented. + */ + if ( !ops->dt_xlate ) + return -EINVAL; + + /* + * According to the Documentation/devicetree/bindings/pci/pci-iommu.txt + * from Linux. + */ + rc =3D iommu_dt_pci_map_id(np, PCI_BDF(pdev->bus, pdev->devfn), "iommu= -map", + "iommu-map-mask", &iommu_spec.np, iommu_spec.= args); + if ( rc ) + return rc =3D=3D -ENODEV ? NO_IOMMU : rc; + + rc =3D iommu_dt_xlate(dev, &iommu_spec); + if ( rc < 0 ) + { + iommu_fwspec_free(dev); + return -EINVAL; + } + + return rc; +} +#endif /* CONFIG_HAS_PCI */ + int iommu_add_dt_device(struct dt_device_node *np) { const struct iommu_ops *ops =3D iommu_get_ops(); diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index c1e4751a581f..dc40fdfb9231 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -852,6 +852,31 @@ int dt_count_phandle_with_args(const struct dt_device_= node *np, */ int dt_get_pci_domain_nr(struct dt_device_node *node); =20 +#ifdef CONFIG_HAS_PCI +/** + * iommu_dt_pci_map_id - Translate an ID through a downstream mapping. + * @np: root complex device node. + * @id: device ID to map. + * @map_name: property name of the map to use. + * @map_mask_name: optional property name of the mask to use. + * @target: optional pointer to a target device node. + * @id_out: optional pointer to receive the translated ID. + * + * Given a device ID, look up the appropriate implementation-defined + * platform ID and/or the target device which receives transactions on that + * ID, as per the "iommu-map" and "msi-map" bindings. Either of @target or + * @id_out may be NULL if only the other is required. If @target points to + * a non-NULL device node pointer, only entries targeting that node will be + * matched; if it points to a NULL value, it will receive the device node = of + * the first matching target phandle, with a reference held. + * + * Return: 0 on success or a standard error code on failure. + */ +int iommu_dt_pci_map_id(const struct dt_device_node *np, uint32_t id, + const char *map_name, const char *map_mask_name, + struct dt_device_node **target, uint32_t *id_out); +#endif /* CONFIG_HAS_PCI */ + struct dt_device_node *dt_find_node_by_phandle(dt_phandle handle); =20 #ifdef CONFIG_DEVICE_TREE_DEBUG diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 405db59971c5..e83de1fced67 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -26,6 +26,7 @@ #include #include #include +#include #include =20 TYPE_SAFE(uint64_t, dfn); @@ -219,7 +220,8 @@ int iommu_dt_domain_init(struct domain *d); int iommu_release_dt_devices(struct domain *d); =20 /* - * Helper to add master device to the IOMMU using generic IOMMU DT binding= s. + * Helpers to add master device to the IOMMU using generic (PCI-)IOMMU + * DT bindings. * * Return values: * 0 : device is protected by an IOMMU @@ -228,12 +230,25 @@ int iommu_release_dt_devices(struct domain *d); * (IOMMU is not enabled/present or device is not connected to it). */ int iommu_add_dt_device(struct dt_device_node *np); +int iommu_add_dt_pci_sideband_ids(struct pci_dev *pdev); =20 int iommu_do_dt_domctl(struct xen_domctl *, struct domain *, XEN_GUEST_HANDLE_PARAM(xen_domctl_t)); =20 +#else /* !HAS_DEVICE_TREE */ +static inline int iommu_add_dt_pci_sideband_ids(struct pci_dev *pdev) +{ + return 0; +} #endif /* HAS_DEVICE_TREE */ =20 +static inline int iommu_add_pci_sideband_ids(struct pci_dev *pdev) +{ + if ( acpi_disabled ) + return iommu_add_dt_pci_sideband_ids(pdev); + return 0; +} + struct page_info; =20 /* --=20 2.40.1 From nobody Wed Apr 24 11:54:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1684444176; cv=pass; d=zohomail.com; s=zohoarc; b=ldh9HJ3AqgLDyhylpyR4mfCyeh9ZjL+/NLGAzAag7Gci77QGoy9EuhUwcGOk+Q+oN89yMfB48fha/bl3iTSNOMWbIy9rPmEhTO8+xpLmNBnlAVYGdDt6hDXrHFikIy81G7WZVl1L2Yl1jpFUsZ3YnpQAq7Y/XaNASEAjyX57hZ8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684444176; 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; bh=MxTD/B2LQB1Jv047UjgOqA+QiFcS4OIKP4Cx/fTEEkk=; b=FDF3ZNZ5GuLB5VlsNNjbS4tAMYQCZEGuz9slKz44TlzFVRtXPZnjGP8dcOP7sXt9YmV0NodwOZnA5CIVPcp1apialpPvX1vb+JvRHyML8TV3TKwqHDlX4yN4xhKsliqDFr6MwpyUPTpr5mCeSClPSeIw+jMSOqqDMbCQWwjQ7X4= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1684444176640365.8225793150044; Thu, 18 May 2023 14:09:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.536559.834998 (Exim 4.92) (envelope-from ) id 1pzks6-0005vS-TJ; Thu, 18 May 2023 21:09:14 +0000 Received: by outflank-mailman (output) from mailman id 536559.834998; Thu, 18 May 2023 21:09:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pzks6-0005vJ-Pw; Thu, 18 May 2023 21:09:14 +0000 Received: by outflank-mailman (input) for mailman id 536559; Thu, 18 May 2023 21:09:13 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pzks5-0003gZ-8d for xen-devel@lists.xenproject.org; Thu, 18 May 2023 21:09:13 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20605.outbound.protection.outlook.com [2a01:111:f400:7eaa::605]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 3b716a8e-f5c0-11ed-8611-37d641c3527e; Thu, 18 May 2023 23:09:11 +0200 (CEST) Received: from DS7PR03CA0097.namprd03.prod.outlook.com (2603:10b6:5:3b7::12) by SJ0PR12MB8613.namprd12.prod.outlook.com (2603:10b6:a03:44d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.33; Thu, 18 May 2023 21:09:03 +0000 Received: from DM6NAM11FT055.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b7:cafe::4e) by DS7PR03CA0097.outlook.office365.com (2603:10b6:5:3b7::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.19 via Frontend Transport; Thu, 18 May 2023 21:09:03 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT055.mail.protection.outlook.com (10.13.173.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.21 via Frontend Transport; Thu, 18 May 2023 21:09:03 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 18 May 2023 16:09:02 -0500 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 18 May 2023 16:09:01 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 3b716a8e-f5c0-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SUqtsNWKjzke+85coSzJ7VAQldY8bQL5RXLADsy0VRONFXm2cME3ji5kBBpdJPwQVJR5XSz8gkB15vsL5hzJkBEK+Qk0zyJRhYNJH1yIsjqohmWRPmBgxtShin2YQoXYjhgHwkzrskVMoFQ2L28NNnllWeikDOzZyYxLhaBncV3XsN/QwXIy5E7xiq/MIB23Jo29A6BZq541NItZVdFAgsAU1eKncvflEaRDYAO2mX2xVt49S32I9wVbw3Axsvc3gGfxgh8QkPa7fbW+QwFQkvZ1NgdN+cjF6nsZxk2zXvVaFouo8BkrBNcrNP4pY3kz4LbYeSFZb3CaJzJsRsAX/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MxTD/B2LQB1Jv047UjgOqA+QiFcS4OIKP4Cx/fTEEkk=; b=SPbyHzZ81QzXgSSXTN7atwxTEtmDckKn9QOLSx1zAOTy4yzTwG2ZBBlaze7PuwQe3UVX2SK7r7PP1PxiK+8itUY66XADRoY0X5IRr4DpvTlj9Xi4vzvif8Bi520T5hRPJe+bsw0OgWm59CjOyK9WgcYV3B0scQUw9b2wivGD1AWq5eGqr+FMJJcL4V2XV42f4XjbSFicjWHZ6bEcZtnTy6xZdDg7XwpGf9vlAUWdPk6Zl/tcwd/zwlCL852fyhyZrfaVwG9Y3hMfmp3zwZeSZ03Kqj+yaJAaLoVL1C4rPiFjRFm5st7ph0V2bIEhiYWeQCgqO8W/1UVJNcI16txUsw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MxTD/B2LQB1Jv047UjgOqA+QiFcS4OIKP4Cx/fTEEkk=; b=kFOVTD5IAn72oyfE6DV51rj2DRsq5Hp3w8p3ytZqEGHCk4ICOSqlJB1H3OBCvd8QOiRR2FcMTjTOc1LCw0JR33llJnHPkXWqrcqIUtvoWe72ZU5QfTak6g8VUrBnkmtUB60QxHHzeixrUA4qJlqcEszwMkZTNxBls0DNXYv1SKA= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Stewart Hildebrand To: CC: Stewart Hildebrand , Stefano Stabellini , Julien Grall , Rahul Singh , Bertrand Marquis , "Jan Beulich" Subject: [PATCH v3 4/6] iommu/arm: iommu_add_dt_pci_sideband_ids phantom handling Date: Thu, 18 May 2023 17:06:56 -0400 Message-ID: <20230518210658.66156-5-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230518210658.66156-1-stewart.hildebrand@amd.com> References: <20230518210658.66156-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT055:EE_|SJ0PR12MB8613:EE_ X-MS-Office365-Filtering-Correlation-Id: f698b08a-9328-4df4-aa27-08db57e41bc1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Dd6XR/njwJuEOsighaKQGU0olMfUNbREGRa0WoDP0rVTPmXdRG4yhBPW8q+07gIVLTF5HkcYVsevVgHQO1zikP13N7QoWShXR+HUDzGOyPeziKqjOMFoxMCB64RzMHtNRhxIpJAUzVtDHfC9E/Q/AbGRXh9DeoaG86o1fGI2jxv9dQJ+7ZEknu8gxBpU19WiASBa2mcwLn2RDtIhJBYQj4UqHSy3YOaE7qgq9eBb/GziJ/03jMx3Gh41JctGuSGP0TxXjk70B8+vGQzu8mSrO6bFDEXMOn0O0EIi19YF5JhvCopNbObsnhm/bLUJleS/Sg7Q6g+uOCc9Alzmzli/m1Whobf8zf6M4p9F8aXIKxr9f6tfvhRChcZBi6L+COnHkYzxIKxt8qz+CGPdV505Ng6kE+Tdh96PN1piZ9U+F75y7fgdURr3QeH9i3AsK5hrYkymbSanyCaBq4KaLxoWX3ywSwFFzdWF4GkAldppsnPPq3d7wCUoUQ9VKhI9mwMxUaCvLSYkCA4cEFo+EsxLhlbksM3ZAMd0vEKzvyO9g6NP0bys2jZY9Kr6wc16Q4RDvWhIm7D9cmgIiEHMOaZ4Zwa57AqDZeFn8u78sI7VQ5OSy3Thoh+GLL2Go51ar9K15kJalL4I0GPXtOKOfnR9Nlk3tWxdFHskPwu1PTVqOo+dwtTTggI28Xv67BCarXosuSZyK05QJb+rn5dxqk1LZBeCqAuJ+D4/mWPpXzf7wAJpGWPkzYMiGEhs0zCVfDTAMRe6VqPKNKdu2HeUKsRPbg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(376002)(346002)(136003)(396003)(39860400002)(451199021)(46966006)(40470700004)(36840700001)(40460700003)(70586007)(4326008)(86362001)(6916009)(478600001)(70206006)(966005)(54906003)(316002)(36756003)(83380400001)(36860700001)(26005)(1076003)(336012)(186003)(47076005)(426003)(2616005)(2906002)(44832011)(8676002)(8936002)(40480700001)(41300700001)(356005)(82310400005)(5660300002)(82740400003)(81166007)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2023 21:09:03.2112 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f698b08a-9328-4df4-aa27-08db57e41bc1 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT055.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB8613 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1684444178953100001 Content-Type: text/plain; charset="utf-8" Handle phantom functions in iommu_add_dt_pci_sideband_ids(). Each phantom function will have a unique requestor ID (RID)/BDF. On ARM, we need to map/translate the RID/BDF to an AXI stream ID for each phantom function according to the pci-iommu device tree mapping [1]. The RID/BDF -> AXI stre= am ID mapping in DT could allow phantom devices (i.e. devices with phantom functi= ons) to use different AXI stream IDs based on the (phantom) function. [1] https://www.kernel.org/doc/Documentation/devicetree/bindings/pci/pci-io= mmu.txt Signed-off-by: Stewart Hildebrand --- v2->v3: * new patch title (was: iommu/arm: iommu_add_dt_pci_device phantom handling) * rework loop to reduce duplication * s/iommu_fwspec_free(pci_to_dev(pdev))/iommu_fwspec_free(dev)/ v1->v2: * new patch --- xen/drivers/passthrough/device_tree.c | 33 ++++++++++++++++----------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthroug= h/device_tree.c index d568166e19ec..c18ddae3e993 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -247,6 +247,7 @@ int iommu_add_dt_pci_sideband_ids(struct pci_dev *pdev) struct device *dev =3D pci_to_dev(pdev); const struct dt_device_node *np; int rc =3D NO_IOMMU; + unsigned int devfn =3D pdev->devfn; =20 if ( !iommu_enabled ) return NO_IOMMU; @@ -271,21 +272,27 @@ int iommu_add_dt_pci_sideband_ids(struct pci_dev *pde= v) if ( !ops->dt_xlate ) return -EINVAL; =20 - /* - * According to the Documentation/devicetree/bindings/pci/pci-iommu.txt - * from Linux. - */ - rc =3D iommu_dt_pci_map_id(np, PCI_BDF(pdev->bus, pdev->devfn), "iommu= -map", - "iommu-map-mask", &iommu_spec.np, iommu_spec.= args); - if ( rc ) - return rc =3D=3D -ENODEV ? NO_IOMMU : rc; + do { + /* + * According to the Documentation/devicetree/bindings/pci/pci-iomm= u.txt + * from Linux. + */ + rc =3D iommu_dt_pci_map_id(np, PCI_BDF(pdev->bus, devfn), "iommu-m= ap", + "iommu-map-mask", &iommu_spec.np, iommu_s= pec.args); + if ( rc ) + return rc =3D=3D -ENODEV ? NO_IOMMU : rc; =20 - rc =3D iommu_dt_xlate(dev, &iommu_spec); - if ( rc < 0 ) - { - iommu_fwspec_free(dev); - return -EINVAL; + rc =3D iommu_dt_xlate(dev, &iommu_spec); + if ( rc < 0 ) + { + iommu_fwspec_free(dev); + return -EINVAL; + } + + devfn +=3D pdev->phantom_stride; } + while ( devfn !=3D pdev->devfn && + PCI_SLOT(devfn) =3D=3D PCI_SLOT(pdev->devfn)); =20 return rc; } --=20 2.40.1 From nobody Wed Apr 24 11:54:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1684444674; cv=pass; d=zohomail.com; s=zohoarc; b=XyyLl4T/DEtCjBZZlALPDKqG2JCo4b2W40hXJAPlr1+mUOaaa078FBHLpoqIDtYilv77BnEhR96w0sCIUxQMOt66pzP3Cgr3luUnS/2451PI1JhEDXgDDIbf3BUJLbJoMBdISrz6t6+s7drrZvK1ch4PJbcOs5RyZxKRtpe2jnk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684444674; 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; bh=RAz7bk/eEBRtyO3ChhU4KoUxEkKuzfEMkl7Zwu/CsVI=; b=I5Yw/jehCa5jkpIEVikpFEwgHLgGC9dWwxQ9xWW/sKqu2yQOEQU/sfJ3y9po17O9CZ0GFTSV+oxQQV/8a6PWYd5f1TvWKdc8CdqwBnWhjbaTrz5rBGO47y6J9wnjs0Y6kolm8QlcAjqC/1YiM18p+d8C7XfQUJ45rzoAVs+aBQU= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1684444674210238.92655555993872; Thu, 18 May 2023 14:17:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.536573.835027 (Exim 4.92) (envelope-from ) id 1pzl0A-0000Bb-6e; Thu, 18 May 2023 21:17:34 +0000 Received: by outflank-mailman (output) from mailman id 536573.835027; Thu, 18 May 2023 21:17:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pzl0A-0000BU-40; Thu, 18 May 2023 21:17:34 +0000 Received: by outflank-mailman (input) for mailman id 536573; Thu, 18 May 2023 21:17:33 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pzksW-0003gZ-NY for xen-devel@lists.xenproject.org; Thu, 18 May 2023 21:09:40 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2060a.outbound.protection.outlook.com [2a01:111:f400:7e88::60a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4baa4d84-f5c0-11ed-8611-37d641c3527e; Thu, 18 May 2023 23:09:38 +0200 (CEST) Received: from BN7PR06CA0051.namprd06.prod.outlook.com (2603:10b6:408:34::28) by PH8PR12MB8606.namprd12.prod.outlook.com (2603:10b6:510:1ce::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.19; Thu, 18 May 2023 21:09:32 +0000 Received: from BN8NAM11FT093.eop-nam11.prod.protection.outlook.com (2603:10b6:408:34:cafe::55) by BN7PR06CA0051.outlook.office365.com (2603:10b6:408:34::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.19 via Frontend Transport; Thu, 18 May 2023 21:09:32 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT093.mail.protection.outlook.com (10.13.177.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.21 via Frontend Transport; Thu, 18 May 2023 21:09:32 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 18 May 2023 16:09:32 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 18 May 2023 14:09:31 -0700 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 18 May 2023 16:09:30 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4baa4d84-f5c0-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E6Wr2OYG3a+Fm5SXOFHd2FRWHDmDxhUP8zsTxSyevBLLKvW+98zwcJC5HrmIS20DUDQ7A2WsSwf5xfZ/zJN+hziLpXUi7WBcsmV9w5iKVWEInVlHBfDuTnHBNYepfJrlVAtdcQRrbH+xOL1zpImvnKniWUoZrlXcVcqBVvy8spZf7RcTuut1ku/LL9zq0sFmvZiwu0q0OgdHvJjvNuRyDuDpU6SwT3shx6cvYukY+JXlXyWwuTgTQ1R0lRvfSWTs2rZA1ArmBYdSeoKCq/gWnXh8BF6UzPCJJBkzbgAOzTxDJlru3vmJeED1VXoalUM3MaRJ/SIlSGDRHCifHYwXUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=RAz7bk/eEBRtyO3ChhU4KoUxEkKuzfEMkl7Zwu/CsVI=; b=ZPCzaYJ6jvLx/ysZ+rUPQl3JSBxcdRp/qWmEwKlUmwc26buxu0w/dy6A5hSZ9hLrutq2pSLH9Ak/5nuBPM17lzaG1bW2lhNNr5uxFzg960VFoulR5xEkpHc95jHgi0bLvgfC6vVjtEloo4pA0UeebVrPmAJMSyg6Lf3rLUx0CISv10gKzzClOi+gWxidlOq2MaLsU1b2n1e0+awiM12/eUamoz/Tem4HNOwSm0bBNtkHMRRfsmtuE724tpAjUlL3U2rbDNp0rfLsZl7/ofXwmh7lwWHLGhhkN5hwAnLho9CLT+1q+9Aoa6nG19gQHVYCTAErjjSUPjCpAdvmg6G9Sw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RAz7bk/eEBRtyO3ChhU4KoUxEkKuzfEMkl7Zwu/CsVI=; b=ClklKs6DNata2RzT7hRoGKX5EWLWUZ+YquIktNtvQHO3mVIgFUGck54FwqnO999CAYT+0roNx/mcnY9fi+WdzYq+x+/8o+n5heL5/A5ZjLc0i3P7AfzBXi3Ifn416eY3nGracvn/NPTPJxE6XEbePrliYqlUyIiouasamqDfgKQ= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Stewart Hildebrand To: CC: Oleksandr Andrushchenko , Julien Grall , Rahul Singh , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk , Oleksandr Tyshchenko , Stewart Hildebrand Subject: [PATCH v3 5/6] xen/arm: smmuv2: Add PCI devices support for SMMUv2 Date: Thu, 18 May 2023 17:06:57 -0400 Message-ID: <20230518210658.66156-6-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230518210658.66156-1-stewart.hildebrand@amd.com> References: <20230518210658.66156-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT093:EE_|PH8PR12MB8606:EE_ X-MS-Office365-Filtering-Correlation-Id: aac9e896-4d5c-4822-0496-08db57e42d44 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZJT4YLVQhFLGIj9qIKSHASBsQ3ItZGieFdULQ3RKZleVCnzzYHspvXbeBeF96lyT1uNazn5AHeNpuJLUPNs/k3qwJU9EoywtdPIKRuBxNKP0jAL8NuekSvBPm/Wt8xLIvTpasaQhapS5Ar6ISh2YoJK54QvPlGjFSXSHfrEIKSr7KRCrmyxwlFZZkUka7bRdpvO/tkAoW3NzvsueMlLePUL7tZn2c+Mqh6/uPC3fQN2LG+M2Jji+IVCI+wlY/pQKLM1LIG3qtkJccsuWuswG1ILafM6QZUynrB8TxFJlUwwW7J7KXhbhVFwzGJxjVwk6bctbdfD5rU4BmjUV5+iJK2nUmFzZHMIRu5XwJVgTcE9GRQxVl92+ER85tzOMUmOXrDY8KykYMAN85zN7Gnx3gljqerfKhia7bLo7CqSD2Ye6gNrXmCrrRtN0MSbh/5mGTnzHmf3uzSVLLu2bharWN8rK6jarITz2oHUnwDeyYab/dvCbtE6dGS1HNIORyrao4a3bWuRPz3XTkH+A1PzejHN1pSy3CAUE4XNkMooNNxtyWNmGY8jpLZFiKhsStDv4T2mNhCvAeEfI/ofSOqDgyFdpEchbc24BqUAOXE1dPBfNrDzQw5nqRkShSYArOnUS/zXW/MNq2zYweeLhN2VU1VDp4IUwdwXSyccWE1YXGHwSUx6+3Ehjtm9mDRQCrS776Uami60EUCVuRPqhGYI2fx4kkuE2/nihEPo1mPz2zPwDfZZnRxG2nrQgxemkbjpYHKjJKvycsUoIfeqGmxmNrW6wSY0Oyz0fu3ikCObFbFM= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(136003)(376002)(346002)(396003)(39860400002)(451199021)(40470700004)(36840700001)(46966006)(2906002)(478600001)(41300700001)(4326008)(6916009)(8936002)(8676002)(316002)(54906003)(44832011)(6666004)(70586007)(70206006)(5660300002)(40460700003)(966005)(26005)(1076003)(82740400003)(356005)(186003)(81166007)(2616005)(83380400001)(40480700001)(47076005)(36756003)(36860700001)(82310400005)(336012)(426003)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2023 21:09:32.6337 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aac9e896-4d5c-4822-0496-08db57e42d44 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT093.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB8606 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1684444675627100001 Content-Type: text/plain; charset="utf-8" From: Oleksandr Andrushchenko Signed-off-by: Oleksandr Tyshchenko Signed-off-by: Oleksandr Andrushchenko Signed-off-by: Stewart Hildebrand --- v2->v3: * invoke iommu_add_pci_sideband_ids() from add_device hook v1->v2: * ignore add_device/assign_device/reassign_device calls for phantom functio= ns (i.e. devfn !=3D pdev->devfn) downstream->v1: * wrap unused function in #ifdef 0 * remove the remove_device() stub since it was submitted separately to the = list [XEN][PATCH v6 12/19] xen/smmu: Add remove_device callback for smmu_iommu= ops https://lists.xenproject.org/archives/html/xen-devel/2023-05/msg00204.html * arm_smmu_(de)assign_dev: return error instead of crashing system * update condition in arm_smmu_reassign_dev * style fixup * add && !is_hardware_domain(d) into condition in arm_smmu_assign_dev() (cherry picked from commit 0c11a7f65f044c26d87d1e27ac6283ef1f9cfb7a from the downstream branch spider-master from https://github.com/xen-troops/xen.git) --- This is a file imported from Linux with modifications for Xen. What should = be the coding style for Xen modifications? --- xen/drivers/passthrough/arm/smmu.c | 114 +++++++++++++++++++++++------ 1 file changed, 93 insertions(+), 21 deletions(-) diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/a= rm/smmu.c index 5b6024d579a8..d426920d8f9b 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -134,8 +134,20 @@ typedef enum irqreturn irqreturn_t; /* Device logger functions * TODO: Handle PCI */ -#define dev_print(dev, lvl, fmt, ...) \ - printk(lvl "smmu: %s: " fmt, dt_node_full_name(dev_to_dt(dev)), ## __VA_= ARGS__) +#ifndef CONFIG_HAS_PCI +#define dev_print(dev, lvl, fmt, ...) \ + printk(lvl "smmu: %s: " fmt, dev_name(dev), ## __VA_ARGS__) +#else +#define dev_print(dev, lvl, fmt, ...) ({ \ + if ( !dev_is_pci((dev)) ) \ + printk(lvl "smmu: %s: " fmt, dev_name((dev)), ## __VA_ARGS__); \ + else \ + { \ + struct pci_dev *pdev =3D dev_to_pci((dev)); \ + printk(lvl "smmu: %pp: " fmt, &pdev->sbdf, ## __VA_ARGS__); \ + } \ +}) +#endif =20 #define dev_dbg(dev, fmt, ...) dev_print(dev, XENLOG_DEBUG, fmt, ## __VA_A= RGS__) #define dev_notice(dev, fmt, ...) dev_print(dev, XENLOG_INFO, fmt, ## __VA= _ARGS__) @@ -187,6 +199,7 @@ static void __iomem *devm_ioremap_resource(struct devic= e *dev, * Xen: PCI functions * TODO: It should be implemented when PCI will be supported */ +#if 0 /* unused */ #define to_pci_dev(dev) (NULL) static inline int pci_for_each_dma_alias(struct pci_dev *pdev, int (*fn) (struct pci_dev *pdev, @@ -196,6 +209,7 @@ static inline int pci_for_each_dma_alias(struct pci_dev= *pdev, BUG(); return 0; } +#endif =20 /* Xen: misc */ #define PHYS_MASK_SHIFT PADDR_BITS @@ -632,7 +646,7 @@ struct arm_smmu_master_cfg { for (i =3D 0; idx =3D cfg->smendx[i], i < num; ++i) =20 struct arm_smmu_master { - struct device_node *of_node; + struct device *dev; struct rb_node node; struct arm_smmu_master_cfg cfg; }; @@ -724,7 +738,7 @@ arm_smmu_get_fwspec(struct arm_smmu_master_cfg *cfg) { struct arm_smmu_master *master =3D container_of(cfg, struct arm_smmu_master, cfg); - return dev_iommu_fwspec_get(&master->of_node->dev); + return dev_iommu_fwspec_get(master->dev); } =20 static void parse_driver_options(struct arm_smmu_device *smmu) @@ -757,7 +771,7 @@ static struct device_node *dev_get_dev_node(struct devi= ce *dev) } =20 static struct arm_smmu_master *find_smmu_master(struct arm_smmu_device *sm= mu, - struct device_node *dev_node) + struct device *dev) { struct rb_node *node =3D smmu->masters.rb_node; =20 @@ -766,9 +780,9 @@ static struct arm_smmu_master *find_smmu_master(struct = arm_smmu_device *smmu, =20 master =3D container_of(node, struct arm_smmu_master, node); =20 - if (dev_node < master->of_node) + if (dev < master->dev) node =3D node->rb_left; - else if (dev_node > master->of_node) + else if (dev > master->dev) node =3D node->rb_right; else return master; @@ -803,9 +817,9 @@ static int insert_smmu_master(struct arm_smmu_device *s= mmu, =3D container_of(*new, struct arm_smmu_master, node); =20 parent =3D *new; - if (master->of_node < this->of_node) + if (master->dev < this->dev) new =3D &((*new)->rb_left); - else if (master->of_node > this->of_node) + else if (master->dev > this->dev) new =3D &((*new)->rb_right); else return -EEXIST; @@ -824,18 +838,18 @@ static int arm_smmu_dt_add_device_legacy(struct arm_s= mmu_device *smmu, struct arm_smmu_master *master; struct device_node *dev_node =3D dev_get_dev_node(dev); =20 - master =3D find_smmu_master(smmu, dev_node); + master =3D find_smmu_master(smmu, dev); if (master) { dev_err(dev, "rejecting multiple registrations for master device %s\n", - dev_node->name); + dev_node ? dev_node->name : ""); return -EBUSY; } =20 master =3D devm_kzalloc(dev, sizeof(*master), GFP_KERNEL); if (!master) return -ENOMEM; - master->of_node =3D dev_node; + master->dev =3D dev; =20 /* Xen: Let Xen know that the device is protected by an SMMU */ device_set_protected(dev); @@ -845,7 +859,7 @@ static int arm_smmu_dt_add_device_legacy(struct arm_smm= u_device *smmu, (fwspec->ids[i] >=3D smmu->num_mapping_groups)) { dev_err(dev, "stream ID for master device %s greater than maximum allowed (%d)\n", - dev_node->name, smmu->num_mapping_groups); + dev_node ? dev_node->name : "", smmu->num_mapping_groups); return -ERANGE; } master->cfg.smendx[i] =3D INVALID_SMENDX; @@ -881,6 +895,21 @@ static int arm_smmu_dt_add_device_generic(u8 devfn, st= ruct device *dev) struct arm_smmu_device *smmu; struct iommu_fwspec *fwspec; =20 +#ifdef CONFIG_HAS_PCI + if ( dev_is_pci(dev) ) + { + struct pci_dev *pdev =3D dev_to_pci(dev); + int ret; + + if ( devfn !=3D pdev->devfn ) + return 0; + + ret =3D iommu_add_pci_sideband_ids(pdev); + if ( ret < 0 ) + iommu_fwspec_free(dev); + } +#endif + fwspec =3D dev_iommu_fwspec_get(dev); if (fwspec =3D=3D NULL) return -ENXIO; @@ -912,11 +941,10 @@ static struct arm_smmu_device *find_smmu_for_device(s= truct device *dev) { struct arm_smmu_device *smmu; struct arm_smmu_master *master =3D NULL; - struct device_node *dev_node =3D dev_get_dev_node(dev); =20 spin_lock(&arm_smmu_devices_lock); list_for_each_entry(smmu, &arm_smmu_devices, list) { - master =3D find_smmu_master(smmu, dev_node); + master =3D find_smmu_master(smmu, dev); if (master) break; } @@ -2006,6 +2034,7 @@ static bool arm_smmu_capable(enum iommu_cap cap) } #endif =20 +#if 0 /* Not used */ static int __arm_smmu_get_pci_sid(struct pci_dev *pdev, u16 alias, void *d= ata) { *((u16 *)data) =3D alias; @@ -2016,6 +2045,7 @@ static void __arm_smmu_release_pci_iommudata(void *da= ta) { kfree(data); } +#endif =20 static int arm_smmu_add_device(struct device *dev) { @@ -2023,12 +2053,13 @@ static int arm_smmu_add_device(struct device *dev) struct arm_smmu_master_cfg *cfg; struct iommu_group *group; void (*releasefn)(void *) =3D NULL; - int ret; =20 smmu =3D find_smmu_for_device(dev); if (!smmu) return -ENODEV; =20 + /* There is no need to distinguish here, thanks to PCI-IOMMU DT bindings = */ +#if 0 if (dev_is_pci(dev)) { struct pci_dev *pdev =3D to_pci_dev(dev); struct iommu_fwspec *fwspec; @@ -2053,10 +2084,12 @@ static int arm_smmu_add_device(struct device *dev) &fwspec->ids[0]); releasefn =3D __arm_smmu_release_pci_iommudata; cfg->smmu =3D smmu; - } else { + } else +#endif + { struct arm_smmu_master *master; =20 - master =3D find_smmu_master(smmu, dev->of_node); + master =3D find_smmu_master(smmu, dev); if (!master) { return -ENODEV; } @@ -2724,6 +2757,27 @@ static int arm_smmu_assign_dev(struct domain *d, u8 = devfn, return -ENOMEM; } =20 +#ifdef CONFIG_HAS_PCI + if ( dev_is_pci(dev) && !is_hardware_domain(d) ) + { + struct pci_dev *pdev =3D dev_to_pci(dev); + + printk(XENLOG_INFO "Assigning device %04x:%02x:%02x.%u to dom%d\n", + pdev->seg, pdev->bus, PCI_SLOT(devfn), PCI_FUNC(devfn), + d->domain_id); + + if ( devfn !=3D pdev->devfn || pdev->domain =3D=3D d ) + return 0; + + list_move(&pdev->domain_list, &d->pdev_list); + pdev->domain =3D d; + + /* dom_io is used as a sentinel for quarantined devices */ + if ( d =3D=3D dom_io ) + return 0; + } +#endif + if (!dev_iommu_group(dev)) { ret =3D arm_smmu_add_device(dev); if (ret) @@ -2773,11 +2827,29 @@ out: return ret; } =20 -static int arm_smmu_deassign_dev(struct domain *d, struct device *dev) +static int arm_smmu_deassign_dev(struct domain *d, u8 devfn, struct device= *dev) { struct iommu_domain *domain =3D dev_iommu_domain(dev); struct arm_smmu_xen_domain *xen_domain; =20 +#ifdef CONFIG_HAS_PCI + if ( dev_is_pci(dev) ) + { + struct pci_dev *pdev =3D dev_to_pci(dev); + + printk(XENLOG_INFO "Deassigning device %04x:%02x:%02x.%u from dom%d\n", + pdev->seg, pdev->bus, PCI_SLOT(devfn), PCI_FUNC(devfn), + d->domain_id); + + if ( devfn !=3D pdev->devfn ) + return 0; + + /* dom_io is used as a sentinel for quarantined devices */ + if ( d =3D=3D dom_io ) + return 0; + } +#endif + xen_domain =3D dom_iommu(d)->arch.priv; =20 if (!domain || domain->priv->cfg.domain !=3D d) { @@ -2805,13 +2877,13 @@ static int arm_smmu_reassign_dev(struct domain *s, = struct domain *t, int ret =3D 0; =20 /* Don't allow remapping on other domain than hwdom */ - if ( t && !is_hardware_domain(t) ) + if ( t && !is_hardware_domain(t) && t !=3D dom_io ) return -EPERM; =20 if (t =3D=3D s) return 0; =20 - ret =3D arm_smmu_deassign_dev(s, dev); + ret =3D arm_smmu_deassign_dev(s, devfn, dev); if (ret) return ret; =20 --=20 2.40.1 From nobody Wed Apr 24 11:54:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1684444302; cv=pass; d=zohomail.com; s=zohoarc; b=LUSfi+Vfmp7cGvkpnTFOqkFL6uYwvBh1T7Vu0NnUC0mh5EiSMVl9e5IX+Wv2S/J+UDFF7k4RuHXF10/oDVLRgA7zLXhJZXH3DRDBeB3gaSWnIomFNk23EI26TsUaNn07NzEn00W7Rm3luElXio1obfe6QckBUl5CRqq+rciZv5U= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684444302; 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; bh=Lc3aiT/FBstHJO8Rds/4fwDxNeL7AHWhcXKg/oYVb4o=; b=F/R3v6fmg2RFFj2iiVBnm5im0DY6gI0A3D/wW0Hzha0pcpw0CJUrgFufHqRaYmhWy/VZrj2orZ1IEbScCbPwbGX3VR0FmvJoE9hQaerNYD/CgIU9EBCceHaKyOgYU6IwiewiWwfmeThf3zaU5b/IjYM9ytqeDdTlYkBXVEsl0rA= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1684444302551962.2397180519802; Thu, 18 May 2023 14:11:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.536566.835008 (Exim 4.92) (envelope-from ) id 1pzku4-0007T4-9e; Thu, 18 May 2023 21:11:16 +0000 Received: by outflank-mailman (output) from mailman id 536566.835008; Thu, 18 May 2023 21:11:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pzku4-0007Sx-6p; Thu, 18 May 2023 21:11:16 +0000 Received: by outflank-mailman (input) for mailman id 536566; Thu, 18 May 2023 21:11:15 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pzku3-0007Sr-79 for xen-devel@lists.xenproject.org; Thu, 18 May 2023 21:11:15 +0000 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on20628.outbound.protection.outlook.com [2a01:111:f400:7e8c::628]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 841f0c6e-f5c0-11ed-b22d-6b7b168915f2; Thu, 18 May 2023 23:11:13 +0200 (CEST) Received: from SJ0PR13CA0010.namprd13.prod.outlook.com (2603:10b6:a03:2c0::15) by PH8PR12MB7325.namprd12.prod.outlook.com (2603:10b6:510:217::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.17; Thu, 18 May 2023 21:11:07 +0000 Received: from DM6NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:a03:2c0:cafe::76) by SJ0PR13CA0010.outlook.office365.com (2603:10b6:a03:2c0::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.6 via Frontend Transport; Thu, 18 May 2023 21:11:07 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT066.mail.protection.outlook.com (10.13.173.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6411.19 via Frontend Transport; Thu, 18 May 2023 21:11:06 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 18 May 2023 16:11:05 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 18 May 2023 14:11:05 -0700 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 18 May 2023 16:11:03 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 841f0c6e-f5c0-11ed-b22d-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=je85EGooONoIrZymclRq8Z4Wjgh0PWAaj+mgjmzhQZbzc2doVtNBu7y8gM7dKQ20xFNzT/QjNnIsg06StOJfX9SPGPjOQV6nWRTFAiT3xKFg8s/k7E7ySiOqKacIkP/qSw6gZirI4026imAPPjcw/jDaP01fK3/v3RDHURspUeVPQWShfLf2jY/cDwmmk3p+IFrYKYsowWF6CoAUPvLlxOCuzKcsNRnqAM170n3MZsFxKKGoRINZNVdsQqgij6DZ5Sv5hd7Fu9ReAFNaZjIUEHlEE0rm8caAVV+ommBdamO0XGl3A5SLmTS/w//1hG5t3YMNem5DM7lFP+/EfndTPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Lc3aiT/FBstHJO8Rds/4fwDxNeL7AHWhcXKg/oYVb4o=; b=iJavxXkt7TgRqQDkFyKwpm7WhF4esoh/MhXdPlAsxwckORZHh95rzh0V+PWvlNfGp6jB5SP4epN+eWFM0c6RyVBRlfBjwuKe7fZB7iTlIqLcTvWyFw4N6soXEDqKngP7q5O91q4h5ChLiWa/Rd72WmGZ9TFOPQ8j3HHEFLwGp3BVAGIB55CDiAyu1ROS/sNpsgNHkgy3NygKvBPBw1Qze/NJUI6GLvyfDbuCUAinkek4mOdkgMSjWYFFtul3FSk3jheX3jkzyYEc44ACXH/mjFZvA3P8JrgIvZC6pA15G9VkGcsXsLaX9b6iKeD2j28l5YgV1GWGtW97Iw4FpMGHwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Lc3aiT/FBstHJO8Rds/4fwDxNeL7AHWhcXKg/oYVb4o=; b=1BmPev53OzxrLHodE+t4gKY3N4J94Zdmlja+8vq2S0GCfhFtsRksEt9DoCF6MmI1akn3Tpx8bsN1FvFkQ46/hx9j0B+m5B775+fFAGSX2L+l/a6Fx5iEyh9L/V+qi/lfFTKQLj2qE6dLUgVyt5wdbrhV8cNWjsnzR4zhn/ln0PQ= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Stewart Hildebrand To: CC: Rahul Singh , Bertrand Marquis , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Stewart Hildebrand Subject: [PATCH v3 6/6] xen/arm: smmuv3: Add PCI devices support for SMMUv3 Date: Thu, 18 May 2023 17:06:58 -0400 Message-ID: <20230518210658.66156-7-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230518210658.66156-1-stewart.hildebrand@amd.com> References: <20230518210658.66156-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT066:EE_|PH8PR12MB7325:EE_ X-MS-Office365-Filtering-Correlation-Id: 6223ce84-9df2-493d-43a4-08db57e46555 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MZglEBikKfx/a1lsqwlQhgOMgnn3h5VXxsWqPjaTZooZ7RSQwadQxX3C4rc40re8ez3M6vN351DrzGJWqy44IIe6GQmPAk43CA32i8S0hKEzM/c9Z73dR4woNe8hqTV/HF7m7CgO3uCCXiiIFZQuHOUbTyJRUIKJiEuydpiPxpoEZB4XKBQvv0MW6Mic5vnNyd02kmo+osiq1amgEisLuH/qs4odWBezGdHbKu3C4E96XRtIYRH9JX+aFr8FtUMKXfedYoDLsSvstiqQ00lv17D3McMiT55PXiO8RdxNLlET6J22yH467VXWT1Zjwa33Pq+4kjV/PIAESklmfliBHQEI4GDL8XaMTd06t2hmhjiCOcOB1SN8Qo6UJ9jIissWaLza3WHnE1y5+bnEAYDKPyBWfsy5J5TTiccM1CYkfFqQsdBrOZzwauJvQ9h8lp1IJBVw1sK0/sI8+Wx0/1hiTxYGeNpCJI8kOSeE34Cs45pHrqK/UdK6/sQf47KQ02MsG0uxNo/SbGfTh8j7DxG56qFLTAJEHmoa5jSD4pKlKQ6e2ptcJ1YhN51fHAcoJAaQ4WiKyAi/fx8YP7C7nlVESPzpCv2/IC8bUOQZqf/XmCstrTOBoc2fNqV1XEphmEP2B2Dm29lWXDpa0NpDQzlDI61Or2RzEGs4L0DupWjh0I//ENeQPCKXGPLmNoEZWSDO+vRHZ+2zJZf7y9jN5+PUzSmNVFjtOeoS2Oc+OTI0YNJbObDbOhpOrhY2qk7yl2Yw4eVxRX7lw7jPw6CXpUbSPw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(346002)(136003)(39860400002)(396003)(376002)(451199021)(46966006)(36840700001)(40470700004)(478600001)(316002)(4326008)(44832011)(2906002)(8936002)(6916009)(41300700001)(70206006)(8676002)(54906003)(6666004)(5660300002)(70586007)(966005)(40460700003)(1076003)(26005)(82740400003)(186003)(81166007)(40480700001)(83380400001)(36860700001)(36756003)(2616005)(47076005)(82310400005)(86362001)(356005)(426003)(336012)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2023 21:11:06.6522 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6223ce84-9df2-493d-43a4-08db57e46555 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7325 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1684444303809100001 Content-Type: text/plain; charset="utf-8" From: Rahul Singh Signed-off-by: Rahul Singh Signed-off-by: Stewart Hildebrand --- v2->v3: * rebase * invoke iommu_add_pci_sideband_ids() from add_device hook v1->v2: * ignore add_device/assign_device/reassign_device calls for phantom functio= ns (i.e. devfn !=3D pdev->devfn) downstream->v1: * rebase * move 2 replacements of s/dt_device_set_protected(dev_to_dt(dev))/device_s= et_protected(dev)/ from this commit to ("xen/arm: Move is_protected flag to struct device") so as to not break ability to bisect * adjust patch title (remove stray space) * arm_smmu_(de)assign_dev: return error instead of crashing system * remove arm_smmu_remove_device() stub * update condition in arm_smmu_reassign_dev * style fixup (cherry picked from commit 7ed6c3ab250d899fe6e893a514278e406a2893e8 from the downstream branch poc/pci-passthrough from https://gitlab.com/xen-project/people/bmarquis/xen-arm-poc.git) --- This is a file imported from Linux with modifications for Xen. What should = be the coding style used for Xen modifications? --- xen/drivers/passthrough/arm/smmu-v3.c | 76 +++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/xen/drivers/passthrough/arm/smmu-v3.c b/xen/drivers/passthroug= h/arm/smmu-v3.c index f5910e79922f..a9ca889bd437 100644 --- a/xen/drivers/passthrough/arm/smmu-v3.c +++ b/xen/drivers/passthrough/arm/smmu-v3.c @@ -1469,14 +1469,32 @@ static bool arm_smmu_sid_in_range(struct arm_smmu_d= evice *smmu, u32 sid) } /* Forward declaration */ static struct arm_smmu_device *arm_smmu_get_by_dev(const struct device *de= v); +static int arm_smmu_assign_dev(struct domain *d, u8 devfn, + struct device *dev, u32 flag); =20 static int arm_smmu_add_device(u8 devfn, struct device *dev) { int i, ret; struct arm_smmu_device *smmu; struct arm_smmu_master *master; - struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(dev); + struct iommu_fwspec *fwspec; + +#ifdef CONFIG_HAS_PCI + if ( dev_is_pci(dev) ) + { + struct pci_dev *pdev =3D dev_to_pci(dev); + int ret; + + if ( devfn !=3D pdev->devfn ) + return 0; + + ret =3D iommu_add_pci_sideband_ids(pdev); + if ( ret < 0 ) + iommu_fwspec_free(dev); + } +#endif =20 + fwspec =3D dev_iommu_fwspec_get(dev); if (!fwspec) return -ENODEV; =20 @@ -1527,6 +1545,17 @@ static int arm_smmu_add_device(u8 devfn, struct devi= ce *dev) dev_info(dev, "Added master device (SMMUv3 %s StreamIds %u)\n", dev_name(fwspec->iommu_dev), fwspec->num_ids); =20 +#ifdef CONFIG_HAS_PCI + if ( dev_is_pci(dev) ) + { + struct pci_dev *pdev =3D dev_to_pci(dev); + + ret =3D arm_smmu_assign_dev(pdev->domain, devfn, dev, 0); + if (ret) + goto err_free_master; + } +#endif + return 0; =20 err_free_master: @@ -2616,6 +2645,27 @@ static int arm_smmu_assign_dev(struct domain *d, u8 = devfn, struct arm_smmu_domain *smmu_domain; struct arm_smmu_xen_domain *xen_domain =3D dom_iommu(d)->arch.priv; =20 +#ifdef CONFIG_HAS_PCI + if ( dev_is_pci(dev) && !is_hardware_domain(d) ) + { + struct pci_dev *pdev =3D dev_to_pci(dev); + + printk(XENLOG_INFO "Assigning device %04x:%02x:%02x.%u to dom%d\n", + pdev->seg, pdev->bus, PCI_SLOT(devfn), + PCI_FUNC(devfn), d->domain_id); + + if ( devfn !=3D pdev->devfn || pdev->domain =3D=3D d ) + return 0; + + list_move(&pdev->domain_list, &d->pdev_list); + pdev->domain =3D d; + + /* dom_io is used as a sentinel for quarantined devices */ + if ( d =3D=3D dom_io ) + return 0; + } +#endif + spin_lock(&xen_domain->lock); =20 /* @@ -2649,7 +2699,7 @@ out: return ret; } =20 -static int arm_smmu_deassign_dev(struct domain *d, struct device *dev) +static int arm_smmu_deassign_dev(struct domain *d, uint8_t devfn, struct d= evice *dev) { struct iommu_domain *io_domain =3D arm_smmu_get_domain(d, dev); struct arm_smmu_xen_domain *xen_domain =3D dom_iommu(d)->arch.priv; @@ -2661,6 +2711,24 @@ static int arm_smmu_deassign_dev(struct domain *d, s= truct device *dev) return -ESRCH; } =20 +#ifdef CONFIG_HAS_PCI + if ( dev_is_pci(dev) ) + { + struct pci_dev *pdev =3D dev_to_pci(dev); + + printk(XENLOG_INFO "Deassigning device %04x:%02x:%02x.%u from dom%d\n", + pdev->seg, pdev->bus, PCI_SLOT(devfn), + PCI_FUNC(devfn), d->domain_id); + + if ( devfn !=3D pdev->devfn ) + return 0; + + /* dom_io is used as a sentinel for quarantined devices */ + if ( d =3D=3D dom_io ) + return 0; + } +#endif + spin_lock(&xen_domain->lock); =20 arm_smmu_detach_dev(master); @@ -2680,13 +2748,13 @@ static int arm_smmu_reassign_dev(struct domain *s, = struct domain *t, int ret =3D 0; =20 /* Don't allow remapping on other domain than hwdom */ - if ( t && !is_hardware_domain(t) ) + if ( t && !is_hardware_domain(t) && (t !=3D dom_io) ) return -EPERM; =20 if (t =3D=3D s) return 0; =20 - ret =3D arm_smmu_deassign_dev(s, dev); + ret =3D arm_smmu_deassign_dev(s, devfn, dev); if (ret) return ret; =20 --=20 2.40.1