Skip to content

Commit 82ff165

Browse files
Bhupesh Sharmatorvalds
authored andcommitted
mm/memcontrol: fix OOPS inside mem_cgroup_get_nr_swap_pages()
Prabhakar reported an OOPS inside mem_cgroup_get_nr_swap_pages() function in a corner case seen on some arm64 boards when kdump kernel runs with "cgroup_disable=memory" passed to the kdump kernel via bootargs. The root-cause behind the same is that currently mem_cgroup_swap_init() function is implemented as a subsys_initcall() call instead of a core_initcall(), this means 'cgroup_memory_noswap' still remains set to the default value (false) even when memcg is disabled via "cgroup_disable=memory" boot parameter. This may result in premature OOPS inside mem_cgroup_get_nr_swap_pages() function in corner cases: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000188 Mem abort info: ESR = 0x96000006 EC = 0x25: DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 Data abort info: ISV = 0, ISS = 0x00000006 CM = 0, WnR = 0 [0000000000000188] user address but active_mm is swapper Internal error: Oops: 96000006 [#1] SMP Modules linked in: <..snip..> Call trace: mem_cgroup_get_nr_swap_pages+0x9c/0xf4 shrink_lruvec+0x404/0x4f8 shrink_node+0x1a8/0x688 do_try_to_free_pages+0xe8/0x448 try_to_free_pages+0x110/0x230 __alloc_pages_slowpath.constprop.106+0x2b8/0xb48 __alloc_pages_nodemask+0x2ac/0x2f8 alloc_page_interleave+0x20/0x90 alloc_pages_current+0xdc/0xf8 atomic_pool_expand+0x60/0x210 __dma_atomic_pool_init+0x50/0xa4 dma_atomic_pool_init+0xac/0x158 do_one_initcall+0x50/0x218 kernel_init_freeable+0x22c/0x2d0 kernel_init+0x18/0x110 ret_from_fork+0x10/0x18 Code: aa1403e3 91106000 97f82a27 14000011 (f940c663) ---[ end trace 9795948475817de4 ]--- Kernel panic - not syncing: Fatal exception Rebooting in 10 seconds.. Fixes: eccb52e ("mm: memcontrol: prepare swap controller setup for integration") Reported-by: Prabhakar Kushwaha <[email protected]> Signed-off-by: Bhupesh Sharma <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Vladimir Davydov <[email protected]> Cc: James Morse <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Will Deacon <[email protected]> Cc: Catalin Marinas <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 45779b0 commit 82ff165

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

mm/memcontrol.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7186,6 +7186,13 @@ static struct cftype memsw_files[] = {
71867186
{ }, /* terminate */
71877187
};
71887188

7189+
/*
7190+
* If mem_cgroup_swap_init() is implemented as a subsys_initcall()
7191+
* instead of a core_initcall(), this could mean cgroup_memory_noswap still
7192+
* remains set to false even when memcg is disabled via "cgroup_disable=memory"
7193+
* boot parameter. This may result in premature OOPS inside
7194+
* mem_cgroup_get_nr_swap_pages() function in corner cases.
7195+
*/
71897196
static int __init mem_cgroup_swap_init(void)
71907197
{
71917198
/* No memory control -> no swap control */
@@ -7200,6 +7207,6 @@ static int __init mem_cgroup_swap_init(void)
72007207

72017208
return 0;
72027209
}
7203-
subsys_initcall(mem_cgroup_swap_init);
7210+
core_initcall(mem_cgroup_swap_init);
72047211

72057212
#endif /* CONFIG_MEMCG_SWAP */

0 commit comments

Comments
 (0)