From: Lu Baolu <baolu.lu@linux.intel.com>
To: iommu@lists.linux.dev, x86@kernel.org,
linux-coco@lists.linux.dev, kvm@vger.kernel.org
Cc: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Jason Gunthorpe <jgg@ziepe.ca>, Kevin Tian <kevin.tian@intel.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
Kiryl Shutsemau <kas@kernel.org>,
Rick Edgecombe <rick.p.edgecombe@intel.com>,
yilun.xu@linux.intel.com, xiaoyao.li@intel.com,
Chao Gao <chao.gao@intel.com>,
linux-kernel@vger.kernel.org, Lu Baolu <baolu.lu@linux.intel.com>
Subject: [PATCH 5/5] iommu/vt-d: Reserve MSB of domain ID space for TDX module
Date: Tue, 15 Sep 2026 15:42:33 +0800 [thread overview]
Message-ID: <20260915074235.1219183-6-baolu.lu@linux.intel.com> (raw)
In-Reply-To: <20260915074235.1219183-1-baolu.lu@linux.intel.com>
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.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
drivers/iommu/intel/tdxc.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/intel/tdxc.c b/drivers/iommu/intel/tdxc.c
index b5dfdeeb23db..1ca03257d456 100644
--- a/drivers/iommu/intel/tdxc.c
+++ b/drivers/iommu/intel/tdxc.c
@@ -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)
--
2.43.0
next prev parent reply other threads:[~2026-09-15 7:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 7:42 [PATCH 0/5] iommu/vt-d: Introduce trusted DMA initialization support Lu Baolu
2026-09-15 7:42 ` [PATCH 1/5] x86/virt/tdx: Add SEAMCALL wrappers for IOMMU setup/clear Lu Baolu
2026-09-15 7:42 ` [PATCH 2/5] x86/virt/tdx: Read global metadata for trusted IOMMU Lu Baolu
2026-09-15 7:42 ` [PATCH 3/5] iommu/vt-d: Add interfaces for trusted DMA initialization Lu Baolu
2026-09-15 7:42 ` [PATCH 4/5] iommu/vt-d: Add helpers to set up and tear down TDX extensions Lu Baolu
2026-09-15 8:04 ` sashiko-bot
2026-09-16 8:37 ` Baolu Lu
2026-09-15 7:42 ` Lu Baolu [this message]
2026-09-15 8:11 ` [PATCH 5/5] iommu/vt-d: Reserve MSB of domain ID space for TDX module sashiko-bot
2026-09-16 8:25 ` Baolu Lu
2026-09-18 2:30 ` [PATCH 0/5] iommu/vt-d: Introduce trusted DMA initialization support Tian, Kevin
2026-09-19 4:04 ` Baolu Lu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260915074235.1219183-6-baolu.lu@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=chao.gao@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=kas@kernel.org \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=rick.p.edgecombe@intel.com \
--cc=robin.murphy@arm.com \
--cc=will@kernel.org \
--cc=x86@kernel.org \
--cc=xiaoyao.li@intel.com \
--cc=yilun.xu@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.