kdump: use generic functions to simplify crashkernel reservation in arch
Subsystems (13)
v3 cover kdump: use generic functions to simplify crashkernel reservation in arch
In the current arm64, crashkernel=,high support has been finished after several rounds of posting and careful reviewing. The code in arm64 which parses crashkernel kernel parameters firstly, then reserve memory can be a good example for other ARCH to refer to.
Whereas in x86_64, the code mixing crashkernel parameter parsing and memory reserving is twisted, and looks messy. Refactoring the code to make it more readable maintainable is necessary.
Here, firstly abstract the crashkernel parameter parsing code into parse_crashkernel() to make it be able to parse crashkernel=,high|low. Then abstract the crashkernel memory reserving code into a generic function reserve_crashkernel_generic(). Finally, in ARCH which crashkernel=,high support is needed, a simple arch_reserve_crashkernel() can be added to call above two functions. This can remove the duplicated implmentation code in each ARCH, like arm64, x86_64 and riscv.
I only did testing on x86_64 and arm64 for below cases, haven't tested riscv. If riscv people can help apply the patchset and give it a shot, it would be great.
crashkernel=512M,high
crashkernel=512M,high crashkernel=256M,low
crashkernel=512M,high crashkernel=0M,low
crashkernel=0M,high crashkernel=256M,low
crashkernel=512M
crashkernel=512M@0x4f000000
crashkernel=1G-4G:256M,4G-64G:320M,64G-:576M
crashkernel=0M
History:v2->v3:
- Move crashk_res and crashk_low_res codes into crash_core.c, and add <asm/crash_core.h> including in <linux/crash_core.h>. These two fix compiling error reported by LKP when CONFIG_CRASH_CORE=on while CONFIG_KEXEC_CORE is unset.
- Adjust the if-else and return logic in parse_crashkernel() according to Lei's suggestion.
- Make riscv use the generic interface to simplify crahskernel reservation code too since crashkernel=,high support has been added into riscv.
- Some minor changes suggested by Lei.
v1->v2:
- Change to add asm/crash_core.h into x86 and arm64 to contain those arch specific macro definitions for generic reservaton. This fixes the compiling error reported by LKP in v1.
https://lore.kernel.org/all/[email protected]/T/#u
- Fix a log typo in patch 8, thanks to Samuel.
- RFC->v1:
https://lore.kernel.org/all/[email protected]/T/#u
[RFC PATCH 0/4] kdump: add generic functions to simplify crashkernel crashkernel in architecture Dave and Philipp commented the old parse_crashkernel_common() and parse_crashkernel_generic() are quite confusing. In this formal post,
I made change to address the concern by unifying all crashkernel
parsing into parse_crashkernel().
Baoquan He (9):
crash_core.c: remove unnecessary parameter of function
crash_core: change the prototype of function parse_crashkernel()
crash_core: change parse_crashkernel() to support
crashkernel=,high|low parsing
crash_core: add generic function to do reservation
crash_core: move crashk_*res definition into crash_core.c
x86: kdump: use generic interface to simplify crashkernel reservation
code
arm64: kdump: use generic interface to simplify crashkernel
reservation
riscv: kdump: use generic interface to simplify crashkernel
reservation
crash_core.c: remove unneeded functions
arch/arm/kernel/setup.c | 3 +- arch/arm64/Kconfig | 3 + arch/arm64/include/asm/crash_core.h | 10 ++ arch/arm64/mm/init.c | 140 ++------------------ arch/ia64/kernel/setup.c | 2 +- arch/loongarch/kernel/setup.c | 4 +- arch/mips/kernel/setup.c | 3 +- arch/powerpc/kernel/fadump.c | 2 +- arch/powerpc/kexec/core.c | 2 +- arch/powerpc/mm/nohash/kaslr_booke.c | 2 +- arch/riscv/Kconfig | 3 + arch/riscv/include/asm/crash_core.h | 11 ++ arch/riscv/include/asm/processor.h | 2 + arch/riscv/mm/init.c | 141 ++------------------ arch/s390/kernel/setup.c | 4 +- arch/sh/kernel/machine_kexec.c | 2 +- arch/x86/Kconfig | 3 + arch/x86/include/asm/crash_core.h | 34 +++++ arch/x86/kernel/setup.c | 143 +++------------------ include/linux/crash_core.h | 49 ++++++- include/linux/kexec.h | 4 - kernel/crash_core.c | 184 ++++++++++++++++++++++++--- kernel/kexec_core.c | 17 --- 23 files changed, 321 insertions(+), 447 deletions(-) create mode 100644 arch/arm64/include/asm/crash_core.h create mode 100644 arch/riscv/include/asm/crash_core.h create mode 100644 arch/x86/include/asm/crash_core.h
Signature · 7 lines
2.41.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v3 1/9 crash_core.c: remove unnecessary parameter of function
In all call sites of __parse_crashkernel(), the parameter 'name' is hardcoded as "crashkernel=". So remove the unnecessary parameter 'name', add local varibale 'name' inside __parse_crashkernel() instead.
--- kernel/crash_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/crash_core.c +4 -4
@@ -248,11 +248,11 @@ static int __init __parse_crashkernel(char *cmdline,unsigned long long system_ram, unsigned long long *crash_size, unsigned long long *crash_base, - const char *name, const char *suffix) { char *first_colon, *first_space;char *ck_cmdline; +char *name ="crashkernel=" ;BUG_ON (!crash_size || !crash_base); *crash_size =0 ;
@@ -290,7 +290,7 @@ int __init parse_crashkernel(char *cmdline, unsigned long long *crash_base) {return __parse_crashkernel (cmdline, system_ram, crash_size, crash_base, -"crashkernel=" ,NULL ); +NULL ); } int __init parse_crashkernel_high(char *cmdline,
@@ -299,7 +299,7 @@ int __init parse_crashkernel_high(char *cmdline, unsigned long long *crash_base) {return __parse_crashkernel (cmdline, system_ram, crash_size, crash_base, -"crashkernel=" , suffix_tbl[SUFFIX_HIGH ]); + suffix_tbl[SUFFIX_HIGH ]); } int __init parse_crashkernel_low(char *cmdline,
@@ -308,7 +308,7 @@ int __init parse_crashkernel_low(char *cmdline, unsigned long long *crash_base) {return __parse_crashkernel (cmdline, system_ram, crash_size, crash_base, -"crashkernel=" , suffix_tbl[SUFFIX_LOW ]); + suffix_tbl[SUFFIX_LOW ]); }/*
Signature · 7 lines
2.41.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v3 2/9 crash_core: change the prototype of function parse_crashkernel()
In reply to Baoquan HeAdd two parameters 'low_size' and 'high' to function parse_crashkernel(), later crashkernel=,high|low parsing will be added. Make adjustments in all call sites of parse_crashkernel() in arch.
--- arch/arm/kernel/setup.c | 3 ++- arch/arm64/mm/init.c | 2 +- arch/ia64/kernel/setup.c | 2 +- arch/loongarch/kernel/setup.c | 4 +++- arch/mips/kernel/setup.c | 3 ++- arch/powerpc/kernel/fadump.c | 2 +- arch/powerpc/kexec/core.c | 2 +- arch/powerpc/mm/nohash/kaslr_booke.c | 2 +- arch/riscv/mm/init.c | 2 +- arch/s390/kernel/setup.c | 4 ++-- arch/sh/kernel/machine_kexec.c | 2 +- arch/x86/kernel/setup.c | 3 ++- include/linux/crash_core.h | 3 ++- kernel/crash_core.c | 15 ++++++++++++--- 14 files changed, 32 insertions(+), 17 deletions(-)
arch/arm/kernel/setup.c +2 -1
@@ -1010,7 +1010,8 @@ static void __init reserve_crashkernel(void) total_mem =get_total_mem (); ret =parse_crashkernel (boot_command_line, total_mem, - &crash_size, &crash_base); + &crash_size, &crash_base, +NULL ,NULL );/* invalid value specified or crashkernel=0 */ if (ret || !crash_size)return ;
arch/arm64/mm/init.c +1 -1
@@ -142,7 +142,7 @@ static void __init reserve_crashkernel(void)/* crashkernel=X[@offset] */ ret =parse_crashkernel (cmdline,memblock_phys_mem_size (), - &crash_size, &crash_base); + &crash_size, &crash_base,NULL ,NULL );if (ret == -ENOENT ) { ret =parse_crashkernel_high (cmdline,0 , &crash_size, &crash_base);if (ret || !crash_size)
arch/ia64/kernel/setup.c +1 -1
@@ -277,7 +277,7 @@ static void __init setup_crashkernel(unsigned long total, int *n)int ret; ret =parse_crashkernel (boot_command_line, total, - &size, &base); + &size, &base,NULL ,NULL );if (ret ==0 && size >0 ) {if (!base) {sort_regions (rsvd_region, *n);
arch/loongarch/kernel/setup.c +3 -1
@@ -267,7 +267,9 @@ static void __init arch_parse_crashkernel(void)unsigned long long crash_base, crash_size; total_mem =memblock_phys_mem_size (); - ret =parse_crashkernel (boot_command_line, total_mem, &crash_size, &crash_base); + ret =parse_crashkernel (boot_command_line, total_mem, + &crash_size, &crash_base, +NULL ,NULL );if (ret <0 || crash_size <=0 )return ;
arch/mips/kernel/setup.c +2 -1
@@ -460,7 +460,8 @@ static void __init mips_parse_crashkernel(void) total_mem =memblock_phys_mem_size (); ret =parse_crashkernel (boot_command_line, total_mem, - &crash_size, &crash_base); + &crash_size, &crash_base, +NULL ,NULL );if (ret !=0 || crash_size <=0 )return ;
arch/powerpc/kernel/fadump.c +1 -1
@@ -313,7 +313,7 @@ static __init u64 fadump_calculate_reserve_size(void)* memory at a predefined offset. */ ret =parse_crashkernel (boot_command_line,memblock_phys_mem_size (), - &size, &base); + &size, &base,NULL ,NULL );if (ret ==0 && size >0 ) {unsigned long max_size;
arch/powerpc/kexec/core.c +1 -1
@@ -109,7 +109,7 @@ void __init reserve_crashkernel(void) total_mem_sz = memory_limit ? memory_limit :memblock_phys_mem_size ();/* use common parsing */ ret =parse_crashkernel (boot_command_line, total_mem_sz, - &crash_size, &crash_base); + &crash_size, &crash_base,NULL ,NULL );if (ret ==0 && crash_size >0 ) { crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size -1 ;
arch/powerpc/mm/nohash/kaslr_booke.c +1 -1
@@ -178,7 +178,7 @@ static void __init get_crash_kernel(void *fdt, unsigned long size)int ret; ret =parse_crashkernel (boot_command_line, size, &crash_size, - &crash_base); + &crash_base,NULL ,NULL );if (ret !=0 || crash_size ==0 )return ;if (crash_base ==0 )
arch/riscv/mm/init.c +1 -1
@@ -1388,7 +1388,7 @@ static void __init reserve_crashkernel(void) } ret =parse_crashkernel (cmdline,memblock_phys_mem_size (), - &crash_size, &crash_base); + &crash_size, &crash_base,NULL ,NULL );if (ret == -ENOENT ) {/* Fallback to crashkernel=X,[high,low] */ ret =parse_crashkernel_high (cmdline,0 , &crash_size, &crash_base);
arch/s390/kernel/setup.c +2 -2
@@ -625,8 +625,8 @@ static void __init reserve_crashkernel(void)phys_addr_t low, high;int rc; - rc =parse_crashkernel (boot_command_line, ident_map_size, &crash_size, - &crash_base); + rc =parse_crashkernel (boot_command_line, ident_map_size, + &crash_size, &crash_base,NULL ,NULL ); crash_base =ALIGN (crash_base,KEXEC_CRASH_MEM_ALIGN ); crash_size =ALIGN (crash_size,KEXEC_CRASH_MEM_ALIGN );
arch/sh/kernel/machine_kexec.c +1 -1
@@ -154,7 +154,7 @@ void __init reserve_crashkernel(void)int ret; ret =parse_crashkernel (boot_command_line,memblock_phys_mem_size (), - &crash_size, &crash_base); + &crash_size, &crash_base,NULL ,NULL );if (ret ==0 && crash_size >0 ) { crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size -1 ;
arch/x86/kernel/setup.c +2 -1
@@ -557,7 +557,8 @@ static void __init reserve_crashkernel(void) total_mem =memblock_phys_mem_size ();/* crashkernel=XM */ - ret =parse_crashkernel (boot_command_line, total_mem, &crash_size, &crash_base); + ret =parse_crashkernel (boot_command_line, total_mem, + &crash_size, &crash_base,NULL ,NULL );if (ret !=0 || crash_size <=0 ) {/* crashkernel=X,high */ ret = parse_crashkernel_high(boot_command_line, total_mem,
include/linux/crash_core.h +2 -1
@@ -80,7 +80,8 @@ Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type,void final_note (Elf_Word *buf);int __init parse_crashkernel (char *cmdline,unsigned long long system_ram, -unsigned long long *crash_size,unsigned long long *crash_base); +unsigned long long *crash_size,unsigned long long *crash_base, +unsigned long long *low_size,bool *high);int parse_crashkernel_high (char *cmdline,unsigned long long system_ram,unsigned long long *crash_size,unsigned long long *crash_base); int parse_crashkernel_low(char *cmdline, unsigned long long system_ram,
kernel/crash_core.c +12 -3
@@ -287,10 +287,19 @@ static int __init __parse_crashkernel(char *cmdline,int __init parse_crashkernel (char *cmdline,unsigned long long system_ram,unsigned long long *crash_size, -unsigned long long *crash_base) +unsigned long long *crash_base, +unsigned long long *low_size, +bool *high) { -return __parse_crashkernel (cmdline, system_ram, crash_size, crash_base, -NULL ); +int ret; + +/* crashkernel=X[@offset] */ + ret =__parse_crashkernel (cmdline, system_ram, crash_size, + crash_base,NULL ); +if (!high) +return ret; + +return 0 ; } int __init parse_crashkernel_high(char *cmdline,
Signature · 7 lines
2.41.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v3 3/9 crash_core: change parse_crashkernel() to support crashkernel=,high|low parsing
In reply to Baoquan HeNow parse_crashkernel() is a real entry point for all kinds of crahskernel parsing on any architecture.
And wrap the crahskernel=,high|low handling inside CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION ifdeffery scope.
--- include/linux/crash_core.h | 6 ++++++ kernel/crash_core.c | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-)
include/linux/crash_core.h +6 -0
@@ -79,6 +79,12 @@ Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type, void *data, size_t data_len);void final_note (Elf_Word *buf); +#ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION +#ifndef DEFAULT_CRASH_KERNEL_LOW_SIZE +#define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20) +#endif +#endif +int __init parse_crashkernel (char *cmdline,unsigned long long system_ram,unsigned long long *crash_size,unsigned long long *crash_base,unsigned long long *low_size,bool *high);
kernel/crash_core.c +33 -3
@@ -283,6 +283,9 @@ static int __init __parse_crashkernel(char *cmdline,/* * That function is the entry point for command line parsing and should be * called from the arch-specific code. +* +* If crashkernel=,high|low is supported on architecture, non-NULL values +* should be passed to parameters 'low_size' and 'high'. */ int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
@@ -296,10 +299,37 @@ int __init parse_crashkernel(char *cmdline,/* crashkernel=X[@offset] */ ret =__parse_crashkernel (cmdline, system_ram, crash_size, crash_base,NULL ); -if (!high) -return ret; +#ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION +/* +* If non-NULL 'high' passed in and no normal crashkernel +* setting detected, try parsing crashkernel=,high|low. +*/ +if (high && ret == -ENOENT ) { + ret =__parse_crashkernel (cmdline,0 , crash_size, + crash_base, suffix_tbl[SUFFIX_HIGH ]); +if (ret || !*crash_size) +return -EINVAL ; -return 0 ; +/* +* crashkernel=Y,low can be specified or not, but invalid value +* is not allowed. +*/ + ret =__parse_crashkernel (cmdline,0 , low_size, + crash_base, suffix_tbl[SUFFIX_LOW ]); +if (ret == -ENOENT ) { + *low_size =DEFAULT_CRASH_KERNEL_LOW_SIZE ; + ret =0 ; + }else if (ret) { +return ret; + } + + *high = true; + } +#endif +if (!*crash_size) + ret = -EINVAL ; + +return ret; } int __init parse_crashkernel_high(char *cmdline,
Signature · 7 lines
2.41.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v3 3/9] crash_core: change parse_crashkernel() to support crashkernel=,high|low parsing
Quoted 5 lines · Baoquan He
Now
parse_crashkernel()is a real entry point for all kinds of crahskernel parsing on any architecture.And wrap the crahskernel=,high|low handling inside
CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATIONifdeffery scope.
Quoted 80 lines
Signed-off-by Baoquan He <[email protected]>--- include/linux/crash_core.h | 6 ++++++ kernel/crash_core.c | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-)include/linux/crash_core.h +6
-0@@ -79,6 +79,12 @@ Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type, void *data, size_t data_len);void final_note (Elf_Word *buf); +#ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION +#ifndef DEFAULT_CRASH_KERNEL_LOW_SIZE +#define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20) +#endif +#endif +int __init parse_crashkernel (char *cmdline,unsigned long long system_ram,unsigned long long *crash_size,unsigned long long *crash_base,unsigned long long *low_size,bool *high);kernel/crash_core.c +33
-3@@ -283,6 +283,9 @@ static int __init __parse_crashkernel(char *cmdline,/* * That function is the entry point for command line parsing and should be * called from the arch-specific code. +* +* If crashkernel=,high|low is supported on architecture, non-NULL values +* should be passed to parameters 'low_size' and 'high'. */ int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,@@ -296,10 +299,37 @@ int __init parse_crashkernel(char *cmdline,/* crashkernel=X[@offset] */ ret =__parse_crashkernel (cmdline, system_ram, crash_size, crash_base,NULL ); -if (!high) -return ret; +#ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION +/* +* If non-NULL 'high' passed in and no normal crashkernel +* setting detected, try parsing crashkernel=,high|low. +*/ +if (high && ret == -ENOENT ) { + ret =__parse_crashkernel (cmdline,0 , crash_size, + crash_base, suffix_tbl[SUFFIX_HIGH ]); +if (ret || !*crash_size) +return -EINVAL ; -return 0 ; +/* +* crashkernel=Y,low can be specified or not, but invalid value +* is not allowed. +*/ + ret =__parse_crashkernel (cmdline,0 , low_size, + crash_base, suffix_tbl[SUFFIX_LOW ]); +if (ret == -ENOENT ) { + *low_size =DEFAULT_CRASH_KERNEL_LOW_SIZE ; + ret =0 ; + }else if (ret) { +return ret; + } + + *high = true; + } +#endif +if (!*crash_size) + ret = -EINVAL ; + +return ret; } int __init parse_crashkernel_high(char *cmdline,
Signature · 8 lines
Regards, Zhen Lei _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v3 4/9 crash_core: add generic function to do reservation
In reply to Baoquan HeIn architecture like x86_64, arm64 and riscv, they have vast virtual address space and usually have huge physical memory RAM. Their crashkernel reservation doesn't have to be limited under 4G RAM, but can be extended to the whole physical memory via crashkernel=,high support.
Now add function reserve_crashkernel_generic() to reserve crashkernel memory if users specify any case of kernel pamameters, like crashkernel=xM[@offset] or crashkernel=,high|low.
This is preparation to simplify code of crashkernel=,high support in architecutures.
--- include/linux/crash_core.h | 28 ++++++++++ kernel/crash_core.c | 107 ++++++++++++++++++++++++++++++++++++- 2 files changed, 134 insertions(+), 1 deletion(-)
include/linux/crash_core.h +28 -0
@@ -93,6 +93,34 @@ int parse_crashkernel_high(char *cmdline, unsigned long long system_ram,int parse_crashkernel_low (char *cmdline,unsigned long long system_ram,unsigned long long *crash_size,unsigned long long *crash_base); +#ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION +#ifndef DEFAULT_CRASH_KERNEL_LOW_SIZE +#define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20) +#endif +#ifndef CRASH_ALIGN +#define CRASH_ALIGN SZ_2M +#endif +#ifndef CRASH_ADDR_LOW_MAX +#define CRASH_ADDR_LOW_MAX SZ_4G +#endif +#ifndef CRASH_ADDR_HIGH_MAX +#define CRASH_ADDR_HIGH_MAX memblock_end_of_DRAM() +#endif + +void __init reserve_crashkernel_generic (char *cmdline, +unsigned long long crash_size, +unsigned long long crash_base, +unsigned long long crash_low_size, +bool high); +#else +static inline void __init reserve_crashkernel_generic (char *cmdline, +unsigned long long crash_size, +unsigned long long crash_base, +unsigned long long crash_low_size, +bool high) +{} +#endif +/* Alignment required for elf header segment */ #define ELF_CORE_HEADER_ALIGN 4096
kernel/crash_core.c +106 -1
125 lines not on this page · raw message
Signature · 7 lines
2.41.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v3 4/9] crash_core: add generic function to do reservation
Quoted 6 lines · Baoquan He
In architecture like
x86_64, arm64 and riscv, they have vast virtual address space and usually have huge physical memory RAM. Their crashkernel reservation doesn't have to be limited under 4G RAM, but can be extended to the whole physical memory via crashkernel=,high support.
Quoted 6 lines
Now add function
reserve_crashkernel_generic()to reserve crashkernel memory if users specify any case of kernel pamameters, like crashkernel=xM[@offset] or crashkernel=,high|low.This is preparation to simplify code of crashkernel=,high support in architecutures.
Quoted 179 lines
Signed-off-by Baoquan He <[email protected]>--- include/linux/crash_core.h | 28 ++++++++++ kernel/crash_core.c | 107 ++++++++++++++++++++++++++++++++++++- 2 files changed, 134 insertions(+), 1 deletion(-)include/linux/crash_core.h +28
-0@@ -93,6 +93,34 @@ int parse_crashkernel_high(char *cmdline, unsigned long long system_ram,int parse_crashkernel_low (char *cmdline,unsigned long long system_ram,unsigned long long *crash_size,unsigned long long *crash_base); +#ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION +#ifndef DEFAULT_CRASH_KERNEL_LOW_SIZE +#define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20) +#endif +#ifndef CRASH_ALIGN +#define CRASH_ALIGN SZ_2M +#endif +#ifndef CRASH_ADDR_LOW_MAX +#define CRASH_ADDR_LOW_MAX SZ_4G +#endif +#ifndef CRASH_ADDR_HIGH_MAX +#define CRASH_ADDR_HIGH_MAX memblock_end_of_DRAM() +#endif + +void __init reserve_crashkernel_generic (char *cmdline, +unsigned long long crash_size, +unsigned long long crash_base, +unsigned long long crash_low_size, +bool high); +#else +static inline void __init reserve_crashkernel_generic (char *cmdline, +unsigned long long crash_size, +unsigned long long crash_base, +unsigned long long crash_low_size, +bool high) +{} +#endif +/* Alignment required for elf header segment */ #define ELF_CORE_HEADER_ALIGN 4096kernel/crash_core.c +106
-1@@ -5,7 +5,6 @@*/ #include <linux/buildid.h> -#include <linux/crash_core.h> #include <linux/init.h> #include <linux/utsname.h> #include <linux/vmalloc.h> @@ -13,6 +12,9 @@#include <linux/kexec.h> #include <linux/memory.h> #include <linux/cpuhotplug.h> +#include <linux/memblock.h> +#include <linux/kexec.h> +#include <linux/kmemleak.h> #include <asm/page.h> #include <asm/sections.h> @@ -360,6 +362,109 @@ static int __init parse_crashkernel_dummy(char *arg) }early_param ("crashkernel" , parse_crashkernel_dummy); +#ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION +static int __init reserve_crashkernel_low (unsigned long long low_size) +{ +#ifdef CONFIG_64BIT +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 (&iomem_resource, &crashk_low_res); +#endif +return 0 ; +} + +void __init reserve_crashkernel_generic (char *cmdline, +unsigned long long crash_size, +unsigned long long crash_base, +unsigned long long crash_low_size, +bool high) +{ +unsigned long long search_end =CRASH_ADDR_LOW_MAX , search_base =0 ; +bool fixed_base = false; + +/* User specifies base address explicitly. */ +if (crash_base) { + fixed_base = true; + search_base = crash_base; + search_end = crash_base + crash_size; + }else if (high) { + search_base =CRASH_ADDR_LOW_MAX ; + search_end =CRASH_ADDR_HIGH_MAX ; + } + +retry: + crash_base =memblock_phys_alloc_range (crash_size,CRASH_ALIGN , + search_base, search_end); +if (!crash_base) { +/* +* For crashkernel=size[KMG]@offset[KMG], print out failure +* message if can't reserve the specified region. +*/ +if (fixed_base) { +pr_warn ("crashkernel reservation failed - memory is in use.\n" ); +return ; + } + +/* +* For crashkernel=size[KMG], if the first attempt was for +* low memory, fall back to high memory, the minimum required +* low memory will be reserved later. +*/ +if (!high && search_end ==CRASH_ADDR_LOW_MAX ) { + search_end =CRASH_ADDR_HIGH_MAX ; + search_base =CRASH_ADDR_LOW_MAX ; + crash_low_size =DEFAULT_CRASH_KERNEL_LOW_SIZE ; + goto retry; + } + +/* +* For crashkernel=size[KMG],high, if the first attempt was +* for high memory, fall back to low memory. +*/ +if (high && search_end ==CRASH_ADDR_HIGH_MAX ) { + search_end =CRASH_ADDR_LOW_MAX ; + search_base =0 ; + goto retry; + } +pr_warn ("cannot allocate crashkernel (size:0x%llx)\n" , + crash_size); +return ; + } + +if ((crash_base >CRASH_ADDR_LOW_MAX ) && + crash_low_size &&reserve_crashkernel_low (crash_low_size)) { +memblock_phys_free (crash_base, crash_size); +return ; + } + +pr_info ("crashkernel reserved: 0x%016llx - 0x%016llx (%lld MB)\n" , + crash_base, crash_base + crash_size, crash_size >>20 ); + +/* +* The crashkernel memory will be removed from the kernel linear +* map. Inform kmemleak so that it won't try to access it. +*/ +kmemleak_ignore_phys (crash_base); +if (crashk_low_res.end) +kmemleak_ignore_phys (crashk_low_res.start); + + crashk_res.start = crash_base; + crashk_res.end = crash_base + crash_size -1 ; +insert_resource (&iomem_resource, &crashk_res); +} +#endif +int crash_prepare_elf64_headers (struct crash_mem *mem,int need_kernel_map,void **addr,unsigned long *sz) {
Signature · 8 lines
Regards, Zhen Lei _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v3 5/9 crash_core: move crashk_*res definition into crash_core.c
In reply to Baoquan HeBoth crashk_res and crashk_low_res are used to mark the reserved crashkernel regions in iomem_resource tree. And later the generic crashkernel resrvation will be added into crash_core.c. So move crashk_res and crashk_low_res definition into crash_core.c to avoid compiling error if CONFIG_CRASH_CORE=on while CONFIG_KEXEC_CORE is unset.
Meanwhile include <asm/crash_core.h> in <linux/crash_core.h> if generic reservation is needed. In that case, <asm/crash_core.h> need be added by ARCH. In asm/crash_core.h, ARCH can provide its own macro definitions to override macros in <linux/crash_core.h> if needed. Wrap the including into CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION ifdeffery scope to avoid compiling error in other ARCH-es which don't take the generic reservation way yet.
--- include/linux/crash_core.h | 8 ++++++++ include/linux/kexec.h | 4 ---- kernel/crash_core.c | 16 ++++++++++++++++ kernel/kexec_core.c | 17 ----------------- 4 files changed, 24 insertions(+), 21 deletions(-)
include/linux/crash_core.h +8 -0
@@ -5,6 +5,14 @@#include <linux/linkage.h> #include <linux/elfcore.h> #include <linux/elf.h> +#ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION +#include <asm/crash_core.h> +#endif + +/* Location of a reserved region to hold the crash kernel. +*/ +extern struct resource crashk_res; +extern struct resource crashk_low_res;#define CRASH_CORE_NOTE_NAME "CORE"#define CRASH_CORE_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
include/linux/kexec.h +0 -4
@@ -22,10 +22,6 @@#include <uapi/linux/kexec.h> #include <linux/verification.h> -/* Location of a reserved region to hold the crash kernel. -*/ -extern struct resource crashk_res; -extern struct resource crashk_low_res;extern note_buf_t __percpu *crash_notes;#ifdef CONFIG_KEXEC_CORE
kernel/crash_core.c +16 -0
@@ -35,6 +35,22 @@ u32 *vmcoreinfo_note;/* trusted vmcoreinfo, e.g. we can make a copy in the crash memory */ static unsigned char *vmcoreinfo_data_safecopy; +/* Location of the reserved area for the crash kernel */ +struct resource crashk_res = { + .name ="Crash kernel" , + .start =0 , + .end =0 , + .flags =IORESOURCE_BUSY |IORESOURCE_SYSTEM_RAM , + .desc =IORES_DESC_CRASH_KERNEL +}; +struct resource crashk_low_res = { + .name ="Crash kernel" , + .start =0 , + .end =0 , + .flags =IORESOURCE_BUSY |IORESOURCE_SYSTEM_RAM , + .desc =IORES_DESC_CRASH_KERNEL +}; +/* * parsing the "crashkernel" commandline *
kernel/kexec_core.c +0 -17
@@ -52,23 +52,6 @@ atomic_t __kexec_lock = ATOMIC_INIT(0);/* Flag to indicate we are going to kexec a new kernel */ bool kexec_in_progress = false; - -/* Location of the reserved area for the crash kernel */ -struct resource crashk_res = { - .name ="Crash kernel" , - .start =0 , - .end =0 , - .flags =IORESOURCE_BUSY |IORESOURCE_SYSTEM_RAM , - .desc =IORES_DESC_CRASH_KERNEL -}; -struct resource crashk_low_res = { - .name ="Crash kernel" , - .start =0 , - .end =0 , - .flags =IORESOURCE_BUSY |IORESOURCE_SYSTEM_RAM , - .desc =IORES_DESC_CRASH_KERNEL -}; -int kexec_should_crash (struct task_struct *p) {/*
Signature · 7 lines
2.41.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v3 5/9] crash_core: move crashk_*res definition into crash_core.c
Quoted 7 lines · Baoquan He
Both
crashk_resandcrashk_low_resare used to mark the reserved crashkernel regions iniomem_resourcetree. And later the generic crashkernel resrvation will be added intocrash_core.c. So movecrashk_resandcrashk_low_resdefinition intocrash_core.cto avoid compiling error ifCONFIG_CRASH_CORE=onwhileCONFIG_KEXEC_COREis unset.
Quoted 7 lines
Meanwhile include <
asm/crash_core.h> in <linux/crash_core.h> if generic reservation is needed. In that case, <asm/crash_core.h> need be added by ARCH. Inasm/crash_core.h, ARCH can provide its own macro definitions to override macros in <linux/crash_core.h> if needed. Wrap the including intoCONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATIONifdeffery scope to avoid compiling error in other ARCH-es which don't take the generic reservation way yet.
Quoted 99 lines
Signed-off-by Baoquan He <[email protected]>--- include/linux/crash_core.h | 8 ++++++++ include/linux/kexec.h | 4 ---- kernel/crash_core.c | 16 ++++++++++++++++ kernel/kexec_core.c | 17 ----------------- 4 files changed, 24 insertions(+), 21 deletions(-)include/linux/crash_core.h +8
-0@@ -5,6 +5,14 @@#include <linux/linkage.h> #include <linux/elfcore.h> #include <linux/elf.h> +#ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION +#include <asm/crash_core.h> +#endif + +/* Location of a reserved region to hold the crash kernel. +*/ +extern struct resource crashk_res; +extern struct resource crashk_low_res;#define CRASH_CORE_NOTE_NAME "CORE"#define CRASH_CORE_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)include/linux/kexec.h +0
-4@@ -22,10 +22,6 @@#include <uapi/linux/kexec.h> #include <linux/verification.h> -/* Location of a reserved region to hold the crash kernel. -*/ -extern struct resource crashk_res; -extern struct resource crashk_low_res;extern note_buf_t __percpu *crash_notes;#ifdef CONFIG_KEXEC_CORE kernel/crash_core.c +16
-0@@ -35,6 +35,22 @@ u32 *vmcoreinfo_note;/* trusted vmcoreinfo, e.g. we can make a copy in the crash memory */ static unsigned char *vmcoreinfo_data_safecopy; +/* Location of the reserved area for the crash kernel */ +struct resource crashk_res = { + .name ="Crash kernel" , + .start =0 , + .end =0 , + .flags =IORESOURCE_BUSY |IORESOURCE_SYSTEM_RAM , + .desc =IORES_DESC_CRASH_KERNEL +}; +struct resource crashk_low_res = { + .name ="Crash kernel" , + .start =0 , + .end =0 , + .flags =IORESOURCE_BUSY |IORESOURCE_SYSTEM_RAM , + .desc =IORES_DESC_CRASH_KERNEL +}; +/* * parsing the "crashkernel" commandline * kernel/kexec_core.c +0
-17@@ -52,23 +52,6 @@ atomic_t __kexec_lock = ATOMIC_INIT(0);/* Flag to indicate we are going to kexec a new kernel */ bool kexec_in_progress = false; - -/* Location of the reserved area for the crash kernel */ -struct resource crashk_res = { - .name ="Crash kernel" , - .start =0 , - .end =0 , - .flags =IORESOURCE_BUSY |IORESOURCE_SYSTEM_RAM , - .desc =IORES_DESC_CRASH_KERNEL -}; -struct resource crashk_low_res = { - .name ="Crash kernel" , - .start =0 , - .end =0 , - .flags =IORESOURCE_BUSY |IORESOURCE_SYSTEM_RAM , - .desc =IORES_DESC_CRASH_KERNEL -}; -int kexec_should_crash (struct task_struct *p) {/*
Signature · 8 lines
Regards, Zhen Lei _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v3 6/9 x86: kdump: use generic interface to simplify crashkernel reservation code
In reply to Baoquan HeWith 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 <asm/crash_core.h>, and define CRASH_ALIGN, CRASH_ADDR_LOW_MAX, CRASH_ADDR_HIGH_MAX and DEFAULT_CRASH_KERNEL_LOW_SIZE in <asm/crash_core.h>;
2) Add arch_reserve_crashkernel() to call parse_crashkernel() and reserve_crashkernel_generic(), and do the ARCH specific work if needed.
3) Add ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION Kconfig in arch/x86/Kconfig.
When adding DEFAULT_CRASH_KERNEL_LOW_SIZE, add crash_low_size_default() to calculate crashkernel low memory because x86_64 has special requirement.
The old reserve_crashkernel_low() and reserve_crashkernel() can be removed.
--- arch/x86/Kconfig | 3 + arch/x86/include/asm/crash_core.h | 34 +++++++ arch/x86/kernel/setup.c | 144 ++++-------------------------- 3 files changed, 52 insertions(+), 129 deletions(-) create mode 100644 arch/x86/include/asm/crash_core.h
arch/x86/Kconfig +3 -0
@@ -2062,6 +2062,9 @@ config ARCH_SUPPORTS_CRASH_DUMP config ARCH_SUPPORTS_CRASH_HOTPLUG def_bool y +config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION + def_bool CRASH_CORE + config PHYSICAL_START hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP) default "0x1000000"
arch/x86/include/asm/crash_core.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _X86_CRASH_CORE_H +#define _X86_CRASH_CORE_H + +/* 16M alignment for crash kernel regions */ +#define CRASH_ALIGN SZ_16M + +/* +* Keep the crash kernel below this limit. +* +* Earlier 32-bits kernels would limit the kernel to the low 512 MB range +* due to mapping restrictions. +* +* 64-bit kdump kernels need to be restricted to be under 64 TB, which is +* the upper limit of system RAM in 4-level paging mode. Since the kdump +* jump could be from 5-level paging to 4-level paging, the jump will fail if +* the kernel is put above 64 TB, and during the 1st kernel bootup there's +* no good way to detect the paging mode of the target kernel which will be +* loaded for dumping. +*/ + +#ifdef CONFIG_X86_32 +# define CRASH_ADDR_LOW_MAX SZ_512M +# define CRASH_ADDR_HIGH_MAX SZ_512M +#else +# define CRASH_ADDR_LOW_MAX SZ_4G +# define CRASH_ADDR_HIGH_MAX SZ_64T +#endif + +# define DEFAULT_CRASH_KERNEL_LOW_SIZE crash_low_size_default() + +extern unsigned long crash_low_size_default (void ); + +#endif /* _X86_CRASH_CORE_H */
arch/x86/kernel/setup.c +15 -129
174 lines not on this page · raw message
Signature · 7 lines
2.41.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
kernel test robot
build botRe: [PATCH v3 6/9] x86: kdump: use generic interface to simplify crashkernel reservation code
kernel test robot noticed the following build warnings:
Hi Baoquan,
kernel test robot noticed the following build warnings:
[auto build test WARNING on powerpc/next]
[also build test WARNING on powerpc/fixes linus/master v6.6-rc1 next-20230914] [cannot apply to arm64/for-next/core tip/x86/core]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Baoquan-He/crash_core-c-remove-unnecessary-parameter-of-function/20230914-113546 base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next patch link: https://lore.kernel.org/r/20230914033142.676708-7-bhe%40redhat.com patch subject: [PATCH v3 6/9] x86: kdump: use generic interface to simplify crashkernel reservation code config: i386-allnoconfig (https://download.01.org/0day-ci/archive/20230914/[email protected]/config) compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230914/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> arch/x86/kernel/setup.c:476:15: warning: no previous prototype for function 'crash_low_size_default' [-Wmissing-prototypes]
unsigned long crash_low_size_default(void)
^ arch/x86/kernel/setup.c:476:1: note: declare 'static' if the function is not intended to be used outside of this translation unit unsigned long crash_low_size_default(void)
^
static
1 warning generated.
vim +/crash_low_size_default +476 arch/x86/kernel/setup.c
472
473 /*
474 * --------- Crashkernel reservation ------------------------------
475 */
> 476 unsigned long crash_low_size_default(void)
477 {
478 #ifdef CONFIG_X86_64
479 return max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20);
480 #else
481 return 0;
482 #endif
483 }
484
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v3 6/9] x86: kdump: use generic interface to simplify crashkernel reservation code
Quoted 26 lines · kernel test robot
Hi Baoquan,
kernel test robot noticed the following build warnings:
[auto build test WARNING on powerpc/next]
[also build test WARNING on powerpc/fixes linus/master v6.6-rc1 next-20230914] [cannot apply to arm64/for-next/core tip/x86/core]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Baoquan-He/crash_core-c-remove-unnecessary-parameter-of-function/20230914-113546 base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next patch link: https://lore.kernel.org/r/20230914033142.676708-7-bhe%40redhat.com patch subject: [PATCH v3 6/9] x86: kdump: use generic interface to simplify crashkernel reservation code config: i386-allnoconfig (https://download.01.org/0day-ci/archive/20230914/[email protected]/config) compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230914/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/All warnings (new ones prefixed by >>):
Quoted 8 lines
Quoted 1 line
Quoted 1 line
arch/x86/kernel/setup.c:476:15: warning: no previous prototype for function 'crash_low_size_default' [-Wmissing-prototypes]unsigned long
crash_low_size_default(void)^
arch/x86/kernel/setup.c:476:1: note: declare 'static' if the function is not intended to be used outside of this translation unit unsigned longcrash_low_size_default(void)
^
static
1 warning generated.
Thanks for reporting this. I can reproduced this warning on x86_64 machine by retrieving the LKP's config and build it with below command:
make ARCH=i386 -j128 W=1 arch/x86/kernel/
I can fix it by moving crash_low_size_default() into arch/x86/include/asm/crash_core.h and make it as static inline as below draft change.
Hi Andrew,
I should post v4 of the whole series or just v4 of this patch?
[PATCH v3 6/9] x86: kdump: use generic interface to simplify crashkernel reservation code
arch/x86/include/asm/crash_core.h +9 -1
@@ -18,6 +18,7 @@* no good way to detect the paging mode of the target kernel which will be * loaded for dumping. */ +extern unsigned long swiotlb_size_or_default (void );#ifdef CONFIG_X86_32 # define CRASH_ADDR_LOW_MAX SZ_512M
@@ -29,6 +30,13 @@# define DEFAULT_CRASH_KERNEL_LOW_SIZE crash_low_size_default() -extern unsigned long crash_low_size_default (void ); +static inline unsigned long crash_low_size_default (void ) +{ +#ifdef CONFIG_X86_64 +return max (swiotlb_size_or_default () + (8UL <<20 ),256UL <<20 ); +#else +return 0 ; +#endif +}#endif /* _X86_CRASH_CORE_H */
arch/x86/kernel/setup.c +0 -12
@@ -470,18 +470,6 @@ static void __init memblock_x86_reserve_range_setup_data(void) } } -/* -* --------- Crashkernel reservation ------------------------------ -*/ -unsigned long crash_low_size_default (void ) -{ -#ifdef CONFIG_X86_64 -return max (swiotlb_size_or_default () + (8UL <<20 ),256UL <<20 ); -#else -return 0 ; -#endif -} -static void __init arch_reserve_crashkernel (void ) {unsigned long long crash_base, crash_size, low_size =0 ;
kernel test robot
build botRe: [PATCH v3 6/9] x86: kdump: use generic interface to simplify crashkernel reservation code
In reply to Baoquan Hekernel test robot noticed the following build warnings:
Hi Baoquan,
kernel test robot noticed the following build warnings:
[auto build test WARNING on powerpc/next]
[also build test WARNING on powerpc/fixes linus/master v6.6-rc1 next-20230914] [cannot apply to arm64/for-next/core tip/x86/core]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Baoquan-He/crash_core-c-remove-unnecessary-parameter-of-function/20230914-113546 base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next patch link: https://lore.kernel.org/r/20230914033142.676708-7-bhe%40redhat.com patch subject: [PATCH v3 6/9] x86: kdump: use generic interface to simplify crashkernel reservation code config: i386-randconfig-003-20230915 (https://download.01.org/0day-ci/archive/20230915/[email protected]/config) compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230915/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> arch/x86/kernel/setup.c:476:15: warning: no previous declaration for 'crash_low_size_default' [-Wmissing-declarations]
unsigned long crash_low_size_default(void)
^~~~~~~~~~~~~~~~~~~~~~
vim +/crash_low_size_default +476 arch/x86/kernel/setup.c
472
473 /*
474 * --------- Crashkernel reservation ------------------------------
475 */
> 476 unsigned long crash_low_size_default(void)
477 {
478 #ifdef CONFIG_X86_64
479 return max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20);
480 #else
481 return 0;
482 #endif
483 }
484
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v4 6/9 x86: kdump: use generic interface to simplify crashkernel reservation code
In reply to Baoquan HeWith 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 <asm/crash_core.h>, and define CRASH_ALIGN, CRASH_ADDR_LOW_MAX, CRASH_ADDR_HIGH_MAX and DEFAULT_CRASH_KERNEL_LOW_SIZE in <asm/crash_core.h>;
2) Add arch_reserve_crashkernel() to call parse_crashkernel() and reserve_crashkernel_generic(), and do the ARCH specific work if needed.
3) Add ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION Kconfig in arch/x86/Kconfig.
When adding DEFAULT_CRASH_KERNEL_LOW_SIZE, add crash_low_size_default() to calculate crashkernel low memory because x86_64 has special requirement.
The old reserve_crashkernel_low() and reserve_crashkernel() can be removed.
---v3->v4:
Move crash_low_size_default() to <asm/crash_core.h> to make it a static inline function. This fixes the warning reported by LKP.
arch/x86/Kconfig | 3 + arch/x86/include/asm/crash_core.h | 42 +++++++++ arch/x86/kernel/setup.c | 148 +++--------------------------- 3 files changed, 56 insertions(+), 137 deletions(-) create mode 100644 arch/x86/include/asm/crash_core.h
arch/x86/Kconfig +3 -0
@@ -2062,6 +2062,9 @@ config ARCH_SUPPORTS_CRASH_DUMP config ARCH_SUPPORTS_CRASH_HOTPLUG def_bool y +config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION + def_bool CRASH_CORE + config PHYSICAL_START hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP) default "0x1000000"
arch/x86/include/asm/crash_core.h new file +42 -0
42 lines not on this page · raw message
arch/x86/kernel/setup.c +11 -137
173 lines not on this page · raw message
Signature · 7 lines
2.41.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
kernel test robot
build botRe: [PATCH v3 6/9] x86: kdump: use generic interface to simplify crashkernel reservation code
In reply to Baoquan Hekernel test robot noticed the following build warnings:
Hi Baoquan,
kernel test robot noticed the following build warnings:
[auto build test WARNING on powerpc/next]
[also build test WARNING on powerpc/fixes v6.6]
[cannot apply to arm64/for-next/core tip/x86/core linus/master next-20231107] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Baoquan-He/crash_core-c-remove-unnecessary-parameter-of-function/20230914-113546 base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next patch link: https://lore.kernel.org/r/20230914033142.676708-7-bhe%40redhat.com patch subject: [PATCH v3 6/9] x86: kdump: use generic interface to simplify crashkernel reservation code config: i386-randconfig-011-20230914 (https://download.01.org/0day-ci/archive/20231107/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231107/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> arch/x86/kernel/setup.c:476:15: warning: no previous prototype for 'crash_low_size_default' [-Wmissing-prototypes]
476 | unsigned long crash_low_size_default(void)
| ^~~~~~~~~~~~~~~~~~~~~~
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for VIDEO_OV2640
Depends on [n]: MEDIA_SUPPORT [=m] && VIDEO_DEV [=m] && VIDEO_CAMERA_SENSOR [=n]
Selected by [m]:
- VIDEO_EM28XX_V4L2 [=m] && USB [=m] && MEDIA_SUPPORT [=m] && MEDIA_USB_SUPPORT [=y] && (MEDIA_CAMERA_SUPPORT [=y] || MEDIA_ANALOG_TV_SUPPORT [=n] || MEDIA_DIGITAL_TV_SUPPORT [=n]) && VIDEO_EM28XX [=m] && MEDIA_SUBDRV_AUTOSELECT [=y] && MEDIA_CAMERA_SUPPORT [=y]
WARNING: unmet direct dependencies detected for VIDEO_MT9V011
Depends on [n]: MEDIA_SUPPORT [=m] && VIDEO_DEV [=m] && VIDEO_CAMERA_SENSOR [=n]
Selected by [m]:
- VIDEO_EM28XX_V4L2 [=m] && USB [=m] && MEDIA_SUPPORT [=m] && MEDIA_USB_SUPPORT [=y] && (MEDIA_CAMERA_SUPPORT [=y] || MEDIA_ANALOG_TV_SUPPORT [=n] || MEDIA_DIGITAL_TV_SUPPORT [=n]) && VIDEO_EM28XX [=m] && MEDIA_SUBDRV_AUTOSELECT [=y] && MEDIA_CAMERA_SUPPORT [=y]
vim +/crash_low_size_default +476 arch/x86/kernel/setup.c
472
473 /*
474 * --------- Crashkernel reservation ------------------------------
475 */
> 476 unsigned long crash_low_size_default(void)
477 {
478 #ifdef CONFIG_X86_64
479 return max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20);
480 #else
481 return 0;
482 #endif
483 }
484
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v3 6/9] x86: kdump: use generic interface to simplify crashkernel reservation code
Quoted 24 lines · kernel test robot
Hi Baoquan,
kernel test robot noticed the following build warnings:
[auto build test WARNING on powerpc/next]
[also build test WARNING on powerpc/fixes v6.6]
[cannot apply to arm64/for-next/core tip/x86/core linus/master next-20231107] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Baoquan-He/crash_core-c-remove-unnecessary-parameter-of-function/20230914-113546 base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next patch link: https://lore.kernel.org/r/20230914033142.676708-7-bhe%40redhat.com patch subject: [PATCH v3 6/9] x86: kdump: use generic interface to simplify crashkernel reservation code config: i386-randconfig-011-20230914 (https://download.01.org/0day-ci/archive/20231107/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231107/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Quoted 5 lines
All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
arch/x86/kernel/setup.c:476:15: warning: no previous prototype for 'crash_low_size_default' [-Wmissing-prototypes]476 | unsigned long
crash_low_size_default(void)
| ^~~~~~~~~~~~~~~~~~~~~~
I didn't try the reproducer at above, whereas this should be an report on an old version of patch. The patch has been updated later and merged into linus's tree now. Please see below commit
commit 9c08a2a139fe83f217625ee0352ce531b9a666ea
Author: Baoquan He <[email protected]> Date: Thu Sep 14 11:31:39 2023 +0800
x86: kdump: use generic interface to simplify crashkernel reservation code
Quoted 32 lines
Kconfigwarnings: (for reference only)
WARNING: unmet direct dependencies detected forVIDEO_OV2640
Depends on [n]:MEDIA_SUPPORT[=m] &&VIDEO_DEV[=m] &&VIDEO_CAMERA_SENSOR[=n]
Selected by [m]:
-VIDEO_EM28XX_V4L2[=m] && USB [=m] &&MEDIA_SUPPORT[=m] &&MEDIA_USB_SUPPORT[=y] && (MEDIA_CAMERA_SUPPORT[=y] ||MEDIA_ANALOG_TV_SUPPORT[=n] ||MEDIA_DIGITAL_TV_SUPPORT[=n]) &&VIDEO_EM28XX[=m] &&MEDIA_SUBDRV_AUTOSELECT[=y] &&MEDIA_CAMERA_SUPPORT[=y]
WARNING: unmet direct dependencies detected forVIDEO_MT9V011
Depends on [n]:MEDIA_SUPPORT[=m] &&VIDEO_DEV[=m] &&VIDEO_CAMERA_SENSOR[=n]
Selected by [m]:
-VIDEO_EM28XX_V4L2[=m] && USB [=m] &&MEDIA_SUPPORT[=m] &&MEDIA_USB_SUPPORT[=y] && (MEDIA_CAMERA_SUPPORT[=y] ||MEDIA_ANALOG_TV_SUPPORT[=n] ||MEDIA_DIGITAL_TV_SUPPORT[=n]) &&VIDEO_EM28XX[=m] &&MEDIA_SUBDRV_AUTOSELECT[=y] &&MEDIA_CAMERA_SUPPORT[=y]vim +/crash_low_size_default +476
arch/x86/kernel/setup.c472 473 /* 474 * --------- Crashkernel reservation ------------------------------ 475 */Quoted 1 line
476 unsigned long
crash_low_size_default(void)477 { 478 #ifdef CONFIG_X86_64 479 return max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20); 480 #else 481 return 0; 482 #endif 483 } 484Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v3 7/9 arm64: kdump: use generic interface to simplify crashkernel reservation
In reply to Baoquan HeWith 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 <asm/crash_core.h>, and define CRASH_ALIGN, CRASH_ADDR_LOW_MAX, CRASH_ADDR_HIGH_MAX and DEFAULT_CRASH_KERNEL_LOW_SIZE in <asm/crash_core.h>;
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.
--- 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
arch/arm64/Kconfig +3 -0
@@ -1483,6 +1483,9 @@ config ARCH_DEFAULT_KEXEC_IMAGE_VERIFY_SIG config ARCH_SUPPORTS_CRASH_DUMP def_bool y +config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION + def_bool CRASH_CORE + config TRANS_TABLE def_bool y depends on HIBERNATION || KEXEC_CORE
arch/arm64/include/asm/crash_core.h new file +10 -0
@@ -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
arch/arm64/mm/init.c +8 -132
170 lines not on this page · raw message
Signature · 7 lines
2.41.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v3 8/9 riscv: kdump: use generic interface to simplify crashkernel reservation
In reply to Baoquan HeWith 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 <asm/crash_core.h>, and define CRASH_ALIGN, CRASH_ADDR_LOW_MAX, CRASH_ADDR_HIGH_MAX and DEFAULT_CRASH_KERNEL_LOW_SIZE in <asm/crash_core.h>;
2) Add arch_reserve_crashkernel() to call parse_crashkernel() and reserve_crashkernel_generic();
3) Add ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION Kconfig in arch/riscv/Kconfig.
The old reserve_crashkernel_low() and reserve_crashkernel() can be removed.
--- arch/riscv/Kconfig | 3 + arch/riscv/include/asm/crash_core.h | 11 +++ arch/riscv/include/asm/processor.h | 2 + arch/riscv/mm/init.c | 141 +++------------------------- 4 files changed, 27 insertions(+), 130 deletions(-) create mode 100644 arch/riscv/include/asm/crash_core.h
arch/riscv/Kconfig +3 -0
@@ -694,6 +694,9 @@ config ARCH_SUPPORTS_KEXEC_PURGATORY config ARCH_SUPPORTS_CRASH_DUMP def_bool y +config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION + def_bool CRASH_CORE + config COMPAT bool "Kernel support for 32-bit U-mode" default 64BIT
arch/riscv/include/asm/crash_core.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _RISCV_CRASH_CORE_H +#define _RISCV_CRASH_CORE_H + +#define CRASH_ALIGN PMD_SIZE + +#define CRASH_ADDR_LOW_MAX dma32_phys_limit +#define CRASH_ADDR_HIGH_MAX memblock_end_of_DRAM() + +extern phys_addr_t memblock_end_of_DRAM (void ); +#endif
arch/riscv/include/asm/processor.h +2 -0
@@ -116,6 +116,8 @@ static inline void wait_for_interrupt(void) __asm__ __volatile__ ("wfi" ); } +extern phys_addr_t dma32_phys_limit; +struct device_node ;int riscv_of_processor_hartid (struct device_node *node,unsigned long *hartid);int riscv_early_of_processor_hartid (struct device_node *node,unsigned long *hartid);
arch/riscv/mm/init.c +11 -130
175 lines not on this page · raw message
Signature · 7 lines
2.41.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v3 8/9] riscv: kdump: use generic interface to simplify crashkernel reservation
Quoted 8 lines · Baoquan He
With the help of newly changed function
parse_crashkernel()and genericreserve_crashkernel_generic(), crashkernel reservation can be simplified by steps:1) Add a new header file <
asm/crash_core.h>, and defineCRASH_ALIGN,CRASH_ADDR_LOW_MAX,CRASH_ADDR_HIGH_MAXandDEFAULT_CRASH_KERNEL_LOW_SIZEin <asm/crash_core.h>;
Quoted 8 lines
2) Add
arch_reserve_crashkernel()to callparse_crashkernel()andreserve_crashkernel_generic();3) Add
ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATIONKconfiginarch/riscv/Kconfig.The old
reserve_crashkernel_low()andreserve_crashkernel()can be removed.
Hi Baoquan,
Sorry for the late response. The refactor code has unified multiple arch via generic interface, which looks great!
However when I tested on my risc-v QEMU environment, a little problem occurred with following messages:
[ 0.000000] crashkernel low memory reserved: 0xf8000000 - 0x100000000 (128 MB) [ 0.000000] crashkernel reserved: 0x0000000177e00000 - 0x0000000277e00000 (4096 MB) [ 0.000000] ------------[ cut here ]------------ [ 0.000000] WARNING: CPU: 0 PID: 0 at kernel/resource.c:779 __insert_resource+0x8e/0xd0 [ 0.000000] Modules linked in: [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 6.6.0-rc2-next-20230920 #1 [ 0.000000] Hardware name: riscv-virtio,qemu (DT) [ 0.000000] epc : __insert_resource+0x8e/0xd0 [ 0.000000] ra : insert_resource+0x28/0x4e [ 0.000000] epc : ffffffff80017344 ra : ffffffff8001742e sp : ffffffff81203db0 [ 0.000000] gp : ffffffff812ece98 tp : ffffffff8120dac0 t0 : ff600001f7ff2b00 [ 0.000000] t1 : 0000000000000000 t2 : 3428203030303030 s0 : ffffffff81203dc0 [ 0.000000] s1 : ffffffff81211e18 a0 : ffffffff81211e18 a1 : ffffffff81289380 [ 0.000000] a2 : 0000000277dfffff a3 : 0000000177e00000 a4 : 0000000177e00000 [ 0.000000] a5 : ffffffff81289380 a6 : 0000000277dfffff a7 : 0000000000000078 [ 0.000000] s2 : ffffffff81289380 s3 : ffffffff80a0bac8 s4 : ff600001f7ff2880 [ 0.000000] s5 : 0000000000000280 s6 : 8000000a00006800 s7 : 000000000000007f [ 0.000000] s8 : 0000000080017038 s9 : 0000000080038ea0 s10: 0000000000000000 [ 0.000000] s11: 0000000000000000 t3 : ffffffff80a0bc00 t4 : ffffffff80a0bc00 [ 0.000000] t5 : ffffffff80a0bbd0 t6 : ffffffff80a0bc00 [ 0.000000] status: 0000000200000100 badaddr: 0000000000000000 cause: 0000000000000003 [ 0.000000] [<ffffffff80017344>] __insert_resource+0x8e/0xd0 [ 0.000000] ---[ end trace 0000000000000000 ]--- [ 0.000000] Failed to add a Crash kernel resource at 177e00000
The crashkernel memory has been allocated successfully, whereas it seems failed to insert into iomem_resource. This should due to the unique reserving logic in risc-v arch specific code, i.e. crashk_res/crashk_low_res will be added into iomem_resource later in init_resources(), which is not aligned with the unified reserving logic.
My simple solution here is removing the arch specific code within #ifdef CONFIG_KEXEC_CORE in init_resources(), which has been tested OK with all your testcases. Or do you have any other idea?
Best regards,
Jiahao
Quoted 237 lines
Signed-off-by Baoquan He <[email protected]>--- arch/riscv/Kconfig | 3 + arch/riscv/include/asm/crash_core.h | 11 +++ arch/riscv/include/asm/processor.h | 2 + arch/riscv/mm/init.c | 141 +++------------------------- 4 files changed, 27 insertions(+), 130 deletions(-)create mode 100644
arch/riscv/include/asm/crash_core.harch/riscv/Kconfig +3
-0@@ -694,6 +694,9 @@ config ARCH_SUPPORTS_KEXEC_PURGATORY config ARCH_SUPPORTS_CRASH_DUMP def_bool y +config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION + def_bool CRASH_CORE + config COMPAT bool "Kernel support for 32-bit U-mode" default 64BITarch/riscv/include/asm/crash_core.h new file +11
-0@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _RISCV_CRASH_CORE_H +#define _RISCV_CRASH_CORE_H + +#define CRASH_ALIGN PMD_SIZE + +#define CRASH_ADDR_LOW_MAX dma32_phys_limit +#define CRASH_ADDR_HIGH_MAX memblock_end_of_DRAM() + +extern phys_addr_t memblock_end_of_DRAM (void ); +#endif arch/riscv/include/asm/processor.h +2
-0@@ -116,6 +116,8 @@ static inline void wait_for_interrupt(void) __asm__ __volatile__ ("wfi" ); } +extern phys_addr_t dma32_phys_limit; +struct device_node ;int riscv_of_processor_hartid (struct device_node *node,unsigned long *hartid);int riscv_early_of_processor_hartid (struct device_node *node,unsigned long *hartid);arch/riscv/mm/init.c +11
-130@@ -65,7 +65,7 @@ extern char _start[];void *_dtb_early_va__initdata ;uintptr_t _dtb_early_pa__initdata ; -static phys_addr_t dma32_phys_limit__initdata ; +phys_addr_t dma32_phys_limit__initdata ;static void __init zone_sizes_init (void ) {@@ -1333,28 +1333,6 @@ static inline void setup_vm_final(void) }#endif /* CONFIG_MMU */ -/* Reserve 128M low memory by default for swiotlb buffer */ -#define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20) - -static int __init reserve_crashkernel_low (unsigned long long low_size) -{ -unsigned long long low_base; - - low_base =memblock_phys_alloc_range (low_size,PMD_SIZE ,0 , dma32_phys_limit); -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%016llx - 0x%016llx (%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 ; - -return 0 ; -} -/* * reserve_crashkernel() - reserves memory for crash kernel * @@ -1362,122 +1340,25 @@ static int __init reserve_crashkernel_low(unsigned long long low_size)* 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_base =0 ; -unsigned long long crash_size =0 ; -unsigned long long crash_low_size =0 ; -unsigned long search_start =memblock_start_of_DRAM (); -unsigned long search_end = (unsigned long )dma32_phys_limit; +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 =0 ; +int ret;if (!IS_ENABLED (CONFIG_KEXEC_CORE ))return ; -/* -* Don't reserve a region for a crash kernel on a crash kernel -* since it doesn't make much sense and we have limited memory -* resources. -*/ -if (is_kdump_kernel ()) { -pr_info ("crashkernel: ignoring reservation request\n" ); -return ; - } ret =parse_crashkernel (cmdline,memblock_phys_mem_size (), - &crash_size, &crash_base,NULL ,NULL ); -if (ret == -ENOENT ) { -/* Fallback to crashkernel=X,[high,low] */ - ret =parse_crashkernel_high (cmdline,0 , &crash_size, &crash_base); -if (ret || !crash_size) -return ; - -/* -* crashkernel=Y,low is valid only when crashkernel=X,high -* is passed. -*/ - ret =parse_crashkernel_low (cmdline,0 , &crash_low_size, &crash_base); -if (ret == -ENOENT ) - crash_low_size =DEFAULT_CRASH_KERNEL_LOW_SIZE ; -else if (ret) -return ; - - search_start = (unsigned long )dma32_phys_limit; - search_end =memblock_end_of_DRAM (); - high = true; - }else if (ret || !crash_size) { -/* Invalid argument value specified */ + &crash_size, &crash_base, + &low_size, &high); +if (ret)return ; - } - - crash_size =PAGE_ALIGN (crash_size); - -if (crash_base) { - fixed_base = true; - search_start = crash_base; - search_end = crash_base + crash_size; - } - -/* -* Current riscv boot protocol requires 2MB alignment for -* RV64 and 4MB alignment for RV32 (hugepage size) -* -* Try to alloc from 32bit addressible physical memory so that -* swiotlb can work on the crash kernel. -*/ - crash_base =memblock_phys_alloc_range (crash_size,PMD_SIZE , - search_start, search_end); -if (crash_base ==0 ) { -/* -* For crashkernel=size[KMG]@offset[KMG], print out failure -* message if can't reserve the specified region. -*/ -if (fixed_base) { -pr_warn ("crashkernel: allocating failed with given size@offset\n" ); -return ; - } - -if (high) { -/* -* For crashkernel=size[KMG],high, if the first attempt was -* for high memory, fall back to low memory. -*/ - search_start =memblock_start_of_DRAM (); - search_end = (unsigned long )dma32_phys_limit; - }else { -/* -* For crashkernel=size[KMG], if the first attempt was for -* low memory, fall back to high memory, the minimum required -* low memory will be reserved later. -*/ - search_start = (unsigned long )dma32_phys_limit; - search_end =memblock_end_of_DRAM (); - crash_low_size =DEFAULT_CRASH_KERNEL_LOW_SIZE ; - } - - crash_base =memblock_phys_alloc_range (crash_size,PMD_SIZE , - search_start, search_end); -if (crash_base ==0 ) { -pr_warn ("crashkernel: couldn't allocate %lldKB\n" , - crash_size >>10 ); -return ; - } - } - -if ((crash_base >= dma32_phys_limit) && crash_low_size && -reserve_crashkernel_low (crash_low_size)) { -memblock_phys_free (crash_base, crash_size); -return ; - } - -pr_info ("crashkernel: reserved 0x%016llx - 0x%016llx (%lld MB)\n" , - crash_base, crash_base + crash_size, crash_size >>20 ); - crashk_res.start = crash_base; - crashk_res.end = crash_base + crash_size -1 ; +reserve_crashkernel_generic (cmdline, crash_size, crash_base, + low_size, high); }void __init paging_init (void )@@ -1495,7 +1376,7 @@ void __init misc_mem_init(void)arch_numa_init ();sparse_init ();zone_sizes_init (); -reserve_crashkernel (); +arch_reserve_crashkernel ();memblock_dump_all (); }
Re: [PATCH v3 8/9] riscv: kdump: use generic interface to simplify crashkernel reservation
Quoted 52 lines · chenjiahao (C)
Quoted 8 lines · Baoquan He
With the help of newly changed function
parse_crashkernel()and genericreserve_crashkernel_generic(), crashkernel reservation can be simplified by steps:1) Add a new header file <
asm/crash_core.h>, and defineCRASH_ALIGN,CRASH_ADDR_LOW_MAX,CRASH_ADDR_HIGH_MAXandDEFAULT_CRASH_KERNEL_LOW_SIZEin <asm/crash_core.h>;Quoted 8 lines
2) Add
arch_reserve_crashkernel()to callparse_crashkernel()andreserve_crashkernel_generic();3) Add
ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATIONKconfiginarch/riscv/Kconfig.The old
reserve_crashkernel_low()andreserve_crashkernel()can be removed.Hi Baoquan,
Sorry for the late response. The refactor code has unified multiple arch via generic interface, which looks great!
However when I tested on my risc-v QEMU environment, a little problem occurred with following messages:
[ 0.000000] crashkernel low memory reserved: 0xf8000000 - 0x100000000 (128 MB) [ 0.000000] crashkernel reserved: 0x0000000177e00000 - 0x0000000277e00000 (4096 MB) [ 0.000000] ------------[ cut here ]------------ [ 0.000000] WARNING: CPU: 0 PID: 0 at kernel/resource.c:779 __insert_resource+0x8e/0xd0 [ 0.000000] Modules linked in: [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 6.6.0-rc2-next-20230920 #1 [ 0.000000] Hardware name: riscv-virtio,qemu (DT) [ 0.000000] epc : __insert_resource+0x8e/0xd0 [ 0.000000] ra : insert_resource+0x28/0x4e [ 0.000000] epc : ffffffff80017344 ra : ffffffff8001742e sp : ffffffff81203db0 [ 0.000000] gp : ffffffff812ece98 tp : ffffffff8120dac0 t0 : ff600001f7ff2b00 [ 0.000000] t1 : 0000000000000000 t2 : 3428203030303030 s0 : ffffffff81203dc0 [ 0.000000] s1 : ffffffff81211e18 a0 : ffffffff81211e18 a1 : ffffffff81289380 [ 0.000000] a2 : 0000000277dfffff a3 : 0000000177e00000 a4 : 0000000177e00000 [ 0.000000] a5 : ffffffff81289380 a6 : 0000000277dfffff a7 : 0000000000000078 [ 0.000000] s2 : ffffffff81289380 s3 : ffffffff80a0bac8 s4 : ff600001f7ff2880 [ 0.000000] s5 : 0000000000000280 s6 : 8000000a00006800 s7 : 000000000000007f [ 0.000000] s8 : 0000000080017038 s9 : 0000000080038ea0 s10: 0000000000000000 [ 0.000000] s11: 0000000000000000 t3 : ffffffff80a0bc00 t4 : ffffffff80a0bc00 [ 0.000000] t5 : ffffffff80a0bbd0 t6 : ffffffff80a0bc00 [ 0.000000] status: 0000000200000100 badaddr: 0000000000000000 cause: 0000000000000003 [ 0.000000] [<ffffffff80017344>] __insert_resource+0x8e/0xd0 [ 0.000000] ---[ end trace 0000000000000000 ]--- [ 0.000000] Failed to add a Crash kernel resource at 177e00000
Quoted 6 lines
The crashkernel memory has been allocated successfully, whereas it seems failed to insert into
iomem_resource. This should due to the unique reserving logic in risc-v arch specific code, i.e. crashk_res/crashk_low_res will be added intoiomem_resourcelater ininit_resources(), which is not aligned with the unified reserving logic.
You are right, I didn't check this in riscv arch carefully. The resouce adding is done repeatedly.
Quoted 4 lines
My simple solution here is removing the arch specific code within #ifdef
CONFIG_KEXEC_COREininit_resources(), which has been tested OK with all your testcases. Or do you have any other idea?
Yeah, that sounds good to me. You can post a patch with a detailed log to describe the spotted problem and the root cause.
Thanks for working on this, Jiahao.
Quoted 221 lines
Quoted 221 lines
Signed-off-by Baoquan He <[email protected]>--- arch/riscv/Kconfig | 3 + arch/riscv/include/asm/crash_core.h | 11 +++ arch/riscv/include/asm/processor.h | 2 + arch/riscv/mm/init.c | 141 +++------------------------- 4 files changed, 27 insertions(+), 130 deletions(-)create mode 100644
arch/riscv/include/asm/crash_core.harch/riscv/Kconfig +3
-0@@ -694,6 +694,9 @@ config ARCH_SUPPORTS_KEXEC_PURGATORY config ARCH_SUPPORTS_CRASH_DUMP def_bool y +config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION + def_bool CRASH_CORE + config COMPAT bool "Kernel support for 32-bit U-mode" default 64BITarch/riscv/include/asm/crash_core.h new file +11
-0@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _RISCV_CRASH_CORE_H +#define _RISCV_CRASH_CORE_H + +#define CRASH_ALIGN PMD_SIZE + +#define CRASH_ADDR_LOW_MAX dma32_phys_limit +#define CRASH_ADDR_HIGH_MAX memblock_end_of_DRAM() + +extern phys_addr_t memblock_end_of_DRAM (void ); +#endif arch/riscv/include/asm/processor.h +2
-0@@ -116,6 +116,8 @@ static inline void wait_for_interrupt(void) __asm__ __volatile__ ("wfi" ); } +extern phys_addr_t dma32_phys_limit; +struct device_node ;int riscv_of_processor_hartid (struct device_node *node,unsigned long *hartid);int riscv_early_of_processor_hartid (struct device_node *node,unsigned long *hartid);arch/riscv/mm/init.c +10
-129@@ -65,7 +65,7 @@ extern char _start[];void *_dtb_early_va__initdata ;uintptr_t _dtb_early_pa__initdata ; -static phys_addr_t dma32_phys_limit__initdata ; +phys_addr_t dma32_phys_limit__initdata ;static void __init zone_sizes_init (void ) {@@ -1333,28 +1333,6 @@ static inline void setup_vm_final(void) }#endif /* CONFIG_MMU */ -/* Reserve 128M low memory by default for swiotlb buffer */ -#define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20) - -static int __init reserve_crashkernel_low (unsigned long long low_size) -{ -unsigned long long low_base; - - low_base =memblock_phys_alloc_range (low_size,PMD_SIZE ,0 , dma32_phys_limit); -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%016llx - 0x%016llx (%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 ; - -return 0 ; -} -/* * reserve_crashkernel() - reserves memory for crash kernel * @@ -1362,122 +1340,25 @@ static int __init reserve_crashkernel_low(unsigned long long low_size)* 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_base =0 ; -unsigned long long crash_size =0 ; -unsigned long long crash_low_size =0 ; -unsigned long search_start =memblock_start_of_DRAM (); -unsigned long search_end = (unsigned long )dma32_phys_limit; +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 =0 ; +int ret;if (!IS_ENABLED (CONFIG_KEXEC_CORE ))return ; -/* -* Don't reserve a region for a crash kernel on a crash kernel -* since it doesn't make much sense and we have limited memory -* resources. -*/ -if (is_kdump_kernel ()) { -pr_info ("crashkernel: ignoring reservation request\n" ); -return ; - } ret =parse_crashkernel (cmdline,memblock_phys_mem_size (), - &crash_size, &crash_base,NULL ,NULL ); -if (ret == -ENOENT ) { -/* Fallback to crashkernel=X,[high,low] */ - ret =parse_crashkernel_high (cmdline,0 , &crash_size, &crash_base); -if (ret || !crash_size) -return ; - -/* -* crashkernel=Y,low is valid only when crashkernel=X,high -* is passed. -*/ - ret =parse_crashkernel_low (cmdline,0 , &crash_low_size, &crash_base); -if (ret == -ENOENT ) - crash_low_size =DEFAULT_CRASH_KERNEL_LOW_SIZE ; -else if (ret) -return ; - - search_start = (unsigned long )dma32_phys_limit; - search_end =memblock_end_of_DRAM (); - high = true; - }else if (ret || !crash_size) { -/* Invalid argument value specified */ + &crash_size, &crash_base, + &low_size, &high); +if (ret)return ; - } - - crash_size =PAGE_ALIGN (crash_size); - -if (crash_base) { - fixed_base = true; - search_start = crash_base; - search_end = crash_base + crash_size; - } - -/* -* Current riscv boot protocol requires 2MB alignment for -* RV64 and 4MB alignment for RV32 (hugepage size) -* -* Try to alloc from 32bit addressible physical memory so that -* swiotlb can work on the crash kernel. -*/ - crash_base =memblock_phys_alloc_range (crash_size,PMD_SIZE , - search_start, search_end); -if (crash_base ==0 ) { -/* -* For crashkernel=size[KMG]@offset[KMG], print out failure -* message if can't reserve the specified region. -*/ -if (fixed_base) { -pr_warn ("crashkernel: allocating failed with given size@offset\n" ); -return ; - } - -if (high) { -/* -* For crashkernel=size[KMG],high, if the first attempt was -* for high memory, fall back to low memory. -*/ - search_start =memblock_start_of_DRAM (); - search_end = (unsigned long )dma32_phys_limit; - }else { -/* -* For crashkernel=size[KMG], if the first attempt was for -* low memory, fall back to high memory, the minimum required -* low memory will be reserved later. -*/ - search_start = (unsigned long )dma32_phys_limit; - search_end =memblock_end_of_DRAM (); - crash_low_size =DEFAULT_CRASH_KERNEL_LOW_SIZE ; - } - - crash_base =memblock_phys_alloc_range (crash_size,PMD_SIZE , - search_start, search_end); -if (crash_base ==0 ) { -pr_warn ("crashkernel: couldn't allocate %lldKB\n" , - crash_size >>10 ); -return ; - } - } - -if ((crash_base >= dma32_phys_limit) && crash_low_size && -reserve_crashkernel_low (crash_low_size)) { -memblock_phys_free (crash_base, crash_size); -return ; - } - -pr_info ("crashkernel: reserved 0x%016llx - 0x%016llx (%lld MB)\n" , - crash_base, crash_base + crash_size, crash_size >>20 ); - crashk_res.start = crash_base; - crashk_res.end = crash_base + crash_size -1 ; +reserve_crashkernel_generic (cmdline, crash_size, crash_base, + low_size, high); }void __init paging_init (void )
Quoted 9 lines
arch/riscv/mm/init.c void __init misc_mem_init(void) · line 1381
Quoted 8 lines
arch/riscv/mm/init.c +1
-1@@ -1495,7 +1376,7 @@ void __init misc_mem_init(void)arch_numa_init ();sparse_init ();zone_sizes_init (); -reserve_crashkernel (); +arch_reserve_crashkernel ();memblock_dump_all (); }
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH v3 9/9 crash_core.c: remove unneeded functions
In reply to Baoquan HeSo far, nobody calls functions parse_crashkernel_high() and parse_crashkernel_low(), remove both of them.
--- include/linux/crash_core.h | 4 ---- kernel/crash_core.c | 18 ------------------ 2 files changed, 22 deletions(-)
include/linux/crash_core.h +0 -4
@@ -96,10 +96,6 @@ void final_note(Elf_Word *buf);int __init parse_crashkernel (char *cmdline,unsigned long long system_ram,unsigned long long *crash_size,unsigned long long *crash_base,unsigned long long *low_size,bool *high); -int parse_crashkernel_high (char *cmdline,unsigned long long system_ram, -unsigned long long *crash_size,unsigned long long *crash_base); -int parse_crashkernel_low (char *cmdline,unsigned long long system_ram, -unsigned long long *crash_size,unsigned long long *crash_base);#ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION #ifndef DEFAULT_CRASH_KERNEL_LOW_SIZE
kernel/crash_core.c +0 -18
@@ -350,24 +350,6 @@ int __init parse_crashkernel(char *cmdline,return ret; } -int __init parse_crashkernel_high (char *cmdline, -unsigned long long system_ram, -unsigned long long *crash_size, -unsigned long long *crash_base) -{ -return __parse_crashkernel (cmdline, system_ram, crash_size, crash_base, - suffix_tbl[SUFFIX_HIGH ]); -} - -int __init parse_crashkernel_low (char *cmdline, -unsigned long long system_ram, -unsigned long long *crash_size, -unsigned long long *crash_base) -{ -return __parse_crashkernel (cmdline, system_ram, crash_size, crash_base, - suffix_tbl[SUFFIX_LOW ]); -} -/* * Add a dummy early_param handler to mark crashkernel= as a known command line * parameter and suppress incorrect warnings in init/main.c.
Signature · 7 lines
2.41.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec