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; From patchwork Mon Jun 3 22:31:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684420 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 1EB37C25B78 for ; Mon, 3 Jun 2024 22:32: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=FOhARvDiXej2d0eFaZG803yYIZ5wwcAvBIPaH1nfMCE=; b=1dspyXKPNEREEN ojMX2z9jdmWJi1iY0m9pWSTx73sSi3LUS+MqTHq2T3m7p75uWJF3CspI0DRCMx0tVW0uVmDcBHsl4 y+VY4asOrHhV2Mfi9lT6US3mkTaJnnyNHAiPJgkmgPvq0K64YfVmWajnD4Jsb/9l3bu3qGzHXvMwV 8H3bu3LJ5+rRMyiypQh8MqMVtM4SetHtKm6ywmqTxiJ7nMPvHSHOVPnobGZYipOIDFTc71GlYBIXz 6rWdyO7IXDvJ3s42uXMNy1ejmkPde5kVzLrv0goiw2B1B5nO1Fn9oZL98lIcBQsRNPZNCHOfAdvUS De2TGMW6MdaCjCqNNwPA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEGDb-00000000Ujh-3myq; Mon, 03 Jun 2024 22:31:55 +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 1sEGDY-00000000UcR-3Oap for linux-arm-kernel@lists.infradead.org; Mon, 03 Jun 2024 22:31:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BsKuNipbZAPF/lbR9nRkLOCh39wuQ5DouLipnAQVPY0l/sXZ2DQ2J2srdMZtCMWpiq48V3n3XhjR3zt9V6Wn/VIss6VYsOJEfx63t1gFlXifLQ8vQZUQJlHRZx+8P+an9zVt/X+tfyhy/LLZGk9XmEzBjTmxe/k5lbp7xcRQfAavhK1cEQtAAYEJv9qHUWZKXdMynFs+P3dTwy7fNsvSJVPVhKFhD9ZktQxMJ69l8KHpslzqay8Wa2iziEh91nrxTLhvFmLDeSjC0AEQ5/ALIJFKDctXp1EVK0iPh3m4SqNiJTtw+8IpdVEygSHrANyESmez+qnnYXzLepxPmGkmuw== 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=lphU3KQKuRLndzzM5bkWVVObagvyxuP0pAYPwpGda5w=; b=e5CozVQruYLuVyXWI/on6DIQrNGuU5j/OU8YyVLLjxyGqC80mDDmlmsKFhAnhLktvlKGIb7KIejD+H8swMwDJesBvZHd5cfISt86Z2F5qrmXqCBOnyExNulYfpU/ouvSXkLm31k8NXnbY9u49KsxJwxFqhlFQlcZVtAsi1E5QH25G+RU23XjxBsgEy6oQiDeC+RZJlztvTTQGDNZ/arLPmCNJ5pO6q/0V7UCriF6QNm0V2hfQKnDYWbHQt1RLYQj7uUMkk2/lY9s0L50X+rn/vHx6NATyC2WK0o/y+XiwGm45j8+I/ffSyugD/RNh2GSNldo2Apa2D448G6HOa5yQA== 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=lphU3KQKuRLndzzM5bkWVVObagvyxuP0pAYPwpGda5w=; b=oHyKofr4mxA2FVWhrLAayfgaEQapQlgYBTzpQYMtjrPTsNxveb7Q2O7bjVQVAXoincdI4F46JWOgllGvQgzagzUS+l5ZuQz7UdH23n/iK++3TFX2TeSk+1DYodJ/PQN6S5YkgQNYBNaB2wbUWuRWuWKKiki6CZwWIlXmm1RpnptNwHxQK04OyCOY2t1Nka59+unn7Q9wY1PIMkmt+SLoXYfSnyazhuU6PFsU7wyTF5DV3X9YIy6A5B5630ySU1Bs61+grcT+tnsoApdhoTQSzOAQdPSQ5TWm5MjX+GETsQT9ObFOiI6stl1ew7ZtRItZ4nJ8YLLLgZtvs5UesaI71g== 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:38 +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:38 +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 2/7] iommu/arm-smmu-v3: Do not zero the strtab twice Date: Mon, 3 Jun 2024 19:31:28 -0300 Message-ID: <2-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR11CA0018.namprd11.prod.outlook.com (2603:10b6:208:23b::23) 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: 7c36cf1d-f5ac-4821-6ee4-08dc841cedfe 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: aPjU2KQAwEd/3yBx7qJw25JLRBnGtEUeSDioQAOFcfwhan2CJe2LPxrZtimNIS4zXCbUj2hPePKN4cy5pd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wf4rHeueGMlhgQJe8b8uvbs7FPn0fjoqGkwAI1VKPs3IGMt8bYiLvw7+C1wjKxpoLC6woKTvW4cZHnnW4bB0l9E2vmWtPhWwDaT8W3yULC1AApdyLo/+r7LTzxCgHnTao1VLqw== 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: KB1b1KOpiubw8YsIMQjq07zlH7a0pdaxtDLaCExVSNlIEQ/++T41vKPR5akkm5oGUl65uUbQm1RKnZW+3jgNEoV3/HRsZ9A0BeHxSmCCmJvcidta8rUcnOWtBW+qo6RVIvW8pvYNriitZu+i1yb9NiUKUYhn7Ay6/BrCgoWr4kGU2EKxaLI388lpCZx0qFiNATtaUovovL7hZPHh49PjheFtlEF0Ttsxz3qmH+5mQgSlIpQ9ivx/d+Bx+sFWK1H73HbJwSgGuB9T3pmmEdbPtGyfzazHSyhEU84UE5svR2Yb93zq0kj7hI1yuERAcwTrJWVztKDvLm18mz8/88hrvL/+5x0stq85L14Loz60tw1ztZf0Kuoe43uhI1CeDaBYt0uLFGP0gVzKXIP76bjp3rHQ2D6d5zixrUaMl2sVWu0+XCzR60gb1VPkcC7zb7nA3HCCFjWaAUHktvHMlXYkNLSt1xGaJTEDe1xZ7VJr8U5/icD1wtXi2PWWAQ6L9svcTBaxwd0rMsGC4wpWXnWf0TUMNGTmxe64qlFcdtFKt+Q30hkcWI7hRKjFZxJjaf2AfU2IwTkeaIEaTYJZNm96Bbqw+kyoFtNq0qca+aY12reJ+1cOKS1NAxU8IppjDxgIQmnVGdMecpBWm4qyDd1WO/pQDaaJkAYy8mbk0nRwqxJSRR1hV2OtOPLeW6aJWxmD27j7QNhnG0//1rZ2Qk4Et1J9bZpjug07SaKzC5Fc5dPydbLYRy2efFXRSnI0nMlNtUdryxW1S0qRa+c9H/5kuTshnfkGzfBDyMhVgBbB1Jps3epjWfPbCUqmNSz1VIN/+N9K2meAoV0tlgjsf0ejjPwbO2y3eZFLkFKKQkFVgv1qAYvZc1Pi+ikCzqVEiwaS/lpJZJVFzXsK0M6mrq1Q+vEBjN2rVdX+7jjOOy1cbSh9IZ5trPG1D9xxHdYmg/hBO4t8tgzzHcXWnIBh+bFsFWRFBXmrTi1RoWHTvXvNQzQ6Zz9Pwzhg3QM3wA4k9NzW8n6qbtiFg8R9+pZzjMt28ZcyYuMwOAwh2NaYQgmeHPEiCagGDjInlRG5Ewy6yktu/U6jgr7ELvcZwYQWWY9yAAkk2faWcjutJ0XPo/PyJQ7xS7E8J9Et31HKMDcw+27CVqRoIy9WaJxsPX1NN9SEsPUcU7YnxOUnXzxxg5KeNNNh7tyj/LBuPiy7UT0sW4b2gLPV3YQ6/63X0fSLz34eGVYp07LptG+mHmasSWm4+JKgckaVCqiDKRl492qXFWB09/6sY/jTrZnIsW2AhfhIYoqvAdI36S9jrzFv0za/VEeyBa5sgxbKUWW0072a1sLMXtWJNloq7g2JMNvB+1QkhhVSotZN4WOyBwpJcrCJmU/gQeEfGYzPo2P70hbodteoNeI1NL0HbNCDbvn5yy7qMeDJFcAjOUNx6dz2+G9h+6AxpfIlHQ0tDsH0+5YEhIuzt3EQDoxVAMig/TNISSwFOp/mNqU4R+qpd2XBnLMw3vhhA7r4FNm0BQpt2vE6t4C6UXPWu5rAboLber1fmwt20wYFC9YOhCyfbMb2/MD/R5w= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7c36cf1d-f5ac-4821-6ee4-08dc841cedfe 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.7838 (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: ap/V1o3mHQwDEcfJ0pFOvUkoOsE/VjKX5qHU8sRXJy+cPVkJ0AbF6qw+BQqvrgMt X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6778 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_153152_863082_88275272 X-CRM114-Status: GOOD ( 11.54 ) 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 dmam_alloc_coherent() already returns zero'd memory so cfg->strtab.l1_desc (the list of DMA addresses for the L2 entries) is already zero'd. arm_smmu_init_l1_strtab() goes through and calls arm_smmu_write_strtab_l1_desc() on the newly allocated (and zero'd) struct arm_smmu_strtab_l1_desc, which ends up computing 'val = 0' and zeroing it again. Remove arm_smmu_init_l1_strtab() and just call devm_kcalloc() from arm_smmu_init_strtab_2lvl to allocate the companion struct. Signed-off-by: Jason Gunthorpe Reviewed-by: Mostafa Saleh --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 27 +++++++-------------- 1 file changed, 9 insertions(+), 18 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 6b4f1a664288db..d27dd0600bf1df 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3220,23 +3220,6 @@ static int arm_smmu_init_queues(struct arm_smmu_device *smmu) PRIQ_ENT_DWORDS, "priq"); } -static int arm_smmu_init_l1_strtab(struct arm_smmu_device *smmu) -{ - unsigned int i; - struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; - - 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( - &smmu->strtab_cfg.strtab.l1_desc[i], &cfg->l1_desc[i]); - - return 0; -} - static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) { void *strtab; @@ -3272,7 +3255,15 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) reg |= FIELD_PREP(STRTAB_BASE_CFG_SPLIT, STRTAB_SPLIT); cfg->strtab_base_cfg = reg; - return arm_smmu_init_l1_strtab(smmu); + cfg->l1_desc = devm_kcalloc(smmu->dev, cfg->num_l1_ents, + sizeof(*cfg->l1_desc), GFP_KERNEL); + if (!cfg->l1_desc) { + dev_err(smmu->dev, + "failed to allocate l1 stream table (%zu bytes)\n", + cfg->num_l1_ents * sizeof(*cfg->l1_desc)); + return -ENOMEM; + } + return 0; } static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu) From patchwork Mon Jun 3 22:31:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684455 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 D50C1C25B75 for ; Mon, 3 Jun 2024 22:46: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=VkRKt5nOdARbHJJT6Mg9/qupVSFr8GEDK2BT7l4z+mM=; b=CW8nU4+t1EY7zl JuLpd8zwOAHeSJ+pQV1COkUGd54WZcQP2PDdoiP0HmUexgie7qujVM7TYmXMOgx9QahVijfAIbIcO 0GdjftcpMMchBuufoKnNFrGGZhuoOXEn2g3OLTeAACayvi/H57Lg25KDjaTNHYARQV2nDJQWo2ABf xBUuTp95BlA51Rhni73NbqnumEo4tBOUNt7bksbxC/L/14OVinPDBUe32x22Ht3LGUaAst+DQ+htO a30iP8nU2GlVS+B3ZWZXUZxufTxPMXehUm/eIOLG2mmi2r0k1wLXNWNz17jbMEpIGMhc93PQzH6Au YIdn4hV9iQgV2XaiegRQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEGRL-00000000XOf-0jII; Mon, 03 Jun 2024 22:46:07 +0000 Received: from mail-bn8nam04on20600.outbound.protection.outlook.com ([2a01:111:f403:2408::600] helo=NAM04-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEGRH-00000000XNi-3lOG for linux-arm-kernel@lists.infradead.org; Mon, 03 Jun 2024 22:46:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EugQ1CqemH9InTPEPIo3n3DR7ZlHxp2FfoKEqhSeJiCSm0FQ8I00IMWQ1baxo0T1DV8Y6cqzvfuL+dmjCaWRnnxmYpmIqw/jthLUwJAL1Qu+BuPyJ4rseWoKNqzye0UGvrKjlCgnOqnyLLOPiaPTteawUirT/aehZOhgKIgOMfAJvnl3nJMDnZ94BAxBcd8ubp7GPv7vx1d7WZpOa66xnXD7DUkU2aXY/OttJgUAMIQdE9sXR7DOUmxTzZ8V1fOYqwDBoz1zsidDfHucNP/LPxM5Zy4jIjnvuE8BUA3CPZJMMp8zxieYvoI0yD2dvaxmYV5XUM+LSma8JZftpNg87g== 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=8S5BLU9hmD0jyUqeJWwDK5uZDH5e8UMpl+jedlZE6w4=; b=huHF0crF2CcatLpxKwduAkAVyhTzKvP/mEi3wSOG9QX7dTScyIMV84Y0HTj2kqW1PFZwBINHlnZ2CH8lCI/ZjGBmFuyJQAF73DLMaDK7IOfd8BMOW2hpW6uy5kHAGzc0piaIoJDSEu7nSzJ5faN9Q0a5hLatPrnYFDR9Fa6idLiI0HTopz87bZcNg6snkJgXws4uwLVIKDVxyUzzFkvsX4FUfISgv7s0dGDRLtKD4r9npn3j707Lg9HwJQodn+/8QEgE9HEhjbGiq/vuT2VP7jiFe9H9gtzDq1noGmDdqr07XGhuP/sQVfINoQcD3ydzNtCGyaMstD1qpT4+tYszDA== 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=8S5BLU9hmD0jyUqeJWwDK5uZDH5e8UMpl+jedlZE6w4=; b=IimGIcz23R3XH1VVPa1dE2DgfNPf8gK7A5PaSQ3cXbVoiWYCEfINK81H+9dIC5TUDk8um5CL2s5qcwYjRtn0XKzcmJPAaPEQzCVWh/E6wNPBCsIHNYE1EAsm2ZPC1iv+4zoek4Fj/Fr96pLvLpStOzw4hSda5J2/QGQaLtRH1hyz4sK+mon3rTV6FTYiFPUNL5zzjUfq9aYAITdZQBzNBufUHkJN5Wxb1w4Hk72o/EF8zbtmCWarf+3YM+C9D4jJsvbwWLndnnVvouh79XbVEbBRmT8X0j409YpFS8QorWIm9EDxh4BX82ZPh/F4ZksjiNKyfYnHQuJFggkQcokXsA== 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:36 +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:36 +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 3/7] iommu/arm-smmu-v3: Shrink the strtab l1_desc array Date: Mon, 3 Jun 2024 19:31:29 -0300 Message-ID: <3-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0102.namprd13.prod.outlook.com (2603:10b6:208:2b9::17) 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: 22e33f04-5d7a-4d87-bb0a-08dc841cece7 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: 2dQEZp0x2V4vcVVNifuibPxqOnu2yrSSIIemPhqQiT47fwUHFzxhC2tzUFPfYuztyxu7r9660J3tegTu6mV/do2PRSRFRY0ABGN32dkEA470UX4y7621einxqNaRNxFpm4IsuoFHCmSDz7+A15yFmfzy93mKtySOIc9ruAY/YoCM4mY6d7pYDTengS7PdvuAwOI+1P4ycZNX4wVtNSrXBVTATS1hfhTpiLqzGQ2Ymqo0f8q1YQ8DtwEX7BBiXMABA/4bwv8J9EyX+OlirmhozVKHtAnvIT7uEAB+ICYHrDoY7j32AsRBkh9uB3U7r+tNNqy+Rck3kvZAlGV3u7jWHvMxzWKcdqzV9tkwJFkecV8LsTqt7Mr8JZC2fDYQRFVI9v2lPtCzO+UpFCubq+er+hvgc4e4M4RoZ84DkXxPM7RZ/tSSn0foQ0Ie1GW34QacSChQsuIRJ0gVO4fE+/U3PliRDgpSTp6cSXbntdVqP2mus001Ur1+5pQjNx62/fvu3bX53o+SngjhSEnks4zlhOFDe+Cea2tR5KwqWGrI830a0p1DU1DusdrWGaNBNWPx8C40w7AUL76b+k6+FWF2qAYTetEVgf6flHnsFZ6KnYi8WoPywe9j2futZAE119H8Q4dVa/Uh/6R2p0aYNmb4P2eCKiEjYC/X0MEXj870agKNdxpif6VXIYFCSTyMcGf8X3FHH0kTjPmTiIRE+TYNwIjR4wqvEouixfVVtI93oZGiuYPVg3gbjU8lGT3YBqycu4nH1ytRKVAIlARw9bW7J3qOTxhnwu+5OWv6it+jz+sFhjY7Iq43cydOjBRfrLKvLOcbSRDGsGChJVHiVn3kRWNE3jp7nnzXMWis7OQ6X0Hw6RM4p2zCoHPi7/DgLdE+q0/j9t0UGNyN2/Cc6QRfBwQ4SDjSfYSu3wFBxUdNJ+m/aVe4Wr8dhU//JBiRabP+AGwFBUbXFITSyXNQvAsir9EhduwjXAKaSg5ZLA2fpkALZ70BjPSTDgEbxmt5E9eJVISUm+qf6jqeII78e2bN14PGKkWqrlIw9YwTOO7+SJWBge1GAh7YUBh00Ouq4oBamkpbdjI3TdUdwOxtcwIxzQh3VfGxTw8VWTj9Fh3vBx78a49lGAQU0b27IJqEeNJztojxTA+7WVCHAULu5K2vJYmV61qvb4C9zeRHw7Q6GVTUpt656jWaRVQ+ipxW8NJw83mUp8F+mvC2rAhbzB8kqPPBfc/oae1q4AJnm2RXML8otLQ5/tEX3ETU/E2Q++00EFy1/m6NzoFH0o8doDL/7w== 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: c0STayKahAXx3E9yGSUdKEkQ0YWFo6LAdESLFjgsMcqCTHPD69CCWnNV81JLGlgJKfdQ7f/PFhEkvX122avXDOJHG964rSPf1/Kvug5p4egxppt2L+LXoVExVU4DnUVb4IYyfoX/r072UZmHk6bMoWOWFr/qG4ihwxW1wJ2TyyA50dLlOWwHTVwRQdgUasIVut3HwF38kWrBC5GUaIXn7Ir4740ndQa9+9l0okgH5J1KISKErzf5SYZsR21UyfPxfajRRELg4K+Kc15CyCMst6RlvlI6YhRC2/OZ+Y9B+4Naf1RLhUlJBKUQDOHExlda/k6dpnt0+pd3kqCetSDIO8eKVJX0OepMI3PDWPtbFsXTeK9pNdcGZzoJ/tIT8cKf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NwkOCZNeuasbQsuUEzmd1mnnSHJj4kB6TrsPK5UBz97bGzGD6p0wC9KOr1Xg6yi1QDpW3vLVwLF1bpfF6WMzBVrEJG/60p4XyEmvg= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 22e33f04-5d7a-4d87-bb0a-08dc841cece7 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:35.0114 (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: AvniJDKCxnY8uCnl95IXym2PvZf6gX7GS5hCGxwfBdoj6dbuekyjtlX7t8ArMh8l X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6778 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_154603_946751_0C54E70C X-CRM114-Status: GOOD ( 11.82 ) 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 The top of the 2 level stream table is (at most) 128k entries big, and two high order allocations are required. One of __le64 which is programmed into the HW (1M), and one of struct arm_smmu_strtab_l1_desc which holds the CPU pointer (3M). There is no reason to store the l2ptr_dma as nothing reads it. devm stores a copy of it and the DMA memory will be freed via devm mechanisms. span is a constant of 8+1. Remove both. This removes 16 bytes from each arm_smmu_l1_ctx_desc and saves up to 2M of memory per iommu instance. Signed-off-by: Jason Gunthorpe Reviewed-by: Mostafa Saleh --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 14 +++++++------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 3 --- 2 files changed, 7 insertions(+), 10 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 d27dd0600bf1df..735dd9ff61890e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1448,12 +1448,12 @@ bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd) /* Stream table manipulation functions */ static void -arm_smmu_write_strtab_l1_desc(__le64 *dst, struct arm_smmu_strtab_l1_desc *desc) +arm_smmu_write_strtab_l1_desc(__le64 *dst, dma_addr_t l2ptr_dma, u8 span) { u64 val = 0; - val |= FIELD_PREP(STRTAB_L1_DESC_SPAN, desc->span); - val |= desc->l2ptr_dma & STRTAB_L1_DESC_L2PTR_MASK; + val |= FIELD_PREP(STRTAB_L1_DESC_SPAN, span); + val |= l2ptr_dma & STRTAB_L1_DESC_L2PTR_MASK; /* The HW has 64 bit atomicity with stores to the L2 STE table */ WRITE_ONCE(*dst, cpu_to_le64(val)); @@ -1655,6 +1655,7 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) { size_t size; void *strtab; + dma_addr_t l2ptr_dma; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; struct arm_smmu_strtab_l1_desc *desc = &cfg->l1_desc[sid >> STRTAB_SPLIT]; @@ -1664,9 +1665,8 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) 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, - GFP_KERNEL); + desc->l2ptr = + dmam_alloc_coherent(smmu->dev, size, &l2ptr_dma, GFP_KERNEL); if (!desc->l2ptr) { dev_err(smmu->dev, "failed to allocate l2 stream table for SID %u\n", @@ -1675,7 +1675,7 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) } arm_smmu_init_initial_stes(desc->l2ptr, 1 << STRTAB_SPLIT); - arm_smmu_write_strtab_l1_desc(strtab, desc); + arm_smmu_write_strtab_l1_desc(strtab, l2ptr_dma, STRTAB_SPLIT + 1); return 0; } 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 4769780259affc..280a04bfb7230c 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -577,10 +577,7 @@ struct arm_smmu_priq { /* High-level stream table and context descriptor structures */ struct arm_smmu_strtab_l1_desc { - u8 span; - struct arm_smmu_ste *l2ptr; - dma_addr_t l2ptr_dma; }; struct arm_smmu_ctx_desc { From patchwork Mon Jun 3 22:31:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684458 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 E6E95C25B75 for ; Mon, 3 Jun 2024 22:46:49 +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=AbKmIeQeu7XVoiGr8hmS20Q1MK6SVDCJA8oUX6EqUMk=; b=0PZt5a1CS+rouM OW4QimRAIMd/osfJBB2YCeUUW+U2wtpmvMejjURafifIwfN4DaJYklp7H2o1YCbRc+3S5hb2SBWF4 Q308xevfVRyXPHREs4QdaKwE9a+ammVAqfj9N2LksIjRM8dJkQWv91/gnZBqpN+RV52tC6dW1NgsT lDrQsHvURjRUqChBiOWG9GxYq5YrA8Yjx+RLDs62MdjRRRUizEdmQaTlE5VDuud1ZVnL/GrlODb9B LjYY92KtuhzFkDak54xUJlR3BefB1MwB6NkHkzpC7O+9sI5N8IOoPAOcB7oVVIvprA+HKLs551tok HkgrzDT9WN+uaNe48wTA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEGRs-00000000XXs-3qOH; Mon, 03 Jun 2024 22:46:40 +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 1sEGRp-00000000XUU-2VVB for linux-arm-kernel@lists.infradead.org; Mon, 03 Jun 2024 22:46:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iinEgzqPB8phoY7yOXTonus0BnDIGMt5TjUp9K0tkglBZekRZFfXKJeJ2YBH/blio0TJynxeSw+GSd5h6lBQKXuE24O3bys23CoIVrdosTqDtS1YMPdyEEPsKn4icywBVgvLRCT5yOvlVEXA9deIHkWgDOB9z/rhtOS9kB30XeRc8FwOlnqc5VkpUv6C0pDzZQQl22n+KA33FCkcwBh7sKKrIwrUkeE+cXJe9gfcWaU5ytbGWw7w8ZCyFO8VcjJ23kjP9cC0hhXnDTMbXF/kLXODYBic3wOjH9Gii+bi8+YaG7o3esxPlYwifDMseKSzpkJjrSFdVdAsmu0PiUXeOg== 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=VRJjIkOu38E5kg3xINGR6FAcRVFKme4NhlxHgbMJFDE=; b=Qh1cGvyLzCqXzLMStMcgYv9HeUP8jtOARsr628P6dR+oXY/6yHWigRJbRPCY2R7NNlVnJw5uW/8aice59VFCAptlruYIGjN0wkOBQs1hCBtM7ORxeDIZGJTsAGfgxGvH5LKZx0BScyOzoqMZlBGU5cE+EQPEERfF27ibZyalRHJD67usAVkgMOniTyWEH4By7LjsJ9jB0zG65tFs5+d5Pkpn53JzmPdfhVTx9Y7oK27cYYUENho7XMvBVdzF+b89pH0g8cusmb0OzPI2GnejJJUva4BcSTsH9dmKlo16GMSbh1Jkym13KbZkSp6U1NidYSVKdQGMR6D0e343kXmvBw== 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=VRJjIkOu38E5kg3xINGR6FAcRVFKme4NhlxHgbMJFDE=; b=oO0a8YYO4TlR8HxbjMoboDOGiww8zNdqpfk/WcLtJWA8zh6w9cCDpmaVCMMZRz4IwBzzV0wEZE/AMXFt0yYaCi2CLJ6cmOyyLXhFUdZfHpGFoKCCrhlcbtbnr0tOXGY0RIyfXY8gW+PN0c8yayy92L9Fc/U3XIqCq/Egf8kCZ8O8H28rMxPI/3LwbvuVD5Tyx8sIw1+WAOWHBQQqefnXVgUaUoZjRT0seH47Cao8s0GDproGsOMpcO8cp4a+3fTsH9l9kwegKjlQxnBf5TnuprXPfnYe9wsqN3XKB/tG8SCwSrD05RHFX0IQxLzJ5JfhwXs/5X2P3vLEi8/4OL1Kvg== 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:39 +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:39 +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 4/7] iommu/arm-smmu-v3: Split struct arm_smmu_ctx_desc_cfg.cdtab Date: Mon, 3 Jun 2024 19:31:30 -0300 Message-ID: <4-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR05CA0022.namprd05.prod.outlook.com (2603:10b6:208:c0::35) 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: a7297142-cac4-4418-1191-08dc841cee07 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: iy1LqQZLKb49E7SKbz5uA59h3IoKhSCQ+5JvDPzoo0o2Ixg/e0oy+gPkhTAKsnz5KuMeGXL6KEVBnRZmbUeXJJqQDNW3D4/8jwtVlz72bYPk1jqsM16g5b7FYFmt0bDXh0c0CDIwG0ssoTxrQMQLlfGEg5orBImwCIpXKAoZS81NWOCGzNe3JFb4ebCAVczi04u/fLalxNYmkZqjMdnMF6yzfW8Mz1lr9TdGs4d5/s9sCN3tyypiSa+BgQh8TFqVRSI9n0zytRTNhAxm/VmLFw1aPNqHbaOoFOckp+OWGVh/38fAb8amZ/C8W9K/VJxsfAVPyZzQOGWjJei+vKXRQ4TT+9b9OcDG4mAUoMhDB9A1Uo/1wsj7x40vk1bSpUD29n1s8OH6HZ1d2dx98mXLuUU6aIC77zczZyaQdlQroQNgfUSVPU9Ak9c0oPaPVrgh3ATZTu0V7wK/+wIyHX4zigX7r2+vVicNDnbG9JJcHVuEARL/bp0BDQnd687TMB5Z8ggveQsIznj4nzZnzTMaaQxP4VIRgduHn+4W75xGNNxAhwYrYwVOki5xCY2IUOOM5RucuPuIqL1Rtpo6UrtGxcZEdmZBfD7j8fFbd9dCzPBttcKuNcY2WlzVQH2uZ3OGeBUJafueLYQ09JAUU33iyD91MmF387ytWRK10CG7faav1M8ESU8ot9r4FodEJge9WQQvSvKMYBAoVGD+gtweXGWaFRjrljdBrMhv7FxQnHReB0GJ0KFm4ttGw2Gx6vYFbad64eR0w31sCRF7aJCZulR2CxIK558o5irGZz0ryYN2fwthO4vCPdlH3DF95sYvEVvwoCh69iwCVeSjRZyRACp5CQYyXAzOgVOUyi2yQSj+4qpCGb3+RfvNYLYiwypCcBA634EFhwNFodMznd8J+iynkDDocrYRWdJVi6uFa18NOHGVwO9dS2WznJf809A1jRH23y8GIQkTvRJFdnUlWFMnA+tvXje5f2QFDfC9beaXROq4D3YjS/2uyrocEfVESgmIU95LoqAD0GlIY5uZCQ9ptBgWlCaS9CCdOCSC02JKw0lYuSATe7QH2KqtYsjM6A9teyKD9UdhKIJ7YydCNnogysbdcws1q+tp/UxMpgWAFH1n4+LOoOS2li/KpSp7TvRtjvroPF8YBHiwhwGqwhhnx46In9J+MqnOaLL/oze+leZlzO4VW1yrKOCjG3HOTaWMaVFA13Tidffm5dFk70NrWuEpl6EPbwl6+mbPRJJzbSYDFLNiRb1v6grLnQZBi8WrXJZrl1LseWFdlo2x8A== 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: mNZDtq6+5lXgKl0nr5z0pEjPZFIqEPEHZ5OfmnrqM9MQZ3n0MNeGHjCudLEqAJtov6E5NIJ/vyj/NMwf9mRXV5z/RVSZezXYDTNZR+66bfH0+Tgsdd7EWO2pMtV93e+gxs1vN0d/fJEilvkWdi3BDjnUQC2JJgk8pwH4IyUYrM2ULe6wn2S89S/BbLW/M8ZW6KeK8S9kOv5dgduiIYPP6Mc+GntfxmBJDH6E+7qyXxgZuR+vuLEH/HbZEOo8zQe8wCoj70I3a7GTibTuXB0vdyPcmTa+LVSnQk4a/goTFv14SykvcQzoqYmu6BWAxzxH/Q6r4uHiMt/E6k6Avv5NE/m8EHJ8JSR+l+29OOkT8cZsbJNiD/S+KaOtK5N1WF8jgqjeRb5LoAfia0WtfUmWp0Urz2cCosW9jZpcIOfkjo2qw7EfyG1qac2mpPHK+h2xAygNlksBs4MY8Ur7lMbT6N3ggCGeg7gBBm3VKSyDvexUBfaEj/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HrEpPLd2wSWgmcU= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: a7297142-cac4-4418-1191-08dc841cee07 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.9460 (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: 76bmWAdTzhZSGF7GNYA8A1ptnX3N+5oG2BXt2vpSMTJr+M+oDvC34Bc6PhTLXwUM X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6778 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_154637_983966_C95E4453 X-CRM114-Status: GOOD ( 15.62 ) 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 CDs and an array of L1 descriptors. Give the two usages different names and correct types. Remove CTXDESC_CD_DWORDS as most usages were indexing or sizing an array of struct arm_smmu_cd. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 60 ++++++++++----------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 17 ++++-- 2 files changed, 41 insertions(+), 36 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 735dd9ff61890e..24c286a0834445 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1170,7 +1170,7 @@ static void arm_smmu_sync_cd(struct arm_smmu_master *master, static int arm_smmu_alloc_cd_leaf_table(struct arm_smmu_device *smmu, struct arm_smmu_l1_ctx_desc *l1_desc) { - size_t size = CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3); + size_t size = CTXDESC_L2_ENTRIES * sizeof(struct arm_smmu_cd); l1_desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, &l1_desc->l2ptr_dma, GFP_KERNEL); @@ -1198,12 +1198,11 @@ struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, struct arm_smmu_l1_ctx_desc *l1_desc; struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; - if (!cd_table->cdtab) + if (!arm_smmu_cdtab_allocated(cd_table)) return NULL; if (cd_table->s1fmt == STRTAB_STE_0_S1FMT_LINEAR) - return (struct arm_smmu_cd *)(cd_table->cdtab + - ssid * CTXDESC_CD_DWORDS); + return &cd_table->cdtab.linear[ssid]; l1_desc = &cd_table->l1_desc[ssid / CTXDESC_L2_ENTRIES]; if (!l1_desc->l2ptr) @@ -1220,7 +1219,7 @@ struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, might_sleep(); iommu_group_mutex_assert(master->dev); - if (!cd_table->cdtab) { + if (!arm_smmu_cdtab_allocated(cd_table)) { if (arm_smmu_alloc_cd_tables(master)) return NULL; } @@ -1236,7 +1235,7 @@ struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, if (arm_smmu_alloc_cd_leaf_table(smmu, l1_desc)) return NULL; - l1ptr = cd_table->cdtab + idx * CTXDESC_L1_DESC_DWORDS; + l1ptr = &cd_table->cdtab.l1_desc[idx]; arm_smmu_write_cd_l1_desc(l1ptr, l1_desc); /* An invalid L1CD can be cached */ arm_smmu_sync_cd(master, ssid, false); @@ -1342,7 +1341,7 @@ void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid) struct arm_smmu_cd target = {}; struct arm_smmu_cd *cdptr; - if (!master->cd_table.cdtab) + if (!arm_smmu_cdtab_allocated(&master->cd_table)) return; cdptr = arm_smmu_get_cd_ptr(master, ssid); if (WARN_ON(!cdptr)) @@ -1352,8 +1351,6 @@ void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid) static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) { - int ret; - size_t l1size; size_t max_contexts; struct arm_smmu_device *smmu = master->smmu; struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; @@ -1366,8 +1363,14 @@ 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); + cd_table->cdtab.linear = dmam_alloc_coherent( + smmu->dev, max_contexts * sizeof(struct arm_smmu_cd), + &cd_table->cdtab_dma, GFP_KERNEL); + if (!cd_table->cdtab.linear) + return -ENOMEM; } else { + size_t l1size; + cd_table->s1fmt = STRTAB_STE_0_S1FMT_64K_L2; cd_table->num_l1_ents = DIV_ROUND_UP(max_contexts, CTXDESC_L2_ENTRIES); @@ -1379,24 +1382,15 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) return -ENOMEM; l1size = cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); + cd_table->cdtab.l1_desc = dmam_alloc_coherent( + smmu->dev, l1size, &cd_table->cdtab_dma, GFP_KERNEL); + if (!cd_table->cdtab.l1_desc) { + devm_kfree(smmu->dev, cd_table->l1_desc); + cd_table->l1_desc = NULL; + return -ENOMEM; + } } - - cd_table->cdtab = dmam_alloc_coherent(smmu->dev, l1size, &cd_table->cdtab_dma, - GFP_KERNEL); - if (!cd_table->cdtab) { - dev_warn(smmu->dev, "failed to allocate context descriptor\n"); - ret = -ENOMEM; - goto err_free_l1; - } - return 0; - -err_free_l1: - if (cd_table->l1_desc) { - devm_kfree(smmu->dev, cd_table->l1_desc); - cd_table->l1_desc = NULL; - } - return ret; } static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) @@ -1407,7 +1401,7 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; if (cd_table->l1_desc) { - size = CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3); + size = CTXDESC_L2_ENTRIES * sizeof(struct arm_smmu_cd); for (i = 0; i < cd_table->num_l1_ents; i++) { if (!cd_table->l1_desc[i].l2ptr) @@ -1421,13 +1415,17 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) cd_table->l1_desc = NULL; l1size = cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); + dmam_free_coherent(smmu->dev, l1size, cd_table->cdtab.l1_desc, + cd_table->cdtab_dma); } else { - l1size = cd_table->num_l1_ents * (CTXDESC_CD_DWORDS << 3); + dmam_free_coherent(smmu->dev, + cd_table->num_l1_ents * + sizeof(struct arm_smmu_cd), + cd_table->cdtab.linear, cd_table->cdtab_dma); } - dmam_free_coherent(smmu->dev, l1size, cd_table->cdtab, cd_table->cdtab_dma); cd_table->cdtab_dma = 0; - cd_table->cdtab = NULL; + cd_table->cdtab.linear = NULL; } bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd) @@ -2955,7 +2953,7 @@ static void arm_smmu_release_device(struct device *dev) arm_smmu_disable_pasid(master); arm_smmu_remove_master(master); - if (master->cd_table.cdtab) + if (arm_smmu_cdtab_allocated(&master->cd_table)) arm_smmu_free_cd_tables(master); kfree(master); } 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 280a04bfb7230c..21c1acf34dd29c 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -279,10 +279,8 @@ struct arm_smmu_ste { #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]; }; #define CTXDESC_CD_0_TCR_T0SZ GENMASK_ULL(5, 0) @@ -312,7 +310,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 @@ -593,7 +591,10 @@ struct arm_smmu_l1_ctx_desc { }; struct arm_smmu_ctx_desc_cfg { - __le64 *cdtab; + union { + struct arm_smmu_cd *linear; + __le64 *l1_desc; + } cdtab; dma_addr_t cdtab_dma; struct arm_smmu_l1_ctx_desc *l1_desc; unsigned int num_l1_ents; @@ -602,6 +603,12 @@ struct arm_smmu_ctx_desc_cfg { u8 s1cdmax; }; +static inline bool +arm_smmu_cdtab_allocated(struct arm_smmu_ctx_desc_cfg *cd_table) +{ + return cd_table->cdtab.linear; +} + struct arm_smmu_s2_cfg { u16 vmid; }; From patchwork Mon Jun 3 22:31:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684459 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 35AA3C25B75 for ; Mon, 3 Jun 2024 22:47: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=iRF5StIhm0uznKQLhNR1wag0NP1dZfH7Oom6LUgcaag=; b=THH+2UXo3nC9Jn LbI5ZTnpSJFliQloIo9m4zz0Rkk2enlFqjUtlFcfOFp0xuiVYWJhjiw0SlZThDoZdgnVpX+7AC8dL u2MoV0DBp1tW7TwnoNWfc7MFhKkFVzGEAI4UDrXe3eEWKPqF3DwySWrnFFwIIN3nU1HXsCKzzdaNK F2uHSdZQtNwC27N2pYB2XyzMg6Ww2mlscPUCL2fHw1Vb4njYb7H+wZs4WV8DbEaPI57QAhUZ2aB4c A4A34Xi6ca0YCmudJisVBz/Qc5MOkssRqLMpVjR2RCUrLEtKymlVKIQjXhhvAzIedFND7qj1Vw8VO jvIWntZs8XLXFRPgZUXg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEGSJ-00000000Xmr-1KlW; Mon, 03 Jun 2024 22:47:07 +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 1sEGSB-00000000XiX-17Me for linux-arm-kernel@lists.infradead.org; Mon, 03 Jun 2024 22:47:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hfv+d0bC3SPVVcgH+71XCOF5DFzffxJKNTznWIcqUqX6abmYic6imbyi6kYWK257p+6/0/7OeKJOVg2hh87wVLqat0YuNvOncsJIEEkTYauq4FXABsy/6SSTD8UmlQt3H4PBIrrxI7SarWbZBdFAnrVUH2W8umIN9kyqpZt/Oar92JWlaJ5mligBKnBSE9Rp/02nJYFYD2bQkuMSYmIJLZ77uuIA+BzXMYCxaUht9qGHNqF8RPuTuF/jMq6aQrZKmAkGhUUPNIgvRpu0YszO9NGIiTOfaJUODX7NGHyc7Hyw5gOcQKyLT/HXu79rE1zxIqh8Q4xvQ74cFT4OQR9CKQ== 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=VXzG4GbzcN3hQJDnSoUtJkUFnOerBqj6wHti26PymiY=; b=MiYtOg6sglAsm5k2Kfy+4kRGMkBSdlWg17bHsImrbc2lnxNGV3dxI4hY8vlL03x2iMNG7uNDdVWTpjgUrTLbrAolGr1Rx8CFAJzOeubR6+6v5GqJc+knYyCJ8zYoNnz2kuRhDux+Km2+yQUDjNHkYPMFAyFvhT01m6CEuc5CIhzMhlRiesP7kkEu8Sjs8DtzIyr3iLOiObxRLcI/Ze8jDst5o4U0iSHarfs38bVXj2AyGlfSrSE2CSqVLw0GOJMU/CBqqG1ChQrTrA0Fqt26kLz1whpFBq6JXRdZYg6/M+3pg51efEuQDINLs/6mGvoPqahp+XwBGyKRUrqb/ZbA9g== 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=VXzG4GbzcN3hQJDnSoUtJkUFnOerBqj6wHti26PymiY=; b=VVoSKVQOqXlO710kWS4nXWnJyG70pGsqE78hFTcq69rdpRqbPug20Fvw6PGo8V3fNelMXJxWj8BpUv/7QaYU1w3g4qD+Tqbyu5UgQ6GLyvK92YIf7YIZiY84gNo4EjZVTns01ZiS6edKgiUf1hzocxWz+NdxZoPYztRAalm9wFsK7z5m+p0R+3ONlZkL3y06uwQBWWO1dAzcE7VYiAuhfxk8fji/7pdYNQBZKtonf3ztG5YAlD0cwAmSkAOkisylnV5qnNibdjdEFRcC2VNHiIXoA2rQxM7gzhOK/39BfVNs0ev521EKgkYbIEmyHElWIuyJmS2V6YvS51OOupWI+w== 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 5/7] iommu/arm-smmu-v3: Do not use devm for the cd table allocations Date: Mon, 3 Jun 2024 19:31:31 -0300 Message-ID: <5-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BLAP220CA0017.NAMP220.PROD.OUTLOOK.COM (2603:10b6:208:32c::22) 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: 4e94d408-43ac-45ec-6c42-08dc841ced14 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: vC1wVQeIm0jkNte/iL4QZwO0YoKrXZWvhU3QTHlf+r9W0dTdl8jCxNTrAtDHGQM6L96Dj9IISmMhMDxgYq52B8JOtJL9zllZYRxbGBxPRVHOxzJ6cAGYuMN49yaExImMsldX50USFKyJWjdhMEFTtd5IL342GiqcegIINmjXVMSvE623btPdMWEOQtlmCv69oI/Ch6pwaf8MoQ/zUFNlNDrV95fB5N/L/VwpnVLz5xA22DVaF3g+bG4a/MyISRLWiY6hyjBPCTgy+ltL7gIEDN8yAD2kmPSir03Qsfzbyym+WrGM6TiFLx0m9CGu0sW6sqFc4KnVvQRmC/cDP/hH8PThd3LpjtnIxQaAz/qseprDGPt0cGTHXICIvDlXzqBF2qffGjlOBd3yB7BZIslvQ7JDAXlmq2Z5zb7MAjDTxO5nGgU4NXth2EqO4bEhzSA87LaHPIQPkvUjOHHPAh+NLxan4p8rQwXFEB7ZGrK6udPwu2UmeGgk1su8+6GKxkEvx4iRdDDsOUk4Rl2mRgjLrrjATKm0C0vCt6nF9OAXOQDKHvkIcLGbRrIlahh0wC7bnlIGkg413VVlvyhpjqeCoT/OWydW195XJp1HjU3GZ9OAWFJCz7vGruvWPajcV9ViUP2zPsgCryEHWK4VKnADxfIl4gSdaNrFFd5rgTVAKQ9u2ddKwqMEumWkkNzYqFkfThmSx9rHxb5SKMD/gBsKcYuwf8aFD8nuXS5cOReiTzKgus92k6CHmUL+pngOEsULFNbfMYzWO0wV2sE72A9zOD+2TGF2arAxfi1i1QnTPkw3ffnH+lY1TEJEZkCpeJ8SBaTZ7RaG4oubry012zH4FiveZs92aLOVfb2jTnv1Q3eVaFUEfU8Smm11DCOExdZU8ifzK/y5fnHFF+VRb/7ylY6AP0Lm0KRrdAWN7jnqOcqwphOazTsK9DhVGqys8T/qGePd8Y7oMyMD1Pikv2JucyOSvBhOlPCh5bgLF+YrHjO6WS9CyefbFhIDir7sUcZ0OUembXYqbQ6LpdQmRm1hIP6iFzFAAqHHuPSp3anfnh4dplPxkjXbtHMt98aKcu4rUD6wcuZvK+iblPrHs5ckcfEO0svwRGNHn1UBHqZIrY5BCcLXF6nWeDyCXr2fjd177eKmg5DPGwu6lEFTffGE+LAFCc+2WwpHRrPaQmx/wZuTtWctfXRJPrHOINrAWbisIIattQMVHlbrmYjwQLF29AX//swUrYO+JRE/2Y3oXjPOR5F6lX9y2lxiu1nD5br3N+UiQt6W48lOnZGnYKAI4A== 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: V8XWFM5xVe60TpkkUQdMfRqdKXHizymiB/guzzzkLDfisYQ8aF7hlBT8Uh26+ORhgJT++2SGWMU5IVCdrJwLfhsILZL/pLBDzWVlcqpEIzcK61Yn0KISURxxCm+iIxCksLdXF2HOz6z9oLQMqSqqG6SvhJ3kPIXqA7zwAxcBN77V4Pt50H9Yy8URvcZL6g+//z6DDC7IQZdN3jXTTi2fYT0Am3l3N3JBRSRU0pcsPzD9UGX26MblVne/i+9fvvG/A1peJxtI5JlBWe3eDIlUmB/9y2IsCEB3iqJFmfxDOe43rbMl34t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2WHkVB4Iz+h2AC80gJ4+LTGzIJc905tV5/5vOtc4A3wDTUwU4n+9Sjnh1iA55E6adwoqUjl3qL5sFgFMlmFs3bREnrxiIhniVBEPA2G011Izzh50Qo9CrObImPmH/EHYvnvbucfgvSNVVjZINyVtc3XEdlH5FtVMT4Fv1FuYqxb5yXbwwrpvX7KoVmrpbA= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e94d408-43ac-45ec-6c42-08dc841ced14 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:35.2416 (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: adZ7OomD5St+9LnnZSH3KZaTsRN3SagV/TPoWSqz2ySpJvKQ3N0Xzvz/8KUTI+7i X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6778 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_154659_426253_8C24C3F1 X-CRM114-Status: GOOD ( 10.00 ) 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 The master->cd_table is entirely contained within the struct arm_smmu_master which is guaranteed to be freed by the core code under arm_smmu_release_device(). There is no reason to use devm here, arm_smmu_free_cd_tables() is reliably called to free the CD related memory. Remove it and save some memory. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 45 +++++++++------------ 1 file changed, 19 insertions(+), 26 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 24c286a0834445..3f2e0462433d2d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1172,13 +1172,10 @@ static int arm_smmu_alloc_cd_leaf_table(struct arm_smmu_device *smmu, { size_t size = CTXDESC_L2_ENTRIES * sizeof(struct arm_smmu_cd); - l1_desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, - &l1_desc->l2ptr_dma, GFP_KERNEL); - if (!l1_desc->l2ptr) { - dev_warn(smmu->dev, - "failed to allocate context descriptor table\n"); + l1_desc->l2ptr = dma_alloc_coherent(smmu->dev, size, + &l1_desc->l2ptr_dma, GFP_KERNEL); + if (!l1_desc->l2ptr) return -ENOMEM; - } return 0; } @@ -1363,7 +1360,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; - cd_table->cdtab.linear = dmam_alloc_coherent( + cd_table->cdtab.linear = dma_alloc_coherent( smmu->dev, max_contexts * sizeof(struct arm_smmu_cd), &cd_table->cdtab_dma, GFP_KERNEL); if (!cd_table->cdtab.linear) @@ -1375,17 +1372,17 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) cd_table->num_l1_ents = DIV_ROUND_UP(max_contexts, CTXDESC_L2_ENTRIES); - cd_table->l1_desc = devm_kcalloc(smmu->dev, cd_table->num_l1_ents, - sizeof(*cd_table->l1_desc), - GFP_KERNEL); + cd_table->l1_desc = kcalloc(cd_table->num_l1_ents, + sizeof(*cd_table->l1_desc), + GFP_KERNEL); if (!cd_table->l1_desc) return -ENOMEM; l1size = cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); - cd_table->cdtab.l1_desc = dmam_alloc_coherent( + cd_table->cdtab.l1_desc = dma_alloc_coherent( smmu->dev, l1size, &cd_table->cdtab_dma, GFP_KERNEL); if (!cd_table->cdtab.l1_desc) { - devm_kfree(smmu->dev, cd_table->l1_desc); + kfree(cd_table->l1_desc); cd_table->l1_desc = NULL; return -ENOMEM; } @@ -1407,25 +1404,21 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) if (!cd_table->l1_desc[i].l2ptr) continue; - dmam_free_coherent(smmu->dev, size, - cd_table->l1_desc[i].l2ptr, - cd_table->l1_desc[i].l2ptr_dma); + dma_free_coherent(smmu->dev, size, + cd_table->l1_desc[i].l2ptr, + cd_table->l1_desc[i].l2ptr_dma); } - devm_kfree(smmu->dev, cd_table->l1_desc); - cd_table->l1_desc = NULL; + kfree(cd_table->l1_desc); l1size = cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); - dmam_free_coherent(smmu->dev, l1size, cd_table->cdtab.l1_desc, - cd_table->cdtab_dma); + dma_free_coherent(smmu->dev, l1size, cd_table->cdtab.l1_desc, + cd_table->cdtab_dma); } else { - dmam_free_coherent(smmu->dev, - cd_table->num_l1_ents * - sizeof(struct arm_smmu_cd), - cd_table->cdtab.linear, cd_table->cdtab_dma); + dma_free_coherent(smmu->dev, + cd_table->num_l1_ents * + sizeof(struct arm_smmu_cd), + cd_table->cdtab.linear, cd_table->cdtab_dma); } - - cd_table->cdtab_dma = 0; - cd_table->cdtab.linear = NULL; } bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd) From patchwork Mon Jun 3 22:31:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684460 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 B1553C25B75 for ; Mon, 3 Jun 2024 22:47:52 +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=AjwXwVQA0oDNk/XtD32tYNfsyWfxbtH8U4MJUpp3ERs=; b=D6iQ0L1/qCTimr pj4trKjF3zgrnRiuD7Z31j2MU9LbZSn0e6GT+/Xwo/slZ7w15dwog2akk5f+j4LDzKQhfEI4i4nDe YlpEjJ3YWOvNgCYIGHN7SdBIzn05mkPpQ3F8hf8vbsHzG1LuPLIKaCXjp+U/3FC57yEdnZpb1WZvW m73to5ZrHzlKhkDCJnC3jHThN0j1ZctRdb3jJ1oHxd1bTIuQjDIV7P+X8y2Y8kVbE6vPKm/P6H2mQ 0F9afRmHcJJw13sLR4rDoK8q8PzaLw0BnRsta0iJfqRQ1Y4m9R6s1MA3z0A+5XpE4LS+VRg3+F8ED vXjZfIdr1MT4haoeVShg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEGSs-00000000Y2b-14tg; Mon, 03 Jun 2024 22:47:42 +0000 Received: from mail-bn8nam04on20601.outbound.protection.outlook.com ([2a01:111:f403:2408::601] helo=NAM04-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEGSp-00000000Y01-05WE for linux-arm-kernel@lists.infradead.org; Mon, 03 Jun 2024 22:47:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HvYdLiXofMsYz2n1/eQ21KdA1cTINSIyjootUsWGEUNE1Ss6YJQ41oNWI5vLF6RX6+Z1rdT6HpzjmePzxkTs8fDgeaF2XDwXELwZzP2ZuPxYyemFbcirzd0hWjclgnkbMgQuT4iKdxhtAaycTVDX1fJxtof2G3joIwfhMaYvqxEmhL/IdvX3HiriLaMetGaWT1qqRv4OzoAtcuECCbjQhi1GT5JlGUraVxQ6+0gzqU/xmKNQq7npfTbaVgEMIr04xp2XedU5vtkc02Y41v1A7/Js/N2N+9z1CotfeOGQGdIVjXL6xmhUr9mFDnrSY4tAljesSEIQ+SHMseds97hMTg== 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=qCVi2xl8orchsUFQicYXMk+Odlf8xzCNbGmii+6RcZY=; b=TdOXjZ8SFexy7L9lJQgSS4QBtZVSHXDLB6SE5NeQTEy5u2mj/zbW9YYLyxOvhkE4ZYLJU19J9c8ioRu1rxoc0vmEYGcICVIcAC19j2pDa4OO0/NZe7iZLYlFpkgHDwo/H3KPVm0OdQZAMScsDfD2/xxA8IEcc6qfvcmlUmGUbVlDBUYF9LhE7tkj/QImIXUsXWE2eOYzAcGxQF828oWq6tekaXGbqV2sWwSupzrOESKgWTOHZ1w/iNoiobGDNDL6dMpITYxNBj9EFkGQB///J44PHq/sBi8pe5UjD32uR1Y2GADDOqO4qSi2S+3ENQGBcJlnA6DQHdJMECG79RoQjA== 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=qCVi2xl8orchsUFQicYXMk+Odlf8xzCNbGmii+6RcZY=; b=qitLtzbtasCVYEyHTWDNJcsGTTYsZiU1cgIMxC8iUisnTjGHpSOSYNdt9PKld572si+RnYA6YLYFNyBd7yBQjY/nUOoTdshSz3V+WjyO9stg2vLkCjDoZNZIOV31paCao3M2dNxnKJikmoIwZyayKpXOxseyMk69zWrVMEeSLUpcwkAs9h55P1gTuCqyZHs+5JW/H5H1J71/DnKLrR5MYtQqP4JdsIV+r6m1tfzv4n1KkxEdKuyjESCIZrH0f2Ei65i6IIoyBsaTNc3b1C3KDHhQ/7Q+Ig3ocyp0p/0NBq7S6m75KNrcw1oqSl810R9N3fbSkSq34wtXmEiiQZ6Vzg== 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:38 +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:38 +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 6/7] iommu/arm-smmu-v3: Shrink the cdtab l1_desc array Date: Mon, 3 Jun 2024 19:31:32 -0300 Message-ID: <6-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BLAP220CA0006.NAMP220.PROD.OUTLOOK.COM (2603:10b6:208:32c::11) 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: ac9e383d-4050-4538-8157-08dc841cee0f 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: ExMqfyACUcLJhoY41mw0itTSV3C7NpF2WXjeHYIAlpMmA7VPbrOnAfiudI2rOzOKYHjPl1p5sKwCBRzF9w5e5+zLZWzemnm/+xfVO1EoTWx8MhOe+DCGUnDxqNtbzLNS8SwS/sVnokf9p+5HcYWVjdA+Au/5lFYWMTby3I+vSqIxwGFTzkgDgTH/yw4Z+uZ/WVA/WATMPHkvW5M1DQlCj151PbtD19zQ7qCM9E+AECbVBusvGqWdSY7GMqn6BYvDIOqG1QHqXVeJAzb4D+pbNRGsL0o28hcZmFRv1yBQJPIqYabvBxX88PrwxW4DrFcOvrK6CuDkHobBsP9vBwSlud4Kk2c9RccxHB2m3SKf5lkAtbWev+wlFqRaIQPu02ybEI0471BMPABuSEoZkT6Pvkg+a2BZk74wSMzhziTVdKDfTcjoiBgR3Q5AAHXBmQsWper3qC34OYr3tFiWdsCvzUW3VShzTzVTE0ZRaxEtd42N0WJVN/PBhg+B5C7KBnZ3Cju6vbIl5MZYZVX3g++ectfXkH8cxI8MfCeC20RIvzAFWqlzuP8G4t7mAHjSrYh135qLqMOiL3sDtRyo67zCc/g51dTvkGExJiNCcDwm7L/Oi6FXe2FjXEu7iIvbhMdJwYpTX9x+mlV7+YLa8Mg6WxJtpPurFrABsXluBxwRdFybkNoOZ/qn5hBQE9n1lrPhTgvY5bCTh3T1p0kRZGfIztzeXjF0wIuyJyIqq+iinQ97R1rWoWx+xMZ8xbxMR617X0+v6rN/oRrojIyRvAl+KQ8TkeskSjC7FHNcjVjfec144dTANPkEKXWb9OvcyMlTZdFvWAJe/+QyY5cG7qcKKua/F19tzRLfEzeCzkmu95Xuapf4mNfYD+RSwiVNS8Sse/GBUrmfXk+TuCJ/EYAtmip9ZS1K4hZVgSYcKQJm+8ZYH2U4sb5ga+cmIRHVFyKV/6jwjWXVkthvMbWBOevL4nwD0p2+wEt3Bjj1zpogBc951+knGQkWxM2cU+EvzEat8FXVeqjMB1fkedA6fBBNhu8Y3i+8xdZlB0rQZzPP1dSJlI9wNR82h+AlgP1TOglD0lIqmU8jWaBuBM9QUOOwvdNDmigFZEric9PNA8zg5Fk3LYAy51buTurlQiNc2tU8PgB9ctZUsh3CuOpOxggRFHPCJkNd6UsgFea6rnCxTOXsfBiXbURr+g9x4wXW8D16Rbi6J5toq7twPOER6fIWFTZZRWV79+CQz6F60uk9Yfp6IYSd7zeW3qvKKaW496inlljYRYoH/bHExMtw81sqCA== 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: ZgJGoIXMzvWVur9FpJdGlLU9jHCt5SeFD0wdmkCxAVuIq/ribsFNbomIynRBdqfIFfAK6/iSOcQMok4vAaCP3rxwJ7OQnGBf3/x715wFDxwWVT/xy0Pf5cnTEg1FjMFM+ZVhVH+Ysq/GQ0ynX8pBh9DzqPA1iwCm5Gi4HEDz516tfbLvR8SCgTJY3swBUatQdIuiKO/4uu/nzznLu2bfowoBbi//gbmK2Cl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YI2pmRqy0q+JpQc1GHX1eMoiq1wAfRdS8q0D/mslZKL0HIPnIZucIZmilzzTuzd0R4K0bt107y9FbEfca8ZVVVSuz5AfnRzXH+MzrAUKOqXP0X8g59gtR4lqaT50ROQZCSLTeBX4vWoQ/TKS3HaaOU07LXprftT4c5J4olOROmXxOHu5AxQ3y1jBOYt44GTa4SOBr8+WEKROj71Smb/aSWq8jUGCZNPwLg7g9f3uC4/7c00gqsC1uD+Sb+MiLdaz1iGrYUK2BWtbzocPYtek53Y= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac9e383d-4050-4538-8157-08dc841cee0f 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.8964 (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: z3DdrKnlzJdbuzzyWEI422Uj4XEFHDfTnxJU5eG15Jh8edA6Lj4Xwiayt7IKJXrL X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6778 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_154739_107246_6DB94DD6 X-CRM114-Status: GOOD ( 13.39 ) 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 The top of the 2 level CD table is (at most) 1024 entries big, and two high order allocations are required. One of __le64 which is programmed into the HW (8k) and one of struct arm_smmu_l1_ctx_desc which holds the CPU pointer (16k). There are two copies of the l2ptr_dma, one is stored in the struct arm_smmu_l1_ctx_desc, and another is encoded in the __le64 for the HW to use. Instead of storing two copies just decode the value from the __le64. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 35 ++++++++++----------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 - 2 files changed, 16 insertions(+), 20 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 3f2e0462433d2d..7a6c9aac4cd450 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1167,28 +1167,19 @@ static void arm_smmu_sync_cd(struct arm_smmu_master *master, arm_smmu_cmdq_batch_submit(smmu, &cmds); } -static int arm_smmu_alloc_cd_leaf_table(struct arm_smmu_device *smmu, - struct arm_smmu_l1_ctx_desc *l1_desc) +static void arm_smmu_write_cd_l1_desc(__le64 *dst, dma_addr_t l2ptr_dma) { - size_t size = CTXDESC_L2_ENTRIES * sizeof(struct arm_smmu_cd); - - l1_desc->l2ptr = dma_alloc_coherent(smmu->dev, size, - &l1_desc->l2ptr_dma, GFP_KERNEL); - if (!l1_desc->l2ptr) - return -ENOMEM; - return 0; -} - -static void arm_smmu_write_cd_l1_desc(__le64 *dst, - struct arm_smmu_l1_ctx_desc *l1_desc) -{ - u64 val = (l1_desc->l2ptr_dma & CTXDESC_L1_DESC_L2PTR_MASK) | - CTXDESC_L1_DESC_V; + 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)); } +static dma_addr_t arm_smmu_cd_l1_get_desc(__le64 *src) +{ + return le64_to_cpu(*src) & CTXDESC_L1_DESC_L2PTR_MASK; +} + struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid) { @@ -1227,13 +1218,18 @@ struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, l1_desc = &cd_table->l1_desc[idx]; if (!l1_desc->l2ptr) { + dma_addr_t l2ptr_dma; __le64 *l1ptr; - if (arm_smmu_alloc_cd_leaf_table(smmu, l1_desc)) + l1_desc->l2ptr = dma_alloc_coherent( + smmu->dev, + CTXDESC_L2_ENTRIES * sizeof(struct arm_smmu_cd), + &l2ptr_dma, GFP_KERNEL); + if (!l1_desc->l2ptr) return NULL; l1ptr = &cd_table->cdtab.l1_desc[idx]; - arm_smmu_write_cd_l1_desc(l1ptr, l1_desc); + arm_smmu_write_cd_l1_desc(l1ptr, l2ptr_dma); /* An invalid L1CD can be cached */ arm_smmu_sync_cd(master, ssid, false); } @@ -1406,7 +1402,8 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) dma_free_coherent(smmu->dev, size, cd_table->l1_desc[i].l2ptr, - cd_table->l1_desc[i].l2ptr_dma); + arm_smmu_cd_l1_get_desc( + &cd_table->cdtab.l1_desc[i])); } kfree(cd_table->l1_desc); 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 21c1acf34dd29c..1ffe2fdfd3755f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -587,7 +587,6 @@ struct arm_smmu_ctx_desc { struct arm_smmu_l1_ctx_desc { struct arm_smmu_cd *l2ptr; - dma_addr_t l2ptr_dma; }; struct arm_smmu_ctx_desc_cfg { From patchwork Mon Jun 3 22:31:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684418 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 4250BC25B75 for ; Mon, 3 Jun 2024 22:32:05 +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=w/qrpj9DMbK5LPcX4M1LZAbs44K1n13zUk6itBXxNf4=; b=gyx9aPue0ylt5c c9ncokEIqVqEyvTq4geqtY4f/C2rj1idVkTztUxHxmBldb2CR7pFR0gMLV7BufhGTVoiVNs3fjslb bO9AnOxFNrLb8WtT+RgbFyu9awun/cKRDgDuv+t01jb4F0uExsQpIucEXhY2Qveoj1dkl0TPXl4pF hFMZxyywrTzJKKvadblV6sj9Q/S3eBwfQzmPz9kPA9mNyOc/Kq7Y22iz09KEdeeBbu9p09C/J3zY5 3cFX8BA7RO3qKS8ikwhjpVN/Q71Xu9l79akWxxh46fo9VJux8IUsyxTPgr2hnXe0AHgVVuqM52S8w J1sET0MBrwa2slAxeBnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEGDW-00000000Uf3-0jgB; Mon, 03 Jun 2024 22:31:50 +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 1sEGDT-00000000UcR-1KMT for linux-arm-kernel@lists.infradead.org; Mon, 03 Jun 2024 22:31:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h6S+JxHzqxhnNC2qeKQESGnQAfnH0XZ1z5y0LDatQwQICPIZm3jRSreqgsjQOpFK+bVavUzlQMweiV6FWmhbcNDq2CA7ane+0hETaeQilfXdodGiZi8U8pcesaWQYdAhaqI9LBjFuioxd7oD3e/MSYondnHgKEmAm9tl+kPoCKSwdGqOXI7uwxS45g0RcXzQPApED1f+1GED7vaiB8wZ+ZYAtR+NJ2YZYTACImd3g4kgGA+5mS68YTw3CJOfWofp1y9EiLYVRm80pqX1qQMQ8Hzm+5bQQw704wH1bUSEuT7r7I3UBEBF2XW9JkMAY57Tjh5EnTj06GuVGofPFuSJhw== 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=OnrP9TZNj45KWCa25TlWJpeIbyGKykmf/Au/wIHgTFI=; b=WdEBQ7svoBlPY7YFJ0PzT79U/KZ02LH4BENEvL6E7dp5A6A+eOxAx/Cv8jXtJDafw9CLV5Ae4OhPKXEHsn4sH5omC/Rtycl5tkCQl/EzZFt5DoZfvScK1Or0nYS6bMyBVN4AokJcjzOixU3OTJF88hftQDEIIsygXV/zuQKAye/huoOfK6Y5FGncVsGY1NMuEntqM63deP1SzsbVyIiuhcrY6hILvxhbemDz2/aZHTgZYqaE19bsDoHHmjv77CtoJ+fDdCUQMCTHP4yHeiCBE2qRv/LA1E2HuctlPKBKOvHOos5ZhGxJGBMYCYaeayEl1MHqjJB5ydvaFCgA3dUI2g== 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=OnrP9TZNj45KWCa25TlWJpeIbyGKykmf/Au/wIHgTFI=; b=f5wnNlSK5+tte1kDNIVxQ5nZ25REYk49B0XUqQFyQ9QkqcpzJxz7r7HjJJTTPHpJIYXYC4TFywLfC6aSJQLa5fbFnDgd00q13rmo7VuLu2GGmvaf9CL2pPwhi+zQn+PAakTuZulNUmfdjXYVjpPfmn62pAhQlfexmvWxts+257gmk+yMdApazWin/asv0cJQNdsGVuir62f1C9SE9wrQVv9YwfB1KoRPLbe7IHpzP9zOM03pDlkeAGBnYtXP8jcyi4ddhz6fL/zb0ofY6QtlsbjvaoZtpa7aiQePJ0QQQc24sJm1VkWWKw4K6PBpg6gG1JTHNd8HsoNCYsQKwkvXkA== 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:36 +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:36 +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 7/7] iommu/arm-smmu-v3: Use the new rb tree helpers Date: Mon, 3 Jun 2024 19:31:33 -0300 Message-ID: <7-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR19CA0017.namprd19.prod.outlook.com (2603:10b6:208:178::30) 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: 25431cc5-bbc9-49f8-dd24-08dc841cece7 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: GqHpijjXRAF8e7oPGbQOCTc8SgGfImMrIe09tt4R3d9epmOj9IQ6Ds0Jym8If5uPZ2H03+yxmVASKxBXfeWFUplG+OvlLVE6Zsewmrsr+AoPJ72iSM0oSzcBXys4wrqkIKgRVoTDYXuRNsKUYS9wptM2nNlfFKtbjLlsZl7zvxK8+njA1gLEDI5ANEnAal4loN1YQcM9car4I3A2sIjT2lFjlE3YgtG2zaHnDZKCD2bz8qVD0eDRVRb1fZv7I6BJv3fVrq29giBm9mppoP3y/KWr9Sh6oY9KmS41KAzb3Ug0dRdoTZ2p/6CbzinhpFiJqKUtIm3vrVohXsq4y7SH2Iasn6anXbTfA1U7eF/DXK071Nm5aA7//gcsQW2qJf3ZLH/Hr0w3BRJVuch02tXI/BfAz2nqAI0j/1B3/XtL+GJy8hX9nafylPstGRFu38HIQNhp/ivWu/tMlUsFoYrycfRa9o4cvbDs5xJtZrNuO4tJFjd8QrQfvGA3Ttt+6KIbdcm4pqkw7Gbru+nuA5ioL14ebSCMLKCUUx2EbbWuUyxJbcp69aNm7eUavpsNZxSGHsHh4srlzOh+LCJrtoDKVPSIdgphm2pRT7yZ2Euya4d8ifpEDaHNQccOmP3nj6cqDs0IvN1lUYNFLeOQ1BlHjslEJsSYDkvxX4Yx8w0/jkbG0h2yzBPNB+kb9LjMKaS6Y2Emm9hsr2RqyB+QHufjCxMVyR0dMSLZFCQ55kfz5nSrwdMaKOM3zZ/VEvyqgKmYQeHYJtk2N6dgECejlwHA7R/rPsEaamB2E0QCBkqZyOsukNT7vTOG2bAB4D5aymu0Ar0Fg2yTkSIkt2zy5YRKx9akZDqOgGrU8M4E5ZjM83DEDv4LffmzcjpIvPtbLV7RA4UjyJvZeJEoyvJZZ4S/NlOj3MjrU3WCkSgQ1NQ2dxZKOX3646D079WUvwntTMCZn4a0iUq3/ak/8HKjwDsfmZ11Ch7+kGuY1l7d7er1cmEYyU25HOU1LUnpo0n7oYQ4Tfj+aLt25ArYEfGF8SHnvrT/2YSEWkDC3b0IjBtpafjhhsXXQKPgvXzYq5nUkRKZinUg3OFBQEcZkHXiPWYySVpQVtmIaDF1eaTTpdOb07WLfGVLQnnEM1Yu34K7H2uB8hTruGT89sOZovEGM476x+vsvp4lCCgljqglhoBUmNe3296uMlfR6i5abSOTp0PExnl69ojSwrecYIezvQfoeaz8fOcBj92L1/GrQsp+WYIoWUfAy65wP8IabbYbiUMHS9KVloRKYBC1r+UmZNAD4g== 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: ectm4WMu4svWuY8uCpJkU6Rdz+C0U4qs8peWN5xJX+1LLO8XWbxLsxusuBfs9WvXSiOmqIuFNhXH2gYWWiVav+JGfBf0iykCBnOlI79NYgunON9UtDyUvwQme43Ro0X3BtjBFszQaRrXViZWg6TBg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8X0dXm7hQYqDVRndJi/pt8SNPW/i/9ktHIdcLudNv7Rd8toRfftYylZPc+wouYaEYDdxVdOTM7THqrAr6sfXN1qt6oLvXzA+npG+SneT76mKFcM/qHn+qpLjjR2BHJDI5IJg/SRCrZRFi5eNVm9pNrchzB5tmTsr2yPCaOjzNfLYS+HfV3q4J3U6Nu/ihDvfkCqvcPmbPzSGze75WVzIujzkTHa2KtlV3WoHOo1gqPX3dDuEfF6aqrS+Fr04nqeNoYjIjOWCEh+OvAAx0tomfR7BSIrDpUBnCSw1RsAm0TEXQFopg2GAS1m1v7goN+hxzduqYz8rZi5Hpntaw0ml/U= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 25431cc5-bbc9-49f8-dd24-08dc841cece7 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:34.9784 (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: juI/f0KTn+EYg3LHeCj34T+6+p0gZmkOaO1twWN414+viQxZsaAbHuTTR4uglotN X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6778 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_153147_376094_91784D9F X-CRM114-Status: GOOD ( 14.46 ) 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 Since v5.12 the rbtree has gained some simplifying helpers aimed at making rb tree users write less convoluted boiler plate code. Instead the caller provides a single comparison function and the helpers generate the prior open-coded stuff. Update smmu->streams to use rb_find_add() and rb_find(). Signed-off-by: Jason Gunthorpe Reviewed-by: Mostafa Saleh --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 68 ++++++++++----------- 1 file changed, 31 insertions(+), 37 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 7a6c9aac4cd450..25bae0b05a488c 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1667,26 +1667,37 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) return 0; } +static int arm_smmu_streams_cmp_key(const void *lhs, const struct rb_node *rhs) +{ + struct arm_smmu_stream *stream_rhs = + rb_entry(rhs, struct arm_smmu_stream, node); + const u32 *sid_lhs = lhs; + + if (*sid_lhs < stream_rhs->id) + return -1; + if (*sid_lhs > stream_rhs->id) + return 1; + return 0; +} + +static int arm_smmu_streams_cmp_node(struct rb_node *lhs, + const struct rb_node *rhs) +{ + return arm_smmu_streams_cmp_key( + &rb_entry(lhs, struct arm_smmu_stream, node)->id, rhs); +} + static struct arm_smmu_master * arm_smmu_find_master(struct arm_smmu_device *smmu, u32 sid) { struct rb_node *node; - struct arm_smmu_stream *stream; lockdep_assert_held(&smmu->streams_mutex); - node = smmu->streams.rb_node; - while (node) { - stream = rb_entry(node, struct arm_smmu_stream, node); - if (stream->id < sid) - node = node->rb_right; - else if (stream->id > sid) - node = node->rb_left; - else - return stream->master; - } - - return NULL; + node = rb_find(&sid, &smmu->streams, arm_smmu_streams_cmp_key); + if (!node) + return NULL; + return rb_entry(node, struct arm_smmu_stream, node)->master; } /* IRQ and event handlers */ @@ -2795,8 +2806,6 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu, { int i; int ret = 0; - struct arm_smmu_stream *new_stream, *cur_stream; - struct rb_node **new_node, *parent_node = NULL; struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(master->dev); master->streams = kcalloc(fwspec->num_ids, sizeof(*master->streams), @@ -2807,9 +2816,9 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu, mutex_lock(&smmu->streams_mutex); for (i = 0; i < fwspec->num_ids; i++) { + struct arm_smmu_stream *new_stream = &master->streams[i]; u32 sid = fwspec->ids[i]; - new_stream = &master->streams[i]; new_stream->id = sid; new_stream->master = master; @@ -2818,28 +2827,13 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu, break; /* Insert into SID tree */ - new_node = &(smmu->streams.rb_node); - while (*new_node) { - cur_stream = rb_entry(*new_node, struct arm_smmu_stream, - node); - parent_node = *new_node; - if (cur_stream->id > new_stream->id) { - new_node = &((*new_node)->rb_left); - } else if (cur_stream->id < new_stream->id) { - new_node = &((*new_node)->rb_right); - } else { - dev_warn(master->dev, - "stream %u already in tree\n", - cur_stream->id); - ret = -EINVAL; - break; - } - } - if (ret) + if (rb_find_add(&new_stream->node, &smmu->streams, + arm_smmu_streams_cmp_node)) { + dev_warn(master->dev, "stream %u already in tree\n", + sid); + ret = -EINVAL; break; - - rb_link_node(&new_stream->node, parent_node, new_node); - rb_insert_color(&new_stream->node, &smmu->streams); + } } if (ret) {