From patchwork Tue Jun 11 00:31:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13692716 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 C5526C27C4F for ; Tue, 11 Jun 2024 00:31:54 +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=ZuYOHkOFfoWB5kEK6BikFdEd277bJbUfAohbV6xaZ9g=; b=bY+XWCxoytM/eo UTWwite+oM0sISAMlSsfBF35+0rY0acHLVvgKt4LOVxvDrbYsJsWZzDx6nVewjcBFAEobI+hDDkYp mentlpnGhrkOL45Q/4XiXQt2mPteTEMe3Dib+SnEivt+UIDbr8CTXPUgU8LFeCBTeioPBtvXmohRM RVu6paHXoQyapLOxCLv5RGMB9oyO6aTZcGuYdiFyaPdjAc16CVeizopY4P6ooTbBI7v423oU7z3Wd 6C1M4+cz9RY4J0F22StKHhtGx7YCvFtNJmeQli+RjqrsIteDLL4vyyLHvrXtmuDFk7i8Oqct6bqAu 8pfkiy+spg5dJejyK0AA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGpQM-00000006yUn-0Fim; Tue, 11 Jun 2024 00:31:42 +0000 Received: from mail-mw2nam12on20629.outbound.protection.outlook.com ([2a01:111:f403:200a::629] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGpQD-00000006yMq-33Ar for linux-arm-kernel@lists.infradead.org; Tue, 11 Jun 2024 00:31:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S0lwEzPgk3Tvu5Hy8wtabZB5Ps7Og+8xaYU6WfgxZSSzyLATdHLLRvTVITIH1epEyZl3+H+hqMhncBVAAxYHyguadOyMSkPPBCVj8hvsyARdnlYgGE5aiFaZ0YL1JiGNjHBx4da3PSikFiBYRfX4twy+BgoNSuN1NgzT80uPNpjq3aVbVAoqdu5CKBFTJg7BWDehZO+MqkuhM2gcI+Fo/q4jFZfhd3/o+ZMexXtP6PQmpimPIej78OnUORB5amuo/TWiHmxcKys2oMpewswi/urclmJ4o7K+0haMOtOLhID7AJXBFoUxO+h3jx/m4DhUdhn5qSEiCXC/v/YsCxJtXQ== 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=homDZW2M0t+/h1BOLIM/SoSRrMIk55R0Qwdxz9cdE50=; b=QarZnH3eE0dK/7DoxTvLoXmYhD3xqnEiAI4tPCY2ifRS5KinlnRmG97yAau3gRVTefs4b7j+NYVYvpCAt4EylWLfVx8AhOc5O0eg7uLqpFVvp9gk7S+d6ObfGFve/mkyH0/has2efD6Jl0/8q4Q5ukaX+WYpOlm1JaQ1MCMkeyHItGsEYDy40u3vRPYImtQ2arrgSlt5gGWyw9AdG8OnhgCK75k1gr5Cb7RzL+/TK7hBaNmqgfrL5bK/S58uY1+kV5FBZXjpT3i0NpnEYD8j4iJ1/kTWNopUf4+TpU6YbWidN5CEGtmifHWc9oqSszrGUuESkLkxkLW2/6UdWY0z8A== 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=homDZW2M0t+/h1BOLIM/SoSRrMIk55R0Qwdxz9cdE50=; b=q8KQrOykhFZyfS5phoJ/3KUpaymnzq6Qe4FmP9r9i/yDnrePVcBYwtPlCNS7V+/imObgLjp9MdGhvasNJM9Vd5d/AqB8azFI0vK8JTXjdttDkpNYUwwwLIWTxFNHZCOLwHLwwe9L/nSaqBZ4xQO0KQe9Jo7F776rU0uqivmEBaqV9RVKZRZq3/dXSGpdribHs3pbHotJxl2mJPCf2G12lwQ+q2zzdsBGYUgYC8fgNsKysn/C3OfZ6+YHofBUGrTyZDXDQQqGcnmuKVncP0+70gB0ThYV/lk/9a9M/ucLKYapHMu1K3Z5NGC2eAh1VVbNO0bIkq+a9kvrTfc9Bjri5Q== 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:24 +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:24 +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 08/10] iommu/arm-smmu-v3: Shrink the cdtab l1_desc array Date: Mon, 10 Jun 2024 21:31:17 -0300 Message-ID: <8-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0430.namprd13.prod.outlook.com (2603:10b6:208:2c3::15) 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: 40d4dae7-b0aa-4f69-b320-08dc89add15f 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: bijEDcsa+hteKbSqkUoxCpLkQe6vbjhUOOYnNIYaUQEes6Mf3ZMDgY4Mm028cBMsbK7nEySXnhJqnwFsFZdtGrYD09W+iCpPlBY75CN8Usklu5N3q6lSr0vuSiSeaBck1lUjYGTxlxICnt5/y0s/hzHeXX89dgqO4njBL8ZzyCqKxV0tJ+IgeVSQ4UPOMhWo4MeWX9bRSJLhlptGkxsiaz5qEmF51qA4R4RxMON2TiMR5QCbXemSJdpJIdeOk1zN4IFQpsWhcm/t8ScJM6bPn1MVgqVwW/4yRyluKqblIVYUVVzmJjPROiwzADvsgNsphozRaxyxR12ZZUZdTILNHLB2IAzDn1d4QMDlbdfU6it9InYtK2+nt9F2RhNQMUB66qy16OC7rEIu0FnTgUcpiJoOn8RABnaL9Ahb+4kc3ZrMoySuXqlE0IPHcWMKvHsAGMId1MUzd5+mi/HZkWxslPiGRKtQqRSMs9txygQU7EkSzGeSDs3UmKjgZv08WPer8Thle/fsdlFQA/kuwDKfgeOafmtpxgEMewO9geX4gjDfwtdlSNzg30SJKW0/YlgS/2i7/qQJYw52YKXGmn8FYMzPGEKcK4ilOWOAMwcPIwjMXDT9kt9maEqlIZYqJcYbHyKufkHM/NGFQOArLg/VU8hHN91z5Qj3P/TRRHEnXhOOjbHarw4gGBpIkTmwW4NCGQssonLBwHqi0BhY2aEQEmrYUuTTeD1pTYWUtdyQyYOZTLdEeIwVWNFqH2omS5ao583eKlC9e3PtTOMvY7s9ip6JawhIwfBYFBQ0o1tYMPkQX4Ow8lqcNxl/BkJxWkSL9a7cPcWPVSj3jPrstOWwtITJjgajbGUz/dtGWjCqNTP6pgceVS7QToJKKqGvkPdvqkDPYBmovkZdRjXl5YOB8dB0h5uSJZ5XQ1oAPMJ56P1eSl0wRsjbKdTc2FzXYfxHFp1aVulOKANlkA6HEgD2tuLk3wF4xZQWrPki+xbP786yRTAK4eWGWviu9tidkBDUAVqlKdQweCTkaXNHvo8xMHKWA8LBNpHmClXtn6xdj7v+XmkwxHk2wQTp+kJX2v1K+gF08HTk2K1eBJSCj1uTvEAxMew4qLVbqZqWeDf7FsrQHBGXUBPhiTgwnC0jOAd9A7Z67CZccvMvoWRcO1SAF2BExfnICeO2yzMBB1f7JO8v/CYYssOcoGbLsO4S7FzdX8W/aTgg/XLG5QJJsmgwvoiwj4aazrdvq4IomQQuvk/G55cJ1dbPj5zQAfrki+WjzCsEKaaTYy2Gdu9AQOsaCMt5p/W5m07i21DPXIHgDCE= 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-MessageData-ChunkCount: 1 X-MS-Exchange-A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I0euXjdj8LJUwK38D3kKlBIOKYRWE0b1HAy2pKWe2/bymV1TJskaOXoOLVgUPqjGDi1dTyP5QH35cFx5XBm2ozROLEmvjyfxsUUqDbZdZnVQKE1akrdRzH2tL1w6p7KMBexsuuVTk5pdvZE1QuMncVYfmbVGOlH/KLX3Igj74w+i8yr11fWTUyMbGLTweTG+2gN6jkouc5HKmXOBPYp3phpt0Hm40xqsb3llEsw8fBQBChbqk1adCobNTQgxkPijXpJhNAUYusdYfRVGral2zr3uGzY9a4MG3T4TDzpVSI9VBsLM/q48SitrAa4D0BFKU8im4Ff2E0TxvIEkjBYs0FqXuLGb97Sosp3plmnc2Jm83wVudHxFJVQVPJu0Evfcbj7DR8tViSne60ignbaWJLKPbWzMVoGNBlGo7kVS1ge8TDFJ9UybxJe7jw6+CxaQ9ZJY0QzPMVtFeab+EfW2zKfzTjXopPmdOghLUfkx3g0CG84R61A1W4gd6+tP2Wjs= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 40d4dae7-b0aa-4f69-b320-08dc89add15f 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:21.5952 (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: URS46DxxPQiYF7gSY/tRRZjMIa8doHCMDWnRdUIoKJRQFPJXSJTUxkOIwbJnseUA X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8565 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240610_173133_881785_987E655C X-CRM114-Status: GOOD ( 13.71 ) 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. Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen --- 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 6245e2558e6a6a..dd65e27aebafd4 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1167,31 +1167,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) { @@ -1231,13 +1219,17 @@ 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); } @@ -1415,7 +1407,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 3862f6e65c770e..2f7d70d92b1f31 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -603,7 +603,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 {