Re: [PATCH v4 07/24] iommu: Defer __iommu_group_free_device() to be outside group->mutex

From: Jason Gunthorpe

Date: Tue May 19 2026 - 07:48:04 EST


On Mon, May 18, 2026 at 08:38:50PM -0700, Nicolin Chen wrote:
> __iommu_group_remove_device() holds group->mutex across the entire call to
> __iommu_group_free_device() that performs sysfs removals, tracing, and the
> final kfree(). But in fact, most of these operations don't really need the
> group->mutex.

Are you sure? sysfs requires unique names, and this mutex is providing
a guarentee that will happen. While it shouldn't be possible to race
remove and attach, it is easier to reason about if we don't have to
make this assumption.

> Subsequent changes will introduce sleepable operations to this function:
> + synchronize_rcu() to defer the gdev->dev put past a grace period.

I'm not keen on that at all.

Jason