LoongArch: Allow memblock arrays to resize
Subsystems (2)
PATCH 1/1 LoongArch: Allow memblock arrays to resize
From: George Guo <[email protected]>
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.
---
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/[email protected]/
arch/loongarch/kernel/setup.c | 3 +++ 1 file changed, 3 insertions(+)
arch/loongarch/kernel/setup.c +3 -0
@@ -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
Signature · 1 line
2.53.0
Quoted 48 lines · George Guo
From: George Guo <[email protected]>
LoongArch never calls
memblock_allow_resize(), so the memblock region arrays cannot grow beyond their static sizes. For the reserved array that isINIT_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 arrayThe 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()callsarch_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 <[email protected]>Signed-off-by Kexin Liu <[email protected]>Signed-off-by George Guo <[email protected]>---
This was patch 5/8 of the LoongArch KHO series v6 [1]. Mike suggested fixing it independently of KHO, and Huacai preferredarch_mem_init()toplatform_init()[1].KHO for LoongArch needs this: after kexec,
kho_memory_init()reserves every preserved range, andluo_stress_fileswith 500 files overflows the reserved array withoutCONFIG_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/[email protected]/
arch/loongarch/kernel/setup.c | 3 +++ 1 file changed, 3 insertions(+)arch/loongarch/kernel/setup.c +0
-0
arch/loongarch/kernel/setup.c static void __init arch_mem_init(char **cmdline_p) · line 408
Quoted 7 lines
arch/loongarch/kernel/setup.c +3
-0@@ -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 :)
Quoted 6 lines
arch/loongarch/kernel/setup.c +0
-0swiotlb_init (true,SWIOTLB_VERBOSE );base-commit:
422e532809572ba1043192bf6a0c653bc68b3140Signature · 1 line
2.53.0
Signature · 2 lines
Sincerely yours, Mike.
Huacai Chen
maintainerHi, George,
Quoted 49 lines · George Guo
From: George Guo <[email protected]>
LoongArch never calls
memblock_allow_resize(), so the memblock region arrays cannot grow beyond their static sizes. For the reserved array that isINIT_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 arrayThe 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()callsarch_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 <[email protected]>Signed-off-by Kexin Liu <[email protected]>Signed-off-by George Guo <[email protected]>---
This was patch 5/8 of the LoongArch KHO series v6 [1]. Mike suggested fixing it independently of KHO, and Huacai preferredarch_mem_init()toplatform_init()[1].KHO for LoongArch needs this: after kexec,
kho_memory_init()reserves every preserved range, andluo_stress_fileswith 500 files overflows the reserved array withoutCONFIG_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/[email protected]/
arch/loongarch/kernel/setup.c | 3 +++ 1 file changed, 3 insertions(+)arch/loongarch/kernel/setup.c +0
-0
arch/loongarch/kernel/setup.c static void __init arch_mem_init(char **cmdline_p) · line 406
Quoted 5 lines
arch/loongarch/kernel/setup.c +2
-0@@ -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
Quoted 9 lines
arch/loongarch/kernel/setup.c +1
-0+memblock_set_bottom_up (true);swiotlb_init (true,SWIOTLB_VERBOSE );base-commit:
422e532809572ba1043192bf6a0c653bc68b3140--
2.53.0
Hi Huacai,
Quoted 2 lines · Huacai Chen
Would you mind if I move it between
memblock_dump_all()andmemblock_set_bottom_up(false)?
Not at all, please go ahead. KHO still works with it there, since kho_memory_init() runs after setup_arch().
Thanks,
George
Quoted 9 lines · George Guo
Hi Huacai,
Quoted 2 lines · Huacai Chen
Would you mind if I move it between
memblock_dump_all()andmemblock_set_bottom_up(false)?Not at all, please go ahead. KHO still works with it there, since
kho_memory_init()runs aftersetup_arch().
Applied, thanks.
Huacai
Quoted 3 lines
Thanks,
George