Re: [PATCH v2 13/26] iommu/amd: Add helper functions to manage DevID / DomID mapping tables

From: Suthikulpanit, Suravee

Date: Sun Jun 28 2026 - 23:25:20 EST




On 5/31/2026 4:26 AM, Weinan Liu wrote:
On Wed, May 27, 2026 at 10:19 PM Suravee Suthikulpanit <suravee.suthikulpanit@xxxxxxx> wrote:

diff --git a/drivers/iommu/amd/iommufd.c b/drivers/iommu/amd/iommufd.c
index 42307ae71b24..efa9e1f49550 100644
--- a/drivers/iommu/amd/iommufd.c
+++ b/drivers/iommu/amd/iommufd.c
@@ -83,6 +83,10 @@ int amd_iommufd_viommu_init(struct iommufd_viommu *viommu, struct iommu_domain *
        /* Reset vIOMMU MMIOs to initialize the vIOMMU */
        iommu_reset_vmmio(iommu, aviommu->gid);

+       ret = amd_viommu_init_one(iommu, aviommu);
+       if (ret)
+               goto err_init;
+
        ret = iommu_copy_struct_to_user(user_data, &data,
                                        IOMMU_VIOMMU_TYPE_AMD,
                                        reserved);
@@ -120,6 +124,7 @@ static void amd_iommufd_viommu_destroy(struct iommufd_viommu *viommu)
        if (aviommu->vfmmio_mmap_offset)
                iommufd_viommu_destroy_mmap(&aviommu->core, aviommu->vfmmio_mmap_offset);
        amd_iommu_gid_free(iommu, aviommu->gid);
+       amd_viommu_uninit_one(iommu, aviommu);
 }

The finalization order should be the reverse of the initialization order.

If amd_iommu_gid_free() is called before amd_viommu_uninit_one(), the gid could be reallocated to a new
vIOMMU instance before the cleanup is complete.
Please consider moving amd_viommu_uninit_one() before the GID free call.


Thanks. I'll take care of this in V3.
Suravee