From patchwork Tue Feb 6 15:12:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13547504 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 CDA78C48297 for ; Tue, 6 Feb 2024 15:14:14 +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=tjk777wzkFcx9I9hPRE+PnCG6zRX32WDelB6rI6RbGE=; b=aB1zABE0d7DvCx 2Yc9FESu3IE/hZd11jA++kwkna8VG8SuuGHroe+HVXFF78rDtbR2s+BJP9Wco9buWgGQGnsm2lEUC ijbRw5kLKkOUopLle2esISJbgOtNevrUSTbiXCADZRQYFq5KBNpSbzb1sZHv343QNcXOZm9Mx1ygv dlpuSNpo6Q9uUpnvRKIJNGINEBePuaX/4IjqzQKLKmKsPH8sOc4E2jt/azuHZ2u7kLeh6T/rhuccx M3XWJbRPZ0Snfh8yh55PjhoTzVUoFTakJ7drWcVXROHFp2Y5hPw8B4KM4w6s8t1IN4E2mRSJPYq46 VitHWjwSV1jVClBjeJ0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN94-000000081up-21b9; Tue, 06 Feb 2024 15:13:58 +0000 Received: from mail-bn8nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:2418::601] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXN8S-000000081Kg-2sXb for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 15:13:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V6xRjCWnZ1S+MP2z66SOBt1jqbfu4AMxpJRdkfI4kQawfnHB2h5O+DVWUsIBo+0iF1YpqxH09kbIS/EWb1LCjtrava9yXqYeV/e9gtd/Rco5+Gv+cAtUP6K7mmeBlj4PK8vLNO/twNhU/gFQyqGEAsi0ye4uzP8MuLtJ0MGtkbUVULEaDRfoKgpXCbHqz9SmamJgBMgzKHYd265y8JNdbEQZbQBC3TMn5KZ0CUun3+EzEnJ0IqKzqzG2Y0qrSoo7G/y5wwd1LSXL/kbkfyDmWbU1aqk1b0IO5rUWxC2IHWSfJFL4kp6yXoYRw3NZMMK/8X2N2wyr9jP2+TevvQBOEg== 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=8uzCZbZUIXBDLszoJSY2OR36PxPIYFQ2QBqrMyC+aQ4=; b=ajUN/5l6CDjwTis4uQ/KzHU7ymwjFkHGJxJ8biciblg1ZoErVigpcRZpBqB0n5SmcfbCtsCT6xXlzhsIhHCFKpb52CRq5Nqj1oCwSzSCIR3NHXs70TRxCwLTFK6/jJw3XhWfqkUxPOihEz5VecIXqf0g4VilMcqojgL4a0QlxXOZflyhp5U5uSVIZedo6HJ3HV8R+/LlDuiaArV5fbi7sW8XOEma49mhzs/eNm+XaTPHt/SKJsjxVdhtLWEx6K/ExuGAZ5zM37Wrok6wwqQ/NeEpWKiHhIeINLoHKCbxATDkPwQKqfRrQ0STdojLK1353ade2odAQ+eR9OO5oWUc+w== 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=8uzCZbZUIXBDLszoJSY2OR36PxPIYFQ2QBqrMyC+aQ4=; b=CuEgqV25wRtNJe0vivvw4VlLUr8Nd3Z2Td/8PIf+1WGn9XibR8g0VJEu7SSB3JaY8n13mwfbVKS0fbolw63OiOVgNnLZZOfROxh9mPFLPL6FZmAOh7j84+5TUguHjDLeEFwmx2MObMYHDDcUNQ0G0v8FcnwC4r8yQ/qeuGKJ1G9wyC532cPvte0cUHyDQBXrxXkTcnP017nzBr8kcAL2OB9J9t9aNA5J5KJ28JQXuMatWZMqXSUr5tOE0nBW7yYnwN5NVEK6Yz84NyFhE3Omim8/F398U+FjcsGIxrv0WRnT73oi4ZmkrPTCGmHCSPGo388cfL69rQbkc54vdO3mtA== 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 SJ0PR12MB6733.namprd12.prod.outlook.com (2603:10b6:a03:477::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.16; Tue, 6 Feb 2024 15:13:05 +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.7270.012; Tue, 6 Feb 2024 15:13:05 +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, Shameer Kolothum , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v5 16/17] iommu/arm-smmu-v3: Pass arm_smmu_domain and arm_smmu_device to finalize Date: Tue, 6 Feb 2024 11:12:53 -0400 Message-ID: <16-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v5-cd1be8dd9c71+3fa-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR13CA0006.namprd13.prod.outlook.com (2603:10b6:208:160::19) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ0PR12MB6733:EE_ X-MS-Office365-Filtering-Correlation-Id: 02422cb2-1b74-40af-dfc4-08dc2726192b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D2vpMqCd++UJrjpTzE3PVQUEGXdtNwm4UAsmiNqdqv2CYuC25ZBkDQIcd5wCSnHd8qfWLA+8txOeTBxauOCQfcqDFakZkaEtCO8QgXhiX5h0VBH2/hk8QXfvQmb5BFYXlECxclHWwplnW2h7nRMhVZn4gQ7clVloqAXwujiYcgRazd4qT6h4XoXdr2/QQYgHMBDah6TSNc+D1YvtmwGrUDF03rfSdjDZ4etQuzTcZ8zvdPQ7cwDfqmbdMjtZF4xvYo4tEJt8QJ1tT9b6a/GzVPtsswgRqOwW9GJcW+qimZQrs+HthzuQWfkN7HvY7ExnESjsFB2z6dkNo3I+pJAyOCSFSBN9A//yfBaPFYISR3Q956U1dTvkq22WNOeb6TwCBcta8ILreHS0YVdSUnDGXJgWQHy2mok6IGVkHuosoHIegRA2NoKRAd8frM3zOVKjMvsKrB9O0P1oM+txg1EjKwYthpjPFnIzy8BEq2yocxCQz+YwpnUuBaUjYToWqPVeSIpSGC+rW/EsT4h3PJJTSVJNdDbRRHrNkZAMAt6w2jw0bFT69Q0/lZ36s2eSmhJ0 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)(346002)(39860400002)(366004)(376002)(396003)(136003)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(54906003)(316002)(83380400001)(110136005)(38100700002)(2616005)(6506007)(6666004)(26005)(2906002)(7416002)(6512007)(6486002)(86362001)(5660300002)(478600001)(8676002)(66946007)(66556008)(4326008)(8936002)(36756003)(66476007)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 44igk/2x98ih+N0ruiRIs0OAIJZQ3nB5lFKxhMt4iDUE1yUYAMQCuLfiALjtHGxYfudhpLM3HR6nwQ9sFwDLkmRUWyYy4H2RYs+JHwZ3Pr7+HFcURJ3fsT+QDevo20fOGef0zIZ2WOS5gIY/oriBq1DSuSAN8Y7VtKupJM9EqlKtOmlNH22FsftikWMDdgpg4g7E7+QWS+fEMqKsxYHIde+e0+DlZ0k70fOvD/hrdFFMpdPnELQ1sXvwZafHrFHly/eZBtaYe7uDbMxIWrjq1DTEi89CZ2A1Mu5H8lQhRf1g60vFcIZ1w/n6Nq5AZ7iN3jX9obRY235/MzC8+HTlACdIBA6sGk9nQP43QiKIcfyF4vaw3EqiN6ohckkGYdZcowwp5J38P1AqnjNjxlM20oPY/UVl0CjfdeCS7U9XhRpuSOBf8KmUbYyDy4FhmnEeNDgf09E/cTKE75kouE6NeJ9samp/xegum2AkXjrZ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0XXYHCtTat1gtEH5YndftWGoNK2RJ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 02422cb2-1b74-40af-dfc4-08dc2726192b X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2024 15:12:56.5130 (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: bTNk6GB6E37WHfqVz98+vZiYdzJpyW/SKnzlqLDO+uvsrVIERW7wVZ5KXIHDqrup X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6733 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_071320_914481_A7EA19E0 X-CRM114-Status: GOOD ( 15.61 ) 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 27a2792a6acd76..7116874c332ffd 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -102,6 +102,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) { @@ -2295,12 +2297,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; @@ -2332,11 +2334,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 */ @@ -2349,17 +2351,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)) @@ -2398,17 +2400,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; } @@ -2600,10 +2603,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;