Re: [PATCH v2 7/8] arm64: kdump: use generic interface to simplify crashkernel reservation
On 2023/8/29 20:16, Baoquan He wrote: > With the help of newly changed function parse_crashkernel() and > generic reserve_crashkernel_generic(), crashkernel reservation can be > simplified by steps: > > 1) Add a new header file , and define CRASH_ALIGN, >CRASH_ADDR_LOW_MAX, CRASH_ADDR_HIGH_MAX and >DEFAULT_CRASH_KERNEL_LOW_SIZE in ; > > 2) Add arch_reserve_crashkernel() to call parse_crashkernel() and >reserve_crashkernel_generic(); > > 3) Add ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION Kconfig in >arch/arm64/Kconfig. > > The old reserve_crashkernel_low() and reserve_crashkernel() can be > removed. Reviewed-by: Zhen Lei > > Signed-off-by: Baoquan He > --- > arch/arm64/Kconfig | 3 + > arch/arm64/include/asm/crash_core.h | 10 ++ > arch/arm64/mm/init.c| 140 ++-- > 3 files changed, 21 insertions(+), 132 deletions(-) > create mode 100644 arch/arm64/include/asm/crash_core.h > > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > index 29db061db9bb..07fb8c71339d 100644 > --- a/arch/arm64/Kconfig > +++ b/arch/arm64/Kconfig > @@ -1481,6 +1481,9 @@ config KEXEC_FILE > for kernel and initramfs as opposed to list of segments as > accepted by previous system call. > > +config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION > + def_bool CRASH_CORE > + > config KEXEC_SIG > bool "Verify kernel signature during kexec_file_load() syscall" > depends on KEXEC_FILE > diff --git a/arch/arm64/include/asm/crash_core.h > b/arch/arm64/include/asm/crash_core.h > new file mode 100644 > index ..9f5c8d339f44 > --- /dev/null > +++ b/arch/arm64/include/asm/crash_core.h > @@ -0,0 +1,10 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +#ifndef _ARM64_CRASH_CORE_H > +#define _ARM64_CRASH_CORE_H > + > +/* Current arm64 boot protocol requires 2MB alignment */ > +#define CRASH_ALIGN SZ_2M > + > +#define CRASH_ADDR_LOW_MAX arm64_dma_phys_limit > +#define CRASH_ADDR_HIGH_MAX (PHYS_MASK + 1) > +#endif > diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c > index 4ad637508b75..48ab23531bb6 100644 > --- a/arch/arm64/mm/init.c > +++ b/arch/arm64/mm/init.c > @@ -64,15 +64,6 @@ EXPORT_SYMBOL(memstart_addr); > */ > phys_addr_t __ro_after_init arm64_dma_phys_limit; > > -/* Current arm64 boot protocol requires 2MB alignment */ > -#define CRASH_ALIGN SZ_2M > - > -#define CRASH_ADDR_LOW_MAX arm64_dma_phys_limit > -#define CRASH_ADDR_HIGH_MAX (PHYS_MASK + 1) > -#define CRASH_HIGH_SEARCH_BASE SZ_4G > - > -#define DEFAULT_CRASH_KERNEL_LOW_SIZE(128UL << 20) > - > /* > * To make optimal use of block mappings when laying out the linear > * mapping, round down the base of physical memory to a size that can > @@ -100,140 +91,25 @@ phys_addr_t __ro_after_init arm64_dma_phys_limit; > #define ARM64_MEMSTART_ALIGN (1UL << ARM64_MEMSTART_SHIFT) > #endif > > -static int __init reserve_crashkernel_low(unsigned long long low_size) > -{ > - unsigned long long low_base; > - > - low_base = memblock_phys_alloc_range(low_size, CRASH_ALIGN, 0, > CRASH_ADDR_LOW_MAX); > - if (!low_base) { > - pr_err("cannot allocate crashkernel low memory > (size:0x%llx).\n", low_size); > - return -ENOMEM; > - } > - > - pr_info("crashkernel low memory reserved: 0x%08llx - 0x%08llx (%lld > MB)\n", > - low_base, low_base + low_size, low_size >> 20); > - > - crashk_low_res.start = low_base; > - crashk_low_res.end = low_base + low_size - 1; > - insert_resource(_resource, _low_res); > - > - return 0; > -} > - > -/* > - * reserve_crashkernel() - reserves memory for crash kernel > - * > - * This function reserves memory area given in "crashkernel=" kernel command > - * line parameter. The memory reserved is used by dump capture kernel when > - * primary kernel is crashing. > - */ > -static void __init reserve_crashkernel(void) > +static void __init arch_reserve_crashkernel(void) > { > - unsigned long long crash_low_size = 0, search_base = 0; > - unsigned long long crash_max = CRASH_ADDR_LOW_MAX; > + unsigned long long low_size = 0; > unsigned long long crash_base, crash_size; > char *cmdline = boot_command_line; > - bool fixed_base = false; > bool high = false; > int ret; > > if (!IS_ENABLED(CONFIG_KEXEC_CORE)) > return; > > - /* crashkernel=X[@offset] */ > ret = parse_crashkernel(cmdline, memblock_phys_mem_size(), > - _size, _base, NULL, NULL); > - if (ret == -ENOENT) { > - ret = parse_crashkernel_high(cmdline, 0, _size, > _base); > - if (ret || !crash_size) > - return; > - > - /* > - * crashkernel=Y,low can be specified or not, but invalid value > - * is not allowed. > -
[PATCH v2 7/8] arm64: kdump: use generic interface to simplify crashkernel reservation
With the help of newly changed function parse_crashkernel() and generic reserve_crashkernel_generic(), crashkernel reservation can be simplified by steps: 1) Add a new header file , and define CRASH_ALIGN, CRASH_ADDR_LOW_MAX, CRASH_ADDR_HIGH_MAX and DEFAULT_CRASH_KERNEL_LOW_SIZE in ; 2) Add arch_reserve_crashkernel() to call parse_crashkernel() and reserve_crashkernel_generic(); 3) Add ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION Kconfig in arch/arm64/Kconfig. The old reserve_crashkernel_low() and reserve_crashkernel() can be removed. Signed-off-by: Baoquan He --- arch/arm64/Kconfig | 3 + arch/arm64/include/asm/crash_core.h | 10 ++ arch/arm64/mm/init.c| 140 ++-- 3 files changed, 21 insertions(+), 132 deletions(-) create mode 100644 arch/arm64/include/asm/crash_core.h diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 29db061db9bb..07fb8c71339d 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1481,6 +1481,9 @@ config KEXEC_FILE for kernel and initramfs as opposed to list of segments as accepted by previous system call. +config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION + def_bool CRASH_CORE + config KEXEC_SIG bool "Verify kernel signature during kexec_file_load() syscall" depends on KEXEC_FILE diff --git a/arch/arm64/include/asm/crash_core.h b/arch/arm64/include/asm/crash_core.h new file mode 100644 index ..9f5c8d339f44 --- /dev/null +++ b/arch/arm64/include/asm/crash_core.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ARM64_CRASH_CORE_H +#define _ARM64_CRASH_CORE_H + +/* Current arm64 boot protocol requires 2MB alignment */ +#define CRASH_ALIGN SZ_2M + +#define CRASH_ADDR_LOW_MAX arm64_dma_phys_limit +#define CRASH_ADDR_HIGH_MAX (PHYS_MASK + 1) +#endif diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 4ad637508b75..48ab23531bb6 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -64,15 +64,6 @@ EXPORT_SYMBOL(memstart_addr); */ phys_addr_t __ro_after_init arm64_dma_phys_limit; -/* Current arm64 boot protocol requires 2MB alignment */ -#define CRASH_ALIGNSZ_2M - -#define CRASH_ADDR_LOW_MAX arm64_dma_phys_limit -#define CRASH_ADDR_HIGH_MAX(PHYS_MASK + 1) -#define CRASH_HIGH_SEARCH_BASE SZ_4G - -#define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20) - /* * To make optimal use of block mappings when laying out the linear * mapping, round down the base of physical memory to a size that can @@ -100,140 +91,25 @@ phys_addr_t __ro_after_init arm64_dma_phys_limit; #define ARM64_MEMSTART_ALIGN (1UL << ARM64_MEMSTART_SHIFT) #endif -static int __init reserve_crashkernel_low(unsigned long long low_size) -{ - unsigned long long low_base; - - low_base = memblock_phys_alloc_range(low_size, CRASH_ALIGN, 0, CRASH_ADDR_LOW_MAX); - if (!low_base) { - pr_err("cannot allocate crashkernel low memory (size:0x%llx).\n", low_size); - return -ENOMEM; - } - - pr_info("crashkernel low memory reserved: 0x%08llx - 0x%08llx (%lld MB)\n", - low_base, low_base + low_size, low_size >> 20); - - crashk_low_res.start = low_base; - crashk_low_res.end = low_base + low_size - 1; - insert_resource(_resource, _low_res); - - return 0; -} - -/* - * reserve_crashkernel() - reserves memory for crash kernel - * - * This function reserves memory area given in "crashkernel=" kernel command - * line parameter. The memory reserved is used by dump capture kernel when - * primary kernel is crashing. - */ -static void __init reserve_crashkernel(void) +static void __init arch_reserve_crashkernel(void) { - unsigned long long crash_low_size = 0, search_base = 0; - unsigned long long crash_max = CRASH_ADDR_LOW_MAX; + unsigned long long low_size = 0; unsigned long long crash_base, crash_size; char *cmdline = boot_command_line; - bool fixed_base = false; bool high = false; int ret; if (!IS_ENABLED(CONFIG_KEXEC_CORE)) return; - /* crashkernel=X[@offset] */ ret = parse_crashkernel(cmdline, memblock_phys_mem_size(), - _size, _base, NULL, NULL); - if (ret == -ENOENT) { - ret = parse_crashkernel_high(cmdline, 0, _size, _base); - if (ret || !crash_size) - return; - - /* -* crashkernel=Y,low can be specified or not, but invalid value -* is not allowed. -*/ - ret = parse_crashkernel_low(cmdline, 0, _low_size, _base); - if (ret == -ENOENT) - crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE; - else if (ret) - return; - -