Skip to content

Commit 0b2cf0a

Browse files
osalvadorvilardagaakpm00
authored andcommitted
mm,page_owner: defer enablement of static branch
Kefeng Wang reported that he was seeing some memory leaks with kmemleak with page_owner enabled. The reason is that we enable the page_owner_inited static branch and then proceed with the linking of stack_list struct to dummy_stack, which means that exists a race window between these two steps where we can have pages already being allocated calling add_stack_record_to_list(), allocating objects and linking them to stack_list, but then we set stack_list pointing to dummy_stack in init_page_owner. Which means that the objects that have been allocated during that time window are unreferenced and lost. Fix this by deferring the enablement of the branch until we have properly set up the list. Link: https://lkml.kernel.org/r/[email protected] Fixes: 4bedfb3 ("mm,page_owner: maintain own list of stack_records structs") Signed-off-by: Oscar Salvador <[email protected]> Reported-by: Kefeng Wang <[email protected]> Closes: https://lore.kernel.org/linux-mm/[email protected]/ Tested-by: Kefeng Wang <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 9253c54 commit 0b2cf0a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mm/page_owner.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ static __init void init_page_owner(void)
118118
register_dummy_stack();
119119
register_failure_stack();
120120
register_early_stack();
121-
static_branch_enable(&page_owner_inited);
122121
init_early_allocated_pages();
123122
/* Initialize dummy and failure stacks and link them to stack_list */
124123
dummy_stack.stack_record = __stack_depot_get_stack_record(dummy_handle);
@@ -129,6 +128,7 @@ static __init void init_page_owner(void)
129128
refcount_set(&failure_stack.stack_record->count, 1);
130129
dummy_stack.next = &failure_stack;
131130
stack_list = &dummy_stack;
131+
static_branch_enable(&page_owner_inited);
132132
}
133133

134134
struct page_ext_operations page_owner_ops = {

0 commit comments

Comments
 (0)