Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [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)
  0 siblings, 1 reply; 2+ 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] 2+ 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)
  0 siblings, 0 replies; 2+ 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] 2+ messages in thread

end of thread, other threads:[~2026-11-19  8:52 UTC | newest]

Thread overview: 2+ 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)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox