Re: [PATCH v6 05/24] iommu/amd: Allocate Guest IDs for IOMMUFD vIOMMU instances
From: Vasant Hegde
Date: Mon Oct 19 2026 - 07:19:56 EST
On 9/30/2026 2:53 PM, Suravee Suthikulpanit wrote:
> Hardware vIOMMU uses a 16-bit Guest ID (GID) per guest IOMMU to
> index driver and hardware state. Allocate one GID per IOMMUFD vIOMMU
> from a per-amd_iommu IDA (unique within that IOMMU; a VM behind
> multiple IOMMUs may hold more than one GID).
>
> Add amd_iommu_gid_alloc() and amd_iommu_gid_free(), store the ID in
> amd_iommu_viommu::gid, and call them from amd_iommufd_viommu_init()
> and destroy. Initialize gid_ida in init_iommu_one() and destroy it
> in free_iommu_one() with the IOMMU object.
>
> Reject amd_iommufd_viommu_init() with -EOPNOTSUPP when the IOMMU
> does not have AMD_IOMMU_FLAG_VIOMMU_EN.
>
> Reviewed-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@xxxxxxx>
> ---
> drivers/iommu/amd/amd_iommu.h | 4 ++++
> drivers/iommu/amd/amd_iommu_types.h | 7 +++++++
> drivers/iommu/amd/init.c | 2 ++
> drivers/iommu/amd/iommu.c | 16 ++++++++++++++++
> drivers/iommu/amd/iommufd.c | 14 ++++++++++++++
> 5 files changed, 43 insertions(+)
>
> diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h
> index b2ae17e3df34..f6cf412a9820 100644
> --- a/drivers/iommu/amd/amd_iommu.h
> +++ b/drivers/iommu/amd/amd_iommu.h
> @@ -227,4 +227,8 @@ amd_iommu_make_clear_dte(struct iommu_dev_data *dev_data, struct dev_table_entry
> struct iommu_domain *
> amd_iommu_alloc_domain_nested(struct iommufd_viommu *viommu, u32 flags,
> const struct iommu_user_data *user_data);
> +
> +/* Guest ID for vIOMMU */
> +int amd_iommu_gid_alloc(struct amd_iommu *iommu);
> +void amd_iommu_gid_free(struct amd_iommu *iommu, int gid);
How about moving these two functions to iommufd.c as this is vIOMMU specific
functions and not called outside iommufd.c ?
-Vasant