Linux Confidential Computing Development
 help / color / mirror / Atom feed
From: Baolu Lu <baolu.lu@linux.intel.com>
To: "Tian, Kevin" <kevin.tian@intel.com>,
	"iommu@lists.linux.dev" <iommu@lists.linux.dev>,
	"x86@kernel.org" <x86@kernel.org>,
	"linux-coco@lists.linux.dev" <linux-coco@lists.linux.dev>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>
Cc: baolu.lu@linux.intel.com, Jason Gunthorpe <jgg@ziepe.ca>,
	Kiryl Shutsemau <kas@kernel.org>,
	"Edgecombe, Rick P" <rick.p.edgecombe@intel.com>,
	"yilun.xu@linux.intel.com" <yilun.xu@linux.intel.com>,
	"Li, Xiaoyao" <xiaoyao.li@intel.com>,
	"Gao, Chao" <chao.gao@intel.com>,
	Binbin Wu <binbin.wu@linux.intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 4/9] iommu/vt-d: Add interface for tdx-host when enabling trusted DMA
Date: Thu, 26 Nov 2026 07:33:39 +0800	[thread overview]
Message-ID: <d9eb3700-ab16-4471-9814-00c62d4602c8@linux.intel.com> (raw)
In-Reply-To: <CO1PR11MB4835EB7D858CC6C8A20F0E148C432@CO1PR11MB4835.namprd11.prod.outlook.com>

On 11/25/2026 11:29 AM, Tian, Kevin wrote:
>> From: Lu Baolu <baolu.lu@linux.intel.com>
>> 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.

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.

> 
>> @@ -689,6 +690,8 @@ struct intel_iommu {
>>   	u64		ecmdcap[DMA_MAX_NUM_ECMDCAP];
>>   	u32		gcmd; /* Holds TE, EAFL. Don't need SRTP, SFL, WBF
>> */
>>   	raw_spinlock_t	register_lock; /* protect register handling */
>> +	/* Acquired for the TDX module. Protected by register_lock. */
>> +	bool		tdxc_acquired;
> 
> "for the TDX module" or "for the TDX mode"?

The TDX mode. Will fix it.

> 
> s/tdxc_acquired/tdx_acquired/

Sure.

> 
>> @@ -47,9 +47,32 @@ struct dmar_drhd_unit {
>>   	u8	ignored:1; 		/* ignore drhd		*/
>>   	u8	include_all:1;
>>   	u8	gfx_dedicated:1;	/* graphic dedicated	*/
>> +	struct mutex tdxc_lock;		/* serializes acquire/release */
> 
> s/tdxc_lock/tdx_lock/

Sure.

> 
>>   	struct intel_iommu *iommu;
>>   };
>>
>> +/*
>> + * struct dmar_tdxc_params - IOMMU information for driving
>> TDH.IOMMU.*
>> + * @reg_base_addr: Register base address of the IOMMU. The TDX module
>> + *		   identifies an IOMMU by it.
>> + * @node: NUMA node of the IOMMU, for allocating the TDX module's
>> + *	  metadata pages local to it.
>> + * @drhd: VT-d internal handle; the caller must not dereference it. It
>> + *	  stays valid for the lifetime of the system because TDX
>> + *	  Connect-capable units are never hot-removed.
> 
> what will happen if the caller deferences it?

This will be dropped as discussed.

> 
>> @@ -2518,3 +2548,158 @@ bool dmar_platform_optin(void)
>>   	return ret;
>>   }
>>   EXPORT_SYMBOL_GPL(dmar_platform_optin);
> 
> code starting here better fits in iommu.c?

See above.

> 
>> +
>> +static void dmar_tdxc_fill_params(struct dmar_drhd_unit *drhd,
>> +				  struct dmar_tdxc_params *params)
>> +{
>> +	params->reg_base_addr = drhd->reg_base_addr;
>> +	params->node = drhd->iommu->node;
>> +	/*
>> +	 * params->drhd stays valid because trusted DMA-capable units are
>> +	 * never hot-removed.
> 
> hmm now the 4th term for IOMMU...

This comment is gone as discussed.

> 
>> +/*
>> + * dmar_tdxc_acquire() - Acquire an IOMMU for TDH.IOMMU.SETUP
>> + * @dev: PCI device that will use trusted DMA
>> + * @params: Returned by dmar_tdxc_get_params() for @dev
>> + *
>> + * Call this right before issuing TDH.IOMMU.SETUP for the first user of
>> + * the IOMMU. On success, the caller must issue TDH.IOMMU.SETUP and
>> call
> 
> why defining the caller behavior here? what would happen if the caller
> just calls acquire()/release() w/o doing any SEAMCALL in between?

Nothing breaks. release() just undoes what acquire() did. You're right
that the interface shouldn't define the caller's behavior.

> 
>> + * dmar_tdxc_release() if it fails. The caller owns the per-IOMMU refcount
>> + * and must serialize all calls for the same IOMMU.
> 
> this function already serializes internally. What is the rationale asking for
> extra serialization in the caller?

None, it isn't needed. I'll describe what acquire() and release() do to
the IOMMU, and drop the requirements on the caller.

> 
>> + *
>> + * Return: 0 on success and error code on failure.
>> + */
>> +int dmar_tdxc_acquire(struct pci_dev *pdev,
>> +		      const struct dmar_tdxc_params *params)
>> +{
>> +	struct dmar_drhd_unit *drhd = params->drhd;
>> +	struct intel_iommu *iommu = drhd->iommu;
>> +	int ret;
>> +
>> +	if (WARN_ON(dmar_tdxc_find_drhd(pdev) != drhd))
>> +		return -EINVAL;
>> +
>> +	guard(mutex)(&drhd->tdxc_lock);
>> +	/* Still set if TDH.IOMMU.CLEAR failed and tdx-host was reloaded. */
>> +	if (iommu->tdxc_acquired)
>> +		return -EBUSY;
> 
> what does "tdx-host was reloaded" actually mean?

It's stale. After a failed TDH.IOMMU.CLEAR, the flag stays set and the
next acquire() fails, whether or not tdx-host is reloaded. I'll reword
it to:

	/* Still set if a previous TDH.IOMMU.CLEAR failed. */

> 
>> +
>> +	/*
>> +	 * TDH.IOMMU.SETUP requires DMA translation, queued invalidation
>> and
>> +	 * scalable mode to be enabled. Catch these here so the error is
> 
> Remove the 1st sentence as it is explained by the code.

Will do.

>> +	 * -EINVAL rather than an opaque TDX_IOMMU_INVALID_STATE.
>> +	 */
>> +	if (!(iommu->gcmd & DMA_GCMD_TE) || !iommu->qi
>> || !sm_supported(iommu))
>> +		return -EINVAL;
>> +

Thanks,
baolu

  reply	other threads:[~2026-11-25 23:33 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  4:30 [PATCH v3 0/9] coco/tdx-host: Introduce trusted DMA initialization support Lu Baolu
2026-11-12  4:30 ` [PATCH v3 1/9] x86/virt/tdx: Add SEAMCALL wrappers for IOMMU setup/clear Lu Baolu
2026-11-18 11:02   ` Binbin Wu
2026-11-23  4:03     ` Baolu Lu
2026-11-23  9:55   ` Xu Yilun
2026-11-24  5:46     ` Baolu Lu
2026-11-24  8:07   ` Tian, Kevin
2026-11-25  2:47     ` Baolu Lu
2026-11-25  3:08       ` Tian, Kevin
2026-11-25  4:26         ` Baolu Lu
2026-11-12  4:30 ` [PATCH v3 2/9] x86/virt/tdx: Read global metadata for trusted IOMMU Lu Baolu
2026-11-18 13:39   ` Binbin Wu
2026-11-23  4:09     ` Baolu Lu
2026-11-24  8:13       ` Tian, Kevin
2026-11-25  2:57         ` Baolu Lu
2026-11-12  4:30 ` [PATCH v3 3/9] x86/virt/tdx: Export Dynamic PAMT helpers to tdx-host Lu Baolu
2026-11-23 10:25   ` Xu Yilun
2026-11-23 16:28     ` Edgecombe, Rick P
2026-11-24  6:07       ` Baolu Lu
2026-11-12  4:30 ` [PATCH v3 4/9] iommu/vt-d: Add interface for tdx-host when enabling trusted DMA Lu Baolu
2026-11-23 15:08   ` Xu Yilun
2026-11-24  7:47     ` Baolu Lu
2026-11-25  3:32       ` Tian, Kevin
2026-11-25  3:29   ` Tian, Kevin
2026-11-25 23:33     ` Baolu Lu [this message]
2026-11-12  4:30 ` [PATCH v3 5/9] iommu/vt-d: Block GCMD and ECMD while acquired by the TDX module Lu Baolu
2026-11-25  3:49   ` Tian, Kevin
2026-11-26  2:10     ` Baolu Lu
2026-11-12  4:30 ` [PATCH v3 6/9] iommu/vt-d: Refuse system suspend " Lu Baolu
2026-11-25  4:01   ` Tian, Kevin
2026-11-25  6:27     ` Baolu Lu
2026-11-12  4:30 ` [PATCH v3 7/9] coco/tdx-host: Add skeleton to support PCI link encryption Lu Baolu
2026-11-18  7:16   ` Chao Gao
2026-11-23  3:30     ` Baolu Lu
2026-11-23 15:26       ` Xu Yilun
2026-11-25  2:24         ` Baolu Lu
2026-11-19  2:52   ` Binbin Wu
2026-11-23  4:18     ` Baolu Lu
2026-11-23 15:43       ` Xu Yilun
2026-11-12  4:30 ` [PATCH v3 8/9] coco/tdx-host: Rename tdx-host.c to main.c Lu Baolu
2026-11-12  4:30 ` [PATCH v3 9/9] coco/tdx-host: Enable trusted DMA on IOMMUs on device connect Lu Baolu
2026-11-18  8:11   ` Chao Gao
2026-11-23  4:51     ` 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=d9eb3700-ab16-4471-9814-00c62d4602c8@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=binbin.wu@linux.intel.com \
    --cc=chao.gao@intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@ziepe.ca \
    --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=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox