dma-buf: heaps: Turn heaps into modules
Subsystems (6)
v2 cover dma-buf: heaps: Turn heaps into modules
Hi,
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/[email protected]/
---
Changes in v2:
- Collect tags
- Don't export dma_contiguous_default_area anymore, but export
dev_get_cma_area instead
- Mentioned that heap modules can't be removed
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Maxime Ripard (9):
dma: contiguous: Turn heap registration logic around
dma: contiguous: Make dev_get_cma_area() a proper function
dma: contiguous: Make dma_contiguous_default_area static
mm: cma: Export dev_get_cma_area()
mm: cma: Export cma_alloc and cma_release
mm: cma: Export cma_get_name
dma-buf: heaps: Export mem_accounting parameter
dma-buf: heaps: cma: Turn the heap into a module
dma-buf: heaps: system: Turn the heap into a module
drivers/dma-buf/dma-heap.c | 1 + drivers/dma-buf/heaps/Kconfig | 4 ++-- drivers/dma-buf/heaps/cma_heap.c | 21 +++++---------------- drivers/dma-buf/heaps/system_heap.c | 5 +++++ include/linux/dma-map-ops.h | 14 ++++++-------- kernel/dma/contiguous.c | 37 ++++++++++++++++++++++++++++++++++--- mm/cma.c | 3 +++ 7 files changed, 56 insertions(+), 29 deletions(-)
---
base-commit: 499a718536dc0e1c1d1b6211847207d58acd9916
change-id: 20260225-dma-buf-heaps-as-modules-1034b3ec9f2a
Best regards,
Signature · 1 line
Maxime Ripard <[email protected]>
PATCH v2 1/9 dma: contiguous: Turn heap registration logic around
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.
--- drivers/dma-buf/heaps/cma_heap.c | 18 ++---------------- include/linux/dma-map-ops.h | 5 +++++ kernel/dma/contiguous.c | 26 ++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 18 deletions(-)
drivers/dma-buf/heaps/cma_heap.c +2 -16
@@ -28,23 +28,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 +399,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_reserved_region (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 ; }
include/linux/dma-map-ops.h +5 -0
@@ -110,10 +110,11 @@ bool dma_release_from_contiguous(struct device *dev, struct page *pages, int count);struct page *dma_alloc_contiguous (struct device *dev,size_t size,gfp_t gfp);void dma_free_contiguous (struct device *dev,struct page *page,size_t size);void dma_contiguous_early_fixup (phys_addr_t base,unsigned long size); +struct cma *dma_contiguous_get_reserved_region (unsigned int idx);#else /* CONFIG_DMA_CMA */ static inline struct cma *dev_get_cma_area (struct device *dev) {return NULL ; }
@@ -148,10 +149,14 @@ static inline void dma_free_contiguous(struct device *dev, struct page *page, __free_pages(page, get_order(size)); }static inline void dma_contiguous_early_fixup (phys_addr_t base,unsigned long size) { } +static inline struct cma *dma_contiguous_get_reserved_region (unsigned int idx) +{ +return NULL ; +}#endif /* CONFIG_DMA_CMA*/ #ifdef CONFIG_DMA_DECLARE_COHERENT int dma_declare_coherent_memory (struct device *dev,phys_addr_t phys_addr,dma_addr_t device_addr,size_t size);
kernel/dma/contiguous.c +24 -2
@@ -456,10 +456,32 @@ void dma_free_contiguous(struct device *dev, struct page *page, size_t size)#include <linux/of_reserved_mem.h> #undef pr_fmt#define pr_fmt (fmt) fmt +static struct cma *rmem_cma_areas[MAX_CMA_AREAS ]; +static unsigned int rmem_cma_areas_num; + +static int rmem_cma_insert_area (struct cma *cma) +{ +if (rmem_cma_areas_num >=ARRAY_SIZE (rmem_cma_areas)) +return -EINVAL ; + + rmem_cma_areas[rmem_cma_areas_num++] = cma; + +return 0 ; +} + +struct cma *dma_contiguous_get_reserved_region (unsigned int idx) +{ +if (idx >= rmem_cma_areas_num) +return NULL ; + +return rmem_cma_areas[idx]; +} +EXPORT_SYMBOL_GPL (dma_contiguous_get_reserved_region); +static int rmem_cma_device_init (struct reserved_mem *rmem,struct device *dev) { dev->cma_area = rmem->priv;return 0 ; }
@@ -504,13 +526,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 =rmem_cma_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
Signature · 1 line
2.53.0
Re: [PATCH v2 1/9] dma: contiguous: Turn heap registration logic around
Quoted 8 lines · 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.
Quoted 6 lines
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.
Reviewed-by T.J. Mercier <[email protected]>Signed-off-by Maxime Ripard <[email protected]>
Quoted 148 lines
--- drivers/dma-buf/heaps/cma_heap.c | 18 ++---------------- include/linux/dma-map-ops.h | 5 +++++ kernel/dma/contiguous.c | 26 ++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 18 deletions(-)drivers/dma-buf/heaps/cma_heap.c +2
-16@@ -28,23 +28,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 +399,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_reserved_region (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 ; }include/linux/dma-map-ops.h +5
-0@@ -110,10 +110,11 @@ bool dma_release_from_contiguous(struct device *dev, struct page *pages, int count);struct page *dma_alloc_contiguous (struct device *dev,size_t size,gfp_t gfp);void dma_free_contiguous (struct device *dev,struct page *page,size_t size);void dma_contiguous_early_fixup (phys_addr_t base,unsigned long size); +struct cma *dma_contiguous_get_reserved_region (unsigned int idx);#else /* CONFIG_DMA_CMA */ static inline struct cma *dev_get_cma_area (struct device *dev) {return NULL ; }@@ -148,10 +149,14 @@ static inline void dma_free_contiguous(struct device *dev, struct page *page, __free_pages(page, get_order(size)); }static inline void dma_contiguous_early_fixup (phys_addr_t base,unsigned long size) { } +static inline struct cma *dma_contiguous_get_reserved_region (unsigned int idx) +{ +return NULL ; +}#endif /* CONFIG_DMA_CMA*/ #ifdef CONFIG_DMA_DECLARE_COHERENT int dma_declare_coherent_memory (struct device *dev,phys_addr_t phys_addr,dma_addr_t device_addr,size_t size);kernel/dma/contiguous.c +24
-3@@ -456,10 +456,32 @@ void dma_free_contiguous(struct device *dev, struct page *page, size_t size)#include <linux/of_reserved_mem.h> #undef pr_fmt#define pr_fmt (fmt) fmt +static struct cma *rmem_cma_areas[MAX_CMA_AREAS ]; +static unsigned int rmem_cma_areas_num; + +static int rmem_cma_insert_area (struct cma *cma) +{ +if (rmem_cma_areas_num >=ARRAY_SIZE (rmem_cma_areas)) +return -EINVAL ; + + rmem_cma_areas[rmem_cma_areas_num++] = cma; + +return 0 ; +} + +struct cma *dma_contiguous_get_reserved_region (unsigned int idx) +{ +if (idx >= rmem_cma_areas_num) +return NULL ; + +return rmem_cma_areas[idx]; +} +EXPORT_SYMBOL_GPL (dma_contiguous_get_reserved_region); +static int rmem_cma_device_init (struct reserved_mem *rmem,struct device *dev) { dev->cma_area = rmem->priv;return 0 ; }@@ -504,13 +526,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 =rmem_cma_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
PATCH v2 2/9 dma: contiguous: Make dev_get_cma_area() a proper function
In reply to Maxime RipardAs 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.
--- include/linux/dma-map-ops.h | 7 +------ kernel/dma/contiguous.c | 8 ++++++++ 2 files changed, 9 insertions(+), 6 deletions(-)
include/linux/dma-map-ops.h +1 -6
@@ -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);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);
kernel/dma/contiguous.c +8 -0
@@ -99,10 +99,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 ];
Signature · 1 line
2.53.0
PATCH v2 3/9 dma: contiguous: Make dma_contiguous_default_area static
In reply to Maxime RipardNow 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.
--- include/linux/dma-map-ops.h | 2 -- kernel/dma/contiguous.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-)
include/linux/dma-map-ops.h +0 -2
@@ -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);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);
kernel/dma/contiguous.c +1 -1
@@ -51,11 +51,11 @@#define CMA_SIZE_MBYTES CONFIG_CMA_SIZE_MBYTES#else #define CMA_SIZE_MBYTES 0#endif -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.
Signature · 1 line
2.53.0
PATCH v2 4/9 mm: cma: Export dev_get_cma_area()
In reply to Maxime RipardThe 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.
--- kernel/dma/contiguous.c | 1 + 1 file changed, 1 insertion(+)
kernel/dma/contiguous.c +1 -0
@@ -106,10 +106,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 ;
Signature · 1 line
2.53.0
David Hildenbrand (Arm)
maintainerRe: [PATCH v2 4/9] mm: cma: Export dev_get_cma_area()
Quoted 9 lines · 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 <[email protected]>--- kernel/dma/contiguous.c | 1 +
The prefix of the patch should likely not be "mm: cma: " :)
Signature · 3 lines
Cheers, David
PATCH v2 5/9 mm: cma: Export cma_alloc and cma_release
In reply to Maxime RipardThe CMA dma-buf heap uses cma_alloc() and cma_release() to allocate and free, respectively, its CMA buffers.
However, these functions are not exported. Since we want to turn the CMA heap into a module, let's export them both.
--- mm/cma.c | 2 ++ 1 file changed, 2 insertions(+)
mm/cma.c +2 -0
@@ -949,10 +949,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 +1026,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;
Signature · 1 line
2.53.0
Re: [PATCH v2 5/9] mm: cma: Export cma_alloc and cma_release
Quoted 31 lines · Maxime Ripard
The CMA dma-buf heap uses
cma_alloc()andcma_release()to allocate and free, respectively, its CMA buffers.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 <[email protected]>Signed-off-by Maxime Ripard <[email protected]>--- mm/cma.c | 2 ++ 1 file changed, 2 insertions(+)mm/cma.c +1
-0@@ -949,10 +949,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 +1026,11 @@ bool cma_release(struct cma *cma, const struct page *pages,
mm/cma.c bool cma_release(struct cma *cma, const struct page *pages, · line 1036
Quoted 10 lines
mm/cma.c +1
-0__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;
Signature · 3 lines
Cheers, David
PATCH v2 6/9 mm: cma: Export cma_get_name
In reply to Maxime RipardThe CMA dma-buf heap uses the cma_get_name() function to get the name of the heap instance it's going to create.
However, this function is not exported. Since we want to turn the CMA heap into a module, let's export it.
--- mm/cma.c | 1 + 1 file changed, 1 insertion(+)
mm/cma.c +1 -0
@@ -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)
Signature · 1 line
2.53.0
David Hildenbrand (Arm)
maintainerRe: [PATCH v2 6/9] mm: cma: Export cma_get_name
Quoted 17 lines · Maxime Ripard
The CMA dma-buf heap uses the
cma_get_name()function to get the name of the heap instance it's going to create.However, this function is not exported. Since we want to turn the CMA heap into a module, let's export it.
Reviewed-by T.J. Mercier <[email protected]>Signed-off-by Maxime Ripard <[email protected]>--- mm/cma.c | 1 + 1 file changed, 1 insertion(+)mm/cma.c +0
-0
mm/cma.c unsigned long cma_get_size(const struct cma *cma) · line 55
Quoted 6 lines
mm/cma.c +1
-0@@ -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);
No real reason to not squash this patch into #5, right?
Signature · 3 lines
Cheers, David
Re: [PATCH v2 6/9] mm: cma: Export cma_get_name
Hi,
Quoted 19 lines · David Hildenbrand (Arm)
Quoted 18 lines · Maxime Ripard
The CMA dma-buf heap uses the
cma_get_name()function to get the name of the heap instance it's going to create.However, this function is not exported. Since we want to turn the CMA heap into a module, let's export it.
Reviewed-by T.J. Mercier <[email protected]>Signed-off-by Maxime Ripard <[email protected]>--- mm/cma.c | 1 + 1 file changed, 1 insertion(+)mm/cma.c +0
-0@@ -50,10 +50,11 @@ unsigned long cma_get_size(const struct cma *cma)
Quoted 7 lines
mm/cma.c unsigned long cma_get_size(const struct cma *cma) · line 55
Quoted 5 lines
mm/cma.c +1
-0const char *cma_get_name (const struct cma *cma) {return cma->name; } +EXPORT_SYMBOL_GPL (cma_get_name);No real reason to not squash this patch into #5, right?
I was assuming it was not really the same "category" of the API than alloc/free, so the reviews might not be the same (like they weren't for dma_contiguous_default_area). But I guess it also makes sense to squash both.
I'll update the series
Thanks!
PATCH v2 7/9 dma-buf: heaps: Export mem_accounting parameter
In reply to Maxime RipardThe 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.
--- drivers/dma-buf/dma-heap.c | 1 + 1 file changed, 1 insertion(+)
drivers/dma-buf/dma-heap.c +1 -0
@@ -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) {
Signature · 1 line
2.53.0
PATCH v2 8/9 dma-buf: heaps: cma: Turn the heap into a module
In reply to Maxime RipardNow 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.
--- drivers/dma-buf/heaps/Kconfig | 2 +- drivers/dma-buf/heaps/cma_heap.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/dma-buf/heaps/Kconfig +1 -1
@@ -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.
drivers/dma-buf/heaps/cma_heap.c +3 -0
@@ -422,5 +422,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" );
Signature · 1 line
2.53.0
kernel test robot
build botRe: [PATCH v2 8/9] dma-buf: heaps: cma: Turn the heap into a module
kernel test robot noticed the following build errors:
Hi Maxime,
kernel test robot noticed the following build errors:
[auto build test ERROR on 499a718536dc0e1c1d1b6211847207d58acd9916]
url: https://github.com/intel-lab-lkp/linux/commits/Maxime-Ripard/dma-contiguous-Turn-heap-registration-logic-around/20260227-212606 base: 499a718536dc0e1c1d1b6211847207d58acd9916 patch link: https://lore.kernel.org/r/20260227-dma-buf-heaps-as-modules-v2-8-454aee7e06cc%40kernel.org patch subject: [PATCH v2 8/9] dma-buf: heaps: cma: Turn the heap into a module config: x86_64-randconfig-002-20260227 (https://download.01.org/0day-ci/archive/20260228/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260228/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: "dma_contiguous_get_reserved_region" [drivers/dma-buf/heaps/cma_heap.ko] undefined!
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v2 9/9 dma-buf: heaps: system: Turn the heap into a module
In reply to Maxime RipardThe 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.
--- drivers/dma-buf/heaps/Kconfig | 2 +- drivers/dma-buf/heaps/system_heap.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/dma-buf/heaps/Kconfig +1 -1
@@ -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.
drivers/dma-buf/heaps/system_heap.c +5 -0
@@ -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" );
Signature · 1 line
2.53.0