From patchwork Wed May 8 18:57:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13659070 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 727C3C04FFE for ; Wed, 8 May 2024 18:58:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UpfWoa56HYWWpMOEZPfJpBoZA7gxArtUYjq7xifBT8k=; b=nFrG48nyAyONnB Ju50y5q+IhvnlAIGmT/iSEHubIE3BGAK0yseMZ1Y3OZ6tgFa5ZeSXMI+exELaQd7X0v/ZWSZbx4fl QVs8CXM/3OFl88hU7biw1eODPjUv4uBtgrmsrpNemwdrnfOAUlbvZ3MnnMVuqLEPc1A/vVutlLuZF x1uM2hfwaKnbs2Knx0ezRkO0YYeyF4UWVXXOC3xw36yOWrVP6c3N0oLBDdMctdfkZ+DrrJLxKmoIP /M8P9xNpXTsW40DejRjMLLz4wG+JenmqMXgCndkFcGoqA7Ea6j5tbqjsNzU9yEPi8xpLKFqmBh4Cx VTq+XkQPHWFPKnwSLP1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4mUh-0000000Gcdl-4BMl; Wed, 08 May 2024 18:58:24 +0000 Received: from mail-dm6nam11on20600.outbound.protection.outlook.com ([2a01:111:f403:2415::600] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4mUB-0000000Gc8t-0zHH for linux-arm-kernel@lists.infradead.org; Wed, 08 May 2024 18:57:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ab82/+a8d8q66b2Re/8DdVfsz0g4bBR0B3jtCmS1Vv3CALQwmiAdKEv3iBqrhtrlfYt3gB6omjgModPx0INZ/R7mILqpC7Nh4jt7dat56WaWh8ljmoLB860HKQxFQ0FWZmkZ8/U9hxrnK3gFHdTx0fDoPQS7PMXiykPzT4gN/C0KXNxnep7ElWxjl3XrF1SpsOBEMwnwTJinQaXlK9/h5AQE5izNJdyCVDuz+2AFx7HsMVztOCtoNmlX+/OuPq5u+SRP8wJltZSH1mJIQSg8M+/5Wj1h6mLGh3vYYC8FNOPX+6kWnSaJ5aag9kKdTjJ1G+PoY6hWb2NGGRV1EGgU6A== 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=F5FTUpjpMSI/6olZMRtQP+S/FJoJlN0+xp6bzMXdtVY=; b=aA7oix9/0n2pupmXEcysk8t+xb2wGwoqJ021+UqDNZDstuhmPM75FllRo9JgGOzvJiyjkLfDR2DouISEMTTZlcTjhSPNeL9lVfZzosgHnGTM99sWbZGo4112++AZsnSQUICjviro+gtQXD/tMOJzoItvPWgbFko/FlVqdde9QV+nbcuMfDjxlvo8/jI+gE7z3X+JSVBoRBmSe81ZJqjN4wC8EKWqee99l04dXx7Rxf4SYjvEkpNmlH8Jz5FLZAFGzuW4ajxvr+Z4en2RM5hKaKOV9dkvHDf4+VVIleRMc0PSbLL7nypd8KaYdGORD6BsmhgVgXlPgMC2ClyEB6iCQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F5FTUpjpMSI/6olZMRtQP+S/FJoJlN0+xp6bzMXdtVY=; b=DIUhOHHCZdz95xneCW4ItWMrFJocjVrAtFt04FxhxwEroydYyuOtEjQStBYregXUYBZMJjJqJ4nlXWGafnyqDZ19gLTCT8o6sVfqUqK1aFCOheOeJdhWJkNekaFbYsmhUkHmHz6a+08j3heqd7ZvQH8RuT1QYfWqjCTmxS7tZWLMgUvJkrdvir3O8C5oeAlApdQNRLHivdnphy0ehfEOZ/ONf1TLxhMwFR+5dYWG7eNXyB3EMskVVhw5/ZROI/i19Su5g67StlsiqhaONXZL45qsEoBUz7UOIAPGZt3NiK3yG/lBkUIj1h988x5Mqtov+TubiY36ZEUyAgIDutwsow== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by CY8PR12MB7514.namprd12.prod.outlook.com (2603:10b6:930:92::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.46; Wed, 8 May 2024 18:57:28 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%3]) with mapi id 15.20.7544.045; Wed, 8 May 2024 18:57:27 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v7 08/14] iommu/arm-smmu-v3: Make SVA allocate a normal arm_smmu_domain Date: Wed, 8 May 2024 15:57:16 -0300 Message-ID: <8-v7-9597c885796c+d2-smmuv3_newapi_p2b_jgg@nvidia.com> In-Reply-To: <0-v7-9597c885796c+d2-smmuv3_newapi_p2b_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0074.namprd13.prod.outlook.com (2603:10b6:208:2b8::19) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|CY8PR12MB7514:EE_ X-MS-Office365-Filtering-Correlation-Id: 634611c7-01d0-4abd-6c1d-08dc6f90b3f5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|366007|7416005|1800799015|376005; X-Microsoft-Antispam-Message-Info: Uz5wvK85S+6l9/rmHoTHagH3ps7faIS9Ifsc2HCPJzeXZ7WhCIHX6qkcCyLkWOuGgxSWBUNibQHpzlEVo4OPQGGWAuesXnoPRd355GB6fxPs5dj3gx6qvWLD7dt8DZInFTo9UIX7rCTaiHgPJggwAbGFgC6otoId7M+r8udYLf5mNry3jQLM+XwwvSthAuMhDKFi2Nfl3p6cOLYhoyTcxQDGoumzBuaJsJVhw6r5AjF1O+bc8AiWWRVjFLSim77LfjlGmMI+f7ixRVjigQERAoZ2IgAiKcXFEkCeWJeofytYxPOWGLHpBXPG9J8KZwyxCf5yY1L0+5g1/GhlKhQBOdynRNWTdNz8rJAN0arxl9mr+odP2OXUd6jALP8Ubnt/xanKJl3BTV4fKPPniurXLw6bVolQ42JCdkLrXNjHRp040Ez7XJzHGejW7HnvOAaQD4DTg8BvxdxXQh5ltkGr5n7A3BW4ryZDlW0bAvoRcIyaCOOAUKY1lQIob6ID0cmSByXX5nvW0x/Skn4v4LCCoVZtAEUCFyF1DOdrCTy+lne2nNq05baL0AgTBCsu30Y74ZDxmpDGuD0zGSVPJ0LKOymcjtRpN2mG2VTovp38EtX2ZnI+wa0i3PDJ6P4HLu0MoAamYwzxhw5JiJKNioQ0waE8LRRv6birqsFH6B4MkjgmuzbNUa33Gt/+jmxX5XYRG8C9jHs8+XRmXnzhD9NQFQJzj19eYQAQto/Pgn1UCxLh2HpclyNnguT+EjAw1tc5qV9t9ybMU9BpW1gt7++E67c/6ct7xl+yXKUZS6rvQooaIMx75RLdZlgXb85h5V0MWrp3y1TWiKlvKlRU+2f8i5R62+S/5FCpSUDyTOyxwhR/r58A2czM+XzNtrTMPkUK6sNDUZ1O07n8VkDbXp6YB4riCO453GsrVLpJJPPpPCJ0Q7G7isI+x6r/cEl/WKxFaq5+uhpOdldbsjEBOCABf45E63bMreuDAwVJduZVq27gP9u75gmqUcA7FhoIOnvXhI5MZnYN8isGBdeWhwOXoSh/o5Ufcy6n9ZTyPoiIEG4bEq+4o8nCWop6s0ecM2hpTvaRQqycOecBibsiMdsEK/cjE5nzcIzBLmx+f0GPRMQDZtrPrXWR6z0yYNS9tgrb1P26oojwxCu+m09uhxfGNNE/+0/nLbDrcTBmEGMFp1m6TUXbgupERmsy6H/9D+DCLSrmzKry90vUKSbNx5nJBfooDh4iCFVj0wn9lZIXZBuR84KYsk3BVNQDAQgFXjpPU1yCfiAfiakdEekPDoM63Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(7416005)(1800799015)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount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8pV8XD2fn1UeiPIedfwRn7vMMOTgADfRDfzwG5a+vKjOo+vEz7oB4mXIcbmgrGxSDiBOXvj8I3K6QnzoUMaasD4Fg+yJ8zKzWgj+nKQ13RJknXwxJP1c/klPdogeQmoVSCmoCAe8Rt6jFavg0MmaRMsRjFUiRUH2Y1uJ2KCB3AF7hA2bdFHntRC2+hsHi5HJFF9GD5zYBxpLbLwi+kxXooRFS7WEiw8fu7Hy1V+JEJpJZIH50qdfFnK3XECrHoen8M75j1k/+j3nY+fMoYbWsswA+yFT+Ao1i2wI9QrUCOpffMyY3X7T85ymhL627nWZd4V06HJ/qWMEOeXYbcvA0f7BSPNKiSapN0ypYFMj3mfVFIJ0YBqYz8u5OE3BDbJGQIq8KfAAKTpaHk72zDQyDxFZAyoLL75Ks3+5Obbqu5PbPOitg7lQQTpLYWhStjzsrsgoUbjOdRwTwhhK+2f4ZCLI/w+TEvt77Vsa0QSzwtkoLfH6qULvZrT1+axoAXAFXsLN5bIgsKoBsKR/aOBMwVgW6bL X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 634611c7-01d0-4abd-6c1d-08dc6f90b3f5 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 May 2024 18:57:26.6120 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jPY7RUBypwjseqjR1u2BfmPCfu7fGcTbW6/UEDHeJyf8lCae9mnrWDv/CIhNiuMf X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7514 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240508_115751_482002_7455C62C X-CRM114-Status: GOOD ( 14.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently the SVA domain is a naked struct iommu_domain, allocate a struct arm_smmu_domain instead. This is necessary to be able to use the struct arm_master_domain mechanism. Tested-by: Nicolin Chen Tested-by: Shameer Kolothum Reviewed-by: Michael Shavit Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 21 +++++++------ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 31 +++++++++++++------ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 ++ 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index 7627cb53da55b9..39ba6766513457 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -639,7 +639,7 @@ static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain, } arm_smmu_make_sva_cd(&target, master, mm, bond->smmu_mn->cd->asid); - ret = arm_smmu_set_pasid(master, NULL, id, &target); + ret = arm_smmu_set_pasid(master, to_smmu_domain(domain), id, &target); if (ret) { list_del(&bond->list); arm_smmu_mmu_notifier_put(bond->smmu_mn); @@ -653,7 +653,7 @@ static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain, static void arm_smmu_sva_domain_free(struct iommu_domain *domain) { - kfree(domain); + kfree(to_smmu_domain(domain)); } static const struct iommu_domain_ops arm_smmu_sva_domain_ops = { @@ -664,13 +664,16 @@ static const struct iommu_domain_ops arm_smmu_sva_domain_ops = { struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev, struct mm_struct *mm) { - struct iommu_domain *domain; + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_device *smmu = master->smmu; + struct arm_smmu_domain *smmu_domain; - domain = kzalloc(sizeof(*domain), GFP_KERNEL); - if (!domain) - return ERR_PTR(-ENOMEM); - domain->type = IOMMU_DOMAIN_SVA; - domain->ops = &arm_smmu_sva_domain_ops; + smmu_domain = arm_smmu_domain_alloc(); + if (IS_ERR(smmu_domain)) + return ERR_CAST(smmu_domain); + smmu_domain->domain.type = IOMMU_DOMAIN_SVA; + smmu_domain->domain.ops = &arm_smmu_sva_domain_ops; + smmu_domain->smmu = smmu; - return domain; + return &smmu_domain->domain; } diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index b2d8b7a1df343a..3011eb10763bee 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2272,6 +2272,22 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap) } } +struct arm_smmu_domain *arm_smmu_domain_alloc(void) +{ + struct arm_smmu_domain *smmu_domain; + + smmu_domain = kzalloc(sizeof(*smmu_domain), GFP_KERNEL); + if (!smmu_domain) + return ERR_PTR(-ENOMEM); + + mutex_init(&smmu_domain->init_mutex); + INIT_LIST_HEAD(&smmu_domain->devices); + spin_lock_init(&smmu_domain->devices_lock); + INIT_LIST_HEAD(&smmu_domain->mmu_notifiers); + + return smmu_domain; +} + static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) { struct arm_smmu_domain *smmu_domain; @@ -2281,14 +2297,9 @@ static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) * We can't really do anything meaningful until we've added a * master. */ - smmu_domain = kzalloc(sizeof(*smmu_domain), GFP_KERNEL); - if (!smmu_domain) - return ERR_PTR(-ENOMEM); - - mutex_init(&smmu_domain->init_mutex); - INIT_LIST_HEAD(&smmu_domain->devices); - spin_lock_init(&smmu_domain->devices_lock); - INIT_LIST_HEAD(&smmu_domain->mmu_notifiers); + smmu_domain = arm_smmu_domain_alloc(); + if (IS_ERR(smmu_domain)) + return ERR_CAST(smmu_domain); if (dev) { struct arm_smmu_master *master = dev_iommu_priv_get(dev); @@ -2303,7 +2314,7 @@ static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) return &smmu_domain->domain; } -static void arm_smmu_domain_free(struct iommu_domain *domain) +static void arm_smmu_domain_free_paging(struct iommu_domain *domain) { struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); struct arm_smmu_device *smmu = smmu_domain->smmu; @@ -3285,7 +3296,7 @@ static struct iommu_ops arm_smmu_ops = { .iotlb_sync = arm_smmu_iotlb_sync, .iova_to_phys = arm_smmu_iova_to_phys, .enable_nesting = arm_smmu_enable_nesting, - .free = arm_smmu_domain_free, + .free = arm_smmu_domain_free_paging, } }; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index e850b7913e67a1..a036610e50da14 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -790,6 +790,8 @@ static inline struct arm_smmu_domain *to_smmu_domain(struct iommu_domain *dom) extern struct xarray arm_smmu_asid_xa; extern struct mutex arm_smmu_asid_lock; +struct arm_smmu_domain *arm_smmu_domain_alloc(void); + void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid); struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid);