mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Cc: Robin Murphy <robin.murphy@arm.com>,
	Petr Tesarik <petr.tesarik.ext@huawei.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH v2] dma: swiotlb: Properly tear down the default pool on exit
Date: Mon, 16 Nov 2026 11:22:21 +0100	[thread overview]
Message-ID: <09a8aeb6-a62d-4402-93ef-3eb4fcf9a6be@samsung.com> (raw)
In-Reply-To: <20261109170603.385791-1-m.szyprowski@samsung.com>

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@vger.kernel.org
> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

Applied to dma-mapping-fixes.

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


      reply	other threads:[~2026-11-16 10:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20261109170611eucas1p2366f6f6462a0178990e401e35849edd5@eucas1p2.samsung.com>
2026-11-09 17:06 ` Marek Szyprowski
2026-11-16 10:22   ` Marek Szyprowski [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=09a8aeb6-a62d-4402-93ef-3eb4fcf9a6be@samsung.com \
    --to=m.szyprowski@samsung.com \
    --cc=iommu@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=petr.tesarik.ext@huawei.com \
    --cc=robin.murphy@arm.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®