Re: [PATCH rc 1/2] iommu: Do not call drivers for empty gathers

Jason Gunthorpe
2026-03-03T13:04:25Z

On Tue, Mar 03, 2026 at 12:53:28PM +0000, Robin Murphy wrote:

> > Further, there are several callers that can trigger empty gathers,
> > especially in unusual conditions. For example iommu_map_nosync() will call
> > a 0 size unmap on some error paths. Also in VFIO, iommupt and other
> > places.
>
> My instinct is still to tidy up the 0-length unmap case(s), but I guess
> iommu_iotlb_sync() is itself also a public API where being more robust
> against erroneous usage is no bad thing.

I also wanted to do that but found enough problematic cases I lost
confidence I could reliably catch them all..

> > - if (domain->ops->iotlb_sync)
> > + if (domain->ops->iotlb_sync &&
> > + likely(iotlb_gather->start < iotlb_gather->end))
>
> Elsewhere we just use "gather->end != 0" as the "non-empty" condition; how
> concerned are we about defending against more-intentionally malformed
> gathers here?

I choose this deliberately to protect the driver, a malformed gather
that is 0 sized, or negative sized looks like it will have Weird
Things happen in drivers.

We could further classify the < and WARN_ON the malformed cases, but I
don't want to pass negative sized gathers into drivers. We'd probably
also have to de-inline the function if more is added. Do you have a
preference?

Jason