[PATCH v3 1/5] iommu: Lock group->mutex in iommu_deferred_attach

Tian, Kevin kevin.tian at intel.com
Fri Aug 15 01:27:17 PDT 2025


> From: Baolu Lu <baolu.lu at linux.intel.com>
> Sent: Friday, August 15, 2025 1:10 PM
> 
> On 8/12/25 06:59, Nicolin Chen wrote:
> >
> > +	/*
> > +	 * This is called on the dma mapping fast path so avoid locking. This is
> > +	 * racy, but we have an expectation that the driver will setup its
> DMAs
> 
> Why not making it like this,
> 
> int iommu_deferred_attach(struct device *dev, struct iommu_domain
> *domain)
> {
>          /* Caller must be a probed driver on dev */
>          if (!dev->iommu_group)
>                  return 0;
> 
>          guard(mutex)(&dev->iommu_group->mutex);
>          if (!dev->iommu->attach_deferred)
>                  return 0;
> 
>          return __iommu_attach_device(domain, dev);
> }
> 

As the comment said it's the fast path so avoid locking. your way
implies that every map call needs to acquire the group mutex.



More information about the Linux-mediatek mailing list