]> Gentwo Git Trees - linux/.git/commitdiff
iommu: Do not revert set_domain for the last gdev
authorNicolin Chen <nicolinc@nvidia.com>
Thu, 23 Oct 2025 02:21:08 +0000 (19:21 -0700)
committerJoerg Roedel <joerg.roedel@amd.com>
Mon, 27 Oct 2025 12:55:35 +0000 (13:55 +0100)
The last gdev is the device that failed the __iommu_device_set_domain().
So, it doesn't need to be reverted, given it's attached to group->domain
already.

This is not a problem currently, since it's a simply re-attach. However,
the core will need to pass in the old domain to __iommu_device_set_domain
so the old domain pointers would be inconsistent between a failed device
and all its prior succeeded devices, as all the prior devices need to be
reverted.

Avoid the re-attach for the last gdev, by breaking before the revert.

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
drivers/iommu/iommu.c

index adef1a37f9311284a2156c14f3d7b147e5adfaea..ce141f095f969e641b9aeada0ea39ac05024dc24 100644 (file)
@@ -2403,6 +2403,9 @@ static int __iommu_group_set_domain_internal(struct iommu_group *group,
         */
        last_gdev = gdev;
        for_each_group_device(group, gdev) {
+               /* No need to revert the last gdev that failed to set domain */
+               if (gdev == last_gdev)
+                       break;
                /*
                 * A NULL domain can happen only for first probe, in which case
                 * we leave group->domain as NULL and let release clean
@@ -2412,8 +2415,6 @@ static int __iommu_group_set_domain_internal(struct iommu_group *group,
                        WARN_ON(__iommu_device_set_domain(
                                group, gdev->dev, group->domain,
                                IOMMU_SET_DOMAIN_MUST_SUCCEED));
-               if (gdev == last_gdev)
-                       break;
        }
        return ret;
 }