[PATCH 1/5] dma-coherent: serialize reserved memory pool initialization

From: Marek Szyprowski

Date: Mon Oct 26 2026 - 06:01:08 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: Marek Szyprowski <m.szyprowski@xxxxxxxxxxx>
---
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