take the segment adding out of locate_mem_hole functions
PATCH v2 1/3 take the segment adding out of locate_mem_hole functions
In locate_mem_hole functions, a memory hole is located and added as kexec_segment. But from the name of locate_mem_hole, it should only take responsibility of searching a available memory hole to contain data of a specified size.
So in this patch add a new field 'mem' into kexec_buf, then take that kexec segment adding code out of locate_mem_hole_top_down and locate_mem_hole_bottom_up. This make clear of the functionality of locate_mem_hole just like it declars to do. And by this locate_mem_hole_callback chould be used later if anyone want to locate a memory hole for other use.
Meanwhile Vivek suggested opening code function __kexec_add_segment(), that way we have to retreive ksegment pointer once and it is easy to read. So just do it in this patch and remove __kexec_add_segment() since no one use it anymore.
--- include/linux/kexec.h | 1 + kernel/kexec.c | 29 ++++++++--------------------- 2 files changed, 9 insertions(+), 21 deletions(-)
include/linux/kexec.h +1 -0
@@ -178,6 +178,7 @@ struct kexec_buf {struct kimage *image;char *buffer;unsigned long bufsz; +unsigned long mem;unsigned long memsz;unsigned long buf_align;unsigned long buf_min;
kernel/kexec.c +8 -21
@@ -2016,22 +2016,6 @@ static int __init crash_save_vmcoreinfo_init(void)subsys_initcall (crash_save_vmcoreinfo_init);#ifdef CONFIG_KEXEC_FILE -static int __kexec_add_segment (struct kimage *image,char *buf, -unsigned long bufsz,unsigned long mem, -unsigned long memsz) -{ -struct kexec_segment *ksegment; - - ksegment = &image->segment[image->nr_segments]; - ksegment->kbuf = buf; - ksegment->bufsz = bufsz; - ksegment->mem = mem; - ksegment->memsz = memsz; - image->nr_segments++; - -return 0 ; -} -static int locate_mem_hole_top_down (unsigned long start,unsigned long end,struct kexec_buf *kbuf) {
@@ -2064,8 +2048,7 @@ static int locate_mem_hole_top_down(unsigned long start, unsigned long end, }while (1 );/* If we are here, we found a suitable memory range */ -__kexec_add_segment (image, kbuf->buffer, kbuf->bufsz, temp_start, - kbuf->memsz); + kbuf->mem = temp_start;/* Success, stop navigating through remaining System RAM ranges */ return 1 ;
@@ -2099,8 +2082,7 @@ static int locate_mem_hole_bottom_up(unsigned long start, unsigned long end, }while (1 );/* If we are here, we found a suitable memory range */ -__kexec_add_segment (image, kbuf->buffer, kbuf->bufsz, temp_start, - kbuf->memsz); + kbuf->mem = temp_start;/* Success, stop navigating through remaining System RAM ranges */ return 1 ;
@@ -2187,7 +2169,12 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz, }/* Found a suitable memory range */ - ksegment = &image->segment[image->nr_segments -1 ]; + ksegment = &image->segment[image->nr_segments]; + ksegment->kbuf = kbuf->buffer; + ksegment->bufsz = kbuf->bufsz; + ksegment->mem = kbuf->mem; + ksegment->memsz = kbuf->memsz; + image->nr_segments++; *load_addr = ksegment->mem;return 0 ; }
Signature · 1 line
1.8.5.3
PATCH v2 2/3 check if crashk_res_low exists when exclude it from crash mem ranges
Add a check if crashk_res_low exists just like GART region does. If crashk_res_low doesn't exist, calling exclude_mem_range is unnecessary.
Meanwhile, since crashk_res_low has been initialized at definition, it's safe just use "if (crashk_low_res.end)" to check if it's exist. And this can make it consistent with other places of check.
--- arch/x86/kernel/crash.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
arch/x86/kernel/crash.c +6 -4
@@ -237,7 +237,7 @@ static void fill_up_crash_elf_data(struct crash_elf_data *ced, ced->max_nr_ranges++;/* If crashk_low_res is not 0, another range split possible */ -if (crashk_low_res.end !=0 ) +if (crashk_low_res.end) ced->max_nr_ranges++; }
@@ -335,9 +335,11 @@ static int elf_header_exclude_ranges(struct crash_elf_data *ced,if (ret)return ret; - ret =exclude_mem_range (cmem, crashk_low_res.start, crashk_low_res.end); -if (ret) -return ret; +if (crashk_low_res.end) { + ret =exclude_mem_range (cmem, crashk_low_res.start, crashk_low_res.end); +if (ret) +return ret; + }/* Exclude GART region */ if (ced->gart_end) {
Signature · 1 line
1.8.5.3
PATCH v2 3/3 kexec: remove the unused function parameter
In reply to Baoquan HeThis is a cleanup. In function parse_crashkernel_suffix, the parameter crash_base is not used. So here remove it.
--- kernel/kexec.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/kexec.c +1 -2
@@ -1759,7 +1759,6 @@ static __initdata char *suffix_tbl[] = {*/ static int __init parse_crashkernel_suffix (char *cmdline,unsigned long long *crash_size, -unsigned long long *crash_base,const char *suffix) {char *cur = cmdline;
@@ -1848,7 +1847,7 @@ static int __init __parse_crashkernel(char *cmdline,if (suffix)return parse_crashkernel_suffix (ck_cmdline, crash_size, - crash_base, suffix); + suffix);/* * if the commandline contains a ':', then that's the extended * syntax -- if not, it must be the classic syntax
Signature · 1 line
1.8.5.3
Sorry, CC this patchset to Andrew.
Quoted 99 lines · Baoquan He
In
locate_mem_holefunctions, a memory hole is located and added askexec_segment. But from the name oflocate_mem_hole, it should only take responsibility of searching a available memory hole to contain data of a specified size.So in this patch add a new field 'mem' into
kexec_buf, then take that kexec segment adding code out oflocate_mem_hole_top_downandlocate_mem_hole_bottom_up. This make clear of the functionality oflocate_mem_holejust like it declars to do. And by thislocate_mem_hole_callbackchould be used later if anyone want to locate a memory hole for other use.Meanwhile Vivek suggested opening code function
__kexec_add_segment(), that way we have to retreive ksegment pointer once and it is easy to read. So just do it in this patch and remove__kexec_add_segment()since no one use it anymore.Signed-off-by Baoquan He <[email protected]>--- include/linux/kexec.h | 1 + kernel/kexec.c | 29 ++++++++--------------------- 2 files changed, 9 insertions(+), 21 deletions(-)include/linux/kexec.h +1
-0@@ -178,6 +178,7 @@ struct kexec_buf {struct kimage *image;char *buffer;unsigned long bufsz; +unsigned long mem;unsigned long memsz;unsigned long buf_align;unsigned long buf_min;kernel/kexec.c +8
-21@@ -2016,22 +2016,6 @@ static int __init crash_save_vmcoreinfo_init(void)subsys_initcall (crash_save_vmcoreinfo_init);#ifdef CONFIG_KEXEC_FILE -static int __kexec_add_segment (struct kimage *image,char *buf, -unsigned long bufsz,unsigned long mem, -unsigned long memsz) -{ -struct kexec_segment *ksegment; - - ksegment = &image->segment[image->nr_segments]; - ksegment->kbuf = buf; - ksegment->bufsz = bufsz; - ksegment->mem = mem; - ksegment->memsz = memsz; - image->nr_segments++; - -return 0 ; -} -static int locate_mem_hole_top_down (unsigned long start,unsigned long end,struct kexec_buf *kbuf) {@@ -2064,8 +2048,7 @@ static int locate_mem_hole_top_down(unsigned long start, unsigned long end, }while (1 );/* If we are here, we found a suitable memory range */ -__kexec_add_segment (image, kbuf->buffer, kbuf->bufsz, temp_start, - kbuf->memsz); + kbuf->mem = temp_start;/* Success, stop navigating through remaining System RAM ranges */ return 1 ;@@ -2099,8 +2082,7 @@ static int locate_mem_hole_bottom_up(unsigned long start, unsigned long end, }while (1 );/* If we are here, we found a suitable memory range */ -__kexec_add_segment (image, kbuf->buffer, kbuf->bufsz, temp_start, - kbuf->memsz); + kbuf->mem = temp_start;/* Success, stop navigating through remaining System RAM ranges */ return 1 ;@@ -2187,7 +2169,12 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz, }/* Found a suitable memory range */ - ksegment = &image->segment[image->nr_segments -1 ]; + ksegment = &image->segment[image->nr_segments]; + ksegment->kbuf = kbuf->buffer; + ksegment->bufsz = kbuf->bufsz; + ksegment->mem = kbuf->mem; + ksegment->memsz = kbuf->memsz; + image->nr_segments++; *load_addr = ksegment->mem;return 0 ; }Signature · 1 line
1.8.5.3
Quoted 12 lines · Baoquan He
In
locate_mem_holefunctions, a memory hole is located and added askexec_segment. But from the name oflocate_mem_hole, it should only take responsibility of searching a available memory hole to contain data of a specified size.So in this patch add a new field 'mem' into
kexec_buf, then take that kexec segment adding code out oflocate_mem_hole_top_downandlocate_mem_hole_bottom_up. This make clear of the functionality oflocate_mem_holejust like it declars to do. And by thislocate_mem_hole_callbackchould be used later if anyone want to locate a memory hole for other use.
Quoted 6 lines
Meanwhile Vivek suggested opening code function
__kexec_add_segment(), that way we have to retreive ksegment pointer once and it is easy to read. So just do it in this patch and remove__kexec_add_segment()since no one use it anymore.Signed-off-by Baoquan He <[email protected]>
Bao,
These 3 patches look good to me. I am assuming you have tested these to make sure nothing is broken.
Thanks
Vivek
Quoted 80 lines
--- include/linux/kexec.h | 1 + kernel/kexec.c | 29 ++++++++--------------------- 2 files changed, 9 insertions(+), 21 deletions(-)include/linux/kexec.h +1
-0@@ -178,6 +178,7 @@ struct kexec_buf {struct kimage *image;char *buffer;unsigned long bufsz; +unsigned long mem;unsigned long memsz;unsigned long buf_align;unsigned long buf_min;kernel/kexec.c +8
-21@@ -2016,22 +2016,6 @@ static int __init crash_save_vmcoreinfo_init(void)subsys_initcall (crash_save_vmcoreinfo_init);#ifdef CONFIG_KEXEC_FILE -static int __kexec_add_segment (struct kimage *image,char *buf, -unsigned long bufsz,unsigned long mem, -unsigned long memsz) -{ -struct kexec_segment *ksegment; - - ksegment = &image->segment[image->nr_segments]; - ksegment->kbuf = buf; - ksegment->bufsz = bufsz; - ksegment->mem = mem; - ksegment->memsz = memsz; - image->nr_segments++; - -return 0 ; -} -static int locate_mem_hole_top_down (unsigned long start,unsigned long end,struct kexec_buf *kbuf) {@@ -2064,8 +2048,7 @@ static int locate_mem_hole_top_down(unsigned long start, unsigned long end, }while (1 );/* If we are here, we found a suitable memory range */ -__kexec_add_segment (image, kbuf->buffer, kbuf->bufsz, temp_start, - kbuf->memsz); + kbuf->mem = temp_start;/* Success, stop navigating through remaining System RAM ranges */ return 1 ;@@ -2099,8 +2082,7 @@ static int locate_mem_hole_bottom_up(unsigned long start, unsigned long end, }while (1 );/* If we are here, we found a suitable memory range */ -__kexec_add_segment (image, kbuf->buffer, kbuf->bufsz, temp_start, - kbuf->memsz); + kbuf->mem = temp_start;/* Success, stop navigating through remaining System RAM ranges */ return 1 ;@@ -2187,7 +2169,12 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz, }/* Found a suitable memory range */ - ksegment = &image->segment[image->nr_segments -1 ]; + ksegment = &image->segment[image->nr_segments]; + ksegment->kbuf = kbuf->buffer; + ksegment->bufsz = kbuf->bufsz; + ksegment->mem = kbuf->mem; + ksegment->memsz = kbuf->memsz; + image->nr_segments++; *load_addr = ksegment->mem;return 0 ; }Signature · 1 line
1.8.5.3