RE: [PATCH v3 4/9] iommu/vt-d: Add interface for tdx-host when enabling trusted DMA
From: Tian, Kevin
Date: Tue Dec 01 2026 - 22:02:55 EST
> From: Baolu Lu <baolu.lu@xxxxxxxxxxxxxxx>
> Sent: Wednesday, December 2, 2026 8:23 AM
>
> On 11/27/2026 3:59 PM, Tian, Kevin wrote:
> >> From: Baolu Lu <baolu.lu@xxxxxxxxxxxxxxx>
> >> Sent: Wednesday, November 25, 2026 4:18 PM
> >>
> >> On 11/25/2026 11:29 AM, Tian, Kevin wrote:
> >>>> From: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
> >>>> Sent: Thursday, November 12, 2026 12:31 PM
> >>>>
> >>>> An Intel IOMMU that supports trusted DMA (ECAP.TDXCS) provides a
> >> second
> >>>> set of DMA translation resources, managed by the TDX module and
> used
> >>>> only for devices assigned to TDs. Before they can be used, the tdx-host
> >>>> driver issues TDH.IOMMU.SETUP to put the IOMMU into Secure TDX
> >> Mode,
> >>>> and
> >>>> issues TDH.IOMMU.CLEAR to take it out again.
> >>>>
> >>>> The VT-d driver owns the hardware state these SEAMCALLs depend on,
> so
> >>>> it checks that state and keeps its own use of the IOMMU out of the TDX
> >>>> module's way. This is cooperation, not enforcement: the TDX module
> >>>> protects trusted DMA regardless, and a misbehaving host can only
> cause
> >>>> failures.
> >>>>
> >>>> Add a per-device interface so that an IOMMU is put into Secure TDX
> Mode
> >>>> only when a device behind it needs trusted DMA. tdx-host tracks how
> >> many
> >>>> devices use each IOMMU and calls into the VT-d driver only for the first
> >>>> and the last of them:
> >>>>
> >>>> - dmar_tdxc_get_params() looks up the DMAR unit translating the
> device
> >>>> and returns its register base address, which is how the TDX module
> >>>> identifies an IOMMU, and its NUMA node, so that tdx-host can
> allocate
> >>>> the TDX module's metadata pages local to that IOMMU.
> >>>>
> >>>> - dmar_tdxc_acquire() is called right before TDH.IOMMU.SETUP. It
> checks
> >>>> the preconditions TDH.IOMMU.SETUP requires (DMA translation,
> >> queued
> >>>> invalidation and scalable mode enabled) and confines the host to the
> >>>> lower half of the domain ID space, since the TDX module owns the
> half
> >>>> with the MSB set.
> >>>>
> >>>> - dmar_tdxc_release() undoes acquire(). tdx-host calls it if
> >>>> TDH.IOMMU.SETUP fails, or after TDH.IOMMU.CLEAR succeeds for
> the
> >> last
> >>>> user. If TDH.IOMMU.CLEAR fails, tdx-host doesn't call it, so the upper
> >>>> half of the domain ID space stays reserved for the TDX module.
> >>>>
> >>>> DMAR units advertising ECAP.TDXCS are excluded from DMAR hotplug.
> No
> >>>> platform currently supports both trusted DMA and DMAR hotplug, so
> that
> >>>> flow can't be validated on hardware. Hot-removing such a unit is also
> >>>> unsafe, because tdx-host may hold a reference to it and the TDX
> module
> >>>> may own its trusted DMA resources. This also keeps the unit handle
> >>>> returned by dmar_tdxc_get_params() valid for the lifetime of the
> system.
> >>>
> >>> Here we used multiple terms (Intel IOMMU, VT-d, DMAR) to talk about
> >>> a same thing. Intel IOMMU and VT-d are interchangeable, commonly
> used
> >>> in many places. But DMAR is more a term in ACPI structure. Better avoid
> >>> it in description, especially in exported interface names.
> >>
> >> Intel IOMMU and VT-d refer to the hardware that the intel-iommu driver
> >> drives. DMAR is the ACPI DMA remapping table, and the term is
> sometimes
> >> used for the remapping hardware units it describes.
> >
> > internally ok, but externally it just adds unnecessary confusion.
>
> Agreed.
>
> >
> >>
> >> The interface here is not an intel-iommu driver interface, since those
> >> should all go through the iommu core. It's exported from the ACPI/DMAR
> >> layer instead, so dmar_tdx_* seems the more fitting name.
> >
> > it's an interface which intel-iommu driver provides to the tsm driver.
> >
> > it's exported from dmar layer because you chose to put it in dmar.c, but
> > really the logic there is about the general iommu object itself at runtime.
>
> It appears not only for the intel-iommu driver; it also affects the
> interrupt remapping code, where the GCMD register is also used to
> control interrupt remapping. Currently, dmar, iommu and interrupt
> remapping are somewhat coupled in the VT-d implementation, but ideally
> they should be independent.
>
yes but the majority part is still about the iommu itself.