Skip to contentSkip to conversation

iommu/vt-d: Introduce trusted DMA initialization support

PATCH Superseded Lu Baolu 3 participants 12 messages Sep 15 – Sep 19

Subsystems (5)
x86 KVM IOMMU Intel IOMMU (VT-d) +1 more subsystems

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Lu Baolu

author maintainer
#0 lore raw

cover iommu/vt-d: Introduce trusted DMA initialization support

Hi,

This series adds Intel VT-d trusted extension support to the host Intel IOMMU driver as groundwork for TEE I/O trusted DMA (e.g. TDX Connect).

The trusted extension introduces a parallel, extension-specific path for trusted DMA assets used by confidential device assignment. Existing VT-d functionality remains unchanged for regular host DMA paths.

From the TDX Connect architecture perspective, VT-d is enhanced with:

1) Trusted DMA translation root table
- A second root-table address register, restricted to SEAM SAI.
- Programmed by the TDX module with the root of TDX-managed DMA translation tables for TD-assigned devices.

2) Trusted invalidation queue
- A second invalidation-queue address register plus dedicated head/tail registers, also restricted to SEAM SAI.

3) IOTLB / DID isolation
- When TDX Connect is enabled, VT-d restricts VMM DID usage and reserves the DID MSB namespace bit for TDX-module use.

This posting focuses on VT-d-side enablement only: it enables those extension-defined resources and control points while preserving existing host VT-d behavior for non-trusted flows. Higher-layer integration (TDX guest/device flows) will be posted separately.

The trusted IOMMU extensions establish an architecture where only TEE-I/O DMA requests can access TD private memory, and only the TDX module can configure TEE-I/O access-control permissions. The host allocates memory for data structures used by the TDX module to manage trusted DMA, then requests the TDX module (via SEAMCALL) to enable the extension in each IOMMU.

Non-TEE-I/O DMA requests are unaffected and continue to be managed by the host through existing IOMMU interfaces.

Patch Breakdown:

- Patch 1: Implements low-level SEAMCALL wrappers (TDH.IOMMU.SETUP/CLEAR) to interface with the TDX module.
- Patch 2: Parses platform global metadata fields to calculate required IOMMU metadata page requirements.
- Patch 3: Introduces the core driver entry points.
- Patch 4: Implements the metadata page allocation and SEAMCALL sequences required to configure and release IOMMU units in trusted mode.
- Patch 5: Restricts the domain ID (DID) space allocated to the host by reserving the MSB for exclusive use by the TDX module.

ABI History:

TDH.IOMMU.CLEAR previously required the host to provide, as input, the parameter page used for TDH.IOMMU.SETUP. This ABI has changed to remove that requirement. Because this ABI change is not yet public, it may cause confusion when referring to the ABI specification.

Reference:

Implementation details follow the interfaces and behavior defined in the TDX Connect Application Binary Interface (ABI) Reference Specification and Intel TDX Connect Architecture Specification:

This is part of the effort to implement the TDX PCIe Link Encryption feature, which includes the following components:

[ ] TDX module extensions initialization, posted in [3]
[X] Introduce trusted DMA initialization support
[ ] SEAMCALL helpers for TDX PCIe Link Encryption
[ ] PCIe Link Encryption Establishment via TDX platform services

A full preview of these dependencies and follow-up changes is avaiable at [4].

Please review. Any feedback is highly appreciated.

Thanks,
Baolu

Lu Baolu (5):
x86/virt/tdx: Add SEAMCALL wrappers for IOMMU setup/clear x86/virt/tdx: Read global metadata for trusted IOMMU iommu/vt-d: Add interfaces for trusted DMA initialization iommu/vt-d: Add helpers to set up and tear down TDX extensions iommu/vt-d: Reserve MSB of domain ID space for TDX module

 drivers/iommu/intel/Kconfig                 |  14 ++
 drivers/iommu/intel/Makefile                |   1 +
 arch/x86/include/asm/tdx.h                  |   3 +
 arch/x86/include/asm/tdx_global_metadata.h  |   5 +
 arch/x86/virt/vmx/tdx/tdx.h                 |   2 +
 drivers/iommu/intel/iommu.h                 |  24 ++
 include/linux/dmar.h                        |  12 +
 arch/x86/virt/vmx/tdx/tdx.c                 |  56 +++++
 arch/x86/virt/vmx/tdx/tdx_global_metadata.c |  20 ++
 drivers/iommu/intel/dmar.c                  |   3 +
 drivers/iommu/intel/iommu.c                 |  11 +
 drivers/iommu/intel/tdxc.c                  | 248 ++++++++++++++++++++
 12 files changed, 399 insertions(+)
 create mode 100644 drivers/iommu/intel/tdxc.c
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH 1/5 x86/virt/tdx: Add SEAMCALL wrappers for IOMMU setup/clear

Add SEAMCALL wrappers for TDH.IOMMU.SETUP and TDH.IOMMU.CLEAR.

TDH.IOMMU.SETUP transitions an IOMMU and related I/O stack into Secure TDX Mode. During this transition, the TDX module validates and protects relevant I/O resources from further untrusted host access, providing the trusted foundation required before enabling TEE-IO security protocols (e.g. SPDM/IDE).

TDH.IOMMU.CLEAR performs the reverse operation and tears down the Secure TDX Mode state for the target IOMMU.

tdh_iommu_setup() takes the IOMMU register base and a host-allocated parameter page for TDX-module metadata, and returns a unique tdx_iommu_id for subsequent operations.

tdh_iommu_clear() takes tdx_iommu_id to tear down the Secure TDX Mode state and return the IOMMU to normal operation.

The caller is responsible for allocating the required pages and populating the parameter page in the ABI-defined format.

See Intel TDX Connect ABI Specification [1], Section 3.2 (TDX Connect Host-Side (SEAMCALL) Interface Functions).

Thanks to Yilun for the initial draft.

[1] https://cdrdv2.intel.com/v1/dl/getContent/858625

---
 arch/x86/include/asm/tdx.h  |  2 ++
 arch/x86/virt/vmx/tdx/tdx.h |  2 ++
 arch/x86/virt/vmx/tdx/tdx.c | 56 +++++++++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+)
arch/x86/include/asm/tdx.h +2 -0
index 89e97d5761d8..8b5411d3eb67 100644
@@ -176,6 +176,8 @@ u64 tdh_mem_page_remove(struct tdx_td *td, u64 gpa, enum pg_level level, u64 *ex
 u64 tdh_phymem_cache_wb(bool resume);
 u64 tdh_phymem_page_wbinvd_tdr(struct tdx_td *td);
 u64 tdh_phymem_page_wbinvd_hkid(u64 hkid, kvm_pfn_t pfn);
+u64 tdh_iommu_setup(u64 reg_base, void *root, u64 *tdx_iommu_id);
+u64 tdh_iommu_clear(u64 tdx_iommu_id);
 #else
 static inline void tdx_init(void) { }
 static inline u32 tdx_get_nr_guest_keyids(void) { return 0; }
arch/x86/virt/vmx/tdx/tdx.h +2 -0
index bdfd0e1e337a..d7beb42cf972 100644
@@ -49,6 +49,8 @@
 #define TDH_SYS_SHUTDOWN		52
 #define TDH_SYS_UPDATE			53
 #define TDH_SYS_DISABLE			69
+#define TDH_IOMMU_SETUP			128
+#define TDH_IOMMU_CLEAR			129
 
 /*
  * SEAMCALL leaf:
arch/x86/virt/vmx/tdx/tdx.c +56 -0

59 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH 2/5 x86/virt/tdx: Read global metadata for trusted IOMMU

In reply to Lu Baolu

Add support for reading the global metadata of the trusted IOMMU.

The trusted IOMMU feature is optionally enumerated via TDX_FEATURES0. Check this feature bit before reading the metadata to avoid causing the entire TDX initialization to fail on platforms that do not support it.

The read value represents the number of pages required for the IOMMU metadata. The host will allocate this count of pages and provide them to the TDX module when it configures the IOMMU to operate in Secure TDX mode via the TDH.IOMMU.SETUP SEAMCALL.

Thanks to Yilun for the initial draft.

---
 arch/x86/include/asm/tdx.h                  |  1 +
 arch/x86/include/asm/tdx_global_metadata.h  |  5 +++++
 arch/x86/virt/vmx/tdx/tdx_global_metadata.c | 20 ++++++++++++++++++++
 3 files changed, 26 insertions(+)
arch/x86/include/asm/tdx.h +1 -0
index 8b5411d3eb67..9c9168822274 100644
@@ -35,6 +35,7 @@
 
 /* Bit definitions of TDX_FEATURES0 metadata field */
 #define TDX_FEATURES0_TD_PRESERVING	BIT_ULL(1)
+#define TDX_FEATURES0_TDXCONNECT	BIT_ULL(6)
 #define TDX_FEATURES0_NO_RBP_MOD	BIT_ULL(18)
 
 #ifndef __ASSEMBLER__
arch/x86/include/asm/tdx_global_metadata.h +5 -0
index 41150d546589..cf64452fe94f 100644
@@ -44,12 +44,17 @@ struct tdx_sys_info_handoff {
 	u16 module_hv;
 };
 
+struct tdx_sys_info_connect {
+	u16 iommu_mt_page_count;
+};
+
 struct tdx_sys_info {
 	struct tdx_sys_info_version version;
 	struct tdx_sys_info_features features;
 	struct tdx_sys_info_tdmr tdmr;
 	struct tdx_sys_info_td_ctrl td_ctrl;
 	struct tdx_sys_info_td_conf td_conf;
+	struct tdx_sys_info_connect tdx_connect;
 };
 
 #endif
arch/x86/virt/vmx/tdx/tdx_global_metadata.c +20 -0
index e49c300f23d4..2ba1c5dcdbe6 100644
@@ -113,6 +113,20 @@ static int get_tdx_sys_info_handoff(struct tdx_sys_info_handoff *sysinfo_handoff
 	return 0;
 }
 
+static __init int get_tdx_sys_info_connect(struct tdx_sys_info_connect *sysinfo_connect)
+{
+	int ret;
+	u64 val;
+
+	ret = read_sys_metadata_field(0x3000000100000003, &val);
+	if (ret)
+		return ret;
+
+	sysinfo_connect->iommu_mt_page_count = val;
+
+	return 0;
+}
+
 static __init int get_tdx_sys_info(struct tdx_sys_info *sysinfo)
 {
 	int ret = 0;
@@ -129,5 +143,11 @@ static __init int get_tdx_sys_info(struct tdx_sys_info *sysinfo)
 	ret = ret ?: get_tdx_sys_info_td_ctrl(&sysinfo->td_ctrl);
 	ret = ret ?: get_tdx_sys_info_td_conf(&sysinfo->td_conf);
 
+	if (ret)
+		return ret;
+
+	if (sysinfo->features.tdx_features0 & TDX_FEATURES0_TDXCONNECT)
+		ret = get_tdx_sys_info_connect(&sysinfo->tdx_connect);
+
 	return ret;
 }
Signature · 1 line
2.43.0
author maintainer
#3 lore raw

PATCH 3/5 iommu/vt-d: Add interfaces for trusted DMA initialization

In reply to Lu Baolu

Add Intel VT-d interfaces to initialize and tear down TDX Connect trusted DMA support across active IOMMUs.

Trusted DMA depends on trusted-IOMMU hardware extensions, advertised by the TDXCS bit in the VT-d Extended Capability Register (ECAP). When present, the TDX module can transition an IOMMU into Secure TDX Mode via TDH.IOMMU.SETUP, and return it to normal host operation via TDH.IOMMU.CLEAR.

In this mode, VT-d provides TDX-managed DMA translation and invalidation resources (trusted translation root and invalidation queue), and splits domain ID ownership so the TDX module can use its reserved namespace independently from host-managed DIDs.

Introduce the following interfaces:
- intel_tdxc_init(): bring up TDX Connect support on all active IOMMUs that advertise TDXCS and have DMA translation enabled.
- intel_tdxc_exit(): tear down per-IOMMU TDX Connect state.

Initialization is best-effort at system scope: IOMMUs without required support are skipped, while failures on attempted bring-up are treated as errors and trigger teardown of previously initialized units.

These entry points are intended to be called by the Intel TDX Connect platform TSM driver during module init/exit.

---
 drivers/iommu/intel/Kconfig  | 14 ++++++
 drivers/iommu/intel/Makefile |  1 +
 drivers/iommu/intel/iommu.h  |  7 +++
 include/linux/dmar.h         | 12 ++++++
 drivers/iommu/intel/iommu.c  | 11 +++++
 drivers/iommu/intel/tdxc.c   | 82 ++++++++++++++++++++++++++++++++++++
 6 files changed, 127 insertions(+)
 create mode 100644 drivers/iommu/intel/tdxc.c
drivers/iommu/intel/Kconfig +14 -0
index 5471f814e073..e8c0ea79a31d 100644
@@ -100,4 +100,18 @@ config INTEL_IOMMU_PERF_EVENTS
 	  to aid performance tuning and debug. These are available on modern
 	  processors which support Intel VT-d 4.0 and later.
 
+config INTEL_IOMMU_TDX_CONNECT
+	bool "Intel IOMMU support for TDX Connect"
+	depends on INTEL_TDX_HOST
+	help
+	  Enable Intel VT-d support required by TDX Connect on TDX host systems.
+
+	  Select this if the host will run TDX Connect workloads that require
+	  trusted assignment/sharing of devices with TDX guests. If enabled,
+	  the Intel IOMMU driver integrates with the TDX host module so DMA
+	  translation state used by those workloads is managed in the TDX trust
+	  domain.
+
+	  If unsure, say N.
+
 endif # INTEL_IOMMU
drivers/iommu/intel/Makefile +1 -0
index ada651c4a01b..25bf3b970acb 100644
@@ -6,3 +6,4 @@ obj-$(CONFIG_INTEL_IOMMU_DEBUGFS) += debugfs.o
 obj-$(CONFIG_INTEL_IOMMU_SVM) += svm.o
 obj-$(CONFIG_IRQ_REMAP) += irq_remapping.o
 obj-$(CONFIG_INTEL_IOMMU_PERF_EVENTS) += perfmon.o
+obj-$(CONFIG_INTEL_IOMMU_TDX_CONNECT) += tdxc.o
drivers/iommu/intel/iommu.h +7 -0
index 23dbe6c24439..452a381e6a40 100644
@@ -187,6 +187,7 @@
  */
 
 #define ecap_pms(e)		(((e) >> 51) & 0x1)
+#define ecap_tdxcs(e)		(((e) >> 50) & 0x1)
 #define ecap_rps(e)		(((e) >> 49) & 0x1)
 #define ecap_smpwc(e)		(((e) >> 48) & 0x1)
 #define ecap_flts(e)		(((e) >> 47) & 0x1)
@@ -1323,6 +1324,12 @@ static inline void intel_iommu_debugfs_create_dev_pasid(struct dev_pasid_info *d
 static inline void intel_iommu_debugfs_remove_dev_pasid(struct dev_pasid_info *dev_pasid) {}
 #endif /* CONFIG_INTEL_IOMMU_DEBUGFS */
 
+#ifdef CONFIG_INTEL_IOMMU_TDX_CONNECT
+extern bool intel_tdxc_initialized;
+#else
+#define intel_tdxc_initialized (0)
+#endif /* CONFIG_INTEL_IOMMU_TDX_CONNECT */
+
 extern const struct attribute_group *intel_iommu_groups[];
 struct context_entry *iommu_context_addr(struct intel_iommu *iommu, u8 bus,
 					 u8 devfn, int alloc);
include/linux/dmar.h +12 -0
index 63e35df2cef4..361c0d4a45fb 100644
@@ -167,6 +167,18 @@ static inline int dmar_iommu_hotplug(struct dmar_drhd_unit *dmaru, bool insert)
 }
 #endif /* CONFIG_INTEL_IOMMU */
 
+#ifdef CONFIG_INTEL_IOMMU_TDX_CONNECT
+int intel_tdxc_init(void);
+void intel_tdxc_exit(void);
+#else
+static inline int intel_tdxc_init(void)
+{
+	return -EOPNOTSUPP;
+}
+
+static inline void intel_tdxc_exit(void) { }
+#endif /* CONFIG_INTEL_IOMMU_TDX_CONNECT */
+
 #ifdef CONFIG_IRQ_REMAP
 extern int dmar_ir_hotplug(struct dmar_drhd_unit *dmaru, bool insert);
 #else  /* CONFIG_IRQ_REMAP */
drivers/iommu/intel/iommu.c +11 -0
index 2e3b3ab216f8..e88457d96b53 100644
@@ -2168,6 +2168,17 @@ static int intel_iommu_add(struct dmar_drhd_unit *dmaru)
 	iommu_set_root_entry(iommu);
 	iommu_enable_translation(iommu);
 
+	/*
+	 * If an IOMMU is hot-added after intel_tdxc_initialized is set, it is
+	 * not enrolled into TDX secure mode. Ideally this should be integrated
+	 * with dmar_iommu_hotplug() so intel_iommu_bringup_tdxc() can run on
+	 * hotplug. This is currently skipped due to lack of hardware validation.
+	 * Log this limitation to make it visible.
+	 */
+	if (intel_tdxc_initialized && ecap_tdxcs(iommu->ecap))
+		pr_info("Trusted DMA for TEE is not enabled on hot-added IOMMU %s\n",
+			iommu->name);
+
 	iommu_disable_protect_mem_regions(iommu);
 	return 0;
 
drivers/iommu/intel/tdxc.c new file +82 -0

82 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#4 lore raw

PATCH 4/5 iommu/vt-d: Add helpers to set up and tear down TDX extensions

In reply to Lu Baolu

Implement per-IOMMU TDX Connect bring-up/tear-down helpers.

For each active IOMMU that advertises TDXCS and has DMA translation enabled, the driver allocates and populates the IOMMU_MT parameter layout required by TDH.IOMMU.SETUP:

- two contiguous invalidation-queue buffers, and
- IOMMU_MT_PAGES_COUNT metadata pages.

The driver invokes tdh_iommu_setup() to transition the IOMMU into Secure TDX Mode, then stores the returned tdx_iommu_id and allocation state for later cleanup.

On teardown, or on partial-init rollback, the driver calls tdh_iommu_clear() for each initialized IOMMU and frees all associated IOMMU_MT pages.

Completion handling:

- TDX_SUCCESS: setup completed successfully.
- TDX_OPERAND_INVALID: treated as "not supported on this IOMMU" and skipped.
- all other return codes: treated as failures and abort initialization with rollback.

No explicit clflush is needed for pages shared with the TDX module in this flow, as cache coherency is handled architecturally.

---
 drivers/iommu/intel/iommu.h |  17 ++++
 drivers/iommu/intel/dmar.c  |   3 +
 drivers/iommu/intel/tdxc.c  | 150 ++++++++++++++++++++++++++++++++++++
 3 files changed, 170 insertions(+)
drivers/iommu/intel/iommu.h +17 -0
index 452a381e6a40..7bf70113c4c8 100644
@@ -680,6 +680,17 @@ struct iommu_pmu {
 #define IOMMU_IRQ_ID_OFFSET_PRQ		(DMAR_UNITS_SUPPORTED)
 #define IOMMU_IRQ_ID_OFFSET_PERF	(2 * DMAR_UNITS_SUPPORTED)
 
+/*
+ * Represents a list of pages for TDX Module defined IOMMU_MT object.
+ * Typically it uses a "root page" as the medium to exchange a list of
+ * data pages between host and TDX Module.
+ */
+struct tdxc_pages {
+	u64 *root;
+	void **pages;
+	unsigned int nr_entries;
+};
+
 struct intel_iommu {
 	void __iomem	*reg; /* Pointer to hardware regs, virtual addr */
 	u64 		reg_phys; /* physical address of hw register set */
@@ -736,6 +747,12 @@ struct intel_iommu {
 	void *perf_statistic;
 
 	struct iommu_pmu *pmu;
+#ifdef CONFIG_INTEL_IOMMU_TDX_CONNECT
+	/* mutex to protect below tdx state data */
+	struct mutex tdx_lock;
+	u64 tdx_iommu_id;
+	struct tdxc_pages *mt_pages;
+#endif
 };
 
 /* PCI domain-device relationship */
drivers/iommu/intel/dmar.c +3 -0
index ba675b08cd20..310b8d0c4132 100644
@@ -1175,6 +1175,9 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd)
 	ida_init(&iommu->domain_ida);
 	mutex_init(&iommu->did_lock);
 	iommu->max_domain_id = cap_ndoms(iommu->cap);
+#ifdef CONFIG_INTEL_IOMMU_TDX_CONNECT
+	mutex_init(&iommu->tdx_lock);
+#endif
 
 	ver = readl(iommu->reg + DMAR_VER_REG);
 	pr_info("%s: reg_base_addr %llx ver %d:%d cap %llx ecap %llx\n",
drivers/iommu/intel/tdxc.c +150 -0

174 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#7 lore raw

PATCH 5/5 iommu/vt-d: Reserve MSB of domain ID space for TDX module

In reply to Lu Baolu

When an Intel IOMMU is enabled for TDX Connect, the VT-d DID namespace must be split so the TDX module can use the MSB-tagged half for trusted DMA translations, while the host/VMM uses the lower half.

After TDH.IOMMU.SETUP succeeds, restrict host domain ID allocation to the lower half of the DID space by capping max_domain_id to ndoms / 2. Before applying the cap, verify that no allocated domain IDs already exist in the upper half; if they do, abort bring-up and roll back the per-IOMMU TDX setup.

On teardown, restore max_domain_id to the full DID range.

This matches Intel TDX Connect architecture requirements for IOTLB/DID isolation between TEE and non-TEE translations.

---
 drivers/iommu/intel/tdxc.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/iommu/intel/tdxc.c +18 -2
index b5dfdeeb23db..1ca03257d456 100644
@@ -129,6 +129,7 @@ static struct tdxc_pages *tdxc_alloc_mt_pages(struct intel_iommu *iommu,
 
 static int intel_iommu_bringup_tdxc(struct intel_iommu *iommu, unsigned int nr_pages)
 {
+	unsigned long ndoms = cap_ndoms(iommu->cap);
 	struct dmar_drhd_unit *drhd = iommu->drhd;
 	u64 r, tdx_iommu_id;
 
@@ -144,6 +145,10 @@ static int intel_iommu_bringup_tdxc(struct intel_iommu *iommu, unsigned int nr_p
 	if (!iommu_mt)
 		return -ENOMEM;
 
+	guard(mutex)(&iommu->did_lock);
+	if (ida_find_first_range(&iommu->domain_ida, ndoms >> 1, ndoms - 1) > 0)
+		return -EBUSY;
+
 	guard(mutex)(&iommu->tdx_lock);
 	r = tdh_iommu_setup(drhd->reg_base_addr, iommu_mt->root, &tdx_iommu_id);
 	/* TDX Extension is not supported on this iommu. Nothing to do. */
@@ -154,17 +159,27 @@ static int intel_iommu_bringup_tdxc(struct intel_iommu *iommu, unsigned int nr_p
 		return -EFAULT;
 	}
 
+	/*
+	 * Intel TDX Connect Architecture Specification, Section 2.2 Trusted DMA
+	 *
+	 * When IOMMU is enabled to support TDX Connect, the IOMMU restricts
+	 * the VMM’s DID setting, reserving the MSB bit for the TDX module. The
+	 * TDX module always sets this reserved bit on the trusted DMA table.
+	 */
+	iommu->max_domain_id = ndoms >> 1;
 	iommu->tdx_iommu_id = tdx_iommu_id;
 	iommu->mt_pages = no_free_ptr(iommu_mt);
 
-	/* Bring-up is not complete yet; report as unsupported for now. */
-	return -EOPNOTSUPP;
+	pr_info("%s: trusted DMA for TEE/IO initialized\n", iommu->name);
+
+	return 0;
 }
 
 static void intel_iommu_teardown_tdxc(struct intel_iommu *iommu)
 {
 	u64 r;
 
+	guard(mutex)(&iommu->did_lock);
 	guard(mutex)(&iommu->tdx_lock);
 
 	if (!iommu->mt_pages)
@@ -179,6 +194,7 @@ static void intel_iommu_teardown_tdxc(struct intel_iommu *iommu)
 	free_mt_pages(iommu->mt_pages);
 	iommu->mt_pages = NULL;
 	iommu->tdx_iommu_id = 0;
+	iommu->max_domain_id = cap_ndoms(iommu->cap);
 }
 
 void intel_tdxc_exit(void)
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH 4/5] iommu/vt-d: Add helpers to set up and tear down TDX extensions

In reply to Lu Baolu
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] iommu: bounds check uses PAGE_SIZE while allocation uses SZ_4K --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] iommu: bounds check uses PAGE_SIZE while allocation uses SZ_4K
--

commit 4edc662d667d9a3f034b902dc510d5238c7c24a5
Author: Lu Baolu <[email protected]>

iommu/vt-d: Add helpers to set up and tear down TDX extensions

This commit implements per-IOMMU TDX Connect bring-up and tear-down helpers. It allocates and populates the IOMMU_MT parameter layout required by TDH.IOMMU.SETUP, and handles initialization completion and rollback.

Quoted 4 lines
drivers/iommu/intel/tdxc.c +0 -0
index 559c752a15273..b5dfdeeb23dba 100644

[ ... ]

drivers/iommu/intel/tdxc.c line 103

Quoted 7 lines
drivers/iommu/intel/tdxc.c +7 -0
+static struct tdxc_pages *tdxc_alloc_mt_pages(struct intel_iommu *iommu,
+					      unsigned int nr_mt_pages)
+{
+	unsigned int nr_entries = nr_mt_pages + IQ_BUFFERS_NUM;
+	struct tdxc_pages *array;
+
+	if (!nr_mt_pages || nr_mt_pages > (PAGE_SIZE / sizeof(u64) - IQ_BUFFERS_NUM))

[Severity: Low]
Does this bounds check use the wrong size macro? It restricts nr_mt_pages based on PAGE_SIZE, but the corresponding root array allocation below is hardcoded to SZ_4K. Should this check use SZ_4K to match the allocation size?

Quoted 9 lines
drivers/iommu/intel/tdxc.c +9 -0
+		return NULL;
+
+	array = kzalloc_obj(*array);
+	if (!array)
+		return NULL;
+
+	array->root = iommu_alloc_pages_node_sz(iommu->node, GFP_KERNEL, SZ_4K);
+	if (!array->root)
+		goto free_array;

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#8 lore raw

Re: [PATCH 5/5] iommu/vt-d: Reserve MSB of domain ID space for TDX module

In reply to Lu Baolu
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] iommu: missing TDX teardown and mt_pages leak on IOMMU hot-remove --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] iommu: missing TDX teardown and mt_pages leak on IOMMU hot-remove --

commit 8a16aba70396ddc74c834953ff8123fae8be9bad
Author: Lu Baolu <[email protected]>

iommu/vt-d: Reserve MSB of domain ID space for TDX module

When an Intel IOMMU is enabled for TDX Connect, the VT-d DID namespace must be split so the TDX module can use the MSB-tagged half for trusted DMA translations, while the host/VMM uses the lower half.

Quoted 4 lines
drivers/iommu/intel/tdxc.c +0 -0
index b5dfdeeb23dba..1ca03257d4563 100644

[ ... ]

Quoted 10 lines
drivers/iommu/intel/tdxc.c +6 -0
@@ -154,17 +159,27 @@ static int intel_iommu_bringup_tdxc(struct intel_iommu *iommu, unsigned int nr_p
 		return -EFAULT;
 	}
 
+	/*
+	 * Intel TDX Connect Architecture Specification, Section 2.2 Trusted DMA
+	 *
+	 * When IOMMU is enabled to support TDX Connect, the IOMMU restricts
+	 * the VMM’s DID setting, reserving the MSB bit for the TDX module. The
+	 * TDX module always sets this reserved bit on the trusted DMA table.

drivers/iommu/intel/tdxc.c static int intel_iommu_bringup_tdxc(struct intel_iommu *iommu, unsigned int nr_p · line 175

Quoted 10 lines
drivers/iommu/intel/tdxc.c +5 -2
+	 */
+	iommu->max_domain_id = ndoms >> 1;
 	iommu->tdx_iommu_id = tdx_iommu_id;
 	iommu->mt_pages = no_free_ptr(iommu_mt);
 
-	/* Bring-up is not complete yet; report as unsupported for now. */
-	return -EOPNOTSUPP;
+	pr_info("%s: trusted DMA for TEE/IO initialized\n", iommu->name);
+
+	return 0;

[Severity: High]
With TDX bring-up now successfully completing here, if this IOMMU is later hot-removed, does this leak the TDX metadata pages (iommu->mt_pages) and leave dangling hardware state in the SEAM firmware?

When ACPI hotplug invokes dmar_iommu_hotplug() with insert=false, the IOMMU is destroyed via:

drivers/iommu/intel/iommu.c:dmar_iommu_hotplug() {
    ...
		disable_dmar_iommu(iommu);
		free_dmar_iommu(iommu);
    ...
}

Because this hot-remove path never calls intel_iommu_teardown_tdxc(), it appears iommu->mt_pages is leaked and tdh_iommu_clear() is never called before the IOMMU structure itself is freed.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
author maintainer
#9 lore raw

Re: [PATCH 5/5] iommu/vt-d: Reserve MSB of domain ID space for TDX module

Quoted 33 lines · On 9/15/2026 4:11 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] iommu: missing TDX teardown and mt_pages leak on IOMMU hot-remove --

commit 8a16aba70396ddc74c834953ff8123fae8be9bad
Author: Lu Baolu <[email protected]>

iommu/vt-d: Reserve MSB of domain ID space for TDX module

When an Intel IOMMU is enabled for TDX Connect, the VT-d DID namespace must be split so the TDX module can use the MSB-tagged half for trusted DMA translations, while the host/VMM uses the lower half.

Quoted 4 lines
drivers/iommu/intel/tdxc.c +0 -0
index b5dfdeeb23dba..1ca03257d4563 100644

[ ... ]

Quoted 15 lines
drivers/iommu/intel/tdxc.c +8 -0
@@ -154,17 +159,27 @@ static int intel_iommu_bringup_tdxc(struct intel_iommu *iommu, unsigned int nr_p
  		return -EFAULT;
  	}
 
+	/*
+	 * Intel TDX Connect Architecture Specification, Section 2.2 Trusted DMA
+	 *
+	 * When IOMMU is enabled to support TDX Connect, the IOMMU restricts
+	 * the VMM’s DID setting, reserving the MSB bit for the TDX module. The
+	 * TDX module always sets this reserved bit on the trusted DMA table.
+	 */
+	iommu->max_domain_id = ndoms >> 1;
  	iommu->tdx_iommu_id = tdx_iommu_id;
  	iommu->mt_pages = no_free_ptr(iommu_mt);
 
Quoted 10 lines

drivers/iommu/intel/tdxc.c static int intel_iommu_bringup_tdxc(struct intel_iommu *iommu, unsigned int nr_p · line 175

Quoted 5 lines
drivers/iommu/intel/tdxc.c +3 -2
-	/* Bring-up is not complete yet; report as unsupported for now. */
-	return -EOPNOTSUPP;
+	pr_info("%s: trusted DMA for TEE/IO initialized\n", iommu->name);
+
+	return 0;

[Severity: High]
With TDX bring-up now successfully completing here, if this IOMMU is later hot-removed, does this leak the TDX metadata pages (iommu->mt_pages) and leave dangling hardware state in the SEAM firmware?

This path is basically unreachable in practice. No TDX Connect-capable platform supports DMAR hotplug.

Quoted 10 lines

When ACPI hotplug invokes dmar_iommu_hotplug() with insert=false, the IOMMU is destroyed via:

drivers/iommu/intel/iommu.c:dmar_iommu_hotplug() {
     ...
		disable_dmar_iommu(iommu);
		free_dmar_iommu(iommu);
     ...
}

I will add the following check for future proofing:

drivers/iommu/intel/iommu.c +4 -0
index e88457d96b53..16203604b751 100644
@@ -2202,6 +2202,10 @@ int dmar_iommu_hotplug(struct dmar_drhd_unit *dmaru, bool insert)
        if (insert) {
                ret = intel_iommu_add(dmaru);
        } else {
+#ifdef CONFIG_INTEL_IOMMU_TDX_CONNECT
+               if (iommu->mt_pages)
+                       return -EBUSY;
+#endif
                disable_dmar_iommu(iommu);
                free_dmar_iommu(iommu);
        }
Quoted 5 lines

Because this hot-remove path never calls intel_iommu_teardown_tdxc(), it appears iommu->mt_pages is leaked and tdh_iommu_clear() is never called before the IOMMU structure itself is freed.

Thanks,
baolu

author maintainer
#6 lore raw

Re: [PATCH 4/5] iommu/vt-d: Add helpers to set up and tear down TDX extensions

In reply to [email protected]
Quoted 19 lines · On 9/15/2026 4:04 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] iommu: bounds check uses PAGE_SIZE while allocation uses SZ_4K
--

commit 4edc662d667d9a3f034b902dc510d5238c7c24a5
Author: Lu Baolu<[email protected]>

iommu/vt-d: Add helpers to set up and tear down TDX extensions

This commit implements per-IOMMU TDX Connect bring-up and tear-down helpers. It allocates and populates the IOMMU_MT parameter layout required by TDH.IOMMU.SETUP, and handles initialization completion and rollback.

Quoted 4 lines
drivers/iommu/intel/tdxc.c +0 -0
index 559c752a15273..b5dfdeeb23dba 100644

[ ... ]

Quoted 11 lines

drivers/iommu/intel/tdxc.c line 103

Quoted 7 lines
drivers/iommu/intel/tdxc.c +7 -0
+static struct tdxc_pages *tdxc_alloc_mt_pages(struct intel_iommu *iommu,
+					      unsigned int nr_mt_pages)
+{
+	unsigned int nr_entries = nr_mt_pages + IQ_BUFFERS_NUM;
+	struct tdxc_pages *array;
+
+	if (!nr_mt_pages || nr_mt_pages > (PAGE_SIZE / sizeof(u64) - IQ_BUFFERS_NUM))

[Severity: Low]
Does this bounds check use the wrong size macro? It restricts nr_mt_pages based on PAGE_SIZE, but the corresponding root array allocation below is hardcoded to SZ_4K. Should this check use SZ_4K to match the allocation size?

I'll use SZ_4K instead of PAGE_SIZE here. The size is fixed at 4KB by the TDX module ABI, so it should not be expressed in terms of the host page size, even though this file is x86-only and PAGE_SIZE == SZ_4K unconditionally. No functional change.

Thanks,
baolu

#10 lore raw
In reply to Lu Baolu
Quoted 23 lines

From: Lu Baolu <[email protected]>
Sent: Tuesday, September 15, 2026 3:42 PM

Hi,

This series adds Intel VT-d trusted extension support to the host Intel IOMMU driver as groundwork for TEE I/O trusted DMA (e.g. TDX Connect).

The trusted extension introduces a parallel, extension-specific path for trusted DMA assets used by confidential device assignment. Existing VT-d functionality remains unchanged for regular host DMA paths.

From the TDX Connect architecture perspective, VT-d is enhanced with:

1) Trusted DMA translation root table
- A second root-table address register, restricted to SEAM SAI.
- Programmed by the TDX module with the root of TDX-managed DMA translation tables for TD-assigned devices.

2) Trusted invalidation queue
- A second invalidation-queue address register plus dedicated head/tail registers, also restricted to SEAM SAI.

Quoted 9 lines

3) IOTLB / DID isolation
- When TDX Connect is enabled, VT-d restricts VMM DID usage and reserves the DID MSB namespace bit for TDX-module use.

This posting focuses on VT-d-side enablement only: it enables those extension-defined resources and control points while preserving existing host VT-d behavior for non-trusted flows. Higher-layer integration (TDX guest/device flows) will be posted separately.

Jason had a comment on this from another thread [1]:

"
Okay, so I saw the driver posting for basic iommu support, can we try to rework that to be split out like Aneesh is doing so everything about TDX calls lives in tsm and intel iommu only provides a small API surface to exchange whatever details are needed to bootstrap TDX module?
"

[1] https://lore.kernel.org/all/[email protected]/

author maintainer
#11 lore raw
Quoted 43 lines · Kevin
Quoted 23 lines

From: Lu Baolu <[email protected]>
Sent: Tuesday, September 15, 2026 3:42 PM

Hi,

This series adds Intel VT-d trusted extension support to the host Intel IOMMU driver as groundwork for TEE I/O trusted DMA (e.g. TDX Connect).

The trusted extension introduces a parallel, extension-specific path for trusted DMA assets used by confidential device assignment. Existing VT-d functionality remains unchanged for regular host DMA paths.

From the TDX Connect architecture perspective, VT-d is enhanced with:

1) Trusted DMA translation root table
- A second root-table address register, restricted to SEAM SAI.
- Programmed by the TDX module with the root of TDX-managed DMA translation tables for TD-assigned devices.

2) Trusted invalidation queue
- A second invalidation-queue address register plus dedicated head/tail registers, also restricted to SEAM SAI.

Quoted 9 lines

3) IOTLB / DID isolation
- When TDX Connect is enabled, VT-d restricts VMM DID usage and reserves the DID MSB namespace bit for TDX-module use.

This posting focuses on VT-d-side enablement only: it enables those extension-defined resources and control points while preserving existing host VT-d behavior for non-trusted flows. Higher-layer integration (TDX guest/device flows) will be posted separately.

Jason had a comment on this from another thread [1]:

"
Okay, so I saw the driver posting for basic iommu support, can we try to rework that to be split out like Aneesh is doing so everything about TDX calls lives in tsm and intel iommu only provides a small API surface to exchange whatever details are needed to bootstrap TDX module?
"

Quoted 1 line

[1] https://lore.kernel.org/all/[email protected]/

Yes, I will head in this direction in the next version.

Thanks,
baolu