RE: [PATCH v4 16/17] iommu: Remove __iommu_group_for_each_dev()

Tian, Kevin
2023-04-20T08:06:23Z

> From: Jason Gunthorpe <jgg@nvidia.com>
> Sent: Wednesday, April 12, 2023 9:52 PM
>
> @@ -1858,7 +1843,15 @@ int bus_iommu_probe(struct bus_type *bus)
> return ret;
> }
> mutex_unlock(&group->mutex);
> - __iommu_group_dma_finalize(group);
> +
> + /*
> + * Mis-locked because the ops->probe_finalize() call-back of

I guess this comment is trying to explain why the following code is
executed out of lock. In that case it reads clearer to me to start
with "Avoid mis-lock ..." and put it before mutex_unlock().

> + * some IOMMU drivers calls arm_iommu_attach_device()
> which
> + * in-turn might call back into IOMMU core code, where it
> tries
> + * to take group->mutex, resulting in a deadlock.
> + */
> + for_each_group_device(group, gdev)
> + iommu_group_do_probe_finalize(gdev->dev);
> }
>
> return 0;
> @@ -2999,8 +2992,12 @@ static ssize_t iommu_group_store_type(struct
> iommu_group *group,
> mutex_unlock(&group->mutex);
>
> /* Make sure dma_ops is appropriatley set */

while at it, s/appropriatley/appropriately/

> - if (!ret)
> - __iommu_group_dma_finalize(group);
> + if (!ret) {
> + struct group_device *gdev;
> +
> + for_each_group_device(group, gdev)
> + iommu_group_do_probe_finalize(gdev->dev);
> + }
>
> return ret ?: count;
> }

Reviewed-by: Kevin Tian <kevin.tian@intel.com>