From patchwork Thu Jan 25 23:57:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13531923 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 8025EC47258 for ; Fri, 26 Jan 2024 01:05:07 +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=6YYNPqizofdJCN1ltBwciZzaSWtgTV6SUd335GMMgt8=; b=iUb235JhbUaL1C uTiYUEHZSzwSjrXkrnYa3wZ+ilCndNcWhDpJAfjDcG6y0Kq2znFhPD2EUUNBTrO+5owQ1CFbE1hvG HwCrY++st9h0w35uRs4dpNSlhcJ2f3YvNvYg/Y4LChKl3KNseI+pZbTSPZMMG/GGwMdpK/FhT3XWz dq7FCdnDyOrpEydDAJ4bYhPYIe9/RwhfVw0h/8fATOISstOS/w+RDHiXLtz3CqHqEcReFvxLUOX+r dMwi28eqlf5vuqWeZPUeiSzkLe4GV2VAoAe5HfhpQf/1VeSJyxr6706esNgd6nGBiusQmcRE4of6o WLEzQXwlnbyBPoldIcxg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTAeN-00000002hT7-3Rnw; Fri, 26 Jan 2024 01:04:55 +0000 Received: from mail-dm6nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:2417::601] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rT9bS-00000002XD8-3PfY for linux-arm-kernel@lists.infradead.org; Thu, 25 Jan 2024 23:57:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G6dBBg8wHsiYTGGOVMvvJwPK4bkz39FCLROEaykaQKFTEhXNDLtLjKOgLcXKx1dtHMKb5gf3GsBAXIy7PjfAFD+e7G39mH2RO/IPQ44bm/awfnvkMT3wG4+f7H6t9/gLVK/Q4hyhY9d9k+vPomAP8VzsIMKZ/51IoGl+6ryN9Gt0ka744q6ryZRyiksQBtRylgj7LOCluwHnuX8ySAj5A6vF6tG3TIh8E8SWN7M4Bwyvx5+NZg0mg8pA2mqtKVs24DSOM8+SHvb88YIszdcPElyBQJ1DKEFBGZXlcNdT72QCA7ghR/q1C8BbBRu7h+DnTsxx8IdBUlEaoS+ShM52xA== 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=IRg1kVqXSznZdQhXxpifepmj1QxQckRVOnw0zHEnVFI=; b=JveWwVjd503chdcbYhDRtN701VlBs2jRmKWw7fmXaHCleAsrEQc7yvNkp2Ia7Bju0ugfXMzqlhQCVDzKQWtYHhpw7Jr5/PM5o2JkVwvv6ejDZtnrNIaYROtRYJpSWzSijb4fdO9T3hpsKg1/9slTSiyJ0rmaKjiCJt8dO4WgXgUsuFoYMhxayb1afQe8XdqM/a+5agJxqtQYf7vxbw0437dtaoHwU0HpnJcrjuMqAeKkjK/pvV8P2WjWHm8kXajHtQmoodoPmV7M92Vh2MsrFC3TNM1KTRI2yHdxt879PdDUuBUOk+ycvwf/xI1IzVOCGtIVCdYMsfqUHZ1dHbfUoQ== 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=IRg1kVqXSznZdQhXxpifepmj1QxQckRVOnw0zHEnVFI=; b=W2QJ1RDAVBgY2L4Z8VsR1y0Qn6cU/OodYFejG1otpzx1AKOYmgynaXFKq0P7cmP9tTO3BNvAOPJ4PcPqyQv/FLFB/zD1nFO8Fa1SgmuaQH/ZzLEmYJtAl6GRqMY51kmpkLdRg82l3/yW1q4vW2e1Z91JviBbXk7cRsViv9rjcykGexrA9rlOE1n/u4IM87bGqfu61PwpGinQJKgZcSEOcqvS19DeAQ86wsvqj2dIWO7X0QTVyje7yJExol4NjWlo/trB+fXAcPcyXcberMcOGUrkHe0QYs6kwABAv1ASPcuDHJWX9J8fJSoarQrVHhg05qe462A7Dp6STxF5R52KrQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SN7PR12MB7881.namprd12.prod.outlook.com (2603:10b6:806:34a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.24; Thu, 25 Jan 2024 23:57:38 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7228.022; Thu, 25 Jan 2024 23:57:38 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameer Kolothum Subject: [PATCH v4 15/16] iommu/arm-smmu-v3: Pass arm_smmu_domain and arm_smmu_device to finalize Date: Thu, 25 Jan 2024 19:57:25 -0400 Message-ID: <15-v4-c93b774edcc4+42d2b-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v4-c93b774edcc4+42d2b-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: SA9PR11CA0003.namprd11.prod.outlook.com (2603:10b6:806:6e::8) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SN7PR12MB7881:EE_ X-MS-Office365-Filtering-Correlation-Id: c79019b0-4c2c-4e4d-7519-08dc1e016517 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XlgOjvy50Jyzz4v/3lws+fdkG/+l7dCVf/cJaBdjh5M48c8geFYs2CHkzvcCizzoD1IbPPdTMxuEqQPT3bAM45nCfE208sV337ldCTGNCNJpUyYUiacpox9jqrvz6npyjrQgotQ2KP0QU5zjBnq23QOnAqEPMrYsE6kHSY40s1MVM3W5T7jKyUY1ACFaRMKMVODWmC9GvSXk9Cg7Ysa8GdNbfQToNLDVym/P1KHIqDTW+b8RrDEpLzh1qPVFfoY+e03omAJPTfmfWv0rsQjxUBBgoRsW26qxo5i7SPSIxokmmE6M7NR3jBuc5KWPdyGXZVgUTtxo6gHalN0V+VXSNo8Otu0WKrGlvj3tU9idNP11HClt9kP43lWWfR6HEEGM8LMqQZqULLOvTBZEyrYE9MGCPxoynfKCAL/COjTKc3Z+o0AeaKqxULgB/yNf4xyFnjxsGtwdqcAEr3wxXpgRm9uD3JglwezAOypjve1SSnetKumU4LG9lOOXcoyMBwKt3kL6UMkTFDjE51002RC/Cyp0LsMBEpSHwlDenQIXjBlORSL7uYcIYb4Zo5uFq14P X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(136003)(396003)(346002)(39860400002)(366004)(230922051799003)(451199024)(64100799003)(1800799012)(186009)(83380400001)(36756003)(66556008)(86362001)(54906003)(110136005)(66946007)(66476007)(26005)(38100700002)(6512007)(2906002)(2616005)(7416002)(478600001)(6666004)(41300700001)(6506007)(6486002)(5660300002)(316002)(8676002)(4326008)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BNw9uydrMwOEAwGEQgyuTfk/O4g6t0OGoZjJKBRacy1i+MFtwT8+FOXbH8sJ90vF8oEDYEyrd4vCWFy7w1GhgwyYVviVIKAc9gXFu93bmJ4HcFas9cEqqAMgA4lrnDrx6V2IT3/hPtzkCUOTbY+ORM5B4hCSFUGw06l+DGDAKBKPtbDOXGLfHbPHW+nbzvLrrpwlPEg/4xoDw640FKNOZt5qzQjvVA+pjYK4D3XxBGzCub+QVRqSw026wIOPyP75K/oSHVEvUSzxVAziXP2mduCqtLg/07Pcv12840rJhu36Cl0/PiVRXkRermYKlNKbmt0150ZdtovA38LC9ifE7XBby2aIQuuESzJ8sxrZKH3kuzSvAd8h5WKX7bJLwHr3tjvVOCD5pqZ05F8stX6iEeE4ImqcoDNYnBEQSH+mroGCx6isSAQ9jPzewOFT5koWfk1few6vNA9cw4GdZNuqkc4dCCcyMEDMa1QmDaJG0othYBH4I307jv5Hh727t0y3VuFIAy6NN9EFmu4GxDKKh5DHf2gZZ4eue2A1qyRqcqPCISJFG1qgriO7d1nINyQ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network-Message-Id: c79019b0-4c2c-4e4d-7519-08dc1e016517 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jan 2024 23:57:32.0549 (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: GY7CREKDxxL5DeT8/+uh4n+DOhMnZ4PxJIxRP2XwVJTcZDB3bu5wQx0O6ayJFXmA X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7881 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240125_155750_950166_9BCDDC32 X-CRM114-Status: GOOD ( 16.07 ) 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 Instead of putting container_of() casts in the internals, use the proper type in this call chain. This makes it easier to check that the two global static domains are not leaking into call chains they should not. Passing the smmu avoids the only caller from having to set it and unset it in the error path. Reviewed-by: Michael Shavit Reviewed-by: Nicolin Chen Tested-by: Shameer Kolothum Tested-by: Nicolin Chen Tested-by: Moritz Fischer Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 34 ++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) 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 92a72ec6ee974a..f4543bf0c18a49 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -103,6 +103,8 @@ static struct arm_smmu_option_prop arm_smmu_options[] = { }; static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu); +static int arm_smmu_domain_finalise(struct arm_smmu_domain *smmu_domain, + struct arm_smmu_device *smmu); static void parse_driver_options(struct arm_smmu_device *smmu) { @@ -2268,12 +2270,12 @@ static void arm_smmu_domain_free(struct iommu_domain *domain) kfree(smmu_domain); } -static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain, +static int arm_smmu_domain_finalise_s1(struct arm_smmu_device *smmu, + struct arm_smmu_domain *smmu_domain, struct io_pgtable_cfg *pgtbl_cfg) { int ret; u32 asid; - struct arm_smmu_device *smmu = smmu_domain->smmu; struct arm_smmu_ctx_desc *cd = &smmu_domain->cd; typeof(&pgtbl_cfg->arm_lpae_s1_cfg.tcr) tcr = &pgtbl_cfg->arm_lpae_s1_cfg.tcr; @@ -2305,11 +2307,11 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain, return ret; } -static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain, +static int arm_smmu_domain_finalise_s2(struct arm_smmu_device *smmu, + struct arm_smmu_domain *smmu_domain, struct io_pgtable_cfg *pgtbl_cfg) { int vmid; - struct arm_smmu_device *smmu = smmu_domain->smmu; struct arm_smmu_s2_cfg *cfg = &smmu_domain->s2_cfg; /* Reserve VMID 0 for stage-2 bypass STEs */ @@ -2322,17 +2324,17 @@ static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain, return 0; } -static int arm_smmu_domain_finalise(struct iommu_domain *domain) +static int arm_smmu_domain_finalise(struct arm_smmu_domain *smmu_domain, + struct arm_smmu_device *smmu) { int ret; unsigned long ias, oas; enum io_pgtable_fmt fmt; struct io_pgtable_cfg pgtbl_cfg; struct io_pgtable_ops *pgtbl_ops; - int (*finalise_stage_fn)(struct arm_smmu_domain *, - struct io_pgtable_cfg *); - struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); - struct arm_smmu_device *smmu = smmu_domain->smmu; + int (*finalise_stage_fn)(struct arm_smmu_device *smmu, + struct arm_smmu_domain *smmu_domain, + struct io_pgtable_cfg *pgtbl_cfg); /* Restrict the stage to what we can actually support */ if (!(smmu->features & ARM_SMMU_FEAT_TRANS_S1)) @@ -2371,17 +2373,18 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain) if (!pgtbl_ops) return -ENOMEM; - domain->pgsize_bitmap = pgtbl_cfg.pgsize_bitmap; - domain->geometry.aperture_end = (1UL << pgtbl_cfg.ias) - 1; - domain->geometry.force_aperture = true; + smmu_domain->domain.pgsize_bitmap = pgtbl_cfg.pgsize_bitmap; + smmu_domain->domain.geometry.aperture_end = (1UL << pgtbl_cfg.ias) - 1; + smmu_domain->domain.geometry.force_aperture = true; - ret = finalise_stage_fn(smmu_domain, &pgtbl_cfg); + ret = finalise_stage_fn(smmu, smmu_domain, &pgtbl_cfg); if (ret < 0) { free_io_pgtable_ops(pgtbl_ops); return ret; } smmu_domain->pgtbl_ops = pgtbl_ops; + smmu_domain->smmu = smmu; return 0; } @@ -2573,10 +2576,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) mutex_lock(&smmu_domain->init_mutex); if (!smmu_domain->smmu) { - smmu_domain->smmu = smmu; - ret = arm_smmu_domain_finalise(domain); - if (ret) - smmu_domain->smmu = NULL; + ret = arm_smmu_domain_finalise(smmu_domain, smmu); } else if (smmu_domain->smmu != smmu) ret = -EINVAL;