Skip to content

Commit d224eb0

Browse files
surenbaghdasaryanakpm00
authored andcommitted
codetag: debug: mark codetags for reserved pages as empty
To avoid debug warnings while freeing reserved pages which were not allocated with usual allocators, mark their codetags as empty before freeing. Link: https://lkml.kernel.org/r/20240321163705.3067592-35-surenb@google.com Signed-off-by: Suren Baghdasaryan <surenb@google.com> Reviewed-by: Kees Cook <keescook@chromium.org> Tested-by: Kees Cook <keescook@chromium.org> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Alex Gaynor <alex.gaynor@gmail.com> Cc: Alice Ryhl <aliceryhl@google.com> Cc: Andreas Hindborg <a.hindborg@samsung.com> Cc: Benno Lossin <benno.lossin@proton.me> Cc: "Björn Roy Baron" <bjorn3_gh@protonmail.com> Cc: Boqun Feng <boqun.feng@gmail.com> Cc: Christoph Lameter <cl@linux.com> Cc: Dennis Zhou <dennis@kernel.org> Cc: Gary Guo <gary@garyguo.net> Cc: Kent Overstreet <kent.overstreet@linux.dev> Cc: Miguel Ojeda <ojeda@kernel.org> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Tejun Heo <tj@kernel.org> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Wedson Almeida Filho <wedsonaf@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 239d6c9 commit d224eb0

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

include/linux/alloc_tag.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static inline void set_codetag_empty(union codetag_ref *ref)
4747
#else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */
4848

4949
static inline bool is_codetag_empty(union codetag_ref *ref) { return false; }
50+
static inline void set_codetag_empty(union codetag_ref *ref) {}
5051

5152
#endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */
5253

include/linux/mm.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/errno.h>
66
#include <linux/mmdebug.h>
77
#include <linux/gfp.h>
8+
#include <linux/pgalloc_tag.h>
89
#include <linux/bug.h>
910
#include <linux/list.h>
1011
#include <linux/mmzone.h>
@@ -3134,6 +3135,14 @@ extern void reserve_bootmem_region(phys_addr_t start,
31343135
/* Free the reserved page into the buddy system, so it gets managed. */
31353136
static inline void free_reserved_page(struct page *page)
31363137
{
3138+
if (mem_alloc_profiling_enabled()) {
3139+
union codetag_ref *ref = get_page_tag_ref(page);
3140+
3141+
if (ref) {
3142+
set_codetag_empty(ref);
3143+
put_page_tag_ref(ref);
3144+
}
3145+
}
31373146
ClearPageReserved(page);
31383147
init_page_count(page);
31393148
__free_page(page);

include/linux/pgalloc_tag.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ static inline void pgalloc_tag_sub_pages(struct alloc_tag *tag, unsigned int nr)
120120

121121
#else /* CONFIG_MEM_ALLOC_PROFILING */
122122

123+
static inline union codetag_ref *get_page_tag_ref(struct page *page) { return NULL; }
124+
static inline void put_page_tag_ref(union codetag_ref *ref) {}
123125
static inline void pgalloc_tag_add(struct page *page, struct task_struct *task,
124126
unsigned int nr) {}
125127
static inline void pgalloc_tag_sub(struct page *page, unsigned int nr) {}

mm/mm_init.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2567,7 +2567,6 @@ void __init set_dma_reserve(unsigned long new_dma_reserve)
25672567
void __init memblock_free_pages(struct page *page, unsigned long pfn,
25682568
unsigned int order)
25692569
{
2570-
25712570
if (IS_ENABLED(CONFIG_DEFERRED_STRUCT_PAGE_INIT)) {
25722571
int nid = early_pfn_to_nid(pfn);
25732572

@@ -2579,6 +2578,17 @@ void __init memblock_free_pages(struct page *page, unsigned long pfn,
25792578
/* KMSAN will take care of these pages. */
25802579
return;
25812580
}
2581+
2582+
/* pages were reserved and not allocated */
2583+
if (mem_alloc_profiling_enabled()) {
2584+
union codetag_ref *ref = get_page_tag_ref(page);
2585+
2586+
if (ref) {
2587+
set_codetag_empty(ref);
2588+
put_page_tag_ref(ref);
2589+
}
2590+
}
2591+
25822592
__free_pages_core(page, order);
25832593
}
25842594

0 commit comments

Comments
 (0)