Skip to content

Commit

Permalink
fadump: Move fadump_cma_init after initmem_init
Browse files Browse the repository at this point in the history
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 is where this causes issues 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 call to 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

Suggested-by: David Hildenbrand <[email protected]>
Reported-by: Sachin P Bappalige <[email protected]>
Signed-off-by: Ritesh Harjani (IBM) <[email protected]>
  • Loading branch information
riteshharjani committed Oct 10, 2024
1 parent 54514b9 commit f24fd4a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
7 changes: 7 additions & 0 deletions arch/powerpc/include/asm/fadump.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ extern int early_init_dt_scan_fw_dump(unsigned long node, const char *uname,
int depth, void *data);
extern int fadump_reserve_mem(void);
#endif

#if defined(CONFIG_FA_DUMP) && defined(CONFIG_CMA)
void fadump_cma_init(void);
#else
void fadump_cma_init(void) { }

Check failure on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (mpc885_ads_defconfig, korg-5.5.0)

no previous prototype for 'fadump_cma_init' [-Werror=missing-prototypes]

Check failure on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (mpc885_ads_defconfig, fedora-40)

no previous prototype for 'fadump_cma_init' [-Werror=missing-prototypes]

Check failure on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (mpc885_ads_defconfig, fedora-40)

no previous prototype for 'fadump_cma_init' [-Werror=missing-prototypes]

Check failure on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (corenet32_smp_defconfig, fedora-40)

no previous prototype for 'fadump_cma_init' [-Werror=missing-prototypes]

Check failure on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (corenet64_smp_defconfig, fedora-40)

no previous prototype for 'fadump_cma_init' [-Werror=missing-prototypes]

Check failure on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (g5_defconfig, korg-5.5.0, /linux/arch/powerpc/configs/g5-qemu.config)

no previous prototype for 'fadump_cma_init' [-Werror=missing-prototypes]

Check failure on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (corenet64_smp_defconfig, korg-5.5.0)

no previous prototype for 'fadump_cma_init' [-Werror=missing-prototypes]

Check failure on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (g5_defconfig, fedora-40, /linux/arch/powerpc/configs/g5-qemu.config)

no previous prototype for 'fadump_cma_init' [-Werror=missing-prototypes]

Check warning on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (mpc885_ads, fedora-40, ppc64)

no previous prototype for function 'fadump_cma_init' [-Wmissing-prototypes]

Check warning on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (mpc885_ads, fedora-40, ppc64)

no previous prototype for function 'fadump_cma_init' [-Wmissing-prototypes]

Check warning on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (mpc885_ads, fedora-40, ppc64)

no previous prototype for function 'fadump_cma_init' [-Wmissing-prototypes]

Check warning on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (pmac32, fedora-40, ppc64)

no previous prototype for function 'fadump_cma_init' [-Wmissing-prototypes]

Check warning on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (pmac32, fedora-40, ppc64)

no previous prototype for function 'fadump_cma_init' [-Wmissing-prototypes]

Check warning on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (pmac32, fedora-40, ppc64)

no previous prototype for function 'fadump_cma_init' [-Wmissing-prototypes]

Check warning on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (corenet64_smp, fedora-40, ppc64)

no previous prototype for function 'fadump_cma_init' [-Wmissing-prototypes]

Check warning on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (corenet64_smp, fedora-40, ppc64)

no previous prototype for function 'fadump_cma_init' [-Wmissing-prototypes]

Check warning on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (corenet64_smp, fedora-40, ppc64)

no previous prototype for function 'fadump_cma_init' [-Wmissing-prototypes]

Check warning on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (corenet64_smp, fedora-40, ppc64)

no previous prototype for function 'fadump_cma_init' [-Wmissing-prototypes]

Check warning on line 41 in arch/powerpc/include/asm/fadump.h

View workflow job for this annotation

GitHub Actions / kernel (corenet64_smp, fedora-40, ppc64)

no previous prototype for function 'fadump_cma_init' [-Wmissing-prototypes]
#endif

#endif /* _ASM_POWERPC_FADUMP_H */
6 changes: 1 addition & 5 deletions arch/powerpc/kernel/fadump.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static struct cma *fadump_cma;
* But for some reason even if it fails we still have the memory reservation
* with us and we can still continue doing fadump.
*/
static void __init fadump_cma_init(void)
void __init fadump_cma_init(void)
{
unsigned long long base, size, end;
int rc;
Expand Down Expand Up @@ -141,8 +141,6 @@ static void __init fadump_cma_init(void)
fw_dump.boot_memory_size >> 20);
return;
}
#else
static void __init fadump_cma_init(void) { }
#endif /* CONFIG_CMA */

/*
Expand Down Expand Up @@ -644,8 +642,6 @@ int __init fadump_reserve_mem(void)

pr_info("Reserved %lldMB of memory at %#016llx (System RAM: %lldMB)\n",
(size >> 20), base, (memblock_phys_mem_size() >> 20));

fadump_cma_init();
}

return ret;
Expand Down
6 changes: 4 additions & 2 deletions arch/powerpc/kernel/setup-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -997,9 +997,11 @@ void __init setup_arch(char **cmdline_p)
initmem_init();

/*
* Reserve large chunks of memory for use by CMA for KVM and hugetlb. These must
* be called after initmem_init(), so that pageblock_order is initialised.
* Reserve large chunks of memory for use by CMA for fadump, KVM and
* hugetlb. These must be called after initmem_init(), so that
* pageblock_order is initialised.
*/
fadump_cma_init();
kvm_cma_reserve();
gigantic_hugetlb_cma_reserve();

Expand Down

0 comments on commit f24fd4a

Please sign in to comment.