Re: [PATCH v2] iommu: Hold group references across bus_iommu_probe()

From: Jason Gunthorpe

Date: Fri Nov 20 2026 - 15:54:10 EST


> [ ... 9 lines skipped ... ]
> This is the "iommu_bus_notifier() being triggered during
> bus_iommu_probe()" case that commit da33e87bd2bf ("iommu: Handle yet
> another race around registration") left open. The sequence is:
>
> CPU0 (driver's of_platform_populate / of_platform_depopulate() path)
> CPU1 (arm_smmu_device_probe() -> iommu_device_register())
>
> CPU0 CPU1
> of_platform_device_create(T)
> bus_iommu_probe()
> __iommu_probe_device(T)
> allocates group X,
> queues X on group_list
> platform_device_unregister(T)
> iommu_bus_notifier()
> __iommu_group_remove_device(T)
> iommu_group_put(X) -> kfree(X)
> list_del_init(&X->entry)
> <- use-after-free

This seems odd, like shouldn't something outside the iommu subsystem
be serializing these two things? If some driver is calling
of_platform_device_create() and racing it with
platform_device_unregister() it is broken, IMHO.

Can you explain more how this arises in the first place?

> @@ -1951,6 +1955,18 @@ static void iommu_group_do_probe_finalize(struct device *dev)
> ops->probe_finalize(dev);
> }
>
> +static void iommu_group_list_put(struct list_head *group_list)
> +{
> + struct iommu_group *group, *next;
> +
> + list_for_each_entry_safe(group, next, group_list, entry) {
> + mutex_lock(&group->mutex);
> + list_del_init(&group->entry);
> + mutex_unlock(&group->mutex);
> + iommu_group_put(group);

What is the mutex for? The group_list is a stack head so what are we
protecting list del against?

--
Jason