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>,
Andrew Morton <akpm@linux-foundation.org>,
stable@vger.kernel.org
Subject: [PATCH 1/5] dma-coherent: serialize reserved memory pool initialization
Date: Mon, 26 Oct 2026 10:54:12 +0100 [thread overview]
Message-ID: <20261026095423.966856-2-m.szyprowski@samsung.com> (raw)
In-Reply-To: <20261026095423.966856-1-m.szyprowski@samsung.com>
Multiple devices can share the same "shared-dma-pool" reserved memory
region, in which case the dma_coherent_mem structure is created 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: 7bfa5ab6fa1b ("drivers: dma-coherent: add initialization from device tree")
Cc: stable@vger.kernel.org
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
kernel/dma/coherent.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/kernel/dma/coherent.c b/kernel/dma/coherent.c
index 4d0266893bcc..ac62b6bd3d0d 100644
--- a/kernel/dma/coherent.c
+++ b/kernel/dma/coherent.c
@@ -7,6 +7,7 @@
#include <linux/slab.h>
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/mutex.h>
#include <linux/dma-direct.h>
#include <linux/dma-map-ops.h>
@@ -335,10 +336,18 @@ static phys_addr_t dma_reserved_default_memory_base __initdata;
static phys_addr_t dma_reserved_default_memory_size __initdata;
#endif
+static DEFINE_MUTEX(rmem_dma_mutex);
+
static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev)
{
- struct dma_coherent_mem *mem = rmem->priv;
+ struct dma_coherent_mem *mem;
+ /*
+ * Multiple devices can share the same pool and may be probed
+ * concurrently, so serialize the initialization of rmem->priv.
+ */
+ guard(mutex)(&rmem_dma_mutex);
+ mem = rmem->priv;
if (!mem) {
mem = dma_init_coherent_memory(rmem->base, rmem->base,
rmem->size, true);
--
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 ` Marek Szyprowski [this message]
[not found] ` <CGME20261026095435eucas1p1f2245a6982ef110340685dc66be53590@eucas1p1.samsung.com>
2026-10-26 9:54 ` [PATCH 2/5] dma: swiotlb: Serialize restricted DMA pool initialization Marek Szyprowski
[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-2-m.szyprowski@samsung.com \
--to=m.szyprowski@samsung.com \
--cc=akpm@linux-foundation.org \
--cc=iommu@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--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®