From nobody Wed Dec 17 07:06:06 2025 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2046.outbound.protection.outlook.com [40.107.220.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46CA226773E for ; Wed, 23 Apr 2025 06:50:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745391046; cv=fail; b=Ncm1mgYZ4vug11S/AtAcNuxRybNe/zLVD3FRuxDxorrazVwt9iOTuIMgP4RbnUuQ0lCA1jQxeEjuT2fuMV6BjqZP8sipZiyIvW4FWM0+kmqW9rsk/l8i1NyeDJLy4hoFmwz9hkTRGVqlzGrVpq76RZF20QjAyus+8bVTdWjS7/Y= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745391046; c=relaxed/simple; bh=9NOpn8AI7yYrbf9di1YfrFXDbGP7f7KtMEGOkp09aJ4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Tt50syxNpreQOXWxQFrqHaqD9whtXclIgtby2PjP4oShTv3i/cn4DZzsphdc9RQtiAc8zBJXkHQi9UmQNTD6/dO2Kw7A54dDiItG+yalX3k9xEKnUihslcOBixCOM57NGGfFuD37I2D5aFzHWUgo0V3BSsk0jlF0nlW0GNknMyY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=AP+3yWtZ; arc=fail smtp.client-ip=40.107.220.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="AP+3yWtZ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Qa3YOvPZub3scIZx7uQiUBGz6/ruXLqMs2ZkCGuedIvTgLWDjmNIILdkYpZiIlsTniH0/CwFiKeeJPhtpr9C9j7EIKV3U8CezJ+Vojo+qNyFX3z0nIqw06GPrTOb3eoOKxl3XUEZ+FRr3FKglNDtgx/PHDzr1AeQtsRzhzkStc8LbwoWmjqG9rN02VPTcgYbFKBsti5JF6OQyeJzqvkE2LA67PDSmst4rfIA8EqQh7jsHRbZVm6tZOTKLkkEAh1K7E1mYtEFs8aBJmU9cULArC3kw5y8IrQJ5PfzWkMqyOdcHY6URBR3kddND+vYU1BvE7Sc/pRrfl1rRgm0Vq0Zng== 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=Cgl9wq2Z0sQ1jt/ttNu1qEAKgbK+V2h2Qw6KTg1nom4=; b=CbQjordVeySBraquL7IYFi8yJ++y0mBLO793TD8wJFvcWI0T5AtsNS1X0GmMYVJ4yY9PYYuClbkp+w5LpAdVpoXet13ESPgP6qwlzb16HjbOMGSZ12kj1/9bGMVtEogZJk5rud9u4LFOBGhogp++DDLETq9nwC2zHCkBclMNi1nxQyEYycachqIOAcQahU5xDPDvvUgH9CpLFTDT5XApwPKRnHxLiVibyTwZmHQdH20VwgHvaRCVOE2rsLesR/mutx/vDXw6OpHaOgpxs10QCt2vZhfbPl1yVMOn7gejRDin0PN5G47m42WpxxbCiIfnn9Vj9HKu37bsKQrYzklOAw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.linux.dev smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Cgl9wq2Z0sQ1jt/ttNu1qEAKgbK+V2h2Qw6KTg1nom4=; b=AP+3yWtZm8c7vlZxbrPkkRtrJLEW+KI3yk1ClJkbrTpRk8pH/YP9oiLMnxSEz4WAkeY912SOCwJttgOvW+e54IcaBgRGEyBr6upi+kIRuNXrPoh3oHnbExL8ZRma2jbqNO5hnTyb5qHGucj58370BLlWZqak+uIWbWhzFzMICic= Received: from DS7PR03CA0203.namprd03.prod.outlook.com (2603:10b6:5:3b6::28) by SJ2PR12MB8848.namprd12.prod.outlook.com (2603:10b6:a03:537::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.35; Wed, 23 Apr 2025 06:50:39 +0000 Received: from DS3PEPF000099D5.namprd04.prod.outlook.com (2603:10b6:5:3b6:cafe::c2) by DS7PR03CA0203.outlook.office365.com (2603:10b6:5:3b6::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.37 via Frontend Transport; Wed, 23 Apr 2025 06:50:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099D5.mail.protection.outlook.com (10.167.17.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8655.12 via Frontend Transport; Wed, 23 Apr 2025 06:50:38 +0000 Received: from BLRANKISONI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 23 Apr 2025 01:50:35 -0500 From: Ankit Soni To: CC: , , , , Subject: [PATCH 1/2] iommu/amd: Add HATDis feature support Date: Wed, 23 Apr 2025 06:50:02 +0000 Message-ID: <6282a5c349812a311a67a8522dc5e4aabfe3ec3a.1745389415.git.Ankit.Soni@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D5:EE_|SJ2PR12MB8848:EE_ X-MS-Office365-Filtering-Correlation-Id: e022233b-7238-404f-340c-08dd82332834 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|376014|36860700013|13003099007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?sbzjOLE3iG8EsElc2wsbojkr/ARWeYvWVdfGgrp03fYkdGLYLmDXR31sqo7P?= =?us-ascii?Q?aFPw5OoyKKVc+vqOkrr8rpwLc1xGZA0RO5bI0e5nodpR+ngEsowiv4gX8gMi?= =?us-ascii?Q?NBUIqSf7pZrqnzK9ZKTn/uI3bvihfWUkoPIA3ZiudFehr69rtaRVenKvdfin?= =?us-ascii?Q?xz75qt72mZGud/68lHEnmPe1jmQJ/xoLRAi2f1U+vJz3/FpZBmCGo3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VGaLBEB8Xzrj4oRIAY2zoU84P7h?= =?us-ascii?Q?6dx6+TrO9DzXTUVG4+/MoZqDjxO87/wNSo5Ie61NnugV52/+VU/PJv1izmYr?= =?us-ascii?Q?/lYlGQHX/FjXxsWGsV3wSEsuNRWRXhd4Sz4KAoTOEjJ6//XOVofv6F4EVD8x?= =?us-ascii?Q?LAu3lasulCmnKHGX3YsSTW+71KjB2hWklv45T2cXlM/utS5hiPT+vnqboFuY?= =?us-ascii?Q?+dIJomSY9L+UnKDRTYIP/JTYQC/MbDmibvhgoML3UFH7nldM5vHpn4PoXZ5S?= =?us-ascii?Q?+zCfpGlNTYwtocC6BkbbHl47L9eTkWgn7+f0uGY7TOGDVJ6HQHcfGg1wd0WN?= =?us-ascii?Q?hKgI3xc7pR8zg6NON9u9z/y+eP0oTBW+iNEc7pvWjREusI1O34EIlx6vQVC2?= =?us-ascii?Q?GdC4+Z6DoL/TTEx5Ad4HCsTs8dwuyVymcqsc/hcwfsDSvcD99PJHg4giRg?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(376014)(36860700013)(13003099007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2025 06:50:38.5150 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e022233b-7238-404f-340c-08dd82332834 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099D5.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8848 Content-Type: text/plain; charset="utf-8" Current AMD IOMMU assumes Host Address Translation (HAT) is always supported, and Linux kernel enables this capability by default. However, in case of emulated and virtualized IOMMU, this might not be the case. For example,current QEMU-emulated AMD vIOMMU does not support host translation for VFIO pass-through device, but the interrupt remapping support is required for x2APIC (i.e. kvm-msi-ext-dest-id is also not supported by the guest OS). This would require the guest kernel to boot with guest kernel option iommu=3Dpt to by-pass the initialization of host (v1) table. The AMD I/O Virtualization Technology (IOMMU) Specification Rev 3.10 [1] introduces a new flag 'HATDis' in the IVHD 11h IOMMU attributes to indicate that HAT is not supported on a particular IOMMU instance. Therefore, modifies the AMD IOMMU driver to detect the new HATDis attributes, and disable host translation and switch to use guest translation if it is available. Otherwise, the driver will disable DMA translation. [1] https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/sp= ecifications/48882_IOMMU.pdf Reviewed-by: Suravee Suthikulpanit Signed-off-by: Ankit Soni --- drivers/iommu/amd/amd_iommu.h | 1 + drivers/iommu/amd/amd_iommu_types.h | 6 +++++- drivers/iommu/amd/init.c | 23 +++++++++++++++++++++-- drivers/iommu/amd/iommu.c | 13 +++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 220c598b7e14..bb14c4800dd0 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -43,6 +43,7 @@ extern int amd_iommu_guest_ir; extern enum protection_domain_mode amd_iommu_pgtable; extern int amd_iommu_gpt_level; extern unsigned long amd_iommu_pgsize_bitmap; +extern bool amd_iommu_hatdis; =20 /* Protection domain ops */ void amd_iommu_init_identity_domain(void); diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_io= mmu_types.h index 5089b58e528a..284ff4309660 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -460,6 +460,9 @@ /* IOMMU Feature Reporting Field (for IVHD type 10h */ #define IOMMU_FEAT_GASUP_SHIFT 6 =20 +/* IOMMU HATDIS for IVHD type 11h and 40h */ +#define IOMMU_IVHD_ATTR_HATDIS_SHIFT 0 + /* IOMMU Extended Feature Register (EFR) */ #define IOMMU_EFR_XTSUP_SHIFT 2 #define IOMMU_EFR_GASUP_SHIFT 7 @@ -558,7 +561,8 @@ struct amd_io_pgtable { }; =20 enum protection_domain_mode { - PD_MODE_V1 =3D 1, + PD_MODE_NONE, + PD_MODE_V1, PD_MODE_V2, }; =20 diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index dd9e26b7b718..f71b236c2af2 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -151,7 +151,7 @@ struct ivmd_header { bool amd_iommu_dump; bool amd_iommu_irq_remap __read_mostly; =20 -enum protection_domain_mode amd_iommu_pgtable =3D PD_MODE_V1; +enum protection_domain_mode amd_iommu_pgtable =3D PD_MODE_NONE; /* Guest page table level */ int amd_iommu_gpt_level =3D PAGE_MODE_4_LEVEL; =20 @@ -168,6 +168,9 @@ static int amd_iommu_target_ivhd_type; u64 amd_iommu_efr; u64 amd_iommu_efr2; =20 +/* dma translation not supported*/ +bool amd_iommu_hatdis; + /* SNP is enabled on the system? */ bool amd_iommu_snp_en; EXPORT_SYMBOL(amd_iommu_snp_en); @@ -1798,6 +1801,11 @@ static int __init init_iommu_one(struct amd_iommu *i= ommu, struct ivhd_header *h, if (h->efr_reg & BIT(IOMMU_EFR_XTSUP_SHIFT)) amd_iommu_xt_mode =3D IRQ_REMAP_X2APIC_MODE; =20 + if (h->efr_attr & BIT(IOMMU_IVHD_ATTR_HATDIS_SHIFT)) { + pr_warn_once("Host Address Translation is not supported.\n"); + amd_iommu_hatdis =3D true; + } + early_iommu_features_init(iommu, h); =20 break; @@ -2582,7 +2590,7 @@ static void init_device_table_dma(struct amd_iommu_pc= i_seg *pci_seg) u32 devid; struct dev_table_entry *dev_table =3D pci_seg->dev_table; =20 - if (dev_table =3D=3D NULL) + if (!dev_table || amd_iommu_pgtable =3D=3D PD_MODE_NONE) return; =20 for (devid =3D 0; devid <=3D pci_seg->last_bdf; ++devid) { @@ -3095,6 +3103,17 @@ static int __init early_amd_iommu_init(void) } } =20 + if (amd_iommu_hatdis) { + if (amd_iommu_v2_pgtbl_supported()) + amd_iommu_pgtable =3D PD_MODE_V2; + } else if (amd_iommu_pgtable =3D=3D PD_MODE_NONE) + /* + * If v1 page table is supported (i.e., amd_iommu_hatdis =3D=3D 0) + * and page table type is not specified in command line, then + * use v1 page table. + */ + amd_iommu_pgtable =3D PD_MODE_V1; + /* Disable any previously enabled IOMMUs */ if (!is_kdump_kernel() || amd_iommu_disabled) disable_iommus(); diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index be8761bbef0f..0ebc264726da 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2393,6 +2393,13 @@ static struct iommu_device *amd_iommu_probe_device(s= truct device *dev) pci_max_pasids(to_pci_dev(dev))); } =20 + if (amd_iommu_pgtable =3D=3D PD_MODE_NONE) { + pr_warn_once("%s: DMA translation not supported by iommu.\n", + __func__); + iommu_dev =3D ERR_PTR(-ENODEV); + goto out_err; + } + out_err: =20 iommu_completion_wait(iommu); @@ -2480,6 +2487,9 @@ static int pdom_setup_pgtable(struct protection_domai= n *domain, case PD_MODE_V2: fmt =3D AMD_IOMMU_V2; break; + case PD_MODE_NONE: + WARN_ON_ONCE(1); + return -EPERM; } =20 domain->iop.pgtbl.cfg.amd.nid =3D dev_to_node(dev); @@ -2501,6 +2511,9 @@ static inline u64 dma_max_address(enum protection_dom= ain_mode pgtable) =20 static bool amd_iommu_hd_support(struct amd_iommu *iommu) { + if (amd_iommu_hatdis) + return false; + return iommu && (iommu->features & FEATURE_HDSUP); } =20 --=20 2.43.0 From nobody Wed Dec 17 07:06:06 2025 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2043.outbound.protection.outlook.com [40.107.100.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA7A2274FDF for ; Wed, 23 Apr 2025 06:50:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745391059; cv=fail; b=bVTHDx/CynaXqAUv7QBVZCuPIv3xDNren4Zen8hepvpThj+14TonpRKbeTpzvHGlwXgKQ0fFuqh2pTx08IEs7Ww/Cj4CEa69fVOGT7lOfZPp0hGSYnaQTTHyLEROR+n6Kl6CX/IDbhVLGY0fHlg2am6NQtgjt8xp1vNQpIzcy88= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745391059; c=relaxed/simple; bh=CGXF527jwST44nhOoAZmnIgYp+YjbqbrkPBOCQV5BUw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Zom2TIebGjVgP3Bfq/1m2o5ZilcWAidB5gZtllDwG8BVQnEMK6APgIaygrgaQjthmB7YO5LcGHgdmBhuaHY53jaIbKlr+7EX+yHRciu3hbbzJ00P281UkrvajgP+zAtCJ0M4SlOPpcGZkgHwo7rAKOwETqoJN6vSdfkRtlHfhGk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=o79OWXYz; arc=fail smtp.client-ip=40.107.100.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="o79OWXYz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=W2N/sZTadGzw8DWVa00pr8T3MD50IowZwM+P5J/BqyLsKWn0RMbTxk6ti8bk3Yec30thS10k8eE+sGiZoiNVHc/aoxe2/AJGLvBZYDhKbWOjiaXQv9vVZvPnri+nhzzuReSVneVTBdr9QF0VCWInKKv8FovW7bsF7jIrDsxP/mwkCZlt/bMTGpz1or8bbtAXzzeKnBO6Yy0sKCZCzkOzNYd5JtLaqFZ68N9VY/iasFghK0ezeSxGyoQNPqSCZHvp7uNxE7QiKD6yYTnq0TZoIo9cH1Ed029VrhoEn19zU6hyCqjNK5tATM0gZhq0Nkzkv2xVVviqHQvpTDDRGAPt6g== 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=G2j7sgfxE4Vpm+CvqSYWdOPuu+4/vjhj8dCllilcVfk=; b=YJ0grSxTG2U8SDh5fTBoz2Aoy7ZVvsX5YNNiwnzfpHSWJaxIOoaMedq8+MsTyJ4SP19lIzBkLl4IaLLgyPgHNPEoJkkUjDZcvwMlaItzHvUSuIvuX/wQnjjihQX0u+ZuE3kOwB+xwlcH88iz+9GtbCJj7+NZx420OXPZ6oLEgu5pgjnFMB/8hT3qFA/5KsT/oxzsk9w7K0mwrRYG9505O09xcN+MF1C5t6vRP0OrGz6zhHNvmIrOW96ENTvXicL94SUnphHTWdqNbhhxRtdjCDXln5yVoTFsPuXj3CqygTGTLAOe6j17H0OqlcwJot920MRoiaq16vXDM3rRpKZehg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.linux.dev smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=G2j7sgfxE4Vpm+CvqSYWdOPuu+4/vjhj8dCllilcVfk=; b=o79OWXYz3UMg/OLgK0YNd3ayleinbvO6SVlDgwNZzPALiZHphdItGKBH/eWZUukEKCR56Xsq5qqqrCClVSjBqlKH5BccfNZWfZj+p2ktGoiedY6jL3abML4DcWQSnjF0JBtTW+jU1WxHhomzELUV3lgoANU2+Ko4rOGKD04IOug= Received: from CH2PR18CA0002.namprd18.prod.outlook.com (2603:10b6:610:4f::12) by IA0PPF84D37DD5C.namprd12.prod.outlook.com (2603:10b6:20f:fc04::bd6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.34; Wed, 23 Apr 2025 06:50:55 +0000 Received: from DS3PEPF000099D8.namprd04.prod.outlook.com (2603:10b6:610:4f:cafe::ec) by CH2PR18CA0002.outlook.office365.com (2603:10b6:610:4f::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.37 via Frontend Transport; Wed, 23 Apr 2025 06:50:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099D8.mail.protection.outlook.com (10.167.17.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8655.12 via Frontend Transport; Wed, 23 Apr 2025 06:50:55 +0000 Received: from BLRANKISONI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 23 Apr 2025 01:50:51 -0500 From: Ankit Soni To: CC: , , , , Subject: [PATCH 2/2] iommu/amd: Add efr[HATS] max v1 page table level Date: Wed, 23 Apr 2025 06:50:03 +0000 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D8:EE_|IA0PPF84D37DD5C:EE_ X-MS-Office365-Filtering-Correlation-Id: e133491d-c662-4316-cfb3-08dd82333231 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?4vrQmtSCwvaZlMU91kIofwqI7IglXf7rNuJodAMoxWLxCUD7VCFgkmt+fWk0?= =?us-ascii?Q?0GobyolvoLUBBPmbatO+/6ZeL5pIP8JALUXyCoaybO43B5fEFGceI1xT/Z3m?= =?us-ascii?Q?WQxFMvC0eACkxL/E+61ttyULnGCu31PNjB2yGff6/+jnhRz96U/7R5gf9hmw?= =?us-ascii?Q?wcSIp+Gl7R4+9m0CiD5SfcSr2R02IpYXopOGhO3ZjQL89Ic4spZXGS/E49Ab?= =?us-ascii?Q?7gg5dkE8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?= =?us-ascii?Q?B3wGslj2ZzU/ENbVmuUlwnRwOxS8A8QEnYw85dKRo7Rew8WTXntt6mjWGHJ6?= =?us-ascii?Q?R4Cfj7DQfuMV60sFDAUiZjZdKM9RsBgz5Tb2OcFfXgsXsbnG1PqC8yEEG7EF?= =?us-ascii?Q?JwTmY9QcC9FXyLt4K1NeStAtvYp3QmWoZj5uQSIstVYEOoJrb2JHC1n6sJAc?= =?us-ascii?Q?6zXvmMFGgnumILBUinTFAShSMCc8CO+EAYHTxdV8iouVisHwseyNtnxr3L8N?= =?us-ascii?Q?itkGUBAqguCec/zWdaf1Ovb6AnMbpRWIKn3IZS+tWMurXzg8YktKPvWM7h15?= =?us-ascii?Q?uG/AWWKYYEPiDc1wiPMilh111UUf8AP6I1q5zM2EV9JB+yUk4UZjKiQIp8Vo?= =?us-ascii?Q?E6EafVZNO/gyzI5ryAg0WchcM4N5YJr8oqqk?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(1800799024)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2025 06:50:55.2609 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e133491d-c662-4316-cfb3-08dd82333231 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099D8.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PPF84D37DD5C Content-Type: text/plain; charset="utf-8" The EFR[HATS] bits indicate maximum host translation level supported by IOMMU. Adding support to set the maximum host page table level as indicated by EFR[HATS]. If the HATS=3D11b (reserved), the driver will attempt to use guest page table for DMA API. Reviewed-by: Suravee Suthikulpanit Signed-off-by: Ankit Soni Reviewed-by: Vasant Hegde --- drivers/iommu/amd/amd_iommu.h | 1 + drivers/iommu/amd/amd_iommu_types.h | 1 + drivers/iommu/amd/init.c | 16 ++++++++++++++++ drivers/iommu/amd/io_pgtable.c | 4 ++-- drivers/iommu/amd/iommu.c | 2 +- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index bb14c4800dd0..0286120ad4a5 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -42,6 +42,7 @@ int amd_iommu_enable_faulting(unsigned int cpu); extern int amd_iommu_guest_ir; extern enum protection_domain_mode amd_iommu_pgtable; extern int amd_iommu_gpt_level; +extern u8 amd_iommu_hpt_level; extern unsigned long amd_iommu_pgsize_bitmap; extern bool amd_iommu_hatdis; =20 diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_io= mmu_types.h index 284ff4309660..6bf81197c2c8 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -96,6 +96,7 @@ #define FEATURE_GA BIT_ULL(7) #define FEATURE_HE BIT_ULL(8) #define FEATURE_PC BIT_ULL(9) +#define FEATURE_HATS GENMASK_ULL(11, 10) #define FEATURE_GATS GENMASK_ULL(13, 12) #define FEATURE_GLX GENMASK_ULL(15, 14) #define FEATURE_GAM_VAPIC BIT_ULL(21) diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index f71b236c2af2..c713756fa44e 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -152,6 +152,8 @@ bool amd_iommu_dump; bool amd_iommu_irq_remap __read_mostly; =20 enum protection_domain_mode amd_iommu_pgtable =3D PD_MODE_NONE; +/* Host page table level */ +u8 amd_iommu_hpt_level; /* Guest page table level */ int amd_iommu_gpt_level =3D PAGE_MODE_4_LEVEL; =20 @@ -3052,6 +3054,7 @@ static int __init early_amd_iommu_init(void) struct acpi_table_header *ivrs_base; int ret; acpi_status status; + u8 efr_hats; =20 if (!amd_iommu_detected) return -ENODEV; @@ -3096,6 +3099,19 @@ static int __init early_amd_iommu_init(void) FIELD_GET(FEATURE_GATS, amd_iommu_efr) =3D=3D GUEST_PGTABLE_5_LEVEL) amd_iommu_gpt_level =3D PAGE_MODE_5_LEVEL; =20 + efr_hats =3D FIELD_GET(FEATURE_HATS, amd_iommu_efr); + if (efr_hats !=3D 0x3) { + /* + * efr[HATS] bits specify the maximum host translation level + * supported, with LEVEL 4 being initial max level. + */ + amd_iommu_hpt_level =3D efr_hats + PAGE_MODE_4_LEVEL; + } else { + pr_warn_once("Disable host address translation due to invalid max level = (%#x).\n", + efr_hats); + amd_iommu_hatdis =3D true; + } + if (amd_iommu_pgtable =3D=3D PD_MODE_V2) { if (!amd_iommu_v2_pgtbl_supported()) { pr_warn("Cannot enable v2 page table for DMA-API. Fallback to v1.\n"); diff --git a/drivers/iommu/amd/io_pgtable.c b/drivers/iommu/amd/io_pgtable.c index 26cf562dde11..0d8bc06f63d7 100644 --- a/drivers/iommu/amd/io_pgtable.c +++ b/drivers/iommu/amd/io_pgtable.c @@ -132,7 +132,7 @@ static bool increase_address_space(struct amd_io_pgtabl= e *pgtable, goto out; =20 ret =3D false; - if (WARN_ON_ONCE(pgtable->mode =3D=3D PAGE_MODE_6_LEVEL)) + if (WARN_ON_ONCE(pgtable->mode =3D=3D amd_iommu_hpt_level)) goto out; =20 *pte =3D PM_LEVEL_PDE(pgtable->mode, iommu_virt_to_phys(pgtable->root)); @@ -531,7 +531,7 @@ static void v1_free_pgtable(struct io_pgtable *iop) =20 /* Page-table is not visible to IOMMU anymore, so free it */ BUG_ON(pgtable->mode < PAGE_MODE_NONE || - pgtable->mode > PAGE_MODE_6_LEVEL); + pgtable->mode > amd_iommu_hpt_level); =20 free_sub_pt(pgtable->root, pgtable->mode, &freelist); iommu_put_pages_list(&freelist); diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 0ebc264726da..a2f957ee9110 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2503,7 +2503,7 @@ static int pdom_setup_pgtable(struct protection_domai= n *domain, static inline u64 dma_max_address(enum protection_domain_mode pgtable) { if (pgtable =3D=3D PD_MODE_V1) - return ~0ULL; + return PM_LEVEL_SIZE(amd_iommu_hpt_level); =20 /* V2 with 4/5 level page table */ return ((1ULL << PM_LEVEL_SHIFT(amd_iommu_gpt_level)) - 1); --=20 2.43.0