Re: [PATCH v2] iommu: Hold group references across bus_iommu_probe()
From: Peter Chen
Date: Tue Nov 24 2026 - 21:49:32 EST
On 26-11-24 08:49:33, Jason Gunthorpe wrote:
> On Mon, Nov 23, 2026 at 11:09:03PM -0800, Peter Chen wrote:
> > The glue driver does what upstream dwc3-imx8mp.c does in
> > dwc3_imx8mp_probe():
> >
> > of_platform_populate(node, NULL, NULL, dev);
> > pdev = of_find_device_by_node(dwc3_np);
> > dwc = platform_get_drvdata(pdev);
> > if (!dwc) {
> > /* core probe deferred, e.g. its SMMU is not there yet */
> > ret = -EPROBE_DEFER;
> > goto depopulate; /* -> platform_device_unregister() */
> > }
>
> That's not how EPROBE_DEFER is supposed to be handled :(
>
> The driver core is already setup to reprobe the child driver later
> inside of_platform_populate()
>
> Your issue is it is quite wrong to try to synchronously reach into a
> probed driver's like this from outside. Then when it fails tearing
> down the device means you defeat the natural EPROBE_DEFER.
>
> This should be asynchronous, then you won't have ordering problems.
>
Agreed.
> But OK, it is clear how you get into this situation.
Thanks. The iommu core can still see a device disappear during
bus_iommu_probe(), from glue drivers like the one above or from any
other removal, so I'd still like to fix the use-after-free in the
core.
> >
> > Yes, the list head is on the stack, but group->entry is in the
> > shared group. "Is group->entry empty" is the de-dup flag that
> > __iommu_probe_device() tests and sets under group->mutex:
> >
> > if (list_empty(&group->entry))
> > list_add_tail(&group->entry, group_list);
>
> A small comment might help. The lock seems necessary
>
Will do. In v3 I will:
- add a comment in iommu_group_list_put() explaining that
group->entry is the de-dup flag tested and set by
__iommu_probe_device() under group->mutex, and that
bus_iommu_probe() may run concurrently for other IOMMU instances;
- add the real-world scenario (a parent populates a child whose probe
defers on the IOMMU, then depopulates it) to the commit message.
Would you have more comments?
--
Thanks,
Peter Chen