* [PATCH 0/3] alloc_tag: two fixes and one cleanup
@ 2026-11-19 8:52 David Hildenbrand (Arm)
2026-11-19 8:52 ` [PATCH 1/3] alloc_tag: handle a NULL tag in alloc_tag_set_inaccurate() David Hildenbrand (Arm)
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-19 8:52 UTC (permalink / raw)
To: Suren Baghdasaryan, Hao Ge, Vlastimil Babka, Johannes Weiner,
Michal Hocko, Brendan Jackman, Zi Yan, Andrew Morton, Usama Arif,
Shakeel Butt, Harry Yoo, Hao Li, Christoph Lameter,
David Rientjes, Roman Gushchin
Cc: linux-mm, David Hildenbrand (Arm), stable, Chris Mason
Hi,
two fixes (one for alloc_tag as triggered by slab, one for mempool) and
one related cleanup to make things consistent.
Quickly reproduced and tested the warnings in a x86-64 VM.
This should go through Andrew's tree. No need to rush, it can wait until
the next merge window.
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
Chris Mason (1):
mempool: fix missing alloc tagging in mempool_resize()
David Hildenbrand (Arm) (2):
alloc_tag: handle a NULL tag in alloc_tag_set_inaccurate()
mempool: account the element array to the caller
include/linux/alloc_tag.h | 3 ++-
include/linux/mempool.h | 7 +++----
mm/mempool.c | 23 ++++++++++++-----------
mm/page_alloc.c | 3 +--
4 files changed, 18 insertions(+), 18 deletions(-)
---
base-commit: 4405c18c95d2d0f99f6c581ef0ee8591a1aa6ccd
change-id: 20261119-alloc_tag-57326f1fcc85
Best regards,
--
David Hildenbrand (Arm) <david@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] alloc_tag: handle a NULL tag in alloc_tag_set_inaccurate()
2026-11-19 8:52 [PATCH 0/3] alloc_tag: two fixes and one cleanup David Hildenbrand (Arm)
@ 2026-11-19 8:52 ` David Hildenbrand (Arm)
2026-11-19 8:52 ` [PATCH 2/3] mempool: fix missing alloc tagging in mempool_resize() David Hildenbrand (Arm)
2026-11-19 8:52 ` [PATCH 3/3] mempool: account the element array to the caller David Hildenbrand (Arm)
2 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-19 8:52 UTC (permalink / raw)
To: Suren Baghdasaryan, Hao Ge, Vlastimil Babka, Johannes Weiner,
Michal Hocko, Brendan Jackman, Zi Yan, Andrew Morton, Usama Arif,
Shakeel Butt, Harry Yoo, Hao Li, Christoph Lameter,
David Rientjes, Roman Gushchin
Cc: linux-mm, David Hildenbrand (Arm), stable, Chris Mason
With memory allocation profiling enabled after boot, a slab allocation
can dereference a NULL pointer if current->alloc_tag is not set and
allocating the slab object extensions fails:
__alloc_tagging_slab_alloc_hook() passes current->alloc_tag to
alloc_tag_set_inaccurate(), which does not handle a NULL tag currently.
One way to trigger it is through rhashtable: rhashtable_init() records
current->alloc_tag in ht->alloc_tag, which is NULL while profiling is
disabled. Once profiling gets enabled, alloc_hooks_tag() sets
current->alloc_tag to that NULL tag when allocating a bucket table.
Fix it by handling NULL tags in alloc_tag_set_inaccurate(), just
like alloc_tag_add() and alloc_tag_sub() already do, and drop the now
unnecessary check in __pgalloc_tag_add().
This has low urgency.
Fixes: b9e2f58ffb84 ("alloc_tag: mark inaccurate allocation counters in /proc/allocinfo output")
Cc: stable@vger.kernel.org
Reported-by: Chris Mason <mason@kernel.org>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
include/linux/alloc_tag.h | 3 ++-
mm/page_alloc.c | 3 +--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h
index 7f2d80a597924..0f9909c6701a7 100644
--- a/include/linux/alloc_tag.h
+++ b/include/linux/alloc_tag.h
@@ -227,7 +227,8 @@ static inline void alloc_tag_sub(union codetag_ref *ref, size_t bytes)
static inline void alloc_tag_set_inaccurate(struct alloc_tag *tag)
{
- tag->ct.flags |= CODETAG_FLAG_INACCURATE;
+ if (tag)
+ tag->ct.flags |= CODETAG_FLAG_INACCURATE;
}
static inline bool alloc_tag_is_inaccurate(struct alloc_tag *tag)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 2fef4092c913c..0b76923145456 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1262,8 +1262,7 @@ void __pgalloc_tag_add(struct page *page, struct task_struct *task,
* clear the tag ref later when page_ext is initialized.
*/
alloc_tag_add_early_pfn(page_to_pfn(page), alloc_flags);
- if (task->alloc_tag)
- alloc_tag_set_inaccurate(task->alloc_tag);
+ alloc_tag_set_inaccurate(task->alloc_tag);
}
}
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] mempool: fix missing alloc tagging in mempool_resize()
2026-11-19 8:52 [PATCH 0/3] alloc_tag: two fixes and one cleanup David Hildenbrand (Arm)
2026-11-19 8:52 ` [PATCH 1/3] alloc_tag: handle a NULL tag in alloc_tag_set_inaccurate() David Hildenbrand (Arm)
@ 2026-11-19 8:52 ` David Hildenbrand (Arm)
2026-11-19 8:52 ` [PATCH 3/3] mempool: account the element array to the caller David Hildenbrand (Arm)
2 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-19 8:52 UTC (permalink / raw)
To: Suren Baghdasaryan, Hao Ge, Vlastimil Babka, Johannes Weiner,
Michal Hocko, Brendan Jackman, Zi Yan, Andrew Morton, Usama Arif,
Shakeel Butt, Harry Yoo, Hao Li, Christoph Lameter,
David Rientjes, Roman Gushchin
Cc: linux-mm, David Hildenbrand (Arm), Chris Mason
From: Chris Mason <mason@kernel.org>
With memory allocation profiling enabled, mempool_resize() allocates new
elements without an allocation tag: mempool_alloc_slab() and friends
use the _noprof allocators and rely on the caller to have set
current->alloc_tag.
Unlike mempool_init() or mempool_alloc(), mempool_resize() is not an
alloc_hooks() wrapper, though.
Therefore, the newly allocated elements are missing from /proc/allocinfo,
and with CONFIG_MEM_ALLOC_PROFILING_DEBUG=y we can trigger
"current->alloc_tag not set" and "alloc_tag was not set" warnings.
Fix it by turning mempool_resize() into an alloc_hooks() wrapper, just
like the other mempool functions that allocate elements.
This has low urgency.
Fixes: e26d8769da6d ("mempool: hook up to memory allocation profiling")
Signed-off-by: Chris Mason <mason@kernel.org>
[ david: adjust description, remove kmalloc_objs() change ]
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
include/linux/mempool.h | 4 +++-
mm/mempool.c | 4 ++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/include/linux/mempool.h b/include/linux/mempool.h
index 6da502aef2f71..5444dcb63efa8 100644
--- a/include/linux/mempool.h
+++ b/include/linux/mempool.h
@@ -59,7 +59,9 @@ struct mempool *mempool_create_node_noprof(int min_nr,
mempool_create_node(_min_nr, _alloc_fn, _free_fn, _pool_data, \
GFP_KERNEL, NUMA_NO_NODE)
-int mempool_resize(struct mempool *pool, int new_min_nr);
+int mempool_resize_noprof(struct mempool *pool, int new_min_nr);
+#define mempool_resize(...) \
+ alloc_hooks(mempool_resize_noprof(__VA_ARGS__))
void mempool_destroy(struct mempool *pool);
void *mempool_alloc_noprof(struct mempool *pool, gfp_t gfp_mask) __malloc;
diff --git a/mm/mempool.c b/mm/mempool.c
index cb74e718b2c65..5e0ba516efdbf 100644
--- a/mm/mempool.c
+++ b/mm/mempool.c
@@ -361,7 +361,7 @@ EXPORT_SYMBOL(mempool_create_node_noprof);
*
* Return: %0 on success, negative error code otherwise.
*/
-int mempool_resize(struct mempool *pool, int new_min_nr)
+int mempool_resize_noprof(struct mempool *pool, int new_min_nr)
{
void *element;
void **new_elements;
@@ -420,7 +420,7 @@ int mempool_resize(struct mempool *pool, int new_min_nr)
out:
return 0;
}
-EXPORT_SYMBOL(mempool_resize);
+EXPORT_SYMBOL(mempool_resize_noprof);
static unsigned int mempool_alloc_from_pool(struct mempool *pool, void **elems,
unsigned int count, unsigned int allocated,
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] mempool: account the element array to the caller
2026-11-19 8:52 [PATCH 0/3] alloc_tag: two fixes and one cleanup David Hildenbrand (Arm)
2026-11-19 8:52 ` [PATCH 1/3] alloc_tag: handle a NULL tag in alloc_tag_set_inaccurate() David Hildenbrand (Arm)
2026-11-19 8:52 ` [PATCH 2/3] mempool: fix missing alloc tagging in mempool_resize() David Hildenbrand (Arm)
@ 2026-11-19 8:52 ` David Hildenbrand (Arm)
2 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-19 8:52 UTC (permalink / raw)
To: Suren Baghdasaryan, Hao Ge, Vlastimil Babka, Johannes Weiner,
Michal Hocko, Brendan Jackman, Zi Yan, Andrew Morton, Usama Arif,
Shakeel Butt, Harry Yoo, Hao Li, Christoph Lameter,
David Rientjes, Roman Gushchin
Cc: linux-mm, David Hildenbrand (Arm)
mempool_create_node() accounts the struct mempool and all elements to
the caller, but the array of element pointers allocated by
mempool_init_node() and mempool_resize() ends up being accounted to
mm/mempool.c in /proc/allocinfo.
Let's consistently account all mempool allocations to the caller, like
ptr_ring_init() and ptr_ring_resize() do, by using the _noprof variants.
mempool_init_node() is only called from mempool_init_noprof() and
mempool_create_node_noprof(), which already set the allocation tag.
While at it, make mempool_init_node() static and rename it to
mempool_init_node_noprof(): it is not used outside of mm/mempool.c, and
calling it without an allocation tag would be wrong.
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
include/linux/mempool.h | 3 ---
mm/mempool.c | 19 ++++++++++---------
2 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/include/linux/mempool.h b/include/linux/mempool.h
index 5444dcb63efa8..7f8e257017c01 100644
--- a/include/linux/mempool.h
+++ b/include/linux/mempool.h
@@ -38,9 +38,6 @@ static inline bool mempool_is_saturated(struct mempool *pool)
}
void mempool_exit(struct mempool *pool);
-int mempool_init_node(struct mempool *pool, int min_nr,
- mempool_alloc_t *alloc_fn, mempool_free_t *free_fn,
- void *pool_data, gfp_t gfp_mask, int node_id);
int mempool_init_noprof(struct mempool *pool, int min_nr,
mempool_alloc_t *alloc_fn, mempool_free_t *free_fn,
void *pool_data);
diff --git a/mm/mempool.c b/mm/mempool.c
index 5e0ba516efdbf..30cbe44d464b3 100644
--- a/mm/mempool.c
+++ b/mm/mempool.c
@@ -243,7 +243,7 @@ void mempool_destroy(struct mempool *pool)
}
EXPORT_SYMBOL(mempool_destroy);
-int mempool_init_node(struct mempool *pool, int min_nr,
+static int mempool_init_node_noprof(struct mempool *pool, int min_nr,
mempool_alloc_t *alloc_fn, mempool_free_t *free_fn,
void *pool_data, gfp_t gfp_mask, int node_id)
{
@@ -257,8 +257,9 @@ int mempool_init_node(struct mempool *pool, int min_nr,
* max() used here to ensure storage for at least 1 element to support
* zero minimum pool
*/
- pool->elements = kmalloc_array_node(max(1, min_nr), sizeof(void *),
- gfp_mask, node_id);
+ pool->elements = kmalloc_array_node_noprof(max(1, min_nr),
+ sizeof(void *), gfp_mask,
+ node_id);
if (!pool->elements)
return -ENOMEM;
@@ -279,7 +280,6 @@ int mempool_init_node(struct mempool *pool, int min_nr,
return 0;
}
-EXPORT_SYMBOL(mempool_init_node);
/**
* mempool_init - initialize a memory pool
@@ -299,8 +299,8 @@ int mempool_init_noprof(struct mempool *pool, int min_nr,
mempool_alloc_t *alloc_fn, mempool_free_t *free_fn,
void *pool_data)
{
- return mempool_init_node(pool, min_nr, alloc_fn, free_fn,
- pool_data, GFP_KERNEL, NUMA_NO_NODE);
+ return mempool_init_node_noprof(pool, min_nr, alloc_fn, free_fn,
+ pool_data, GFP_KERNEL, NUMA_NO_NODE);
}
EXPORT_SYMBOL(mempool_init_noprof);
@@ -333,8 +333,8 @@ struct mempool *mempool_create_node_noprof(int min_nr,
if (!pool)
return NULL;
- if (mempool_init_node(pool, min_nr, alloc_fn, free_fn, pool_data,
- gfp_mask, node_id)) {
+ if (mempool_init_node_noprof(pool, min_nr, alloc_fn, free_fn,
+ pool_data, gfp_mask, node_id)) {
kfree(pool);
return NULL;
}
@@ -384,7 +384,8 @@ int mempool_resize_noprof(struct mempool *pool, int new_min_nr)
spin_unlock_irqrestore(&pool->lock, flags);
/* Grow the pool */
- new_elements = kmalloc_objs(*new_elements, new_min_nr);
+ new_elements = kmalloc_array_noprof(new_min_nr, sizeof(*new_elements),
+ GFP_KERNEL);
if (!new_elements)
return -ENOMEM;
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-19 8:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 8:52 [PATCH 0/3] alloc_tag: two fixes and one cleanup David Hildenbrand (Arm)
2026-11-19 8:52 ` [PATCH 1/3] alloc_tag: handle a NULL tag in alloc_tag_set_inaccurate() David Hildenbrand (Arm)
2026-11-19 8:52 ` [PATCH 2/3] mempool: fix missing alloc tagging in mempool_resize() David Hildenbrand (Arm)
2026-11-19 8:52 ` [PATCH 3/3] mempool: account the element array to the caller David Hildenbrand (Arm)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox