From patchwork Mon Jun 3 22:31:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684419 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 8FD78C27C50 for ; Mon, 3 Jun 2024 22:32:06 +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=b6UpRmk1kYpNz4bG1Dl2YCTxVSHfa/vZa18vco82XV8=; b=sFskHNYLi0BxRT nw0LwplT4GPHgIeeunQlew73UWvKTCcSDGrYo21R+TeHuM8++k0pi7s2OSMINGRoxkHuy8X2GJr4i EO5sPTfviFGZ26SwnEnMRvGPVy6mxgfhigsYA7CMMHqFEo+4T8ElxDV23Jdpgnb5xIxaGuktS29Lt VO44Cu0aJZt0Pg11isXVVmryg5Brehc95Eeq79kAQZChNPMOdvBgZabE+vS2NHOUeniqDfGKfN0k+ JAkQ/HZT9YS7LfYXigmcO+3V15s7QghfbmuWLJs4/CYDtUCh0TMgNLTl1Xj4nRov22kHED0v+tfN3 sOMY2XaZSbMeQCmRmW7Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEGDa-00000000Uip-3AER; Mon, 03 Jun 2024 22:31:54 +0000 Received: from mail-mw2nam04on20601.outbound.protection.outlook.com ([2a01:111:f403:240a::601] helo=NAM04-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEGDX-00000000UcR-1eXt for linux-arm-kernel@lists.infradead.org; Mon, 03 Jun 2024 22:31:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O+QsKinjQ1aNOnc4jwUFng9fMEevqVkQ+LQmQ5evRFD1SxHRJVJufHdNGj9dhSBIeBCF2rzSqc+ijpD8P3HNE8LXqroZBOO8Dc4ZwUivLqrTJQxn/Yb/MPU33UVitez2BUsDu/T6TCZ84IMGuxfJ7jm9IpWIALUGUjXwTZTBb3gwQ6l/P2GdL4KaoYaqp0D6u8JHXWEjGQZrWpKsMscZbkBawOJbwu4H9CbYsQAKnCGRG5CRMgojq+J6K4ys/lIK8yz6xoZdmdn8PetRS7Jn+rNRFNQqDL8fDNxyufsW4TdG2fZuU9ZultX6NpGuHP4h+1Fp71CIGBVBxFiPXo9Shw== 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=6kJMQ9BilAOqpV19Fj3qu+WByFe+BHkWI0tph5bvXPE=; b=LrfXcGMajKjcc0PVp7ZgFt9BZChac5rKNqTaU39TUWQjcC9l476bRVVBfJ7in6NpClLU8uopnp/lWw+s/p+ugqaX9k71v/KAs2XsPdHnPzbonxzV7A8QS8NtYaygK0TI3nCnJUIfLgwH24dBUrafzdf0Svo9AD8rOBrVUE87bTcBbe9qjmoMeO/HlLqAGyHtl4qKocCqzDp2oPP3Z4Q34JcfVWTW6qpyk3yrhsyQK05kNgz5eKElOMd+Rmhv49lUtQtC8RwzHXq07qnbrUNyN+jbnFpHandmBq3wbosd8NV32mDLnR5u9NuEluQEPMpR8m7VzMeDN5DcsSzwkKeFrA== 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=6kJMQ9BilAOqpV19Fj3qu+WByFe+BHkWI0tph5bvXPE=; b=Iibe4ElA3M0zq6V4o0n8/feNLTCrWiLRDvLE3RmSK1ehXAXhdIKfK6aEwICJLSnzOhtW1n67M9iHvXQdGngfHK8XatsfVpFtL6ZysyiLrECCAOfFS0o4PXrPtN94A3Ksw+d09y3m3XCBL81+wd2/R80veTUay0qwOhjC9IwHh3BKaWNcgsAj6DBBdhG3QrsCxmpItkEVzx+QmziumEonZ2s8dkOd+YHS2ayrICYxy2aVuVtKRY0QdTj9V82zEtJD7+us2MUcndA3VAtH2/Sm13kphyueq+jA+S79U8X30C82/6tHkdmxsTQ7Tk6+opEdAaXNKe3MwPLi4DneGpsClg== 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 MW4PR12MB6778.namprd12.prod.outlook.com (2603:10b6:303:1e8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.25; Mon, 3 Jun 2024 22:31:37 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%4]) with mapi id 15.20.7633.021; Mon, 3 Jun 2024 22:31:37 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Ryan Roberts , Mostafa Saleh Subject: [PATCH 1/7] iommu/arm-smmu-v3: Split struct arm_smmu_strtab_cfg.strtab Date: Mon, 3 Jun 2024 19:31:27 -0300 Message-ID: <1-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR08CA0027.namprd08.prod.outlook.com (2603:10b6:208:239::32) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|MW4PR12MB6778:EE_ X-MS-Office365-Filtering-Correlation-Id: a87ca2e6-e346-4518-cc13-08dc841ceddd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|366007|1800799015; X-Microsoft-Antispam-Message-Info: dOKXSl8lWAoQhohRu+ERO42ikNR12VVqQAWTznkQlX91uDI9krc0ftPNsJSvn9kWjvC6Dt8kIz4dfs74ivXP+iyxowMaNSJcIch3dKSh22HMBt2m5M8FAw4K5Svqu9gwVnRMmUsS1Hypn1aAv7oTByX3oraQjInl8CmEWSLc0AZ9LvVbIQj9dXllnxzSyKNdf9KP5S+cpoqCcT0xGJEb40LsdQxxmLbpUKMwe9oB3EfcTQOkWDxgchGUa8siyHYiHQ8gCGb7bg7BbV2jKd+71FL7ILxgwVQjQcdugT7CHX9ngPoU4I4VzvMOhAzJbhklMvbzrVBX1AcRkBF91ULoCawq7hByGs8NiKFaDdC4AtJiGX70LrVIKqYrld04t5oNp+0oGvJg+GRObqLhfKfwBYuTn7l1vPLeIoN4v8wFf/WjNNBrYeuNWGlRMQQRd+Rt69JJLxIT4P1lfEv23oULsd2zSpRLdSuByD7jwakGH4VAIY0sVb4ZN5B87uNdH715PfT3CYkPZKkbWVFZU/n2aGJjuL53XePtiURuuor/1WaA5pfXH6qTOFGrL9l+Mxa364/SNDABtB3pd8IZh/KvTccYS//n49EfcQZiSf8uGv4nl1EWlbDJatYqvQfk8o+M97/GmYDu5JeIYisWGkopwKQwbwTb3LPYrHxP+ZdpogvefFGvHwrSitMCKC1/6nD9LS6PAQIvhO7o6fDkhi7fcWltosi9unS1D6SKeXhZcqddOSXXGxiKzc8V9vUBzpgcFJnuGkmmZN1EEFz9q+sZzivpN9qJ7tI/SyBH/7AlHhqt6Cq+ufGhS8O158e0aTIOxTfexBotFH+1Oa2Svw2/oMBHkRWDwWIfNaC/Ycjg/E3Q+ZzDmMl8fq0udAEAb2CJsrRZYXMoTh962VMaRbyErbCTwNIvWo1Mr1YjIXRQSWEercNxyk4y6vFD11F60uzzZBXuX7JMhi0qkfUa/lsQPZBRtgAM0BQaLhzlHPmtv1otSIeqiLnz59794Yn7+yvJG7D/lKXpq2xhhpYpbYPOknh7b8d5czNtYWoP6GDEUZ80CrWwibha8CJsSIXhY+NxNxVr6AEgc1LcLxsqtfpiDynPC4phlKvdcAC1qKerBABZQ/1dLj4D/1Z5r2xVnx3A/fpYteG4WVuFBXQHU4haeDJWVrgOsxHo5AvkaTgS2J0/1qrCkQdXbM1mV8WPxREk1/vWIY4YE90qVK3FK3CmeU2gsumsK0eHcLITFYsFb4ETLZlRi7IZIUG4hTY/04ofXdwRMosHFEApXS8cT1r4OA== 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)(376005)(366007)(1800799015);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vxyHIx77FLUC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KO8trfmA2pHktA5v4ZBKOfqTWnKFJV1iGInyHHEyKtyCE8gcM/nISBAnqAUTK3PTZqz+e5S2y35URFB/yPiJ/SB8DRE6FzTVB5ECQjbdHoudZSQuMnu6bAbuOrq0QcOVME9ImCwyAnou0D7iOwGFEeLTN8a8h41jO16XprHE/3fY1Zhbq/hmh8++7pOovPLO2ro8Pm+xF2HtdByH6ga9NiU6YG8HxOl5xeY94PJ2oZNspyTKFMUWn/lBo5+VlNGoTVNB6zEVSQofFupQtmqQRGCd2nqokeJ8MOsMZpeSMLX3xhiVWjnsSpIBoCDIrVa0pXNSruwNWWoFxCbHTyGfVdZuZCT9zpjkS9qpaU7gk2pYb5QGa4UTQGiDX9oHOy9JpVma7Y1MvH6DO1kg0YetCfX0MUlPrCRscrHRtqZrE16QbulyihE7C0Hrv9LlQcBpPm9Mfi5CAe9+bsDqHbH6OCpJC7uA5xHgo/KeY= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: a87ca2e6-e346-4518-cc13-08dc841ceddd X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2024 22:31:36.5713 (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: +6k/E+GQRpoUBuxL+5ClNNm+bBX0dUhhyAj2jWyzQHOZWioYXxZBmOcM7QEDSmsi X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6778 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_153151_449025_23205BB9 X-CRM114-Status: GOOD ( 13.32 ) 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 This is being used as both an array of STEs and an array of L1 descriptors. Give the two usages different names and correct types. Remove STRTAB_STE_DWORDS as most usages were indexing or sizing an array of struct arm_smmu_ste. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 21 +++++++++------------ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 9 +++++---- 2 files changed, 14 insertions(+), 16 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 ab415e107054c1..6b4f1a664288db 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1661,8 +1661,8 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) if (desc->l2ptr) return 0; - size = 1 << (STRTAB_SPLIT + ilog2(STRTAB_STE_DWORDS) + 3); - strtab = &cfg->strtab[(sid >> STRTAB_SPLIT) * STRTAB_L1_DESC_DWORDS]; + size = (1 << STRTAB_SPLIT) * sizeof(struct arm_smmu_ste); + strtab = &cfg->strtab.l1_desc[sid >> STRTAB_SPLIT]; desc->span = STRTAB_SPLIT + 1; desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, &desc->l2ptr_dma, @@ -2409,8 +2409,7 @@ arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid) return &cfg->l1_desc[idx1].l2ptr[idx2]; } else { /* Simple linear lookup */ - return (struct arm_smmu_ste *)&cfg - ->strtab[sid * STRTAB_STE_DWORDS]; + return &cfg->strtab.linear[sid]; } } @@ -3225,17 +3224,15 @@ static int arm_smmu_init_l1_strtab(struct arm_smmu_device *smmu) { unsigned int i; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; - void *strtab = smmu->strtab_cfg.strtab; cfg->l1_desc = devm_kcalloc(smmu->dev, cfg->num_l1_ents, sizeof(*cfg->l1_desc), GFP_KERNEL); if (!cfg->l1_desc) return -ENOMEM; - for (i = 0; i < cfg->num_l1_ents; ++i) { - arm_smmu_write_strtab_l1_desc(strtab, &cfg->l1_desc[i]); - strtab += STRTAB_L1_DESC_DWORDS << 3; - } + for (i = 0; i < cfg->num_l1_ents; ++i) + arm_smmu_write_strtab_l1_desc( + &smmu->strtab_cfg.strtab.l1_desc[i], &cfg->l1_desc[i]); return 0; } @@ -3267,7 +3264,7 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) l1size); return -ENOMEM; } - cfg->strtab = strtab; + cfg->strtab.l1_desc = strtab; /* Configure strtab_base_cfg for 2 levels */ reg = FIELD_PREP(STRTAB_BASE_CFG_FMT, STRTAB_BASE_CFG_FMT_2LVL); @@ -3285,7 +3282,7 @@ static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu) u32 size; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; - size = (1 << smmu->sid_bits) * (STRTAB_STE_DWORDS << 3); + size = (1 << smmu->sid_bits) * sizeof(cfg->strtab.linear[0]); strtab = dmam_alloc_coherent(smmu->dev, size, &cfg->strtab_dma, GFP_KERNEL); if (!strtab) { @@ -3294,7 +3291,7 @@ static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu) size); return -ENOMEM; } - cfg->strtab = strtab; + cfg->strtab.linear = strtab; cfg->num_l1_ents = 1 << smmu->sid_bits; /* Configure strtab_base_cfg for a linear table covering all SIDs */ 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 1242a086c9f948..4769780259affc 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -206,10 +206,8 @@ #define STRTAB_L1_DESC_SPAN GENMASK_ULL(4, 0) #define STRTAB_L1_DESC_L2PTR_MASK GENMASK_ULL(51, 6) -#define STRTAB_STE_DWORDS 8 - struct arm_smmu_ste { - __le64 data[STRTAB_STE_DWORDS]; + __le64 data[8]; }; #define STRTAB_STE_0_V (1UL << 0) @@ -612,7 +610,10 @@ struct arm_smmu_s2_cfg { }; struct arm_smmu_strtab_cfg { - __le64 *strtab; + union { + struct arm_smmu_ste *linear; + __le64 *l1_desc; + } strtab; dma_addr_t strtab_dma; struct arm_smmu_strtab_l1_desc *l1_desc; unsigned int num_l1_ents;