Re: [PATCH 15/24] iommu/amd: Add helper functions to manage DevID / DomID mapping tables

From: Suthikulpanit, Suravee

Date: Wed Sep 02 2026 - 20:41:37 EST




On 8/19/2026 8:30 PM, guanghuifeng@xxxxxxxxxxxxxxxxx wrote:
diff --git a/drivers/iommu/amd/viommu.c b/drivers/iommu/amd/viommu.c
index 2c1a267826dc..91d0dd3ac912 100644
--- a/drivers/iommu/amd/viommu.c
+++ b/drivers/iommu/amd/viommu.c
@@ -26,6 +26,20 @@

...

+int amd_viommu_init_one(struct amd_iommu *iommu, struct amd_iommu_viommu *viommu)
+{
+    int ret;
+
+    ret = alloc_private_vm_region(iommu, &viommu->devid_table,
+                      VIOMMU_DEVID_MAPPING_BASE,
+                      VIOMMU_DEVID_MAPPING_ENTRY_SIZE,
+                      viommu->gid);
+    if (ret)
+        goto err_out;
+
+    ret = alloc_private_vm_region(iommu, &viommu->domid_table,
+                      VIOMMU_DOMID_MAPPING_BASE,
+                      VIOMMU_DOMID_MAPPING_ENTRY_SIZE,
+                      viommu->gid);
+    if (ret)
+        goto err_out;
+
+    return 0;
+err_out:
+    amd_viommu_uninit_one(iommu, viommu);
+    return -ENOMEM;
+}

The err_out label overwrites the real error with -ENOMEM.
alloc_private_vm_region() (via viommu_priv_alloc_map()) can also
return -EINVAL when the pdom is not set up, and that information
gets lost on the way to iommufd. Please just "return ret;" here.

Ok. I'll fix this in v5.

Thanks,
Suravee