Re: [PATCH v3 4/9] iommu/vt-d: Add interface for tdx-host when enabling trusted DMA
From: Baolu Lu
Date: Tue Nov 24 2026 - 02:47:35 EST
On 11/23/2026 11:08 PM, Xu Yilun wrote:
Add a per-device interface so that an IOMMU is put into Secure TDX ModeI think tdxc is not a good name since "TDX Connect" is not preferred as
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
a technical term. These APIs would be used by x86/tdx, so can we at
least avoid using tdxc for these APIs?
I'm open to this. I used the dmar_tdxc_* prefix because the VT-d spec
calls this feature "TDX Connect Support". Since these are interfaces for
the tdx-host module, I'm fine with renaming them to dmar_tdx_*.
[...]
+static void dmar_tdxc_fill_params(struct dmar_drhd_unit *drhd,Why we store drhd in the params, any information to expose to TDX via
+ 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.
+ */
+ params->drhd = drhd;
drhd?
[...]
+/*We can get drhd via pci_dev, then why we require callers to input
+ * dmar_tdxc_get_params() - Get the IOMMU information for a device
+ * @dev: PCI device that will use trusted DMA
+ * @params: Filled in on success
+ *
+ * Look up the IOMMU that translates @dev and return what tdx-host needs
+ * to issue TDH.IOMMU.SETUP and TDH.IOMMU.CLEAR on it. This only reads
+ * information and doesn't change any state. Devices behind the same
+ * IOMMU get the same @params->reg_base_addr.
+ *
+ * Return 0 on success and error code on failure.
+ */
+int dmar_tdxc_get_params(struct pci_dev *pdev, struct dmar_tdxc_params *params)
+{
+ struct dmar_drhd_unit *drhd = dmar_tdxc_find_drhd(pdev);
+
+ if (IS_ERR(drhd))
+ return PTR_ERR(drhd);
+
+ dmar_tdxc_fill_params(drhd, params);
+
+ return 0;
+}
+EXPORT_SYMBOL_FOR_MODULES(dmar_tdxc_get_params, "tdx-host");
+
+/*
+ * 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
+ * dmar_tdxc_release() if it fails. The caller owns the per-IOMMU refcount
+ * and must serialize all calls for the same IOMMU.
+ *
+ * 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))
this info and judge? Like an intelligence test?
The drhd was there so the VT-d driver could check that @pdev and @params
match. But you're right that the check only exists because the API takes
both. I'll drop drhd from the params and make acquire()/release() take
only the pci_dev, so there's nothing to mismatch.
Thanks,
baolu