Commit 18e98e56 authored by Barry Song's avatar Barry Song Committed by Linus Torvalds

mm: cma: fix the name of CMA areas

Patch series "mm: fix the names of general cma and hugetlb cma", v2.

The current code of CMA can only work when users pass a const string as
name parameter.  we need to fix the way to handle names in CMA.  On the
other hand, to avoid name conflicts after enabling CMA_DEBUGFS, each
hugetlb should get a different CMA name.

This patch (of 2):

If users give a name saved in stack, the current code will generate magic
pointer.  if users don't give a name(NULL), kasprintf() will always return
NULL as we are at the early stage.  that means cma_init_reserved_mem()
will return -ENOMEM if users set name parameter as NULL.

[natechancellor@gmail.com: return cma->name directly in cma_get_name]
  Link: https://github.com/ClangBuiltLinux/linux/issues/1063
  Link: http://lkml.kernel.org/r/20200623015840.621964-1-natechancellor@gmail.comSigned-off-by: default avatarBarry Song <song.bao.hua@hisilicon.com>
Signed-off-by: default avatarNathan Chancellor <natechancellor@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
Acked-by: default avatarRoman Gushchin <guro@fb.com>
Link: http://lkml.kernel.org/r/20200616223131.33828-2-song.bao.hua@hisilicon.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 835832ba
...@@ -52,7 +52,7 @@ unsigned long cma_get_size(const struct cma *cma) ...@@ -52,7 +52,7 @@ unsigned long cma_get_size(const struct cma *cma)
const char *cma_get_name(const struct cma *cma) const char *cma_get_name(const struct cma *cma)
{ {
return cma->name ? cma->name : "(undefined)"; return cma->name;
} }
static unsigned long cma_bitmap_aligned_mask(const struct cma *cma, static unsigned long cma_bitmap_aligned_mask(const struct cma *cma,
...@@ -202,13 +202,12 @@ int __init cma_init_reserved_mem(phys_addr_t base, phys_addr_t size, ...@@ -202,13 +202,12 @@ int __init cma_init_reserved_mem(phys_addr_t base, phys_addr_t size,
* subsystems (like slab allocator) are available. * subsystems (like slab allocator) are available.
*/ */
cma = &cma_areas[cma_area_count]; cma = &cma_areas[cma_area_count];
if (name) {
cma->name = name; if (name)
} else { snprintf(cma->name, CMA_MAX_NAME, name);
cma->name = kasprintf(GFP_KERNEL, "cma%d\n", cma_area_count); else
if (!cma->name) snprintf(cma->name, CMA_MAX_NAME, "cma%d\n", cma_area_count);
return -ENOMEM;
}
cma->base_pfn = PFN_DOWN(base); cma->base_pfn = PFN_DOWN(base);
cma->count = size >> PAGE_SHIFT; cma->count = size >> PAGE_SHIFT;
cma->order_per_bit = order_per_bit; cma->order_per_bit = order_per_bit;
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include <linux/debugfs.h> #include <linux/debugfs.h>
#define CMA_MAX_NAME 64
struct cma { struct cma {
unsigned long base_pfn; unsigned long base_pfn;
unsigned long count; unsigned long count;
...@@ -15,7 +17,7 @@ struct cma { ...@@ -15,7 +17,7 @@ struct cma {
spinlock_t mem_head_lock; spinlock_t mem_head_lock;
struct debugfs_u32_array dfs_bitmap; struct debugfs_u32_array dfs_bitmap;
#endif #endif
const char *name; char name[CMA_MAX_NAME];
}; };
extern struct cma cma_areas[MAX_CMA_AREAS]; extern struct cma cma_areas[MAX_CMA_AREAS];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment