Re: [PATCH 4/4] iommu/dma: restore flush queue use in dma_iova_destroy()

From: Jason Gunthorpe

Date: Fri Nov 27 2026 - 10:17:44 EST


On Fri, Nov 27, 2026 at 03:45:15PM +0100, Marek Szyprowski wrote:
> On 27.11.2026 15:37, Jason Gunthorpe wrote:

> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> index 0e329ecd7dfa..106da975bf0f 100644
> --- a/drivers/iommu/dma-iommu.c
> +++ b/drivers/iommu/dma-iommu.c
> @@ -1892,11 +1892,12 @@ static void __dma_iova_free(struct device *dev, struct dma_iova_state *state,
>   */
>  void dma_iova_free(struct device *dev, struct dma_iova_state *state)
>  {
> -       struct iommu_iotlb_gather iotlb_gather;
> -
> -       iommu_iotlb_gather_init(&iotlb_gather);
> -       iotlb_gather.queued = state->__size & DMA_IOVA_USE_FQ;
> -       __dma_iova_free(dev, state, &iotlb_gather);
> +       /*
> +        * Nothing is linked any more and every dma_iova_unlink() has already
> +        * invalidated the IOTLB synchronously, so there is no deferred
> +        * invalidation to wait for and the IOVA can be reused right away.
> +        */
> +       __dma_iova_free(dev, state, NULL);
>  }
>  EXPORT_SYMBOL_GPL(dma_iova_free);

That makes sense, but I'm a little lost why we needed the
DMA_IOVA_USE_FQ ?

If any queued gather was ever created then the ultimate free has to
also be queued. But the comment implies that queued gathers were never
created in this case?

> @@ -2190,12 +2191,13 @@ void dma_iova_destroy(struct device *dev, struct dma_iova_state *state,
>         struct iommu_iotlb_gather iotlb_gather;
>
>         iommu_iotlb_gather_init(&iotlb_gather);
> -       iotlb_gather.queued = state->__size & DMA_IOVA_USE_FQ;
>
>         /*
>          * We can be here if the first call to dma_iova_link() failed and
> -        * there is nothing to unlink, so let's be more clear.
> +        * there is nothing to unlink, so let's be more clear. Only queue the
> +        * gather if there is an unmap whose invalidation can be deferred.
>          */

Not sure what this comment means now? What invalidation cannot be deferred?

> +       iotlb_gather.queued = mapped_len && (state->__size & DMA_IOVA_USE_FQ);
>         if (mapped_len)

I'd probably put it inside the if..

Jason