[PATCH v6 5/8] LoongArch: Allow memblock arrays to resize
From: George Guo
Date: Thu Oct 29 2026 - 13:32:10 EST
From: George Guo <guodongtai@xxxxxxxxxx>
LoongArch never calls memblock_allow_resize(), so the reserved region
array cannot grow beyond INIT_MEMBLOCK_RESERVED_REGIONS entries
(INIT_MEMBLOCK_REGIONS + NR_CPUS).
After kexec, kho_memory_init() reserves every range preserved by KHO.
Each range that is not adjacent to another one needs its own entry, so
with enough scattered preserved pages the array overflows and the
incoming kernel panics:
Kernel panic - not syncing: memblock: cannot resize reserved array
Call Trace:
memblock_double_array+0x2d4/0x2f8
memblock_isolate_range+0x54/0x1a8
memblock_setclr_flag+0x44/0xe0
kho_preserved_memory_reserve+0x78/0xb8
...
kho_memory_init+0xbc/0x394
mm_core_init+0x124/0x154
start_kernel+0x568/0x6dc
The liveupdate luo_stress_files test with 500 files triggers it on a
kernel without CONFIG_SMP, where NR_CPUS is 1. With CONFIG_SMP the
array is larger and the test passes, but more preserved memory still
overflows it.
When the reserved array is full, memblock allocates a bigger array
from free memory. This is only safe once all memory in use has been
reserved, so enable resizing in arch_mem_init() after the firmware,
kernel and initrd reservations are made.
The memory preserved by KHO is reserved later, in kho_memory_init().
A new array cannot land on it either, because kho_populate() already
limits memblock allocations to the KHO bootmem areas, which hold no
preserved data.
Co-developed-by: Kexin Liu <liukexin@xxxxxxxxxx>
Signed-off-by: Kexin Liu <liukexin@xxxxxxxxxx>
Signed-off-by: George Guo <guodongtai@xxxxxxxxxx>
---
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..dff2e0c67ea0 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();
+ /* KHO may restore more reserved regions than the initial array holds. */
+ memblock_allow_resize();
+
memblock_set_bottom_up(true);
swiotlb_init(true, SWIOTLB_VERBOSE);
--
2.53.0