Re: [PATCH] iommu/dma: free the entire IOVA reservation in dma_iova_destroy()

From: Leon Romanovsky

Date: Wed Jul 01 2026 - 15:10:43 EST


On Wed, Jul 01, 2026 at 05:20:33PM +0800, Honglei Huang wrote:
> dma_iova_try_alloc() reserves IOVA for the whole requested size and
> records it in state->__size, but callers may subsequently link only a
> part of that reservation, for example the drm_gpusvm mixed range case,
> where a device page range is linked incrementally.
>
> The doc for dma_iova_destroy() is:
>
> "Unlink the IOVA range up to @mapped_len and free the entire IOVA
> space."
>
> However __iommu_dma_iova_unlink() computed the amount of IOVA to free
> from @mapped_len rather than from the full reservation. When the
> reservation is larger than the linked length, the tail
> [mapped_len, reserved size] is never returned to the allocator and
> is leaked, contrary to the documented contract.
>
> Free the whole reservation using dma_iova_size(), mirroring
> dma_iova_free(). The unmap step still operates on @mapped_len only, and
> the same iotlb_gather is reused so a single IOTLB flush is performed.
>
> Fixes: 433a76207dcf ("dma-mapping: Implement link/unlink ranges API")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Honglei Huang <honghuan@xxxxxxx>
> ---
> drivers/iommu/dma-iommu.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>

Thanks,
Reviewed-by: Leon Romanovsky <leonro@xxxxxxxxxx>