From nobody Sat Feb 7 06:40:11 2026 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013070.outbound.protection.outlook.com [40.107.201.70]) (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 8FA742D8773 for ; Thu, 15 Jan 2026 06:08:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.201.70 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457329; cv=fail; b=aD1jt7XrvgDu5RzcFflZ4jKrEAV/DLKwdWMenKu6dfFMZI0g2Q5rlRmjY5qp8u3YgPgNDw5zdZPqEQNSESp2SY+MnIIE8x1W+pKwvZ5WV98mOjhEHdl2WnMztrmjosvwavz406PEOolVWws2vG20Cx17u1JetDzoVv1lxf7f9Zw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457329; c=relaxed/simple; bh=PI1QUd36k+LrAeSkkS82B1vqUG0k/26ubDhIUtFHg2M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ky8YX80nxkhSwPX4JmQCS5pnE4Pzf/wHAs/eQL0f2mjt0lQhKhGJsQ4ZwSYuWuDZg3t8rQPu1HCj2ZVj9TLMxGYkrkcL3QzFr1vMDoFYdkBvaK4Q4LueUDL9484r7CaxQqb9mPatRHTSOum4dArxrUOjCXeDtWIZAvTO36zJsSA= 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=39YX/qUq; arc=fail smtp.client-ip=40.107.201.70 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="39YX/qUq" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oplIZpdANHAQaT0UK9pxeLYhkqQpbsT5YLN6CZEOFCcUuGsr5cdVtjmLfSx5VATOka6qS2fH90F+Q8DOKxjIAE8MGsBHVUxY0vbjf2TFgQqWEQmxy2bITu/EUfZEgg3RjuHaWLZTK/UgTtgEL6mpMUiXPlHcYIEZ7iYRb3mTcZ2A8JUayOQCSJsz55gPauYKTEqV+UBL0tRv4fuXeAxV3ZpYTBzuUpXzmrACumzLp0cip2YyIk90wk9TjqngADLEYvGzG9VbiUUVvNF5oxZEEGhb8JvnCMoV6eiruX9TQotDfFuF5lRXw87TOGKWQJQ+waoiR2/XWN/NnVA2E3qFKA== 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=1LzJMJ0OmT4PcZv2tOa6ilmRApJ6PJ+SwjLXVK54mxo=; b=o9D0YCEyh2uNTANhyH5GVHHbajVYe9BkoNmciUr/sfh4kIcPBR4G8qtKFSr+Qaeej49wIPdXYyWhEATAOXeazCXIAPnweN1G9enDfaRM+qEn1EFnMNu1XKOa2mi4Sx7UYKOyI96jmQlyWbrmEsSAw+F7GE5mJFrNLapoxsfbe8qWBhzI3cYLUxyeu1eLmk7aXTn5GKZAcW922lM5d4QrcWy9BtvUC++MtGoyl7SyxgBGmI7kJPtZL9rN8nDWdQ2tf1DcQ7Nyn5aCEvMCXQeiX+abEW0+yRujeqTDIwKMHVu2UOslEt7X5XBgUwlgbg2slRlisiRiZqLyPSIpV60A9w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com 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=1LzJMJ0OmT4PcZv2tOa6ilmRApJ6PJ+SwjLXVK54mxo=; b=39YX/qUqphZin1mDOYhjAT2RNa2i6ZnGkvUZP3yvzCGSBl9NTEkJ3Zy2czOLWOoYWaAKWerWcmp7DvACajhgotYL8RzFOMyyGP7gyEqdX7tYHqf2bElhSFDtYtW/26LBqA56lI797yn+dcP++NmjnfNXHAtOMnKw77reFvHHzI0= Received: from SN1PR12CA0046.namprd12.prod.outlook.com (2603:10b6:802:20::17) by IA1PR12MB9029.namprd12.prod.outlook.com (2603:10b6:208:3f0::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.5; Thu, 15 Jan 2026 06:08:43 +0000 Received: from SA2PEPF00003F65.namprd04.prod.outlook.com (2603:10b6:802:20:cafe::a3) by SN1PR12CA0046.outlook.office365.com (2603:10b6:802:20::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.6 via Frontend Transport; Thu, 15 Jan 2026 06:08:41 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00003F65.mail.protection.outlook.com (10.167.248.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.1 via Frontend Transport; Thu, 15 Jan 2026 06:08:41 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 15 Jan 2026 00:08:35 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v6 01/13] iommu/amd: Add support for hw_info for iommu capability query Date: Thu, 15 Jan 2026 06:08:02 +0000 Message-ID: <20260115060814.10692-2-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> References: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F65:EE_|IA1PR12MB9029:EE_ X-MS-Office365-Filtering-Correlation-Id: db888825-ef92-4b2e-983d-08de53fc8843 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|1800799024|36860700013|7053199007|13003099007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?dHaBUe38lFYUlYm9B/o7JXYvMyS6QVDHi2f536ik2JsDzLhV8uQ2N+XZaAhV?= =?us-ascii?Q?YHATw5ZZE/2PeaHJc1j0TNCRGN3/5oDa79qmzAKmFl4BUCJeWlH47qSk8HMf?= =?us-ascii?Q?px/hjDVc8kuKdUvJmDGdl6Nfx87ywpajF8rsLoUcJ33TL9Ui82ixChC7gaZ3?= =?us-ascii?Q?I/ZofrnNde7Gyam3Txv+DrNF6wYxhsHNJ4EePPSQkc+qbkC9olqZuRLrX9Zc?= =?us-ascii?Q?/xrZFhEAxdNPEvj/JMGM278z36VRZlQ+VN0sVAcWkey7p3i1k9gTI69X9wv1?= =?us-ascii?Q?w9cyTvHJvXXUQWp2iDH/0fuN6QfD3PIkdVEQAwOqtplDnQbhoRkh/u6cGkEx?= =?us-ascii?Q?6lTO+VBug8nRhJsUCILZ+kBLHfQxzs05bQL1thUqT4EhKiHv6Afs6m/KZ6Mn?= =?us-ascii?Q?8CuVezD1hAvHLawiqrsy5hTI3n1i1C70MLSin2PBShE7xZyLnx+MEpnMyV3X?= =?us-ascii?Q?BNws15IetMA4DNAeAhmAFFJZjyG/kQqHvY3+1hPH3WSBfQa9beRO2HxaXbXH?= =?us-ascii?Q?uYOehuT1lq38lj+k0K2lFCCWWbKA8/IGneABnaAFhBdSDzRhqPAjXTnLHum0?= =?us-ascii?Q?jLqlAJ7lzWHZV4AgK+ZiU1kpJsihNG4ij7B7vO3U29UNHANC9ILc2vDLuqnz?= =?us-ascii?Q?PDZasrWi+v9QfypPSIw55oCqqEhuSj5IEc0FyjLSRbIQ9RcR7R7g5Mq3w+JZ?= =?us-ascii?Q?kKX7yb9XMOg55xRnhWJIuB3W4Oxj4K68ZHrcaGTqnPvbUVTLMHSsD88KA/Fg?= =?us-ascii?Q?UfxQn9aXBXdu56KQSaG93JlHiiwHd1xGBbVMBWXbFhQFBTM0L3/wWr2Ny23s?= =?us-ascii?Q?7N9eaQoqiZTuGQAsmMJwew0xpDW1FiqaCnBxdQ4cD5Z0z2Rp6WOiy8iikywR?= =?us-ascii?Q?25Emq3/KFgsFFKPChwWbaus7RC1whtWWN6ox1OcNvH7gCXn9v4Rh7cOiazYq?= =?us-ascii?Q?9rUd+trYAyZzx+ylofUsLMGXG1CT2U77vRpCc57wtCu9UVb9TPU+V1tDE08Z?= =?us-ascii?Q?JMStX3lu7EZgiknrceCiMuyfvyllo5h/L0dCMe1i1razffHv3uwelqyn09WS?= =?us-ascii?Q?L1NNKCyQ+3CgQ6EmA7Cz68wnWPMf4z3FV76Lhf7EoRZv7woRz+/+UbFxlFTC?= =?us-ascii?Q?mUirtzcfUQZK2vG12eXJhDArxaljMoqbgCsKxHP39qBidbTi+uSgHh1Zp2Nm?= =?us-ascii?Q?13W3+8HaY/+S3mNT3VGhKZrNp6OuxFSNss6AnOcu5DQuMPVE1c6mOKRwioRQ?= =?us-ascii?Q?ljlx9ZFO8bC+6o5glC8KdGryflPoLlifK/c9dMLjFta5RLTZMRCiAiNsFISq?= =?us-ascii?Q?7JMNAuAnct638T3lzbE4bHy1R5JK4AFEzWm3Ep2prhwTVBUauhzW5pb7JfGq?= =?us-ascii?Q?U6htEiZlsy6hPHcVsw4Q2nU9RG4decEbT9dk03Bqxao3T6gw0ITdnGoPmb04?= =?us-ascii?Q?xF1sZZnMQRUWhI6gWWBBGEsfMLdNnSvItO6L77a4ScLweXlTXYtIe0+pmQ/v?= =?us-ascii?Q?bvErZNnsAMnf+AI9fcwRRD06nESod/8dl1HEwG/n72T12MkMmhix/A1c0odd?= =?us-ascii?Q?tMNSlCfANOlwYRLKlyTqmexU9Ps44KK8suxhHBMnggguA6onhBmZ5ApiFivi?= =?us-ascii?Q?Tn+ENjM5/6uhf3J3HDrcBdXHB4l3mgY3cCLpPQBb+2fEm7iDriEpy8WdB8yY?= =?us-ascii?Q?cEpKag=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(1800799024)(36860700013)(7053199007)(13003099007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2026 06:08:41.5562 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: db888825-ef92-4b2e-983d-08de53fc8843 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F65.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB9029 Content-Type: text/plain; charset="utf-8" AMD IOMMU Extended Feature (EFR) and Extended Feature 2 (EFR2) registers specify features supported by each IOMMU hardware instance. The IOMMU driver checks each feature-specific bits before enabling each feature at run time. For IOMMUFD, the hypervisor passes the raw value of amd_iommu_efr and amd_iommu_efr2 to VMM via iommufd IOMMU_DEVICE_GET_HW_INFO ioctl. Reviewed-by: Nicolin Chen Reviewed-by: Vasant Hegde Reviewed-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/Kconfig | 10 ++++++++++ drivers/iommu/amd/Makefile | 1 + drivers/iommu/amd/iommu.c | 2 ++ drivers/iommu/amd/iommufd.c | 31 +++++++++++++++++++++++++++++++ drivers/iommu/amd/iommufd.h | 15 +++++++++++++++ include/uapi/linux/iommufd.h | 28 ++++++++++++++++++++++++++++ 6 files changed, 87 insertions(+) create mode 100644 drivers/iommu/amd/iommufd.c create mode 100644 drivers/iommu/amd/iommufd.h diff --git a/drivers/iommu/amd/Kconfig b/drivers/iommu/amd/Kconfig index f2acf471cb5d..588355ff7eb7 100644 --- a/drivers/iommu/amd/Kconfig +++ b/drivers/iommu/amd/Kconfig @@ -30,6 +30,16 @@ config AMD_IOMMU your BIOS for an option to enable it or if you have an IVRS ACPI table. =20 +config AMD_IOMMU_IOMMUFD + bool "Enable IOMMUFD features for AMD IOMMU (EXPERIMENTAL)" + depends on IOMMUFD + depends on AMD_IOMMU + help + Support for IOMMUFD features intended to support virtual machines + with accelerated virtual IOMMUs. + + Say Y here if you are doing development and testing on this feature. + config AMD_IOMMU_DEBUGFS bool "Enable AMD IOMMU internals in DebugFS" depends on AMD_IOMMU && IOMMU_DEBUGFS diff --git a/drivers/iommu/amd/Makefile b/drivers/iommu/amd/Makefile index 5412a563c697..41f053b49dce 100644 --- a/drivers/iommu/amd/Makefile +++ b/drivers/iommu/amd/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y +=3D iommu.o init.o quirks.o ppr.o pasid.o +obj-$(CONFIG_AMD_IOMMU_IOMMUFD) +=3D iommufd.o obj-$(CONFIG_AMD_IOMMU_DEBUGFS) +=3D debugfs.o diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 5d45795c367a..b6154c73e514 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -43,6 +43,7 @@ #include =20 #include "amd_iommu.h" +#include "iommufd.h" #include "../irq_remapping.h" #include "../iommu-pages.h" =20 @@ -3079,6 +3080,7 @@ static bool amd_iommu_enforce_cache_coherency(struct = iommu_domain *domain) =20 const struct iommu_ops amd_iommu_ops =3D { .capable =3D amd_iommu_capable, + .hw_info =3D amd_iommufd_hw_info, .blocked_domain =3D &blocked_domain, .release_domain =3D &blocked_domain, .identity_domain =3D &identity_domain.domain, diff --git a/drivers/iommu/amd/iommufd.c b/drivers/iommu/amd/iommufd.c new file mode 100644 index 000000000000..72eaaa923d04 --- /dev/null +++ b/drivers/iommu/amd/iommufd.c @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ + +#include + +#include "iommufd.h" +#include "amd_iommu.h" +#include "amd_iommu_types.h" + +void *amd_iommufd_hw_info(struct device *dev, u32 *length, u32 *type) +{ + struct iommu_hw_info_amd *hwinfo; + + if (*type !=3D IOMMU_HW_INFO_TYPE_DEFAULT && + *type !=3D IOMMU_HW_INFO_TYPE_AMD) + return ERR_PTR(-EOPNOTSUPP); + + hwinfo =3D kzalloc(sizeof(*hwinfo), GFP_KERNEL); + if (!hwinfo) + return ERR_PTR(-ENOMEM); + + *length =3D sizeof(*hwinfo); + *type =3D IOMMU_HW_INFO_TYPE_AMD; + + hwinfo->efr =3D amd_iommu_efr; + hwinfo->efr2 =3D amd_iommu_efr2; + + return hwinfo; +} diff --git a/drivers/iommu/amd/iommufd.h b/drivers/iommu/amd/iommufd.h new file mode 100644 index 000000000000..f880be80a30d --- /dev/null +++ b/drivers/iommu/amd/iommufd.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ + +#ifndef AMD_IOMMUFD_H +#define AMD_IOMMUFD_H + +#if IS_ENABLED(CONFIG_AMD_IOMMU_IOMMUFD) +void *amd_iommufd_hw_info(struct device *dev, u32 *length, u32 *type); +#else +#define amd_iommufd_hw_info NULL +#endif /* CONFIG_AMD_IOMMU_IOMMUFD */ + +#endif /* AMD_IOMMUFD_H */ diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 2c41920b641d..3db37f6042a0 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -623,6 +623,32 @@ struct iommu_hw_info_tegra241_cmdqv { __u8 __reserved; }; =20 +/** + * struct iommu_hw_info_amd - AMD IOMMU device info + * + * @efr : Value of AMD IOMMU Extended Feature Register (EFR) + * @efr2: Value of AMD IOMMU Extended Feature 2 Register (EFR2) + * + * Please See description of these registers in the following sections of + * the AMD I/O Virtualization Technology (IOMMU) Specification. + * (https://docs.amd.com/v/u/en-US/48882_3.10_PUB) + * + * - MMIO Offset 0030h IOMMU Extended Feature Register + * - MMIO Offset 01A0h IOMMU Extended Feature 2 Register + * + * Note: The EFR and EFR2 are raw values reported by hardware. + * VMM is responsible to determine the appropriate flags to be exposed to + * the VM since cetertain features are not currently supported by the kern= el + * for HW-vIOMMU. + * + * Current VMM-allowed list of feature flags are: + * - EFR[GTSup, GASup, GioSup, PPRSup, EPHSup, GATS, GLX, PASmax] + */ +struct iommu_hw_info_amd { + __aligned_u64 efr; + __aligned_u64 efr2; +}; + /** * enum iommu_hw_info_type - IOMMU Hardware Info Types * @IOMMU_HW_INFO_TYPE_NONE: Output by the drivers that do not report hard= ware @@ -632,6 +658,7 @@ struct iommu_hw_info_tegra241_cmdqv { * @IOMMU_HW_INFO_TYPE_ARM_SMMUV3: ARM SMMUv3 iommu info type * @IOMMU_HW_INFO_TYPE_TEGRA241_CMDQV: NVIDIA Tegra241 CMDQV (extension fo= r ARM * SMMUv3) info type + * @IOMMU_HW_INFO_TYPE_AMD: AMD IOMMU info type */ enum iommu_hw_info_type { IOMMU_HW_INFO_TYPE_NONE =3D 0, @@ -639,6 +666,7 @@ enum iommu_hw_info_type { IOMMU_HW_INFO_TYPE_INTEL_VTD =3D 1, IOMMU_HW_INFO_TYPE_ARM_SMMUV3 =3D 2, IOMMU_HW_INFO_TYPE_TEGRA241_CMDQV =3D 3, + IOMMU_HW_INFO_TYPE_AMD =3D 4, }; =20 /** --=20 2.34.1 From nobody Sat Feb 7 06:40:11 2026 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013044.outbound.protection.outlook.com [40.93.196.44]) (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 ECFAF2D59E8 for ; Thu, 15 Jan 2026 06:08:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.196.44 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457334; cv=fail; b=lXbVkKVUYC2Mik94LK+F14vSOaNKS0ScVUAxYaZhKe2IdwJvw7t46/aDqn+SbBG0fRJmKOReiloHuXC/mf1FQfUNzfrEXmUI3heEoobLu/BgsMq+HEGitwT4nsJBDJGDnDMs+i2LjHrKbGzpAv2MTSMnS1Y40AcyTCtHN9KBMts= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457334; c=relaxed/simple; bh=vQ6IoML/DhdYApLzeMC8xJuOI9IMVhN/sPzoem+g3Gk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=k/aDt/Ms9cngn/F/cYv2ipQU02jr7gyJZyGJBjoNEZ0bxRqkjLGaHaTf16NuuWb68bS/MLi4qcq3uthJjpCvN/J8vG9VHnqtyFNGxp5vcxqai2K8ZQJQtx2zBQEI3I3Hp9kIu3Vgg6B+KQ7bF2gihJbxx25ggjHgBUYEummnDzg= 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=dNwtKqka; arc=fail smtp.client-ip=40.93.196.44 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="dNwtKqka" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qkGdoXjm7FGfeHdLFSUwQZEIXVcP2OnDsfj+55/phS/i/1tySyxQe5Vit7RC9fLRwqHFn1Xw+2aC+yLO1aI9ZPgQDSeKuiA1Foil371Lwt/ZjdgI/2yurNDxKpRMrILsCnIfKmFU0LM67O7+kkbSwyDvkQZ5vbIjJKWFXZ0ZqDPU16BInATcNQLftGVeeX1MPAynXF1F/uLIBr5eIchuuAcbUChTnUbfFnTcBaMrFYh9zYD5EBcInftXdGGi3VD7hHEFywiKdVEaHfIdNKC5mesxs7FM8PkaXWg1Bcv0wO66DTYqvBKnjzKVtvVIzjMxCwFuUOrYIzdrdthuRoeEnQ== 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=11vXy0dUWmIsjTfMzv22F29PqkoHLYFUGa8M+x05V5I=; b=BfXgyVPRTJ+7lE609bca3YNT4ohgqjzTxCqy0jUekBDKnY+4mAt66mGY/9Cs8JPXjjHoxDxfv0Zg9IO8Ni3XnwqdKg+xeARjMe1C9bFpO/e7e2Pi5Pbyn1OGjkvtNhKfPgj+SOEIebcwQWGxywn9KnZfI02HrOba1IUxOpWLrNln4tmaMN5PHOZ9Du0aO/aQlwwuwtiqdpBpiTI3OX/4truSA3iD7TcVy2wjFxtvLOZvMM6MaVY4SwJEvrqtmKNIdQLkswVRTeYlMvDtYiC6mQT22YPrERqFLZW542/e9Of7XVo77En3g8D3WdsesWxY8KZD9wIFvtGIUM3GPYB0AQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com 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=11vXy0dUWmIsjTfMzv22F29PqkoHLYFUGa8M+x05V5I=; b=dNwtKqkaxgASbC2U82zgcW3pIRaZpxwrKPY4oFtpNLeRzE1M6fdPOUzpv1wjHcno8gT1L1x2A7xbZoohnIlOsMENtjADoit22U48hTmbctjFU0sT87Q0RMUV4riJ6BzyMfR4nEmRCfY8dlNdZcsFW59XQOAsdEXuM8AYfqGLh3Q= Received: from SA9PR13CA0050.namprd13.prod.outlook.com (2603:10b6:806:22::25) by IA0PPFAF4999BF6.namprd12.prod.outlook.com (2603:10b6:20f:fc04::be0) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.4; Thu, 15 Jan 2026 06:08:48 +0000 Received: from SA2PEPF00003F66.namprd04.prod.outlook.com (2603:10b6:806:22:cafe::72) by SA9PR13CA0050.outlook.office365.com (2603:10b6:806:22::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.4 via Frontend Transport; Thu, 15 Jan 2026 06:08:47 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00003F66.mail.protection.outlook.com (10.167.248.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.1 via Frontend Transport; Thu, 15 Jan 2026 06:08:47 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 15 Jan 2026 00:08:41 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v6 02/13] iommu/amd: Rename DEV_DOMID_MASK to DTE_DOMID_MASK Date: Thu, 15 Jan 2026 06:08:03 +0000 Message-ID: <20260115060814.10692-3-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> References: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F66:EE_|IA0PPFAF4999BF6:EE_ X-MS-Office365-Filtering-Correlation-Id: 6577963f-c5ac-4a2f-7e71-08de53fc8bbe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|376014|7416014|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?B3bJzS4BXfZuBx+DEPaiGajzhXBBizTXyLRxKGr4h0EFwtrjXJw7VwMPPu2J?= =?us-ascii?Q?v+hwYhzjx5pV7ab7blTwCF5GguoF457po9pNBkAZyrtSW+8ozQ2KOKuqbR9o?= =?us-ascii?Q?MMRXCh6IJEeylUcMy/RstemBYFvDq7UGOA79yNPkki6+3KP5BqWixbrkOxVr?= =?us-ascii?Q?U/zzgKnc4iANoaaxXsfQ7HJw05qiWrU0v8ERY2vBSoQf3aKFapPRu4mSgvqx?= =?us-ascii?Q?8xKsAGKWzO4SYRSxxtlUI/fAZOegEQ6xW6/mottJvBfsWs4nxA31+tQnlN7p?= =?us-ascii?Q?iUaYTskBYN6+LVI19IetE/GessKQPsSJyD6+Ox3x1p+ZvzVXoPp/f26XInB/?= =?us-ascii?Q?/9Zp6313o8eNvKtXLb2QMS0H8UkxCED9eATbOQXR2StE2YBG2Pvu99h4cb42?= =?us-ascii?Q?rD7oyWA1816xVvDqls05CwzlIti9MvklK3kLDh84o0nfxjb1eVl+oj14jtJc?= =?us-ascii?Q?tBvxMWTRa2aCl0TjeXfbw3SEq2peKS6KeVjh9pPcyxzZHRTkiVvPr2g0HgQt?= =?us-ascii?Q?t/iFb/V3tBLWla88Ts2rSiY+rAYKyUGz8fMHkwgMAZjc+ooMWHIaTZfCg29r?= =?us-ascii?Q?MnGAI0YfQypt88ru6YtwQr/itE6bXj0mZWHc47o22oVeUHK3afSzI7Zegx0F?= =?us-ascii?Q?c3uHkI+IWSPEHJyCfXFQW1B0PYcSRXjTbRwMQ52DCSnLOvsD/zrEfPRbafQ0?= =?us-ascii?Q?DVPjzIySDdOy6ief5SOIjraemVAso+WS3LVaH8882i/6yaeobB38Yf9E4e74?= =?us-ascii?Q?yDNLB+n7L+Q+68YtRrp3VZXcbwFxbNLTEBEWU+ID+GwYQCsWW7B7fSyP4Axa?= =?us-ascii?Q?oHlG+5p3tKszVpo/xfiKEd/EOo3Em+koWdA04KQ7/msmQ09KES/kW4fBVsbr?= =?us-ascii?Q?kR7e8heVGLnJEaoLNEf176FX/CZHudADUAtDZGe1M/yuEUyw5HoyceI1KwH4?= =?us-ascii?Q?Hi/hrHGqyyMrlUqim1QMldD6r84MW267XZ4Mb2VtzN9E3BIIVN10DWkI0nh6?= =?us-ascii?Q?NL2iboI3Jf+hBZdLf0FkE38mKupm+hw3uervKq9u+/wOrJ4IHg53UKD8brGL?= =?us-ascii?Q?8erd5R1ud2Sry/S19wIXhzxkjc1ta8aNfP5Pvr3bwhxr6ZhI0Pa8jY3j/IWh?= =?us-ascii?Q?xpBbEbABEhvl9KmE1phLer9eavpIez9arfiaCWOYfxTrAkxQDQAcR4Kayi9D?= =?us-ascii?Q?yUcRegrcrO7UBLgOteZIzJNqm4eMDyZkz5cWSDkBerGAx9WAnOU9JGvSPBpT?= =?us-ascii?Q?suRJJZp+AfPqyKY2zPmizHSJu5DLgJD4xmCkl+pPkhI8adw7LpdIzOllB4gq?= =?us-ascii?Q?4xOaer/iOzXMlD4P8ulDhG2derSeN+gxXD0ho/Xd6iDbDMvQ+i51nZqLajlf?= =?us-ascii?Q?tXW+LjYFmCt8fS278V9HPj9HXxjFKMJUjNwXPGDle4fdJyb/rSmaHk/Utsom?= =?us-ascii?Q?igJ6VIirttl3k6CZUOd9cc51KpnX7HZqhLt7srW6XOVrgvrTp5LdXaQES74D?= =?us-ascii?Q?AVJSH0eGjQV84qNSGswo6waohIdu/p99iY20QHnah63Neq0pHOFScw6kXzrr?= =?us-ascii?Q?QpbUvl08ZrLSmsE6RZUD1bE6SQRV2kqSQ4R+/pZWIAm2GfZdSnOhIioUDYzP?= =?us-ascii?Q?DBWt5JoqgXkkAR8rW0Su+qvj/uS8tOhVzks0tTGE2Ge9?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(36860700013)(376014)(7416014)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2026 06:08:47.3935 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6577963f-c5ac-4a2f-7e71-08de53fc8bbe 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F66.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PPFAF4999BF6 Content-Type: text/plain; charset="utf-8" Also change the define to use GENMASK_ULL instead. There is no functional change. Reviewed-by: Nicolin Chen Reviewed-by: Jason Gunthorpe Reviewed-by: Vasant Hegde Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu_types.h | 2 +- drivers/iommu/amd/init.c | 2 +- drivers/iommu/amd/iommu.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_io= mmu_types.h index 320733e7d8b4..14801d734684 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -358,7 +358,7 @@ =20 #define DTE_FLAG_IOTLB BIT_ULL(32) #define DTE_FLAG_MASK (0x3ffULL << 32) -#define DEV_DOMID_MASK 0xffffULL +#define DTE_DOMID_MASK GENMASK_ULL(15, 0) =20 #define DTE_GCR3_14_12 GENMASK_ULL(60, 58) #define DTE_GCR3_30_15 GENMASK_ULL(31, 16) diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index 384c90b4f90a..cfbc9ff105c3 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -1179,7 +1179,7 @@ static bool __reuse_device_table(struct amd_iommu *io= mmu) for (devid =3D 0; devid <=3D pci_seg->last_bdf; devid++) { old_dev_tbl_entry =3D &pci_seg->old_dev_tbl_cpy[devid]; dte_v =3D FIELD_GET(DTE_FLAG_V, old_dev_tbl_entry->data[0]); - dom_id =3D FIELD_GET(DEV_DOMID_MASK, old_dev_tbl_entry->data[1]); + dom_id =3D FIELD_GET(DTE_DOMID_MASK, old_dev_tbl_entry->data[1]); =20 if (!dte_v || !dom_id) continue; diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index b6154c73e514..2ab0f3c98425 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2116,7 +2116,7 @@ static void set_dte_entry(struct amd_iommu *iommu, if (dev_data->ats_enabled) new.data[1] |=3D DTE_FLAG_IOTLB; =20 - old_domid =3D READ_ONCE(dte->data[1]) & DEV_DOMID_MASK; + old_domid =3D READ_ONCE(dte->data[1]) & DTE_DOMID_MASK; new.data[1] |=3D domid; =20 /* --=20 2.34.1 From nobody Sat Feb 7 06:40:11 2026 Received: from BL0PR03CU003.outbound.protection.outlook.com (mail-eastusazon11012068.outbound.protection.outlook.com [52.101.53.68]) (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 451FB2D879A for ; Thu, 15 Jan 2026 06:09:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.53.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457341; cv=fail; b=HwM9NqGmgDomYLT0QqE1bYztzj3dc7Hd9rawFSm+F3M0pWBTPQbYv47YMUs9NvrO4hw0HjpFaXQoFdm83h/FVcSeh1nnREx8KdvBBgSC1t2cwaJd0XoE7NGHlPmabk5vj8b5QyYF+Gih3FV908kA+uIQZUaLQLZrJ2j46e+Qcfw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457341; c=relaxed/simple; bh=GF+cYYvNMCSzgA/nzXAcUCm31kFqVR0uLCgkb2WnuOA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pRHvTZeC/06pIw5XHgsBmWwOG5YQ9WROohV18AR7WJqbvCauphfo4dbJg2ztKzygzZiyNMcVudZt5+yXhxr7f8RMGsa1zZ5tyaPIOaMF7UclnaxMTC5DifatU7NO5hyYXDKgnREp4ixFAgsbXgNqx0+q7cnFyzGiQBOyzeRqm9U= 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=q1BbWQVi; arc=fail smtp.client-ip=52.101.53.68 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="q1BbWQVi" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lZKz5cptUTwC/m6esAOYNiL7nSQ3wbLCJDMdd2Dx0PuQ86voqxJk7i76OIBdWP12L4FPQT7VWFRtKl6dZiSf8u3YZDI6g+J4EipZTrS2Im0g+UGzBuAAcCXZG/rxw9qXFFVv0HZh0jcnxAH6IWgzRc2pSV9e/hbo6xbocSAkZ1Gp/knSM/sFJXjYCo8PmgBMcwgE09Crg26vveH40rnsIH6hYMLV1Mz60QE5EVegdnE6EkVR8+ve/2S5XhoyEaMzhfCuCuCvgkFDAAMc8Q/uTQ/e1VXI9B0d5+9uwY7H+kOdEQYyS++ktCnNRHx3gBmiK48Qw2yuqFbpDjih5ceUmQ== 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=YdMLarvre61YiY7b/kjBXU7/Q19ef8ThoWTO72fth38=; b=dLjiJkrBU+I7xY1/ZbFrhwhc87+nXA0+TBMV348vLrBgbayVVQINqfoxNssi3Kq2UPVqp1wtDwndqGXjHg7W1ALg/eelroexF/9w2VZW1HJjXgYAr0884U8XhceT+9XrDVKLRA8jRy/CO4GDCr59g5Z/C1uhNPqwitohF6qDsDZxUqpfWn9bMD1PgnAo1rX8LdzRTV1hAORBUTmy2IR2Bh6NQgU5OEz1Vvit/5XYSxwWWp4f4saaycNSvOQSeyO8JpQuIT/b0K/wg+CYH5tejwbGGtPTGS3+V6xEnQ2XiAniff9GN4W2+p5z1f4q3Aqb2sXLspCv7YlMHDNZpmdOSA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com 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=YdMLarvre61YiY7b/kjBXU7/Q19ef8ThoWTO72fth38=; b=q1BbWQViz4Mx5wzrowKNW3fIO8caIV5Tcf7qKMoGYGMMie1RGYn6KEpe03eKqwxc5ISardZtAqwb2hk+AmmjRLfGbKvkBgcq91Xm10qbQlpGVE9rG4prU0nTCcjGNitzzbhqtnS2Ch0IyXEqw+DWDBp9JtztlKz0CWXBifHbN4E= Received: from SA1P222CA0167.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c3::15) by IA1PR12MB8287.namprd12.prod.outlook.com (2603:10b6:208:3f5::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.5; Thu, 15 Jan 2026 06:08:54 +0000 Received: from SA2PEPF00003F68.namprd04.prod.outlook.com (2603:10b6:806:3c3:cafe::aa) by SA1P222CA0167.outlook.office365.com (2603:10b6:806:3c3::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.5 via Frontend Transport; Thu, 15 Jan 2026 06:08:52 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00003F68.mail.protection.outlook.com (10.167.248.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.1 via Frontend Transport; Thu, 15 Jan 2026 06:08:53 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 15 Jan 2026 00:08:47 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v6 03/13] iommu/amd: Make amd_iommu_make_clear_dte() non-static inline Date: Thu, 15 Jan 2026 06:08:04 +0000 Message-ID: <20260115060814.10692-4-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> References: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F68:EE_|IA1PR12MB8287:EE_ X-MS-Office365-Filtering-Correlation-Id: 81f15cde-eab1-43c7-965b-08de53fc8f31 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|82310400026|36860700013|376014|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?fwPcDdSUuJVdKuHnJYoc5R8OObXLLo9b9awC8N55132U0xRLVbxWYtjmGCLt?= =?us-ascii?Q?lfcXU2yQpt/UkrlnlC/x+Ppv9RL5k4BH08wWaNMFr2YwO1iC25mYK5Uwld/L?= =?us-ascii?Q?vJtogQQxpD419/3csFhbXry3o5vPGAcsptYtyqFJbtTA4h+SAUKXTgNRRQHH?= =?us-ascii?Q?XnrHWww6DxzurwqGVsmp6Py9p2rWPNSa14XNs4QQVfNZ3udYEArcW2+x6oZU?= =?us-ascii?Q?BmoIGsNDenbHqKKS2V7mxQIVfRenDDN4P27S8eeCHQXIPXU2i5tZwNQ9OjGw?= =?us-ascii?Q?GoBauptE+3KqBzJkurMy+jv9cy/mdqGwMjlxlKXPoWLvRYHGOH3n5pdIfN7G?= =?us-ascii?Q?ws3FMXxN87kyILiJ+24dEJqk0b/ULZL278DacxyXJz4eB2UnDXHb+FMUJGct?= =?us-ascii?Q?6K5LwyNDZDTd1kZSfbQn1YGLxvlfcNJ7PI4euP6DYVC1Mq6wfgLeRIEgYbqw?= =?us-ascii?Q?LiYrmaeNSQzF45cTRS+S4JWPj3E6Eguu9Z7eUSQvRk6CI68d7Sy2F1Q+elsU?= =?us-ascii?Q?LSep4fmwJg3JKcvpr1q7/LjX8VaJ+ekMeT3LSMm03Q/vlC3Q8AdPoeJ8QQcI?= =?us-ascii?Q?7tazYsXdWqwFAZ/PHVRBrr3KSiZ5uf9f7plnn0q+sfFUlH9WOI8FIQp3Zp1g?= =?us-ascii?Q?IODPRy92d/KB7dx0J/wiZaj1DWp2AqwP2y+FiRJCR84k4Zne7VHzGllEvI4Y?= =?us-ascii?Q?p7VZYLaSFGmFfF04Y5ai+LFzPqP51U3i+Vr2GoHKSZIiCR2V/BgJldTdNrel?= =?us-ascii?Q?UwbYFDjJ4/RX8ckr1dt1ro0pNRiiAqTmfLURfU7u0n/apVOoUSOitT+XPhfL?= =?us-ascii?Q?5V1X/ORaw3H/zjK/FCc2yLavrGUVFSGnBrnET7+AsevxWDUgEaJRfOa6xK/a?= =?us-ascii?Q?tlxXS+t5reN9x02L7481EEbz9fOJyChCkayV8wxEQgOKrSa6txdKue6Ce02c?= =?us-ascii?Q?VrI7krhMIU/o9W1FKDm2D/wYqn1t0Il0C5veibWhX7R5RtG5R2qA32l73nNw?= =?us-ascii?Q?sWUHqiWaiMOomnmx7L/MUD5yfjKWTgSpuwxI+cVeHVqogtXJ8rfapMnq5z1J?= =?us-ascii?Q?6P4jaLa5ymJanh3o+1dhyvhgKjHlkLYv942p/cFk0yKITVsw23k1FcHs0vEh?= =?us-ascii?Q?mxdmL8wURjPl9RQ6HK4qYdeTPsCUFYqZnouBktAVLdw1c/P/+azrh0Wb8cLa?= =?us-ascii?Q?3dG+mb8MBmivlaTpESuTMQB3vnKvQB44F8nffLPIuVk4HQ47WrEh0n4tDoMq?= =?us-ascii?Q?FPeEL5RJrBzCJu5qUhOQn5HDXBuCSdvP11GgXXHAfvEaY0nW0Fk0zCoYziw8?= =?us-ascii?Q?vcoQTzNmD+QEbjo+niCQXecSwd9F7ln+mllAQ/K3e8fm0xXzm0mRMIuYZALo?= =?us-ascii?Q?K6SaZQvYCrpu9djSWeI2WKK2V8ZNQWewWMKrCrdkaF7iG+IG0PQ5AaJ9WccH?= =?us-ascii?Q?cEef50nFiYDBq+8gxJpodmFEIx9T5+I7m9gffG2Wrg9fdCa4Jl+jIChFIhI+?= =?us-ascii?Q?6kbk5A+dKm07Sx2LKWLhEWrMzAPM2RBtF+ETtJL45i7ktvr2qFEsNADb+15X?= =?us-ascii?Q?CTig4AXJETgFJuDF6nl6+v7FNIye1KLEDU+a4o1ATzNsyiH/3o1g3xicUqZ9?= =?us-ascii?Q?9zmezkq58iwxs2YIGkWK/VsgCN5zwtc1RnAF8f6ycNbXcQYvJBlxwcyaHjCx?= =?us-ascii?Q?QYFb0g=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(82310400026)(36860700013)(376014)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2026 06:08:53.1718 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 81f15cde-eab1-43c7-965b-08de53fc8f31 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F68.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8287 Content-Type: text/plain; charset="utf-8" This will be reused in a new nested.c file for nested translation. Also, remove unused function parameter ptr. Reviewed-by: Nicolin Chen Reviewed-by: Vasant Hegde Reviewed-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 8 ++++++++ drivers/iommu/amd/iommu.c | 13 ++----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index b742ef1adb35..8eb5e9857079 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -190,4 +190,12 @@ void amd_iommu_domain_set_pgtable(struct protection_do= main *domain, struct dev_table_entry *get_dev_table(struct amd_iommu *iommu); struct iommu_dev_data *search_dev_data(struct amd_iommu *iommu, u16 devid); =20 +static inline void +amd_iommu_make_clear_dte(struct iommu_dev_data *dev_data, struct dev_table= _entry *new) +{ + /* All existing DTE must have V bit set */ + new->data128[0] =3D DTE_FLAG_V; + new->data128[1] =3D 0; +} + #endif /* AMD_IOMMU_H */ diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 2ab0f3c98425..ded8d4ba86e3 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2011,14 +2011,6 @@ int amd_iommu_clear_gcr3(struct iommu_dev_data *dev_= data, ioasid_t pasid) return ret; } =20 -static void make_clear_dte(struct iommu_dev_data *dev_data, struct dev_tab= le_entry *ptr, - struct dev_table_entry *new) -{ - /* All existing DTE must have V bit set */ - new->data128[0] =3D DTE_FLAG_V; - new->data128[1] =3D 0; -} - /* * Note: * The old value for GCR3 table and GPT have been cleared from caller. @@ -2068,7 +2060,7 @@ static void set_dte_entry(struct amd_iommu *iommu, struct dev_table_entry *dte =3D &get_dev_table(iommu)[dev_data->devid]; struct pt_iommu_amdv1_hw_info pt_info; =20 - make_clear_dte(dev_data, dte, &new); + amd_iommu_make_clear_dte(dev_data, &new); =20 if (gcr3_info && gcr3_info->gcr3_tbl) domid =3D dev_data->gcr3_info.domid; @@ -2149,9 +2141,8 @@ static void set_dte_entry(struct amd_iommu *iommu, static void clear_dte_entry(struct amd_iommu *iommu, struct iommu_dev_data= *dev_data) { struct dev_table_entry new =3D {}; - struct dev_table_entry *dte =3D &get_dev_table(iommu)[dev_data->devid]; =20 - make_clear_dte(dev_data, dte, &new); + amd_iommu_make_clear_dte(dev_data, &new); update_dte256(iommu, dev_data, &new); } =20 --=20 2.34.1 From nobody Sat Feb 7 06:40:11 2026 Received: from PH8PR06CU001.outbound.protection.outlook.com (mail-westus3azon11012016.outbound.protection.outlook.com [40.107.209.16]) (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 9C5F62D979F for ; Thu, 15 Jan 2026 06:09:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.209.16 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457344; cv=fail; b=Pr0IXLkqUg/SGkHDWyFMg4TSWlOMkMC7UVPGv82fkw4B2S+EbJ7971JJOgFtSN2vcWsPNELWbASyzBM3znmICT7zgd2IQAeoh1J0mTTl7utZr5YWwEz6jfmx2TFk5CpZ5s2it2py2vtingt/7mC0iJYoFoRmwR8xLLTKTh7VZaw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457344; c=relaxed/simple; bh=5WSoV3chfxnDvqnQyV0aEZGsj/JxeduOCr9U+LdSzhY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IgnBWiannsRfFQASQGnG1hPTZAmssn4YXTc6Ho+O1Ya4JvKVFkCco2VQ36mt+a6zDSpK0DKS+pcrziktVlf0EspIAu33mocuOwqPahLaq9quVci0VoxJcLExErxpdqKKkPWOPF5pIyGo9rGEoOBMhQvskbal6ZpEntkBK5YYtw0= 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=oToLpwDu; arc=fail smtp.client-ip=40.107.209.16 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="oToLpwDu" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=aTyDaD3igIvnElZA5OT+w9VYOckxVCQ/ug05t7We8fTWeICgjYZtm6GW7Z4q9ZK67v9x5ACQqj7fuMhTK+u+G2n+Em3iT1N9xoYtu9QHw0VlGAQmv5vPdP4nlFT44FDgw1WCf/lPCHBLgAOkm15t2bSxUHfNPk9AMK8/QtNkWKxSGUn81MIcJCvwaNQ7mGxzLbJMkTokpPs/uwUQnL9yegqkiXRvKAmDJH02aqfnhKJ7x5OrbThVqcLKKeacAfF/w3SxWNg9PvYsyAV1H0lRPvBv60WdC2mTT25a6O4O9UqTwOTBjmWEufhF6nxNlKPQeaizwvXb6+4ejfnoBADiUg== 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=f80J25Etcv17vI0fnNgG09jgF+b1b5pgYZHoPcIxZn4=; b=vb8RfDcEIgVb6UEkzDLIaiqXr94roUYxguayZBNWklBmTV3ntigmWPu2HZFJmE96ddRHs3QmkPgCNjZ7BC1rWSpiSMGxh6SRJcxOh5yx2CJtrNlhMIlAZklIWLnDsfqtf+6BjQbm141yqVvrY8vsAisxgCY+o5OmS6JgCPhulavwgL6f/GPZ8rcRvwmcXvSoKSVWP2/1b4cwqBm6W5hAVMU9txQ7ecyIQslXld9v2daJqDgP1mYMVBU54+T7/UQYtBMIED4858gwr+PHhASbTwbjlW7IMbC3B3gVKdJZELuX8aN/Zzbq+Iw6FDYGFWFCGHrJLcMS2Q9/Z46D2RrTBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com 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=f80J25Etcv17vI0fnNgG09jgF+b1b5pgYZHoPcIxZn4=; b=oToLpwDuM85C/zVd4ceilxjFiZBcdK+b4UNke1Lh0EdP1+4vkWCXo7CHdFilqBo/uKIP9ZI2NIDUPdZA/IL6kzslO53w+lc2GZ8Ru68GE2fhe6giMGF4sDiuBcfTCErHxXs8+X7iAGLWz+au9SjpjASfUcyC4CNsFVAVg731Pq8= Received: from SN1PR12CA0076.namprd12.prod.outlook.com (2603:10b6:802:20::47) by PH8PR12MB6842.namprd12.prod.outlook.com (2603:10b6:510:1c9::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.6; Thu, 15 Jan 2026 06:08:58 +0000 Received: from SA2PEPF00003F65.namprd04.prod.outlook.com (2603:10b6:802:20:cafe::1d) by SN1PR12CA0076.outlook.office365.com (2603:10b6:802:20::47) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.4 via Frontend Transport; Thu, 15 Jan 2026 06:08:57 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00003F65.mail.protection.outlook.com (10.167.248.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.1 via Frontend Transport; Thu, 15 Jan 2026 06:08:58 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 15 Jan 2026 00:08:53 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v6 04/13] iommu/amd: Introduce helper function amd_iommu_update_dte() Date: Thu, 15 Jan 2026 06:08:05 +0000 Message-ID: <20260115060814.10692-5-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> References: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F65:EE_|PH8PR12MB6842:EE_ X-MS-Office365-Filtering-Correlation-Id: 247642fb-f68c-4135-773b-08de53fc9290 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|376014|7416014|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?HyLck6GBGlBzHOBTpnPlnRGQ8+dttVutV0MBxjAorjcGHwo7oKZolW+N6/gJ?= =?us-ascii?Q?eHkMNusR/KqyVG8rY71QOGBBN75w1AsFdAgc5J6+4Vik+Re+7QlAD2EaXr1P?= =?us-ascii?Q?g00Hds9zvUbM5+Tr+dux8qxodTyedpNPvUDpS+aYmgS5etms0GKkdfPenxPy?= =?us-ascii?Q?a6TL+4nimgHyIK790/CIRbZQ8RN8jMq7/fwzViV5xve8ymaFkApWNkRKxmgm?= =?us-ascii?Q?MC+6ncUkTlhH7zNFWuMFQ6rr3UBcoa/oxT7zh7JUGEJsNUVLM0dY+9Q9c8gT?= =?us-ascii?Q?OolHh82fE7tjVQFIgO6WluoTGyOw2nYlSKcFOcbG2+QfGpsW3kRQ9nw66LjM?= =?us-ascii?Q?fXisKrXkn+mkMM8CBd/KJRk55GMAA55KdUflWFCdrR+nn3CB1juasxlfQa3H?= =?us-ascii?Q?dG0em85eSoCt3cY1aG1lpK8eggptd8955sEp16uyh4tjMgydedinys89C7aW?= =?us-ascii?Q?r3Q3yu0O02NDygUhTkSLgyGR48olwDGYHPJhxzS9x1IPij6vIbZYJiCLvngM?= =?us-ascii?Q?tHnKRbChsRbhL2pG4fY8pCrqfRNWPzIOSlkVuUVYByM07QcjWhU2Kk+ZYizN?= =?us-ascii?Q?0ISRkNPekugyIX06bH9M6WcerVHJ5TK7IpOlQqyw0mJnhygbKARAM7uNqq3W?= =?us-ascii?Q?ehwShg/PlcF40JAUrzbWUs4lddI4GuCFzo8RctF58e28/fSJH+dQ3V++wwkX?= =?us-ascii?Q?tRPecRLj+uOoWfNFylktPYeP1MT8qcvSPmbTKn6yi9D1rFuSkVQzDMEkgNDG?= =?us-ascii?Q?B1juxKlfjF+6b8wB294cdBYzddbAHWKvx2wc54xmsTZst2RVmxwqwUy2af2d?= =?us-ascii?Q?1WKdRuaCEQR0Genmz2qKsQnCExRrChsXYlYDU/WD8II9bg5h4pwY6my/17Up?= =?us-ascii?Q?JljhKbKMcaH10upnsu7QGEj1Rr7SMKZ2Yrf1GoQS5eQdf4C8F3kI0X/AqJl+?= =?us-ascii?Q?ggaUbizsHhThKRyZPWpmMMC5jXILk+uE5NA/jlofxZM6VU6MlSf99vOsDgy4?= =?us-ascii?Q?gfYcX+vcGVij7u+K3h8BaBD9HRWyLo+LB9VkodaOcer1bScLJNoEUC7Q3KGf?= =?us-ascii?Q?O296w2AdVdp6G976aDhzDS0BwcOzg9gybna6xbJznaOGFy06lC9M4Vx5Cmzg?= =?us-ascii?Q?G9InXfa9ECiw00OdasA259w+SsMssg3RJ2UutW2K9UZQSdz9dOo/VtcKokD1?= =?us-ascii?Q?7OX0/w/OAOXmio+WD/WZBE6mKMz88MrVBS7wbc32RlbutW03JMIY3y2PGIY0?= =?us-ascii?Q?wac+uyVccs6F13R8OPYHozRv8qaKiXKn1GdlKQja5N8OaIaelJALYYP4wVuE?= =?us-ascii?Q?+IRyIhVrpf7P0kbDFU7VacT+eQCmJDxxp8rG7oCJ0o4xCMyOKWLtqZ6+3TXM?= =?us-ascii?Q?atGtNpbfwrqvbFtr13oUXHCOzywGUJ4GNuZaiKMVeXCKpWAe7jIpW/KubJMO?= =?us-ascii?Q?QQhJnOWXVW87aVSMSR5Z9eim1FfCxt71GoMPhoaXoLP+Iyss5g7Kb7A10K6C?= =?us-ascii?Q?wuKhtq9nJ2yxPwZLPhYVHPyasKirInp5EetieDuIosHi0Q2oY84PeccDkXSn?= =?us-ascii?Q?jrPZLxAm1/1w2RV+rZ/YaGqQkBNhZoV9Kqxm2/nbFFdpMEw4FclXB/Au/WE4?= =?us-ascii?Q?v+IUS6XuZQmBrxVCNZ58vaDtRvMRctF/Ilxx8PWzGyBpLMe9336k0YrfGjrW?= =?us-ascii?Q?k7nTuw=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700013)(376014)(7416014)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2026 06:08:58.8276 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 247642fb-f68c-4135-773b-08de53fc9290 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F65.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6842 Content-Type: text/plain; charset="utf-8" Which includes DTE update, clone_aliases, DTE flush and completion-wait commands to avoid code duplication when reuse to setup DTE for nested translation. Also, make amd_iommu_update_dte() non-static to reuse in in a new nested.c file for nested translation. Reviewed-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 4 ++++ drivers/iommu/amd/iommu.c | 24 ++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 8eb5e9857079..d97b9b6d76d3 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -190,6 +190,10 @@ void amd_iommu_domain_set_pgtable(struct protection_do= main *domain, struct dev_table_entry *get_dev_table(struct amd_iommu *iommu); struct iommu_dev_data *search_dev_data(struct amd_iommu *iommu, u16 devid); =20 +void amd_iommu_update_dte(struct amd_iommu *iommu, + struct iommu_dev_data *dev_data, + struct dev_table_entry *new); + static inline void amd_iommu_make_clear_dte(struct iommu_dev_data *dev_data, struct dev_table= _entry *new) { diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index ded8d4ba86e3..6fea4ac97e3d 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -76,6 +76,8 @@ static void set_dte_entry(struct amd_iommu *iommu, struct iommu_dev_data *dev_data, phys_addr_t top_paddr, unsigned int top_level); =20 +static int device_flush_dte(struct iommu_dev_data *dev_data); + static void amd_iommu_change_top(struct pt_iommu *iommu_table, phys_addr_t top_paddr, unsigned int top_level); =20 @@ -86,6 +88,10 @@ static bool amd_iommu_enforce_cache_coherency(struct iom= mu_domain *domain); static int amd_iommu_set_dirty_tracking(struct iommu_domain *domain, bool enable); =20 +static void clone_aliases(struct amd_iommu *iommu, struct device *dev); + +static int iommu_completion_wait(struct amd_iommu *iommu); + /*************************************************************************= *** * * Helper functions @@ -203,6 +209,16 @@ static void update_dte256(struct amd_iommu *iommu, str= uct iommu_dev_data *dev_da spin_unlock_irqrestore(&dev_data->dte_lock, flags); } =20 +void amd_iommu_update_dte(struct amd_iommu *iommu, + struct iommu_dev_data *dev_data, + struct dev_table_entry *new) +{ + update_dte256(iommu, dev_data, new); + clone_aliases(iommu, dev_data->dev); + device_flush_dte(dev_data); + iommu_completion_wait(iommu); +} + static void get_dte256(struct amd_iommu *iommu, struct iommu_dev_data *dev= _data, struct dev_table_entry *dte) { @@ -2123,7 +2139,7 @@ static void set_dte_entry(struct amd_iommu *iommu, =20 set_dte_gcr3_table(iommu, dev_data, &new); =20 - update_dte256(iommu, dev_data, &new); + amd_iommu_update_dte(iommu, dev_data, &new); =20 /* * A kdump kernel might be replacing a domain ID that was copied from @@ -2143,7 +2159,7 @@ static void clear_dte_entry(struct amd_iommu *iommu, = struct iommu_dev_data *dev_ struct dev_table_entry new =3D {}; =20 amd_iommu_make_clear_dte(dev_data, &new); - update_dte256(iommu, dev_data, &new); + amd_iommu_update_dte(iommu, dev_data, &new); } =20 /* Update and flush DTE for the given device */ @@ -2155,10 +2171,6 @@ static void dev_update_dte(struct iommu_dev_data *de= v_data, bool set) set_dte_entry(iommu, dev_data, 0, 0); else clear_dte_entry(iommu, dev_data); - - clone_aliases(iommu, dev_data->dev); - device_flush_dte(dev_data); - iommu_completion_wait(iommu); } =20 /* --=20 2.34.1 From nobody Sat Feb 7 06:40:11 2026 Received: from CO1PR03CU002.outbound.protection.outlook.com (mail-westus2azon11010059.outbound.protection.outlook.com [52.101.46.59]) (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 918A22D8796 for ; Thu, 15 Jan 2026 06:09:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.46.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457353; cv=fail; b=ev7LhKh6w8p0GLFNMuU4rDm4qqnUbAZTmX4X5qlIuDaCek7v0AjcRiKECVP6moMTDbwoPYNviiabD/GQrmcYhvB6WaLrA8QSxGJTItG114o+Nx4SPTPN8yLAVLRkrAzsEyrq4emd6rEayvLp+jMxPDZbTpLUi+N9C5J9W5i3hUs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457353; c=relaxed/simple; bh=CvTGr3zhrSdTS7yWboiJi2FRwOPHC38YAxXAP/sveq0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QL2gJn4ElSx81O683w300H/oEXEriNv2mr4zTVxABfkq+0HW3/21McvheE2990tmIS7aR/GGrzkcaa4ZGdbF7x4tqU61qGYi8nZ/rDCLFH3G5fYNMMrSgvivSOxnllTtVe6KAfszXzKQxdKx5bWJ1H2kygrGc9iN7rC0PAPH7eE= 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=QRx+TFkS; arc=fail smtp.client-ip=52.101.46.59 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="QRx+TFkS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mCOjjiZSdnq2GUep7+euDZiEeblHOumfqrWJV1s1KTQjLlewSBL/FvyTfvJsdATXnkyMEp1HybjjqDKhh5TB0p7WpOu3I5t6UL9Zkkd3yV61T+QjAqJ78ECvZXFmZdCzOhn7UXdr90kRW39zOE4JtIdn376jUAtsPXxx7cr6u1TtmGRha4jbO0rbqGiLbjvOTTP7ARj5uDER63LVBMWmOCXAhLYB+lG1rnBKyyn+p7mfFtVJPeSz8RTOAYoM8M/loWe5z0ohxTdmx2ChhODRjppgKR98WtECmPoTfGJtqoMJm2Q4jS/yFPFcHvbw0yjIHGg9xnt0wgkzMTe+vYBSVg== 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=ZlR8CiAy5HrhukKNc33sCqFdfksok7tMp79bTJkb8OY=; b=MEmjeW/CrybGBE5syfy5q3zVYaedL6jbb0NjjZiJbe9k27QGxy/rg3ZjLEe0oWKG5UcrXctTFLK4SVXZHEpvZXyWZUv9eZZdEoapIZeiICSbdbdtSX3QEeslpBNzHydW2JpH4pTCXh/862FnXcdpwpT8zt49ZMivoJDfT906Bz2N19ZDEdhvsO7Hc781+hitN8WHCgkJEX0G09n0jBAzOgDOZMzWf+oc2EZ0W+Bu1iXAg9nH/iCeXBt4GKUY4+//ZjzxjqnyIQSPWY23WAaUTrzZrLs565rLgbEIKKfOJYjZo05pEWtaroOYsfzwTVHQR5uOTj1ILLu6bp6A6AWSAQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com 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=ZlR8CiAy5HrhukKNc33sCqFdfksok7tMp79bTJkb8OY=; b=QRx+TFkSeGDhGwrMquF0rnPYLW+LxQ30S0OmFL8Zv7piGVYxZLXNWTXoqgDFk8sH90zFLqRf99wzjUvKUAOhU8KNu/Wjl1QPvdfKEROjpgr+u9zk+GNKfxZIW7XCOAfemIclmWcoIIt/J82wsmW/pqkdJIJrdcwcYIyeerzMx+w= Received: from SA9PR13CA0056.namprd13.prod.outlook.com (2603:10b6:806:22::31) by BN7PPF9C6E5285F.namprd12.prod.outlook.com (2603:10b6:40f:fc02::6db) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.5; Thu, 15 Jan 2026 06:09:06 +0000 Received: from SA2PEPF00003F66.namprd04.prod.outlook.com (2603:10b6:806:22:cafe::ca) by SA9PR13CA0056.outlook.office365.com (2603:10b6:806:22::31) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.4 via Frontend Transport; Thu, 15 Jan 2026 06:09:06 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00003F66.mail.protection.outlook.com (10.167.248.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.1 via Frontend Transport; Thu, 15 Jan 2026 06:09:06 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 15 Jan 2026 00:08:58 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v6 05/13] iommufd: Introduce data struct for AMD nested domain allocation Date: Thu, 15 Jan 2026 06:08:06 +0000 Message-ID: <20260115060814.10692-6-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> References: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F66:EE_|BN7PPF9C6E5285F:EE_ X-MS-Office365-Filtering-Correlation-Id: 3570f0bd-7067-4c9d-c26d-08de53fc96e5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|7416014|376014|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?w9xRK7klWu9NmjWlp8ojglnf5taER3xXjjwTwjOhjGIQwFssXkq0wydPwOpq?= =?us-ascii?Q?JefFIiVY5Tiwin22OKil7Op9fsEC63Njgix4AgBtGR744VJ1lfzUeCE5ze8z?= =?us-ascii?Q?MjYOlfDvZ/X5wPBO0CXOqGCwUTPuGU2rDKWGq/veN8FF0EBWIEKz4/5KANgB?= =?us-ascii?Q?Gc0fjPP5IJ50WRo98+oZfbBF2A2SwKIgsMGlZtZb0Mbo2Z7GX/7FXLO4+VGj?= =?us-ascii?Q?5PsKnN13hMx6TwzuIiB8td/rR9ZDbb05SA6v6qUKkyzeuGYNb3b9MjhPNHW8?= =?us-ascii?Q?n+H/OcCLECZtIBvtQ3CkckqpreK6uFzmCO1lc8lhRdbPuZVVpUJ3cq5VZtkf?= =?us-ascii?Q?jRg5FkjbprXkX7DzYptMrbnQVMcdqwjWDwttu9Ad/4e+DrulMG130LF3K+tR?= =?us-ascii?Q?z0scsHA7lk1l4ahgiJyLW5d90mvARdNwRnNTDXwu3S2esJmPmGmTSESmCtjp?= =?us-ascii?Q?ReZkZZiwk6xlBPVDdsQTIfRUiOUKKdwlEoiRTlSxbuPZpSAnEdJM3uz5zMCS?= =?us-ascii?Q?OLZPh5JAQeBQmAo+Tea9alvyILi39/1LtRrTST0qBMH+cR5I/j7byZrWEbkk?= =?us-ascii?Q?7FQhIgQBrd85PW56AKUgVgLQU5brV1+6T9NwUqgo7aUcSgJwR1jGKOe+cOmn?= =?us-ascii?Q?eDM3gp/tKibZ4lWJdxmWYvs6pVHj7NIzlSM2jqIl6Uiyn3P39upvhBpuD6WY?= =?us-ascii?Q?md9pF9Lg39bOzWS+qmLM0dcCo3yR1KpSi4dT+eNozMZVfcAdxxJWpoKMI1K3?= =?us-ascii?Q?UhRJJn17X+m8jivEEqHelxu4C9MBPnkewHXfdR5Im3aZtz4Fj++VJte2eP+T?= =?us-ascii?Q?AbggzmQgFXl3f8Md2fi9PJUy0lbu6zh2TUHRX49nCBx4Bvktz1OCNkaFJUx1?= =?us-ascii?Q?RALxjwQ1LtyhYK3+ulqo2C5Ui3x0u4Aj9qWAdudFSt7KobmVbRF2kO8848RP?= =?us-ascii?Q?ScqObKc+LhZbNA7KUBI+c4Bg8ckYsNX13QTJLlSn7I9pfVd0jXqPUefu/jRq?= =?us-ascii?Q?rG6Gp4ytNZ5hweMcWGfAwmcsxpHYoMStY4fbN4kEur3pCobhE1ALAxqT/ND/?= =?us-ascii?Q?/dPHnJoElLJgJwZXUQF1zUQBzCCQ+8YgOWgKNf8Msk4aywUbFRD4jCow3Ekw?= =?us-ascii?Q?kCFJ2jV+9wCEcZG5mCQH7Dk3C5Ht6gFiGg+I5tkqywHTxRGduYjr93+FV7Y8?= =?us-ascii?Q?dT9NPXAbZeUMzWHaJcuvDCWTyEzSvl+e/gOSa//iMyTT2j7N9/yIhPWI7nYM?= =?us-ascii?Q?MfVefatj26GOgXskCEXEMXHiHbNoZLxvwm3mtjxmulKY5snMVFPaOe+OxMh3?= =?us-ascii?Q?EZStjlg9Np81nOxUMYMkuIxwjCPhUB3A+jOqxgIgd2TTM7llniP1yhXI8FpK?= =?us-ascii?Q?TZMDYUibA3EBCmHq2IWhNx38duLSXmXXIz4CU9tOPbF/MzvHm0PSuOODUi9h?= =?us-ascii?Q?DCOgP4mmKDCcXWVtKpGMecxPIPR+DMEUv7gvchZSybCA4/ojUjI4dmV5e/Qi?= =?us-ascii?Q?18aH84EFrwDcXiIaiWIorB5SXk95XINrzjdODk5V/NNpHmYAJhXhdq5JeBMG?= =?us-ascii?Q?LIV2lETMQAr4dlC8giURwWzjGp3SW3Odk8Yc3w5ttIXmidZOUSu6vhQVztz9?= =?us-ascii?Q?waclnWtbNHB4O4U68Amvatpz7pvVTWM1dHlM7ymSd4w6NFpHJUUIBgDe39Al?= =?us-ascii?Q?Bx49Dw=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(1800799024)(7416014)(376014)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2026 06:09:06.1292 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3570f0bd-7067-4c9d-c26d-08de53fc96e5 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F66.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PPF9C6E5285F Content-Type: text/plain; charset="utf-8" Introduce IOMMU_HWPT_DATA_AMD_GUEST data type for IOMMU guest page table, which is used for stage-1 in nested translation. The data structure contains information necessary for setting up the AMD HW-vIOMMU support. Reviewed-by: Jason Gunthorpe Reviewed-by: Nicolin Chen Reviewed-by: Vasant Hegde Signed-off-by: Suravee Suthikulpanit --- include/uapi/linux/iommufd.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 3db37f6042a0..1dafbc552d37 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -465,16 +465,27 @@ struct iommu_hwpt_arm_smmuv3 { __aligned_le64 ste[2]; }; =20 +/** + * struct iommu_hwpt_amd_guest - AMD IOMMU guest I/O page table data + * (IOMMU_HWPT_DATA_AMD_GUEST) + * @dte: Guest Device Table Entry (DTE) + */ +struct iommu_hwpt_amd_guest { + __aligned_u64 dte[4]; +}; + /** * enum iommu_hwpt_data_type - IOMMU HWPT Data Type * @IOMMU_HWPT_DATA_NONE: no data * @IOMMU_HWPT_DATA_VTD_S1: Intel VT-d stage-1 page table * @IOMMU_HWPT_DATA_ARM_SMMUV3: ARM SMMUv3 Context Descriptor Table + * @IOMMU_HWPT_DATA_AMD_GUEST: AMD IOMMU guest page table */ enum iommu_hwpt_data_type { IOMMU_HWPT_DATA_NONE =3D 0, IOMMU_HWPT_DATA_VTD_S1 =3D 1, IOMMU_HWPT_DATA_ARM_SMMUV3 =3D 2, + IOMMU_HWPT_DATA_AMD_GUEST =3D 3, }; =20 /** --=20 2.34.1 From nobody Sat Feb 7 06:40:11 2026 Received: from PH8PR06CU001.outbound.protection.outlook.com (mail-westus3azon11012009.outbound.protection.outlook.com [40.107.209.9]) (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 B1CCE2D59E8 for ; Thu, 15 Jan 2026 06:09:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.209.9 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457361; cv=fail; b=ga7QN/GgerDqTplnonZbwx1jPNpGHyYlcwjuTH7PfiYr8JfVCQ0E2j70lRcPXJX5g7jTnyxpZc3j3xcRq+jeyhvh86WMN81ZJzZpljXDfD5lnyz7WC67TjZR+5bQhjebGcpOxzH7AninVF1mQlii/7eKFVR68fS5Krw3d2DLuSk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457361; c=relaxed/simple; bh=EJJgtUoCKj6FhyMVkQTa1AGYFjX+NIDYWgv1lqoTy+c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FlpxoKp+k9zn7TqeVfhnAPT//fc/f8pFpScy0WXidlVvGCEnFhaPPl23Ld3wamMGpCm9S0/5O4l9T6naJyeI5iqAdpDGNgNOPjQo24tXMSfesUCrwPQDwvG6lMqeeewm87XW2GhDwTz2ChwFdvMNNEFlVqjn9iHKEpGKe+jhj/o= 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=470R9TJF; arc=fail smtp.client-ip=40.107.209.9 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="470R9TJF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=c6Dxm+22IjEKAvoT0OwEouFDyFGCvvsAIa1N5NU1G3s1b74+7LDTWJBkQgTuZ3KNw6FaBmTgRiXS3hLO0qO4b+tM8YLBdrWdqN9dc4SYfXIRqMPpJ1QjOzT1YRdi/kPgy59CoDxooXie84KpUAQAPlnuV2SdaChFujXfcLx2qNjhj/jXv743GJXbmeQYGgQJLDoJ4sM/Q3FIIKd2NMC29aAQyyQcDayJ58BvOQuLQpOAFNXhSS9R7B8MotfFmgD0aMBzUBGApWvXEcBMLy/3jKYGKOt/SD43oZ/2VKyuFYOqX0vVZ1uM3ocVzSsUkLZk551jXjJBq5XNqVxJ8Uxlqw== 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=PK53GPvKI6mUiT/N+CgLS/T7xXZIp5miW5Z7f+uxhb8=; b=QPk+aKmItYgjBDyxGwWupb4bTeWm6KI/Rmlr4F/Vo41DNtF0PCXb02rBvCzo9w/VT8UfqVc1YJWOm3ZjvpNQwXu2/j8H8ewAmfHNKT6aUdbWzm7X7gi9fI321FU4wbbK4dDrvke7qbvYXu7Y7XNzjzKVntloHPauFkvEHemwb7+A5N/mywRJReqOtNPX7pFjr6Tpj2A5BwN6BNC2lDal8BCuslpQUq3UY3pbKWirLD5AaXcYORaW4HrHcWyk0p22iL5OqOj7pWHRaiXpyZtDvYYrjHdlJ6Q82imO0LsQyeCUsJ6KmAIHGTYfm/1WmoYgUbTM4WXTGRDJBMb4tYyZZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com 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=PK53GPvKI6mUiT/N+CgLS/T7xXZIp5miW5Z7f+uxhb8=; b=470R9TJF/+c4UVezg+ZYWorjIn9I87DGxDS182CaJrRnEQSxgWI/dlUGt0T9LwzYSNRJuTt+aGJ0FerJ7y1qcthALeiPNEHmJcX0piAqUCQVqZ29KZuPUSBwoWFz0/IXhSTPfE+YY6ic6LGXl4a/5wRhSEvDcu43HEaywwMCgbA= Received: from SN1PR12CA0050.namprd12.prod.outlook.com (2603:10b6:802:20::21) by CH1PPFC908D89D1.namprd12.prod.outlook.com (2603:10b6:61f:fc00::623) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.5; Thu, 15 Jan 2026 06:09:10 +0000 Received: from SA2PEPF00003F65.namprd04.prod.outlook.com (2603:10b6:802:20:cafe::9b) by SN1PR12CA0050.outlook.office365.com (2603:10b6:802:20::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.6 via Frontend Transport; Thu, 15 Jan 2026 06:09:10 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00003F65.mail.protection.outlook.com (10.167.248.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.1 via Frontend Transport; Thu, 15 Jan 2026 06:09:10 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 15 Jan 2026 00:09:04 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v6 06/13] iommu/amd: Always enable GCR3TRPMode when supported. Date: Thu, 15 Jan 2026 06:08:07 +0000 Message-ID: <20260115060814.10692-7-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> References: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F65:EE_|CH1PPFC908D89D1:EE_ X-MS-Office365-Filtering-Correlation-Id: 1ce2c90d-db76-46a5-2a82-08de53fc9970 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|36860700013|82310400026|1800799024|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?TMTKDSvihp6GQ9scjyqzQo6nDUrxQJZ5LEWkOACL7K2cH6OWBWF6RfnlGkgQ?= =?us-ascii?Q?0k5ae8a5kDrcQ3HCUEsoCkPcyeySmma6gWxx83Gr+QV4HmqNDU7J3dO2cpF0?= =?us-ascii?Q?2vE/JU1YlcQkGrbL60cT1A/bTsjz4gV7uzWfxCLQlU4MpEc1kZjGr88IgTbR?= =?us-ascii?Q?5EEuNYniQ2aT0TaHmNn5PMsTBdhBD1NY6T8kJYRX8gHoew7oCUbgdz70qRoU?= =?us-ascii?Q?R45yh1UbqyoTCjlk/7/iz4Fbhx0w2ZI0QrhxSOAI3ZFJkmnoFHM91zf0ZIwB?= =?us-ascii?Q?wWIihVVIWfrh52yi1Fr9saPeRcx3o0jQ96/XnAdQ8tuhITnpwJ/MD14KOhtQ?= =?us-ascii?Q?ZwWCh/qJEs9o2tu9WW0b1gnQgegfW8yKZ91j934FZbLMeNuWJQaUB3nDUdgc?= =?us-ascii?Q?/o0LOT6Vii3LQlg+RdkKfT1QpOv51b/oBNPIfcpZxTYByFrnyzY1L/3nB0tm?= =?us-ascii?Q?3eOQQd/nMRJtl9pmtOdwi6MYMd4NIErIOD4+5hWPhAYwIYmHLOs0xRUV6zeZ?= =?us-ascii?Q?bQ7qG2S9XESh9yIgWVgkJH6HkFr3UuwUOcR+CrYUtus9VkvIu9GxlZXzWA+c?= =?us-ascii?Q?Y4jbEeSpW2SrQD2HOQjXgLpIaCbXNUc3S53nYMMjIJOU0PVBUgZTxlmj21IE?= =?us-ascii?Q?aFBOdNz24L3IoqnNnLn+TGO0pom+OLPtLmMVD26A1A7jkZQewsM0jLodWSN4?= =?us-ascii?Q?dXpGNeA6140VsUD6IJmnjsBxgnGjJ2eCroEDra6dUWMFYV499FVirDAjYpgw?= =?us-ascii?Q?qzu79/2g/h7XDm5xzakA4MyjN0raekOU05pKe0E1Nw88CKP1zHr0nndDVdvc?= =?us-ascii?Q?f0u3vfdSMHMIqeEpJu150cL5c3CQKwesPb1TWMV7NsXPbtiphPeeFaKsGT+K?= =?us-ascii?Q?9LU7NbalTxc1KMdH2UUIeh4xTS+TN5F9Fm0YgceAnFbf/8/qdSE2cEm7JgRG?= =?us-ascii?Q?bvxnP2fxbAwWm5CceYaedNTCFN0O+f+t7uxweB1Gq3RVMTjS268DQNHfVH9G?= =?us-ascii?Q?JaZ1NY5OqHpZJnd3LovUbmOVgZ6AoVupfyy700DT2MjYUXq3S/UPZa09pJ4+?= =?us-ascii?Q?LzsMQipWXguGM/2zv/cPkpp/kkGG9f3/vVwK6luHhkfjqBxcMYC/DxqvWz75?= =?us-ascii?Q?8nuszTPt/J3UDeCqgTuvPLM+MHMf8BwsUWnhTPLL3rHS7FxQAtjt28EF47Zc?= =?us-ascii?Q?utAG0g/xsDiXzHvvdVYoKIod0Vfm5YeS4wIp8/eX7bfDSax9N5wBByW1B8ey?= =?us-ascii?Q?ZCJZ3GOEhbc1oOMcXByzEDLtiwaZ99LH4nVMu9YyP5MHnLOD20Andtu7cSc5?= =?us-ascii?Q?PSwVtcIcgZL2R4i3az5bu+TAUbyQ7lDqwaYAc1OVf9DwOFLkp/DJH3OkseaQ?= =?us-ascii?Q?hPWl3mYgpbZdSwiLl5XHL151oAWL7/15b5QFrNPkiXkwkQPc8t9xbj5XghpV?= =?us-ascii?Q?p0m5LgmMMMwP3UdCNEwa8qAFGGKitpiMjTNhL82l9NpteQE7/HitqSJ2F6Lo?= =?us-ascii?Q?t8wgQccuIUNN5pc20bO4CUd4lE+47HdQM6f5eC9g7qo1ajKS2o7X2ZV6jHRp?= =?us-ascii?Q?w5/jlPhNQNeowzIMw5ajjYWvFe3FAW3TKK3t79Hgajy3rJkzrITbakwXRMK9?= =?us-ascii?Q?jN9cHQg1bX3046GBbraydI3Dwznn8ZEBlu411zZBSXjH?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(7416014)(36860700013)(82310400026)(1800799024)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2026 06:09:10.3608 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1ce2c90d-db76-46a5-2a82-08de53fc9970 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F65.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH1PPFC908D89D1 Content-Type: text/plain; charset="utf-8" The GCR3TRPMode feature allows the DTE[GCR3TRP] field to be configured with GPA (instead of SPA). This simplifies the implementation, and is a pre-requisite for nested translation support. Therefore, always enable this feature if available. Reviewed-by: Jason Gunthorpe Reviewed-by: Nicolin Chen Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu_types.h | 2 ++ drivers/iommu/amd/init.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_io= mmu_types.h index 14801d734684..d8753841cd1f 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -108,6 +108,7 @@ =20 /* Extended Feature 2 Bits */ #define FEATURE_SEVSNPIO_SUP BIT_ULL(1) +#define FEATURE_GCR3TRPMODE BIT_ULL(3) #define FEATURE_SNPAVICSUP GENMASK_ULL(7, 5) #define FEATURE_SNPAVICSUP_GAM(x) \ (FIELD_GET(FEATURE_SNPAVICSUP, x) =3D=3D 0x1) @@ -186,6 +187,7 @@ #define CONTROL_EPH_EN 45 #define CONTROL_XT_EN 50 #define CONTROL_INTCAPXT_EN 51 +#define CONTROL_GCR3TRPMODE 58 #define CONTROL_IRTCACHEDIS 59 #define CONTROL_SNPAVIC_EN 61 =20 diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index cfbc9ff105c3..b1c344ed7dbd 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -1122,6 +1122,14 @@ static void iommu_enable_gt(struct amd_iommu *iommu) return; =20 iommu_feature_enable(iommu, CONTROL_GT_EN); + + /* + * This feature needs to be enabled prior to a call + * to iommu_snp_enable(). Since this function is called + * in early_enable_iommu(), it is safe to enable here. + */ + if (check_feature2(FEATURE_GCR3TRPMODE)) + iommu_feature_enable(iommu, CONTROL_GCR3TRPMODE); } =20 /* sets a specific bit in the device table entry. */ --=20 2.34.1 From nobody Sat Feb 7 06:40:11 2026 Received: from CY7PR03CU001.outbound.protection.outlook.com (mail-westcentralusazon11010038.outbound.protection.outlook.com [40.93.198.38]) (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 A50A02D8372 for ; Thu, 15 Jan 2026 06:09:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.198.38 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457362; cv=fail; b=mzQXYxVkGVkUpYA/MSCj12s+6qblJITKqu3qKMwMrwWdAR0DkXbF5TFhm0pckpi7VaRSOfpNKH6VfkVVeJXpLEuGBTZQyPw1bwa46GdGcaPo1De0sW8Lm4+mCekxPrN1aC/Vg9gHFEVigQ33jVI+2PdtQqF07XRz9i33WYyfNQw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457362; c=relaxed/simple; bh=vvVSLZ9ImZlYsqAZdzEiSbitcT7IzVZt0fdTi09B4Y8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KbvhrFswFLxgJD9j6tIhKU2fUI/7iz+E0mgTtS6nmo+sYkl8/W7cbQ8Nz8DPHO6+aGM0vHke1IjBPXLcaG4txMTofF/2dkBO52hhidAvyeiU8A2uccTg/QV0iaROOFVdR0U7EWVkhr9S9whLQRGWsQDPYRtK87FcT/GeyfSrrwo= 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=ZiZ2Qu5v; arc=fail smtp.client-ip=40.93.198.38 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="ZiZ2Qu5v" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kQw6YjIJXM2tvrIpQ1weqJ2Vql//PkaH4+K5FM4z5YiYKM5r5EvM2iaKZvG7ERSPIhfQo+0cGgVNiiyTrxb/3d8yc9VAo4SOJImm9UPBMySv8GlDhxyxFjYCRpdU2s5dqIPxld/VfIX4tJUpTG6hUyMmw0ugYwmIekAeaPkz/GwWXppwSPsd3eoN7haQj1Qbc+w/aDDudRwRJKbT0mxVN/2pko3nvj6vYfJIJEqJ5jnSz2Zl09DOZY3wiPSMCfQuiDPPUluT/gmY32FXKzjcwr/W5oKq76MWaTHhuM8s6364Q9Z03dzfOTe7Nkq8HTUccJt2dxMs2dn7MSds+3SM1Q== 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=t6wfwZHH41RL/zq7uyzKNqn6z7Urm4pJvs3R7I3hIA0=; b=R2rPSHsI4oxdzpmtOSQHx4/GZwVFoQqVKN1dwTdHQH6tAHe2horuc4lpNLr7RMA1fVu4byWefEm3PbTcQNLNrYqyndI1WPFgR3onFq8ajH5l35WXTUWC4DN/5EajRp2UYICwUfvDPQHosfwRov0VDItlle8bkLzohKWQSq6wPiTwQPvZeMVYmCmAwibG1xe1knYTYOxJKleRKNar8vJBKlVvLCsdJAWabSfQrK218q6R95bXZ0SFRP2eM5OuLuKkz3l1ZkquEjA/iEgXiBGMAkEW4ccW8LaaxB5KgX86EuuJuLZQ2csMqOE1aw23bgxMSde9dkTCsi9IfcQyWzyJxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com 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=t6wfwZHH41RL/zq7uyzKNqn6z7Urm4pJvs3R7I3hIA0=; b=ZiZ2Qu5vJ3snyy9iFv3ehwcHs6Sf8NAiCjbp3Oz+o0dyKYrI6yYIUbtCEK6Gq/b93u3Fh9RRfgTKfn++P2Wv1gPuc3uhikImlJkYTBI0U2ZHZV7wmru2nXTLbbn+knX5JHUDdj0ZvldxHcY1YnZ+buEmISzeY76TSETgNfhAmGA= Received: from SN1PR12CA0063.namprd12.prod.outlook.com (2603:10b6:802:20::34) by SA0PR12MB7462.namprd12.prod.outlook.com (2603:10b6:806:24b::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.5; Thu, 15 Jan 2026 06:09:16 +0000 Received: from SA2PEPF00003F65.namprd04.prod.outlook.com (2603:10b6:802:20:cafe::8c) by SN1PR12CA0063.outlook.office365.com (2603:10b6:802:20::34) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.4 via Frontend Transport; Thu, 15 Jan 2026 06:09:16 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00003F65.mail.protection.outlook.com (10.167.248.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.1 via Frontend Transport; Thu, 15 Jan 2026 06:09:16 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 15 Jan 2026 00:09:10 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v6 07/13] iommu/amd: Add support for nest parent domain allocation Date: Thu, 15 Jan 2026 06:08:08 +0000 Message-ID: <20260115060814.10692-8-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> References: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F65:EE_|SA0PR12MB7462:EE_ X-MS-Office365-Filtering-Correlation-Id: 17ed659c-3f31-437d-8b59-08de53fc9d35 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|7416014|376014|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?A+MMDc3/cMEJ/+zbsGLJBRi6ANEQ3mGp3Au4KdyAF/SBmekRcpJ02CsjF+DH?= =?us-ascii?Q?aC9Oi9rSs1sIX9UPAjvQCB1aHBwG/PWVtcMk+fBfVDpq2TcqBl89d1Nt5t+n?= =?us-ascii?Q?px+5YoNH72k+SCZQdskBtNVB3PKWi4H+A38bMIvyJOQFL9yACp3v2FeBAAOA?= =?us-ascii?Q?2tCJytitXSdme5iMZKKaanCv9kp9UU1Jr+3Km44mIrLesAxdKDb9vrl/RQL+?= =?us-ascii?Q?/jZKgUE4pmWt1/XUFKXUNddHzVnQncy11XxEuFfzxXiCTbMPG2Agvmexp8bG?= =?us-ascii?Q?lfAUJyq6yhFLsq3qVE0Ae3RbuQZTGLKmyAA0+niLD9RUVhmxnTmLUnzJb6Ug?= =?us-ascii?Q?splZwsd3H3SwJK8qlUd5taox8FJwhwOrTL8S4sm4/zepjJ90l11uXunXN/cz?= =?us-ascii?Q?Bk5VuM87Got2N+IQ8j6rmZuk97JDwfBoHPmeymkld+UhF+CaniWZ8PkxkXMT?= =?us-ascii?Q?ZcUmCuPIuXgtWF2C82m1BKzh6IYymhXyzIX6PaJ0Eg544RfOxWW+rSFA0B5v?= =?us-ascii?Q?TlxkXxrXXn1ICPSAU3jtbNYfcLr4oxwQ9spNYFWe77V+/KC79HHD2WmnETDG?= =?us-ascii?Q?kjUGzcOrl56/UNlJsOeHut8Dmg+B9q72sexJv+ZXwYZ+dpJ4FU0MRAXL17wg?= =?us-ascii?Q?Nw/a131MDSjRbvXGTzPj0DL3LJmndQZjLyejrPAIKDFZnwBnqTWV81lThj7X?= =?us-ascii?Q?JWz07a2UsVVsXGru4vPaz54yakt62WVPoofPvELnnLyuh7ZDbeHSADAHCyBk?= =?us-ascii?Q?jFEeDsJb2B/zW3TPONxU1mnp1+AA0q/5beLJ9AISyx3yQ/0FlXnc0K10vrOq?= =?us-ascii?Q?hVVrYs3Ux7knfKwAUafhpEyaUTNYDLiMoWm0um+sVLK7AgVPy/LeExGfn1nb?= =?us-ascii?Q?0DZJFZEwYc+DcZNMB12qUoWJ9ugfLZ7sLHdiLF37Pi2QXQiIw1C/KUKguEic?= =?us-ascii?Q?YnB2aoEZH5SuYnuiumfxx2JZ4USw9Ae2oRCK1xfVGWJr2qfaFrKHgLjz0zvn?= =?us-ascii?Q?yQHT9L4AIhlNsdAnQ0/R77MTBQZY/l+uniXI7Sy9XK/So/Gq2Z7LQ6JDtxiR?= =?us-ascii?Q?QFsjzJ81D+zFQCUU81nxg78OwkAHYw+uLqUsN8LL35kb37Jty5FqH5KeLWDu?= =?us-ascii?Q?5RK/VdfKoFum4BOSC733hGOuAQi74JqdChc83ot3FPSSToy6mVwXI/48T/Tj?= =?us-ascii?Q?t1khNVEcp3FEHrIT2aKGnGp3z94cchoF7Qdcwa1wLXmvB+oxwPxjZc8fyGOq?= =?us-ascii?Q?ipSZ8iUply0sTipt67LNK7US63XPlW8n2lmdgE5ppKy/yht9QDKhZpqBKf2l?= =?us-ascii?Q?e24grOFz3vxwpJexXYbOOAFP+Lgh32ODAHIOPHcrBLFycm5d5w96jIPj3Rps?= =?us-ascii?Q?RHCp6VPzkYEVmIztLFMN0nAy6Sg7UexXb1b5xvyIbtxnNcPtQsiEc2U3BkVn?= =?us-ascii?Q?dSfF4+n/NatA0W36MKzJJXAt2d0c5cf/aqHcxfwqRY7+34awL47e7PY+ILMi?= =?us-ascii?Q?EcICpMRn/R0fdYGT1lS/qr364HNctDK6DbIuiiA9SL6Lxl1qz2uo599Z801w?= =?us-ascii?Q?QfTYGvoPXqfTBWguhLFLIBHkZJm0L9PGqwvD+FLlrC6jT8RDNENBFoEahgHL?= =?us-ascii?Q?NqCNk2iXWTDH+xqNe7YdhDk9R0uRJ9s7NzBy4QebBAXpdsEJVKoGFV9jC37P?= =?us-ascii?Q?XRZ3kg=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(82310400026)(7416014)(376014)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2026 06:09:16.6892 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 17ed659c-3f31-437d-8b59-08de53fc9d35 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F65.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB7462 Content-Type: text/plain; charset="utf-8" To support nested translation, the nest parent domain is allocated with IOMMU_HWPT_ALLOC_NEST_PARENT flag, and stores information of the v1 page table for stage 2 (i.e. GPA->SPA). Also, only support nest parent domain on AMD system, which can support the Guest CR3 Table (GCR3TRPMode) feature. This feature is required in order to program DTE[GCR3 Table Root Pointer] with the GPA. Reviewed-by: Nicolin Chen Reviewed-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/iommu.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 6fea4ac97e3d..9b2fd852eb88 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2765,6 +2765,14 @@ static struct iommu_domain *amd_iommu_domain_alloc_p= aging_v2(struct device *dev, return &domain->domain; } =20 +static inline bool is_nest_parent_supported(u32 flags) +{ + /* Only allow nest parent when these features are supported */ + return check_feature(FEATURE_GT) && + check_feature(FEATURE_GIOSUP) && + check_feature2(FEATURE_GCR3TRPMODE); +} + static struct iommu_domain * amd_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags, const struct iommu_user_data *user_data) @@ -2772,16 +2780,28 @@ amd_iommu_domain_alloc_paging_flags(struct device *= dev, u32 flags, { struct amd_iommu *iommu =3D get_amd_iommu_from_dev(dev); const u32 supported_flags =3D IOMMU_HWPT_ALLOC_DIRTY_TRACKING | - IOMMU_HWPT_ALLOC_PASID; + IOMMU_HWPT_ALLOC_PASID | + IOMMU_HWPT_ALLOC_NEST_PARENT; =20 if ((flags & ~supported_flags) || user_data) return ERR_PTR(-EOPNOTSUPP); =20 switch (flags & supported_flags) { case IOMMU_HWPT_ALLOC_DIRTY_TRACKING: - /* Allocate domain with v1 page table for dirty tracking */ - if (!amd_iommu_hd_support(iommu)) + case IOMMU_HWPT_ALLOC_NEST_PARENT: + case IOMMU_HWPT_ALLOC_DIRTY_TRACKING | IOMMU_HWPT_ALLOC_NEST_PARENT: + /* + * Allocate domain with v1 page table for dirty tracking + * and/or Nest parent. + */ + if ((flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING) && + !amd_iommu_hd_support(iommu)) + break; + + if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && + !is_nest_parent_supported(flags)) break; + return amd_iommu_domain_alloc_paging_v1(dev, flags); case IOMMU_HWPT_ALLOC_PASID: /* Allocate domain with v2 page table if IOMMU supports PASID. */ --=20 2.34.1 From nobody Sat Feb 7 06:40:11 2026 Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010018.outbound.protection.outlook.com [52.101.61.18]) (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 304DB2DA76B for ; Thu, 15 Jan 2026 06:09:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.61.18 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457370; cv=fail; b=WlR8qXvwcMCTBASQXAwrHSL5RuroWYWz83uXjp/WpSvYqA//lprR9+Qp6rYqcswzniRG567YZdnJXEjHROIGLI8x74oYulk9U/ijGTipxPexOQ9/ENoBQaozVTD4i5yHYeB2NBeaj5bJqOoGlRIGEn7GxuVPAGQLytHCZ1p8sCY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457370; c=relaxed/simple; bh=3Quf0CxSMAlmWSULneDJVUR+/XGXV2VzvmrM1GNHF3E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZCqDwJfXjTSjx62Ui15OVx8ZuCJ9IpqITeE8D7dmLPmC5ebly5lDWL8qmUrj3s5cazfH3kRFLK2u2tWFpFtvmSvuO+ofbSw98b/0hBv3EE5TtAkg9pLKkM926UwPnNfVtaQ84FsxDtKT3us/H8XddPAj1m78IYhPDnTAosjss6k= 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=C4i8mtIk; arc=fail smtp.client-ip=52.101.61.18 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="C4i8mtIk" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dtKS5Jkj0my2hR6zgCBCZNZ0KnEdb+IY6ap0LseHy9Qo0c5rSlHHvQy34mZSGzY0jjI9sNxxBjqIgJLF954FBttN2N3B2wSNxUlmweEaari0NUMePbSBgVogCMbQCNh2nNN90mOKucDzIKTwarNjVpeHWEAqsIrXZktC3QIStD6vipFjNBef+BOU422L/TWxYEvpF6YIzwpvq/reun3wFTSvnPfedQ1Oj3pTcHzKsL2Wh4ioHZQn5qCFhw0jT4o+Gr1Y2rCacb5bZ/FMtZxfznv6DcnPZki6JLxEBb0yIWNVySUqSCv+7WQJrEktZHnuAClkzjz6q1WW3YnS6QXLIw== 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=q+kUiqxtWYTWg3e1BwLTtmQz5OY17FaFR6hrabfjsrc=; b=oiAnq72SLzI7GkahjGpFCTbQojnFM/DKcv9iNVWzw1DV6qnlE/cpNPumFUG5kWswp7GJuCbj1nBxljQlvJXCebTEmj24gKlQHhiPgAbHra5IgSNLoZ5VVyJBfximibnl5+kH7Ar/Ex2/Kp5EbD9ubl07lu2kcQio4AM0jDV4leeUxefMP6kwCnCOKEpwG+xHE+BkZ+6w/aBykP1VON65sNGTHplFFdBysbuLH7dljN9B/qEANc84k1HqZzSy4RVVcAOMooUy4iA3laAPO6QMRvdRkv9o4NVKx7FlIoRzhbbRdTwqi1MJrxCrCSBq3a3kwvdVXi3IWxywc2PXvaA2qw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com 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=q+kUiqxtWYTWg3e1BwLTtmQz5OY17FaFR6hrabfjsrc=; b=C4i8mtIkbufx390yYtLfXC1zbNCpFxUksDFYZazcIx+kaiPrWPNpJ+3zc7WnAZvoB7j5p4W/8oEvz3LfobQ834B/YDAKv9h3ro8wmvWXR/59VefUbexS5j10biKiLLME1RLqf8S/lRFh2zeS9J9Li5TCQZAipUqLI6Qg1R2xB4g= Received: from SA1P222CA0170.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c3::26) by MN0PR12MB6200.namprd12.prod.outlook.com (2603:10b6:208:3c3::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9499.7; Thu, 15 Jan 2026 06:09:22 +0000 Received: from SA2PEPF00003F63.namprd04.prod.outlook.com (2603:10b6:806:3c3:cafe::ff) by SA1P222CA0170.outlook.office365.com (2603:10b6:806:3c3::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.5 via Frontend Transport; Thu, 15 Jan 2026 06:09:20 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00003F63.mail.protection.outlook.com (10.167.248.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.1 via Frontend Transport; Thu, 15 Jan 2026 06:09:21 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 15 Jan 2026 00:09:16 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v6 08/13] iommu/amd: Introduce struct amd_iommu_viommu Date: Thu, 15 Jan 2026 06:08:09 +0000 Message-ID: <20260115060814.10692-9-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> References: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F63:EE_|MN0PR12MB6200:EE_ X-MS-Office365-Filtering-Correlation-Id: 9012e9ef-0988-4ad3-5cdf-08de53fca044 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|7416014|376014|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?mglREs4rmMZemiHfED3Er3Wg0pygQqhiOtgySg69Ps6NH++nnd+BjuHYmW95?= =?us-ascii?Q?Q49fctE6yPCmoYPVzQZvuShvxOO4T2LFDuWp2E3urZMggpi9PpAr9+WyeCU5?= =?us-ascii?Q?3dWR7+OIrqczYeLrlzVQ4pA59zcigBE+/M2cNJgz70lAfq5dVUmZgNWlwyIX?= =?us-ascii?Q?mdg64ihhNJn7ShA/EvLxqIrkqFoUcBamtHwFlkfr7FP/teIPqKL93rzQr3FT?= =?us-ascii?Q?5/3dUqaIBSBZHF/uCOA2Rjg5tgkeXGP8lhRkp4LfbONBaOpz9ZafcNiwvMWC?= =?us-ascii?Q?WRkOJueNNqm2UMDKP9/QGFki39GRj0/QGVuFJixzzsxQUVCehWYHs0UNINfA?= =?us-ascii?Q?ihkfAXjAUGMns+OriHk26TxUaT7ZfXx5JiVRftabhZpK+4Ph3FlWNuNu1v+5?= =?us-ascii?Q?NnBgue/QsFxfFaMHbhcRzuR6Mv8o/RpQnf0wbQODeqzfW0CDbppK6WYfciXf?= =?us-ascii?Q?w276jS9a+HxxohUCPovLMBU+dzhTeboYoXBI92umuErOG8DrHLtbKFu7qYIc?= =?us-ascii?Q?rp7vNRqqCP22+6U2DNuDiW9g3jOY6uH8DBLrXHlawqJ/7TLSfX+PL5i+BbC9?= =?us-ascii?Q?pqXFNTPL/wbBr+dT9RjeTzFXJH90QWRWFYmJ9ZSdN2NbMQTx4B3tx389LXcO?= =?us-ascii?Q?Cpmw8PcEWyH1nWFrl+ix6xqKRGqx3tgtbYdJg9GKf8lbOCPEwrgQmwGMp33Q?= =?us-ascii?Q?m5qfZ30dtfUqLOddRFPEiCxLO2rL3+Uo/CWJj5vnEPktnc6hmVG4SIqXNOPw?= =?us-ascii?Q?Ir+uj75mexBfM+DEtg+EEeNhyNBG7ORJbTcEdZbQQYSTckrjcB4wBv49yM7s?= =?us-ascii?Q?glQjtvXSJNNtzGfXAk1q/B7Wn8HzDpZwhacfaMIXyXrC6IBWsja+QxWD5qpc?= =?us-ascii?Q?2n9cVnsStJxafAH4fihrH5wVA1E9/DDE3WNozWpABOONOCadZFmmqfXrqBzv?= =?us-ascii?Q?dtO/gXfEyeAlVo8/65apHUrZ58EVY8/s9xOHVkcBLjBkPz/zJwoahhbIQ7UU?= =?us-ascii?Q?Hbssd/pLz9bJk7m5uVw7sMz8Dq15Kj0u+h4meu2EYt25V84Nb4sNhw1co6/N?= =?us-ascii?Q?ScOVBSq7OvAyQv53FzWFayrnJXL8rPqWEQzGTPiMbHvi44zTXuetF/jjMWJi?= =?us-ascii?Q?jVvbwJckbZuF+pa0cQaeUHOIxHh2tryjjH6r80WqmpdijaifXR3N2w2wgO36?= =?us-ascii?Q?6s9ckRcJWpUQ+5aiMSTmVfy+R2Ntg/SKlSwrGhSXU0hAekjOWf9/SUOl6qCs?= =?us-ascii?Q?ubOqGwnDYEGoaN9/t2eutedOIxFp579MM981IN9K8xr1QMIG0CPd3ecZ1yzW?= =?us-ascii?Q?5BunZ72fTx9qjdJe9vg0MNaANxuw9xEi2eMQGSezyvTW6FoDicdPFNWUgeAu?= =?us-ascii?Q?mJySW2mPDnIGMmp+7btxtsYuQ7+iXwNIuBJvXoUIV3PQrVlX0AxeshkaIFKU?= =?us-ascii?Q?QgkdFKeLsmibH977EfgQjlwaP2s4Cg7kmAKIyAYC21yTXcNNWAlmcWZiS0Xk?= =?us-ascii?Q?btaEcB5ohp3+GDYX8p2pcxT6l4qDd/IXOnW0NmkS8sUR52ZLPnaKBQRXUk1x?= =?us-ascii?Q?WmgqkQdyvI3Z9YS40kJSNveUcMH62VyN/Zub14EcKhZZ8AnqMmVTD2GcfSEG?= =?us-ascii?Q?z5pnFukbb/Dl/BZ9Kfx6TGNIQOCpDEtFg9/b5jWd1h5z02+1EPgOqjNvfoi+?= =?us-ascii?Q?K5EQyg=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700013)(7416014)(376014)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2026 06:09:21.8508 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9012e9ef-0988-4ad3-5cdf-08de53fca044 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F63.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6200 Content-Type: text/plain; charset="utf-8" Which stores reference to nested parent domain assigned during the call to struct iommu_ops.viommu_init(). Information in the nest parent is needed when setting up the nested translation. Note that the viommu initialization will be introduced in subsequent commit. Reviewed-by: Jason Gunthorpe Reviewed-by: Nicolin Chen Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu_types.h | 6 ++++++ drivers/iommu/amd/iommu.c | 2 ++ drivers/iommu/amd/iommufd.c | 16 ++++++++++++++++ drivers/iommu/amd/iommufd.h | 5 +++++ 4 files changed, 29 insertions(+) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_io= mmu_types.h index d8753841cd1f..d5b3393ab3a9 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include =20 @@ -495,6 +496,11 @@ struct pdom_iommu_info { u32 refcnt; /* Count of attached dev/pasid per domain/IOMMU */ }; =20 +struct amd_iommu_viommu { + struct iommufd_viommu core; + struct protection_domain *parent; /* nest parent domain for this viommu */ +}; + /* * This structure contains generic data for IOMMU protection domains * independent of their use. diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 9b2fd852eb88..ebc96f1f564f 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -3116,6 +3116,8 @@ const struct iommu_ops amd_iommu_ops =3D { .is_attach_deferred =3D amd_iommu_is_attach_deferred, .def_domain_type =3D amd_iommu_def_domain_type, .page_response =3D amd_iommu_page_response, + .get_viommu_size =3D amd_iommufd_get_viommu_size, + .viommu_init =3D amd_iommufd_viommu_init, }; =20 #ifdef CONFIG_IRQ_REMAP diff --git a/drivers/iommu/amd/iommufd.c b/drivers/iommu/amd/iommufd.c index 72eaaa923d04..eb6119bdcf12 100644 --- a/drivers/iommu/amd/iommufd.c +++ b/drivers/iommu/amd/iommufd.c @@ -29,3 +29,19 @@ void *amd_iommufd_hw_info(struct device *dev, u32 *lengt= h, u32 *type) =20 return hwinfo; } + +size_t amd_iommufd_get_viommu_size(struct device *dev, enum iommu_viommu_t= ype viommu_type) +{ + return VIOMMU_STRUCT_SIZE(struct amd_iommu_viommu, core); +} + +int amd_iommufd_viommu_init(struct iommufd_viommu *viommu, struct iommu_do= main *parent, + const struct iommu_user_data *user_data) +{ + struct protection_domain *pdom =3D to_pdomain(parent); + struct amd_iommu_viommu *aviommu =3D container_of(viommu, struct amd_iomm= u_viommu, core); + + aviommu->parent =3D pdom; + + return 0; +} diff --git a/drivers/iommu/amd/iommufd.h b/drivers/iommu/amd/iommufd.h index f880be80a30d..f05aad495b5b 100644 --- a/drivers/iommu/amd/iommufd.h +++ b/drivers/iommu/amd/iommufd.h @@ -8,8 +8,13 @@ =20 #if IS_ENABLED(CONFIG_AMD_IOMMU_IOMMUFD) void *amd_iommufd_hw_info(struct device *dev, u32 *length, u32 *type); +size_t amd_iommufd_get_viommu_size(struct device *dev, enum iommu_viommu_t= ype viommu_type); +int amd_iommufd_viommu_init(struct iommufd_viommu *viommu, struct iommu_do= main *parent, + const struct iommu_user_data *user_data); #else #define amd_iommufd_hw_info NULL +#define amd_iommufd_viommu_init NULL +#define amd_iommufd_get_viommu_size NULL #endif /* CONFIG_AMD_IOMMU_IOMMUFD */ =20 #endif /* AMD_IOMMUFD_H */ --=20 2.34.1 From nobody Sat Feb 7 06:40:11 2026 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011069.outbound.protection.outlook.com [52.101.52.69]) (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 A982D2DC328 for ; Thu, 15 Jan 2026 06:09:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457375; cv=fail; b=hrmAETLaOURiN4FtGAdlzcGwXpNsjaC8MlNW4ru7+Om/BuF58vjSyIwiEHoTCgcKvK6O6X7nIa3yRuUkF3flV3DRd5jywizmokRUSRwj1idvs/pPWhji+iG1ENz6Vim4cmuMEwNWKFIspWphUC1/P0blSuXaz7eBJ+K1bivJJw4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457375; c=relaxed/simple; bh=SYLAQWdn26808DNlOMA8PVxuZirkHIxrBJaDac0Tk1c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MLHen0wNdtd1VrhzplDru8QwSaU1FrFktvsgziuphfpruPqPxwBSCUCJ/ayuRYJR2kauhwhvDWh9YHlC/4nn2e+h04tzIf4k2htxIS4DfDmwo5zyByqrgdwkUPpis80Ldwlw2OvCxJOrqOQvbU1Ipc0WLuV8p3eLMoXhVnZ7GfU= 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=loX/9x1i; arc=fail smtp.client-ip=52.101.52.69 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="loX/9x1i" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NRAAmN/2Z/NfSwX++EC6KcBhLwRFNDtJYY5pbDRR8o1n+lQ1dGPOCr6kefOvnAFME/TLAFLr9FOmXTumv6S/UYFU4f6qBe/IBOHBgfGW7vG6k4Eb06pOrGc7NbHiaWFpkYCPYt5yZgq8yy2hwnjNv6AfLFLHpZMINff6ZWxdmLQAaj2efLlE7UxC8DFGVKEnDbChY0sHWIWQELENOzzkcJMUJHG9vwex+t6UlWd1Gv+B3amgL7hM3BNbm/+AchBFodKnHCV/Pg0uJUrNMr5wtzUL+bG4w6yO8lyT1o5vWEFO8WBit5PeUYiNweTwWdKP8rc//tRpk2CHKZItsdbL8w== 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=rnnoR8FHvmNEkdMi4SgwIU2H3CQmm3qwlcOdf3ja/iM=; b=D6Zla83ipJm0K9pyd1tRmTn5LmBqtJp8IjXrp4bWzTT2p0Pt0oqEw9P8CgujuW8jzp1tW1tHfk0qJEx3fdyBRaEKd89+hWeKDRzW4sPZxeGv4aL1Smcjyvpm4S8eMULKw97pHa35OS86b/Q8a++8OnRNRaS88Nx+HO9yVtGEa4Lk3uEKyBoGJaYpU9MkhOpUb7SHtr728ZYZVLMWL5NMngapbb6pApfLKVgcY+1RWzOssUzADfcLlzyrQXJ2j32jmCSShpy6vhHxcrzgeZwt7yj8aq78n+KTUQeU2JwiXZSaSauRvPCUyKswRGj9nh8SAPnGlDrWoO6VML8n6dYKkw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com 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=rnnoR8FHvmNEkdMi4SgwIU2H3CQmm3qwlcOdf3ja/iM=; b=loX/9x1iV3DpRIIB9hgQ09bzJUoifbJDhYvFJ5jYNy+uQQKSFoOfBN/yILLRHY8HZntfnDLYVefU3wxgZvCOUUvENeoxsb04dXIfuTRhSFgORhB2CEq8NugZG47PT83USnJwa+ep0Q7QMgrgR9VeXTRTjc+dwcfQuZu3dWU3meU= Received: from SN7PR04CA0231.namprd04.prod.outlook.com (2603:10b6:806:127::26) by LV8PR12MB9357.namprd12.prod.outlook.com (2603:10b6:408:1ff::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9499.7; Thu, 15 Jan 2026 06:09:27 +0000 Received: from SA2PEPF00003F64.namprd04.prod.outlook.com (2603:10b6:806:127:cafe::d0) by SN7PR04CA0231.outlook.office365.com (2603:10b6:806:127::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.5 via Frontend Transport; Thu, 15 Jan 2026 06:09:27 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00003F64.mail.protection.outlook.com (10.167.248.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.1 via Frontend Transport; Thu, 15 Jan 2026 06:09:27 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 15 Jan 2026 00:09:21 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v6 09/13] iommu/amd: Add support for nested domain allocation Date: Thu, 15 Jan 2026 06:08:10 +0000 Message-ID: <20260115060814.10692-10-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> References: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F64:EE_|LV8PR12MB9357:EE_ X-MS-Office365-Filtering-Correlation-Id: 9463a40a-7b44-487b-30b0-08de53fca3b5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|7416014|376014|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?zqgrJWs4VlrWhoSEllHAcdMuAI8QQgTFuCmKY/YTEZ1d1Q6AxW+S6rM5Lsz1?= =?us-ascii?Q?HjRUuhVJu32PwTP6uFIE5GwqEOueh0MFuN9K+pSdMgaCSX+h/EzZQy9i5Al/?= =?us-ascii?Q?hDPP3z9gM4zNsYhbhoSEaqX2W6+IyRWeTJxlvjcSJZjzgFAw8n7jIBlFFQVN?= =?us-ascii?Q?VC42s3PG4McLLpd/wAbWUcImrGyFlzGapp+D9bIosJKUHmnSQNOAMd9YjaTx?= =?us-ascii?Q?Cm2nGMJc96pIWwzX7biYiZbqAsuCnO1wQ5GdiPqlhRQhblNQPIBNyqWB2pIM?= =?us-ascii?Q?Os4tYC7x64iqo31Uo8V+zSRyXkNvmh7ZUUAAyI/DeDvK2ja214nBdjdTsiM9?= =?us-ascii?Q?i0LcM0XBlYV2b8TA1GPmhYACI3p9EcHRzF249M+Ouu+aVGTcpwBU2PZM6epw?= =?us-ascii?Q?ntg28gBtJPBdy1nkU3GIG42JGvf3Jckp/emQxpWxiq4B0iOKB1fgtDundUM7?= =?us-ascii?Q?CqkppVxm0PSxcO6zsuQMQTekSLm4FvJNUkzQkZ/1+x2A7Rq6tVm2Cpvgm3Nz?= =?us-ascii?Q?EaeqG5j6o/i+mG1oei6iWnRbOBkRr7wm0GVSMqAyG3AYU+pcWwFpYtwHP8uM?= =?us-ascii?Q?Z8yqC7HWZr25/NxIppQGi72coqCqB2BtYVTrAPjJOt8qdT8VdRf95Mkswfhb?= =?us-ascii?Q?O3IeUVkKbE7Xod8rLT7VWV2MHxqUczB0TXquC9Q8mW2n06GbDFBiylDvMe9S?= =?us-ascii?Q?n80BGMaC7lxD8T9kfwCzhwcjtcs3dK6ldQ3vYrKp6hOv/BdXMJprL/P+5/99?= =?us-ascii?Q?k3PFToyuRPH0UQiKn668n3e3usXMm9qg2FDEi4dlUT7U2Zn7Ol17/XpIHsKJ?= =?us-ascii?Q?ythyBXqP/by+Y+wlxXnAeNL1XD3/8bsqS0mk2MpOVO1AfHsuCJMLO00yLp3E?= =?us-ascii?Q?WwUogzZsF5kOHl0kf9je9cQoXpa/p7uJcbIyNp8KPt16y2YJJAaNlD1mZsAw?= =?us-ascii?Q?L9UabfVBx4JwhO9BwSPZjmzri/eajSpw49UCMMGndcLv9tXR6akIHMl/GwRT?= =?us-ascii?Q?alZMDtTYRT0AtrDwP4M8/s/+/IgoMsaJN+8fv6R+qrkHhn/Q5iFTh03EROsd?= =?us-ascii?Q?bLL6cy4ywVMoP6W7f71de/YFN1fNIdYflYw+hY53VEXFE6K64pfae31o5SJG?= =?us-ascii?Q?ssdZERW2mnB+eKk96ITszcAhKE2etZQQg4BDJpCP9HPrZABllH/SkF7nq1ev?= =?us-ascii?Q?Ubh/AxdjaPin9xRWZc0p8NUaZqIPRERh29rLC8kCq5bu7KlKrbkmW2qajJg6?= =?us-ascii?Q?KXWXZ+n53fFAmZj0K81ezi+NXAZTkJ3sa6ZoXBHayhetniljLbwdT2s7Fpqk?= =?us-ascii?Q?HvJJCFk5Zyi90cAFzbwvzP8fOoXZeVQRP3w1k3JJGdtDDrfHP6bot6MtwvB3?= =?us-ascii?Q?1KPhkiprmOA130pEo9hC9DOXzQBRl1rEWcdL77Hps8b458u2oR1VOIaw/bky?= =?us-ascii?Q?MxDKLLwetBYSIfsVTVQ/Qwt+ab8kSc5UTj0fED+H0hFaf/e0K1seeTGa5/+i?= =?us-ascii?Q?TheDB62FqMPpRnr5brKZeY7rEZuQ+T47CsjyMUsT5GqjKkhKC2z3wNDjouGy?= =?us-ascii?Q?VWCtgs7ad+GDNRuKxMRMSuwDtgYVGk7tgV5EppTyzyT1LLbMBBm6FZnQlDv5?= =?us-ascii?Q?MR5/cxafaeqk1kMPbceTwXHmE+0BPst2eoPczxugrRMdqQbJXz1jh1w4JsPN?= =?us-ascii?Q?zWCL6A=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(36860700013)(7416014)(376014)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2026 06:09:27.6258 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9463a40a-7b44-487b-30b0-08de53fca3b5 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F64.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9357 Content-Type: text/plain; charset="utf-8" The nested domain is allocated with IOMMU_DOMAIN_NESTED type to store stage-1 translation (i.e. GVA->GPA). This includes the GCR3 root pointer table along with guest page tables. The struct iommu_hwpt_amd_guest contains this information, and is passed from user-space as a parameter of the struct iommu_ops.domain_alloc_nested(). Reviewed-by: Nicolin Chen Reviewed-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/Makefile | 2 +- drivers/iommu/amd/amd_iommu.h | 4 + drivers/iommu/amd/amd_iommu_types.h | 14 ++++ drivers/iommu/amd/nested.c | 110 ++++++++++++++++++++++++++++ 4 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 drivers/iommu/amd/nested.c diff --git a/drivers/iommu/amd/Makefile b/drivers/iommu/amd/Makefile index 41f053b49dce..94b8ef2acb18 100644 --- a/drivers/iommu/amd/Makefile +++ b/drivers/iommu/amd/Makefile @@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y +=3D iommu.o init.o quirks.o ppr.o pasid.o -obj-$(CONFIG_AMD_IOMMU_IOMMUFD) +=3D iommufd.o +obj-$(CONFIG_AMD_IOMMU_IOMMUFD) +=3D iommufd.o nested.o obj-$(CONFIG_AMD_IOMMU_DEBUGFS) +=3D debugfs.o diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index d97b9b6d76d3..aa29afe96e90 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -202,4 +202,8 @@ amd_iommu_make_clear_dte(struct iommu_dev_data *dev_dat= a, struct dev_table_entry new->data128[1] =3D 0; } =20 +/* NESTED */ +struct iommu_domain * +amd_iommu_alloc_domain_nested(struct iommufd_viommu *viommu, u32 flags, + const struct iommu_user_data *user_data); #endif /* AMD_IOMMU_H */ diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_io= mmu_types.h index d5b3393ab3a9..487ee6123de5 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -21,6 +21,8 @@ #include #include =20 +#include + /* * Maximum number of IOMMUs supported */ @@ -353,6 +355,8 @@ #define DTE_FLAG_V BIT_ULL(0) #define DTE_FLAG_TV BIT_ULL(1) #define DTE_FLAG_HAD (3ULL << 7) +#define DTE_MODE_MASK GENMASK_ULL(11, 9) +#define DTE_HOST_TRP GENMASK_ULL(51, 12) #define DTE_FLAG_GIOV BIT_ULL(54) #define DTE_FLAG_GV BIT_ULL(55) #define DTE_GLX GENMASK_ULL(57, 56) @@ -501,6 +505,16 @@ struct amd_iommu_viommu { struct protection_domain *parent; /* nest parent domain for this viommu */ }; =20 +/* + * Nested domain is specifically used for nested translation + */ +struct nested_domain { + struct iommu_domain domain; /* generic domain handle used by iommu core c= ode */ + u16 gdom_id; /* domain ID from gDTE */ + struct iommu_hwpt_amd_guest gdte; /* Guest vIOMMU DTE */ + struct amd_iommu_viommu *viommu; /* AMD hw-viommu this nested domain bel= ong to */ +}; + /* * This structure contains generic data for IOMMU protection domains * independent of their use. diff --git a/drivers/iommu/amd/nested.c b/drivers/iommu/amd/nested.c new file mode 100644 index 000000000000..a8c0bb4dd733 --- /dev/null +++ b/drivers/iommu/amd/nested.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ + +#define dev_fmt(fmt) "AMD-Vi: " fmt + +#include +#include + +#include "amd_iommu.h" + +static const struct iommu_domain_ops nested_domain_ops; + +static inline struct nested_domain *to_ndomain(struct iommu_domain *dom) +{ + return container_of(dom, struct nested_domain, domain); +} + +/* + * Validate guest DTE to make sure that configuration for host (v1) + * and guest (v2) page tables are valid when allocating nested domain. + */ +static int validate_gdte_nested(struct iommu_hwpt_amd_guest *gdte) +{ + u32 gpt_level =3D FIELD_GET(DTE_GPT_LEVEL_MASK, gdte->dte[2]); + + /* Must be zero: Mode, Host-TPR */ + if (FIELD_GET(DTE_MODE_MASK, gdte->dte[0]) !=3D 0 || + FIELD_GET(DTE_HOST_TRP, gdte->dte[0]) !=3D 0) + return -EINVAL; + + /* GCR3 TRP must be non-zero if V, GV is set */ + if (FIELD_GET(DTE_FLAG_V, gdte->dte[0]) =3D=3D 1 && + FIELD_GET(DTE_FLAG_GV, gdte->dte[0]) =3D=3D 1 && + FIELD_GET(DTE_GCR3_14_12, gdte->dte[0]) =3D=3D 0 && + FIELD_GET(DTE_GCR3_30_15, gdte->dte[1]) =3D=3D 0 && + FIELD_GET(DTE_GCR3_51_31, gdte->dte[1]) =3D=3D 0) + return -EINVAL; + + /* Valid Guest Paging Mode values are 0 and 1 */ + if (gpt_level !=3D GUEST_PGTABLE_4_LEVEL && + gpt_level !=3D GUEST_PGTABLE_5_LEVEL) + return -EINVAL; + + /* GLX =3D 3 is reserved */ + if (FIELD_GET(DTE_GLX, gdte->dte[0]) =3D=3D 3) + return -EINVAL; + + /* + * We need to check host capability before setting + * the Guest Paging Mode + */ + if (gpt_level =3D=3D GUEST_PGTABLE_5_LEVEL && + amd_iommu_gpt_level < PAGE_MODE_5_LEVEL) + return -EOPNOTSUPP; + + return 0; +} + +/* + * This function is assigned to struct iommufd_viommu_ops.alloc_domain_nes= ted() + * during the call to struct iommu_ops.viommu_init(). + */ +struct iommu_domain * +amd_iommu_alloc_domain_nested(struct iommufd_viommu *viommu, u32 flags, + const struct iommu_user_data *user_data) +{ + int ret; + struct nested_domain *ndom; + struct amd_iommu_viommu *aviommu =3D container_of(viommu, struct amd_iomm= u_viommu, core); + + if (user_data->type !=3D IOMMU_HWPT_DATA_AMD_GUEST) + return ERR_PTR(-EOPNOTSUPP); + + ndom =3D kzalloc(sizeof(*ndom), GFP_KERNEL); + if (!ndom) + return ERR_PTR(-ENOMEM); + + ret =3D iommu_copy_struct_from_user(&ndom->gdte, user_data, + IOMMU_HWPT_DATA_AMD_GUEST, + dte); + if (ret) + goto out_err; + + ret =3D validate_gdte_nested(&ndom->gdte); + if (ret) + goto out_err; + + ndom->gdom_id =3D FIELD_GET(DTE_DOMID_MASK, ndom->gdte.dte[1]); + ndom->domain.ops =3D &nested_domain_ops; + ndom->domain.type =3D IOMMU_DOMAIN_NESTED; + ndom->viommu =3D aviommu; + + return &ndom->domain; +out_err: + kfree(ndom); + return ERR_PTR(ret); +} + +static void nested_domain_free(struct iommu_domain *dom) +{ + struct nested_domain *ndom =3D to_ndomain(dom); + + kfree(ndom); +} + +static const struct iommu_domain_ops nested_domain_ops =3D { + .free =3D nested_domain_free, +}; --=20 2.34.1 From nobody Sat Feb 7 06:40:11 2026 Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010005.outbound.protection.outlook.com [52.101.61.5]) (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 F11152DB7B5 for ; Thu, 15 Jan 2026 06:09:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.61.5 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457381; cv=fail; b=GNqyek9BMropm/jhbtm0opnvDfJ9RrFNYiMQwaHERh6wcKcxHljRODH7csRLuYDfKpWiLf3nqMY3MYjvBB1Cb3e2abpT5NOZrfnVXLD2XGe0yPIAbuaeC9GYiqhh4i5zhVladt1oRspaZuoTSXYcOtf2NG3jOmbBb2JCDTx0RpM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457381; c=relaxed/simple; bh=TSCpMNvWM+S5bXNtHobB0vGpG2c+90HJVIsNziEVnxk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=R8f2KwBxB64uM1N+WO8PZxGmyzlCRjuFCnsmSnMHusrhc6TSHJDdOEWs1FIbJE0/7trVnOsVamwJfZAEaDnVED4z741qUW8/WTyNsoEE1FyxGpa5SBh35bu06jDE5PJMusBglHPUU3qXOfI8x7Gi5JlaDO0DtGWki5VhzvtfhfY= 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=Zyo1CqcQ; arc=fail smtp.client-ip=52.101.61.5 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="Zyo1CqcQ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=M3EL6p7IkLl+L75XwcE2NNZ6VSuxXZafq7flNjT7iQGLGsAhwt7W7d77yoiLQj4gadF8aOWVTBtw6S9P36QsPFQLeOQTvfgI0UC2rkR+S6TNiJzHY5IxhsPucUYvw+gvZZY3UFNAOGrm1ZOR4IYJGLovVpoDxa5+KXwlUUAg7C3y3SNT3LENPI2nOmSiyIuLBs6GCnt5p/KUZUZL+N86ZxrEBWGaWP6wJseRV+Ly16DBg/S9x5gp3PJh6gs875G2l20e++TdfN7NVUjy34amwamPW3AE883ShuDUYmmd5HTs27ZbL90J5zlzTbvCzv8foiHYa3NOrBDTl7WEeijq1g== 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=sDkxCW1V4hB9SWI62MwGMWB8/A1widW1fbznhUdklM4=; b=uoqkjXvzVjmyqPp4rNzMQ9gKI+7xH+nqkkMG9Qz3r6QQNt7pWv2iycYogWgdznzLXRdCLvoNCZNsENwPpjb9Go3HMo4tLWu6TwcRcIldPot2wEL6QY7u8+quzYJ68M7J0yFVLvfGyl3xftAeB6qyB1ZujRmbOEBBopO9m80TeZS7Z/5bjavOORi1wgPNZoSzMNMm5seFiBd4YFyUJrv6NHxyvA0nCAg/DjNVMMuLZ3HYbSknsH0RysPV069LLzFnHxEyR01Z1W0nbQzp5Z7EqdLIkYEgcKYXow5e4QPrEWwYVipYu7a1BUiDQ2uxZ6j6BnSMtqf5cWJ6g6TJCupJKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com 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=sDkxCW1V4hB9SWI62MwGMWB8/A1widW1fbznhUdklM4=; b=Zyo1CqcQKk0c6GGyS9wOhHRs8jtWXQzYUq3AFxIrsRKpBzzO3xmWn0EdwgccSjpJq/iLH0Mqz+tHnVxL/Aijuu8ugeqRL0eIdN3plGOtVJOD7ect2cKKI5u/yHn1fNlOHjtYUcAsGt0ICbe0uSbaGKhDDrsIMJs68ijxyTabrQU= Received: from SN7PR04CA0217.namprd04.prod.outlook.com (2603:10b6:806:127::12) by MW3PR12MB4492.namprd12.prod.outlook.com (2603:10b6:303:57::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9499.5; Thu, 15 Jan 2026 06:09:34 +0000 Received: from SA2PEPF00003F64.namprd04.prod.outlook.com (2603:10b6:806:127:cafe::5) by SN7PR04CA0217.outlook.office365.com (2603:10b6:806:127::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.5 via Frontend Transport; Thu, 15 Jan 2026 06:09:31 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00003F64.mail.protection.outlook.com (10.167.248.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.1 via Frontend Transport; Thu, 15 Jan 2026 06:09:33 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 15 Jan 2026 00:09:27 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v6 10/13] iommu/amd: Introduce gDomID-to-hDomID Mapping and handle parent domain invalidation Date: Thu, 15 Jan 2026 06:08:11 +0000 Message-ID: <20260115060814.10692-11-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> References: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F64:EE_|MW3PR12MB4492:EE_ X-MS-Office365-Filtering-Correlation-Id: 4b06b0e0-0650-4c4b-453c-08de53fca76b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|376014|7416014|1800799024|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Z7YwVNLLlQ2dr+ObnNSNOXmYdSou+GBguzZvH7fFsazfRGn8PcDPnKklAHe3?= =?us-ascii?Q?Hb2luRi4bnvcIBb1Qk/M0W0vnpzoketJXmG4n6hiUiEc8NbTygG6uNtH9xbH?= =?us-ascii?Q?JXCd8CkWOkS1Oc3HMjqqALy2yEdOM0C8bbxQoBiZ6TjGS7Tq3gPWcapkqSS7?= =?us-ascii?Q?zOml72l+E7sHg+vjdyAS4WDj1ngnvtNtY5H+MXuf62iQCOJcSRZeP1weH1FZ?= =?us-ascii?Q?8r4qfjmlSBuGHIEGFD9j1P+/Yk9PEarXc9dKUdGfOpO3M20IBHHMyr4nxa13?= =?us-ascii?Q?4T4iEypVzszcdiGR6iA2JxH5ovkeoD8JEFFNLZmmzhAYOErcGQcoNnpi3OjY?= =?us-ascii?Q?kF2GdRdVfAK6mDErQUpJLVJQ0elppB/xdF7qqHfazglQPND0ILfBBukj1LVU?= =?us-ascii?Q?Pg+cuwp1B/YeXB+kZf4dKbnjkpbCvDJ9Fk4+WyyuyeXWkAmngiFaXDberuZn?= =?us-ascii?Q?g4lAVjl5q73+DM2Ei6Ztv1ge4pPWltXhEDFlqq3jBj84+kwpqHMe5bVhcUPc?= =?us-ascii?Q?FuT1my1UyOflyLEteuR2J7jXDBCohNH4fe7gGeLBwS0FdN1xeGhv0wzZ2BTe?= =?us-ascii?Q?ihstLT2WyVZqzDaOcYzkonVubExwhGnB/Z/LuSfCilmNwp252V/3CGtalR45?= =?us-ascii?Q?McvmcKkCA1H/FfX24C0t17v6f6WbJuqpZxAnQixS6JpbEDZPgdV9DddOUuNN?= =?us-ascii?Q?A9OPbqCL+9KiWJCsfoM+P5ulCi+Vyl4ZHC1KLgLb7hX40yAmvtDTpj6McUfD?= =?us-ascii?Q?cM9P0ZXMlS09O/4kJU591R/v9nbf9EbEPSW5AYjnyhn8HAD0uIh0JuVSeIo7?= =?us-ascii?Q?AVeO7NfUKNP6Q8+Yp+wvYEKI1RKZB3BUDNRLgXfDVS5WjTdl4XRf1L7AvOJV?= =?us-ascii?Q?PE4+WCBIi/0uq+p32ZxSamSUobiRF5Fcu5pY9KuTI4I8k+xxm1rMYbJYK991?= =?us-ascii?Q?/EfJcCDoibDLr24BFrqCtAm7ny0aV7Poh8Ac2gkiJxCD6QE8UHzertLKSkQZ?= =?us-ascii?Q?WRyZHkWy4yWX+PXBFnAWfvj1w87uyfaa/jG+kWBbj5fbM5+Bxll4IHdj6QhI?= =?us-ascii?Q?RqNQv9b8xdB+5SnLoLT0SYZYoPQ74AeljXgWRWVQ+Ym5JeIpiE7KSqepVIga?= =?us-ascii?Q?bik+i2GWH2ceZiAeIk9WmnL4VGtUx+1ZQMxCyMoyTrGIcok91ojQOYs9w6St?= =?us-ascii?Q?1wEciG1zUkSIKTfxFl2rZIMkFRgJXCs847yBu5WxO9CwVj8eiRgJKcWDWfMU?= =?us-ascii?Q?PQGqBDu6CizmR048YKkkeH8ABcDKxjwsQ9k+GHAJMkAfv4sKEPzaXzFqeZsv?= =?us-ascii?Q?B0jlnOenN5WpzkgCkLZNG1zANWKzwb7d0tlkr566Csq9EJzkARFmmL76FuXh?= =?us-ascii?Q?88QiZLXmm/7YbkuUbcDIWRlTtX0Re0s2Gcr8JP6atiT89p8l/lW7nD3pyZmU?= =?us-ascii?Q?F0YJ5KgKvQkbDCU89IFGVE5i+96+QWukxvOCVvgO0iuNi9JfaWH8rXnlXlKa?= =?us-ascii?Q?db2DBZ35GDo1p7y70uov4qNiCFkOSmsJmaxwl4ms0OWozj49+c8yJpYSg3Gv?= =?us-ascii?Q?f7EQD+EKqG1LvREpEUKhhBprMb3pNUm4gpH0cDWhwTu0qpPV+KSJcr8ynLEY?= =?us-ascii?Q?32fmuiMKk5sILYp1x1BBRl62nzW320HTkC4r2+SZEiS8q+a/yjLAZdgc+PUN?= =?us-ascii?Q?8hB95Q=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(376014)(7416014)(1800799024)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2026 06:09:33.8178 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4b06b0e0-0650-4c4b-453c-08de53fca76b 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F64.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4492 Content-Type: text/plain; charset="utf-8" Each nested domain is assigned guest domain ID (gDomID), which guest OS programs into guest Device Table Entry (gDTE). For each gDomID, the driver assigns a corresponding host domain ID (hDomID), which will be programmed into the host Device Table Entry (hDTE). The hDomID is allocated during amd_iommu_alloc_domain_nested(), and free during nested_domain_free(). The gDomID-to-hDomID mapping info (struct guest_domain_mapping_info) is stored in a per-viommu xarray (struct amd_iommu_viommu.gdomid_array), which is indexed by gDomID. Note also that parent domain can be shared among struct iommufd_viommu. Therefore, when hypervisor invalidates the nest parent domain, the AMD IOMMU command INVALIDATE_IOMMU_PAGES must be issued for each hDomID in the gdomid_array. This is handled by the iommu_flush_pages_v1_hdom_ids(), where it iterates through struct protection_domain.viommu_list. Suggested-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu_types.h | 23 ++++++ drivers/iommu/amd/iommu.c | 38 ++++++++++ drivers/iommu/amd/iommufd.c | 31 ++++++++ drivers/iommu/amd/nested.c | 111 ++++++++++++++++++++++++++++ 4 files changed, 203 insertions(+) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_io= mmu_types.h index 487ee6123de5..4a98ac7dca0f 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -503,6 +503,22 @@ struct pdom_iommu_info { struct amd_iommu_viommu { struct iommufd_viommu core; struct protection_domain *parent; /* nest parent domain for this viommu */ + struct list_head pdom_list; /* For protection_domain->viommu_list */ + + /* + * Per-vIOMMU guest domain ID to host domain ID mapping. + * Indexed by guest domain ID. + */ + struct xarray gdomid_array; +}; + +/* + * Contains guest domain ID mapping info, + * which is stored in the struct xarray gdomid_array. + */ +struct guest_domain_mapping_info { + refcount_t users; + u32 hdom_id; /* Host domain ID */ }; =20 /* @@ -511,6 +527,7 @@ struct amd_iommu_viommu { struct nested_domain { struct iommu_domain domain; /* generic domain handle used by iommu core c= ode */ u16 gdom_id; /* domain ID from gDTE */ + struct guest_domain_mapping_info *gdom_info; struct iommu_hwpt_amd_guest gdte; /* Guest vIOMMU DTE */ struct amd_iommu_viommu *viommu; /* AMD hw-viommu this nested domain bel= ong to */ }; @@ -535,6 +552,12 @@ struct protection_domain { =20 struct mmu_notifier mn; /* mmu notifier for the SVA domain */ struct list_head dev_data_list; /* List of pdom_dev_data */ + + /* + * Store reference to list of vIOMMUs, which use this protection domain. + * This will be used to look up host domain ID when flushing this domain. + */ + struct list_head viommu_list; }; PT_IOMMU_CHECK_DOMAIN(struct protection_domain, iommu, domain); PT_IOMMU_CHECK_DOMAIN(struct protection_domain, amdv1.iommu, domain); diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index ebc96f1f564f..e33076b99aac 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1539,6 +1539,32 @@ static void amd_iommu_flush_tlb_domid(struct amd_iom= mu *iommu, u32 dom_id) iommu_completion_wait(iommu); } =20 +static int iommu_flush_pages_v1_hdom_ids(struct protection_domain *pdom, u= 64 address, size_t size) +{ + int ret =3D 0; + struct amd_iommu_viommu *aviommu; + + list_for_each_entry(aviommu, &pdom->viommu_list, pdom_list) { + unsigned long i; + struct guest_domain_mapping_info *gdom_info; + struct amd_iommu *iommu =3D container_of(aviommu->core.iommu_dev, + struct amd_iommu, iommu); + + xa_lock(&aviommu->gdomid_array); + xa_for_each(&aviommu->gdomid_array, i, gdom_info) { + struct iommu_cmd cmd; + + pr_debug("%s: iommu=3D%#x, hdom_id=3D%#x\n", __func__, + iommu->devid, gdom_info->hdom_id); + build_inv_iommu_pages(&cmd, address, size, gdom_info->hdom_id, + IOMMU_NO_PASID, false); + ret |=3D iommu_queue_command(iommu, &cmd); + } + xa_unlock(&aviommu->gdomid_array); + } + return ret; +} + static void amd_iommu_flush_all(struct amd_iommu *iommu) { struct iommu_cmd cmd; @@ -1687,6 +1713,17 @@ static int domain_flush_pages_v1(struct protection_d= omain *pdom, ret |=3D iommu_queue_command(pdom_iommu_info->iommu, &cmd); } =20 + /* + * A domain w/ v1 table can be a nest parent, which can have + * multiple nested domains. Each nested domain has 1:1 mapping + * between gDomID and hDomID. Therefore, flush every hDomID + * associated to this nest parent domain. + * + * See drivers/iommu/amd/nested.c: amd_iommu_alloc_domain_nested() + */ + if (!list_empty(&pdom->viommu_list)) + ret |=3D iommu_flush_pages_v1_hdom_ids(pdom, address, size); + return ret; } =20 @@ -2504,6 +2541,7 @@ static void protection_domain_init(struct protection_= domain *domain) spin_lock_init(&domain->lock); INIT_LIST_HEAD(&domain->dev_list); INIT_LIST_HEAD(&domain->dev_data_list); + INIT_LIST_HEAD(&domain->viommu_list); xa_init(&domain->iommu_array); } =20 diff --git a/drivers/iommu/amd/iommufd.c b/drivers/iommu/amd/iommufd.c index eb6119bdcf12..2e50633d9c72 100644 --- a/drivers/iommu/amd/iommufd.c +++ b/drivers/iommu/amd/iommufd.c @@ -9,6 +9,8 @@ #include "amd_iommu.h" #include "amd_iommu_types.h" =20 +static const struct iommufd_viommu_ops amd_viommu_ops; + void *amd_iommufd_hw_info(struct device *dev, u32 *length, u32 *type) { struct iommu_hw_info_amd *hwinfo; @@ -38,10 +40,39 @@ size_t amd_iommufd_get_viommu_size(struct device *dev, = enum iommu_viommu_type vi int amd_iommufd_viommu_init(struct iommufd_viommu *viommu, struct iommu_do= main *parent, const struct iommu_user_data *user_data) { + unsigned long flags; struct protection_domain *pdom =3D to_pdomain(parent); struct amd_iommu_viommu *aviommu =3D container_of(viommu, struct amd_iomm= u_viommu, core); =20 + xa_init_flags(&aviommu->gdomid_array, XA_FLAGS_ALLOC1); aviommu->parent =3D pdom; =20 + viommu->ops =3D &amd_viommu_ops; + + spin_lock_irqsave(&pdom->lock, flags); + list_add(&aviommu->pdom_list, &pdom->viommu_list); + spin_unlock_irqrestore(&pdom->lock, flags); + return 0; } + +static void amd_iommufd_viommu_destroy(struct iommufd_viommu *viommu) +{ + unsigned long flags; + struct amd_iommu *iommu =3D container_of(viommu->iommu_dev, struct amd_io= mmu, iommu); + struct amd_iommu_viommu *aviommu =3D container_of(viommu, struct amd_iomm= u_viommu, core); + struct protection_domain *pdom =3D aviommu->parent; + + spin_lock_irqsave(&pdom->lock, flags); + list_del(&aviommu->pdom_list); + spin_unlock_irqrestore(&pdom->lock, flags); + xa_destroy(&aviommu->gdomid_array); +} + +/* + * See include/linux/iommufd.h + * struct iommufd_viommu_ops - vIOMMU specific operations + */ +static const struct iommufd_viommu_ops amd_viommu_ops =3D { + .destroy =3D amd_iommufd_viommu_destroy, +}; diff --git a/drivers/iommu/amd/nested.c b/drivers/iommu/amd/nested.c index a8c0bb4dd733..8154a773eed8 100644 --- a/drivers/iommu/amd/nested.c +++ b/drivers/iommu/amd/nested.c @@ -6,6 +6,7 @@ #define dev_fmt(fmt) "AMD-Vi: " fmt =20 #include +#include #include =20 #include "amd_iommu.h" @@ -58,6 +59,33 @@ static int validate_gdte_nested(struct iommu_hwpt_amd_gu= est *gdte) return 0; } =20 +static void *gdom_info_load_or_alloc_locked(struct xarray *xa, unsigned lo= ng index) +{ + struct guest_domain_mapping_info *elm, *res; + + elm =3D xa_load(xa, index); + if (elm) + return elm; + + xa_unlock(xa); + elm =3D kzalloc(sizeof(struct guest_domain_mapping_info), GFP_KERNEL); + xa_lock(xa); + if (!elm) + return ERR_PTR(-ENOMEM); + + res =3D __xa_cmpxchg(xa, index, NULL, elm, GFP_KERNEL); + if (xa_is_err(res)) + res =3D ERR_PTR(xa_err(res)); + + if (res) { + kfree(elm); + return res; + } + + refcount_set(&elm->users, 0); + return elm; +} + /* * This function is assigned to struct iommufd_viommu_ops.alloc_domain_nes= ted() * during the call to struct iommu_ops.viommu_init(). @@ -68,6 +96,7 @@ amd_iommu_alloc_domain_nested(struct iommufd_viommu *viom= mu, u32 flags, { int ret; struct nested_domain *ndom; + struct guest_domain_mapping_info *gdom_info; struct amd_iommu_viommu *aviommu =3D container_of(viommu, struct amd_iomm= u_viommu, core); =20 if (user_data->type !=3D IOMMU_HWPT_DATA_AMD_GUEST) @@ -92,7 +121,63 @@ amd_iommu_alloc_domain_nested(struct iommufd_viommu *vi= ommu, u32 flags, ndom->domain.type =3D IOMMU_DOMAIN_NESTED; ndom->viommu =3D aviommu; =20 + /* + * Normally, when a guest has multiple pass-through devices, + * the IOMMU driver setup DTEs with the same stage-2 table and + * use the same host domain ID (hDomId). In case of nested translation, + * if the guest setup different stage-1 tables with same PASID, + * IOMMU would use the same TLB tag. This will results in TLB + * aliasing issue. + * + * The guest is assigning gDomIDs based on its own algorithm for managing + * cache tags of (DomID, PASID). Within a single viommu, the nest parent = domain + * (w/ S2 table) is used by all DTEs. But we need to consistently map the= gDomID + * to a single hDomID. This is done using an xarray in the vIOMMU to + * keep track of the gDomID mapping. When the S2 is changed, the INVALIDA= TE_IOMMU_PAGES + * command must be issued for each hDomID in the xarray. + */ + xa_lock(&aviommu->gdomid_array); + + gdom_info =3D gdom_info_load_or_alloc_locked(&aviommu->gdomid_array, ndom= ->gdom_id); + if (IS_ERR(gdom_info)) { + xa_unlock(&aviommu->gdomid_array); + ret =3D PTR_ERR(gdom_info); + goto out_err; + } + + /* Check if gDomID exist */ + if (refcount_inc_not_zero(&gdom_info->users)) { + ndom->gdom_info =3D gdom_info; + xa_unlock(&aviommu->gdomid_array); + + pr_debug("%s: Found gdom_id=3D%#x, hdom_id=3D%#x\n", + __func__, ndom->gdom_id, gdom_info->hdom_id); + + return &ndom->domain; + } + + /* The gDomID does not exist. We allocate new hdom_id */ + gdom_info->hdom_id =3D amd_iommu_pdom_id_alloc(); + if (gdom_info->hdom_id <=3D 0) { + __xa_cmpxchg(&aviommu->gdomid_array, + ndom->gdom_id, gdom_info, NULL, GFP_ATOMIC); + xa_unlock(&aviommu->gdomid_array); + ret =3D -ENOSPC; + goto out_err_gdom_info; + } + + ndom->gdom_info =3D gdom_info; + refcount_set(&gdom_info->users, 1); + + xa_unlock(&aviommu->gdomid_array); + + pr_debug("%s: Allocate gdom_id=3D%#x, hdom_id=3D%#x\n", + __func__, ndom->gdom_id, gdom_info->hdom_id); + return &ndom->domain; + +out_err_gdom_info: + kfree(gdom_info); out_err: kfree(ndom); return ERR_PTR(ret); @@ -100,8 +185,34 @@ amd_iommu_alloc_domain_nested(struct iommufd_viommu *v= iommu, u32 flags, =20 static void nested_domain_free(struct iommu_domain *dom) { + struct guest_domain_mapping_info *curr; struct nested_domain *ndom =3D to_ndomain(dom); + struct amd_iommu_viommu *aviommu =3D ndom->viommu; + + xa_lock(&aviommu->gdomid_array); + + if (!refcount_dec_and_test(&ndom->gdom_info->users)) { + xa_unlock(&aviommu->gdomid_array); + return; + } + + /* + * The refcount for the gdom_id to hdom_id mapping is zero. + * It is now safe to remove the mapping. + */ + curr =3D __xa_cmpxchg(&aviommu->gdomid_array, ndom->gdom_id, + ndom->gdom_info, NULL, GFP_ATOMIC); + + xa_unlock(&aviommu->gdomid_array); + if (WARN_ON(!curr || xa_err(curr))) + return; + + /* success */ + pr_debug("%s: Free gdom_id=3D%#x, hdom_id=3D%#x\n", + __func__, ndom->gdom_id, curr->hdom_id); =20 + amd_iommu_pdom_id_free(ndom->gdom_info->hdom_id); + kfree(curr); kfree(ndom); } =20 --=20 2.34.1 From nobody Sat Feb 7 06:40:11 2026 Received: from DM5PR21CU001.outbound.protection.outlook.com (mail-centralusazon11011020.outbound.protection.outlook.com [52.101.62.20]) (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 3B70C18C332 for ; Thu, 15 Jan 2026 06:09:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.62.20 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457384; cv=fail; b=cISCa0PXzeyWnUBxr0hzoaVXqO4tzQP1sR5qrb7cAabpSMTrmyXJUsmKN+udEJN8znvxHxMFC+GggDiOHXWak4LQv7Wh9oKqVn+hdCTEftj0vHTZmlqUEPDJ8/K0DAl7nzTlqQGUP0bkclZm5Ut1xbhEfOtd1/y3GkLMShiG+h0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457384; c=relaxed/simple; bh=A5QsHig0m+Ij3JP9fDMjVBfWYQneRshHY0MLRjkF7o8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fTDr+AnaLXt8G3xm/Z0ORmLC33t5amXXm70GFGrFsZ3X4Ez4i9QfgAjmQFIykExKk895vmy2jNFVU950MqykQevJESiSDPYDpQ5PF39nJIaK7AM61CLdGZedhG4i8yV64lpHIxoEPNBoKSVr5BpUHy5U/KuRHPlwgbBoT76F79U= 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=XUwyRDZg; arc=fail smtp.client-ip=52.101.62.20 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="XUwyRDZg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=A0abvHNwPHcleM/rLTKdM1lS/nxsH8LZ3nJX4ZD3wi258jWst4Z/0eLR66NHVhlafdlwvgc0EgoX649uPknKnTLX3DdxihUbaCQYu87tJUR2WJL2qs1GwqGXmJRXobB+L//FmXHFwf+c7YbN4172zv3rpM6bb2GxQwQ64CJREONsmUWf310IfoRt1V0843HMjy/KGkULSfHwWz5KnLCNtD58DdsxEnnvGwLxEaFc2r6zhresqx+Yt+8ykikbMGimZ9WQQGkUVHZlyTfCehdvRQl1ON4v+Jq8G23LDkz0d7NPGeSJHc7XVKYwe/eJmsLIRRv2WJneNB+tN1lJopnuDA== 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=LrNaJhvDsF0g5+fYn65PRYyGcaBwi8+Dw32r7gVt8gc=; b=aDewfxak3D5NmFccXlNnCqQqxkaZ8xc8Nmjb42SQH8CsS7YKsAHCMP15OdPkkqzAivCWychjp51Juyxbw2Ue1+5BNuECsk1K/aZEYcOmkKsDndV1/wHtVN+Mf8iCZb2bkM1oevhQMtghLOyMs/Jmtq9UN0foGQpviM/5NnnYVlRUF2d/Zv9ccIR9ypd4a1CYA4JQLTbkrBxVxnxvEuWCI206YGQn4pDkF/hD7GijoEWVoSb+aLVqTX8Z57s9Uz1h//MJ+6x19Hs2BKkGJQKcn+hMKEU04KW2cQdUKHx9mYgqBbSWjqjkT7RGBY87MvPjpkMcgpkyJmlpP3a+XjinHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com 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=LrNaJhvDsF0g5+fYn65PRYyGcaBwi8+Dw32r7gVt8gc=; b=XUwyRDZgo0biLbuucRti4Bhmt95Bz7KrPrPhlKDWvtHH86Z346YiY9946AoaUAu/zNlhvWA1goykaInh48JfXR0xNErZkB+aDtzOvqySsCPlH9kS6bwSQcDAmhBlsx1goX0n34/XfrIcy6PM1TDtuZtiZyJE2QIx5xllvaxjURY= Received: from SN1PR12CA0064.namprd12.prod.outlook.com (2603:10b6:802:20::35) by CY1PR12MB9628.namprd12.prod.outlook.com (2603:10b6:930:105::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9499.7; Thu, 15 Jan 2026 06:09:39 +0000 Received: from SA2PEPF00003F65.namprd04.prod.outlook.com (2603:10b6:802:20:cafe::1) by SN1PR12CA0064.outlook.office365.com (2603:10b6:802:20::35) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.4 via Frontend Transport; Thu, 15 Jan 2026 06:09:28 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00003F65.mail.protection.outlook.com (10.167.248.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.1 via Frontend Transport; Thu, 15 Jan 2026 06:09:39 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 15 Jan 2026 00:09:33 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v6 11/13] iommu/amd: Refactor persistent DTE bits programming into amd_iommu_make_clear_dte() Date: Thu, 15 Jan 2026 06:08:12 +0000 Message-ID: <20260115060814.10692-12-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> References: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F65:EE_|CY1PR12MB9628:EE_ X-MS-Office365-Filtering-Correlation-Id: ff63de7e-188a-4914-db8c-08de53fcaadd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|36860700013|7416014|1800799024|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?b7lePuqAzAdoz8y+PYJf/dE8hqp5SoBIULDJadEFincRqPnD/wrc8MPUMeD1?= =?us-ascii?Q?yJYO0NuR2vzDThbJj4rYUytk5U5UzTIv0qLhfKH73ZvD6U4foJ+cGnvpjJ/Y?= =?us-ascii?Q?+DiCDmSmZnUIHGh62BEkNyvNYTsHmaj72IwB5hjfhuxMI6ApolAt3fhTB7lz?= =?us-ascii?Q?g0c5dnPrXxNXSbzScOsYcG9kEik80vkIIoEg+4QCExkWfc8tCRjRpveQuNd5?= =?us-ascii?Q?MR3+FEmc5VjGziVU9ma9L7D8xheQAKbJZkwXCBkJMbaatLQ7dTxov7cv+3Mf?= =?us-ascii?Q?OoX05dAcGGXzpQyQSS3QVNdGF42A3NetWvxg//jHLCuRLP8vfGw+gXRZJV7V?= =?us-ascii?Q?O+rQvhT0NshJDT04iiFkSeiHapbQnQiC/xPve8mfovwgDUXU9FvodfY++Vec?= =?us-ascii?Q?TF5yEb+yxtHOfWCH5IN5GrNB5sBpv8b+epRv7awZ2sq+fCOAESbnz75NeniC?= =?us-ascii?Q?EtLheT+nfc6aWHyysXg3eOex3Y7ts4wJq99Evnc+EKE1gfBmJnWk0vlGNV39?= =?us-ascii?Q?Pc97RlCWrPZZsUBoHhTPH6QFCAohtd8HD6LiJ56zhrHsZSj5OfFIQ4zM220G?= =?us-ascii?Q?AjAnN7OkEoP5mcvboy6ZKEd+hyBCNyYGMRTrNze63yeZnOr1GJQ0wCbUgsfz?= =?us-ascii?Q?BDZ4T/cGtATiIVrCccbzSaUF5di7MuQB/TU8lCCn5Y4lxP+qJJndQTeMsrqf?= =?us-ascii?Q?anVU1wbxfgLjcLXnnXqTPpRncTZzR6TEaA0sg8LB2Ry6+cWt4+4Wci9LgXRR?= =?us-ascii?Q?MsnNjciLwmjTD0IkpTP5Gc5eLRDWolpkr1Z0zM3oyzz/VcuAjo0F/77MI2ms?= =?us-ascii?Q?aucQb6PSOsDGLCPrL1rQXyyrr9EP/YLAAN0l38lI5j332v7y1RQwzAYfYzCO?= =?us-ascii?Q?iIEd+XW/f2+kZqo2j52u8PJ/+R/C58HhoMUXC3ANa/pEwRtqfoNmSeyZoY0L?= =?us-ascii?Q?M013sZrqIFPuFIaqfQZvF1ODTb2R5HFyKvwduOruGLeR14lypCdX8g5Wa4hR?= =?us-ascii?Q?g4B7Mj+nlYAXWY80Fntrus6d0S6AaMIWrr7ZrG7Hhl6ZEEmxSKN91BtLuRuK?= =?us-ascii?Q?Enb4+jfZh381JMebVKatz8aG2a7w2ogsA8nIM0ch/fV+gYXIx4F/QKD7HJs0?= =?us-ascii?Q?9cIdPwTi6R2X/CtU1xBrSQg2BfX+dz/BBl8bBuOq2liHPDwIh3zyn/DVZsBB?= =?us-ascii?Q?Fu2fUx6sX047CEC0GGpeWpxVj95MJTihF7ld63NqXE6Mi75vUX//CrnBdWgL?= =?us-ascii?Q?ABAu+szE8lQKZY/D73iQ2juWt/3zix9weTsimn3EK8x1xdwkM/Q3bLxzcblS?= =?us-ascii?Q?sYgxoyFwyW5B3MYABnH1Bj7Qp8T1zYMCrGxXuv2XVc+wRT6+4bE5KwnCan9g?= =?us-ascii?Q?1f3UYcHCEeHDwcavNh3SQI92Dy+ptvUKYUICv3qrizbzl962tJuk5WBqwUGI?= =?us-ascii?Q?4zEIWE+Uo+cgddLe3UDE3uRfJ3JrxIDTJIF2VnaeW8UbhhsbL1K2EOvX9KHb?= =?us-ascii?Q?Xe9q+ey7lVnlchrUhBfI5gRBywzMdr+jQzeId9S3GJ7fZGP6RcTOulk6NZgn?= =?us-ascii?Q?F2yc/1NUC3Z1TTuKAtIpFNSAWh16cYDV4wTj9zUvqOa7ZR1t44iDxMtbmMJM?= =?us-ascii?Q?/EXzZqA+xYBQod9rDXZ8V7NvXGWAHbBL2Zt8KGVd+F+bv9AyodkutNtfsU48?= =?us-ascii?Q?kQGteg=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(82310400026)(36860700013)(7416014)(1800799024)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2026 06:09:39.6094 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ff63de7e-188a-4914-db8c-08de53fcaadd 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F65.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB9628 Content-Type: text/plain; charset="utf-8" To help avoid duplicate logic when programing DTE for nested translation. Note that this commit changes behavior of when the IOMMU driver is switching domain during attach and the blocking domain, where DTE bit fields for interrupt pass-through (i.e. Lint0, Lint1, NMI, INIT, ExtInt) and System management message could be affected. These DTE bits are specified in the IVRS table for specific devices, and should be persistent. Suggested-by: Jason Gunthorpe Reviewed-by: Jason Gunthorpe Reviewed-by: Nicolin Chen Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 13 +++++++++++++ drivers/iommu/amd/iommu.c | 11 ----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index aa29afe96e90..00fc9c6073de 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -197,9 +197,22 @@ void amd_iommu_update_dte(struct amd_iommu *iommu, static inline void amd_iommu_make_clear_dte(struct iommu_dev_data *dev_data, struct dev_table= _entry *new) { + struct dev_table_entry *initial_dte; + struct amd_iommu *iommu =3D get_amd_iommu_from_dev(dev_data->dev); + /* All existing DTE must have V bit set */ new->data128[0] =3D DTE_FLAG_V; new->data128[1] =3D 0; + + /* + * Restore cached persistent DTE bits, which can be set by information + * in IVRS table. See set_dev_entry_from_acpi(). + */ + initial_dte =3D amd_iommu_get_ivhd_dte_flags(iommu->pci_seg->id, dev_data= ->devid); + if (initial_dte) { + new->data128[0] |=3D initial_dte->data128[0]; + new->data128[1] |=3D initial_dte->data128[1]; + } } =20 /* NESTED */ diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index e33076b99aac..dafd34465fc0 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2106,7 +2106,6 @@ static void set_dte_entry(struct amd_iommu *iommu, { u16 domid; u32 old_domid; - struct dev_table_entry *initial_dte; struct dev_table_entry new =3D {}; struct protection_domain *domain =3D dev_data->domain; struct gcr3_tbl_info *gcr3_info =3D &dev_data->gcr3_info; @@ -2164,16 +2163,6 @@ static void set_dte_entry(struct amd_iommu *iommu, old_domid =3D READ_ONCE(dte->data[1]) & DTE_DOMID_MASK; new.data[1] |=3D domid; =20 - /* - * Restore cached persistent DTE bits, which can be set by information - * in IVRS table. See set_dev_entry_from_acpi(). - */ - initial_dte =3D amd_iommu_get_ivhd_dte_flags(iommu->pci_seg->id, dev_data= ->devid); - if (initial_dte) { - new.data128[0] |=3D initial_dte->data128[0]; - new.data128[1] |=3D initial_dte->data128[1]; - } - set_dte_gcr3_table(iommu, dev_data, &new); =20 amd_iommu_update_dte(iommu, dev_data, &new); --=20 2.34.1 From nobody Sat Feb 7 06:40:11 2026 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010029.outbound.protection.outlook.com [52.101.201.29]) (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 1257918C332 for ; Thu, 15 Jan 2026 06:09:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.29 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457393; cv=fail; b=elVH3WLSJk/B5HK4sGyWueHvCS3Iuq/qB15zplkY78j5sWqLS5jBXfsTc4+ytQhi+qUr/nmAsJVD+gYBlj34FBt2gc62vu1X/ID7vlDELIQlovxxz2N6EUWtLpWxHALwOF/8zVXqujAzI3osIqz6tYu/lufM9DUMtrSgl+ZDNSs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457393; c=relaxed/simple; bh=Pp2vORKBaRYaqIi8KlzNL8VSV1Nd4FKsAppoxkjYMIM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=owwC/d3EAGRR7nrxv/n7v4V7HHSP6lQMIxYRY270UqcuqilnBmk/dcfJHIy0A/wB5si1wfUCl0RpqAmfSueWt05CSwLq0d9B6SHQsxFL45PZtIF9R+oHtd9Zqc087Kd27kLQostmemJuLmSD7r0As6Le2s9gWQWYWmnZpT0bRh0= 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=EqPyAtPn; arc=fail smtp.client-ip=52.101.201.29 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="EqPyAtPn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=w+xDu9fsIGm/qHyl62lfUGNT1IS+YDPkCpPhqN9WdqNhtEFTTI6Fy2tn7RSfamODhydyDAvwjFO2OEO5utonyBjkl/YP6R/tW1GJYeSvsfQyClzKoQO/j10nrQgWoRJDwV1NVmbsMQnmrLdwVgFYuyCoom48BXGq+WkCnVeOZPpVBSSffSk6zpAqio5TXmCRAJw4BcYPY/QTHkA/e1PnejaU540hS8OnuwpwY/5SFDaRBCnFY45/UnhmG5Sm+BC6kd+2O1Fz8TntAbCC1da62Gb3xjZkhD5GpU0/bafRJ/LO9WfiFCAYq42EmIJhMunW2TrWb4zTfX2cvx/vXEXrcQ== 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=h3ZaiU65hxMCXABkFG+PWjGOPKYSS7kt5PiP5jJ+Klo=; b=ggEXxCG5Rh8rD2jgmNuRke/7k8QPbxvNzE6ZtIFnLGwqTH1QputheRitwEPZeZGQ/I7WWNc+BU9aNGTx3K0C0WDg7vW00NZOyoIW4dHv6+kP/t+erpzV5c90inYKjLwdnKWu+sVfceHU7CrvZlXwmhOLpL4Nnp9JWIX+gaWOS8IvNiDIAPyi3gluYCTqXWWAic0+s8rusrFXAR+rXdPABT40lZfCJedqPZ6g/wzWd7lWjeY9h5mJBZ81NWUKZMCgvBv6Q9+NGOoGv0MkD1o8OF3xVLV9L+eesKOUMQt2wDb3b6tG7K6TWS1irePI7hqtNGUK43M9/r1st6dsMW5NZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com 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=h3ZaiU65hxMCXABkFG+PWjGOPKYSS7kt5PiP5jJ+Klo=; b=EqPyAtPnxjOCcEqVV9iDCRjeVH8V9v4nLNh+YtRfED8K3GYP8MLjk41BzyP/P5Q8m5345gDHjoFra3abW+wkDZm8ix4a08PakbFMr3bTIQLlcivKJjsFyujMHlpEeUUK0QS2OOtE70JmHelSiFcYqJqVzQTATjI7cqXQYu/cJ+k= Received: from SA9P221CA0026.NAMP221.PROD.OUTLOOK.COM (2603:10b6:806:25::31) by SA5PPF8DEAB7A29.namprd12.prod.outlook.com (2603:10b6:80f:fc04::8d4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.6; Thu, 15 Jan 2026 06:09:45 +0000 Received: from SA2PEPF00003F62.namprd04.prod.outlook.com (2603:10b6:806:25:cafe::4e) by SA9P221CA0026.outlook.office365.com (2603:10b6:806:25::31) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.5 via Frontend Transport; Thu, 15 Jan 2026 06:09:39 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00003F62.mail.protection.outlook.com (10.167.248.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.1 via Frontend Transport; Thu, 15 Jan 2026 06:09:45 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 15 Jan 2026 00:09:39 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v6 12/13] iommu/amd: Refactor logic to program the host page table in DTE Date: Thu, 15 Jan 2026 06:08:13 +0000 Message-ID: <20260115060814.10692-13-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> References: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F62:EE_|SA5PPF8DEAB7A29:EE_ X-MS-Office365-Filtering-Correlation-Id: d6de8a85-f920-4877-d128-08de53fcae2e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|1800799024|36860700013|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?rTVWEJwxn5oDVDPnXm5ick7thXJxqf2o5YSdilqK42EWYBcIx6N8Bian6dAX?= =?us-ascii?Q?uxnodCJ6BWLA1FbAhIkO5RxjypjObZY/9d+dXhp9Qm3DlfuPu/RwBRpfL/Bm?= =?us-ascii?Q?GSZX72Ogg1N5oJ3ipDCH+80gC1Xsi1Uu1gkp74g8SRTQ2fDFOYsnGk9htI1k?= =?us-ascii?Q?suq+BqvUsSwmhN7ovD1OdMNMynnz2yXfZ6l147TTJrDMykD4ZV2Q4OZ3XvN9?= =?us-ascii?Q?8iT+W8A3UxxXAgYwQoDbvLgViYn/t6ZOzGoiwA7TEn4h0pbo0Ujx7ByUGpgg?= =?us-ascii?Q?+O10d02skfTDaKymwmQw5vO2WnARcaZOjINX4Suwnamd1lYY/IYin+pU4LhX?= =?us-ascii?Q?fX3pn7WDXnneng3TwnODJ5GQWBkf6Pc3GECPgVWytjpOer851p5EIaOxSlyv?= =?us-ascii?Q?l5PHl0kxk+oZ9SnJf52EO7oM3Qp5a6X2BUKXy8cLE3V7cOFPwic0MkSAMdX9?= =?us-ascii?Q?MLAjqEeha01PomvI9r4vbVItpRtJ4vLbo4qUguWZsV66w0lJooOraX5MNR4S?= =?us-ascii?Q?a1tVc5uCDDtRnPw9sY40eiStSnvsq5yN4VfVHViq/m47bRkj3QybCAfGy3uN?= =?us-ascii?Q?D/II5I/fV6i0wdi7IomKVQgom+m2LoUWOa+7N7g2uaO8670MC7PbJv5+GDjw?= =?us-ascii?Q?LHoz7Oq/kWd5PuLzASOE7VSHLs2PmPPeu2SFPH66DX39T9z5EjySQ5RinN0c?= =?us-ascii?Q?hv5naTWuHjW16d0cP+o7v05nihecBdFrkneYDkBXm54UeuiApLKSaPcCUJUS?= =?us-ascii?Q?wC1acjp07qCfjxWujyS9iMWxJCyX68O16ULevgir+zgLcckS26N28bdvAGZX?= =?us-ascii?Q?7mSO72AaBTwwsiUqhxzLSsTVjRubhiIrtuZzrA0/XUheUYMmJTYReiNts0QQ?= =?us-ascii?Q?FdOiMZ5rSZQOJjsWa0U8w/hD5ccatX2s0s4fuK/VemnckrBlBLseIjgV3Yfb?= =?us-ascii?Q?LPu5U8kbtza0SWnsdY1Tav+R4+dZRcLXXezOpU0G4gWAt0DCIvwnBj3EgpSW?= =?us-ascii?Q?c/5sHFN5Rx4IgJsQkiJaBVPbxVC9Y/kf6QIt2XqXSRwkaKzwQytw1uUdhRBv?= =?us-ascii?Q?HgU+/XtDOOzoUG922XAn/ySsGyLlnNWtuHConsIBdSfHcgg3nf/ayOVBDuNC?= =?us-ascii?Q?3l/VuxLBCZ8mG0Y+a3KrORoyXvv4oiSu3H3Pa84x1NCcxbKuPIDkGhPdB7jD?= =?us-ascii?Q?nmqzWje9dsancZNEScPb06ew6FOnEkQB8ikeerafUG1DT4X8hnU9QadKKhON?= =?us-ascii?Q?Z2qD1E6XVwHgYFEgAVdR7OUkF8fCClb2dhF0BmK1CJo09ecJxByk9vn7+ocK?= =?us-ascii?Q?kH4IIRTHzmLbsSHFYiGWdFbyu5IoK1J1j9V6iLN+fNQVhyhpufLFUgWvZFsy?= =?us-ascii?Q?jpW1k4T2p6Q9sUSme8DV1o8ZMnPr80DmGvX1sbMhCOxVMgP2UoPxMIyjCtIH?= =?us-ascii?Q?8rrskhdyVsSPO1qvAlNtitpPRZAXmKvAl606hMeS2bT/uxs3n/8hh1WRQnbp?= =?us-ascii?Q?vNR148dko6uxEj2mMxxc0Fcp+d7z6WNkKbEdU52a59OJut4VKs3YWCa9R64w?= =?us-ascii?Q?aKQ9+JncbfDLHgD6vCHssloTsqsV21Qn0UYi9aCaLzzjPvfThXh85ASvr7fy?= =?us-ascii?Q?HsidMjP6jZTAddSEDN5sgF/5TaC3rIfdA8OObOgbtNewqYeLJMwsHVTMSMez?= =?us-ascii?Q?syBAJw=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(1800799024)(36860700013)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2026 06:09:45.1957 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d6de8a85-f920-4877-d128-08de53fcae2e 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F62.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA5PPF8DEAB7A29 Content-Type: text/plain; charset="utf-8" Introduce the amd_iommu_set_dte_v1() helper function to configure IOMMU host (v1) page table into DTE. This will be used later when attaching nested doamin. Also, remove obsolete warning when SNP is enabled and domain id is zero since this check is no longer applicable. Suggested-by: Jason Gunthorpe Reviewed-by: Jason Gunthorpe Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/amd_iommu.h | 4 + drivers/iommu/amd/amd_iommu_types.h | 1 + drivers/iommu/amd/iommu.c | 150 ++++++++++++++-------------- 3 files changed, 82 insertions(+), 73 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 00fc9c6073de..02f10922f70b 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -190,6 +190,10 @@ void amd_iommu_domain_set_pgtable(struct protection_do= main *domain, struct dev_table_entry *get_dev_table(struct amd_iommu *iommu); struct iommu_dev_data *search_dev_data(struct amd_iommu *iommu, u16 devid); =20 +void amd_iommu_set_dte_v1(struct iommu_dev_data *dev_data, + struct protection_domain *domain, u16 domid, + struct pt_iommu_amdv1_hw_info *pt_info, + struct dev_table_entry *new); void amd_iommu_update_dte(struct amd_iommu *iommu, struct iommu_dev_data *dev_data, struct dev_table_entry *new); diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_io= mmu_types.h index 4a98ac7dca0f..cfcbad6c28ff 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -357,6 +357,7 @@ #define DTE_FLAG_HAD (3ULL << 7) #define DTE_MODE_MASK GENMASK_ULL(11, 9) #define DTE_HOST_TRP GENMASK_ULL(51, 12) +#define DTE_FLAG_PPR BIT_ULL(52) #define DTE_FLAG_GIOV BIT_ULL(54) #define DTE_FLAG_GV BIT_ULL(55) #define DTE_GLX GENMASK_ULL(57, 56) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index dafd34465fc0..17b0f48f1721 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2068,102 +2068,106 @@ int amd_iommu_clear_gcr3(struct iommu_dev_data *d= ev_data, ioasid_t pasid) * Note: * The old value for GCR3 table and GPT have been cleared from caller. */ -static void set_dte_gcr3_table(struct amd_iommu *iommu, - struct iommu_dev_data *dev_data, - struct dev_table_entry *target) +static void set_dte_gcr3_table(struct iommu_dev_data *dev_data, + struct dev_table_entry *new) { struct gcr3_tbl_info *gcr3_info =3D &dev_data->gcr3_info; - u64 gcr3; + u64 gcr3 =3D iommu_virt_to_phys(gcr3_info->gcr3_tbl); =20 - if (!gcr3_info->gcr3_tbl) - return; - - pr_debug("%s: devid=3D%#x, glx=3D%#x, gcr3_tbl=3D%#llx\n", - __func__, dev_data->devid, gcr3_info->glx, - (unsigned long long)gcr3_info->gcr3_tbl); - - gcr3 =3D iommu_virt_to_phys(gcr3_info->gcr3_tbl); + new->data[0] |=3D DTE_FLAG_TV | + (dev_data->ppr ? DTE_FLAG_PPR : 0) | + (pdom_is_v2_pgtbl_mode(dev_data->domain) ? DTE_FLAG_GIOV : 0) | + DTE_FLAG_GV | + FIELD_PREP(DTE_GLX, gcr3_info->glx) | + FIELD_PREP(DTE_GCR3_14_12, gcr3 >> 12) | + DTE_FLAG_IR | DTE_FLAG_IW; =20 - target->data[0] |=3D DTE_FLAG_GV | - FIELD_PREP(DTE_GLX, gcr3_info->glx) | - FIELD_PREP(DTE_GCR3_14_12, gcr3 >> 12); - if (pdom_is_v2_pgtbl_mode(dev_data->domain)) - target->data[0] |=3D DTE_FLAG_GIOV; - - target->data[1] |=3D FIELD_PREP(DTE_GCR3_30_15, gcr3 >> 15) | - FIELD_PREP(DTE_GCR3_51_31, gcr3 >> 31); + new->data[1] |=3D FIELD_PREP(DTE_DOMID_MASK, dev_data->gcr3_info.domid) | + FIELD_PREP(DTE_GCR3_30_15, gcr3 >> 15) | + (dev_data->ats_enabled ? DTE_FLAG_IOTLB : 0) | + FIELD_PREP(DTE_GCR3_51_31, gcr3 >> 31); =20 /* Guest page table can only support 4 and 5 levels */ if (amd_iommu_gpt_level =3D=3D PAGE_MODE_5_LEVEL) - target->data[2] |=3D FIELD_PREP(DTE_GPT_LEVEL_MASK, GUEST_PGTABLE_5_LEVE= L); + new->data[2] |=3D FIELD_PREP(DTE_GPT_LEVEL_MASK, GUEST_PGTABLE_5_LEVEL); else - target->data[2] |=3D FIELD_PREP(DTE_GPT_LEVEL_MASK, GUEST_PGTABLE_4_LEVE= L); + new->data[2] |=3D FIELD_PREP(DTE_GPT_LEVEL_MASK, GUEST_PGTABLE_4_LEVEL); +} + +void amd_iommu_set_dte_v1(struct iommu_dev_data *dev_data, + struct protection_domain *domain, u16 domid, + struct pt_iommu_amdv1_hw_info *pt_info, + struct dev_table_entry *new) +{ + u64 host_pt_root =3D __sme_set(pt_info->host_pt_root); + + /* Note Dirty tracking is used for v1 table only for now */ + new->data[0] |=3D DTE_FLAG_TV | + FIELD_PREP(DTE_MODE_MASK, pt_info->mode) | + (domain->dirty_tracking ? DTE_FLAG_HAD : 0) | + FIELD_PREP(DTE_HOST_TRP, host_pt_root >> 12) | + DTE_FLAG_IR | DTE_FLAG_IW; + + new->data[1] |=3D FIELD_PREP(DTE_DOMID_MASK, domid) | + (dev_data->ats_enabled ? DTE_FLAG_IOTLB : 0); +} + +static void set_dte_v1(struct iommu_dev_data *dev_data, + struct protection_domain *domain, u16 domid, + phys_addr_t top_paddr, unsigned int top_level, + struct dev_table_entry *new) +{ + struct pt_iommu_amdv1_hw_info pt_info; + + /* + * When updating the IO pagetable, the new top and level + * are provided as parameters. For other operations i.e. + * device attach, retrieve the current pagetable info + * via the IOMMU PT API. + */ + if (top_paddr) { + pt_info.host_pt_root =3D top_paddr; + pt_info.mode =3D top_level + 1; + } else { + WARN_ON(top_paddr || top_level); + pt_iommu_amdv1_hw_info(&domain->amdv1, &pt_info); + } + + amd_iommu_set_dte_v1(dev_data, domain, domid, &pt_info, new); +} + +static void set_dte_passthrough(struct iommu_dev_data *dev_data, + struct protection_domain *domain, + struct dev_table_entry *new) +{ + new->data[0] |=3D DTE_FLAG_TV | DTE_FLAG_IR | DTE_FLAG_IW; + + new->data[1] |=3D FIELD_PREP(DTE_DOMID_MASK, domain->id) | + (dev_data->ats_enabled) ? DTE_FLAG_IOTLB : 0; } =20 static void set_dte_entry(struct amd_iommu *iommu, struct iommu_dev_data *dev_data, phys_addr_t top_paddr, unsigned int top_level) { - u16 domid; u32 old_domid; struct dev_table_entry new =3D {}; struct protection_domain *domain =3D dev_data->domain; struct gcr3_tbl_info *gcr3_info =3D &dev_data->gcr3_info; struct dev_table_entry *dte =3D &get_dev_table(iommu)[dev_data->devid]; - struct pt_iommu_amdv1_hw_info pt_info; =20 amd_iommu_make_clear_dte(dev_data, &new); =20 - if (gcr3_info && gcr3_info->gcr3_tbl) - domid =3D dev_data->gcr3_info.domid; - else { - domid =3D domain->id; - - if (domain->domain.type & __IOMMU_DOMAIN_PAGING) { - /* - * When updating the IO pagetable, the new top and level - * are provided as parameters. For other operations i.e. - * device attach, retrieve the current pagetable info - * via the IOMMU PT API. - */ - if (top_paddr) { - pt_info.host_pt_root =3D top_paddr; - pt_info.mode =3D top_level + 1; - } else { - WARN_ON(top_paddr || top_level); - pt_iommu_amdv1_hw_info(&domain->amdv1, - &pt_info); - } - - new.data[0] |=3D __sme_set(pt_info.host_pt_root) | - (pt_info.mode & DEV_ENTRY_MODE_MASK) - << DEV_ENTRY_MODE_SHIFT; - } - } - - new.data[0] |=3D DTE_FLAG_IR | DTE_FLAG_IW; - - /* - * When SNP is enabled, we can only support TV=3D1 with non-zero domain I= D. - * This is prevented by the SNP-enable and IOMMU_DOMAIN_IDENTITY check in - * do_iommu_domain_alloc(). - */ - WARN_ON(amd_iommu_snp_en && (domid =3D=3D 0)); - new.data[0] |=3D DTE_FLAG_TV; - - if (dev_data->ppr) - new.data[0] |=3D 1ULL << DEV_ENTRY_PPR; - - if (domain->dirty_tracking) - new.data[0] |=3D DTE_FLAG_HAD; - - if (dev_data->ats_enabled) - new.data[1] |=3D DTE_FLAG_IOTLB; - old_domid =3D READ_ONCE(dte->data[1]) & DTE_DOMID_MASK; - new.data[1] |=3D domid; - - set_dte_gcr3_table(iommu, dev_data, &new); + if (gcr3_info->gcr3_tbl) + set_dte_gcr3_table(dev_data, &new); + else if (domain->domain.type =3D=3D IOMMU_DOMAIN_IDENTITY) + set_dte_passthrough(dev_data, domain, &new); + else if ((domain->domain.type & __IOMMU_DOMAIN_PAGING) && + domain->pd_mode =3D=3D PD_MODE_V1) + set_dte_v1(dev_data, domain, domain->id, top_paddr, top_level, &new); + else + WARN_ON(true); =20 amd_iommu_update_dte(iommu, dev_data, &new); =20 --=20 2.34.1 From nobody Sat Feb 7 06:40:11 2026 Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazon11010051.outbound.protection.outlook.com [52.101.193.51]) (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 4E27E2DC357 for ; Thu, 15 Jan 2026 06:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.193.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457398; cv=fail; b=U/nefZzS7dounRKr4+4MR2ShdInxNgeTudWZIoOYThIazVTGn0chEdBLoAP8OvxjlJEIiN3fplqe9AaORqFqyOnpvZZ4vmOvaYt7erDvxzzUHDguyVTOLExgK90TnDXewqUwOiPrm7m/YVrziimpsr98RGGj74Ak/X5TnXf3nOM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768457398; c=relaxed/simple; bh=h5tEBcJuu2UaKWvV2Jb7iC9niUcLF3eGGtFFTkvwzmo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OV4keHffhUvE+8hGOVkQSS40QSLmepeW7KT1OdQem7/A0xnbsbuFC9KWexWfPLpM3QXmO/9rv5zoRmnR2/CPRoyoBWdQ3F3H7l3Ko++L81tyVaQWWZdvks6eM7VWZxADi5fBlsLKJvTtL39+oEoEXp7AjLbs0xJHayH11njD0BM= 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=WreItoeN; arc=fail smtp.client-ip=52.101.193.51 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="WreItoeN" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BHWOTtBuNgw5TW0DEN/ZgJ9VI1WEScg4bH4Cd0CdOC5cCoJmCA6TvdRYKTm9HFzQBlhRaMph1z+EqJ4YQ2inMgY3RIWQBSaeV0YLGBX+1LpLlzUagj7c34hP/LFa4CxrpqNQxvmGKCt0ryVMM7LEitAe2HcQn4gU+gMBtR938dDH3WJdz4lt7HE8wnbFRvYiYW18N7eFnF8zQWVFJ10WLIMV/omO4MKZb92V1skxNR6kRfUq1bT1yCMuYYsa7KN/nyzxKxsV4QCZnHX5juslJLp+U1mCbVqbcH3TKzO7ThPkoMF0W659cSLLHqIicplcaxnOF3A/CYCeRWOi2duHJA== 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=PAyHd0osgdvj9FTO8SaZuUNIMW1jIrvcQp3g3DjVggo=; b=OCSjMr/9nDpxLPQFawg3v4cSdCdfQtS4D0XW0lxsImEq3TW2FsvkhVUA2+NlQx8jbIYb+CseAsGgq0KQ0SZ14xy3q+8aHAi4XU+QN4VrM6rOmON2sz5N3Vth6NP+uaEovtA48yDGn3VZEkaQf35z2I9WzeIsJHgyq6s/VW8bM1k43A2p5qxSvDCKfVQChr5dkGaoakJpKFlY7f5Ph7qhGBLHNHzw3Ls+IWwavSKCdedv43S+0S0XmNUbgUgRZQyNp0XdFq1Gx87fE2TO3B6QwCcf63JNVlwFiHGL+MDwr/USAaax/OEDFcSXVCMrx0La4G/yv1qxLwG1wTPJsYXfVw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com 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=PAyHd0osgdvj9FTO8SaZuUNIMW1jIrvcQp3g3DjVggo=; b=WreItoeNZCNi/4jPME1nvg7aBweOIGIE4xC2esCK5O36I+t99ikLli218cfqlF/Vc0JABtp7/ZBwA9dcP0emPYw1L2FxrnV8wBgCLfTjjOmRckbOgXT9pV5VON5IT/cCM2ABX2WgankZDRVZKW/Q8aVD5sWSFm7aglWxE7pQ4Pk= Received: from SA9P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:806:25::13) by CH1PR12MB9623.namprd12.prod.outlook.com (2603:10b6:610:2b3::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.5; Thu, 15 Jan 2026 06:09:51 +0000 Received: from SA2PEPF00003F62.namprd04.prod.outlook.com (2603:10b6:806:25:cafe::b8) by SA9P221CA0008.outlook.office365.com (2603:10b6:806:25::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.6 via Frontend Transport; Thu, 15 Jan 2026 06:09:51 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00003F62.mail.protection.outlook.com (10.167.248.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.1 via Frontend Transport; Thu, 15 Jan 2026 06:09:51 +0000 Received: from purico-ed03host.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 15 Jan 2026 00:09:45 -0600 From: Suravee Suthikulpanit To: , CC: , , , , , , , , , , , , , , , , , , Suravee Suthikulpanit Subject: [PATCH v6 13/13] iommu/amd: Add support for nested domain attach/detach Date: Thu, 15 Jan 2026 06:08:14 +0000 Message-ID: <20260115060814.10692-14-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> References: <20260115060814.10692-1-suravee.suthikulpanit@amd.com> 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F62:EE_|CH1PR12MB9623:EE_ X-MS-Office365-Filtering-Correlation-Id: 7e30955f-96de-48b2-0035-08de53fcb1b0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?HzVUpgT1AvVoM1rAUMxq76xTeW5kl3cGRgM/f4Ex/YRtQ7yYMhj9sPCGRA9s?= =?us-ascii?Q?gFOh79XNFh/QOVNT/yOR8IEtWEgC9JB5T2eFFN+cIABqX4Fh1P1FTLa7zDCj?= =?us-ascii?Q?mKyY4llLTiXzQZ69LJr3N82wy5s7y+pk+CCxf8TG+Ce0VyqvWovNfZoS8uk4?= =?us-ascii?Q?tK4vGmyxk1SYEZyj1oX90uyEXlQs3FdL7N5UCyyuRdNUL+RyPbcGp3TBWpQp?= =?us-ascii?Q?cBKBgz8R8TVh5g77yM8dRtT9MwDLhAs6tpzKfJs517zDVPmUOXwCzctmz46g?= =?us-ascii?Q?42wN4QZWrWzGN+8ifS8+SFMQ7OtqQMJJRoGBNkWSV0wRRTe6FJIzWQ+EEJt+?= =?us-ascii?Q?AQwfAOoL4Exy+E8/01TlANXwVxCXA6Vw8/ECM/g8dGQbVuGnAvA3po+OWAS5?= =?us-ascii?Q?rtnSy4+x17Sus/kQ7kcKguNpuzgyBQWGbJTeBoashPIgYBL6UmUw+G7Y264r?= =?us-ascii?Q?iQkOX5GMEBq1D4nZ20UCEE7E6TD8tmZoUuRu/py9gB+oF93Vi22aQ7EnT1U/?= =?us-ascii?Q?km/lWZ38/bbC3BluL22dIGZWYSKI1b1aAwQIJv5UrRY5SULkETvUJ12tV/5F?= =?us-ascii?Q?fKpUmB+GvMnNrrBLS3IGt0plxfXIG05dOgqYZ951AYIISBtW37E2vWvi4vPW?= =?us-ascii?Q?vjBmN6qxgUC48KUkJr+3g8oI4qzhf3oe9f5hRFXqMvIEgbj7Pb5Thu6JmbFd?= =?us-ascii?Q?0DdDjnlTNTCLskXL35T+uExqB45tIcukx6Qxu9f7vGVxrHU40EffdPIQN/j2?= =?us-ascii?Q?n9jtrERqwIsEPK0EZdBWIyUxh3qqYGTKRI/USTVaaHxYTJqqHK+LjnPX21xf?= =?us-ascii?Q?6mBkjz89kKKeoDoOBK2yRlIF0hPCL7+Yk6IWZyAJhKFG/AYdfHEON6d0/O2/?= =?us-ascii?Q?RQN8beJQrQrHAityWT36RKUCNYzcQilmdbkT6bPfi/ipTy+fsolwRqLLoYVQ?= =?us-ascii?Q?XZZ7kUZ8FvSLBPNDZfzu3vFylFnyfgprdfWlcCtLUS5R/E+ssOVtQY8Y2++/?= =?us-ascii?Q?ynVSWHhqWWgc3NteLmgCdrf6GKGem1xrEUD4yd6zaRggo2X775fgIevB12AL?= =?us-ascii?Q?ESwOGi+nHqdOoY5jfkTNIKBzLWZINnsnVm3yiv1I4WsLXzIN4sY9b6Pfe9Pe?= =?us-ascii?Q?XRmAmekto1c2lkRhBG2Q0nWC2VllgDP+AQF+87d4CB9OPAwd4z+PZVkVeCUi?= =?us-ascii?Q?bQD32pjHUkcm/o0uB6j+w8wD0rUEDSiSRGQ+9MAXdt0zQxV/y5zaVCRM67Xm?= =?us-ascii?Q?wlcahMYfvUXCs+TvXub9+sTrKsBF1qAZ3zqJQ1OCG+d/MQ8WFv/63/laFX8g?= =?us-ascii?Q?LLLs0Y31GuhNs5B+D4HkYHPttOFWmnOe1gpvupzO2UPoJFHw2KpRYRTNbr3q?= =?us-ascii?Q?qVhbYDdCGxxkB6CYktVFSVe+CzmfO8LMV10l43x4nllQwoOLDk0M6SW0O2bb?= =?us-ascii?Q?V0sZ6vvcCor+iCYVqfAfeSwqpQBWcII7hX0t4oT+R9ke/hw9tKikE/3KuHVS?= =?us-ascii?Q?UYzy6R9dLgDxjU5wMZQRpS4/DwflAH+d/GcLyq/NfHbZ5PapW/5YJYwod6oV?= =?us-ascii?Q?U9adxpYlRDg/ctBdbhd+nzBl/Sf0b+/i6CSqJYVQxm1DC10NfaCeIv7NS0qn?= =?us-ascii?Q?NSSaogWFfFIvncyaBuZchmxY6bf9LhUuRkhXjwux/wj7xApcQCG6f6bQzagV?= =?us-ascii?Q?8/jiTg=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2026 06:09:51.0743 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7e30955f-96de-48b2-0035-08de53fcb1b0 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F62.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH1PR12MB9623 Content-Type: text/plain; charset="utf-8" Introduce set_dte_nested() to program guest translation settings in the host DTE when attaches the nested domain to a device. Reviewed-by: Nicolin Chen Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/nested.c | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/drivers/iommu/amd/nested.c b/drivers/iommu/amd/nested.c index 8154a773eed8..66cc36133c8b 100644 --- a/drivers/iommu/amd/nested.c +++ b/drivers/iommu/amd/nested.c @@ -183,6 +183,78 @@ amd_iommu_alloc_domain_nested(struct iommufd_viommu *v= iommu, u32 flags, return ERR_PTR(ret); } =20 +static void set_dte_nested(struct amd_iommu *iommu, struct iommu_domain *d= om, + struct iommu_dev_data *dev_data, struct dev_table_entry *new) +{ + struct protection_domain *parent; + struct nested_domain *ndom =3D to_ndomain(dom); + struct iommu_hwpt_amd_guest *gdte =3D &ndom->gdte; + struct pt_iommu_amdv1_hw_info pt_info; + + /* + * The nest parent domain is attached during the call to the + * struct iommu_ops.viommu_init(), which will be stored as part + * of the struct amd_iommu_viommu.parent. + */ + if (WARN_ON(!ndom->viommu || !ndom->viommu->parent)) + return; + + parent =3D ndom->viommu->parent; + amd_iommu_make_clear_dte(dev_data, new); + + /* Retrieve the current pagetable info via the IOMMU PT API. */ + pt_iommu_amdv1_hw_info(&parent->amdv1, &pt_info); + + /* + * Use domain ID from nested domain to program DTE. + * See amd_iommu_alloc_domain_nested(). + */ + amd_iommu_set_dte_v1(dev_data, parent, ndom->gdom_info->hdom_id, + &pt_info, new); + + /* GV is required for nested page table */ + new->data[0] |=3D DTE_FLAG_GV; + + /* Guest PPR */ + new->data[0] |=3D gdte->dte[0] & DTE_FLAG_PPR; + + /* Guest translation stuff */ + new->data[0] |=3D gdte->dte[0] & (DTE_GLX | DTE_FLAG_GIOV); + + /* GCR3 table */ + new->data[0] |=3D gdte->dte[0] & DTE_GCR3_14_12; + new->data[1] |=3D gdte->dte[1] & (DTE_GCR3_30_15 | DTE_GCR3_51_31); + + /* Guest paging mode */ + new->data[2] |=3D gdte->dte[2] & DTE_GPT_LEVEL_MASK; +} + +static int nested_attach_device(struct iommu_domain *dom, struct device *d= ev, + struct iommu_domain *old) +{ + struct dev_table_entry new =3D {0}; + struct iommu_dev_data *dev_data =3D dev_iommu_priv_get(dev); + struct amd_iommu *iommu =3D get_amd_iommu_from_dev_data(dev_data); + int ret =3D 0; + + /* + * Needs to make sure PASID is not enabled + * for this attach path. + */ + if (WARN_ON(dev_data->pasid_enabled)) + return -EINVAL; + + mutex_lock(&dev_data->mutex); + + set_dte_nested(iommu, dom, dev_data, &new); + + amd_iommu_update_dte(iommu, dev_data, &new); + + mutex_unlock(&dev_data->mutex); + + return ret; +} + static void nested_domain_free(struct iommu_domain *dom) { struct guest_domain_mapping_info *curr; @@ -217,5 +289,6 @@ static void nested_domain_free(struct iommu_domain *dom) } =20 static const struct iommu_domain_ops nested_domain_ops =3D { + .attach_dev =3D nested_attach_device, .free =3D nested_domain_free, }; --=20 2.34.1