From patchwork Tue Aug 6 23:31:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755480 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 233E3C49EA1 for ; Tue, 6 Aug 2024 23:34:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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=B++ncH0RJ+pDAVZWs0XZHrEN9RctEPrhMdjP7SgL2qY=; b=qFmJHRd1JoWWomtiwfjver4CWb cnsiiFHlcGU6nxLmOFA06gZVISkze+/eHnRH8s8odTXU3FKz/eEGsenT5UZMD0QXQK45p2Ad2Zy+o SZTBkSyDwAmpLmdHogZ0PQAblL0D1kWQjC0Eah2Ex2Z1te4hKZxO82e6wd6uaL0jlqXThM8wl1FkY oNHad9E4YVvbjQnU4Q35kli1GJVbvq4zlbwWMIuvs75f33T3oSGvOcXY/lLVSRmYDik5uMeurLgjQ OJ14KwlbHIJYXm9TvCF9VVnRjHGrfVK6a2zvjVidstQ7gIYfku7iFNSTCF+hx1A2XYqLuebrBEY9e iGvr++NA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbThG-00000003KJl-1pR7; Tue, 06 Aug 2024 23:34:30 +0000 Received: from mail-dm6nam10on2062c.outbound.protection.outlook.com ([2a01:111:f400:7e88::62c] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTed-00000003Jdz-3wE2 for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:31:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sAUwrS5fXCzOnVmBdVXDle5ZrBV6CPM5UCurRw6IFEP7J+u90WxRLXKVOqu4N7HAaZUlsGsEp3Z0Zfr25twFiExhb6HET1DKiPgkLJMiiQLYQYt+i/CeQ2d1njBjUa6HuRUzVY4jy5qdQwOCN/xdW6y6XGBVLDb1HUbWFGT/NkAXUA+cp1brGYDFv0rqPp+fZN7RVyViPZTwNhBy1SD5xFUhE8oQ4Qs1KshyTS8QTrOqTzce4KN5nBlXfpl5Ed20LFIIkB6PlbuYyOwQEcB5BAHSNxngzrgr4WGcBM+d5Hq6WcBi34/pR0bkvy/I8YNho/jexRpGYs3kvhAYk12UIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=B++ncH0RJ+pDAVZWs0XZHrEN9RctEPrhMdjP7SgL2qY=; b=qGofdVtK46IThGmpiUo+xLbVn33htxObK8HSIWKf6iONHp6DpiE4u1b5AGsEZRlkUzcELS1l4qX3xA4FSmGkMLgI6jePfAQD/syXtFzyVBk/xrODKFLRpHy/TMcneRfKbtc4jI76l8PwvHzCOjP2Cvo+BkXr5Gde4UfRv6CJZFRsBQh9M4xQgf3eQBA6LFD+3vm8qpBadplohv+FkmEmWJqxxX+BImZUNrjtsmIX+9Mzl49KpBJTYiot/Zr17QnSunjqUWj+7xaLGBjtH5YfkgsDJBrveIrFyGkDgqMolc/C1lf9urthmO9pSKnAji6HgNEUq036S0f33ZkNjtTcRQ== 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=B++ncH0RJ+pDAVZWs0XZHrEN9RctEPrhMdjP7SgL2qY=; b=EV9VqhzTuJTb+JWt7djkI4+CdsctD/fjYBSps+TdEOD5qfOxlBftovzZLNcV3bFY0X2aH1NgVDyHNgEeSFtw6jvCK2wl4p9f12PC4qDL9et8pSojfqUcH6NLCZ5kd2cIUapcqeoYobvx4+wb2caQrjRxy43hNS4LN06S0+IGQ2UldTeBaJZib1ZaaD9HW3L6DidGllWCx+4fRgRFWhl4g9bWeODdSX3ytmKJQtH+pkv2omNcepljOZf8cLC+Ck+LJrKIj2swmiQc/giEe0wx9rO1XNzQQON5Kmivw854vVIGPFpjg92PS7gTnfrrra4qMqFocQKkuCMUoUVNhsZIxA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by PH0PR12MB7839.namprd12.prod.outlook.com (2603:10b6:510:286::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.23; Tue, 6 Aug 2024 23:31:31 +0000 Received: from CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8]) by CH3PR12MB7763.namprd12.prod.outlook.com ([fe80::8b63:dd80:c182:4ce8%3]) with mapi id 15.20.7849.008; Tue, 6 Aug 2024 23:31:31 +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 v3 8/9] iommu/arm-smmu-v3: Add types for each level of the CD table Date: Tue, 6 Aug 2024 20:31:22 -0300 Message-ID: <8-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BN9PR03CA0108.namprd03.prod.outlook.com (2603:10b6:408:fd::23) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|PH0PR12MB7839:EE_ X-MS-Office365-Filtering-Correlation-Id: d584257e-83d0-4c39-8487-08dcb66fe467 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: NQh5NkbPzCqkzBB1YbrfnHMz7J8XJ08F/g4xnZnBCOqSLFm0TW2FoPh/619m6d01+noyVg+FBlSw46hS4mMbocsapYcPnHZ0//Sm8LOok7XgWllwirELzgE2+wf//zmmHqTAo3Ckj4Rm2AccBq3ygb+/4OPjnRauiSIN94BQyb5ox9WseatL5DBujPPnWiFJXZ5tvhnNS3noRcHQYa1C3EpGC/iHApIyPyRWrU5kuSuO27mqYmvzlBw0kCaI/by/lqps78tGD3j/5gKPFDTSgj/3MBeWQ8ZY+++xgvq1KyVLAqKARSchDUqChvt6IINNjCRxlml1tTz46laoYG5exOMKgA0OnfbprqaQSyN5xFr/B8XtnNQYUXLb0LXQRjO0BlIi7LN3AK0ERHSeY6Uy3ygWfk2mfHqeFMDNm4He9+a7/ZAvqDxcJpU2QmNP2dB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cBzSXyt9GwmGu4d/iSGEkpQp0q8HVkMevNYTXWQLXCSrR7svHa8hIw2Kd4n3Xxgoqv5cx+eb8bGwe5b4IvBo9gaa/E0bWCYvzE3sOgp5R6p/hQZaVicOEquDeZ9qprzKeUxGZfLT0M/HJKHvjM/jdpLkk8IfEh3Nso7jZhPe27Y+vXfmkugfuqrUwKX6ih11g9jT6Y4uUIruC0izTBZCmUIf/GHtOjXBbDEFOZL1ddh+2tN4G7WDr5/SN6vGIWufYwTc3E2eptzJC8sED+u35MlVhzdiX38BB6yKcrpLpGTMSwd7nVmRRoY8rikJJkakJdYIe9Z9x+e0SM9+kikYEYcHkaKNDt2YEBXZaB9n3kNC8aWEyCVre/ttsmsIMY4g+byA/nW/z2O/c48fQdGCKXHykK8LHOIP+QpOCVlLjReEaVU4NrOPkqIulpBZEd/d8nFk4Wep5TBKaNsXQY8qOmZTBCuU0tUluQUbTGRO6W6H+1r9+Ay7cVmIKt3EOGeEX+7cTlnumJeP7ID+txaY0456VU9esa6xNC163O+ina9jbO2bhc= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d584257e-83d0-4c39-8487-08dcb66fe467 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:31:27.0595 (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: wx38eVY+/ElkzUKcG2lHR/vyi6i2wC1IKtFBNJfPfinBbEkqPUQ4CBdzUIumLjTT X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7839 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_163148_023456_12F78A9F X-CRM114-Status: GOOD ( 15.11 ) 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 As well as indexing helpers arm_smmu_cdtab_l1/2_idx(). Remove CTXDESC_L1_DESC_DWORDS and CTXDESC_CD_DWORDS replacing them all with type specific calculations. Tested-by: Nicolin Chen Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 46 +++++++++++---------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 27 +++++++++--- 2 files changed, 46 insertions(+), 27 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 d23a845ad82223..70b37d7f0e245d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1179,17 +1179,18 @@ static void arm_smmu_sync_cd(struct arm_smmu_master *master, arm_smmu_cmdq_batch_submit(smmu, &cmds); } -static void arm_smmu_write_cd_l1_desc(__le64 *dst, dma_addr_t l2ptr_dma) +static void arm_smmu_write_cd_l1_desc(struct arm_smmu_cdtab_l1 *dst, + dma_addr_t l2ptr_dma) { u64 val = (l2ptr_dma & CTXDESC_L1_DESC_L2PTR_MASK) | CTXDESC_L1_DESC_V; /* The HW has 64 bit atomicity with stores to the L2 CD table */ - WRITE_ONCE(*dst, cpu_to_le64(val)); + WRITE_ONCE(dst->l2ptr, cpu_to_le64(val)); } -static dma_addr_t arm_smmu_cd_l1_get_desc(const __le64 *src) +static dma_addr_t arm_smmu_cd_l1_get_desc(const struct arm_smmu_cdtab_l1 *src) { - return le64_to_cpu(*src) & CTXDESC_L1_DESC_L2PTR_MASK; + return le64_to_cpu(src->l2ptr) & CTXDESC_L1_DESC_L2PTR_MASK; } struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, @@ -1202,13 +1203,12 @@ struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, return NULL; if (cd_table->s1fmt == STRTAB_STE_0_S1FMT_LINEAR) - return (struct arm_smmu_cd *)(cd_table->cdtab + - ssid * CTXDESC_CD_DWORDS); + return &((struct arm_smmu_cd *)cd_table->cdtab)[ssid]; - l1_desc = &cd_table->l1_desc[ssid / CTXDESC_L2_ENTRIES]; + l1_desc = &cd_table->l1_desc[arm_smmu_cdtab_l1_idx(ssid)]; if (!l1_desc->l2ptr) return NULL; - return &l1_desc->l2ptr[ssid % CTXDESC_L2_ENTRIES]; + return &l1_desc->l2ptr->cds[arm_smmu_cdtab_l2_idx(ssid)]; } static struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, @@ -1226,7 +1226,7 @@ static struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, } if (cd_table->s1fmt == STRTAB_STE_0_S1FMT_64K_L2) { - unsigned int idx = ssid / CTXDESC_L2_ENTRIES; + unsigned int idx = arm_smmu_cdtab_l1_idx(ssid); struct arm_smmu_l1_ctx_desc *l1_desc; l1_desc = &cd_table->l1_desc[idx]; @@ -1240,8 +1240,10 @@ static struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, if (!l1_desc->l2ptr) return NULL; - arm_smmu_write_cd_l1_desc(&cd_table->cdtab[idx], - l2ptr_dma); + arm_smmu_write_cd_l1_desc( + &((struct arm_smmu_cdtab_l1 *) + cd_table->cdtab)[idx], + l2ptr_dma); /* An invalid L1CD can be cached */ arm_smmu_sync_cd(master, ssid, false); } @@ -1385,7 +1387,7 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) cd_table->s1fmt = STRTAB_STE_0_S1FMT_LINEAR; cd_table->num_l1_ents = max_contexts; - l1size = max_contexts * (CTXDESC_CD_DWORDS << 3); + l1size = max_contexts * sizeof(struct arm_smmu_cd); } else { cd_table->s1fmt = STRTAB_STE_0_S1FMT_64K_L2; cd_table->num_l1_ents = DIV_ROUND_UP(max_contexts, @@ -1397,7 +1399,8 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) if (!cd_table->l1_desc) return -ENOMEM; - l1size = cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); + l1size = cd_table->num_l1_ents * + sizeof(struct arm_smmu_cdtab_l1); } cd_table->cdtab = dma_alloc_coherent(smmu->dev, l1size, @@ -1421,27 +1424,28 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) { int i; - size_t size, l1size; + size_t l1size; struct arm_smmu_device *smmu = master->smmu; struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; if (cd_table->l1_desc) { - size = CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3); - for (i = 0; i < cd_table->num_l1_ents; i++) { if (!cd_table->l1_desc[i].l2ptr) continue; - dma_free_coherent(smmu->dev, size, + dma_free_coherent(smmu->dev, + sizeof(*cd_table->l1_desc[i].l2ptr), cd_table->l1_desc[i].l2ptr, - arm_smmu_cd_l1_get_desc( - &cd_table->cdtab[i])); + arm_smmu_cd_l1_get_desc(&( + (struct arm_smmu_cdtab_l1 *) + cd_table->cdtab)[i])); } kfree(cd_table->l1_desc); - l1size = cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); + l1size = cd_table->num_l1_ents * + sizeof(struct arm_smmu_cdtab_l1); } else { - l1size = cd_table->num_l1_ents * (CTXDESC_CD_DWORDS << 3); + l1size = cd_table->num_l1_ents * sizeof(struct arm_smmu_cd); } dma_free_coherent(smmu->dev, l1size, cd_table->cdtab, 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 68841ba3c2e789..681804a3f86bec 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -296,16 +296,31 @@ static inline u32 arm_smmu_strtab_l2_idx(u32 sid) */ #define CTXDESC_L2_ENTRIES 1024 -#define CTXDESC_L1_DESC_DWORDS 1 #define CTXDESC_L1_DESC_V (1UL << 0) #define CTXDESC_L1_DESC_L2PTR_MASK GENMASK_ULL(51, 12) -#define CTXDESC_CD_DWORDS 8 - struct arm_smmu_cd { - __le64 data[CTXDESC_CD_DWORDS]; + __le64 data[8]; }; +struct arm_smmu_cdtab_l2 { + struct arm_smmu_cd cds[CTXDESC_L2_ENTRIES]; +}; + +struct arm_smmu_cdtab_l1 { + __le64 l2ptr; +}; + +static inline unsigned int arm_smmu_cdtab_l1_idx(unsigned int ssid) +{ + return ssid / CTXDESC_L2_ENTRIES; +} + +static inline unsigned int arm_smmu_cdtab_l2_idx(unsigned int ssid) +{ + return ssid % CTXDESC_L2_ENTRIES; +} + #define CTXDESC_CD_0_TCR_T0SZ GENMASK_ULL(5, 0) #define CTXDESC_CD_0_TCR_TG0 GENMASK_ULL(7, 6) #define CTXDESC_CD_0_TCR_IRGN0 GENMASK_ULL(9, 8) @@ -336,7 +351,7 @@ struct arm_smmu_cd { * When the SMMU only supports linear context descriptor tables, pick a * reasonable size limit (64kB). */ -#define CTXDESC_LINEAR_CDMAX ilog2(SZ_64K / (CTXDESC_CD_DWORDS << 3)) +#define CTXDESC_LINEAR_CDMAX ilog2(SZ_64K / sizeof(struct arm_smmu_cd)) /* Command queue */ #define CMDQ_ENT_SZ_SHIFT 4 @@ -605,7 +620,7 @@ struct arm_smmu_ctx_desc { }; struct arm_smmu_l1_ctx_desc { - struct arm_smmu_cd *l2ptr; + struct arm_smmu_cdtab_l2 *l2ptr; }; struct arm_smmu_ctx_desc_cfg {