Re: [PATCH v2 18/26] iommu/amd: Add translation DTE and VFctrl TransDevID helpers

From: Jason Gunthorpe

Date: Mon Jun 01 2026 - 09:31:58 EST


On Thu, May 28, 2026 at 05:17:30AM +0000, Suravee Suthikulpanit wrote:

> +void amd_iommu_set_translate_dte(struct amd_iommu *iommu, u16 gid,
> + struct protection_domain *pdom,
> + u32 devid)
> +{
> + u64 tmp0 = 0ULL, tmp1 = 0ULL;
> + struct pt_iommu_amdv1_hw_info pt_info;
> + struct dev_table_entry *dev_table = get_dev_table(iommu);
> +
> + pt_iommu_amdv1_hw_info(&pdom->amdv1, &pt_info);
> +
> + pr_debug("%s: gid=%#x, iommu_devid=%#x, devid=%#x, host_pt_root=%#llx, mode=%#x\n",
> + __func__, gid, iommu->devid, devid, pt_info.host_pt_root, pt_info.mode);
> +
> + /* Setup DTE for v1 page table at the offset specified by devid */
> + tmp0 |= FIELD_PREP(DTE_HOST_TRP, pt_info.host_pt_root >> 12);
> + tmp0 |= FIELD_PREP(DTE_MODE_MASK, pt_info.mode);
> + tmp0 |= (DTE_FLAG_IR | DTE_FLAG_IW | DTE_FLAG_TV | DTE_FLAG_V);
> + tmp1 |= FIELD_PREP(DTE_DOMID_MASK, pdom->id);
> +
> + dev_table[devid].data[0] = tmp0;
> + dev_table[devid].data[1] = tmp1;

Please stop editing DTEs in place.

This looks like it is writing some otherwise unused DTE, it should
fully initialize it and use the normal flow to write it.

Jason