* [PATCH] mm: cma: make mm/cma.h self-contained and conditionalize includes
@ 2026-08-15 8:40 Eamon Sippy
2026-08-15 10:03 ` Barry Song
2026-08-15 10:32 ` [PATCH v2] " Eamon Sippy
0 siblings, 2 replies; 4+ messages in thread
From: Eamon Sippy @ 2026-08-15 8:40 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-mm, linux-kernel, Eamon Sippy
mm/cma.h uses types from <linux/spinlock.h>, <linux/mutex.h>,
<linux/atomic.h> and <linux/list.h> without explicitly including them,
violating the kernel header self-containment guidelines.
<linux/debugfs.h> and <linux/kobject.h> are also included unconditionally
even though they are only needed under CONFIG_CMA_DEBUGFS and
CONFIG_CMA_SYSFS respectively. Move the struct cma_kobject definition and
<linux/kobject.h> inside the CONFIG_CMA_SYSFS block, and move
<linux/debugfs.h> inside CONFIG_CMA_DEBUGFS.
Remove spurious trailing semicolons after the empty inline function bodies
in the CONFIG_CMA_SYSFS #else branch.
Add <linux/cma.h> so that MAX_CMA_AREAS and CMA_MAX_NAME are always
available when this header is included.
Signed-off-by: Eamon Sippy <eamon112009@gmail.com>
---
mm/cma.h | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/mm/cma.h b/mm/cma.h
index c70180c36559..0a1cb0141756 100644
--- a/mm/cma.h
+++ b/mm/cma.h
@@ -2,13 +2,24 @@
#ifndef __MM_CMA_H__
#define __MM_CMA_H__
+#include <linux/atomic.h>
+#include <linux/cma.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/spinlock.h>
+
+#ifdef CONFIG_CMA_DEBUGFS
#include <linux/debugfs.h>
+#endif
+
+#ifdef CONFIG_CMA_SYSFS
#include <linux/kobject.h>
struct cma_kobject {
struct kobject kobj;
struct cma *cma;
};
+#endif
/*
* Multi-range support. This can be useful if the size of the allocation
@@ -37,10 +48,10 @@ struct cma_memrange {
#define CMA_MAX_RANGES 8
struct cma {
- unsigned long count;
- unsigned long available_count;
+ unsigned long count;
+ unsigned long available_count;
unsigned int order_per_bit; /* Order of pages represented by one bit */
- spinlock_t lock;
+ spinlock_t lock; /* protects allocation bitmap */
struct mutex alloc_mutex;
#ifdef CONFIG_CMA_DEBUGFS
struct hlist_head mem_head;
@@ -86,10 +97,11 @@ void cma_sysfs_account_fail_pages(struct cma *cma, unsigned long nr_pages);
void cma_sysfs_account_release_pages(struct cma *cma, unsigned long nr_pages);
#else
static inline void cma_sysfs_account_success_pages(struct cma *cma,
- unsigned long nr_pages) {};
+ unsigned long nr_pages) {}
static inline void cma_sysfs_account_fail_pages(struct cma *cma,
- unsigned long nr_pages) {};
+ unsigned long nr_pages) {}
static inline void cma_sysfs_account_release_pages(struct cma *cma,
- unsigned long nr_pages) {};
+ unsigned long nr_pages) {}
#endif
+
#endif
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] mm: cma: make mm/cma.h self-contained and conditionalize includes
2026-08-15 8:40 [PATCH] mm: cma: make mm/cma.h self-contained and conditionalize includes Eamon Sippy
@ 2026-08-15 10:03 ` Barry Song
2026-08-15 10:32 ` [PATCH v2] " Eamon Sippy
1 sibling, 0 replies; 4+ messages in thread
From: Barry Song @ 2026-08-15 10:03 UTC (permalink / raw)
To: Eamon Sippy; +Cc: Andrew Morton, linux-mm, linux-kernel
On Sat, Aug 15, 2026 at 4:41 PM Eamon Sippy <eamon112009@gmail.com> wrote:
>
> mm/cma.h uses types from <linux/spinlock.h>, <linux/mutex.h>,
> <linux/atomic.h> and <linux/list.h> without explicitly including them,
> violating the kernel header self-containment guidelines.
>
> <linux/debugfs.h> and <linux/kobject.h> are also included unconditionally
> even though they are only needed under CONFIG_CMA_DEBUGFS and
> CONFIG_CMA_SYSFS respectively. Move the struct cma_kobject definition and
> <linux/kobject.h> inside the CONFIG_CMA_SYSFS block, and move
> <linux/debugfs.h> inside CONFIG_CMA_DEBUGFS.
>
> Remove spurious trailing semicolons after the empty inline function bodies
> in the CONFIG_CMA_SYSFS #else branch.
>
> Add <linux/cma.h> so that MAX_CMA_AREAS and CMA_MAX_NAME are always
> available when this header is included.
>
> Signed-off-by: Eamon Sippy <eamon112009@gmail.com>
[...]
> + unsigned long available_count;
> unsigned int order_per_bit; /* Order of pages represented by one bit */
> - spinlock_t lock;
> + spinlock_t lock; /* protects allocation bitmap */
I’m not convinced this lock is only for protecting the bitmap. It also
protects things such as cma->available_count and the allocation checks
around page_range_contiguous(). Could we drop the added comment or
use a more accurate description?
> struct mutex alloc_mutex;
Best Regards
Barry
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] mm: cma: make mm/cma.h self-contained and conditionalize includes
2026-08-15 8:40 [PATCH] mm: cma: make mm/cma.h self-contained and conditionalize includes Eamon Sippy
2026-08-15 10:03 ` Barry Song
@ 2026-08-15 10:32 ` Eamon Sippy
2026-08-15 11:35 ` Barry Song
1 sibling, 1 reply; 4+ messages in thread
From: Eamon Sippy @ 2026-08-15 10:32 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-mm, linux-kernel, Eamon Sippy
mm/cma.h uses types from <linux/spinlock.h>, <linux/mutex.h>,
<linux/atomic.h> and <linux/list.h> without explicitly including them,
violating the kernel header self-containment guidelines.
<linux/debugfs.h> and <linux/kobject.h> are also included unconditionally
even though they are only needed under CONFIG_CMA_DEBUGFS and
CONFIG_CMA_SYSFS respectively. Move the struct cma_kobject definition and
<linux/kobject.h> inside the CONFIG_CMA_SYSFS block, and move
<linux/debugfs.h> inside CONFIG_CMA_DEBUGFS.
Remove spurious trailing semicolons after the empty inline function bodies
in the CONFIG_CMA_SYSFS #else branch.
Add <linux/cma.h> so that MAX_CMA_AREAS and CMA_MAX_NAME are always
available when this header is included.
Changes in v2:
- Drop inaccurate spinlock comment; the lock also protects
available_count and allocation checks (Barry)
Signed-off-by: Eamon Sippy <eamon112009@gmail.com>
---
mm/cma.h | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/mm/cma.h b/mm/cma.h
index c70180c36559..68e574b0f951 100644
--- a/mm/cma.h
+++ b/mm/cma.h
@@ -2,13 +2,24 @@
#ifndef __MM_CMA_H__
#define __MM_CMA_H__
+#include <linux/atomic.h>
+#include <linux/cma.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/spinlock.h>
+
+#ifdef CONFIG_CMA_DEBUGFS
#include <linux/debugfs.h>
+#endif
+
+#ifdef CONFIG_CMA_SYSFS
#include <linux/kobject.h>
struct cma_kobject {
struct kobject kobj;
struct cma *cma;
};
+#endif
/*
* Multi-range support. This can be useful if the size of the allocation
@@ -37,10 +48,10 @@ struct cma_memrange {
#define CMA_MAX_RANGES 8
struct cma {
- unsigned long count;
- unsigned long available_count;
+ unsigned long count;
+ unsigned long available_count;
unsigned int order_per_bit; /* Order of pages represented by one bit */
- spinlock_t lock;
+ spinlock_t lock;
struct mutex alloc_mutex;
#ifdef CONFIG_CMA_DEBUGFS
struct hlist_head mem_head;
@@ -86,10 +97,11 @@ void cma_sysfs_account_fail_pages(struct cma *cma, unsigned long nr_pages);
void cma_sysfs_account_release_pages(struct cma *cma, unsigned long nr_pages);
#else
static inline void cma_sysfs_account_success_pages(struct cma *cma,
- unsigned long nr_pages) {};
+ unsigned long nr_pages) {}
static inline void cma_sysfs_account_fail_pages(struct cma *cma,
- unsigned long nr_pages) {};
+ unsigned long nr_pages) {}
static inline void cma_sysfs_account_release_pages(struct cma *cma,
- unsigned long nr_pages) {};
+ unsigned long nr_pages) {}
#endif
+
#endif
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2] mm: cma: make mm/cma.h self-contained and conditionalize includes
2026-08-15 10:32 ` [PATCH v2] " Eamon Sippy
@ 2026-08-15 11:35 ` Barry Song
0 siblings, 0 replies; 4+ messages in thread
From: Barry Song @ 2026-08-15 11:35 UTC (permalink / raw)
To: Eamon Sippy; +Cc: Andrew Morton, linux-mm, linux-kernel
On Sat, Aug 15, 2026 at 6:33 PM Eamon Sippy <eamon112009@gmail.com> wrote:
>
> mm/cma.h uses types from <linux/spinlock.h>, <linux/mutex.h>,
> <linux/atomic.h> and <linux/list.h> without explicitly including them,
> violating the kernel header self-containment guidelines.
>
> <linux/debugfs.h> and <linux/kobject.h> are also included unconditionally
> even though they are only needed under CONFIG_CMA_DEBUGFS and
> CONFIG_CMA_SYSFS respectively. Move the struct cma_kobject definition and
> <linux/kobject.h> inside the CONFIG_CMA_SYSFS block, and move
> <linux/debugfs.h> inside CONFIG_CMA_DEBUGFS.
>
> Remove spurious trailing semicolons after the empty inline function bodies
> in the CONFIG_CMA_SYSFS #else branch.
>
> Add <linux/cma.h> so that MAX_CMA_AREAS and CMA_MAX_NAME are always
> available when this header is included.
>
> Changes in v2:
> - Drop inaccurate spinlock comment; the lock also protects
> available_count and allocation checks (Barry)
>
> Signed-off-by: Eamon Sippy <eamon112009@gmail.com>
> ---
Reviewed-by: Barry Song <baohua@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-15 11:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-15 8:40 [PATCH] mm: cma: make mm/cma.h self-contained and conditionalize includes Eamon Sippy
2026-08-15 10:03 ` Barry Song
2026-08-15 10:32 ` [PATCH v2] " Eamon Sippy
2026-08-15 11:35 ` Barry Song
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.