From patchwork Tue Aug 6 23:31:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13755483 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 7BB5AC49EA1 for ; Tue, 6 Aug 2024 23:36:21 +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=P6/FJ2tOwiz4XcawISnzVitqeIGHke3n2G5zNAU8e3I=; b=qYSre1x+IluJQ13mNbIkTz6Xp3 cUum0GFzWZawF8umj8vCn32mSig0C+RbCQiVDeBdW9M6d23wAE0B18N5cv1vmn+F0DhRukWLFAXiu wtgmty58P87x92FWmgK0AFCiX+gAObU0M5eTe3SjHWjpjj7Zx3aqBHGfha5PvcLnezQidQP7yzMcN NeE/0UXapRiCW9A5z0qV4uwZQSUx43Qm9iqKSc+dIPONk8KGzzqbnuKzTi9LC9hkj/qPOdsenqkCp SM/GEdQGho40Jn0ISPnOpkHxAglHMN8nQm8liPievrArvES+eJL2uc3CkdyFkKRjQNH/uZG01hB5g PUa9v7Zw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTip-00000003Kh9-2WjT; Tue, 06 Aug 2024 23:36:07 +0000 Received: from mail-dm6nam10on2062c.outbound.protection.outlook.com ([2a01:111:f400:7e88::62c] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbTef-00000003Jdz-3Hm5 for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 23:31:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ljaWTSEPYJLmsCfqyEPqp7MQMkVX39Pbmkyc5f1jD/dhId8WfrbAHZL6RyU+UDH8gSXN4+kZxUEUPNaTKjq1YMrIOf3lVmVfWHRIOWxW2x74nKFpi+qysTTd2Hy2jwA9AsFGrZv2ychbQa1yUCk/hVx1Gdrib9S+LqeYJZ4X3eoZK2m/EfRl3ZiZjsVqGFxWoEluGrWaJfbovRXabV8R99a7jbfeenkykYCcHr8W1ShcPArjZU3Y5WOk/oL38nNpNwWXoN5TW84X50bpsiMW4wXfHtWq1KGiM/hWzQPZjSv7EwowqHQjOc7Z8LLHgw8VZZwxwEGhyjx//4lqzI5dMQ== 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=P6/FJ2tOwiz4XcawISnzVitqeIGHke3n2G5zNAU8e3I=; b=NtN4bJGaqFgz4/bV4n9FB8QaloJV4Ddv75q2HIEG3L37TZKW40Hmm9kwq5ZVm9cL06BYeKo1RAL4ZuPwhOuXWoOk5/XGEHBh+4GoBXjWzeyQ1210G+hs7Ois4muIE6Ism0X/mnoZSb6deZwe995UpbfgAOZenoC2vV3p3EkGnB++iO5LeKnWdNF5n7i6p+djeQhRh7r11ADzEVX3oWUG7edkvGA5N4wBLknzBwr4oqSUyMte5xBePaOa2I7q/XucBtH4UUEPLvo5aHUybQqwfC7JzngDlrzZ+5FuVeqmViVUx2kOBuJ9cwmpwVvyyr1mwVGCbeff8UHmc+ZAWiciyg== 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=P6/FJ2tOwiz4XcawISnzVitqeIGHke3n2G5zNAU8e3I=; b=qIRoGeHvwLMlGYGPlrsu6Ig8XDneNd57I8H+ilOLJt05Em9Lq9vICnIDb9Efz+4qwmhDt9e20j4fkhRA7vfgbME95YyOOojst+BH0JH/mD6IlhTZvQx4gL7JQDWwsZjXyuhceNaIgHwIKQt+7PQ8IGrhZpiiAh5xjb+5zOuKzG5jZvKSBvw6ZMiynThTO+w3Qm5avUFtjOED5eojVYw9zTUskEz0LjKIeU9I4YaYG413VYgS2YlBorKYdp36mOl4zJXRsP4rZlLtOjbqvw/qKevahUNptyHWr0iO3iBbrNRNI4BixyEp6zzKOw7p7gtL1WCNF75iba2HeS2J+THzIw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) by PH0PR12MB7839.namprd12.prod.outlook.com (2603:10b6:510:286::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.23; Tue, 6 Aug 2024 23:31:32 +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:32 +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 7/9] iommu/arm-smmu-v3: Shrink the cdtab l1_desc array Date: Tue, 6 Aug 2024 20:31:21 -0300 Message-ID: <7-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BN8PR04CA0056.namprd04.prod.outlook.com (2603:10b6:408:d4::30) To CH3PR12MB7763.namprd12.prod.outlook.com (2603:10b6:610:145::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB7763:EE_|PH0PR12MB7839:EE_ X-MS-Office365-Filtering-Correlation-Id: 1261e25d-fe55-4d26-3852-08dcb66fe497 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: hZQ1vOL6xLGriLhMRaF67dQkQZkubwPHu7kxtmg+fEkNL/fXZmyoEagYo1uil04vqy3csBk+N4hgnhSSgr+XT5Hb1wNopaOrbbB8IVPBwNhc/e7WD/eYcp29L5TX0RZXjmDVhoEOVk4+91K39izoaRBd6RYZm/rBYtAQ2AA85OJ47tGqDYslFMFPZ9hXZCL7mMq1uBsEaMy9DPNsTxWDR6y7reBfqW6jIdutwJr/syT4/uEZFU+PCHCmnMveDoD9Zmu7Jeq2kpbHjpJx7ZkhqZDjQ8h5fIaY0okPe9H2m52t5Z6xg7GPW9iJGON9ntbwFRwqW87qwj4qWVqW/iTUHxiL9uSbUz2BSP1SckOkBpEy+AFBgXOU0BVwF/8u0IZKw/gpkY3Xd7kQ9l5SM9tI+S+pd1GAKgbWNo1vStqSi3ZXyXxVkcMPgfBjuCLhjkGjeiAxNYOqrwozCdnCcoALeHN9QfVxB1bojcLBaxPYIIx9mxbPcGF40pQZZehxL34jTQozleExsSaOquQI+8iO4hKIhAp8xDcW43Mnn8ESFYjOeMe86FRyH4noZ7cnA9KqIMeMPZVOrBJEH6yRLig6DlzjCGrniqPXYmsOYE+qBGqhvooiVmeLxK81UbHlYShSe8BOYnf14n2/Hm+BvYj1E7XeD1G4Gl8+hrpy+tZ9MJLyvt8MEx65dDLLtnFfZ0wTCKN4IpFnHdPXYY6np7+IMD0VsDVs+OFCOYclA28sdXq6yIH4AQQf8sAd0YjNhUCP7d+SBZm25ZY5hqivgMfylXEBOea6g6x6exniR0EMHzxFdRWNG4rfEbWK7ObTi7RGsLZX5EK0OGPg+MDzNrzmpsj8rb1Zx8jYmRI9MTmOdi1Zs8Hs0rp5TvlnKgX8QQQpFNs/vefdsytFOGsim38ZvY1fzVS3Ce3u6FIq/tlDnH69jMc3VtKXIfoTHD3pKe7E57qhXET8aKlAW2SXeVP8abVVhEfHxJSU/oksWhwzImh//NuNvJpmgbgpdMbxgLUGbV9agO9WqeGIbqvaryFjCZPAslx+2gr13RNppCd/HXlrNTMjNyKWjH0zJpOJPHMZuDbeCnBWKQ99MKGhQBoj0cHJTVANBeiGnDkS601yeZoqFjfyggRok8ebg3IjAQk/YWmQwFlYVE1hrE8MV5eJSqJvOjhrxWWxFqSU3Gn9gLNmqVDJJajCtQl8zYPnnYriF3+HJnie8Ns4Gj1VIXwyl8WJeSNNRvHqRecuakCRcEyZU118bxOJpN0o8GUPa1EIdP9IaOHNay22N6fMPb1KwheMFThtz7An3IKruIhFXErlBvyDqo+qw9gYO4CEAeHORnkYks8w+G/sdC9MSaVW6g== 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)(376014)(1800799024);DIR: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Y989A961S3hPSjUqATbisvrMaKVA/jpw+DgheNxQXpeisAMWfFupqTl/QcrWTiNpOmhUZfLORKhcx1jcj0ys2RncD5PKlOE0q03FHSkiGaSjE8QR/k3idqxB6v0uKgtPyNMHCw+/AhEtGzjpFmTfxJgz6Hqln+BUApgNNa81Rw8lbU64/AOLID3M/yKiqw6skhuI9l4DRe1T3GBIas/dqcYgZUJ23MywmzWdwirUcf75jRArcH40c3N5CoMevatZio9AJz5Eil9lfiW4+4aA3ucYNwvSpokxF1trv+cwVM9wQXwGs/j9nzsp3YWK/rOBwPi+VE2tIQEIfHiUc8y7kfKrqMsKHmv1dNKJcaNkACgTwqbvGz0/ak8+PAr4UVZ/TIAEZlY7nxcqxg0Du36wsoNoYSe3gsFGEsA8VXzFRQGSCRxqwlqMXeNgdGguvqIruyxcaAZi85xF1omuUZVQaDaGVC/60p2zHz3qpXIcabDlAf6g4d/AZUiMZCSR5/7vMwrWlgU5J5GeG2a1wRTTb43k01YOKP9PCzq+26EF+eiRXn7fHGzqOQjxPaflFAjkXMNKrGM= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1261e25d-fe55-4d26-3852-08dcb66fe497 X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB7763.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 23:31:27.3322 (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: thLLt6fSwq5/22IhvbqiiivOZLi28L6FnVISR8eiyf+85TZFUMfn2BgXha1rYOpn X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7839 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_163149_923644_2680031E X-CRM114-Status: GOOD ( 14.17 ) 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. Tested-by: Nicolin Chen Reviewed-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 41 +++++++++------------ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 - 2 files changed, 17 insertions(+), 25 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 e6607d9d590c4d..d23a845ad82223 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1179,31 +1179,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 * (CTXDESC_CD_DWORDS << 3); - - 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"); - 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(const __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) { @@ -1243,13 +1231,17 @@ static 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) { - __le64 *l1ptr; + dma_addr_t l2ptr_dma; - 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 + idx * CTXDESC_L1_DESC_DWORDS; - arm_smmu_write_cd_l1_desc(l1ptr, l1_desc); + arm_smmu_write_cd_l1_desc(&cd_table->cdtab[idx], + l2ptr_dma); /* An invalid L1CD can be cached */ arm_smmu_sync_cd(master, ssid, false); } @@ -1442,7 +1434,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[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 be931616d9a27e..68841ba3c2e789 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -606,7 +606,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 {