[PATCH] LoongArch: Allow memblock arrays to resize
From: George Guo
Date: Thu Nov 19 2026 - 05:02:29 EST
From: George Guo <guodongtai@xxxxxxxxxx>
LoongArch never calls memblock_allow_resize(), so the memblock region
arrays cannot grow beyond their static sizes. For the reserved array
that is INIT_MEMBLOCK_RESERVED_REGIONS (INIT_MEMBLOCK_REGIONS +
NR_CPUS) entries. Once it is full, the next reservation that needs a
new region panics:
Kernel panic - not syncing: memblock: cannot resize reserved array
The memory setup code was derived from MIPS, which never enables
resizing either. Nothing on LoongArch needs the arrays to stay static.
When an array is full, memblock allocates a bigger one from free
memory, so resizing is only safe once all memory in use is reserved.
By the time setup_arch() calls arch_mem_init(), the kernel image, the
initrd, the firmware memory map, the device tree reserved-memory
regions and the crash kernel are reserved, so enable resizing there.
Co-developed-by: Kexin Liu <liukexin@xxxxxxxxxx>
Signed-off-by: Kexin Liu <liukexin@xxxxxxxxxx>
Signed-off-by: George Guo <guodongtai@xxxxxxxxxx>
---
This was patch 5/8 of the LoongArch KHO series v6 [1]. Mike suggested
fixing it independently of KHO, and Huacai preferred arch_mem_init()
to platform_init() [1].
KHO for LoongArch needs this: after kexec, kho_memory_init() reserves
every preserved range, and luo_stress_files with 500 files overflows
the reserved array without CONFIG_SMP. A bigger array cannot land on
preserved memory, because KHO limits memblock allocations to its
bootmem areas by then.
Changes since v6 5/8:
- Sent on its own, without the KHO series.
- Reworded the commit message and the comment so they do not depend
on KHO.
[1] https://lore.kernel.org/all/20261029172956.20791-6-dongtai.guo@xxxxxxxxx/
arch/loongarch/kernel/setup.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c
index 6fa4a22a58fd..8c33346a123a 100644
--- a/arch/loongarch/kernel/setup.c
+++ b/arch/loongarch/kernel/setup.c
@@ -402,6 +402,9 @@ static void __init arch_mem_init(char **cmdline_p)
check_kernel_sections_mem();
+ /* All memory in use is reserved now, so memblock can grow its arrays. */
+ memblock_allow_resize();
+
memblock_set_bottom_up(true);
swiotlb_init(true, SWIOTLB_VERBOSE);
base-commit: 422e532809572ba1043192bf6a0c653bc68b3140
--
2.53.0