Some bug fixes and cleanups related to kexec
Subsystems (6)
v5 cover Some bug fixes and cleanups related to kexec
This series includes some bug fixes and cleanups for kexec.
This v5 series introduces no changes to any patches. I just reorganize the patches and repost them.
Yuntao Wang (3):
kexec: modify the meaning of the end parameter in
kimage_is_destination_range()
kexec_file: fix incorrect temp_start value in
locate_mem_hole_top_down()
x86/kexec: use pr_err() instead of pr_debug() when an error occurs
arch/x86/kernel/kexec-bzimage64.c | 2 +- kernel/kexec_core.c | 8 ++++---- kernel/kexec_file.c | 4 ++-- mm/highmem.c | 2 -- 4 files changed, 7 insertions(+), 9 deletions(-)
Signature · 1 line
2.43.0
PATCH v5 1/3 kexec: modify the meaning of the end parameter in kimage_is_destination_range()
The end parameter received by kimage_is_destination_range() should be the last valid byte address of the target memory segment plus 1. However, in the locate_mem_hole_bottom_up() and locate_mem_hole_top_down() functions, the corresponding value passed to kimage_is_destination_range() is the last valid byte address of the target memory segment, which is 1 less.
There are two ways to fix this bug. We can either correct the logic of the locate_mem_hole_bottom_up() and locate_mem_hole_top_down() functions, or we can fix kimage_is_destination_range() by making the end parameter represent the last valid byte address of the target memory segment. Here, we choose the second approach.
Due to the modification to kimage_is_destination_range(), we also need to adjust its callers, such as kimage_alloc_normal_control_pages() and kimage_alloc_page().
---v1->v2:
Fix this issue using the approach suggested by Eric and Baoquan.
v2->v3:
Modify the assignment of eaddr as suggested by Baoquan.
v3->v4:
eaddr = epfn << PAGE_SHIFT - 1 causes a compilation warning, fix it.
v4->v5:
No changes.
kernel/kexec_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/kexec_core.c +4 -4
@@ -276,8 +276,8 @@ int kimage_is_destination_range(struct kimage *image,unsigned long mstart, mend; mstart = image->segment[i].mem; - mend = mstart + image->segment[i].memsz; -if ((end > mstart) && (start < mend)) + mend = mstart + image->segment[i].memsz -1 ; +if ((end >= mstart) && (start <= mend))return 1 ; }
@@ -370,7 +370,7 @@ static struct page *kimage_alloc_normal_control_pages(struct kimage *image, pfn =page_to_boot_pfn (pages); epfn = pfn + count; addr = pfn <<PAGE_SHIFT ; - eaddr = epfn <<PAGE_SHIFT ; + eaddr = (epfn <<PAGE_SHIFT ) -1 ;if ((epfn >= (KEXEC_CONTROL_MEMORY_LIMIT >>PAGE_SHIFT )) ||kimage_is_destination_range (image, addr, eaddr)) {list_add (&pages->lru, &extra_pages);
@@ -716,7 +716,7 @@ static struct page *kimage_alloc_page(struct kimage *image,/* If the page is not a destination page use it */ if (!kimage_is_destination_range (image, addr, - addr +PAGE_SIZE )) + addr +PAGE_SIZE -1 ))break ;/*
Signature · 1 line
2.43.0
PATCH v5 2/3 kexec_file: fix incorrect temp_start value in locate_mem_hole_top_down()
In reply to Yuntao Wangtemp_end represents the address of the last available byte. Therefore, the starting address of the memory segment with temp_end as its last available byte and a size of kbuf->memsz, that is, the value of temp_start, should be temp_end - kbuf->memsz + 1 instead of temp_end - kbuf->memsz.
Additionally, use the ALIGN_DOWN macro instead of open-coding it directly in locate_mem_hole_top_down() to improve code readability.
--- kernel/kexec_file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/kexec_file.c +2 -2
@@ -426,11 +426,11 @@ static int locate_mem_hole_top_down(unsigned long start, unsigned long end,unsigned long temp_start, temp_end; temp_end =min (end, kbuf->buf_max); - temp_start = temp_end - kbuf->memsz; + temp_start = temp_end - kbuf->memsz +1 ; do { /* align down start */ - temp_start = temp_start & (~(kbuf->buf_align - 1)); + temp_start = ALIGN_DOWN(temp_start, kbuf->buf_align); if (temp_start < start || temp_start < kbuf->buf_min) return 0;
Signature · 1 line
2.43.0
PATCH v5 3/3 x86/kexec: use pr_err() instead of pr_debug() when an error occurs
In reply to Yuntao WangWhen an error is detected, use pr_err() instead of pr_debug() to output log message.
In addition, remove the unnecessary return from set_page_address().
--- arch/x86/kernel/kexec-bzimage64.c | 2 +- mm/highmem.c | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-)
arch/x86/kernel/kexec-bzimage64.c +1 -1
@@ -424,7 +424,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,* command line. Make sure it does not overflow */ if (cmdline_len +MAX_ELFCOREHDR_STR_LEN > header->cmdline_size) { -pr_debug ("Appending elfcorehdr=<addr> to command line exceeds maximum allowed length\n" ); +pr_err ("Appending elfcorehdr=<addr> to command line exceeds maximum allowed length\n" );return ERR_PTR (-EINVAL ); }
mm/highmem.c +0 -2
@@ -799,8 +799,6 @@ void set_page_address(struct page *page, void *virtual) }spin_unlock_irqrestore (&pas->lock, flags); } - -return ; }void __init page_address_init (void )
Signature · 1 line
2.43.0
Andrew Morton
maintainerRe: [PATCH v5 3/3] x86/kexec: use pr_err() instead of pr_debug() when an error occurs
Quoted 10 lines · On Sun, 17 Dec 2023 11:35:28 +0800 Yuntao Wang <[email protected]> wrote:
When an error is detected, use
pr_err()instead ofpr_debug()to output log message.In addition, remove the unnecessary return from
set_page_address()....
arch/x86/kernel/kexec-bzimage64.c static void *bzImage64_load(struct kimage *image, char *kernel, · line 429
Quoted 7 lines
arch/x86/kernel/kexec-bzimage64.c +1
-1@@ -424,7 +424,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,* command line. Make sure it does not overflow */ if (cmdline_len +MAX_ELFCOREHDR_STR_LEN > header->cmdline_size) { -pr_debug ("Appending elfcorehdr=<addr> to command line exceeds maximum allowed length\n" ); +pr_err ("Appending elfcorehdr=<addr> to command line exceeds maximum allowed length\n" );return ERR_PTR (-EINVAL ); }
https://lkml.kernel.org/r/[email protected] has already changed this to call kexec_dprintk(). I'll skip this patch.
PATCH 1/1 x86/kexec: use pr_err() instead of kexec_dprintk() when an error occurs
When an error is detected, use pr_err() instead of kexec_dprintk() to output log message.
In addition, remove the unnecessary return from set_page_address().
--- arch/x86/kernel/kexec-bzimage64.c | 2 +- mm/highmem.c | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-)
arch/x86/kernel/kexec-bzimage64.c +1 -1
@@ -429,7 +429,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,* command line. Make sure it does not overflow */ if (cmdline_len +MAX_ELFCOREHDR_STR_LEN > header->cmdline_size) { -kexec_dprintk ("Appending elfcorehdr=<addr> to command line exceeds maximum allowed length\n" ); +pr_err ("Appending elfcorehdr=<addr> to command line exceeds maximum allowed length\n" );return ERR_PTR (-EINVAL ); }
mm/highmem.c +0 -2
@@ -799,8 +799,6 @@ void set_page_address(struct page *page, void *virtual) }spin_unlock_irqrestore (&pas->lock, flags); } - -return ; }void __init page_address_init (void )
Signature · 1 line
2.43.0
Andrew Morton
maintainerRe: [PATCH] x86/kexec: use pr_err() instead of kexec_dprintk() when an error occurs
Quoted 4 lines · On Tue, 19 Dec 2023 15:29:01 +0800 Yuntao Wang <[email protected]> wrote:
When an error is detected, use
pr_err()instead ofkexec_dprintk()to output log message.In addition, remove the unnecessary return from
set_page_address().
The above describes what the code does, which is already quite clear from looking at the code.
Please write changelogs and code comments which describe *why* the code does something, rather than *what* it does.
arch/x86/kernel/kexec-bzimage64.c static void *bzImage64_load(struct kimage *image, char *kernel, · line 432
Quoted 10 lines
arch/x86/kernel/kexec-bzimage64.c +1
-1@@ -429,7 +429,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,* command line. Make sure it does not overflow */ if (cmdline_len +MAX_ELFCOREHDR_STR_LEN > header->cmdline_size) { -kexec_dprintk ("Appending elfcorehdr=<addr> to command line exceeds maximum allowed length\n" ); +pr_err ("Appending elfcorehdr=<addr> to command line exceeds maximum allowed length\n" );
ie, what are the reasons for this change?
Quoted 18 lines
arch/x86/kernel/kexec-bzimage64.c +0
-0return ERR_PTR (-EINVAL ); }mm/highmem.c +0
-2@@ -799,8 +799,6 @@ void set_page_address(struct page *page, void *virtual) }spin_unlock_irqrestore (&pas->lock, flags); } - -return ; }void __init page_address_init (void )Signature · 1 line
2.43.0
PATCH v2 1/1 x86/kexec: use pr_err() instead of kexec_dprintk() when an error occurs
When detecting an error, the current code uses kexec_dprintk() to output log message. This is not quite appropriate as kexec_dprintk() is mainly used for outputting debugging messages, rather than error messages.
Replace kexec_dprintk() with pr_err(). This also makes the output method for this error log align with the output method for other error logs in this function.
Additionally, the last return statement in set_page_address() is unnecessary, remove it.
---
v1 -> v2: Rewrite changelogs
arch/x86/kernel/kexec-bzimage64.c | 2 +- mm/highmem.c | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-)
arch/x86/kernel/kexec-bzimage64.c +1 -1
@@ -429,7 +429,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,* command line. Make sure it does not overflow */ if (cmdline_len +MAX_ELFCOREHDR_STR_LEN > header->cmdline_size) { -kexec_dprintk ("Appending elfcorehdr=<addr> to command line exceeds maximum allowed length\n" ); +pr_err ("Appending elfcorehdr=<addr> to command line exceeds maximum allowed length\n" );return ERR_PTR (-EINVAL ); }
mm/highmem.c +0 -2
@@ -799,8 +799,6 @@ void set_page_address(struct page *page, void *virtual) }spin_unlock_irqrestore (&pas->lock, flags); } - -return ; }void __init page_address_init (void )
Signature · 1 line
2.43.0
Quoted 4 lines · Yuntao Wang
This series includes some bug fixes and cleanups for kexec.
This v5 series introduces no changes to any patches. I just reorganize the patches and repost them.
LGTM, thx.
Quoted 17 lines
Yuntao Wang (3):
kexec: modify the meaning of the end parameter in
kimage_is_destination_range()
kexec_file: fix incorrecttemp_startvalue in
locate_mem_hole_top_down()
x86/kexec: usepr_err()instead ofpr_debug()when an error occursarch/x86/kernel/kexec-bzimage64.c | 2 +- kernel/kexec_core.c | 8 ++++---- kernel/kexec_file.c | 4 ++-- mm/highmem.c | 2 -- 4 files changed, 7 insertions(+), 9 deletions(-)Signature · 1 line
2.43.0