]> git.itanic.dy.fi Git - linux-stable/commit
mm,page_owner: defer enablement of static branch
authorOscar Salvador <osalvador@suse.de>
Tue, 9 Apr 2024 13:17:15 +0000 (15:17 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 16 Apr 2024 22:39:51 +0000 (15:39 -0700)
commit0b2cf0a45e06d9538a2371f90150297a87b20eea
treef3cb26ea80ee0551477fc25d4c81dd1f3471741a
parent9253c54e01b6505d348afbc02abaa4d9f8a01395
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/20240409131715.13632-1-osalvador@suse.de
Fixes: 4bedfb314bdd ("mm,page_owner: maintain own list of stack_records structs")
Signed-off-by: Oscar Salvador <osalvador@suse.de>
Reported-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Closes: https://lore.kernel.org/linux-mm/74b147b0-718d-4d50-be75-d6afc801cd24@huawei.com/
Tested-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/page_owner.c