Re: [PATCH v2 4/4] coco/tdx-host: Initialize trusted DMA on all capable IOMMUs
From: Chao Gao
Date: Mon Oct 19 2026 - 03:05:40 EST
>+static int tdx_iommu_setup(struct dmar_drhd_unit *drhd)
>+{
>+ const struct tdx_sys_info *tdx_sysinfo = tdx_get_sysinfo();
>+ unsigned int mt_page_count = tdx_sysinfo->tdx_connect.iommu_mt_page_count;
>+ struct tdx_iommu_state *state;
>+ u64 r, tdx_iommu_id;
>+ int ret;
>+
>+ struct tdx_iommu_state *iommu_state __free(kfree) = kzalloc_obj(*iommu_state);
>+ if (!iommu_state)
>+ return -ENOMEM;
>+
>+ struct tdx_iommu_pages *iommu_mt __free(free_mt_pages) =
>+ tdx_iommu_alloc_mt_pages(drhd, mt_page_count);
>+ if (!iommu_mt)
>+ return -ENOMEM;
>+
>+ r = tdh_iommu_setup(drhd->reg_base_addr, iommu_mt->root, &tdx_iommu_id);
Dynamic PAMT was merged in 7.3. With it enabled, the PAMT for 4K pages
is no longer allocated up front, and the kernel must add PAMT backing
before giving a page to the TDX module. So, the IQ buffers and the metadata
pages need tdx_pamt_get() before TDH.IOMMU.SETUP and tdx_pamt_put() after
TDH.IOMMU.CLEAR hands them back.