]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
iommu/dma: Do not try to iommu_map a 0 length region in swiotlb
authorJason Gunthorpe <jgg@nvidia.com>
Mon, 8 Jun 2026 18:10:04 +0000 (15:10 -0300)
committerMarek Szyprowski <m.szyprowski@samsung.com>
Tue, 9 Jun 2026 20:23:42 +0000 (22:23 +0200)
commit6ec91df8aff77e2e8fe3179c1f3fc15b43a40ba3
tree723138071ad58605d0727d924665e7f3867ca54a
parent9bfaa86b405381326c971984fd6da184c289713f
iommu/dma: Do not try to iommu_map a 0 length region in swiotlb

iommu_dma_iova_link_swiotlb() processes a mapping that is unaligned in three
parts, the head, middle and trailer. If the middle is empty because there
are no aligned pages it will call down to iommu_map() with a 0 size
which the iommupt implementation will fail as illegal.

It then tries to do an error unwind and starts from the wrong spot
corrupting the mapping so the eventual destruction triggers a WARN_ON.

Check for 0 length and avoid mapping and use offset not 0 as the starting
point to unlink.

This is frequently triggered by using some kinds of thunderbolt NVMe
drives that trigger forced SWIOTLB for unaligned memory. NVMe seems to
pass in oddly aligned buffers for the passthrough commands from smartctl
that hit this condition.

Cc: stable@vger.kernel.org
Fixes: 433a76207dcf ("dma-mapping: Implement link/unlink ranges API")
Reported-by: Mark Lord <mlord@pobox.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Reviewed-by: Samiullah Khawaja <skhawaja@google.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://lore.kernel.org/r/0-v1-8536728bc89f+469-swiotlb_warn_jgg@nvidia.com
drivers/iommu/dma-iommu.c