aboutsummaryrefslogtreecommitdiffstats
path: root/lib/alloc_tag.c
diff options
context:
space:
mode:
authorDavid Wang <[email protected]>2024-12-13 01:33:32 +0000
committerAndrew Morton <[email protected]>2024-12-19 03:04:46 +0000
commit640a603943a7659340c10044c0a1c98ae4e13189 (patch)
treefbe3be6535a01d7f7dd285216a8ccef7db88d521 /lib/alloc_tag.c
parentmm/vmstat: fix a W=1 clang compiler warning (diff)
downloadkernel-640a603943a7659340c10044c0a1c98ae4e13189.tar.gz
kernel-640a603943a7659340c10044c0a1c98ae4e13189.zip
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/[email protected] Fixes: 51f43d5d82ed ("mm/codetag: swap tags when migrate pages") Signed-off-by: David Wang <[email protected]> Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-lkp/[email protected] Acked-by: Suren Baghdasaryan <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: Yu Zhao <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
Diffstat (limited to 'lib/alloc_tag.c')
-rw-r--r--lib/alloc_tag.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c
index 35f7560a309a..3a0413462e9f 100644
--- a/lib/alloc_tag.c
+++ b/lib/alloc_tag.c
@@ -209,6 +209,13 @@ void pgalloc_tag_swap(struct folio *new, struct folio *old)
return;
}
+ /*
+ * Clear tag references to avoid debug warning when using
+ * __alloc_tag_ref_set() with non-empty reference.
+ */
+ set_codetag_empty(&ref_old);
+ set_codetag_empty(&ref_new);
+
/* swap tags */
__alloc_tag_ref_set(&ref_old, tag_new);
update_page_tag_ref(handle_old, &ref_old);