From patchwork Mon Jun 3 22:31:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684460 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 B1553C25B75 for ; Mon, 3 Jun 2024 22:47:52 +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=AjwXwVQA0oDNk/XtD32tYNfsyWfxbtH8U4MJUpp3ERs=; b=D6iQ0L1/qCTimr pj4trKjF3zgrnRiuD7Z31j2MU9LbZSn0e6GT+/Xwo/slZ7w15dwog2akk5f+j4LDzKQhfEI4i4nDe YlpEjJ3YWOvNgCYIGHN7SdBIzn05mkPpQ3F8hf8vbsHzG1LuPLIKaCXjp+U/3FC57yEdnZpb1WZvW m73to5ZrHzlKhkDCJnC3jHThN0j1ZctRdb3jJ1oHxd1bTIuQjDIV7P+X8y2Y8kVbE6vPKm/P6H2mQ 0F9afRmHcJJw13sLR4rDoK8q8PzaLw0BnRsta0iJfqRQ1Y4m9R6s1MA3z0A+5XpE4LS+VRg3+F8ED vXjZfIdr1MT4haoeVShg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEGSs-00000000Y2b-14tg; Mon, 03 Jun 2024 22:47:42 +0000 Received: from mail-bn8nam04on20601.outbound.protection.outlook.com ([2a01:111:f403:2408::601] helo=NAM04-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEGSp-00000000Y01-05WE for linux-arm-kernel@lists.infradead.org; Mon, 03 Jun 2024 22:47:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HvYdLiXofMsYz2n1/eQ21KdA1cTINSIyjootUsWGEUNE1Ss6YJQ41oNWI5vLF6RX6+Z1rdT6HpzjmePzxkTs8fDgeaF2XDwXELwZzP2ZuPxYyemFbcirzd0hWjclgnkbMgQuT4iKdxhtAaycTVDX1fJxtof2G3joIwfhMaYvqxEmhL/IdvX3HiriLaMetGaWT1qqRv4OzoAtcuECCbjQhi1GT5JlGUraVxQ6+0gzqU/xmKNQq7npfTbaVgEMIr04xp2XedU5vtkc02Y41v1A7/Js/N2N+9z1CotfeOGQGdIVjXL6xmhUr9mFDnrSY4tAljesSEIQ+SHMseds97hMTg== 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=qCVi2xl8orchsUFQicYXMk+Odlf8xzCNbGmii+6RcZY=; b=TdOXjZ8SFexy7L9lJQgSS4QBtZVSHXDLB6SE5NeQTEy5u2mj/zbW9YYLyxOvhkE4ZYLJU19J9c8ioRu1rxoc0vmEYGcICVIcAC19j2pDa4OO0/NZe7iZLYlFpkgHDwo/H3KPVm0OdQZAMScsDfD2/xxA8IEcc6qfvcmlUmGUbVlDBUYF9LhE7tkj/QImIXUsXWE2eOYzAcGxQF828oWq6tekaXGbqV2sWwSupzrOESKgWTOHZ1w/iNoiobGDNDL6dMpITYxNBj9EFkGQB///J44PHq/sBi8pe5UjD32uR1Y2GADDOqO4qSi2S+3ENQGBcJlnA6DQHdJMECG79RoQjA== 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=qCVi2xl8orchsUFQicYXMk+Odlf8xzCNbGmii+6RcZY=; b=qitLtzbtasCVYEyHTWDNJcsGTTYsZiU1cgIMxC8iUisnTjGHpSOSYNdt9PKld572si+RnYA6YLYFNyBd7yBQjY/nUOoTdshSz3V+WjyO9stg2vLkCjDoZNZIOV31paCao3M2dNxnKJikmoIwZyayKpXOxseyMk69zWrVMEeSLUpcwkAs9h55P1gTuCqyZHs+5JW/H5H1J71/DnKLrR5MYtQqP4JdsIV+r6m1tfzv4n1KkxEdKuyjESCIZrH0f2Ei65i6IIoyBsaTNc3b1C3KDHhQ/7Q+Ig3ocyp0p/0NBq7S6m75KNrcw1oqSl810R9N3fbSkSq34wtXmEiiQZ6Vzg== 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 MW4PR12MB6778.namprd12.prod.outlook.com (2603:10b6:303:1e8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.25; Mon, 3 Jun 2024 22:31:38 +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.021; Mon, 3 Jun 2024 22:31:38 +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 6/7] iommu/arm-smmu-v3: Shrink the cdtab l1_desc array Date: Mon, 3 Jun 2024 19:31:32 -0300 Message-ID: <6-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BLAP220CA0006.NAMP220.PROD.OUTLOOK.COM (2603:10b6:208:32c::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_|MW4PR12MB6778:EE_ X-MS-Office365-Filtering-Correlation-Id: ac9e383d-4050-4538-8157-08dc841cee0f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|366007|1800799015; X-Microsoft-Antispam-Message-Info: ExMqfyACUcLJhoY41mw0itTSV3C7NpF2WXjeHYIAlpMmA7VPbrOnAfiudI2rOzOKYHjPl1p5sKwCBRzF9w5e5+zLZWzemnm/+xfVO1EoTWx8MhOe+DCGUnDxqNtbzLNS8SwS/sVnokf9p+5HcYWVjdA+Au/5lFYWMTby3I+vSqIxwGFTzkgDgTH/yw4Z+uZ/WVA/WATMPHkvW5M1DQlCj151PbtD19zQ7qCM9E+AECbVBusvGqWdSY7GMqn6BYvDIOqG1QHqXVeJAzb4D+pbNRGsL0o28hcZmFRv1yBQJPIqYabvBxX88PrwxW4DrFcOvrK6CuDkHobBsP9vBwSlud4Kk2c9RccxHB2m3SKf5lkAtbWev+wlFqRaIQPu02ybEI0471BMPABuSEoZkT6Pvkg+a2BZk74wSMzhziTVdKDfTcjoiBgR3Q5AAHXBmQsWper3qC34OYr3tFiWdsCvzUW3VShzTzVTE0ZRaxEtd42N0WJVN/PBhg+B5C7KBnZ3Cju6vbIl5MZYZVX3g++ectfXkH8cxI8MfCeC20RIvzAFWqlzuP8G4t7mAHjSrYh135qLqMOiL3sDtRyo67zCc/g51dTvkGExJiNCcDwm7L/Oi6FXe2FjXEu7iIvbhMdJwYpTX9x+mlV7+YLa8Mg6WxJtpPurFrABsXluBxwRdFybkNoOZ/qn5hBQE9n1lrPhTgvY5bCTh3T1p0kRZGfIztzeXjF0wIuyJyIqq+iinQ97R1rWoWx+xMZ8xbxMR617X0+v6rN/oRrojIyRvAl+KQ8TkeskSjC7FHNcjVjfec144dTANPkEKXWb9OvcyMlTZdFvWAJe/+QyY5cG7qcKKua/F19tzRLfEzeCzkmu95Xuapf4mNfYD+RSwiVNS8Sse/GBUrmfXk+TuCJ/EYAtmip9ZS1K4hZVgSYcKQJm+8ZYH2U4sb5ga+cmIRHVFyKV/6jwjWXVkthvMbWBOevL4nwD0p2+wEt3Bjj1zpogBc951+knGQkWxM2cU+EvzEat8FXVeqjMB1fkedA6fBBNhu8Y3i+8xdZlB0rQZzPP1dSJlI9wNR82h+AlgP1TOglD0lIqmU8jWaBuBM9QUOOwvdNDmigFZEric9PNA8zg5Fk3LYAy51buTurlQiNc2tU8PgB9ctZUsh3CuOpOxggRFHPCJkNd6UsgFea6rnCxTOXsfBiXbURr+g9x4wXW8D16Rbi6J5toq7twPOER6fIWFTZZRWV79+CQz6F60uk9Yfp6IYSd7zeW3qvKKaW496inlljYRYoH/bHExMtw81sqCA== 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)(366007)(1800799015);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0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L2tVmwpdPUO9ck+5IXvtwNgoms0E1hFhlUVRleL6qRTiKy62eu/+Nr7NCe46aRnJFBrACG5bw3qzvyzSEqlmSYO4WftBTUVd4v8lyYUdgC0GzN4DGStLTKLBRBX5ig9nPbDJJiwIwC3k5BImOfCcMWgR58QKc66Y2Y7kvwrEF+p1Op/AteKuEKzIGLTY2FVPB9Ui3tpm6kI2x4Q20pfHvqJ6KEZcO8cE8IDygYI2pmRqy0q+JpQc1GHX1eMoiq1wAfRdS8q0D/mslZKL0HIPnIZucIZmilzzTuzd0R4K0bt107y9FbEfca8ZVVVSuz5AfnRzXH+MzrAUKOqXP0X8g59gtR4lqaT50ROQZCSLTeBX4vWoQ/TKS3HaaOU07LXprftT4c5J4olOROmXxOHu5AxQ3y1jBOYt44GTa4SOBr8+WEKROj71Smb/aSWq8jUGCZNPwLg7g9f3uC4/7c00gqsC1uD+Sb+MiLdaz1iGrYUK2BWtbzocPYtek53Y= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac9e383d-4050-4538-8157-08dc841cee0f X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2024 22:31:36.8964 (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: z3DdrKnlzJdbuzzyWEI422Uj4XEFHDfTnxJU5eG15Jh8edA6Lj4Xwiayt7IKJXrL X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6778 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_154739_107246_6DB94DD6 X-CRM114-Status: GOOD ( 13.39 ) 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 --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 35 ++++++++++----------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 - 2 files changed, 16 insertions(+), 20 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 3f2e0462433d2d..7a6c9aac4cd450 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1167,28 +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 * sizeof(struct arm_smmu_cd); - - l1_desc->l2ptr = dma_alloc_coherent(smmu->dev, size, - &l1_desc->l2ptr_dma, GFP_KERNEL); - if (!l1_desc->l2ptr) - 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(__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) { @@ -1227,13 +1218,18 @@ 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) { + dma_addr_t l2ptr_dma; __le64 *l1ptr; - 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.l1_desc[idx]; - arm_smmu_write_cd_l1_desc(l1ptr, l1_desc); + arm_smmu_write_cd_l1_desc(l1ptr, l2ptr_dma); /* An invalid L1CD can be cached */ arm_smmu_sync_cd(master, ssid, false); } @@ -1406,7 +1402,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.l1_desc[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 21c1acf34dd29c..1ffe2fdfd3755f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -587,7 +587,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 {