Skip to content

Commit a8fc28d

Browse files
surenbaghdasaryanakpm00
authored andcommitted
alloc_tag: introduce clear_page_tag_ref() helper function
In several cases we are freeing pages which were not allocated using common page allocators. For such cases, in order to keep allocation accounting correct, we should clear the page tag to indicate that the page being freed is expected to not have a valid allocation tag. Introduce clear_page_tag_ref() helper function to be used for this. Link: https://lkml.kernel.org/r/20240813150758.855881-1-surenb@google.com Fixes: d224eb0 ("codetag: debug: mark codetags for reserved pages as empty") Signed-off-by: Suren Baghdasaryan <surenb@google.com> Suggested-by: David Hildenbrand <david@redhat.com> Acked-by: David Hildenbrand <david@redhat.com> Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Kees Cook <keescook@chromium.org> Cc: Kent Overstreet <kent.overstreet@linux.dev> Cc: Sourav Panda <souravpanda@google.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: <stable@vger.kernel.org> [6.10] Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent edb907a commit a8fc28d

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

include/linux/pgalloc_tag.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ static inline void put_page_tag_ref(union codetag_ref *ref)
4343
page_ext_put(page_ext_from_codetag_ref(ref));
4444
}
4545

46+
static inline void clear_page_tag_ref(struct page *page)
47+
{
48+
if (mem_alloc_profiling_enabled()) {
49+
union codetag_ref *ref = get_page_tag_ref(page);
50+
51+
if (ref) {
52+
set_codetag_empty(ref);
53+
put_page_tag_ref(ref);
54+
}
55+
}
56+
}
57+
4658
static inline void pgalloc_tag_add(struct page *page, struct task_struct *task,
4759
unsigned int nr)
4860
{
@@ -126,6 +138,7 @@ static inline void pgalloc_tag_sub_pages(struct alloc_tag *tag, unsigned int nr)
126138

127139
static inline union codetag_ref *get_page_tag_ref(struct page *page) { return NULL; }
128140
static inline void put_page_tag_ref(union codetag_ref *ref) {}
141+
static inline void clear_page_tag_ref(struct page *page) {}
129142
static inline void pgalloc_tag_add(struct page *page, struct task_struct *task,
130143
unsigned int nr) {}
131144
static inline void pgalloc_tag_sub(struct page *page, unsigned int nr) {}

mm/mm_init.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,15 +2459,7 @@ void __init memblock_free_pages(struct page *page, unsigned long pfn,
24592459
}
24602460

24612461
/* pages were reserved and not allocated */
2462-
if (mem_alloc_profiling_enabled()) {
2463-
union codetag_ref *ref = get_page_tag_ref(page);
2464-
2465-
if (ref) {
2466-
set_codetag_empty(ref);
2467-
put_page_tag_ref(ref);
2468-
}
2469-
}
2470-
2462+
clear_page_tag_ref(page);
24712463
__free_pages_core(page, order, MEMINIT_EARLY);
24722464
}
24732465

mm/page_alloc.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5815,14 +5815,7 @@ unsigned long free_reserved_area(void *start, void *end, int poison, const char
58155815

58165816
void free_reserved_page(struct page *page)
58175817
{
5818-
if (mem_alloc_profiling_enabled()) {
5819-
union codetag_ref *ref = get_page_tag_ref(page);
5820-
5821-
if (ref) {
5822-
set_codetag_empty(ref);
5823-
put_page_tag_ref(ref);
5824-
}
5825-
}
5818+
clear_page_tag_ref(page);
58265819
ClearPageReserved(page);
58275820
init_page_count(page);
58285821
__free_page(page);

0 commit comments

Comments
 (0)