Re: [PATCH rfcv2 6/8] iommu/arm-smmu-v3: Populate smmu_domain->invs when attaching masters

From: Nicolin Chen
Date: Wed Oct 01 2025 - 13:17:17 EST


On Wed, Oct 01, 2025 at 01:25:16PM -0300, Jason Gunthorpe wrote:
> On Tue, Sep 30, 2025 at 01:19:29PM -0700, Nicolin Chen wrote:
> > I see a cleaner way of handling this is to update invs->num_invs
> > inside arm_smmu_invs_unref():
> > ----------------------------------------------------------------
> > @@ -1209,6 +1216,13 @@ size_t arm_smmu_invs_unref(struct arm_smmu_invs *invs,
> > j++;
> > }
> > }
> > +
> > + /* The lock is required to fence concurrent ATS operations. */
> > + write_lock_irqsave(&invs->rwlock, flags);
> > + /* Trim the size by removing tailing trash entries */
> > + WRITE_ONCE(invs->num_invs, num_invs);
> > + write_unlock_irqrestore(&invs->rwlock, flags);
>
> That seems Ok
>
> It means the arm_smmu_invs_unref() becomes the fence that guarentees
> the ATS is stopped for anything marked as trash.
>
> Then the next steps can just be normal RCU and don't need rwlocking.

Yea. The "old" flag could be dropped too:

while (true) {
invs = rcu_dereference(smmu_domain->invs);

/*
* Avoid locking unless ATS is being used. No ATS invalidate can
* be going on after a domain is detached.
*/
locked = false;
- if (invs->has_ats || READ_ONCE(invs->old)) {
+ if (invs->has_ats) {
read_lock(&invs->rwlock);
- if (invs->old) {
- read_unlock(&invs->rwlock);
- continue;
- }
locked = true;
}
break;
}

Thanks
Nicolin