Re: [PATCH v6 23/24] iommu/amd: Assign per-vIOMMU translate device ID
From: Vasant Hegde
Date: Wed Oct 21 2026 - 06:11:50 EST
On 9/30/2026 2:53 PM, Suravee Suthikulpanit wrote:
> Allocate one translate-device-id per IOMMUFD vIOMMU instance from the
> per-segment pool on init. Reset MMIO first, then program translation
> DTE and VFctrl TransDevID under trans_devid_lock so PCI-probe relocate
> cannot interleave. Clear both on init error and destroy, and drop the
> id before amd_viommu_uninit_one().
>
> Initialize pdom_list before set_translate_dte() so list_empty() is
> valid. Drop the late list_add; set_translate_dte() already publishes
> the vIOMMU on viommu_list under pdom->lock. list_del_init() on init
> error if that add ran.
>
> Free the synthetic translate-device-id DTE object on init error and
> destroy; it is not stored in the per-segment xarray.
>
> Add per-vIOMMU trans_devid_lock to serialize DTE and VFctrl TransDevID
> updates on init and teardown. VFctrl TransDevID is not written from
> amd_viommu_uninit_one().
>
> Destroy trans_devid_lock on init error and on vIOMMU destroy, after
> the last unlock, the same way as vfctrl_lock.
>
> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@xxxxxxx>
> ---
> drivers/iommu/amd/amd_iommu_types.h | 10 +++++
> drivers/iommu/amd/iommufd.c | 68 +++++++++++++++++++++++++----
> 2 files changed, 69 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h
> index 5f84f25e3f37..c748bab27509 100644
> --- a/drivers/iommu/amd/amd_iommu_types.h
> +++ b/drivers/iommu/amd/amd_iommu_types.h
> @@ -556,6 +556,16 @@ struct amd_iommu_viommu {
> /* Synthetic DTE; not stored in pci_seg->dev_data_xa */
> struct iommu_dev_data *trans_dev_data;
>
> + /*
> + * Serializes this vIOMMU's translation DTE and VFctrl TransDevID
> + * updates on init and teardown. VFctrl TransDevID is not written
> + * from amd_viommu_uninit_one().
> + *
> + * Nested lock order: trans_devid_lock, then
> + * pci_seg->trans_devid_mutex.
> + */
> + struct mutex trans_devid_lock;
Do we really need another lock? We already have lock for vfctl update and
allocating traslation device id.
-Vasant