Re: [PATCH v2] dma: swiotlb: Properly tear down the default pool on exit
From: Marek Szyprowski
Date: Mon Nov 16 2026 - 05:22:34 EST
On 09.11.2026 18:06, Marek Szyprowski wrote:
> With CONFIG_SWIOTLB_DYNAMIC enabled, the default memory pool is added to
> the io_tlb_default_mem.pools RCU list during initialization. When an IOMMU
> takes over DMA translation, swiotlb_exit() tears the default pool down and
> clears it with memset(), but leaves its node on the pools list. The list
> then contains a zeroed entry with a NULL next pointer, and any later walk
> of the list, for example mem_used() when reading the io_tlb_used debugfs
> file, dereferences an invalid pointer and crashes.
>
> swiotlb_exit() also leaves the io_tlb_default_mem fields that describe
> the pool. io_tlb_default_mem.nslabs and can_grow stay set, so
> is_swiotlb_allocated() and is_swiotlb_active() keep returning true, and
> swiotlb_find_slots() can schedule dynamic pool allocation after teardown.
> Without CONFIG_SWIOTLB_DYNAMIC, a later mapping can reach the zeroed
> defpool and hit BUG_ON(area_index >= pool->nareas). Before the pool data
> was split out of struct io_tlb_mem, swiotlb_exit() cleared the whole
> structure, including nslabs.
>
> Clear can_grow and cancel any pending dyn_alloc work, then remove the
> default pool from the list and subtract its slots from nslabs, and wait
> for an RCU grace period before clearing it, so that no reader can still
> see it. Without CONFIG_SWIOTLB_DYNAMIC, reset nslabs directly.
>
> As a result, with CONFIG_SWIOTLB_DYNAMIC swiotlb no longer silently keeps
> working through dynamic or transient pools after an IOMMU has turned it
> off, so for example dma-iommu bouncing for untrusted devices reports that
> bounce buffers are inactive, as it did before the dynamic pools support.
>
> Fixes: 158dbe9c9a3d ("swiotlb: separate memory pool data from other allocator data")
> Fixes: 62708b2ba405 ("swiotlb: add a flag whether SWIOTLB is allowed to grow")
> Fixes: 1aaa736815eb ("swiotlb: allocate a new memory pool when existing pools are full")
> Closes: https://sashiko.dev/#/bug/linux-f75998aa-65ea-4596-9bb4-fa83773012a3
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Marek Szyprowski <m.szyprowski@xxxxxxxxxxx>
Applied to dma-mapping-fixes.
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland