From: Marek Szyprowski <m.szyprowski@samsung.com>
To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
Robin Murphy <robin.murphy@arm.com>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
Claire Chang <tientzu@chromium.org>,
stable@vger.kernel.org
Subject: [PATCH 2/5] dma: swiotlb: Serialize restricted DMA pool initialization
Date: Mon, 26 Oct 2026 10:54:13 +0100 [thread overview]
Message-ID: <20261026095423.966856-3-m.szyprowski@samsung.com> (raw)
In-Reply-To: <20261026095423.966856-1-m.szyprowski@samsung.com>
Multiple devices can share the same restricted DMA pool, in which case
the io_tlb_mem structure is allocated and initialized by the first
device attached to it and stored in rmem->priv. To avoid the potential
race, serialize the check and initialization of rmem->priv with a mutex.
Fixes: 0b84e4f8b793 ("swiotlb: Add restricted DMA pool initialization")
Closes: https://sashiko.dev/#/bug/linux-6fda7589-591d-4a68-b6e1-b1561f867319
Cc: stable@vger.kernel.org
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
kernel/dma/swiotlb.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 2c57b49ac7c0..db731f7891b7 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -35,6 +35,7 @@
#include <linux/init.h>
#include <linux/memblock.h>
#include <linux/mm.h>
+#include <linux/mutex.h>
#include <linux/pfn.h>
#include <linux/rculist.h>
#include <linux/scatterlist.h>
@@ -1986,10 +1987,12 @@ void swiotlb_free_from_pool(struct device *dev,
swiotlb_release_slots(dev, tlb_addr, pool);
}
+static DEFINE_MUTEX(rmem_swiotlb_mutex);
+
static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
struct device *dev)
{
- struct io_tlb_mem *mem = rmem->priv;
+ struct io_tlb_mem *mem;
unsigned long nslabs = rmem->size >> IO_TLB_SHIFT;
/* Set Per-device io tlb area to one */
@@ -2003,8 +2006,10 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
/*
* Since multiple devices can share the same pool, the private data,
* io_tlb_mem struct, will be initialized by the first device attached
- * to it.
+ * to it. Serialize this, as devices may be probed concurrently.
*/
+ guard(mutex)(&rmem_swiotlb_mutex);
+ mem = rmem->priv;
if (!mem) {
struct io_tlb_pool *pool;
--
2.43.0
next prev parent reply other threads:[~2026-10-26 9:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20261026095434eucas1p29408e916eda327a5e9c83f64b0df4e66@eucas1p2.samsung.com>
2026-10-26 9:54 ` [PATCH 0/5] dma-mapping: assorted sashiko.dev fixes Marek Szyprowski
[not found] ` <CGME20261026095434eucas1p1bb0ac7f1e94bcac196fdc97a0f2c9e9f@eucas1p1.samsung.com>
2026-10-26 9:54 ` [PATCH 1/5] dma-coherent: serialize reserved memory pool initialization Marek Szyprowski
[not found] ` <CGME20261026095435eucas1p1f2245a6982ef110340685dc66be53590@eucas1p1.samsung.com>
2026-10-26 9:54 ` Marek Szyprowski [this message]
[not found] ` <CGME20261026095435eucas1p129baa137891d2e9f5408b47afd6c556c@eucas1p1.samsung.com>
2026-10-26 9:54 ` [PATCH 3/5] dma: swiotlb: Remove default pool from the pools list on exit Marek Szyprowski
[not found] ` <CGME20261026095436eucas1p295baef3daff27873165c70d6d578c1b6@eucas1p2.samsung.com>
2026-10-26 9:54 ` [PATCH 4/5] dma-pool: release CMA pages on atomic_pool_expand() error path Marek Szyprowski
[not found] ` <CGME20261026095436eucas1p1338aced1035d6754d5094555237b6748@eucas1p1.samsung.com>
2026-10-26 9:54 ` [PATCH 5/5] dma-direct: zero memory allocated with DMA_ATTR_NO_KERNEL_MAPPING Marek Szyprowski
2026-11-05 8:03 ` [PATCH 0/5] dma-mapping: assorted sashiko.dev fixes Marek Szyprowski
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=20261026095423.966856-3-m.szyprowski@samsung.com \
--to=m.szyprowski@samsung.com \
--cc=iommu@lists.linux.dev \
--cc=konrad.wilk@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=stable@vger.kernel.org \
--cc=tientzu@chromium.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®