[PATCH] Revert "iommu/dma: simplify dma_iova_destroy() and drop the free_iova helper"

Leon Romanovsky leon at kernel.org
Fri Nov 27 07:18:13 PST 2026


On Fri, Nov 27, 2026 at 12:28:16PM +0100, Marek Szyprowski wrote:
> On 25.11.2026 19:34, Leon Romanovsky wrote:
> > On Wed, Nov 25, 2026 at 06:21:06PM +0100, Marek Szyprowski wrote:
> >> On 25.11.2026 14:51, Sibi Sankar wrote:
> >>> This reverts commit 1acce29926d93f3eba427696fe3da6451504dae2.
> >>>
> >>> Before this commit, dma_iova_destroy() unmapped through
> >>> __iommu_dma_iova_unlink(..., free_iova=true), which set
> >>> iotlb_gather.queued from cookie->fq_domain, skipped iommu_iotlb_sync()
> >>> and freed the IOVA with the queued gather, exactly like
> >>> __iommu_dma_unmap(). After it, dma_iova_destroy() calls
> >>> dma_iova_unlink() and then dma_iova_free():
> >>>
> >>>   - dma_iova_unlink() never marks its gather as queued and always calls
> >>>     iommu_iotlb_sync() after iommu_unmap_fast().
> >>>   - dma_iova_free() passes a NULL gather to iommu_dma_free_iova(), so
> >>>     the IOVA goes straight back to the allocator through
> >>>     free_iova_fast() and never through queue_iova().
> >>>
> >>> DMA-FQ domains therefore get strict invalidation on this path. That
> >>> includes the block layer's blk_rq_dma_map() path, which NVMe uses for
> >>> all data transfers, so iommu.strict=0 has no effect on NVMe I/O.
> >>>
> >>> hw/sw details: Qualcomm Glymur CRD: SMMUv3 with no RANGE_INV,
> >>> 	       4K pages; NVMe SSD on PCIe Gen5 x4
> >>>
> >>> Fio sequential read/write numbers:
> >>>   Domain                          seq write    seq read
> >>>   DMA (strict)                    2694 MiB/s   2693 MiB/s
> >>>   DMA-FQ (lazy), flush queue      2707 MiB/s   2803 MiB/s
> >>>     bypassed (this regression)
> >>>   DMA-FQ (lazy), flush queue      10.6 GiB/s   11.9 GiB/s
> >>>     used by dma_iova_destroy()
> >>>
> >>> Fixes: 1acce29926d9 ("iommu/dma: simplify dma_iova_destroy() and drop the free_iova helper")
> >>> Cc: stable at vger.kernel.org # v7.3+
> >>> Signed-off-by: Sibi Sankar <sibi.sankar at oss.qualcomm.com>
> >>
> >> The performance data clearly shows that the flush queue was there for
> >> the reason. Together with this revert it would probably make sense to
> >> apply the v1 of the reverted patch:
> >>
> >> https://lore.kernel.org/all/20260701092033.422867-1-honghuan@amd.com/
> >>
> >> Leon, do You see any other option?
> > These numbers shows clearly that we had iotlb_gather.queued != 0
> > and never performed iommu_iotlb_sync(domain, &iotlb_gather); while
> > destroying mapped IOVA.
> >
> > I agree with you, v1 is the easiest solution, however my preferred one
> > is to cache gather when it is created and keep it in dma_iova_state 
> > structure for whole life cycle of that struct.
> 
> I've played with the code (using LLM ;) and there are some issues with this
> approach:
> 
> 1. tso_dma_map_completion_save() copies the struct dma_iova_state by value,
> what breaks internals of the struct iommu_iotlb_gather.
> 2. adding iommu_iotlb_gather to dma_iova_state increase the struct size
> from 16 to 64 bytes, what lands in every NVMe request, RDMA rw contexts,
> TSO maps and HMM.

I had that idea before AI era and before TSO was converted to use
dma_iova_state. :)

> 
> I've decided to put only the 'use_fq' bit in the __size entry and baked the
> fix. It looks quite nice. This approach solves both above issues, although
> it requires to also fix some drivers which already pokes __size directly
> instead of calling dma_iova_size().
> 
> I will post this in a few minutes.
> 
> Best regards
> -- 
> Marek Szyprowski, PhD
> Samsung R&D Institute Poland
> 



More information about the linux-arm-kernel mailing list