From patchwork Tue Jun 11 00:31:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13692722 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 505EDC27C4F for ; Tue, 11 Jun 2024 00:46:26 +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=xtlYN9ToQtAUJ0o6Q44ilxbfAmbvBxOxZvuSiwaY3LI=; b=0vyiUR0yfBNBA2 Bd+NfjR9jFCiGK2upGfYVdUda2UZco9i1LJE8ac8YFfERlHrX4inU8FEho/UW1/v0WidX7C5dxbg+ LN0HRq7SUc+ROYhbq/VRWZM2fkWYPOftJFMDwsnh64VhhyDrkhyidujy50eb5VhxX271elTJWCMFe DRv19iJukG1idL7yg2k0MSaUS0taYGDSnFGcdAeqTgwB33YmwHVf/sWgSLk9OxcNSDhH2Dp6DwaSD FmcwsTW98RlORaldQi0IKlLQk0raGhpzaGuDlkL7bVxq0qA/NaV+c91x5XJcFrbRrtc6oewAovBqq yzshHKsgC2459SG997UQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGpeM-000000070EY-0QxP; Tue, 11 Jun 2024 00:46:10 +0000 Received: from mail-dm6nam04on20600.outbound.protection.outlook.com ([2a01:111:f403:2409::600] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGpeJ-000000070E5-011c for linux-arm-kernel@lists.infradead.org; Tue, 11 Jun 2024 00:46:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ImvHsKfHl9MmfCKu+3NW5VLHvFALP8f5xoynHQnKUqldEoIcJFLsc1J1tPIhXpm7Jq9LSrslPQ6qhhM+o+CKrYiZo0TDgL0w45wpf+96g/0lUZOvcxlzO5paxlfsRuYdqPLnSTWOZLe6nIkJTHhB1rabS17ElVEVeqxrtdX7RvxHKLNpJ5CSyc1C91lkEjYpLi4eZj6+aLIuDJBBwH0WwpeOp0C3hKl7rZ/0eeu8xa6iP6o+JRLZ+xTnSFbfB+314jaW4nztpGjgAqY/Du7+FiQJNmJzD6ZHGPu6Dya1FoOvk5aZ543yueDQo36JYpMeQ+keOlalTTm8rQ+e6svDQA== 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=VLUGPmKneAgy+CXJnRO+PByM6IvyAVil2RAIAxUOr/g=; b=dQASkO6JNUSLicMFKOcipQ/hDHXJ3d8mmCezGZRou+3BKGGtYtnjzGRwhmzGoQap/yuGyLtq0nNAgc/KqWtKpD3QiKVbXS9idsIEA0tYI1cWemosJU0E5lV/eTY0LSPf4Th4hkMwv0dbdJo/zmpkwqNHWksA5w+Ab4sxjzXTE9YAd6QJBfBHM2dsQ0HqPYxONdiW66WuSr4ifKZmdchtCjR270bUey+vo2jSpxzQGlhqrXp3TQqLgKN+1Qo4tOQgQvIv4DMdv4peQroM549UXdp0mSa/IwmNC4jv4Fu+A71c19piWYaLJvdbI+7KoUjD69v4klqSx+/BtPOHquAF9A== 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=VLUGPmKneAgy+CXJnRO+PByM6IvyAVil2RAIAxUOr/g=; b=QumwHLaevR2KZYLbXiTCPnSfSP9QusUVEedSoq3S+nSoAjcYGBwL3hR08kaUB+SEXqmojCmHr0kI8PTvp1IqxKp7I3Jf8Xv9ydoMcnnvumZswk+rOTcHc4yaoUsynb4jMBxJZ8VfiD06Wh0ZkyoTRpZ9J7wJ0o7h2rDzG5RjwqaKI7zHQrcGtz7RC2JeLJ4Tv/S2cauc6OLdN7MEdCezNqupW2OBqoyXwl+AvZfjAD2iAdt4oAeZV4O94dQkyba8tpg+gKZGH4hjDMQ8KoAF+TAR3p2xuC1dtZW0Tof8kXyD7Xw8q8qq5wJvP/GZ921c1rHzxAnRDLXIfmNGNyjsAg== 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 MN6PR12MB8565.namprd12.prod.outlook.com (2603:10b6:208:47d::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.36; Tue, 11 Jun 2024 00:31:26 +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.036; Tue, 11 Jun 2024 00:31:26 +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 v2 07/10] iommu/arm-smmu-v3: Do not use devm for the cd table allocations Date: Mon, 10 Jun 2024 21:31:16 -0300 Message-ID: <7-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR22CA0006.namprd22.prod.outlook.com (2603:10b6:208:238::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_|MN6PR12MB8565:EE_ X-MS-Office365-Filtering-Correlation-Id: 3a739b7b-0464-4aad-7446-08dc89add255 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|1800799015|366007; X-Microsoft-Antispam-Message-Info: Qve5khLNYZhwKp0RmfoIGxxLjnNDROHpk3YyIAfJLXxvXjWmWX8Q0J+9CYYV5Md8AadXtDTRAUJnf7b376FUtQFTkQfDG7dGw79IpzKvRjURNbAXKTl/+71Nx4G8Mlv7LUsV6oP3s9erw2E+EXzOH7kY5Bmc11eUoYRzBE7qWJep6GysHyDPSdOd4qhexekc0cZvK/zy3Wj63JwMymL8IK4qIHOyUI1nwDn+rDou7SKGoNcgy5EIlyKvpKkQsXoGtpMgIbyKtAqOkjD9lnO+GMfodYCAWMozFKB2c5/JjRpRBHLWLag8cpv6Qy2/19dXYQdPf/0sWiT/v4hsELL4d8t4Z9NOqGbIiLNcau8qZLMtnm6MecXd/jShIqtY8Ge5POc+MnNOMKUFAzQ0XtxqdKtOr/ry16Swig4LECY0ue+EKoxL0GnW4fnk+7ZI5aUV+KNLTJSS5Ns2Fg+wW1CagAj4K+Pgc0i+l6tRRz1MtvPNXDLRT5I30bLK2IG+8RPCz9jN+lXDr9LgRh+P++eWyQwdMwYCw+aBS+cx0nKexdzr7iWTH9dScEjdd8pREWP9eEQ0BF3RZq834EP3KN8WOdItIzVK8lfCQG9SJyGCM8hG8wyRL3aBjtKfDm49zSKDqRz7qY+Y66XEPFaUpBKnk32b+XmQPbMiY1XAvtzQRQM78Aqj3qBgK6UvpoCY+zgBGGtC4HytF92rgaHWNjShj9DaOQtzGQlpbrLEOBRei5DP1GAaK8WBZiCwU0DI8h7++npI4+DzdRKnpaz8p7HJ2Mjua56Z9RMUinBICriHIuAD35Owli21Yd3cR9kP8gbKZ/vMsIMQLhmuiy/FPS5lcUr/XmDfHvD6C7Gxez+YqKe6NR/1oix1yOh31Qbpx+7dzJahwvHvqqlni2rNdOBzue9XW9NgAIyxxKYLqMzGRTDs+vJdyszSB+K1ZQVKARqr8iaxatQNlsrrPNvkQq/ikjQgBIwrJTPbjrnbB4pdEHe5fK0GOuLhRcwFERXRcYvjXwEl4PBhjhMgQ4Yj+Kizo2WZPMts2wVDfRkub42gDRoq2y43mAEmEmza+RNC1LNZiQHh3/VpGvUSECP/HjEL8nOdDWcp8yMeaJuAK6THWlovWnWJS2bM0asDV+jbWcLrJHE8KHJG9fnJo1aTf8UWpQOc97q7xog9JAnnNXcCDwr4Q3OMU5q0ILxUckPwnMa6iQr/e7WvysClMp7wDQukxoK/b01wVyV5wo7BSYifRN/rFjGQfOqTQ8kHcXCmGN171dV8BW3S8eTs08cycaIO18hHtUZT9HnhKevMv4R5JTZN+0fmpsRWNq94SBZBD6M5 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)(1800799015)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-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b4hxE9qpErnxOKHFbbU0Fic/DFyoX2PnNT6IX1Kd+W6uofXz7mMUBh3OXOeWpsVYAiDAhdF1/gwnZ+g9jHOy1/RUP7Cqel2JKPOZSBvtvS5GjaKU0E6W2WdmgtTDYRHGItyF7HrWhWrNrqHy9c5uqvB3hEmzMIju6euSsnX8DDa7WSNRGMpx4/INKCpIDcHCKyK9chomq5O99QAZV+H1Jj21jvQjAm/fHxTmfLqpnIN0X0l6unyxnidDcU+0R00GTE6BqSAomRglQliLE6SdXgIPGL7/fUzzPiIQxgQHw5Ah+7k7C6PfiB0zSN6X8GpbSwX4ly57h2ysNeXhM6aCk6IPCh8SsdrM8pomOHgvhQrHcw/T+kx7FiDarDdamAzquqjXM5NEbuq+7ndGHEjbcQWkDXjK7U+AqPYuxaW80sbasHGbG1X3WE20HYPTNuA7UjYk3MwewQ6E9kEzgb0C7XLWJm/KlOhVKfC7LVLaPiiu/zRBnsa0EzlpyJmMkXFmK3QMyL3DypoGjjsULf42DvIGdGwI/nY3FlcVX+F7OlDWqxNk= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3a739b7b-0464-4aad-7446-08dc89add255 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2024 00:31:23.5204 (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: 4pcv8o+n7wtjJHJtDZOvcpetuGblgY1QElJ4e8eSBgGR0l4e1TvA3WMQYnmSn8C/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8565 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240610_174607_060913_89CA784D X-CRM114-Status: UNSURE ( 9.75 ) X-CRM114-Notice: Please train this message. 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 Reviewed-by: Nicolin Chen --- 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 b36bf6bed67d5f..6245e2558e6a6a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1172,8 +1172,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"); @@ -1372,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 = 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; @@ -1393,7 +1393,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; @@ -1413,21 +1413,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); } bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd)