From patchwork Mon Feb 26 17:07:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572521 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 33739C5478C for ; Mon, 26 Feb 2024 17:08:17 +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=QipVkOxMo0uw8azsXPGopdHY/RHISJn5qkPm5fnWT/c=; b=tZ5ebAKtxW3riN r4DiQgx9k4JYPYw6JB5bqgyrxsTNPJV8XZ+I3/iGkRZI0IJkzFLp+iAoJzKtxUESRTV3JA41GHxbe cjIXmich2uB5Ai37Bn/sr5godqxuhA53yhN+JE2cjt3D0iSp5z4G7FV3rh5g05FBGq+rB6VKrkrmx eERf5aNDwfMfan/3STtBZ/v5zg1tMklk8DRxz2ppPiyxHLs73v4hJVgAhQf6eHPpD14S+dHueQrhV 1VDdCHqIKA+Cf8AsAcXYrp6079dZJlvEsUWQpKPeZDtkJByDEdfgMY7aL9byXDtaIr8v2uHcHVOuU KxU/LG5PvuMs41NYvHPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeSG-00000001pqK-17Ru; Mon, 26 Feb 2024 17:07:53 +0000 Received: from mail-dm6nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:2417::600] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeS4-00000001ph5-41Rt for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:07:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VS62wjgdCGNB1GqS4pJY+/L6Oxu4+yCMvqG6uewXMD2uZPAk7mLLc01J+MYxI7blahnpG7Vd6+W9R1aGBc5AZGRkApzu0L9JKXiKFP3YnoCwH6gKO9Aei8NMMIdFlAD26GxuKwQ0inClGSKzYIY6Y0mElrrIBOML2VuJ/pYqD4ae5ugk76EQunWV4JrIvwXM9QZEnrEf6ueCsit3mUbGnTxCPDJJvS2KXLFNH9wRv3//lkiGc+CspcVyVolu6bx6CacM0kWCXUvGj5xRRLC2pFjpsGDI/K+q26uNuW27tu9Abk3bykHIfe7CaGVEUHcD+4g3cfKB9jVTm38JWpXfYA== 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=ZSWI2KHW5zcH0QlDKCwINPDZOpnQiCisbxGGeezTrcM=; b=H3qB34+KKatennzJa5ymTrdTA37PEsQYBaXwBaGUOtZnJIpfYevNRCa/EYkr0H1iC7wR2uOtzymXxD8bKm130BkwPilXGwQlysvwwHXUSIiYBtejQGDzJVlGYVEFUktXSdxXzYqk3FX7hjzeAeX5bgf9xIW9SzkUNnxmlhHt2V4jPLVkVfXpxtfvR/C3kzD0XqWS1p5a7hLfozWcaeibRu4tG3VPO/UYV9ArO9/9A5Xi7KZF088PgDcy0yNtc8XroAMsocmp9on+eSnaJDo7z95qw+FC5NWmfq6VaYgBeJQs6qUAxdjj6X44o3CsNyH1Xrf07n9s3F6ygbwWHGsGNQ== 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=ZSWI2KHW5zcH0QlDKCwINPDZOpnQiCisbxGGeezTrcM=; b=uGkibC8AVl8BNdLTx65N6dZ9EgoFkKRG9oGyzmFZk/HGTYZdnfXRbYxszUtIHfYOfp2Z9GH3Dk3l3VbULhZuGBAog/fK0eGYTCe6SfOVP8d75HXlBGa7VT+OUYiBawa3ZQWux0TXwAqtncvqxiVmkGYK8JniW/fVQ/HsR0C7XNUELmTLQdRDRWYrzZEpw/MPxTcZyZqjYoXOgyFpkfwEKzd4jvuuy4KPQZIT+gCJhI0B6DpWI1t5TOCndbYycWhP4ZMXX3dXOKPWhXhQddJsvTY2fWcPUxjZnkw5q5MOBucjZc2zAGsTzCaokwvvUrEWPxvc9rk9Vy0yb98Zr6IOTw== 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 PH7PR12MB6905.namprd12.prod.outlook.com (2603:10b6:510:1b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:30 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:30 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 15/16] iommu/arm-smmu-v3: Pass arm_smmu_domain and arm_smmu_device to finalize Date: Mon, 26 Feb 2024 13:07:26 -0400 Message-ID: <15-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR1501CA0025.namprd15.prod.outlook.com (2603:10b6:207:17::38) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|PH7PR12MB6905:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d93afb7-7bc3-4dbb-becf-08dc36ed69cb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bTLS03aqq1X9aYrJ1XUnu3AohMtuPvTqKY3+xErEbexnl7DjeuflxrER+A+ef6jHthg9FKw7JJQNorScQwP8momEjK9cXmvD1h4ah4/CIoc/L58ROvKn+M9Dwc6+i1SUiN13qQl3h0jJZowTAq5Ksjz/UiiI34YXopIUGZnSCvryIpL9yya+J84R/eFwQtx9pZMXyuXqK2Vd/flrW199gOcORGIW9BK9cZzcGblPpEIFpygxBwNrMdCJeXxQDYBukpZDrAgmuferc/F/ThK1SWw6UqNmwTlHENU4AyrV4UcNqVLhfKvCKISvxh/rZeI8a4VSMjQED1YupCg3Qi/GYdJUXLbukT00q9A5iEotKeb8fdFcNS/tVFkeCPIp03RumeSQpREH+Dzl8hZvbv1NDE/O0235IoE2DL8kjb+iDlDwLJy0tAosCzPppYxTTVgIJs4R9RyhumXjEpO3EypsM39Kq6vVOQegbKPwtDT9cje2cF1guL3B5I1WUV1V9Ih1dJaROT5qsZzMRyo67MGZ7L9gT2mX1VtEPNujTameCWtN8LIqPqhAQPlCbCTcE0VPzHIs5JO4V0JjNJAF7tWRED59stfWKdaOTQsLJsUzVXbituajdiN6bmF8fNAbr3w/ 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Dax2gul0eVi8XCU9bDdA0Zdr1dUOLKGtDeMC3fAcpMVNQ6AuZ542hKL2QDc4B7Rcquo13vnK2aung/UwdfgBKm7MSOnJdVOSA7igzGY5eBQ64Ar/8VlP4qdDyccvQo3C8QMG+ui3uZJl62mh05DQNYZSNqWD20bvmGkhfiThee1plhNOCTp8Xi8wnRLcepQ8MQpp+rihsb1Ss592lAe86ZewAFVBXC5Xau8GkA+k5Ii/5sNAf+/JXkKZ6kPSXehzjVWmCupbrErw0AMeijHWUJAF7z29EIVAnRJmsWCbBbtYheAMy1LFL+k0Kc+YeIAskawxyA/Fm2vOaNkZvcg+qQx21CJuVEz54pq+1yekkxjvfnJIC0O6Smzdmii6WDQ64vPeijSbFPS/1YEGAFzfRjtwg3iYdLPmnHOf7Wf5GvvdrC6Om9ESEiEwClGlqSrwD+iE6hwTuZmEE/9qz8WLyrItnY7W0Ml62p8UvscualDdHALP3zmzkV3MEV2734OCnE0vEcpe9Ziwn2KaObtrgflFeTFjATUKiY2rCMYjvt/gnclQ62xpJ8cvaSZ+mcc4iVpn67uG3EBJ0ZpT2zJxP3cH6i/JXS2oAssSqeFhIc6rpZ4BBPggBRElu0bjGDqAyntDAVZVTwJ6AwwHOQi7PM/ftK1FDnhrDAM8jk+hpfNVmIB0EDdtFK0+Onp1HcY93+5zIZdLjNGqijSWJIKOjGB37Bc4S4UZQzkL+pW+yuHd03Icexf2XxEVIObM8t/3q6lO2jZtjIQd7aRjpmafp7gFFmUisASq0HSzgeyxze1j33RDZEggNKHmgCPFT6fETi6Vfqjx/3qf2I+ScJMC6VFpCH3OB+QBfOB61fDXt95sJAnkxhmBZMykPTnuInL1zEfonAzPYjK5K0+wB2v+ANOvrhOpATtIc+2Iu65mcNZfuJw5mrhLz/BdToj4oRg7FKDJY+rFK1OiC1AEuztFzMJjEzPeUnYZj3uMRth6Q/KoosHrt7ErGmEaPdJDI3x1EMCKzxAO/VRek3psM7b77QNaRIa61IxC5RA7NGaew/1r1Dfcj4tfEOvfagIty4XuaXsdRtWYLW7rq9omR5OtUxaUZ13cj+zPdzky7Dzxics3m8LScgHBeid43gWqqm1SUHk3edQ2LqfGuqZwUELl+dqtikZIW+nGt+ETmy8RaBGTUO61KOcxapXf9KMTU1Ky8M5TV2iFo29dBhVAoCS9/B4phRke0VE/BFvKiQIcp0VOxVYnOoAlcm7w/hRwv+KkxB4m6C3xNuNw743/BOsm6sS6imrmrgdgJOvUEeokhufwj7FkZTml3lgNjg4e/l24G+JwxTZE0oCMjuQ1k0JQvIt/kl+rKH1oqSF+exlE0Ajy6vxLdH6pT2wfRL8QoH6MAHpwqOqGEzL/BHnZ+kglJKtz4Fs1hdtf9FVsBm3nHx2jppB8EkL/J+C4gUfWCml3jijk+9yLqjTewx6XQ5ZI2OlDtTgICAO/FTY6yJvU0eus4S7xO1GOtGQmcky/LlBgfqDGtRLQUirrTRei0f0O2j3dHPkqMPuI3xXA3zy4e4I= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d93afb7-7bc3-4dbb-becf-08dc36ed69cb X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:29.2071 (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: JkC86n5lx58C4giJT63LebNHkApdKfrh62mMV11hE5HGJdU3kpLtwVZXbxqAxlch X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090741_178774_9517BE2E X-CRM114-Status: GOOD ( 15.34 ) 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 | 35 +++++++++++---------- 1 file changed, 18 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 1303e9c603fc6a..ebd8362c8aa3ac 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -89,6 +89,9 @@ static struct arm_smmu_option_prop arm_smmu_options[] = { { 0, NULL}, }; +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) { int i = 0; @@ -2242,12 +2245,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; @@ -2279,11 +2282,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 */ @@ -2296,17 +2299,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)) @@ -2345,17 +2348,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; } @@ -2547,10 +2551,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;