* [PATCH] LoongArch: Allow memblock arrays to resize
@ 2026-11-19 10:02 George Guo
2026-11-19 11:07 ` Mike Rapoport
2026-11-19 12:05 ` Huacai Chen
0 siblings, 2 replies; 3+ messages in thread
From: George Guo @ 2026-11-19 10:02 UTC (permalink / raw)
To: chenhuacai, kernel
Cc: rppt, liukexin, guodongtai, loongarch, linux-mm, linux-kernel
From: George Guo <guodongtai@kylinos.cn>
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@kylinos.cn>
Signed-off-by: Kexin Liu <liukexin@kylinos.cn>
Signed-off-by: George Guo <guodongtai@kylinos.cn>
---
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@linux.dev/
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] LoongArch: Allow memblock arrays to resize
2026-11-19 10:02 [PATCH] LoongArch: Allow memblock arrays to resize George Guo
@ 2026-11-19 11:07 ` Mike Rapoport
2026-11-19 12:05 ` Huacai Chen
1 sibling, 0 replies; 3+ messages in thread
From: Mike Rapoport @ 2026-11-19 11:07 UTC (permalink / raw)
To: George Guo
Cc: chenhuacai, kernel, liukexin, guodongtai, loongarch, linux-mm,
linux-kernel
On Thu, Nov 19, 2026 at 07:02:16PM +0900, George Guo wrote:
> From: George Guo <guodongtai@kylinos.cn>
>
> 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@kylinos.cn>
> Signed-off-by: Kexin Liu <liukexin@kylinos.cn>
> Signed-off-by: George Guo <guodongtai@kylinos.cn>
> ---
> 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@linux.dev/
>
> 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);
The placement seems about right to me :)
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> swiotlb_init(true, SWIOTLB_VERBOSE);
>
> base-commit: 422e532809572ba1043192bf6a0c653bc68b3140
> --
> 2.53.0
>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] LoongArch: Allow memblock arrays to resize
2026-11-19 10:02 [PATCH] LoongArch: Allow memblock arrays to resize George Guo
2026-11-19 11:07 ` Mike Rapoport
@ 2026-11-19 12:05 ` Huacai Chen
1 sibling, 0 replies; 3+ messages in thread
From: Huacai Chen @ 2026-11-19 12:05 UTC (permalink / raw)
To: George Guo
Cc: kernel, rppt, liukexin, guodongtai, loongarch, linux-mm, linux-kernel
Hi, George,
On Thu, Nov 19, 2026 at 6:02 PM George Guo <dongtai.guo@linux.dev> wrote:
>
> From: George Guo <guodongtai@kylinos.cn>
>
> 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@kylinos.cn>
> Signed-off-by: Kexin Liu <liukexin@kylinos.cn>
> Signed-off-by: George Guo <guodongtai@kylinos.cn>
> ---
> 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@linux.dev/
>
> 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();
Would you mind if I move it between memblock_dump_all() and
memblock_set_bottom_up(false)?
Huacai
> +
> memblock_set_bottom_up(true);
>
> swiotlb_init(true, SWIOTLB_VERBOSE);
>
> base-commit: 422e532809572ba1043192bf6a0c653bc68b3140
> --
> 2.53.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-19 12:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 10:02 [PATCH] LoongArch: Allow memblock arrays to resize George Guo
2026-11-19 11:07 ` Mike Rapoport
2026-11-19 12:05 ` Huacai Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®