Subject: Re: [PATCH v2] iommu: Always fill in gather when unmapping

From: Jason Gunthorpe <[email-masked]>
Date: Thu, 2 Apr 2026 13:51:23 -0300

On Thu, Apr 02, 2026 at 04:59:29PM +0100, Robin Murphy wrote:
> > @@ -666,9 +666,22 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data,
> >   		/* Clear the remaining entries */
> >   		__arm_lpae_clear_pte(ptep, &iop->cfg, i);
> > -		if (gather && !iommu_iotlb_gather_queued(gather))
> > -			for (int j = 0; j < i; j++)
> > -				io_pgtable_tlb_add_page(iop, gather, iova + j * size, size);
> > +		if (gather && !iommu_iotlb_gather_queued(gather)) {
> > +			if (iop->cfg.tlb && iop->cfg.tlb->tlb_add_range) {
> > +				iop->cfg.tlb->tlb_add_range(gather, iova,
> > +							    i * size, size,
> > +							    iop->cookie);
> > +
> > +			} else {
> > +				iommu_iotlb_gather_add_range(gather, iova,
> > +							     i * size);
> > +
> > +				for (int j = 0; j < i; j++)
> > +					io_pgtable_tlb_add_page(iop, gather,
> > +								iova + j * size,
> > +								size);
> > +			}
> > +		}
> 
> NAK, this is insane.

This quite an optimization for SMMUv3 so it doesn't have to fit into
the ill fitting add_page api. What is "insane" here?

> If you'd rather make gathers mandatory for all drivers than fix it in the
> core code, then for goodness' sake just add the trivial one-liner to the
> handful of .unamp_pages implementations which need it, 

Do I understand this right, you want to not touch io-pgtable and
instead the unmap trampolines will fix the gather like mkt is doing?

Jason