* [PATCH v4 1/8] dma: contiguous: Turn heap registration logic around
2026-03-31 10:00 ` [PATCH v4 0/8] dma-buf: heaps: Turn heaps into modules Maxime Ripard
@ 2026-03-31 10:00 ` Maxime Ripard
2026-03-31 10:00 ` [PATCH v4 2/8] dma: contiguous: Make dev_get_cma_area() a proper function Maxime Ripard
` (7 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Maxime Ripard @ 2026-03-31 10:00 UTC (permalink / raw)
To: Sumit Semwal, Benjamin Gaignard, Brian Starkey, John Stultz,
T.J. Mercier, Christian König, Marek Szyprowski,
Robin Murphy, Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko
Cc: Albert Esteve, linux-media, dri-devel, linaro-mm-sig,
linux-kernel, iommu, linux-mm, Maxime Ripard
The CMA heap instantiation was initially developed by having the
contiguous DMA code call into the CMA heap to create a new instance
every time a reserved memory area is probed.
Turning the CMA heap into a module would create a dependency of the
kernel on a module, which doesn't work.
Let's turn the logic around and do the opposite: store all the reserved
memory CMA regions into the contiguous DMA code, and provide an iterator
for the heap to use when it probes.
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
drivers/dma-buf/heaps/cma_heap.c | 19 ++------------
include/linux/dma-buf/heaps/cma.h | 16 ------------
include/linux/dma-map-ops.h | 5 ++++
kernel/dma/contiguous.c | 55 +++++++++++++++++++++++++++++++++++----
4 files changed, 57 insertions(+), 38 deletions(-)
diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c
index bd3370b9a3f6d4e18885a1d0e8ba3f659b85ef47..33cac626da1198e3c4a1cdcd562223c1924b6ceb 100644
--- a/drivers/dma-buf/heaps/cma_heap.c
+++ b/drivers/dma-buf/heaps/cma_heap.c
@@ -12,11 +12,10 @@
#define pr_fmt(fmt) "cma_heap: " fmt
#include <linux/cma.h>
#include <linux/dma-buf.h>
-#include <linux/dma-buf/heaps/cma.h>
#include <linux/dma-heap.h>
#include <linux/dma-map-ops.h>
#include <linux/err.h>
#include <linux/highmem.h>
#include <linux/io.h>
@@ -28,23 +27,10 @@
#include <linux/slab.h>
#include <linux/vmalloc.h>
#define DEFAULT_CMA_NAME "default_cma_region"
-static struct cma *dma_areas[MAX_CMA_AREAS] __initdata;
-static unsigned int dma_areas_num __initdata;
-
-int __init dma_heap_cma_register_heap(struct cma *cma)
-{
- if (dma_areas_num >= ARRAY_SIZE(dma_areas))
- return -EINVAL;
-
- dma_areas[dma_areas_num++] = cma;
-
- return 0;
-}
-
struct cma_heap {
struct dma_heap *heap;
struct cma *cma;
};
@@ -412,22 +398,21 @@ static int __init __add_cma_heap(struct cma *cma, const char *name)
}
static int __init add_cma_heaps(void)
{
struct cma *default_cma = dev_get_cma_area(NULL);
+ struct cma *cma;
unsigned int i;
int ret;
if (default_cma) {
ret = __add_cma_heap(default_cma, DEFAULT_CMA_NAME);
if (ret)
return ret;
}
- for (i = 0; i < dma_areas_num; i++) {
- struct cma *cma = dma_areas[i];
-
+ for (i = 0; (cma = dma_contiguous_get_area_by_idx(i)) != NULL; i++) {
ret = __add_cma_heap(cma, cma_get_name(cma));
if (ret) {
pr_warn("Failed to add CMA heap %s", cma_get_name(cma));
continue;
}
diff --git a/include/linux/dma-buf/heaps/cma.h b/include/linux/dma-buf/heaps/cma.h
deleted file mode 100644
index e751479e21e703e24a5f799b4a7fc8bd0df3c1c4..0000000000000000000000000000000000000000
--- a/include/linux/dma-buf/heaps/cma.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef DMA_BUF_HEAP_CMA_H_
-#define DMA_BUF_HEAP_CMA_H_
-
-struct cma;
-
-#ifdef CONFIG_DMABUF_HEAPS_CMA
-int dma_heap_cma_register_heap(struct cma *cma);
-#else
-static inline int dma_heap_cma_register_heap(struct cma *cma)
-{
- return 0;
-}
-#endif // CONFIG_DMABUF_HEAPS_CMA
-
-#endif // DMA_BUF_HEAP_CMA_H_
diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h
index 60b63756df821d839436618f1fca2bfa3eabe075..c4c93c72ff6ff3ff5c59b7161970805422e9dccb 100644
--- a/include/linux/dma-map-ops.h
+++ b/include/linux/dma-map-ops.h
@@ -97,10 +97,11 @@ static inline struct cma *dev_get_cma_area(struct device *dev)
{
if (dev && dev->cma_area)
return dev->cma_area;
return dma_contiguous_default_area;
}
+struct cma *dma_contiguous_get_area_by_idx(unsigned int idx);
void dma_contiguous_reserve(phys_addr_t addr_limit);
int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
phys_addr_t limit, struct cma **res_cma, bool fixed);
@@ -115,10 +116,14 @@ void dma_contiguous_early_fixup(phys_addr_t base, unsigned long size);
#else /* CONFIG_DMA_CMA */
static inline struct cma *dev_get_cma_area(struct device *dev)
{
return NULL;
}
+static inline struct cma *dma_contiguous_get_area_by_idx(unsigned int idx)
+{
+ return NULL;
+}
static inline void dma_contiguous_reserve(phys_addr_t limit)
{
}
static inline int dma_contiguous_reserve_area(phys_addr_t size,
phys_addr_t base, phys_addr_t limit, struct cma **res_cma,
diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c
index c56004d314dc2e436cddf3b20a4ee6ce8178bee4..afa9fd31304051d200cd4396dec26dd50becc375 100644
--- a/kernel/dma/contiguous.c
+++ b/kernel/dma/contiguous.c
@@ -40,21 +40,51 @@
#include <asm/page.h>
#include <linux/memblock.h>
#include <linux/err.h>
#include <linux/sizes.h>
-#include <linux/dma-buf/heaps/cma.h>
#include <linux/dma-map-ops.h>
#include <linux/cma.h>
#include <linux/nospec.h>
#ifdef CONFIG_CMA_SIZE_MBYTES
#define CMA_SIZE_MBYTES CONFIG_CMA_SIZE_MBYTES
#else
#define CMA_SIZE_MBYTES 0
#endif
+static struct cma *dma_contiguous_areas[MAX_CMA_AREAS];
+static unsigned int dma_contiguous_areas_num;
+
+static int dma_contiguous_insert_area(struct cma *cma)
+{
+ if (dma_contiguous_areas_num >= ARRAY_SIZE(dma_contiguous_areas))
+ return -EINVAL;
+
+ dma_contiguous_areas[dma_contiguous_areas_num++] = cma;
+
+ return 0;
+}
+
+/**
+ * dma_contiguous_get_area_by_idx() - Get contiguous area at given index
+ * @idx: index of the area we query
+ *
+ * Queries for the contiguous area located at index @idx.
+ *
+ * Returns:
+ * A pointer to the requested contiguous area, or NULL otherwise.
+ */
+struct cma *dma_contiguous_get_area_by_idx(unsigned int idx)
+{
+ if (idx >= dma_contiguous_areas_num)
+ return NULL;
+
+ return dma_contiguous_areas[idx];
+}
+EXPORT_SYMBOL_GPL(dma_contiguous_get_area_by_idx);
+
struct cma *dma_contiguous_default_area;
/*
* Default global CMA area size can be defined in kernel's .config.
* This is useful mainly for distro maintainers to create a kernel
@@ -262,13 +292,28 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
&dma_contiguous_default_area,
fixed);
if (ret)
return;
- ret = dma_heap_cma_register_heap(dma_contiguous_default_area);
+ /*
+ * We need to insert the new area in our list to avoid
+ * any inconsistencies between having the default area
+ * listed in the DT or not.
+ *
+ * The DT case is handled by rmem_cma_setup() and will
+ * always insert all its areas in our list. However, if
+ * it didn't run (because OF_RESERVED_MEM isn't set, or
+ * there's no DT region specified), then we don't have a
+ * default area yet, and no area in our list.
+ *
+ * This block creates the default area in such a case,
+ * but we also need to insert it in our list to avoid
+ * having a default area but an empty list.
+ */
+ ret = dma_contiguous_insert_area(dma_contiguous_default_area);
if (ret)
- pr_warn("Couldn't register default CMA heap.");
+ pr_warn("Couldn't queue default CMA region for heap creation.");
}
}
void __weak
dma_contiguous_early_fixup(phys_addr_t base, unsigned long size)
@@ -504,13 +549,13 @@ static int __init rmem_cma_setup(struct reserved_mem *rmem)
rmem->priv = cma;
pr_info("Reserved memory: created CMA memory pool at %pa, size %ld MiB\n",
&rmem->base, (unsigned long)rmem->size / SZ_1M);
- err = dma_heap_cma_register_heap(cma);
+ err = dma_contiguous_insert_area(cma);
if (err)
- pr_warn("Couldn't register CMA heap.");
+ pr_warn("Couldn't store CMA reserved area.");
return 0;
}
RESERVEDMEM_OF_DECLARE(cma, "shared-dma-pool", rmem_cma_setup);
#endif
--
2.53.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v4 2/8] dma: contiguous: Make dev_get_cma_area() a proper function
2026-03-31 10:00 ` [PATCH v4 0/8] dma-buf: heaps: Turn heaps into modules Maxime Ripard
2026-03-31 10:00 ` [PATCH v4 1/8] dma: contiguous: Turn heap registration logic around Maxime Ripard
@ 2026-03-31 10:00 ` Maxime Ripard
2026-03-31 10:00 ` [PATCH v4 3/8] dma: contiguous: Make dma_contiguous_default_area static Maxime Ripard
` (6 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Maxime Ripard @ 2026-03-31 10:00 UTC (permalink / raw)
To: Sumit Semwal, Benjamin Gaignard, Brian Starkey, John Stultz,
T.J. Mercier, Christian König, Marek Szyprowski,
Robin Murphy, Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko
Cc: Albert Esteve, linux-media, dri-devel, linaro-mm-sig,
linux-kernel, iommu, linux-mm, Maxime Ripard
As we try to enable dma-buf heaps, and the CMA one in particular, to
compile as modules, we need to export dev_get_cma_area(). It's currently
implemented as an inline function that returns either the content of
device->cma_area or dma_contiguous_default_area.
Thus, it means we need to export dma_contiguous_default_area, which
isn't really something we want any module to have access to.
Instead, let's make dev_get_cma_area() a proper function we will be able
to export so we can avoid exporting dma_contiguous_default_area.
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
include/linux/dma-map-ops.h | 7 +------
kernel/dma/contiguous.c | 8 ++++++++
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h
index c4c93c72ff6ff3ff5c59b7161970805422e9dccb..8604106c0c01b6a9dadc45263f3b1d9ecfacd4aa 100644
--- a/include/linux/dma-map-ops.h
+++ b/include/linux/dma-map-ops.h
@@ -91,16 +91,11 @@ static inline void set_dma_ops(struct device *dev,
#endif /* CONFIG_ARCH_HAS_DMA_OPS */
#ifdef CONFIG_DMA_CMA
extern struct cma *dma_contiguous_default_area;
-static inline struct cma *dev_get_cma_area(struct device *dev)
-{
- if (dev && dev->cma_area)
- return dev->cma_area;
- return dma_contiguous_default_area;
-}
+struct cma *dev_get_cma_area(struct device *dev);
struct cma *dma_contiguous_get_area_by_idx(unsigned int idx);
void dma_contiguous_reserve(phys_addr_t addr_limit);
int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
phys_addr_t limit, struct cma **res_cma, bool fixed);
diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c
index afa9fd31304051d200cd4396dec26dd50becc375..40a0ead24979cfdf25e4779545536a5438e26356 100644
--- a/kernel/dma/contiguous.c
+++ b/kernel/dma/contiguous.c
@@ -129,10 +129,18 @@ early_param("cma", early_cma);
bool __init cma_skip_dt_default_reserved_mem(void)
{
return size_cmdline != -1;
}
+struct cma *dev_get_cma_area(struct device *dev)
+{
+ if (dev && dev->cma_area)
+ return dev->cma_area;
+
+ return dma_contiguous_default_area;
+}
+
#ifdef CONFIG_DMA_NUMA_CMA
static struct cma *dma_contiguous_numa_area[MAX_NUMNODES];
static phys_addr_t numa_cma_size[MAX_NUMNODES] __initdata;
static struct cma *dma_contiguous_pernuma_area[MAX_NUMNODES];
--
2.53.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v4 3/8] dma: contiguous: Make dma_contiguous_default_area static
2026-03-31 10:00 ` [PATCH v4 0/8] dma-buf: heaps: Turn heaps into modules Maxime Ripard
2026-03-31 10:00 ` [PATCH v4 1/8] dma: contiguous: Turn heap registration logic around Maxime Ripard
2026-03-31 10:00 ` [PATCH v4 2/8] dma: contiguous: Make dev_get_cma_area() a proper function Maxime Ripard
@ 2026-03-31 10:00 ` Maxime Ripard
2026-03-31 10:00 ` [PATCH v4 4/8] dma: contiguous: Export dev_get_cma_area() Maxime Ripard
` (5 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Maxime Ripard @ 2026-03-31 10:00 UTC (permalink / raw)
To: Sumit Semwal, Benjamin Gaignard, Brian Starkey, John Stultz,
T.J. Mercier, Christian König, Marek Szyprowski,
Robin Murphy, Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko
Cc: Albert Esteve, linux-media, dri-devel, linaro-mm-sig,
linux-kernel, iommu, linux-mm, Maxime Ripard
Now that dev_get_cma_area() is no longer inline, we don't have any user
of dma_contiguous_default_area() outside of contiguous.c so we can make
it static.
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
include/linux/dma-map-ops.h | 2 --
kernel/dma/contiguous.c | 2 +-
2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h
index 8604106c0c01b6a9dadc45263f3b1d9ecfacd4aa..bef279ebeae7de59dd504e631f47c64d7e223736 100644
--- a/include/linux/dma-map-ops.h
+++ b/include/linux/dma-map-ops.h
@@ -89,12 +89,10 @@ static inline void set_dma_ops(struct device *dev,
{
}
#endif /* CONFIG_ARCH_HAS_DMA_OPS */
#ifdef CONFIG_DMA_CMA
-extern struct cma *dma_contiguous_default_area;
-
struct cma *dev_get_cma_area(struct device *dev);
struct cma *dma_contiguous_get_area_by_idx(unsigned int idx);
void dma_contiguous_reserve(phys_addr_t addr_limit);
int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c
index 40a0ead24979cfdf25e4779545536a5438e26356..fd8d3518a2323f0a631fb185ef92a24c35f8d25d 100644
--- a/kernel/dma/contiguous.c
+++ b/kernel/dma/contiguous.c
@@ -81,11 +81,11 @@ struct cma *dma_contiguous_get_area_by_idx(unsigned int idx)
return dma_contiguous_areas[idx];
}
EXPORT_SYMBOL_GPL(dma_contiguous_get_area_by_idx);
-struct cma *dma_contiguous_default_area;
+static struct cma *dma_contiguous_default_area;
/*
* Default global CMA area size can be defined in kernel's .config.
* This is useful mainly for distro maintainers to create a kernel
* that works correctly for most supported systems.
--
2.53.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v4 4/8] dma: contiguous: Export dev_get_cma_area()
2026-03-31 10:00 ` [PATCH v4 0/8] dma-buf: heaps: Turn heaps into modules Maxime Ripard
` (2 preceding siblings ...)
2026-03-31 10:00 ` [PATCH v4 3/8] dma: contiguous: Make dma_contiguous_default_area static Maxime Ripard
@ 2026-03-31 10:00 ` Maxime Ripard
2026-03-31 10:00 ` [PATCH v4 5/8] mm: cma: Export cma_alloc(), cma_release() and cma_get_name() Maxime Ripard
` (4 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Maxime Ripard @ 2026-03-31 10:00 UTC (permalink / raw)
To: Sumit Semwal, Benjamin Gaignard, Brian Starkey, John Stultz,
T.J. Mercier, Christian König, Marek Szyprowski,
Robin Murphy, Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko
Cc: Albert Esteve, linux-media, dri-devel, linaro-mm-sig,
linux-kernel, iommu, linux-mm, Maxime Ripard
The CMA dma-buf heap uses the dev_get_cma_area() function to retrieve
the default contiguous area.
Now that this function is no longer inlined, and since we want to turn
the CMA heap into a module, let's export it.
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
kernel/dma/contiguous.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c
index fd8d3518a2323f0a631fb185ef92a24c35f8d25d..83a5bd9488e1448cc72e92ed204ce804164cc6b8 100644
--- a/kernel/dma/contiguous.c
+++ b/kernel/dma/contiguous.c
@@ -136,10 +136,11 @@ struct cma *dev_get_cma_area(struct device *dev)
if (dev && dev->cma_area)
return dev->cma_area;
return dma_contiguous_default_area;
}
+EXPORT_SYMBOL_GPL(dev_get_cma_area);
#ifdef CONFIG_DMA_NUMA_CMA
static struct cma *dma_contiguous_numa_area[MAX_NUMNODES];
static phys_addr_t numa_cma_size[MAX_NUMNODES] __initdata;
--
2.53.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v4 5/8] mm: cma: Export cma_alloc(), cma_release() and cma_get_name()
2026-03-31 10:00 ` [PATCH v4 0/8] dma-buf: heaps: Turn heaps into modules Maxime Ripard
` (3 preceding siblings ...)
2026-03-31 10:00 ` [PATCH v4 4/8] dma: contiguous: Export dev_get_cma_area() Maxime Ripard
@ 2026-03-31 10:00 ` Maxime Ripard
2026-03-31 10:00 ` [PATCH v4 6/8] dma-buf: heaps: Export mem_accounting parameter Maxime Ripard
` (3 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Maxime Ripard @ 2026-03-31 10:00 UTC (permalink / raw)
To: Sumit Semwal, Benjamin Gaignard, Brian Starkey, John Stultz,
T.J. Mercier, Christian König, Marek Szyprowski,
Robin Murphy, Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko
Cc: Albert Esteve, linux-media, dri-devel, linaro-mm-sig,
linux-kernel, iommu, linux-mm, Maxime Ripard
The CMA dma-buf heap uses cma_alloc() and cma_release() to allocate and
free, respectively, its CMA buffers, and cma_get_name() to get the name
of the heap instance it's going to create.
However, these functions are not exported. Since we want to turn the CMA
heap into a module, let's export them both.
Reviewed-by: T.J. Mercier <tjmercier@google.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
mm/cma.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/cma.c b/mm/cma.c
index 94b5da468a7d719e5144d33b06bcc7619c0fbcc9..550effb9c4e01cc488b5744fe61d55a5b70a6d6c 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -50,10 +50,11 @@ unsigned long cma_get_size(const struct cma *cma)
const char *cma_get_name(const struct cma *cma)
{
return cma->name;
}
+EXPORT_SYMBOL_GPL(cma_get_name);
static unsigned long cma_bitmap_aligned_mask(const struct cma *cma,
unsigned int align_order)
{
if (align_order <= cma->order_per_bit)
@@ -949,10 +950,11 @@ struct page *cma_alloc(struct cma *cma, unsigned long count,
if (page)
set_pages_refcounted(page, count);
return page;
}
+EXPORT_SYMBOL_GPL(cma_alloc);
static struct cma_memrange *find_cma_memrange(struct cma *cma,
const struct page *pages, unsigned long count)
{
struct cma_memrange *cmr = NULL;
@@ -1025,10 +1027,11 @@ bool cma_release(struct cma *cma, const struct page *pages,
__cma_release_frozen(cma, cmr, pages, count);
return true;
}
+EXPORT_SYMBOL_GPL(cma_release);
bool cma_release_frozen(struct cma *cma, const struct page *pages,
unsigned long count)
{
struct cma_memrange *cmr;
--
2.53.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v4 6/8] dma-buf: heaps: Export mem_accounting parameter
2026-03-31 10:00 ` [PATCH v4 0/8] dma-buf: heaps: Turn heaps into modules Maxime Ripard
` (4 preceding siblings ...)
2026-03-31 10:00 ` [PATCH v4 5/8] mm: cma: Export cma_alloc(), cma_release() and cma_get_name() Maxime Ripard
@ 2026-03-31 10:00 ` Maxime Ripard
2026-03-31 10:00 ` [PATCH v4 7/8] dma-buf: heaps: cma: Turn the heap into a module Maxime Ripard
` (2 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Maxime Ripard @ 2026-03-31 10:00 UTC (permalink / raw)
To: Sumit Semwal, Benjamin Gaignard, Brian Starkey, John Stultz,
T.J. Mercier, Christian König, Marek Szyprowski,
Robin Murphy, Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko
Cc: Albert Esteve, linux-media, dri-devel, linaro-mm-sig,
linux-kernel, iommu, linux-mm, Maxime Ripard
The mem_accounting kernel parameter is used by heaps to know if they
should account allocations in their respective cgroup controllers.
Since we're going to allow heaps to compile as modules, we need to
export that variable.
Reviewed-by: T.J. Mercier <tjmercier@google.com>
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
drivers/dma-buf/dma-heap.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c
index ac5f8685a649496c0e1c6decbf263b63fa472d04..a76bf3f8b071a3d5bf39a8513f31e9e8aa16e02f 100644
--- a/drivers/dma-buf/dma-heap.c
+++ b/drivers/dma-buf/dma-heap.c
@@ -51,10 +51,11 @@ static DEFINE_XARRAY_ALLOC(dma_heap_minors);
bool __read_mostly mem_accounting;
module_param(mem_accounting, bool, 0444);
MODULE_PARM_DESC(mem_accounting,
"Enable cgroup-based memory accounting for dma-buf heap allocations (default=false).");
+EXPORT_SYMBOL_NS_GPL(mem_accounting, "DMA_BUF_HEAP");
static int dma_heap_buffer_alloc(struct dma_heap *heap, size_t len,
u32 fd_flags,
u64 heap_flags)
{
--
2.53.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v4 7/8] dma-buf: heaps: cma: Turn the heap into a module
2026-03-31 10:00 ` [PATCH v4 0/8] dma-buf: heaps: Turn heaps into modules Maxime Ripard
` (5 preceding siblings ...)
2026-03-31 10:00 ` [PATCH v4 6/8] dma-buf: heaps: Export mem_accounting parameter Maxime Ripard
@ 2026-03-31 10:00 ` Maxime Ripard
2026-03-31 10:00 ` [PATCH v4 8/8] dma-buf: heaps: system: " Maxime Ripard
2026-03-31 12:54 ` [PATCH v4 0/8] dma-buf: heaps: Turn heaps into modules Marek Szyprowski
8 siblings, 0 replies; 13+ messages in thread
From: Maxime Ripard @ 2026-03-31 10:00 UTC (permalink / raw)
To: Sumit Semwal, Benjamin Gaignard, Brian Starkey, John Stultz,
T.J. Mercier, Christian König, Marek Szyprowski,
Robin Murphy, Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko
Cc: Albert Esteve, linux-media, dri-devel, linaro-mm-sig,
linux-kernel, iommu, linux-mm, Maxime Ripard
Now that all the symbols used by the CMA heap are exported, turning the
CMA heap into a module becomes pretty easy: we just need to add the
usual MODULE_* macros, import the proper namespaces and change the
Kconfig symbol to a tristate.
This heap won't be able to unload though, since we're missing a lot of
infrastructure to make it safe.
Reviewed-by: T.J. Mercier <tjmercier@google.com>
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
drivers/dma-buf/heaps/Kconfig | 2 +-
drivers/dma-buf/heaps/cma_heap.c | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/dma-buf/heaps/Kconfig b/drivers/dma-buf/heaps/Kconfig
index a5eef06c422644e8aadaf5aff2bd9a33c49c1ba3..aed0b9b4febf388376cfc41be9843980d010c4e8 100644
--- a/drivers/dma-buf/heaps/Kconfig
+++ b/drivers/dma-buf/heaps/Kconfig
@@ -4,11 +4,11 @@ config DMABUF_HEAPS_SYSTEM
help
Choose this option to enable the system dmabuf heap. The system heap
is backed by pages from the buddy allocator. If in doubt, say Y.
config DMABUF_HEAPS_CMA
- bool "DMA-BUF CMA Heap"
+ tristate "DMA-BUF CMA Heap"
depends on DMABUF_HEAPS && DMA_CMA
help
Choose this option to enable dma-buf CMA heap. This heap is backed
by the Contiguous Memory Allocator (CMA). If your system has these
regions, you should say Y here.
diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c
index 33cac626da1198e3c4a1cdcd562223c1924b6ceb..0ed519a19da455df7441396c96934a107fd72ffb 100644
--- a/drivers/dma-buf/heaps/cma_heap.c
+++ b/drivers/dma-buf/heaps/cma_heap.c
@@ -421,5 +421,8 @@ static int __init add_cma_heaps(void)
return 0;
}
module_init(add_cma_heaps);
MODULE_DESCRIPTION("DMA-BUF CMA Heap");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("DMA_BUF");
+MODULE_IMPORT_NS("DMA_BUF_HEAP");
--
2.53.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v4 8/8] dma-buf: heaps: system: Turn the heap into a module
2026-03-31 10:00 ` [PATCH v4 0/8] dma-buf: heaps: Turn heaps into modules Maxime Ripard
` (6 preceding siblings ...)
2026-03-31 10:00 ` [PATCH v4 7/8] dma-buf: heaps: cma: Turn the heap into a module Maxime Ripard
@ 2026-03-31 10:00 ` Maxime Ripard
2026-03-31 12:54 ` [PATCH v4 0/8] dma-buf: heaps: Turn heaps into modules Marek Szyprowski
8 siblings, 0 replies; 13+ messages in thread
From: Maxime Ripard @ 2026-03-31 10:00 UTC (permalink / raw)
To: Sumit Semwal, Benjamin Gaignard, Brian Starkey, John Stultz,
T.J. Mercier, Christian König, Marek Szyprowski,
Robin Murphy, Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko
Cc: Albert Esteve, linux-media, dri-devel, linaro-mm-sig,
linux-kernel, iommu, linux-mm, Maxime Ripard
The system heap can be easily turned into a module by adding the usual
MODULE_* macros, importing the proper namespaces and changing the
Kconfig symbol to a tristate.
This heap won't be able to unload though, since we're missing a lot of
infrastructure to make it safe.
Reviewed-by: T.J. Mercier <tjmercier@google.com>
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
drivers/dma-buf/heaps/Kconfig | 2 +-
drivers/dma-buf/heaps/system_heap.c | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/dma-buf/heaps/Kconfig b/drivers/dma-buf/heaps/Kconfig
index aed0b9b4febf388376cfc41be9843980d010c4e8..e273fb18feca091ccd9b406e68f86c12efb339e9 100644
--- a/drivers/dma-buf/heaps/Kconfig
+++ b/drivers/dma-buf/heaps/Kconfig
@@ -1,7 +1,7 @@
config DMABUF_HEAPS_SYSTEM
- bool "DMA-BUF System Heap"
+ tristate "DMA-BUF System Heap"
depends on DMABUF_HEAPS
help
Choose this option to enable the system dmabuf heap. The system heap
is backed by pages from the buddy allocator. If in doubt, say Y.
diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
index b3650d8fd6511a4a755612cfe3a9d9fee796f80e..1957403b0f2ae5e82ab39f5945dfe82808e93964 100644
--- a/drivers/dma-buf/heaps/system_heap.c
+++ b/drivers/dma-buf/heaps/system_heap.c
@@ -442,5 +442,10 @@ static int __init system_heap_create(void)
return PTR_ERR(sys_heap);
return 0;
}
module_init(system_heap_create);
+
+MODULE_DESCRIPTION("DMA-BUF System Heap");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("DMA_BUF");
+MODULE_IMPORT_NS("DMA_BUF_HEAP");
--
2.53.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v4 0/8] dma-buf: heaps: Turn heaps into modules
2026-03-31 10:00 ` [PATCH v4 0/8] dma-buf: heaps: Turn heaps into modules Maxime Ripard
` (7 preceding siblings ...)
2026-03-31 10:00 ` [PATCH v4 8/8] dma-buf: heaps: system: " Maxime Ripard
@ 2026-03-31 12:54 ` Marek Szyprowski
2026-04-02 5:06 ` Sumit Semwal
8 siblings, 1 reply; 13+ messages in thread
From: Marek Szyprowski @ 2026-03-31 12:54 UTC (permalink / raw)
To: Maxime Ripard, Sumit Semwal, Benjamin Gaignard, Brian Starkey,
John Stultz, T.J. Mercier, Christian König, Robin Murphy,
Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko
Cc: Albert Esteve, linux-media, dri-devel, linaro-mm-sig,
linux-kernel, iommu, linux-mm
On 31.03.2026 12:00, Maxime Ripard wrote:
> The recent introduction of heaps in the optee driver [1] made possible
> the creation of heaps as modules.
>
> It's generally a good idea if possible, including for the already
> existing system and CMA heaps.
>
> The system one is pretty trivial, the CMA one is a bit more involved,
> especially since we have a call from kernel/dma/contiguous.c to the CMA
> heap code. This was solved by turning the logic around and making the
> CMA heap call into the contiguous DMA code.
>
> Let me know what you think,
> Maxime
>
> 1: https://lore.kernel.org/dri-devel/20250911135007.1275833-4-jens.wiklander@linaro.org/
>
> Signed-off-by: Maxime Ripard <mripard@kernel.org>
Applied again patches 1-5 to my dma-mapping-for-next branch. I hope this time it
won't cause new problems in linux-next.
Here is a stable branch to apply remaining dma-buf heaps patches:
https://web.git.kernel.org/pub/scm/linux/kernel/git/mszyprowski/linux.git/log/?h=dma-contig-for-7.1-modules-prep-v4
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v4 0/8] dma-buf: heaps: Turn heaps into modules
2026-03-31 12:54 ` [PATCH v4 0/8] dma-buf: heaps: Turn heaps into modules Marek Szyprowski
@ 2026-04-02 5:06 ` Sumit Semwal
2026-04-02 13:11 ` Maxime Ripard
0 siblings, 1 reply; 13+ messages in thread
From: Sumit Semwal @ 2026-04-02 5:06 UTC (permalink / raw)
To: Marek Szyprowski
Cc: Maxime Ripard, Benjamin Gaignard, Brian Starkey, John Stultz,
T.J. Mercier, Christian König, Robin Murphy, Andrew Morton,
David Hildenbrand, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Albert Esteve, linux-media, dri-devel, linaro-mm-sig,
linux-kernel, iommu, linux-mm
Hello Maxime,
On Tue, 31 Mar 2026 at 18:24, Marek Szyprowski <m.szyprowski@samsung.com> wrote:
>
> On 31.03.2026 12:00, Maxime Ripard wrote:
> > The recent introduction of heaps in the optee driver [1] made possible
> > the creation of heaps as modules.
> >
> > It's generally a good idea if possible, including for the already
> > existing system and CMA heaps.
> >
> > The system one is pretty trivial, the CMA one is a bit more involved,
> > especially since we have a call from kernel/dma/contiguous.c to the CMA
> > heap code. This was solved by turning the logic around and making the
> > CMA heap call into the contiguous DMA code.
> >
> > Let me know what you think,
> > Maxime
> >
> > 1: https://lore.kernel.org/dri-devel/20250911135007.1275833-4-jens.wiklander@linaro.org/
> >
> > Signed-off-by: Maxime Ripard <mripard@kernel.org>
Thank you for this patch series; now that it is needed by more folks,
I think we can merge this.
Marek, I'll coordinate with you on this - thank you!
Best,
Sumit.
>
>
> Applied again patches 1-5 to my dma-mapping-for-next branch. I hope this time it
>
> won't cause new problems in linux-next.
>
>
> Here is a stable branch to apply remaining dma-buf heaps patches:
>
> https://web.git.kernel.org/pub/scm/linux/kernel/git/mszyprowski/linux.git/log/?h=dma-contig-for-7.1-modules-prep-v4
>
>
> Best regards
> --
> Marek Szyprowski, PhD
> Samsung R&D Institute Poland
>
--
Thanks and regards,
Sumit Semwal (he / him)
Senior Tech Lead - Platforms and Virtualisation
Linaro.org │ Arm Solutions at Light Speed
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v4 0/8] dma-buf: heaps: Turn heaps into modules
2026-04-02 5:06 ` Sumit Semwal
@ 2026-04-02 13:11 ` Maxime Ripard
2026-04-02 13:32 ` Sumit Semwal
0 siblings, 1 reply; 13+ messages in thread
From: Maxime Ripard @ 2026-04-02 13:11 UTC (permalink / raw)
To: Sumit Semwal
Cc: Marek Szyprowski, Benjamin Gaignard, Brian Starkey, John Stultz,
T.J. Mercier, Christian König, Robin Murphy, Andrew Morton,
David Hildenbrand, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Albert Esteve, linux-media, dri-devel, linaro-mm-sig,
linux-kernel, iommu, linux-mm
[-- Attachment #1: Type: text/plain, Size: 1354 bytes --]
On Thu, Apr 02, 2026 at 10:36:48AM +0530, Sumit Semwal wrote:
> Hello Maxime,
>
> On Tue, 31 Mar 2026 at 18:24, Marek Szyprowski <m.szyprowski@samsung.com> wrote:
> >
> > On 31.03.2026 12:00, Maxime Ripard wrote:
> > > The recent introduction of heaps in the optee driver [1] made possible
> > > the creation of heaps as modules.
> > >
> > > It's generally a good idea if possible, including for the already
> > > existing system and CMA heaps.
> > >
> > > The system one is pretty trivial, the CMA one is a bit more involved,
> > > especially since we have a call from kernel/dma/contiguous.c to the CMA
> > > heap code. This was solved by turning the logic around and making the
> > > CMA heap call into the contiguous DMA code.
> > >
> > > Let me know what you think,
> > > Maxime
> > >
> > > 1: https://lore.kernel.org/dri-devel/20250911135007.1275833-4-jens.wiklander@linaro.org/
> > >
> > > Signed-off-by: Maxime Ripard <mripard@kernel.org>
>
> Thank you for this patch series; now that it is needed by more folks,
> I think we can merge this.
>
> Marek, I'll coordinate with you on this - thank you!
If Marek plans on sending it during the next merge window, maybe the
best thing to do for us is just to wait for -rc1 and apply the rest of
the patches. Otherwise, we can merge the branch in drm-misc.
Maxime
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 273 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v4 0/8] dma-buf: heaps: Turn heaps into modules
2026-04-02 13:11 ` Maxime Ripard
@ 2026-04-02 13:32 ` Sumit Semwal
0 siblings, 0 replies; 13+ messages in thread
From: Sumit Semwal @ 2026-04-02 13:32 UTC (permalink / raw)
To: Maxime Ripard
Cc: Marek Szyprowski, Benjamin Gaignard, Brian Starkey, John Stultz,
T.J. Mercier, Christian König, Robin Murphy, Andrew Morton,
David Hildenbrand, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Albert Esteve, linux-media, dri-devel, linaro-mm-sig,
linux-kernel, iommu, linux-mm
Hi Maxime,
On Thu, 2 Apr 2026 at 18:42, Maxime Ripard <mripard@kernel.org> wrote:
>
> On Thu, Apr 02, 2026 at 10:36:48AM +0530, Sumit Semwal wrote:
> > Hello Maxime,
> >
> > On Tue, 31 Mar 2026 at 18:24, Marek Szyprowski <m.szyprowski@samsung.com> wrote:
> > >
> > > On 31.03.2026 12:00, Maxime Ripard wrote:
> > > > The recent introduction of heaps in the optee driver [1] made possible
> > > > the creation of heaps as modules.
> > > >
> > > > It's generally a good idea if possible, including for the already
> > > > existing system and CMA heaps.
> > > >
> > > > The system one is pretty trivial, the CMA one is a bit more involved,
> > > > especially since we have a call from kernel/dma/contiguous.c to the CMA
> > > > heap code. This was solved by turning the logic around and making the
> > > > CMA heap call into the contiguous DMA code.
> > > >
> > > > Let me know what you think,
> > > > Maxime
> > > >
> > > > 1: https://lore.kernel.org/dri-devel/20250911135007.1275833-4-jens.wiklander@linaro.org/
> > > >
> > > > Signed-off-by: Maxime Ripard <mripard@kernel.org>
> >
> > Thank you for this patch series; now that it is needed by more folks,
> > I think we can merge this.
> >
> > Marek, I'll coordinate with you on this - thank you!
>
> If Marek plans on sending it during the next merge window, maybe the
> best thing to do for us is just to wait for -rc1 and apply the rest of
> the patches. Otherwise, we can merge the branch in drm-misc.
We could do that. Are we ok to wait till -rc1?
>
> Maxime
Best,
Sumit
^ permalink raw reply [flat|nested] 13+ messages in thread