Re: [PATCH 05/22] iommu/amd: Introduce vIOMMU Guest-ID (GID)

Weinan Liu
2026-04-07T07:01:49Z

On Mon, Mar 30, 2026 at 1:43 AM Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> wrote:

> diff --git a/drivers/iommu/amd/iommufd.c b/drivers/iommu/amd/iommufd.c
> index e7ffa7e8915b..6fba5d9b1310 100644
> --- a/drivers/iommu/amd/iommufd.c
> +++ b/drivers/iommu/amd/iommufd.c
> @@ -43,13 +43,35 @@ size_t amd_iommufd_get_viommu_size(struct device *dev, enum iommu_viommu_type vi
>  int amd_iommufd_viommu_init(struct iommufd_viommu *viommu, struct iommu_domain *parent,
>                             const struct iommu_user_data *user_data)
>  {
> +       aviommu->gid = amd_iommu_gid_alloc();
Since the gid is defined as a u16, the return value from amd_iommu_gid_alloc() will cast any negative
error codes to a large positive value.
> +       if (aviommu->gid < 0)
> +               return aviommu->gid;