From patchwork Fri Sep 6 15:47:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13794404 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 6BC11E6FE2D for ; Fri, 6 Sep 2024 15:56:40 +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=Aacp5HoyRGiT+Z0OoH6Y8m5l4yd97f+ZUML7XVgZoe8=; b=AtwmmwoenvRoO81WIqQfv1ciIB oGoHNmVfBzDonjlRSbjG//JJs2zDeqWnHmIXior+K/HSO3IGO7f/9IWHvOm3pbJ5n2UROwZunuaAw tpjg57m2/UDZn5E2In/sUPhwWAt0/q88cdvovD9WRBsXjb9DpH/W7Zfj1ZRIGLgGTWnhWqEl4coBp 5XK1n9HBTGxsMViUUBdKOAcUvqSfRt9HVQuUjLkMjrBhAUaUcJ0snZjyG9PoA+0z4/1+xvx1XNewY 7sxBLtjsyOP9lWy22Uic/OXe0qK/D0zJ48njn2f1n2/T5BKhckvQWJVrkMYG85kJ4eVg1jKg5iIYz 6AXsGu7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smbK0-0000000CrUn-3OwS; Fri, 06 Sep 2024 15:56:28 +0000 Received: from mail-dm6nam12on20627.outbound.protection.outlook.com ([2a01:111:f403:2417::627] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smbC4-0000000Cpj0-0mDu for linux-arm-kernel@lists.infradead.org; Fri, 06 Sep 2024 15:48:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tNVX97K1RTHc8CaqLbG+oX67fa+WjAjiigx1D0bFAawZQ+fL14zrt7qcMwW7yKl4XP1+PXk3tbd8AS7tJSkfOzwI5HzwyOvyPq7cG90dc34eaRx04M5v9tpccvAOAb3Zy3BhILTswDkqNLO39Xg0gupuH/IXMN3T/uVhiXbuTPAy+LbWU039FL2ouEy+/h7Gf5Rnm4EsKz67n1Vi+fmOqrAwyXXctxHIBT20h+NaIxIeqKzCbXMareCEOIYcyjOXqYz/ZYJJF5UCe2GM3Iu4LAuEXSin3qCqjEPE+osIW4Zd7zxLPD/lrNY+T/VsLOgiygOuFLlfa/U5Hff2Ma7obQ== 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=Aacp5HoyRGiT+Z0OoH6Y8m5l4yd97f+ZUML7XVgZoe8=; b=tvZd8SZeaDTB/TJeiHIZVvuEuhr0CmK/Bqnc3AOMFPmpnitBrYS1GoQXu5PdVt7T0gJFR6TrU45YdXPFQwnV/Trryg2pzIZCwRLzhFfCbQndHqz1+rqyc7K14C1HX6ON7SB4omeZ6Yv19dVaqeJA59hfFNsUHG60LFAfhWoSZh/kD0o9QU1sPIbKYqt+Ra682vjC41hqC2Mi23cwUvVPEkDVjSS2VZ9/ZhS8mu15Vb3e0GV33Go0UYYQHwrilYY6VBKL+nTqytd9w/+aNTyvTMCfC7YO7lSSI7Vw4XSnENG6iVJCmcv2dZZV1H69gXplsfF0I3VJiyZ2g4EiH0Eqcg== 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=Aacp5HoyRGiT+Z0OoH6Y8m5l4yd97f+ZUML7XVgZoe8=; b=YljRv68L8dR/64PLmA4R7ARMivn503ks3aSngX18rxWs8UGdkTpgmVwGym8vVtksKjAy+YBiapAY30p6iNp3imXrmT4jb0+7H+IHiD2+ZZ+GliviUJmaJhbOj4yNhFSL6LOHdr3zioQTVgGRoC4kELb8kSqFUcvvfVKwLbMRiwPTJvZj9s7cpT2nokiO2cIHgLPjAFk/L+Cjqy1KpUkowp9Ib07DOboylHiZwgeKIau0yLnLr4l90Zlyn5w0wkcsp+cezRcgOlqWhC/5Rx6HHCkDYEH7pn2FzNQIy1kKLieA5RdGmdvbu8FAsLnGid+Wv9fIuc9hiPWtODanVszEOQ== 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 SN7PR12MB6792.namprd12.prod.outlook.com (2603:10b6:806:267::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.28; Fri, 6 Sep 2024 15:48:03 +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.7918.024; Fri, 6 Sep 2024 15:48:03 +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 v4 5/8] iommu/arm-smmu-v3: Do not use devm for the cd table allocations Date: Fri, 6 Sep 2024 12:47:52 -0300 Message-ID: <5-v4-6416877274e1+1af-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v4-6416877274e1+1af-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR16CA0031.namprd16.prod.outlook.com (2603:10b6:208:134::44) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|SN7PR12MB6792:EE_ X-MS-Office365-Filtering-Correlation-Id: e6d5c73e-92c8-4f4d-8038-08dcce8b4715 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: OuIYWEn1uBg11vl3yr9vvZrhFvPzp/oy2KgbKhFKJEQbkxc2NOZieNNLBpWH9DQHAOJHhA9ye/BQlNhh0KwamuOsiB7M+/l358TzGpA5BmlPrs2VH+J+ZiaoHWbtoihRHaEMJjDDmbP9TRw5EQ1uc2e4wp8CYF6pdF7i5v8o6KTXIO08bd7R9RWgiqB6F9KR/7v+MV61AYweRJy6QaUSBO0SN+SbSrqu9Dy1yzICp8aS59MOa25J2GrCDMkKos5+W11Kb600eVYCXUZIwoXmcPYfMCznUJiKLMKZ+U3PltEwoBTqXm1xmCK0HKBnePupFZdDrdt5NbRFTohzSTol6WETtMXDdqAddxRZKZT+JB2BsXHGj1YyfDNfUyMfF+5rslMaHshOMjslyWHihgCkNapju89VqpB+b5G7fSoD7vkTonmLD6da2oArBj2jhKRHJ5lOaPiHb9VHj4UrHkbt7GYh+SHpKNltHM18eCZZOBZgJU6YTMSqOVP4rjNXRgv1wr1fwcAbS73CzpZHSRV0c7jrsUSiuYT4ut98uQ6dQ4JGkJ5L14gbYPce95sWx91uR9LgCQ0ie1RzeralGW/ktfU9I6kIlaykC6Kh+h91azDmcJHV0KEYiD1vrsG1V8XE3LZg+jk/od8QnQOPexGeF0z7SQR1ss4nX6C9oJZ0CzqLKOIFn6cTXl1dgEJbFf5VMl4WRMw3tjiQ6wRYywUYRtu0JIdXU1nopkkS+pmBlHFFcWpmkRMPP0z+ZMG9yO4E+coJiI+h6ABQk+VtN+5RS32BqxUeUg1NF6cC9pFDpAFZkjUM9zPmvtM2FsTHmqx3x5HdPGmvrQUjQM99hqcl2ZAyCponbPjWsx1F6tJDvntyk5o+qP0KAqseJ52jkG/RMMlzL8mivk5plRO1qv1uxGV/WVuWqfWyAxCltuYxa+3xaMNUvgHHaT/4KI0gpyCTMScq85RnX9TNLEWlaQyxovKDt188Is3hkLzyOc83NWzgPLbX6Ut6RVGXrKqacBPLtCSizPl65JLDkE4EkSLh5EzJegi8PKNtNhH0r9j29ShPrA6t2Z8e2s2BvEK7I2bdrJyCg4hFkmd7ZBx+soazi9f9V57csO+HfIVXnN0+HKcHGePZutUg/msE/dIGgeTYzJf6fYlL9fNpeJaBQOj7YmZ8dVuP33/pnh4mE7TRpIGjuXcOUocu6dfoD5k3TJdNcRoY95w0gT6CNm1zLwEYw0kfa4EdL1awnGAPSC3i9eeCdBgUTAnI30AjmIQCri2T+AeEllcKHiLpzcVHwDxm604m4ceLfhaiTUyvVgRbTcy+ZtjXIHoVGuPxie4fRj05TfWoza9TI8EfGHZmjvd2lQ== 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)(376014)(366016)(1800799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o3BPrQZdG8YYFoxOM+Z5BdpQzWpsf1GSFgDuIUHCTEsBoGzCoq85903Gpq1J8rfBNGMNh32+XdNiiej9eozEvutQBWom3n9nFwU5/NxBWSbbCYOKjuRYaYbyL8/4/nDqPMco34bP6hNzDMet2MSDNJrqfM2QDk0ozD1GEavVzt2hnARQ3S1nVID4Cgpk112AALu1ap7wAOigEdP2x3b599rhMnoCMInHnoP4Zc61LRK/dEnAvNkWmV0kaWP+zYeggcdWpiKpWoga3hDOOP9amhDIFTYu9gWVNx0j9hfDgBCciFI9WUkEmr+e0Berc2eUpjiWWrqMmz9B+lvkKgPwXc1yfBirDNMxS9mxNNjsLz1ckIuIROqg2oa+D0gsjhroW/+nOw1sVpaBQeE1+GXMQVk++2Tlp8N6KiRSUqHGBIaHlYfDwQ/blVzpxIn3ZsKVxx6uvAJ7RZI+yoeHBqRvp/nAIOvdaWx6V8AwFRYFa4gKeJPLLGsINThSk/GFihtj6q6Kb37jSd9/6F01WS9oDsqiOwdtFcZC6UHs9mdhY8qv7eQX3h0kDGCnQqHdlYxSAta6Di3pHNURjrORT3/Tjg3hIJqqFI8rtxYj X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e6d5c73e-92c8-4f4d-8038-08dcce8b4715 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2024 15:47:56.9403 (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: yGCNCTKXWWcJ5CqSCFyOqBY+/wJSctkNNSus8fCuUVAWedf3V6CATfGNtNfJKaCQ X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6792 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240906_084816_292055_FB7EC618 X-CRM114-Status: GOOD ( 10.35 ) 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 | 29 +++++++++------------ 1 file changed, 13 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 bb6c556995a7a7..c69d50e39b21eb 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1222,8 +1222,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"); @@ -1437,17 +1437,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; @@ -1458,7 +1458,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; @@ -1478,21 +1478,18 @@ 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 */