From patchwork Tue Aug 6 23:31:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755476 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 F042CC49EA1 for ; Tue, 6 Aug 2024 23:32:31 +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=prsWV50SKiIwgOQZkGv6ZIkbClrt2zSdiRSUQUzexYI=; b=FKZSSw0BpBjSz55Je2758nXpeF DUu0R0/TyjEdSkcS3EmJURgtePkKpykFpPQMSq/lH4VQO/CbNqqPwN21yX9jssc7coVDw0NBjQ7N8 0D18yEkaVc+48Bj8RHIFHNomb7OHulwzt/UsxlSk6T0PSSU5tydqBZbgbHoT62PE0aXL7c74q0YLe EWhITx6uNTpnU9QpmpQNr59xQXslzAq9wljs34PSAMz8U/ooBAun5n4J8mCwGxaicj9ZzCX7RldcR 6dMQopC/1UQsiJeIGvRl4zpPQyPkUUbAQV3h3ee1q+yiumpAUaln0K+RUVffTv8XWDAkLy3AQGPH/ noaK9hQQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTf9-00000003JnD-0Lmi; Tue, 06 Aug 2024 23:32:19 +0000 Received: from mail-dm3nam02on20601.outbound.protection.outlook.com ([2a01:111:f403:2405::601] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTea-00000003Jej-0Kla for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:31:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oDv8QBYvB9npyub9rpag1jaB8cIEIoD/L2RwQye7Osc+AEa+LFpEeOFY77OXF7uQWZVWqhSZaIRxGaY5tFZcNXe0bxfPMAXaHF59NeoGdckNPuBlCn0ycwmimp7z4A1a3cnaDoF1CiGjFHm+pMPog1zOHwxn1VBWik/Udm7e1bjLJnD2HitTwwCiRuSWuP2cWIig1o8eUuntlRTFwA9WQTwWyccnO+tffuOFBL9XpQAXXI819f63YMc+1kgA2Zt7YplRDjP9++na1arf76ceGdL4wHHm8uD3Yx7irRRewGm2lsUdUelfpJJs5JI8v0wXkP366fHfznAGvE4/AidhRQ== 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=prsWV50SKiIwgOQZkGv6ZIkbClrt2zSdiRSUQUzexYI=; b=SRBtkmdmilU7mmNol6/P5RvIu/mYcqPUd1kDRpRdCKaJPgFrYslcGMdQkCPu5OeEOnQdwp/1MXCl0vI6ReO71KVO/6bktiUwkFMu9GRu5q8gj1xY+x1dfsIRB9PXdYuAUpF4xaGTjMW/LlHHllmRBIr3rJz58IRmGnOA5GsgZo3emjdcBlzNYRHLXYxR73RXyBERLlTIoUbzakw2AGJoRrXD1Nkb8EI8S1XyXIEtTvUvDIwvLd1Qg+s+55cBIzgCGqMJbmbH83wv5Gjpu+uoztpXHVwyzbfrmEPgWRcvz7dVib2CpDYEim9HIrsnby64OAYC80rBa7pI2EJC0cqDzw== 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=prsWV50SKiIwgOQZkGv6ZIkbClrt2zSdiRSUQUzexYI=; b=lVewv+O6liAIMlipNmL2FmWN0dhyoKJNx0o79Yfjaft4vDvQKmdlAadZlRRgHE8+5Mv3rgrvIpYjCVn53CmxdjAvroOaImpbTjiCdn4CurWUAh6DyyHOs2GLEDDC9vHKfDxniRDXVGtwP+RjoAU0OGl3kGPTaeIR2dVAvZ8FV/UhNg3l6P7aMsTUJ1GX155wJCNz3a8WSgOWUOJg0+/OEhYY6hKk3/TD27aBJG3vSazXU7ZJq+tFn+NEu6MPOM7w8iyinI/tDIQI9IKkKyCLTzSPk7Xe3AseHWZovWcDVgEZ1250FU8iDYN7t0jNeLGgBnPIQEzjXLEnPKDEZVk5hA== 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 MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Tue, 6 Aug 2024 23:31:27 +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:25 +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 6/9] iommu/arm-smmu-v3: Do not use devm for the cd table allocations Date: Tue, 6 Aug 2024 20:31:20 -0300 Message-ID: <6-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BN9PR03CA0394.namprd03.prod.outlook.com (2603:10b6:408:111::9) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: 3995bef0-3dd3-4a1b-706b-08dcb66fe32b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014; X-Microsoft-Antispam-Message-Info: tE52CdduFYyFJABkDz3FK7vLLDshxsu+CO/dvRC0ETybEZHO+8SwDfmyrBc0axGkSHqIdxhC5Aezrz5yb6Syd7Dxxdoz1k88xCd9CTIhobDNa+lZFmxu5h8nPBRjwqj7AhtrhLelA37q82okModVJKpjW56/Qh19FUtO/HTRDuZSlqG4wOpzTnNUmyEJRUIb1A7vZ8n+mHfEjMmrrTSNO/LeNE9Z6dg3fEpMmffuJtlCgnAk7H/fTBrFjb2hoLzGiXyFMvdwoWekFgwCjGo2UHYiU2Fr4BlXNUNa6/hb0FkY7S1U3AqpixZSAamOGoG2h4Is3QwzcEMNT7QHI1IILBK6CdXVa/2pp03eJ6VvgvTkWIAyiXyYbtJSn5sAmAxqzhJzT8ZktrzH+ljPl1SMv3H/aY3P5D9j07h5hz43ZqRlB+CA0vFuCPjbbizRR3Eby8xga8WibfrR5jsLlI/bDjg9IVBq0KwVUyr/t6lZML6hurd8TzSS5xCTOffhx4RJQEbVjd658FxDzLL6WadEuPilC3kv73REKNL16dJ77Yj0RizRS3pa9BHLaLBzRaPZYfJ03vaa9jIzL3cF32zrWLgvjLFUPG1CHkvaGgIgrtcXq4kGKF1tC7YrPXwpx6VSRxDvxeGcUF5ENsl7FAOJDgic20/mwhJh8m8AltOCn9tFLlyjO8DwM7KGklKGPDAUvgfElTHbaEZVvrosaLMoZF573ZpgLyDlFknnxoNNW6o4/AlcM2TvPtW7pGcGsxrb/U3nk/l88RdIr+V802dP1xR2/mgKdhyfOy+rTDropaNvA6kQQKYNXX4608NQsRwKkYIoOYMPwaVZw9CQyvEBXvbDFNwkWrS3xnXKIcmZv1CLjXO/aFVzL9l9Th8n+iG+kst0IepE3u6x0PPRb/UYqk4MPNavVsYqV0JlwvpA84vckZMiZbewytJK3n2aautJvTVIO11a193+4tv6ZgOrJXoh+0YCkMgjMAQJMxLcCaVahb2P0wd4nuB4OXzbSZww3/A8e/Qr++3uQ/3Q7nsNEsQIYiOGaYgqCnj4qJv6eOQL8Cr0+aIIJdCIlVLuxZmiwLQsJkxnGSREVnm2v7xKrUF+k0O5e0LR3iIAyBPnJDDmxjvqy53oIX5K+ECbePGzLpvrlKf6oRrPCud47rKLakx3ayxVBESXRQcl34yIcBfdZ6Sx/gipctAlEb9X3+aBndYW7Iy7CRAJyhce5G4diQAJPza54XkIa+V0PpGqrYdxfbJlAWpd0EuZTBJbpK7bwPMb4j/eTAyLVNrHmZF10vT8EIKi8TwL/ZAWJBNwDYagypYQfFTTNA8JVplAJrITEUlhlfcFc3D0KvwexotfEQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR12MB7763.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014);DIR:OUT;SFP:1101; X-MS-Exchange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+cW8zAyy4M+zRx+IMsCdmcvJPQJWNIXAiHux7cWM4eNQrnXHfqrRJAmZHu6gaxnGr+sWx662q2SoV0FmDN09TVwCZy2Ug6NMneBabE2pcNJ80X1lU5mqx87DONjNloKSj4VjB1cElZu9nR3czoRtp89kdiONTQTVeJdeUMRvp1ubnSCLNYH2w6wdw9OAp2WwwvpBHhhaOkbv9FP4VFUjntigiTbHx+HZSTTTHxUQFPPhiGtQHXfJcwSLwTe640ctQNjwhiFi2+zEn8oiyliMvTd3P/tpL/UhAuAETmeeblbwwYQcGch7n8CUY69H/qU9p/CPUiddOLH8U6fm+csywa7eCzrCHm8IUEAj4HVR3HiMgzrY+QpiBuSqsuMP5ZjQQIugyDlTau3vGw62hHfFZwBeNUAXadSns/ed/Dl1TD4/0xA5w7ccvNroaLuOQu/UzEgc1c2Aii0Ci4a1zTsOsji+yTSO1Cpp1d4auaEaKPFYrqN5GSZpRhD9oNL5Sc8ofIXIAe8rTd/9KAU6jNsSQ3lJd7v9d5DxwJCFeAIsetR/uKv3j X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3995bef0-3dd3-4a1b-706b-08dcb66fe32b 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:24.9847 (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: HWHkMujcjC5ibGpFFpLFtgeBDtY1i7DEPRNOtk/QRYagYPsBYyzrocA0wcYk0/sP X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_163144_133074_2B7F0315 X-CRM114-Status: GOOD ( 10.31 ) 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. Tested-by: Nicolin Chen Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 30 ++++++++++----------- 1 file 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 95bd4a36268c00..e6607d9d590c4d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1184,8 +1184,8 @@ static int arm_smmu_alloc_cd_leaf_table(struct arm_smmu_device *smmu, { size_t size = CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3); - l1_desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, - &l1_desc->l2ptr_dma, GFP_KERNEL); + l1_desc->l2ptr = dma_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"); @@ -1399,17 +1399,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 = dmam_alloc_coherent(smmu->dev, l1size, &cd_table->cdtab_dma, - GFP_KERNEL); + cd_table->cdtab = dma_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; @@ -1420,7 +1420,7 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) err_free_l1: if (cd_table->l1_desc) { - devm_kfree(smmu->dev, cd_table->l1_desc); + kfree(cd_table->l1_desc); cd_table->l1_desc = NULL; } return ret; @@ -1440,21 +1440,19 @@ 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); } else { l1size = cd_table->num_l1_ents * (CTXDESC_CD_DWORDS << 3); } - dmam_free_coherent(smmu->dev, l1size, cd_table->cdtab, cd_table->cdtab_dma); - cd_table->cdtab_dma = 0; - cd_table->cdtab = NULL; + dma_free_coherent(smmu->dev, l1size, cd_table->cdtab, + cd_table->cdtab_dma); } /* Stream table manipulation functions */