* [PATCH v2] mm: Move kvmalloc-related functions to slab.h
@ 2021-06-22 21:57 Matthew Wilcox (Oracle)
2021-06-23 6:52 ` Pekka Enberg
0 siblings, 1 reply; 2+ messages in thread
From: Matthew Wilcox (Oracle) @ 2021-06-22 21:57 UTC (permalink / raw)
To: Andrew Morton, linux-mm, linux-kernel, Vlastimil Babka,
Joonsoo Kim, David Rientjes, Pekka Enberg, Christoph Lameter
Cc: Matthew Wilcox (Oracle)
Not all files in the kernel should include mm.h. Migrating callers from
kmalloc to kvmalloc is easier if the kvmalloc functions are in slab.h.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
v2: allmodconfig revealed someone calling kvmalloc without slab.h. It
doesn't include mm.h either, but clearly it's being included through
some indirect path.
drivers/of/kexec.c | 1 +
include/linux/mm.h | 32 --------------------------------
include/linux/slab.h | 32 ++++++++++++++++++++++++++++++++
3 files changed, 33 insertions(+), 32 deletions(-)
diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c
index f335d941a716..b90660c05f30 100644
--- a/drivers/of/kexec.c
+++ b/drivers/of/kexec.c
@@ -16,6 +16,7 @@
#include <linux/of.h>
#include <linux/of_fdt.h>
#include <linux/random.h>
+#include <linux/slab.h>
#include <linux/types.h>
/* relevant device tree properties */
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8ae31622deef..750a6f227ec7 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -798,38 +798,6 @@ static inline int is_vmalloc_or_module_addr(const void *x)
}
#endif
-extern void *kvmalloc_node(size_t size, gfp_t flags, int node);
-static inline void *kvmalloc(size_t size, gfp_t flags)
-{
- return kvmalloc_node(size, flags, NUMA_NO_NODE);
-}
-static inline void *kvzalloc_node(size_t size, gfp_t flags, int node)
-{
- return kvmalloc_node(size, flags | __GFP_ZERO, node);
-}
-static inline void *kvzalloc(size_t size, gfp_t flags)
-{
- return kvmalloc(size, flags | __GFP_ZERO);
-}
-
-static inline void *kvmalloc_array(size_t n, size_t size, gfp_t flags)
-{
- size_t bytes;
-
- if (unlikely(check_mul_overflow(n, size, &bytes)))
- return NULL;
-
- return kvmalloc(bytes, flags);
-}
-
-static inline void *kvcalloc(size_t n, size_t size, gfp_t flags)
-{
- return kvmalloc_array(n, size, flags | __GFP_ZERO);
-}
-
-extern void kvfree(const void *addr);
-extern void kvfree_sensitive(const void *addr, size_t len);
-
static inline int head_compound_mapcount(struct page *head)
{
return atomic_read(compound_mapcount_ptr(head)) + 1;
diff --git a/include/linux/slab.h b/include/linux/slab.h
index 0c97d788762c..ee676de68afe 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -697,6 +697,38 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
return kmalloc_node(size, flags | __GFP_ZERO, node);
}
+void *kvmalloc_node(size_t size, gfp_t flags, int node);
+static inline void *kvmalloc(size_t size, gfp_t flags)
+{
+ return kvmalloc_node(size, flags, NUMA_NO_NODE);
+}
+static inline void *kvzalloc_node(size_t size, gfp_t flags, int node)
+{
+ return kvmalloc_node(size, flags | __GFP_ZERO, node);
+}
+static inline void *kvzalloc(size_t size, gfp_t flags)
+{
+ return kvmalloc(size, flags | __GFP_ZERO);
+}
+
+static inline void *kvmalloc_array(size_t n, size_t size, gfp_t flags)
+{
+ size_t bytes;
+
+ if (unlikely(check_mul_overflow(n, size, &bytes)))
+ return NULL;
+
+ return kvmalloc(bytes, flags);
+}
+
+static inline void *kvcalloc(size_t n, size_t size, gfp_t flags)
+{
+ return kvmalloc_array(n, size, flags | __GFP_ZERO);
+}
+
+void kvfree(const void *addr);
+void kvfree_sensitive(const void *addr, size_t len);
+
unsigned int kmem_cache_size(struct kmem_cache *s);
void __init kmem_cache_init_late(void);
--
2.30.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] mm: Move kvmalloc-related functions to slab.h
2021-06-22 21:57 [PATCH v2] mm: Move kvmalloc-related functions to slab.h Matthew Wilcox (Oracle)
@ 2021-06-23 6:52 ` Pekka Enberg
0 siblings, 0 replies; 2+ messages in thread
From: Pekka Enberg @ 2021-06-23 6:52 UTC (permalink / raw)
To: Matthew Wilcox (Oracle)
Cc: Andrew Morton, linux-mm, LKML, Vlastimil Babka, Joonsoo Kim,
David Rientjes, Christoph Lameter
On Wed, Jun 23, 2021 at 12:58 AM Matthew Wilcox (Oracle)
<willy@infradead.org> wrote:
> Not all files in the kernel should include mm.h. Migrating callers from
> kmalloc to kvmalloc is easier if the kvmalloc functions are in slab.h.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Acked-by: Pekka Enberg <penberg@kernel.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-06-23 6:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-22 21:57 [PATCH v2] mm: Move kvmalloc-related functions to slab.h Matthew Wilcox (Oracle)
2021-06-23 6:52 ` Pekka Enberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox