Skip to content

Commit deb9922

Browse files
committed
mm/codetag: clear tags before swap
JIRA: https://issues.redhat.com/browse/RHEL-78135 commit 640a603 Author: David Wang <00107082@163.com> Date: Fri Dec 13 09:33:32 2024 +0800 mm/codetag: clear tags before swap When CONFIG_MEM_ALLOC_PROFILING_DEBUG is set, kernel WARN would be triggered when calling __alloc_tag_ref_set() during swap: alloc_tag was not cleared (got tag for mm/filemap.c:1951) WARNING: CPU: 0 PID: 816 at ./include/linux/alloc_tag.h... Clear code tags before swap can fix the warning. And this patch also fix a potential invalid address dereference in alloc_tag_add_check() when CONFIG_MEM_ALLOC_PROFILING_DEBUG is set and ref->ct is CODETAG_EMPTY, which is defined as ((void *)1). Link: https://lkml.kernel.org/r/20241213013332.89910-1-00107082@163.com Fixes: 51f43d5 ("mm/codetag: swap tags when migrate pages") Signed-off-by: David Wang <00107082@163.com> Reported-by: kernel test robot <oliver.sang@intel.com> Closes: https://lore.kernel.org/oe-lkp/202412112227.df61ebb-lkp@intel.com Acked-by: Suren Baghdasaryan <surenb@google.com> Cc: Kent Overstreet <kent.overstreet@linux.dev> Cc: Yu Zhao <yuzhao@google.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Luiz Capitulino <luizcap@redhat.com>
1 parent 39cadff commit deb9922

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

include/linux/alloc_tag.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static inline struct alloc_tag_counters alloc_tag_read(struct alloc_tag *tag)
140140
#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG
141141
static inline void alloc_tag_add_check(union codetag_ref *ref, struct alloc_tag *tag)
142142
{
143-
WARN_ONCE(ref && ref->ct,
143+
WARN_ONCE(ref && ref->ct && !is_codetag_empty(ref),
144144
"alloc_tag was not cleared (got tag for %s:%u)\n",
145145
ref->ct->filename, ref->ct->lineno);
146146

lib/alloc_tag.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ void pgalloc_tag_swap(struct folio *new, struct folio *old)
209209
return;
210210
}
211211

212+
/*
213+
* Clear tag references to avoid debug warning when using
214+
* __alloc_tag_ref_set() with non-empty reference.
215+
*/
216+
set_codetag_empty(&ref_old);
217+
set_codetag_empty(&ref_new);
218+
212219
/* swap tags */
213220
__alloc_tag_ref_set(&ref_old, tag_new);
214221
update_page_tag_ref(handle_old, &ref_old);

0 commit comments

Comments
 (0)