From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67B9C606A322 for ; Fri, 4 Dec 2026 21:09:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=C5YuzrLg; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=h4l+b4aJ 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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:CC:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=o+A94oS+xgGZEz1yQRDsrUzZWjtyet/2wf+ig2h5yEU=; b=C5YuzrLgrvqtkiPxLYtqyWFX0y xuMF4HXp6QWtKvIbN5G5OX5+5Aa3Sv7FeO+i1b4XymCNPI+oFdoTXiQ0GoWPKNTUNDoXrU1LxdpU8 UgPO96zlFvKMUu3KVk0j4g4Pb4bv1z91q0v6Tfvd88OLHWlmKS07ZyfEAUuQdVAKxMaCi71XHWVT6 WckIHM+qRhsp6zropPCG6Rv23WHTOQyavX9bl94KE/M4TQpwXjrae94iMjNM0omOiG1RWSR80McKQ V00t1SxSdsqZxtwRcOW6OaGPbEGeDfvHHlbtdyLpnofZ5jwp6ANFgaDHHV3CAkQk+8IBHpw9XBa4i QGjzIKIA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZaWv-00000001VK1-3QwF; Fri, 04 Dec 2026 21:09:21 +0000 Received: from mail-northcentralusazon11012020.outbound.protection.outlook.com ([40.107.200.20] helo=CH5PR02CU005.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZaWr-00000001VJR-29lC for linux-arm-kernel@lists.infradead.org; Fri, 04 Dec 2026 21:09:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=krWVJPqNJE6Q3fmNf9WlnbIGUKfzSPnPuFL/DpqJqVJOqfG6N+mHbLECF/gPXtBHKVhqUvmDsz26kmbZlphklLqrkaraNvbmusrbvr3QQAEPkevKW2A+fzN19uAOB4rfPegmW+HE6cGSdIr0V1DmkdP4KINHe72tAy0GrPjSX2E8tF1OYUWoIxlN7YEVggR/p9TuKF0YnIygIwB50Axjn2BpNuN1ubJUiYZdAX+awx56EEQQRDRT83hytKznl2EsubUZg1w4iyxRzZb+p4RStxRUpYmba7Aw9Y+rJBlCdM6xGQEkOWkDVZCTsj//V2LtzGJTdmvFKQJxPC4/C8zOQw== 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=o+A94oS+xgGZEz1yQRDsrUzZWjtyet/2wf+ig2h5yEU=; b=ZFoFIPFRhp6vL9bVuHYneSID0a2HPmO2R92AXaZrUooQKUjYayPZh+1H+D6xPWYhMTIMOOIuHip8sBpBZjUyhs2N+rilZITx3i4vj0ojlJOm2zSo+2UCZ2FvNEJKffjpIq7+zFN44zc5PUf/yTiXvDvGy/hxCkgzt58VHQdKjHu2GUz4lKhi0RbL2gdtAlAzBmdEzDfd52lffPEjnKulN2D2/fYDJmLCP6q5foKYXMreocrEjl8uk0oc1hahofDJvbgKNZerSOozfIhYLWkXQ7FZZ/eFtmYLP9lYl5QZSqoBFf6QVN8ef7yF7scc3lvbpq+onrXfzXoTgHb19gpG0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=lists.linux.dev smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=o+A94oS+xgGZEz1yQRDsrUzZWjtyet/2wf+ig2h5yEU=; b=h4l+b4aJJ5T6axvzT4LuVbw4U9vZBYcAD7W0FA10RA5+JDsdCOPyF13yz4NkSd2q6hCn6y+yLa1xu6El88+T/xjURKatz6tJEGAk82b8XZiSksZ+Itta8+2nXsKsCUOc1u4YN45FwzDsbMtO5t2jE+tA3qqqqQNRj4qWNoqwKMIRh05JlIMUqlCwRIT45NCOQNSceBM/TDLZcIToU+WGmRtyMXBX7K37wt2/p010RF0dPf15iLLeJYLmuyHg4hFB2TuTUBwYpMe4SCxPMj6dj4M8ysZ4KhNiBMlG5Stj8cIIMKhpHwJbptYg67P69cYZBaM5GY2TonA4QtErPa04/Q== Received: from CH2PR20CA0029.namprd20.prod.outlook.com (2603:10b6:610:58::39) by LV8PR12MB9208.namprd12.prod.outlook.com (2603:10b6:408:182::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.11; Fri, 4 Dec 2026 21:09:06 +0000 Received: from CH2PEPF00016D47.namprd02.prod.outlook.com (2603:10b6:610:58:cafe::52) by CH2PR20CA0029.outlook.office365.com (2603:10b6:610:58::39) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.13 via Frontend Transport; Fri, 4 Dec 2026 21:09:06 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CH2PEPF00016D47.mail.protection.outlook.com (10.167.244.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.709.6 via Frontend Transport; Fri, 4 Dec 2026 21:09:06 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Fri, 4 Dec 2026 13:08:46 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Fri, 4 Dec 2026 13:08:46 -0800 Received: from nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57 via Frontend Transport; Fri, 4 Dec 2026 13:08:44 -0800 Date: Fri, 4 Dec 2026 13:08:43 -0800 From: Nicolin Chen To: Jason Gunthorpe CC: , "Joerg Roedel (AMD)" , Jean-Philippe Brucker , , Robin Murphy , Will Deacon , David Matlack , "John Garry" , Pasha Tatashin , , Pranjal Shrivastava , "Samiullah Khawaja" , Mostafa Saleh Subject: Re: [PATCH v3 08/13] iommupt/armv8: Implement the iommu specific components Message-ID: References: <0-v3-97feb2edfbab+748d0a-iommupt_armv8_jgg@nvidia.com> <8-v3-97feb2edfbab+748d0a-iommupt_armv8_jgg@nvidia.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <8-v3-97feb2edfbab+748d0a-iommupt_armv8_jgg@nvidia.com> X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00016D47:EE_|LV8PR12MB9208:EE_ X-MS-Office365-Filtering-Correlation-Id: 8b5b338b-67c6-4d83-a071-08df524ad528 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|376014|7416014|23010399003|82310400026|1800799024|11063799006|56012099006|261028144727099003|261026140227099003|261021121427099003|261102123227099003|10067099003|261009223027099003|261021135927099003|261022075727099003|261026121527099003|261022105027099003|18002099003|22082099003|4143699003|6133799003; X-Microsoft-Antispam-Message-Info: 3FGvqgLPpryyMHka6MxfamERfkLx6efTXe9y0EOIWK71vKgBP3hQrCEmL7uIvSBsK6s+qIzYELKkZCytzTTUMffEQyXWNnpJzItHdjLfCTYjLLZ+MvXcQH5HrWm7y6IRSzhLH9cDKDajErq2/SMk049DIlRxVnDJc5B/NSw/pEEddYl4e78+uoltp6/3FoJu++d9BlmT6H+xPAdz+3BuoDOPTnl5TquNZB+dtQaV6v3u8b+6FatSk4009tbYgOwcJ85vReYBEeSdo/YM/sU7JrXnnTuH7tEjKXiiDbjypp696UO80V2S4q6IaQ0PO1SFXeYcY05s7tTWAxUVtW4r1Is/t+FLsdx+CMyDgLOL87Jpk+aC38xfU+iaJdR/jzkByTClVc01ffU6Jfv/1yzunu5H4FyYMliGL4AB/1/v0zX9ZXNX+JgmnyB6XXeT3IGRWCYoK3jM+I6E0RRY8uIKFZCfG/vOIMOdi5ynxs3MAHR56px9UrGdUJcTQdnMwLP3ozbjmkZv71HaP8GlnUzJbvsrUEJx9N5WLhy8dAo+e9qQZVeyig4qoT2qlNIdgGaTifbbvjlKYOFg4YwsNFxnDZ4TXlCZ2wXWZ41oX9pZEb17BpCsXzSAbFV2thXWZ4P9X7oO35dmWv+us1PHcMuVOWKnyEziiBpuXZ2eyNLG1ry4XJP7a76h/uUbfxqJOPS55b0mk65hbDo+taSVp4ZrPw== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(36860700016)(376014)(7416014)(23010399003)(82310400026)(1800799024)(11063799006)(56012099006)(261028144727099003)(261026140227099003)(261021121427099003)(261102123227099003)(10067099003)(261009223027099003)(261021135927099003)(261022075727099003)(261026121527099003)(261022105027099003)(18002099003)(22082099003)(4143699003)(6133799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ll/h0rDZxaTt0byMO/0nNwMK06E/OIZoCJH8aQQpHWxoCETuzjTiKSZ5GhVgIWsk6C9sAK7jqiLHBgoSE1kLtgYvyzkcRQik1+RHy+9qZDkyDLMgHvU3MpX/mEc81wHDSVnMxpP9W9QgDnvv7UqEa24XC3FNubAEuH5GJClE3xblTDcqKBZSxQ/nnLRE8bwMMCz3qaQRGfLSyQUL6D2YC9RuTBaVpJE6oXoWSnnBkc1FD4eAeibw8VQ5qjIeeWB2M5Kc0xurqdJlofN6lI3+IC0Eov1qY+DUZRbEpzS4r83oAEhyvj5FQPJ/QwU8bK6jjuyUwrBdHwNXNFcgSd5U1K31EJzXxmWfFiV9FbKd4p+c9lbCm3uj4TA+wpOCW4AuZpJJF65Vm9Ekr4H11MnsWn2vxvFzqS71nnSDLyPbVsVSoxhSUNSgNI5fqI711rEp X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2026 21:09:06.5640 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8b5b338b-67c6-4d83-a071-08df524ad528 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00016D47.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9208 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261204_130917_757524_2A4D0AB8 X-CRM114-Status: GOOD ( 29.25 ) X-Spam-Score: -2.2 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-6.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Sun, Nov 15, 2026 at 07:30:38PM -0400, Jason Gunthorpe wrote: > The iommu page table is built on top of the generic components, add the > peices required to turn that on for ARMv8 s/peices/pieces > - Makefile and kconfig > - pt_iommu_* functions for ARMv8, including the complicated > initialization of the level and structure from a typical pt_iommu cfg > - pt_iommu_hw_info to return the field values program into the STE > - 12 kunit patterns covering a range of operating modes > > Include an inline helper pt_iommu_armv8_choose_granule_lg2sz() that does > similar to what iopgtbl does to select an appropriate translation granule s/iopgtbl/io-pgtble-arm > +config IOMMU_PT_ARMV8 > + tristate "IOMMU page table for 64 bit ARMv8" > + depends on !GENERIC_ATOMIC64 # for cmpxchg64 > + help > + iommu_domain implementation for the ARMv8 VMSAv8-64 and the VMSAv8-32 > + long descriptor pagetable format. This format supports both stage-1 > + and stage-2, as well as address spaces up to 48-bits in size with I see this patch supports 52 bits. > +static inline void armv8pt_s2_validate_level(unsigned int top_level, > + unsigned int tgsz_lg2, > + unsigned int vasz_lg2, bool lpa2) > +{ > + unsigned int max_top_level; > + > + switch (tgsz_lg2) { > + case SZLG2_4K: > + if (lpa2) > + max_top_level = > + vasz_lg2 >= 52 ? > + ARMLn1 : > + (vasz_lg2 >= 44 ? ARML0 : ARML1); > + else > + max_top_level = vasz_lg2 >= 44 ? ARML0 : ARML1; > + break; > + case SZLG2_16K: /* ARM level 1 requires PA >= 42 */ > + max_top_level = vasz_lg2 >= 42 ? ARML1 : ARML2; max_top_level can be 0 in 16K when vasz_lg2 >= 52. > +static inline int armv8pt_iommu_fmt_init(struct pt_iommu_armv8 *iommu_table, > + const struct pt_iommu_armv8_cfg *cfg) > +{ [...] > + /* > + * R_SRKBC: For the 4KB granule, an initial lookup level of 3 is > + * only supported if FEAT_TTST is implemented. See Table D8-9 and > + * Table D8-24. FEAT_TTST is not supported. > + */ > + if (pt_feature(&armv8pt->common, PT_FEAT_ARMV8_S2) && > + tgsz_lg2 == SZLG2_4K && levels == 1) > + return -EINVAL; > + > + /* > + * D8.2.2: Always use the S2 concatenated tables feature (I_TDMHR) > + * to fold a top level of up to 16 tables into the next lower > + * level. Since FEAT_TTST is not supported single level cannot be > + * selected here either. Notice that there are a number of cases > + * in the spec that require concatenated tables (eg R_DXBSH), > + * since this always uses them it is OK. See commit 4dcac8407fe1 > + * ("iommu/io-pgtable-arm: Fix stage-2 concatenation with 16K") > + */ > + if (!pt_feature(&armv8pt->common, PT_FEAT_DYNAMIC_TOP) && > + pt_feature(&armv8pt->common, PT_FEAT_ARMV8_S2) && levels > 1) { > + unsigned int topsz_lg2 = > + vasz_lg2 - (tgsz_lg2 + (tgsz_lg2 - ilog2(sizeof(u64))) * > + (levels - 1)); > + if (topsz_lg2 <= ilog2(16)) > + levels--; > + } Should we move the "levels == 1" test (R_SRKBC) after concatenation? > +static inline void > +armv8pt_iommu_fmt_hw_info(struct pt_iommu_armv8 *table, > + const struct pt_range *top_range, > + struct pt_iommu_armv8_hw_info *info) > +{ [...] > + if (pt_feature(common, PT_FEAT_ARMV8_S2)) { > + /* > + * STE S2SL0/S2SL2: Starting level in VTCR_EL2.SL0/SL2 > + * encoding. Table from D24.2.210 SL0: > + * > + * 4K: top_level ARMLx S2SL0 S2SL2 > + * 1 ARML2 0 0 > + * 2 ARML1 1 0 > + * 3 ARML0 2 0 > + * 4 ARMLn1 0 1 (FEAT_LPA2) > + * > + * 16K/64K: > + * 0 ARML3 0 > + * 1 ARML2 1 > + * 2 ARML1 2 Is this missing (or on purpose): * 3 ARML0 3 (16K; FEAT_LPA2) ? > + */ > + info->s2.sl2 = 0; > + if (tgsz_lg2 == SZLG2_4K) { > + if (top_range->top_level == ARMLn1) { > + info->s2.sl0 = 0; > + info->s2.sl2 = 1; > + } else { > + info->s2.sl0 = top_range->top_level - 1; Though it's not in the list above, top_level can be 0 (ARML3) for 4K, right? Would 0 - 1 underflow here? > +#if defined(GENERIC_PT_KUNIT) > +static const struct pt_iommu_armv8_cfg armv8_kunit_fmt_cfgs[] = { > + /* > + * See R_DXBSH: 16K granule + 48-bit S2 is required to start at level 1 > + * with 2 concatenated tables. > + */ > + [4] = { .tgsz_lg2 = 14, > + .common.features = BIT(PT_FEAT_ARMV8_S2), > + .common.hw_max_oasz_lg2 = 48, > + .common.hw_max_vasz_lg2 = 48 }, > + [5] = { .tgsz_lg2 = 14, > + .common.features = BIT(PT_FEAT_ARMV8_TTBR1), > + .common.hw_max_oasz_lg2 = 48, > + .common.hw_max_vasz_lg2 = 48 }, > + /* 64K granule */ > + [6] = { .tgsz_lg2 = 16, > + .common.features = BIT(PT_FEAT_ARMV8_DBM), > + .common.hw_max_oasz_lg2 = 48, > + .common.hw_max_vasz_lg2 = 48 }, > + [7] = { .tgsz_lg2 = 16, > + .common.features = BIT(PT_FEAT_ARMV8_S2), > + .common.hw_max_oasz_lg2 = 48, > + .common.hw_max_vasz_lg2 = 48 }, > + [8] = { .tgsz_lg2 = 16, > + .common.features = BIT(PT_FEAT_ARMV8_TTBR1), > + .common.hw_max_oasz_lg2 = 48, > + .common.hw_max_vasz_lg2 = 48 }, > + /* S2 concatenated table configurations at smaller IPA sizes */ > + [9] = { .tgsz_lg2 = 12, > + .common.features = BIT(PT_FEAT_ARMV8_S2), > + .common.hw_max_oasz_lg2 = 40, > + .common.hw_max_vasz_lg2 = 40 }, > + [10] = { .tgsz_lg2 = 12, > + .common.features = BIT(PT_FEAT_ARMV8_S2), > + .common.hw_max_oasz_lg2 = 42, > + .common.hw_max_vasz_lg2 = 42 }, > + [11] = { .tgsz_lg2 = 14, > + .common.features = BIT(PT_FEAT_ARMV8_S2), > + .common.hw_max_oasz_lg2 = 40, > + .common.hw_max_vasz_lg2 = 40 }, > +}; Would it be worth adding a 52-bit coverage with PT_FEAT_ARMV8_LPA2? Nicolin