From patchwork Fri Sep 6 15:47:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13794392 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 1B757E6FE2F for ; Fri, 6 Sep 2024 15:55:38 +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=Iew0CgRP/kyNnXTBtf0n1fqA4yCeeQwjgKjKrVeDomc=; b=JE4OmZ5PQ/GNCUwd/yqtdjkTHL v8UInhDAdMAxJ6GtZV6KL4pWMFq+m4cJJwAgZajFETmlDhbLmgjUdvb46QCZu/ze6xfn8mXbvJl5Y lOepRJuVlEiSGnKmEIt9gaW+u1hXFWsBsP4RV+cprxp62tSsj7l6t+jmfW0D9o9RH2tEOCeE5WhRW zfULc6af4PuIQ8FIcc8gt6Fw0k0jDX+6XFz78p8jSJhIrOA6y0ORqKRx31dGhp4ajj1SU6hZ0lsAy Qral0xxoWzxZQrT6KoVIvf78MQ6UQx/1alGgy8jQgW7HlgWSzLdBl19H5bA21Hie6YFOUm6YBxUqn wXQ+GWHA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smbJ2-0000000CrEm-0Tm9; Fri, 06 Sep 2024 15:55: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 1smbC2-0000000Cpj0-3I9E for linux-arm-kernel@lists.infradead.org; Fri, 06 Sep 2024 15:48:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rddvEnZG/utWjKEB2P4OOgxW3xEvs9eIA+NzGelv8o4V16w/iPosfpqF89grZwv5fJjx99ic+4FEUswHf7EXVV2iRCVQtkDnNhlSlnltSHltm8/PSpYOFlasU/lRKT5/OBOPet4OxJtDMA6MajaFpDIl3vehgN2wBVp8d0aB4YXwiWqIGlyZV2wNlC4PJsXk9wsxmtWZ6tae0iOl0PcC9YwwrEgV/56nIGPJcKTaqtWygbIzYw2HK96Ag4Ejhc8YjzdlzlG/dSs5VDCXaWrMVwOVIPCiwLKsAWrvTmnhvuyUUybvvYGXuAqUi4pkTBQQc7MVAlkB4zIL0lmvaiG2Lw== 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=Iew0CgRP/kyNnXTBtf0n1fqA4yCeeQwjgKjKrVeDomc=; b=IZgx8hwCmMVUv5+7wrqDl1AYfKtIYiItCDjRFKP29XEEqzYRBRkpxe0CwjMFNjbZetZvU099WWTWeV64oVQVlhdVK/GMfDz1c3VhcFxV7RL9NoHUb45kecX1abg2GkT+2GYIOfUT1iBd8yvKSxX1bMF7D0Fmak1H5OM5NDzNNi6NkdyB9E2w7758ytgOLONIxuJWv94ht+TP0NufkMh5VkXuGZfBaxCNgRu3CbcekM0AisOLTNQ+QQ9ZVGPGNRYQwpbJ0XdjIpJL6rdl4DJE5Kj7+mTqqn2UGnyOCwMKXcWkLxP/ytQYmmGwW52rLXD10HcJQToNFaK4JgYFCJOFsQ== 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=Iew0CgRP/kyNnXTBtf0n1fqA4yCeeQwjgKjKrVeDomc=; b=rvWnm94VdiwaG8LgZXslQqCrCsWRWNJzHWH7OBu9MHI5zmRhikGC2XkwoqZ1fZFYlsLl+TqzAHT3VO1zkXg4waZhVGh6ZoOVbL3BLJQgLXNWTF81D6PtR2d5uNVdjerO5C7Z7INevz9TNFt94x5tK1wWeuXoTC1zdr1iaNVaBDkfPayAI/mey/7DCNfCgevlVi1sYTfdSWcDKDCceETiQne/lZBaIolh1zB5+hcU3Q8rMuRomqSiCr248L9nJhlp2ZjaM/+GIb2zfFkKDfCiu0pjGwHTzTkFa3eqa0U6zE9atC40ZsWpQ/tPM+in6z5cld2cTth2hB+RpRfm4c31Vw== 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:47:57 +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:47:57 +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 6/8] iommu/arm-smmu-v3: Shrink the cdtab l1_desc array Date: Fri, 6 Sep 2024 12:47:53 -0300 Message-ID: <6-v4-6416877274e1+1af-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v4-6416877274e1+1af-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: MN0PR05CA0006.namprd05.prod.outlook.com (2603:10b6:208:52c::31) 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: 19934ae8-1a91-4e47-988a-08dcce8b4710 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: 1dvzezGSddsP8DN3bh73yQQNUCiRb9ZB9ZFeQ0TCpTp+jH6cBvm871p2uO/UQU4YFS9O3CRREtIiZhW/xvyD40UxK+yCrQ81spY38jkk4RhUszxAPrhdgb5M00RoxpeHTfh2lEFNSnr4D/hBoc1I3eGXThMT4T5I7pRC6GvXVAnlMAMu6eiUJ0CTGcDc1+BWIQx3AjPfcwhG3uk+er4mGHofDfS+mTGFe8+PUoL4tMPvm3V5xAsY2oCdtK1tgvuv5jb+DGAhWnUQcj+DwSQv24IOGBvut2ZGS9Lh4R5ApYDkfeALdBN1+z2Do0gNdtlNVunOwfRAPDCgHBHlxXwWxVHM+p123KFPfExtM2YdYIk0MJfPNMeCymd57DQ//NpjnUgohcdxgL/bj2HHsrjeZSR/hGxE4xbV/BgrQFOAzEBROGwSBFE6YCW3Y6HLIzMvofun1K/V0PIc/XLFNe+AlOXPvWH+lhmdr7YAgkY3SMxv6hshaSngKEzVlLthTv6OZlROMOsRle4yrM6giaKQZxnzLdABxre4McVhhtglloa1zPzjW9h/0X94Tgikin3yQHSrrBtyCPU/Kma/NpOzCFB0xa32obQVn1GZz/xY8qS5XK/PPg83JCutBqWHlgK1qXJubWOjYqCC+rKAzOPQ6fCZzq7VFkRKHPbIp5OA5IJPP9pnk4gJXf7SDMO8lQyV01BUDQfCKoM7Khl/NvvhE5W0+4z4lopHHC1fCVpc/EwQOLqIm241lesGjv3ljVGycDNDLG6akOG/Klk08zd1GU6hSVnuVRDOvR//Bgo+a/g1WZHwtWJq8Z3V9Mfve7bLcRv3DS1C+kNaPQg+h3Qp4CYFkLAEf+l+4+Effs8NqMGiPLBB/kdrg19AiuhM4MzzThYNnlXjPW3AFw3d9rxHfOgAQtVecxUx5IwURwCW62o5UUuHP0ukhHbHEn+6D4TUvsIx/6I6XyQBanbf8WNvL3w7JzIKD3e5NEC3Xz4dTqG21u2klcBrmnzG+RCpek9ku7KZEA6QZc5Nrm51Uptyon0ZDtoiXUaosmGwfhpFZcZXG4pAfsvB3371w7QwLHKzIQzumvJkKM2X4y//4EjIK5xYx1wVvaes0Cq0yn8DMB22RXdIMRQ/MY0A2gzDeFm+jNpI/2FuZGyGPOB0tDN0E2TrFYKBwZhkHTmOUEFZ15Yt/6qlruOUQU9NvFsXlrCE5r1CBWLlftav17uX5qe8ES9hy/ryC9CTYKBkocAZ5l88kBvM4p38WNaDDcyxQKhRKLtDhQav2+QqjU4jyHboxhN1hboDOaneY49zhAT6FpjZ1NmeIf/HuP5XAAAxPgzuPJkDSby6RrnSC7drN/CTmA== 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)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cs7c3MkCrq3D4rRHzI1GK4nhDTuR9ygljoGs565b71ofLxcOkceyc6t1GX42viNazychRkbgqFIbjjnZw4UzQXA5pFx9jY6TJQT1T2jwXJca0d7fqYsnEsJMKjyhCS0P2IXImy+fN3WfwJABxGPsJeMirMVlEx0YbogWdHSf6l7FE+xtIwU+V3F4WkA7TqrPm0YKd1ES5OJWpwfjpZ6pTPmdUUZiB4b0UXfStqCzWrzRi427UpQS4GAYhG2kYdFGsmoBOuQbd0AohWjMj7S5wtq3eDIKBPeJ/0pe/cxFpV4R5lEmmoWRQr0W3TUAnyTwiKmjV51S5419c1cNI8uG+podDOK+W2tLVAAYN0RjpRpz3do93ckEtafKxz8HIZkBn2uWycn9WNCl4qDhsST/RH3n4syuxlrnYGpveCk23RSYrdCFDoUOadpr13mdOHyNLQ/SnzVvdXClDLpJRWnoo82beWE8WFuacaOL2UcAUFIa6maRKJzJbelvornpXevWNYTxC8hdU0sHi6TExlbb3kq33Jkpjdv2ULY/xyXHXnQ4640uxXq0wch1ueyNtxFGUTqXLG8H4ent6Z26XkaVGB9Vx7cgg0DkHIkoPN4/3UiPG9z9zzgazSEUk7U6pEY/Iga6JJ0bBRJAqJerTqDvUif9FW2kMJAmPzZYshv3j63af2op7FUEuGRUPvGc487TH0zXu0u1X5QP+HkGu6NZmTdgHkyysCZ+CEjZhLsyKF9dw2Yjwo5yDrOmShtIZvPLTCdNgAQkRAPA699CHX4tKgDgS//qfWre5CnQg2z/bYwMjv/E7oOkLD1utvMgmMTn+T1/dRjduwAWBT1ktnFud8/oAn0d9T7MRfFWrSnIu+37nWmg6CF9L3knWkM9AyKiYVL7SUb5AaZFvavrZhtcaGisLY3khDXSrvOrjsEuVyp8jzyz0y+Sk/iIUCcTj83QaRdY3aMzH3lyThdFEjzQLBoP/rwZpWzqLDkQ1OrKcblPoLYUTkY+HJNEWihhVSoJ6B5NV14xmuxl8JOudUzonD/kt1EKYkTXCHBVOb9aas6f/hiSDcmz5GLpjHsF6sxUtC5xo4f3rg0rcVJZeLsvXBH+P6hIMU6VTbOoNCmNavjmkfnU+26gs8GBQbI5RxfxOj2HxUb6xah8kHW3eqpvsxlubIdJfA2xbZJqb/olkl11NkG6VcfwPbmJ4UjSvUS+iYV4AiF3o5aq9SanjPAuk1XrfxKsRuUCAG+CR7PUR4nU0hS76Bxvkbh2/+vUFS49yKnQnXVlmLwtB8DZTw/P9Nb9+j6ebufRTmzICGjRoqIxRyhpR/j/lSTIQBJFphVlystpwiCI/VZb/1EGNDZHF9dMhlHRGDHEzZlqFR6neBMv2mxU0ASBNlxQEer8S/o19xJP9HE6uXj1L3J/g/HX1DnNA0M0KoJdn5bfEw/1vt1j7bOzbFbEiT4RTLsqX7O4RcL/2y43/I1XwikYq65zU6wAdPc6QU3dmjTeCdPF/DIH9TEV6wo3bhA4HR6uODWqph2iXmCienboTEKiWqv5trOuca7Nf5hHdWKRMJKOLjjNOrqVj9Sqy1jTX7Dn3nCT X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 19934ae8-1a91-4e47-988a-08dcce8b4710 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.9115 (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: MZTfoGI65HmjunT3tTUSReZEjcy5IY1GYHMVQk2MUF6yjRnLhAiDkdcHSHb3dzzB X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6792 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240906_084814_861720_4EC3FE49 X-CRM114-Status: GOOD ( 14.26 ) 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 | 42 +++++++++------------ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 - 2 files changed, 18 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 c69d50e39b21eb..3c33ebffbe62de 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1217,31 +1217,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) { @@ -1281,13 +1269,18 @@ 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; + size_t size; - if (arm_smmu_alloc_cd_leaf_table(smmu, l1_desc)) + size = CTXDESC_L2_ENTRIES * sizeof(struct arm_smmu_cd); + l1_desc->l2ptr = dma_alloc_coherent(smmu->dev, size, + &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); } @@ -1480,7 +1473,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 33a8bee1b82e3b..8b5628771b9671 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -619,7 +619,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 {