Skip to content

Commit 05b94ca

Browse files
riteshharjanimpe
authored andcommitted
powerpc/fadump: Move fadump_cma_init to setup_arch() after initmem_init()
During early init CMA_MIN_ALIGNMENT_BYTES can be PAGE_SIZE, since pageblock_order is still zero and it gets initialized later during initmem_init() e.g. setup_arch() -> initmem_init() -> sparse_init() -> set_pageblock_order() One such use case where this causes issue is - early_setup() -> early_init_devtree() -> fadump_reserve_mem() -> fadump_cma_init() This causes CMA memory alignment check to be bypassed in cma_init_reserved_mem(). Then later cma_activate_area() can hit a VM_BUG_ON_PAGE(pfn & ((1 << order) - 1)) if the reserved memory area was not pageblock_order aligned. Fix it by moving the fadump_cma_init() after initmem_init(), where other such cma reservations also gets called. <stack trace> ============== page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10010 flags: 0x13ffff800000000(node=1|zone=0|lastcpupid=0x7ffff) CMA raw: 013ffff800000000 5deadbeef0000100 5deadbeef0000122 0000000000000000 raw: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: VM_BUG_ON_PAGE(pfn & ((1 << order) - 1)) ------------[ cut here ]------------ kernel BUG at mm/page_alloc.c:778! Call Trace: __free_one_page+0x57c/0x7b0 (unreliable) free_pcppages_bulk+0x1a8/0x2c8 free_unref_page_commit+0x3d4/0x4e4 free_unref_page+0x458/0x6d0 init_cma_reserved_pageblock+0x114/0x198 cma_init_reserved_areas+0x270/0x3e0 do_one_initcall+0x80/0x2f8 kernel_init_freeable+0x33c/0x530 kernel_init+0x34/0x26c ret_from_kernel_user_thread+0x14/0x1c Fixes: 11ac3e8 ("mm: cma: use pageblock_order as the single alignment") Suggested-by: David Hildenbrand <[email protected]> Reported-by: Sachin P Bappalige <[email protected]> Acked-by: Hari Bathini <[email protected]> Reviewed-by: Madhavan Srinivasan <[email protected]> Signed-off-by: Ritesh Harjani (IBM) <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://patch.msgid.link/3ae208e48c0d9cefe53d2dc4f593388067405b7d.1729146153.git.ritesh.list@gmail.com
1 parent 6faeac5 commit 05b94ca

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

arch/powerpc/include/asm/fadump.h

+7
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@ extern int early_init_dt_scan_fw_dump(unsigned long node, const char *uname,
3434
int depth, void *data);
3535
extern int fadump_reserve_mem(void);
3636
#endif
37+
38+
#if defined(CONFIG_FA_DUMP) && defined(CONFIG_CMA)
39+
void fadump_cma_init(void);
40+
#else
41+
static inline void fadump_cma_init(void) { }
42+
#endif
43+
3744
#endif /* _ASM_POWERPC_FADUMP_H */

arch/powerpc/kernel/fadump.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static struct cma *fadump_cma;
7878
* But for some reason even if it fails we still have the memory reservation
7979
* with us and we can still continue doing fadump.
8080
*/
81-
static void __init fadump_cma_init(void)
81+
void __init fadump_cma_init(void)
8282
{
8383
unsigned long long base, size, end;
8484
int rc;
@@ -139,8 +139,6 @@ static void __init fadump_cma_init(void)
139139
fw_dump.boot_memory_size >> 20);
140140
return;
141141
}
142-
#else
143-
static void __init fadump_cma_init(void) { }
144142
#endif /* CONFIG_CMA */
145143

146144
/*
@@ -642,8 +640,6 @@ int __init fadump_reserve_mem(void)
642640

643641
pr_info("Reserved %lldMB of memory at %#016llx (System RAM: %lldMB)\n",
644642
(size >> 20), base, (memblock_phys_mem_size() >> 20));
645-
646-
fadump_cma_init();
647643
}
648644

649645
return ret;

arch/powerpc/kernel/setup-common.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -997,9 +997,11 @@ void __init setup_arch(char **cmdline_p)
997997
initmem_init();
998998

999999
/*
1000-
* Reserve large chunks of memory for use by CMA for KVM and hugetlb. These must
1001-
* be called after initmem_init(), so that pageblock_order is initialised.
1000+
* Reserve large chunks of memory for use by CMA for fadump, KVM and
1001+
* hugetlb. These must be called after initmem_init(), so that
1002+
* pageblock_order is initialised.
10021003
*/
1004+
fadump_cma_init();
10031005
kvm_cma_reserve();
10041006
gigantic_hugetlb_cma_reserve();
10051007

0 commit comments

Comments
 (0)