public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] kexec: print out debugging message if required for kexec_load
@ 2025-11-03  6:34 Qiang Ma
  2025-11-03  6:34 ` [PATCH v2 1/4] kexec: Fix uninitialized struct kimage *image pointer Qiang Ma
                   ` (3 more replies)
  0 siblings, 4 replies; 22+ messages in thread
From: Qiang Ma @ 2025-11-03  6:34 UTC (permalink / raw)
  To: akpm, bhe; +Cc: kexec, linux-kernel, Qiang Ma

Overview:
=========
The commit a85ee18c7900 ("kexec_file: print out debugging message
if required") has added general code printing in kexec_file_load(),
but not in kexec_load().
    
Since kexec_load and kexec_file_load are not triggered simultaneously,
we can unify the debug flag of kexec and kexec_file as kexec_core_dbg_print.
    
Next, we need to do some things in this patchset:
    
1. rename kexec_file_dbg_print to kexec_core_dbg_print
2. Add KEXEC_DEBUG
3. Initialize kexec_core_dbg_print for kexec
4. Fix uninitialized struct kimage *image pointer 
5. Set the reset of kexec_file_dbg_print to kimage_free

Testing:
=========
I did testing on x86_64, arm64 and loongarch. On x86_64, the printed messages
look like below:

unset CONFIG_KEXEC_FILE:
[   81.476959] kexec: nr_segments = 7
[   81.477565] kexec: segment[0]: buf=0x00000000c22469d2 bufsz=0x70 mem=0x100000 memsz=0x1000
[   81.478797] kexec: segment[1]: buf=0x00000000dedbb3b1 bufsz=0x140 mem=0x101000 memsz=0x1000
[   81.480075] kexec: segment[2]: buf=0x00000000d7657a33 bufsz=0x30 mem=0x102000 memsz=0x1000
[   81.481288] kexec: segment[3]: buf=0x00000000c7eb60a6 bufsz=0x16f40a8 mem=0x23bd0b000 memsz=0x16f5000
[   81.489018] kexec: segment[4]: buf=0x00000000d1ca53c8 bufsz=0xd73400 mem=0x23d400000 memsz=0x2ab7000
[   81.499697] kexec: segment[5]: buf=0x00000000697bac5a bufsz=0x50dc mem=0x23fff1000 memsz=0x6000
[   81.501084] kexec: segment[6]: buf=0x000000001f743a68 bufsz=0x70e0 mem=0x23fff7000 memsz=0x9000
[   81.502374] kexec: kexec_load: type:0, start:0x23fff7700 head:0x10a4b9002 flags:0x3e0010

set CONFIG_KEXEC_FILE
[   36.774228] kexec_file: kernel: 0000000066c386c8 kernel_size: 0xd78400
[   36.821814] kexec-bzImage64: Loaded purgatory at 0x23fffb000
[   36.821826] kexec-bzImage64: Loaded boot_param, command line and misc at 0x23fff9000 bufsz=0x12d0 memsz=0x2000
[   36.821829] kexec-bzImage64: Loaded 64bit kernel at 0x23d400000 bufsz=0xd73400 memsz=0x2ab7000
[   36.821918] kexec-bzImage64: Loaded initrd at 0x23bd0b000 bufsz=0x16f40a8 memsz=0x16f40a8
[   36.821920] kexec-bzImage64: Final command line is: root=/dev/mapper/test-root crashkernel=auto rd.lvm.lv=test/root
[   36.821925] kexec-bzImage64: E820 memmap:
[   36.821926] kexec-bzImage64: 0000000000000000-000000000009ffff (1)
[   36.821928] kexec-bzImage64: 0000000000100000-0000000000811fff (1)
[   36.821930] kexec-bzImage64: 0000000000812000-0000000000812fff (2)
[   36.821931] kexec-bzImage64: 0000000000813000-00000000bee38fff (1)
[   36.821933] kexec-bzImage64: 00000000bee39000-00000000beec2fff (2)
[   36.821934] kexec-bzImage64: 00000000beec3000-00000000bf8ecfff (1)
[   36.821935] kexec-bzImage64: 00000000bf8ed000-00000000bfb6cfff (2)
[   36.821936] kexec-bzImage64: 00000000bfb6d000-00000000bfb7efff (3)
[   36.821937] kexec-bzImage64: 00000000bfb7f000-00000000bfbfefff (4)
[   36.821938] kexec-bzImage64: 00000000bfbff000-00000000bff7bfff (1)
[   36.821939] kexec-bzImage64: 00000000bff7c000-00000000bfffffff (2)
[   36.821940] kexec-bzImage64: 00000000feffc000-00000000feffffff (2)
[   36.821941] kexec-bzImage64: 00000000ffc00000-00000000ffffffff (2)
[   36.821942] kexec-bzImage64: 0000000100000000-000000023fffffff (1)
[   36.872348] kexec_file: nr_segments = 4
[   36.872356] kexec_file: segment[0]: buf=0x000000005314ece7 bufsz=0x4000 mem=0x23fffb000 memsz=0x5000
[   36.872370] kexec_file: segment[1]: buf=0x000000006e59b143 bufsz=0x12d0 mem=0x23fff9000 memsz=0x2000
[   36.872374] kexec_file: segment[2]: buf=0x00000000eb7b1fc3 bufsz=0xd73400 mem=0x23d400000 memsz=0x2ab7000
[   36.882172] kexec_file: segment[3]: buf=0x000000006af76441 bufsz=0x16f40a8 mem=0x23bd0b000 memsz=0x16f5000
[   36.889113] kexec_file: kexec_file_load: type:0, start:0x23fffb150 head:0x101a2e002 flags:0x8

Changes in v2:
==========
- Unify the debug flag of kexec and kexec_file
- Fix uninitialized struct kimage *image pointer
- Fix the issue of mismatch between loop variable types

Qiang Ma (4):
  kexec: Fix uninitialized struct kimage *image pointer
  kexec: add kexec_core flag to control debug printing
  kexec: print out debugging message if required for kexec_load
  kexec_file: Fix the issue of mismatch between loop variable types

 include/linux/kexec.h      |  9 +++++----
 include/uapi/linux/kexec.h |  1 +
 kernel/kexec.c             | 16 +++++++++++++++-
 kernel/kexec_core.c        |  4 +++-
 kernel/kexec_file.c        |  9 ++++-----
 5 files changed, 28 insertions(+), 11 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH v2 1/4] kexec: Fix uninitialized struct kimage *image pointer
  2025-11-03  6:34 [PATCH v2 0/4] kexec: print out debugging message if required for kexec_load Qiang Ma
@ 2025-11-03  6:34 ` Qiang Ma
  2025-11-03  6:34 ` [PATCH v2 2/4] kexec: add kexec_core flag to control debug printing Qiang Ma
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 22+ messages in thread
From: Qiang Ma @ 2025-11-03  6:34 UTC (permalink / raw)
  To: akpm, bhe; +Cc: kexec, linux-kernel, Qiang Ma

The image is initialized to NULL. Then, after calling kimage_alloc_init,
we can directly goto 'out' because at this time, the kimage_free will
determine whether image is a NULL pointer.

This can also prepare for the subsequent patch's kexec_core_dbg_print
to be reset to zero in kimage_free.

Signed-off-by: Qiang Ma <maqianga@uniontech.com>
---
 kernel/kexec.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/kexec.c b/kernel/kexec.c
index 28008e3d462e..9bb1f2b6b268 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -95,6 +95,8 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
 	unsigned long i;
 	int ret;
 
+	image = NULL;
+
 	/*
 	 * Because we write directly to the reserved memory region when loading
 	 * crash kernels we need a serialization here to prevent multiple crash
@@ -129,7 +131,7 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
 
 	ret = kimage_alloc_init(&image, entry, nr_segments, segments, flags);
 	if (ret)
-		goto out_unlock;
+		goto out;
 
 	if (flags & KEXEC_PRESERVE_CONTEXT)
 		image->preserve_context = 1;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v2 2/4] kexec: add kexec_core flag to control debug printing
  2025-11-03  6:34 [PATCH v2 0/4] kexec: print out debugging message if required for kexec_load Qiang Ma
  2025-11-03  6:34 ` [PATCH v2 1/4] kexec: Fix uninitialized struct kimage *image pointer Qiang Ma
@ 2025-11-03  6:34 ` Qiang Ma
  2025-11-05  3:09   ` Baoquan He
  2025-11-03  6:34 ` [PATCH v2 3/4] kexec: print out debugging message if required for kexec_load Qiang Ma
  2025-11-03  6:34 ` [PATCH v2 4/4] kexec_file: Fix the issue of mismatch between loop variable types Qiang Ma
  3 siblings, 1 reply; 22+ messages in thread
From: Qiang Ma @ 2025-11-03  6:34 UTC (permalink / raw)
  To: akpm, bhe; +Cc: kexec, linux-kernel, Qiang Ma

The commit a85ee18c7900 ("kexec_file: print out debugging message
if required") has added general code printing in kexec_file_load(),
but not in kexec_load().

Since kexec_load and kexec_file_load are not triggered
simultaneously, we can unify the debug flag of kexec and kexec_file
as kexec_core_dbg_print.

Next, we need to do four things:

1. rename kexec_file_dbg_print to kexec_core_dbg_print
2. Add KEXEC_DEBUG
3. Initialize kexec_core_dbg_print for kexec
4. Set the reset of kexec_file_dbg_print to kimage_free

Signed-off-by: Qiang Ma <maqianga@uniontech.com>
---
 include/linux/kexec.h      | 9 +++++----
 include/uapi/linux/kexec.h | 1 +
 kernel/kexec.c             | 1 +
 kernel/kexec_core.c        | 4 +++-
 kernel/kexec_file.c        | 4 +---
 5 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index ff7e231b0485..cad8b5c362af 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -455,10 +455,11 @@ bool kexec_load_permitted(int kexec_image_type);
 
 /* List of defined/legal kexec flags */
 #ifndef CONFIG_KEXEC_JUMP
-#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR | KEXEC_CRASH_HOTPLUG_SUPPORT)
+#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR | KEXEC_CRASH_HOTPLUG_SUPPORT | \
+			KEXEC_DEBUG)
 #else
 #define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT | KEXEC_UPDATE_ELFCOREHDR | \
-			KEXEC_CRASH_HOTPLUG_SUPPORT)
+			KEXEC_CRASH_HOTPLUG_SUPPORT | KEXEC_DEBUG)
 #endif
 
 /* List of defined/legal kexec file flags */
@@ -525,10 +526,10 @@ static inline int arch_kexec_post_alloc_pages(void *vaddr, unsigned int pages, g
 static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) { }
 #endif
 
-extern bool kexec_file_dbg_print;
+extern bool kexec_core_dbg_print;
 
 #define kexec_dprintk(fmt, arg...) \
-        do { if (kexec_file_dbg_print) pr_info(fmt, ##arg); } while (0)
+	do { if (kexec_core_dbg_print) pr_info(fmt, ##arg); } while (0)
 
 extern void *kimage_map_segment(struct kimage *image, unsigned long addr, unsigned long size);
 extern void kimage_unmap_segment(void *buffer);
diff --git a/include/uapi/linux/kexec.h b/include/uapi/linux/kexec.h
index 55749cb0b81d..819c600af125 100644
--- a/include/uapi/linux/kexec.h
+++ b/include/uapi/linux/kexec.h
@@ -14,6 +14,7 @@
 #define KEXEC_PRESERVE_CONTEXT	0x00000002
 #define KEXEC_UPDATE_ELFCOREHDR	0x00000004
 #define KEXEC_CRASH_HOTPLUG_SUPPORT 0x00000008
+#define KEXEC_DEBUG		0x00000010
 #define KEXEC_ARCH_MASK		0xffff0000
 
 /*
diff --git a/kernel/kexec.c b/kernel/kexec.c
index 9bb1f2b6b268..c7a869d32f87 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -42,6 +42,7 @@ static int kimage_alloc_init(struct kimage **rimage, unsigned long entry,
 	if (!image)
 		return -ENOMEM;
 
+	kexec_core_dbg_print = !!(flags & KEXEC_DEBUG);
 	image->start = entry;
 	image->nr_segments = nr_segments;
 	memcpy(image->segment, segments, nr_segments * sizeof(*segments));
diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index fa00b239c5d9..865f2b14f23b 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -53,7 +53,7 @@ atomic_t __kexec_lock = ATOMIC_INIT(0);
 /* Flag to indicate we are going to kexec a new kernel */
 bool kexec_in_progress = false;
 
-bool kexec_file_dbg_print;
+bool kexec_core_dbg_print;
 
 /*
  * When kexec transitions to the new kernel there is a one-to-one
@@ -576,6 +576,8 @@ void kimage_free(struct kimage *image)
 	kimage_entry_t *ptr, entry;
 	kimage_entry_t ind = 0;
 
+	kexec_core_dbg_print = false;
+
 	if (!image)
 		return;
 
diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index eb62a9794242..4a24aadbad02 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -138,8 +138,6 @@ void kimage_file_post_load_cleanup(struct kimage *image)
 	 */
 	kfree(image->image_loader_data);
 	image->image_loader_data = NULL;
-
-	kexec_file_dbg_print = false;
 }
 
 #ifdef CONFIG_KEXEC_SIG
@@ -314,7 +312,7 @@ kimage_file_alloc_init(struct kimage **rimage, int kernel_fd,
 	if (!image)
 		return -ENOMEM;
 
-	kexec_file_dbg_print = !!(flags & KEXEC_FILE_DEBUG);
+	kexec_core_dbg_print = !!(flags & KEXEC_FILE_DEBUG);
 	image->file_mode = 1;
 
 #ifdef CONFIG_CRASH_DUMP
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v2 3/4] kexec: print out debugging message if required for kexec_load
  2025-11-03  6:34 [PATCH v2 0/4] kexec: print out debugging message if required for kexec_load Qiang Ma
  2025-11-03  6:34 ` [PATCH v2 1/4] kexec: Fix uninitialized struct kimage *image pointer Qiang Ma
  2025-11-03  6:34 ` [PATCH v2 2/4] kexec: add kexec_core flag to control debug printing Qiang Ma
@ 2025-11-03  6:34 ` Qiang Ma
  2025-11-05  3:01   ` Baoquan He
  2025-11-03  6:34 ` [PATCH v2 4/4] kexec_file: Fix the issue of mismatch between loop variable types Qiang Ma
  3 siblings, 1 reply; 22+ messages in thread
From: Qiang Ma @ 2025-11-03  6:34 UTC (permalink / raw)
  To: akpm, bhe; +Cc: kexec, linux-kernel, Qiang Ma, kernel test robot

The commit a85ee18c7900 ("kexec_file: print out debugging message
if required") has added general code printing in kexec_file_load(),
but not in kexec_load().

Especially in the RISC-V architecture, kexec_image_info() has been
removed(commit eb7622d908a0 ("kexec_file, riscv: print out debugging
message if required")). As a result, when using '-d' for the kexec_load
interface, print nothing in the kernel space. This might be helpful for
verifying the accuracy of the data passed to the kernel. Therefore,
refer to this commit a85ee18c7900 ("kexec_file: print out debugging
message if required"), debug print information has been added.

Signed-off-by: Qiang Ma <maqianga@uniontech.com>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202510310332.6XrLe70K-lkp@intel.com/
---
 kernel/kexec.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/kernel/kexec.c b/kernel/kexec.c
index c7a869d32f87..9b433b972cc1 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -154,7 +154,15 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
 	if (ret)
 		goto out;
 
+	kexec_dprintk("nr_segments = %lu\n", nr_segments);
 	for (i = 0; i < nr_segments; i++) {
+		struct kexec_segment *ksegment;
+
+		ksegment = &image->segment[i];
+		kexec_dprintk("segment[%lu]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
+			      i, ksegment->buf, ksegment->bufsz, ksegment->mem,
+			      ksegment->memsz);
+
 		ret = kimage_load_segment(image, i);
 		if (ret)
 			goto out;
@@ -166,6 +174,9 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
 	if (ret)
 		goto out;
 
+	kexec_dprintk("kexec_load: type:%u, start:0x%lx head:0x%lx flags:0x%lx\n",
+		      image->type, image->start, image->head, flags);
+
 	/* Install the new kernel and uninstall the old */
 	image = xchg(dest_image, image);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v2 4/4] kexec_file: Fix the issue of mismatch between loop variable types
  2025-11-03  6:34 [PATCH v2 0/4] kexec: print out debugging message if required for kexec_load Qiang Ma
                   ` (2 preceding siblings ...)
  2025-11-03  6:34 ` [PATCH v2 3/4] kexec: print out debugging message if required for kexec_load Qiang Ma
@ 2025-11-03  6:34 ` Qiang Ma
  2025-11-05  3:05   ` Baoquan He
  3 siblings, 1 reply; 22+ messages in thread
From: Qiang Ma @ 2025-11-03  6:34 UTC (permalink / raw)
  To: akpm, bhe; +Cc: kexec, linux-kernel, Qiang Ma

The type of the struct kimage member variable nr_segments is unsigned long.
Correct the loop variable i and the print format specifier type.

Signed-off-by: Qiang Ma <maqianga@uniontech.com>
---
 kernel/kexec_file.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index 4a24aadbad02..7afdaa0efc50 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -366,7 +366,8 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
 	int image_type = (flags & KEXEC_FILE_ON_CRASH) ?
 			 KEXEC_TYPE_CRASH : KEXEC_TYPE_DEFAULT;
 	struct kimage **dest_image, *image;
-	int ret = 0, i;
+	int ret = 0;
+	unsigned long i;
 
 	/* We only trust the superuser with rebooting the system. */
 	if (!kexec_load_permitted(image_type))
@@ -432,7 +433,7 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
 		struct kexec_segment *ksegment;
 
 		ksegment = &image->segment[i];
-		kexec_dprintk("segment[%d]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
+		kexec_dprintk("segment[%lu]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
 			      i, ksegment->buf, ksegment->bufsz, ksegment->mem,
 			      ksegment->memsz);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 3/4] kexec: print out debugging message if required for kexec_load
  2025-11-03  6:34 ` [PATCH v2 3/4] kexec: print out debugging message if required for kexec_load Qiang Ma
@ 2025-11-05  3:01   ` Baoquan He
  2025-11-05  3:41     ` Qiang Ma
  0 siblings, 1 reply; 22+ messages in thread
From: Baoquan He @ 2025-11-05  3:01 UTC (permalink / raw)
  To: Qiang Ma; +Cc: akpm, kexec, linux-kernel, kernel test robot

On 11/03/25 at 02:34pm, Qiang Ma wrote:
> The commit a85ee18c7900 ("kexec_file: print out debugging message
> if required") has added general code printing in kexec_file_load(),
> but not in kexec_load().
> 
> Especially in the RISC-V architecture, kexec_image_info() has been
> removed(commit eb7622d908a0 ("kexec_file, riscv: print out debugging
> message if required")). As a result, when using '-d' for the kexec_load
> interface, print nothing in the kernel space. This might be helpful for
> verifying the accuracy of the data passed to the kernel. Therefore,
> refer to this commit a85ee18c7900 ("kexec_file: print out debugging
> message if required"), debug print information has been added.
> 
> Signed-off-by: Qiang Ma <maqianga@uniontech.com>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202510310332.6XrLe70K-lkp@intel.com/
> ---
>  kernel/kexec.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/kernel/kexec.c b/kernel/kexec.c
> index c7a869d32f87..9b433b972cc1 100644
> --- a/kernel/kexec.c
> +++ b/kernel/kexec.c
> @@ -154,7 +154,15 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
>  	if (ret)
>  		goto out;
>  
> +	kexec_dprintk("nr_segments = %lu\n", nr_segments);
>  	for (i = 0; i < nr_segments; i++) {
> +		struct kexec_segment *ksegment;
> +
> +		ksegment = &image->segment[i];
> +		kexec_dprintk("segment[%lu]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
> +			      i, ksegment->buf, ksegment->bufsz, ksegment->mem,
> +			      ksegment->memsz);

There has already been a print_segments() in kexec-tools/kexec/kexec.c,
you will get duplicated printing. That sounds not good. Have you tested
this?

> +
>  		ret = kimage_load_segment(image, i);
>  		if (ret)
>  			goto out;
> @@ -166,6 +174,9 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
>  	if (ret)
>  		goto out;
>  
> +	kexec_dprintk("kexec_load: type:%u, start:0x%lx head:0x%lx flags:0x%lx\n",
> +		      image->type, image->start, image->head, flags);
> +
>  	/* Install the new kernel and uninstall the old */
>  	image = xchg(dest_image, image);
>  
> -- 
> 2.20.1
> 


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 4/4] kexec_file: Fix the issue of mismatch between loop variable types
  2025-11-03  6:34 ` [PATCH v2 4/4] kexec_file: Fix the issue of mismatch between loop variable types Qiang Ma
@ 2025-11-05  3:05   ` Baoquan He
  2025-11-05  3:47     ` Qiang Ma
       [not found]     ` <c669d240-1ee8-4897-a30d-3efefe161085@uniontech.com>
  0 siblings, 2 replies; 22+ messages in thread
From: Baoquan He @ 2025-11-05  3:05 UTC (permalink / raw)
  To: Qiang Ma; +Cc: akpm, kexec, linux-kernel

On 11/03/25 at 02:34pm, Qiang Ma wrote:
> The type of the struct kimage member variable nr_segments is unsigned long.
> Correct the loop variable i and the print format specifier type.

I can't see what's meaningful with this change. nr_segments is unsigned
long, but it's the range 'i' will loop. If so, we need change all for
loop of the int iterator.

> 
> Signed-off-by: Qiang Ma <maqianga@uniontech.com>
> ---
>  kernel/kexec_file.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
> index 4a24aadbad02..7afdaa0efc50 100644
> --- a/kernel/kexec_file.c
> +++ b/kernel/kexec_file.c
> @@ -366,7 +366,8 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
>  	int image_type = (flags & KEXEC_FILE_ON_CRASH) ?
>  			 KEXEC_TYPE_CRASH : KEXEC_TYPE_DEFAULT;
>  	struct kimage **dest_image, *image;
> -	int ret = 0, i;
> +	int ret = 0;
> +	unsigned long i;
>  
>  	/* We only trust the superuser with rebooting the system. */
>  	if (!kexec_load_permitted(image_type))
> @@ -432,7 +433,7 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
>  		struct kexec_segment *ksegment;
>  
>  		ksegment = &image->segment[i];
> -		kexec_dprintk("segment[%d]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
> +		kexec_dprintk("segment[%lu]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
>  			      i, ksegment->buf, ksegment->bufsz, ksegment->mem,
>  			      ksegment->memsz);
>  
> -- 
> 2.20.1
> 


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 2/4] kexec: add kexec_core flag to control debug printing
  2025-11-03  6:34 ` [PATCH v2 2/4] kexec: add kexec_core flag to control debug printing Qiang Ma
@ 2025-11-05  3:09   ` Baoquan He
  2025-11-05  4:32     ` Qiang Ma
  0 siblings, 1 reply; 22+ messages in thread
From: Baoquan He @ 2025-11-05  3:09 UTC (permalink / raw)
  To: Qiang Ma; +Cc: akpm, kexec, linux-kernel

On 11/03/25 at 02:34pm, Qiang Ma wrote:
> The commit a85ee18c7900 ("kexec_file: print out debugging message
> if required") has added general code printing in kexec_file_load(),
> but not in kexec_load().
> 
> Since kexec_load and kexec_file_load are not triggered
> simultaneously, we can unify the debug flag of kexec and kexec_file
> as kexec_core_dbg_print.

After reconsidering this, I regret calling it kexec_core_dbg_print.
That sounds a printing only happening in kexec_core. Maybe
kexec_dbg_print is better. Because here kexec refers to a generic
concept, but not limited to kexec_load interface only. Just my personal
thinking.

Other than the naming, the whole patch looks good to me. Thanks.

> 
> Next, we need to do four things:
> 
> 1. rename kexec_file_dbg_print to kexec_core_dbg_print
> 2. Add KEXEC_DEBUG
> 3. Initialize kexec_core_dbg_print for kexec
> 4. Set the reset of kexec_file_dbg_print to kimage_free
> 
> Signed-off-by: Qiang Ma <maqianga@uniontech.com>
> ---
>  include/linux/kexec.h      | 9 +++++----
>  include/uapi/linux/kexec.h | 1 +
>  kernel/kexec.c             | 1 +
>  kernel/kexec_core.c        | 4 +++-
>  kernel/kexec_file.c        | 4 +---
>  5 files changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/include/linux/kexec.h b/include/linux/kexec.h
> index ff7e231b0485..cad8b5c362af 100644
> --- a/include/linux/kexec.h
> +++ b/include/linux/kexec.h
> @@ -455,10 +455,11 @@ bool kexec_load_permitted(int kexec_image_type);
>  
>  /* List of defined/legal kexec flags */
>  #ifndef CONFIG_KEXEC_JUMP
> -#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR | KEXEC_CRASH_HOTPLUG_SUPPORT)
> +#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR | KEXEC_CRASH_HOTPLUG_SUPPORT | \
> +			KEXEC_DEBUG)
>  #else
>  #define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT | KEXEC_UPDATE_ELFCOREHDR | \
> -			KEXEC_CRASH_HOTPLUG_SUPPORT)
> +			KEXEC_CRASH_HOTPLUG_SUPPORT | KEXEC_DEBUG)
>  #endif
>  
>  /* List of defined/legal kexec file flags */
> @@ -525,10 +526,10 @@ static inline int arch_kexec_post_alloc_pages(void *vaddr, unsigned int pages, g
>  static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) { }
>  #endif
>  
> -extern bool kexec_file_dbg_print;
> +extern bool kexec_core_dbg_print;
>  
>  #define kexec_dprintk(fmt, arg...) \
> -        do { if (kexec_file_dbg_print) pr_info(fmt, ##arg); } while (0)
> +	do { if (kexec_core_dbg_print) pr_info(fmt, ##arg); } while (0)
>  
>  extern void *kimage_map_segment(struct kimage *image, unsigned long addr, unsigned long size);
>  extern void kimage_unmap_segment(void *buffer);
> diff --git a/include/uapi/linux/kexec.h b/include/uapi/linux/kexec.h
> index 55749cb0b81d..819c600af125 100644
> --- a/include/uapi/linux/kexec.h
> +++ b/include/uapi/linux/kexec.h
> @@ -14,6 +14,7 @@
>  #define KEXEC_PRESERVE_CONTEXT	0x00000002
>  #define KEXEC_UPDATE_ELFCOREHDR	0x00000004
>  #define KEXEC_CRASH_HOTPLUG_SUPPORT 0x00000008
> +#define KEXEC_DEBUG		0x00000010
>  #define KEXEC_ARCH_MASK		0xffff0000
>  
>  /*
> diff --git a/kernel/kexec.c b/kernel/kexec.c
> index 9bb1f2b6b268..c7a869d32f87 100644
> --- a/kernel/kexec.c
> +++ b/kernel/kexec.c
> @@ -42,6 +42,7 @@ static int kimage_alloc_init(struct kimage **rimage, unsigned long entry,
>  	if (!image)
>  		return -ENOMEM;
>  
> +	kexec_core_dbg_print = !!(flags & KEXEC_DEBUG);
>  	image->start = entry;
>  	image->nr_segments = nr_segments;
>  	memcpy(image->segment, segments, nr_segments * sizeof(*segments));
> diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
> index fa00b239c5d9..865f2b14f23b 100644
> --- a/kernel/kexec_core.c
> +++ b/kernel/kexec_core.c
> @@ -53,7 +53,7 @@ atomic_t __kexec_lock = ATOMIC_INIT(0);
>  /* Flag to indicate we are going to kexec a new kernel */
>  bool kexec_in_progress = false;
>  
> -bool kexec_file_dbg_print;
> +bool kexec_core_dbg_print;
>  
>  /*
>   * When kexec transitions to the new kernel there is a one-to-one
> @@ -576,6 +576,8 @@ void kimage_free(struct kimage *image)
>  	kimage_entry_t *ptr, entry;
>  	kimage_entry_t ind = 0;
>  
> +	kexec_core_dbg_print = false;
> +
>  	if (!image)
>  		return;
>  
> diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
> index eb62a9794242..4a24aadbad02 100644
> --- a/kernel/kexec_file.c
> +++ b/kernel/kexec_file.c
> @@ -138,8 +138,6 @@ void kimage_file_post_load_cleanup(struct kimage *image)
>  	 */
>  	kfree(image->image_loader_data);
>  	image->image_loader_data = NULL;
> -
> -	kexec_file_dbg_print = false;
>  }
>  
>  #ifdef CONFIG_KEXEC_SIG
> @@ -314,7 +312,7 @@ kimage_file_alloc_init(struct kimage **rimage, int kernel_fd,
>  	if (!image)
>  		return -ENOMEM;
>  
> -	kexec_file_dbg_print = !!(flags & KEXEC_FILE_DEBUG);
> +	kexec_core_dbg_print = !!(flags & KEXEC_FILE_DEBUG);
>  	image->file_mode = 1;
>  
>  #ifdef CONFIG_CRASH_DUMP
> -- 
> 2.20.1
> 


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 3/4] kexec: print out debugging message if required for kexec_load
  2025-11-05  3:01   ` Baoquan He
@ 2025-11-05  3:41     ` Qiang Ma
  2025-11-05  7:53       ` Baoquan He
  0 siblings, 1 reply; 22+ messages in thread
From: Qiang Ma @ 2025-11-05  3:41 UTC (permalink / raw)
  To: Baoquan He; +Cc: akpm, kexec, linux-kernel, kernel test robot


在 2025/11/5 11:01, Baoquan He 写道:
> On 11/03/25 at 02:34pm, Qiang Ma wrote:
>> The commit a85ee18c7900 ("kexec_file: print out debugging message
>> if required") has added general code printing in kexec_file_load(),
>> but not in kexec_load().
>>
>> Especially in the RISC-V architecture, kexec_image_info() has been
>> removed(commit eb7622d908a0 ("kexec_file, riscv: print out debugging
>> message if required")). As a result, when using '-d' for the kexec_load
>> interface, print nothing in the kernel space. This might be helpful for
>> verifying the accuracy of the data passed to the kernel. Therefore,
>> refer to this commit a85ee18c7900 ("kexec_file: print out debugging
>> message if required"), debug print information has been added.
>>
>> Signed-off-by: Qiang Ma <maqianga@uniontech.com>
>> Reported-by: kernel test robot <lkp@intel.com>
>> Closes: https://lore.kernel.org/oe-kbuild-all/202510310332.6XrLe70K-lkp@intel.com/
>> ---
>>   kernel/kexec.c | 11 +++++++++++
>>   1 file changed, 11 insertions(+)
>>
>> diff --git a/kernel/kexec.c b/kernel/kexec.c
>> index c7a869d32f87..9b433b972cc1 100644
>> --- a/kernel/kexec.c
>> +++ b/kernel/kexec.c
>> @@ -154,7 +154,15 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
>>   	if (ret)
>>   		goto out;
>>   
>> +	kexec_dprintk("nr_segments = %lu\n", nr_segments);
>>   	for (i = 0; i < nr_segments; i++) {
>> +		struct kexec_segment *ksegment;
>> +
>> +		ksegment = &image->segment[i];
>> +		kexec_dprintk("segment[%lu]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
>> +			      i, ksegment->buf, ksegment->bufsz, ksegment->mem,
>> +			      ksegment->memsz);
> There has already been a print_segments() in kexec-tools/kexec/kexec.c,
> you will get duplicated printing. That sounds not good. Have you tested
> this?
I have tested it, kexec-tools is the debug message printed
in user space, while kexec_dprintk is printed
in kernel space.

This might be helpful for verifying the accuracy of
the data passed to the kernel.
>> +
>>   		ret = kimage_load_segment(image, i);
>>   		if (ret)
>>   			goto out;
>> @@ -166,6 +174,9 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
>>   	if (ret)
>>   		goto out;
>>   
>> +	kexec_dprintk("kexec_load: type:%u, start:0x%lx head:0x%lx flags:0x%lx\n",
>> +		      image->type, image->start, image->head, flags);
>> +
>>   	/* Install the new kernel and uninstall the old */
>>   	image = xchg(dest_image, image);
>>   
>> -- 
>> 2.20.1
>>
>


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 4/4] kexec_file: Fix the issue of mismatch between loop variable types
  2025-11-05  3:05   ` Baoquan He
@ 2025-11-05  3:47     ` Qiang Ma
  2025-11-05  6:56       ` Baoquan He
       [not found]     ` <c669d240-1ee8-4897-a30d-3efefe161085@uniontech.com>
  1 sibling, 1 reply; 22+ messages in thread
From: Qiang Ma @ 2025-11-05  3:47 UTC (permalink / raw)
  To: Baoquan He; +Cc: akpm, kexec, linux-kernel


在 2025/11/5 11:05, Baoquan He 写道:
> On 11/03/25 at 02:34pm, Qiang Ma wrote:
>> The type of the struct kimage member variable nr_segments is unsigned long.
>> Correct the loop variable i and the print format specifier type.
> I can't see what's meaningful with this change. nr_segments is unsigned
> long, but it's the range 'i' will loop. If so, we need change all for
> loop of the int iterator.
If image->nr_segments is large enough, 'i' overflow causes an infinite loop.
>> Signed-off-by: Qiang Ma <maqianga@uniontech.com>
>> ---
>>   kernel/kexec_file.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
>> index 4a24aadbad02..7afdaa0efc50 100644
>> --- a/kernel/kexec_file.c
>> +++ b/kernel/kexec_file.c
>> @@ -366,7 +366,8 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
>>   	int image_type = (flags & KEXEC_FILE_ON_CRASH) ?
>>   			 KEXEC_TYPE_CRASH : KEXEC_TYPE_DEFAULT;
>>   	struct kimage **dest_image, *image;
>> -	int ret = 0, i;
>> +	int ret = 0;
>> +	unsigned long i;
>>   
>>   	/* We only trust the superuser with rebooting the system. */
>>   	if (!kexec_load_permitted(image_type))
>> @@ -432,7 +433,7 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
>>   		struct kexec_segment *ksegment;
>>   
>>   		ksegment = &image->segment[i];
>> -		kexec_dprintk("segment[%d]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
>> +		kexec_dprintk("segment[%lu]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
>>   			      i, ksegment->buf, ksegment->bufsz, ksegment->mem,
>>   			      ksegment->memsz);
>>   
>> -- 
>> 2.20.1
>>
>


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 4/4] kexec_file: Fix the issue of mismatch between loop variable types
       [not found]     ` <c669d240-1ee8-4897-a30d-3efefe161085@uniontech.com>
@ 2025-11-05  4:31       ` Qiang Ma
  0 siblings, 0 replies; 22+ messages in thread
From: Qiang Ma @ 2025-11-05  4:31 UTC (permalink / raw)
  To: Baoquan He; +Cc: akpm, kexec, linux-kernel


在 2025/11/5 11:47, Qiang Ma 写道:
>
> 在 2025/11/5 11:05, Baoquan He 写道:
>> On 11/03/25 at 02:34pm, Qiang Ma wrote:
>>> The type of the struct kimage member variable nr_segments is 
>>> unsigned long.
>>> Correct the loop variable i and the print format specifier type.
>> I can't see what's meaningful with this change. nr_segments is unsigned
>> long, but it's the range 'i' will loop. If so, we need change all for
>> loop of the int iterator.
> If image->nr_segments is large enough, 'i' overflow causes an infinite 
> loop.
Meanwhile, the do_kexec_load() was checked and also defined as 'unsigned 
long i'.
>>> Signed-off-by: Qiang Ma <maqianga@uniontech.com>
>>> ---
>>>   kernel/kexec_file.c | 5 +++--
>>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
>>> index 4a24aadbad02..7afdaa0efc50 100644
>>> --- a/kernel/kexec_file.c
>>> +++ b/kernel/kexec_file.c
>>> @@ -366,7 +366,8 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, 
>>> int, initrd_fd,
>>>       int image_type = (flags & KEXEC_FILE_ON_CRASH) ?
>>>                KEXEC_TYPE_CRASH : KEXEC_TYPE_DEFAULT;
>>>       struct kimage **dest_image, *image;
>>> -    int ret = 0, i;
>>> +    int ret = 0;
>>> +    unsigned long i;
>>>         /* We only trust the superuser with rebooting the system. */
>>>       if (!kexec_load_permitted(image_type))
>>> @@ -432,7 +433,7 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, 
>>> int, initrd_fd,
>>>           struct kexec_segment *ksegment;
>>>             ksegment = &image->segment[i];
>>> -        kexec_dprintk("segment[%d]: buf=0x%p bufsz=0x%zx mem=0x%lx 
>>> memsz=0x%zx\n",
>>> +        kexec_dprintk("segment[%lu]: buf=0x%p bufsz=0x%zx mem=0x%lx 
>>> memsz=0x%zx\n",
>>>                     i, ksegment->buf, ksegment->bufsz, ksegment->mem,
>>>                     ksegment->memsz);
>>>   --
>>> 2.20.1
>>>
>>

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 2/4] kexec: add kexec_core flag to control debug printing
  2025-11-05  3:09   ` Baoquan He
@ 2025-11-05  4:32     ` Qiang Ma
  0 siblings, 0 replies; 22+ messages in thread
From: Qiang Ma @ 2025-11-05  4:32 UTC (permalink / raw)
  To: Baoquan He; +Cc: akpm, kexec, linux-kernel


在 2025/11/5 11:09, Baoquan He 写道:
> On 11/03/25 at 02:34pm, Qiang Ma wrote:
>> The commit a85ee18c7900 ("kexec_file: print out debugging message
>> if required") has added general code printing in kexec_file_load(),
>> but not in kexec_load().
>>
>> Since kexec_load and kexec_file_load are not triggered
>> simultaneously, we can unify the debug flag of kexec and kexec_file
>> as kexec_core_dbg_print.
> After reconsidering this, I regret calling it kexec_core_dbg_print.
> That sounds a printing only happening in kexec_core. Maybe
> kexec_dbg_print is better. Because here kexec refers to a generic
> concept, but not limited to kexec_load interface only. Just my personal
> thinking.
This sounds reasonable. The next version will be renamed kexec_dbg_print.
>
> Other than the naming, the whole patch looks good to me. Thanks.
>
>> Next, we need to do four things:
>>
>> 1. rename kexec_file_dbg_print to kexec_core_dbg_print
>> 2. Add KEXEC_DEBUG
>> 3. Initialize kexec_core_dbg_print for kexec
>> 4. Set the reset of kexec_file_dbg_print to kimage_free
>>
>> Signed-off-by: Qiang Ma <maqianga@uniontech.com>
>> ---
>>   include/linux/kexec.h      | 9 +++++----
>>   include/uapi/linux/kexec.h | 1 +
>>   kernel/kexec.c             | 1 +
>>   kernel/kexec_core.c        | 4 +++-
>>   kernel/kexec_file.c        | 4 +---
>>   5 files changed, 11 insertions(+), 8 deletions(-)
>>
>> diff --git a/include/linux/kexec.h b/include/linux/kexec.h
>> index ff7e231b0485..cad8b5c362af 100644
>> --- a/include/linux/kexec.h
>> +++ b/include/linux/kexec.h
>> @@ -455,10 +455,11 @@ bool kexec_load_permitted(int kexec_image_type);
>>   
>>   /* List of defined/legal kexec flags */
>>   #ifndef CONFIG_KEXEC_JUMP
>> -#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR | KEXEC_CRASH_HOTPLUG_SUPPORT)
>> +#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR | KEXEC_CRASH_HOTPLUG_SUPPORT | \
>> +			KEXEC_DEBUG)
>>   #else
>>   #define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT | KEXEC_UPDATE_ELFCOREHDR | \
>> -			KEXEC_CRASH_HOTPLUG_SUPPORT)
>> +			KEXEC_CRASH_HOTPLUG_SUPPORT | KEXEC_DEBUG)
>>   #endif
>>   
>>   /* List of defined/legal kexec file flags */
>> @@ -525,10 +526,10 @@ static inline int arch_kexec_post_alloc_pages(void *vaddr, unsigned int pages, g
>>   static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) { }
>>   #endif
>>   
>> -extern bool kexec_file_dbg_print;
>> +extern bool kexec_core_dbg_print;
>>   
>>   #define kexec_dprintk(fmt, arg...) \
>> -        do { if (kexec_file_dbg_print) pr_info(fmt, ##arg); } while (0)
>> +	do { if (kexec_core_dbg_print) pr_info(fmt, ##arg); } while (0)
>>   
>>   extern void *kimage_map_segment(struct kimage *image, unsigned long addr, unsigned long size);
>>   extern void kimage_unmap_segment(void *buffer);
>> diff --git a/include/uapi/linux/kexec.h b/include/uapi/linux/kexec.h
>> index 55749cb0b81d..819c600af125 100644
>> --- a/include/uapi/linux/kexec.h
>> +++ b/include/uapi/linux/kexec.h
>> @@ -14,6 +14,7 @@
>>   #define KEXEC_PRESERVE_CONTEXT	0x00000002
>>   #define KEXEC_UPDATE_ELFCOREHDR	0x00000004
>>   #define KEXEC_CRASH_HOTPLUG_SUPPORT 0x00000008
>> +#define KEXEC_DEBUG		0x00000010
>>   #define KEXEC_ARCH_MASK		0xffff0000
>>   
>>   /*
>> diff --git a/kernel/kexec.c b/kernel/kexec.c
>> index 9bb1f2b6b268..c7a869d32f87 100644
>> --- a/kernel/kexec.c
>> +++ b/kernel/kexec.c
>> @@ -42,6 +42,7 @@ static int kimage_alloc_init(struct kimage **rimage, unsigned long entry,
>>   	if (!image)
>>   		return -ENOMEM;
>>   
>> +	kexec_core_dbg_print = !!(flags & KEXEC_DEBUG);
>>   	image->start = entry;
>>   	image->nr_segments = nr_segments;
>>   	memcpy(image->segment, segments, nr_segments * sizeof(*segments));
>> diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
>> index fa00b239c5d9..865f2b14f23b 100644
>> --- a/kernel/kexec_core.c
>> +++ b/kernel/kexec_core.c
>> @@ -53,7 +53,7 @@ atomic_t __kexec_lock = ATOMIC_INIT(0);
>>   /* Flag to indicate we are going to kexec a new kernel */
>>   bool kexec_in_progress = false;
>>   
>> -bool kexec_file_dbg_print;
>> +bool kexec_core_dbg_print;
>>   
>>   /*
>>    * When kexec transitions to the new kernel there is a one-to-one
>> @@ -576,6 +576,8 @@ void kimage_free(struct kimage *image)
>>   	kimage_entry_t *ptr, entry;
>>   	kimage_entry_t ind = 0;
>>   
>> +	kexec_core_dbg_print = false;
>> +
>>   	if (!image)
>>   		return;
>>   
>> diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
>> index eb62a9794242..4a24aadbad02 100644
>> --- a/kernel/kexec_file.c
>> +++ b/kernel/kexec_file.c
>> @@ -138,8 +138,6 @@ void kimage_file_post_load_cleanup(struct kimage *image)
>>   	 */
>>   	kfree(image->image_loader_data);
>>   	image->image_loader_data = NULL;
>> -
>> -	kexec_file_dbg_print = false;
>>   }
>>   
>>   #ifdef CONFIG_KEXEC_SIG
>> @@ -314,7 +312,7 @@ kimage_file_alloc_init(struct kimage **rimage, int kernel_fd,
>>   	if (!image)
>>   		return -ENOMEM;
>>   
>> -	kexec_file_dbg_print = !!(flags & KEXEC_FILE_DEBUG);
>> +	kexec_core_dbg_print = !!(flags & KEXEC_FILE_DEBUG);
>>   	image->file_mode = 1;
>>   
>>   #ifdef CONFIG_CRASH_DUMP
>> -- 
>> 2.20.1
>>
>


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 4/4] kexec_file: Fix the issue of mismatch between loop variable types
  2025-11-05  3:47     ` Qiang Ma
@ 2025-11-05  6:56       ` Baoquan He
  2025-11-05  7:06         ` Qiang Ma
  0 siblings, 1 reply; 22+ messages in thread
From: Baoquan He @ 2025-11-05  6:56 UTC (permalink / raw)
  To: Qiang Ma; +Cc: akpm, kexec, linux-kernel

On 11/05/25 at 11:47am, Qiang Ma wrote:
> 
> 在 2025/11/5 11:05, Baoquan He 写道:
> > On 11/03/25 at 02:34pm, Qiang Ma wrote:
> > > The type of the struct kimage member variable nr_segments is unsigned long.
> > > Correct the loop variable i and the print format specifier type.
> > I can't see what's meaningful with this change. nr_segments is unsigned
> > long, but it's the range 'i' will loop. If so, we need change all for
> > loop of the int iterator.
> If image->nr_segments is large enough, 'i' overflow causes an infinite loop.

Please check kexec_add_buffer(), there's checking for the value which
upper limit is restricted to 16.

        if (kbuf->image->nr_segments >= KEXEC_SEGMENT_MAX)
                return -EINVAL;

> > > Signed-off-by: Qiang Ma <maqianga@uniontech.com>
> > > ---
> > >   kernel/kexec_file.c | 5 +++--
> > >   1 file changed, 3 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
> > > index 4a24aadbad02..7afdaa0efc50 100644
> > > --- a/kernel/kexec_file.c
> > > +++ b/kernel/kexec_file.c
> > > @@ -366,7 +366,8 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
> > >   	int image_type = (flags & KEXEC_FILE_ON_CRASH) ?
> > >   			 KEXEC_TYPE_CRASH : KEXEC_TYPE_DEFAULT;
> > >   	struct kimage **dest_image, *image;
> > > -	int ret = 0, i;
> > > +	int ret = 0;
> > > +	unsigned long i;
> > >   	/* We only trust the superuser with rebooting the system. */
> > >   	if (!kexec_load_permitted(image_type))
> > > @@ -432,7 +433,7 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
> > >   		struct kexec_segment *ksegment;
> > >   		ksegment = &image->segment[i];
> > > -		kexec_dprintk("segment[%d]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
> > > +		kexec_dprintk("segment[%lu]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
> > >   			      i, ksegment->buf, ksegment->bufsz, ksegment->mem,
> > >   			      ksegment->memsz);
> > > -- 
> > > 2.20.1
> > > 
> > 
> 


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 4/4] kexec_file: Fix the issue of mismatch between loop variable types
  2025-11-05  6:56       ` Baoquan He
@ 2025-11-05  7:06         ` Qiang Ma
  0 siblings, 0 replies; 22+ messages in thread
From: Qiang Ma @ 2025-11-05  7:06 UTC (permalink / raw)
  To: Baoquan He; +Cc: akpm, kexec, linux-kernel


在 2025/11/5 14:56, Baoquan He 写道:
> On 11/05/25 at 11:47am, Qiang Ma wrote:
>> 在 2025/11/5 11:05, Baoquan He 写道:
>>> On 11/03/25 at 02:34pm, Qiang Ma wrote:
>>>> The type of the struct kimage member variable nr_segments is unsigned long.
>>>> Correct the loop variable i and the print format specifier type.
>>> I can't see what's meaningful with this change. nr_segments is unsigned
>>> long, but it's the range 'i' will loop. If so, we need change all for
>>> loop of the int iterator.
>> If image->nr_segments is large enough, 'i' overflow causes an infinite loop.
> Please check kexec_add_buffer(), there's checking for the value which
> upper limit is restricted to 16.
>
>          if (kbuf->image->nr_segments >= KEXEC_SEGMENT_MAX)
>                  return -EINVAL;
Oh, then this patch is really not necessary.
>>>> Signed-off-by: Qiang Ma <maqianga@uniontech.com>
>>>> ---
>>>>    kernel/kexec_file.c | 5 +++--
>>>>    1 file changed, 3 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
>>>> index 4a24aadbad02..7afdaa0efc50 100644
>>>> --- a/kernel/kexec_file.c
>>>> +++ b/kernel/kexec_file.c
>>>> @@ -366,7 +366,8 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
>>>>    	int image_type = (flags & KEXEC_FILE_ON_CRASH) ?
>>>>    			 KEXEC_TYPE_CRASH : KEXEC_TYPE_DEFAULT;
>>>>    	struct kimage **dest_image, *image;
>>>> -	int ret = 0, i;
>>>> +	int ret = 0;
>>>> +	unsigned long i;
>>>>    	/* We only trust the superuser with rebooting the system. */
>>>>    	if (!kexec_load_permitted(image_type))
>>>> @@ -432,7 +433,7 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
>>>>    		struct kexec_segment *ksegment;
>>>>    		ksegment = &image->segment[i];
>>>> -		kexec_dprintk("segment[%d]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
>>>> +		kexec_dprintk("segment[%lu]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
>>>>    			      i, ksegment->buf, ksegment->bufsz, ksegment->mem,
>>>>    			      ksegment->memsz);
>>>> -- 
>>>> 2.20.1
>>>>
>

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 3/4] kexec: print out debugging message if required for kexec_load
  2025-11-05  3:41     ` Qiang Ma
@ 2025-11-05  7:53       ` Baoquan He
  2025-11-05  8:35         ` Qiang Ma
  2025-11-05  8:48         ` Qiang Ma
  0 siblings, 2 replies; 22+ messages in thread
From: Baoquan He @ 2025-11-05  7:53 UTC (permalink / raw)
  To: Qiang Ma; +Cc: akpm, kexec, linux-kernel, kernel test robot

On 11/05/25 at 11:41am, Qiang Ma wrote:
> 
> 在 2025/11/5 11:01, Baoquan He 写道:
> > On 11/03/25 at 02:34pm, Qiang Ma wrote:
> > > The commit a85ee18c7900 ("kexec_file: print out debugging message
> > > if required") has added general code printing in kexec_file_load(),
> > > but not in kexec_load().
> > > 
> > > Especially in the RISC-V architecture, kexec_image_info() has been
> > > removed(commit eb7622d908a0 ("kexec_file, riscv: print out debugging
> > > message if required")). As a result, when using '-d' for the kexec_load
> > > interface, print nothing in the kernel space. This might be helpful for
> > > verifying the accuracy of the data passed to the kernel. Therefore,
> > > refer to this commit a85ee18c7900 ("kexec_file: print out debugging
> > > message if required"), debug print information has been added.
> > > 
> > > Signed-off-by: Qiang Ma <maqianga@uniontech.com>
> > > Reported-by: kernel test robot <lkp@intel.com>
> > > Closes: https://lore.kernel.org/oe-kbuild-all/202510310332.6XrLe70K-lkp@intel.com/
> > > ---
> > >   kernel/kexec.c | 11 +++++++++++
> > >   1 file changed, 11 insertions(+)
> > > 
> > > diff --git a/kernel/kexec.c b/kernel/kexec.c
> > > index c7a869d32f87..9b433b972cc1 100644
> > > --- a/kernel/kexec.c
> > > +++ b/kernel/kexec.c
> > > @@ -154,7 +154,15 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
> > >   	if (ret)
> > >   		goto out;
> > > +	kexec_dprintk("nr_segments = %lu\n", nr_segments);
> > >   	for (i = 0; i < nr_segments; i++) {
> > > +		struct kexec_segment *ksegment;
> > > +
> > > +		ksegment = &image->segment[i];
> > > +		kexec_dprintk("segment[%lu]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
> > > +			      i, ksegment->buf, ksegment->bufsz, ksegment->mem,
> > > +			      ksegment->memsz);
> > There has already been a print_segments() in kexec-tools/kexec/kexec.c,
> > you will get duplicated printing. That sounds not good. Have you tested
> > this?
> I have tested it, kexec-tools is the debug message printed
> in user space, while kexec_dprintk is printed
> in kernel space.
> 
> This might be helpful for verifying the accuracy of
> the data passed to the kernel.

Hmm, that's not necessary with a debug printing to verify value passed
in kernel. We should only add debug pringing when we need but lack it. 
I didn't check it carefully, if you add the debug printing only for
verifying accuracy, that doesn't justify the code change.

> > > +
> > >   		ret = kimage_load_segment(image, i);
> > >   		if (ret)
> > >   			goto out;
> > > @@ -166,6 +174,9 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
> > >   	if (ret)
> > >   		goto out;
> > > +	kexec_dprintk("kexec_load: type:%u, start:0x%lx head:0x%lx flags:0x%lx\n",
> > > +		      image->type, image->start, image->head, flags);
> > > +
> > >   	/* Install the new kernel and uninstall the old */
> > >   	image = xchg(dest_image, image);
> > > -- 
> > > 2.20.1
> > > 
> > 
> 


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 3/4] kexec: print out debugging message if required for kexec_load
  2025-11-05  7:53       ` Baoquan He
@ 2025-11-05  8:35         ` Qiang Ma
  2025-11-05  8:55           ` Baoquan He
  2025-11-05  8:48         ` Qiang Ma
  1 sibling, 1 reply; 22+ messages in thread
From: Qiang Ma @ 2025-11-05  8:35 UTC (permalink / raw)
  To: Baoquan He; +Cc: akpm, kexec, linux-kernel, kernel test robot


在 2025/11/5 15:53, Baoquan He 写道:
> On 11/05/25 at 11:41am, Qiang Ma wrote:
>> 在 2025/11/5 11:01, Baoquan He 写道:
>>> On 11/03/25 at 02:34pm, Qiang Ma wrote:
>>>> The commit a85ee18c7900 ("kexec_file: print out debugging message
>>>> if required") has added general code printing in kexec_file_load(),
>>>> but not in kexec_load().
>>>>
>>>> Especially in the RISC-V architecture, kexec_image_info() has been
>>>> removed(commit eb7622d908a0 ("kexec_file, riscv: print out debugging
>>>> message if required")). As a result, when using '-d' for the kexec_load
>>>> interface, print nothing in the kernel space. This might be helpful for
>>>> verifying the accuracy of the data passed to the kernel. Therefore,
>>>> refer to this commit a85ee18c7900 ("kexec_file: print out debugging
>>>> message if required"), debug print information has been added.
>>>>
>>>> Signed-off-by: Qiang Ma <maqianga@uniontech.com>
>>>> Reported-by: kernel test robot <lkp@intel.com>
>>>> Closes: https://lore.kernel.org/oe-kbuild-all/202510310332.6XrLe70K-lkp@intel.com/
>>>> ---
>>>>    kernel/kexec.c | 11 +++++++++++
>>>>    1 file changed, 11 insertions(+)
>>>>
>>>> diff --git a/kernel/kexec.c b/kernel/kexec.c
>>>> index c7a869d32f87..9b433b972cc1 100644
>>>> --- a/kernel/kexec.c
>>>> +++ b/kernel/kexec.c
>>>> @@ -154,7 +154,15 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
>>>>    	if (ret)
>>>>    		goto out;
>>>> +	kexec_dprintk("nr_segments = %lu\n", nr_segments);
>>>>    	for (i = 0; i < nr_segments; i++) {
>>>> +		struct kexec_segment *ksegment;
>>>> +
>>>> +		ksegment = &image->segment[i];
>>>> +		kexec_dprintk("segment[%lu]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
>>>> +			      i, ksegment->buf, ksegment->bufsz, ksegment->mem,
>>>> +			      ksegment->memsz);
>>> There has already been a print_segments() in kexec-tools/kexec/kexec.c,
>>> you will get duplicated printing. That sounds not good. Have you tested
>>> this?
>> I have tested it, kexec-tools is the debug message printed
>> in user space, while kexec_dprintk is printed
>> in kernel space.
>>
>> This might be helpful for verifying the accuracy of
>> the data passed to the kernel.
> Hmm, that's not necessary with a debug printing to verify value passed
> in kernel. We should only add debug pringing when we need but lack it.
> I didn't check it carefully, if you add the debug printing only for
> verifying accuracy, that doesn't justify the code change.
It's not entirely because of it.

Another reason is that for RISC-V, for kexec_file_load interface,
kexec_image_info() was deleted at that time because the content
has been printed out in generic code.

However, these contents were not printed in kexec_load because
kexec_image_info was deleted. So now it has been added.
>>>> +
>>>>    		ret = kimage_load_segment(image, i);
>>>>    		if (ret)
>>>>    			goto out;
>>>> @@ -166,6 +174,9 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
>>>>    	if (ret)
>>>>    		goto out;
>>>> +	kexec_dprintk("kexec_load: type:%u, start:0x%lx head:0x%lx flags:0x%lx\n",
>>>> +		      image->type, image->start, image->head, flags);
>>>> +
>>>>    	/* Install the new kernel and uninstall the old */
>>>>    	image = xchg(dest_image, image);
>>>> -- 
>>>> 2.20.1
>>>>
>

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 3/4] kexec: print out debugging message if required for kexec_load
  2025-11-05  7:53       ` Baoquan He
  2025-11-05  8:35         ` Qiang Ma
@ 2025-11-05  8:48         ` Qiang Ma
  1 sibling, 0 replies; 22+ messages in thread
From: Qiang Ma @ 2025-11-05  8:48 UTC (permalink / raw)
  To: Baoquan He; +Cc: akpm, kexec, linux-kernel, kernel test robot


在 2025/11/5 15:53, Baoquan He 写道:
> On 11/05/25 at 11:41am, Qiang Ma wrote:
>> 在 2025/11/5 11:01, Baoquan He 写道:
>>> On 11/03/25 at 02:34pm, Qiang Ma wrote:
>>>> The commit a85ee18c7900 ("kexec_file: print out debugging message
>>>> if required") has added general code printing in kexec_file_load(),
>>>> but not in kexec_load().
>>>>
>>>> Especially in the RISC-V architecture, kexec_image_info() has been
>>>> removed(commit eb7622d908a0 ("kexec_file, riscv: print out debugging
>>>> message if required")). As a result, when using '-d' for the kexec_load
>>>> interface, print nothing in the kernel space. This might be helpful for
>>>> verifying the accuracy of the data passed to the kernel. Therefore,
>>>> refer to this commit a85ee18c7900 ("kexec_file: print out debugging
>>>> message if required"), debug print information has been added.
>>>>
>>>> Signed-off-by: Qiang Ma <maqianga@uniontech.com>
>>>> Reported-by: kernel test robot <lkp@intel.com>
>>>> Closes: https://lore.kernel.org/oe-kbuild-all/202510310332.6XrLe70K-lkp@intel.com/
>>>> ---
>>>>    kernel/kexec.c | 11 +++++++++++
>>>>    1 file changed, 11 insertions(+)
>>>>
>>>> diff --git a/kernel/kexec.c b/kernel/kexec.c
>>>> index c7a869d32f87..9b433b972cc1 100644
>>>> --- a/kernel/kexec.c
>>>> +++ b/kernel/kexec.c
>>>> @@ -154,7 +154,15 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
>>>>    	if (ret)
>>>>    		goto out;
>>>> +	kexec_dprintk("nr_segments = %lu\n", nr_segments);
>>>>    	for (i = 0; i < nr_segments; i++) {
>>>> +		struct kexec_segment *ksegment;
>>>> +
>>>> +		ksegment = &image->segment[i];
>>>> +		kexec_dprintk("segment[%lu]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
>>>> +			      i, ksegment->buf, ksegment->bufsz, ksegment->mem,
>>>> +			      ksegment->memsz);
>>> There has already been a print_segments() in kexec-tools/kexec/kexec.c,
>>> you will get duplicated printing. That sounds not good. Have you tested
>>> this?
>> I have tested it, kexec-tools is the debug message printed
>> in user space, while kexec_dprintk is printed
>> in kernel space.
>>
>> This might be helpful for verifying the accuracy of
>> the data passed to the kernel.
> Hmm, that's not necessary with a debug printing to verify value passed
> in kernel. We should only add debug pringing when we need but lack it.
> I didn't check it carefully, if you add the debug printing only for
> verifying accuracy, that doesn't justify the code change.
>
Also, adding these prints here is helpful for debugging the 
kimage_load_segment().
>>>> +
>>>>    		ret = kimage_load_segment(image, i);
>>>>    		if (ret)
>>>>    			goto out;
>>>> @@ -166,6 +174,9 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
>>>>    	if (ret)
>>>>    		goto out;
>>>> +	kexec_dprintk("kexec_load: type:%u, start:0x%lx head:0x%lx flags:0x%lx\n",
>>>> +		      image->type, image->start, image->head, flags);
>>>> +
>>>>    	/* Install the new kernel and uninstall the old */
>>>>    	image = xchg(dest_image, image);
>>>> -- 
>>>> 2.20.1
>>>>
>


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 3/4] kexec: print out debugging message if required for kexec_load
  2025-11-05  8:35         ` Qiang Ma
@ 2025-11-05  8:55           ` Baoquan He
  2025-11-05 11:28             ` Qiang Ma
  0 siblings, 1 reply; 22+ messages in thread
From: Baoquan He @ 2025-11-05  8:55 UTC (permalink / raw)
  To: Qiang Ma; +Cc: akpm, kexec, linux-kernel, kernel test robot

On 11/05/25 at 04:35pm, Qiang Ma wrote:
> 
> 在 2025/11/5 15:53, Baoquan He 写道:
> > On 11/05/25 at 11:41am, Qiang Ma wrote:
> > > 在 2025/11/5 11:01, Baoquan He 写道:
> > > > On 11/03/25 at 02:34pm, Qiang Ma wrote:
> > > > > The commit a85ee18c7900 ("kexec_file: print out debugging message
> > > > > if required") has added general code printing in kexec_file_load(),
> > > > > but not in kexec_load().
> > > > > 
> > > > > Especially in the RISC-V architecture, kexec_image_info() has been
> > > > > removed(commit eb7622d908a0 ("kexec_file, riscv: print out debugging
> > > > > message if required")). As a result, when using '-d' for the kexec_load
> > > > > interface, print nothing in the kernel space. This might be helpful for
> > > > > verifying the accuracy of the data passed to the kernel. Therefore,
> > > > > refer to this commit a85ee18c7900 ("kexec_file: print out debugging
> > > > > message if required"), debug print information has been added.
> > > > > 
> > > > > Signed-off-by: Qiang Ma <maqianga@uniontech.com>
> > > > > Reported-by: kernel test robot <lkp@intel.com>
> > > > > Closes: https://lore.kernel.org/oe-kbuild-all/202510310332.6XrLe70K-lkp@intel.com/
> > > > > ---
> > > > >    kernel/kexec.c | 11 +++++++++++
> > > > >    1 file changed, 11 insertions(+)
> > > > > 
> > > > > diff --git a/kernel/kexec.c b/kernel/kexec.c
> > > > > index c7a869d32f87..9b433b972cc1 100644
> > > > > --- a/kernel/kexec.c
> > > > > +++ b/kernel/kexec.c
> > > > > @@ -154,7 +154,15 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
> > > > >    	if (ret)
> > > > >    		goto out;
> > > > > +	kexec_dprintk("nr_segments = %lu\n", nr_segments);
> > > > >    	for (i = 0; i < nr_segments; i++) {
> > > > > +		struct kexec_segment *ksegment;
> > > > > +
> > > > > +		ksegment = &image->segment[i];
> > > > > +		kexec_dprintk("segment[%lu]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
> > > > > +			      i, ksegment->buf, ksegment->bufsz, ksegment->mem,
> > > > > +			      ksegment->memsz);
> > > > There has already been a print_segments() in kexec-tools/kexec/kexec.c,
> > > > you will get duplicated printing. That sounds not good. Have you tested
> > > > this?
> > > I have tested it, kexec-tools is the debug message printed
> > > in user space, while kexec_dprintk is printed
> > > in kernel space.
> > > 
> > > This might be helpful for verifying the accuracy of
> > > the data passed to the kernel.
> > Hmm, that's not necessary with a debug printing to verify value passed
> > in kernel. We should only add debug pringing when we need but lack it.
> > I didn't check it carefully, if you add the debug printing only for
> > verifying accuracy, that doesn't justify the code change.
> It's not entirely because of it.
> 
> Another reason is that for RISC-V, for kexec_file_load interface,
> kexec_image_info() was deleted at that time because the content
> has been printed out in generic code.
> 
> However, these contents were not printed in kexec_load because
> kexec_image_info was deleted. So now it has been added.

print_segments() in kexec-tools/kexec/kexec.c is a generic function,
shouldn't you make it called in kexec-tools for risc-v? I am confused by
the purpose of this patchset.

> > > > > +
> > > > >    		ret = kimage_load_segment(image, i);
> > > > >    		if (ret)
> > > > >    			goto out;
> > > > > @@ -166,6 +174,9 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
> > > > >    	if (ret)
> > > > >    		goto out;
> > > > > +	kexec_dprintk("kexec_load: type:%u, start:0x%lx head:0x%lx flags:0x%lx\n",
> > > > > +		      image->type, image->start, image->head, flags);
> > > > > +
> > > > >    	/* Install the new kernel and uninstall the old */
> > > > >    	image = xchg(dest_image, image);
> > > > > -- 
> > > > > 2.20.1
> > > > > 
> > 
> 


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 3/4] kexec: print out debugging message if required for kexec_load
  2025-11-05  8:55           ` Baoquan He
@ 2025-11-05 11:28             ` Qiang Ma
  2025-11-05 13:01               ` Baoquan He
  0 siblings, 1 reply; 22+ messages in thread
From: Qiang Ma @ 2025-11-05 11:28 UTC (permalink / raw)
  To: Baoquan He; +Cc: akpm, kexec, linux-kernel, kernel test robot


在 2025/11/5 16:55, Baoquan He 写道:
> On 11/05/25 at 04:35pm, Qiang Ma wrote:
>> 在 2025/11/5 15:53, Baoquan He 写道:
>>> On 11/05/25 at 11:41am, Qiang Ma wrote:
>>>> 在 2025/11/5 11:01, Baoquan He 写道:
>>>>> On 11/03/25 at 02:34pm, Qiang Ma wrote:
>>>>>> The commit a85ee18c7900 ("kexec_file: print out debugging message
>>>>>> if required") has added general code printing in kexec_file_load(),
>>>>>> but not in kexec_load().
>>>>>>
>>>>>> Especially in the RISC-V architecture, kexec_image_info() has been
>>>>>> removed(commit eb7622d908a0 ("kexec_file, riscv: print out debugging
>>>>>> message if required")). As a result, when using '-d' for the kexec_load
>>>>>> interface, print nothing in the kernel space. This might be helpful for
>>>>>> verifying the accuracy of the data passed to the kernel. Therefore,
>>>>>> refer to this commit a85ee18c7900 ("kexec_file: print out debugging
>>>>>> message if required"), debug print information has been added.
>>>>>>
>>>>>> Signed-off-by: Qiang Ma <maqianga@uniontech.com>
>>>>>> Reported-by: kernel test robot <lkp@intel.com>
>>>>>> Closes: https://lore.kernel.org/oe-kbuild-all/202510310332.6XrLe70K-lkp@intel.com/
>>>>>> ---
>>>>>>     kernel/kexec.c | 11 +++++++++++
>>>>>>     1 file changed, 11 insertions(+)
>>>>>>
>>>>>> diff --git a/kernel/kexec.c b/kernel/kexec.c
>>>>>> index c7a869d32f87..9b433b972cc1 100644
>>>>>> --- a/kernel/kexec.c
>>>>>> +++ b/kernel/kexec.c
>>>>>> @@ -154,7 +154,15 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
>>>>>>     	if (ret)
>>>>>>     		goto out;
>>>>>> +	kexec_dprintk("nr_segments = %lu\n", nr_segments);
>>>>>>     	for (i = 0; i < nr_segments; i++) {
>>>>>> +		struct kexec_segment *ksegment;
>>>>>> +
>>>>>> +		ksegment = &image->segment[i];
>>>>>> +		kexec_dprintk("segment[%lu]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
>>>>>> +			      i, ksegment->buf, ksegment->bufsz, ksegment->mem,
>>>>>> +			      ksegment->memsz);
>>>>> There has already been a print_segments() in kexec-tools/kexec/kexec.c,
>>>>> you will get duplicated printing. That sounds not good. Have you tested
>>>>> this?
>>>> I have tested it, kexec-tools is the debug message printed
>>>> in user space, while kexec_dprintk is printed
>>>> in kernel space.
>>>>
>>>> This might be helpful for verifying the accuracy of
>>>> the data passed to the kernel.
>>> Hmm, that's not necessary with a debug printing to verify value passed
>>> in kernel. We should only add debug pringing when we need but lack it.
>>> I didn't check it carefully, if you add the debug printing only for
>>> verifying accuracy, that doesn't justify the code change.
>> It's not entirely because of it.
>>
>> Another reason is that for RISC-V, for kexec_file_load interface,
>> kexec_image_info() was deleted at that time because the content
>> has been printed out in generic code.
>>
>> However, these contents were not printed in kexec_load because
>> kexec_image_info was deleted. So now it has been added.
> print_segments() in kexec-tools/kexec/kexec.c is a generic function,
> shouldn't you make it called in kexec-tools for risc-v? I am confused by
> the purpose of this patchset.
There is a problem with what I expressed.
I don't want to add print_segments to riscv.
I want to add some debugging message(ksegment,kimage,flag) for kexec_load.

Although ksegment debugging message has been printed in kexec-tools,
it is still helpful for debugging the kernel space function.
>
>>>>>> +
>>>>>>     		ret = kimage_load_segment(image, i);
>>>>>>     		if (ret)
>>>>>>     			goto out;
>>>>>> @@ -166,6 +174,9 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
>>>>>>     	if (ret)
>>>>>>     		goto out;
>>>>>> +	kexec_dprintk("kexec_load: type:%u, start:0x%lx head:0x%lx flags:0x%lx\n",
>>>>>> +		      image->type, image->start, image->head, flags);
>>>>>> +
>>>>>>     	/* Install the new kernel and uninstall the old */
>>>>>>     	image = xchg(dest_image, image);
>>>>>> -- 
>>>>>> 2.20.1
>>>>>>
>

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 3/4] kexec: print out debugging message if required for kexec_load
  2025-11-05 11:28             ` Qiang Ma
@ 2025-11-05 13:01               ` Baoquan He
  2025-11-05 15:05                 ` Qiang Ma
  0 siblings, 1 reply; 22+ messages in thread
From: Baoquan He @ 2025-11-05 13:01 UTC (permalink / raw)
  To: Qiang Ma; +Cc: akpm, kexec, linux-kernel, kernel test robot

On 11/05/25 at 07:28pm, Qiang Ma wrote:
> 
> 在 2025/11/5 16:55, Baoquan He 写道:
> > On 11/05/25 at 04:35pm, Qiang Ma wrote:
> > > 在 2025/11/5 15:53, Baoquan He 写道:
> > > > On 11/05/25 at 11:41am, Qiang Ma wrote:
> > > > > 在 2025/11/5 11:01, Baoquan He 写道:
> > > > > > On 11/03/25 at 02:34pm, Qiang Ma wrote:
> > > > > > > The commit a85ee18c7900 ("kexec_file: print out debugging message
> > > > > > > if required") has added general code printing in kexec_file_load(),
> > > > > > > but not in kexec_load().
> > > > > > > 
> > > > > > > Especially in the RISC-V architecture, kexec_image_info() has been
> > > > > > > removed(commit eb7622d908a0 ("kexec_file, riscv: print out debugging
> > > > > > > message if required")). As a result, when using '-d' for the kexec_load
> > > > > > > interface, print nothing in the kernel space. This might be helpful for
> > > > > > > verifying the accuracy of the data passed to the kernel. Therefore,
> > > > > > > refer to this commit a85ee18c7900 ("kexec_file: print out debugging
> > > > > > > message if required"), debug print information has been added.
> > > > > > > 
> > > > > > > Signed-off-by: Qiang Ma <maqianga@uniontech.com>
> > > > > > > Reported-by: kernel test robot <lkp@intel.com>
> > > > > > > Closes: https://lore.kernel.org/oe-kbuild-all/202510310332.6XrLe70K-lkp@intel.com/
> > > > > > > ---
> > > > > > >     kernel/kexec.c | 11 +++++++++++
> > > > > > >     1 file changed, 11 insertions(+)
> > > > > > > 
> > > > > > > diff --git a/kernel/kexec.c b/kernel/kexec.c
> > > > > > > index c7a869d32f87..9b433b972cc1 100644
> > > > > > > --- a/kernel/kexec.c
> > > > > > > +++ b/kernel/kexec.c
> > > > > > > @@ -154,7 +154,15 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
> > > > > > >     	if (ret)
> > > > > > >     		goto out;
> > > > > > > +	kexec_dprintk("nr_segments = %lu\n", nr_segments);
> > > > > > >     	for (i = 0; i < nr_segments; i++) {
> > > > > > > +		struct kexec_segment *ksegment;
> > > > > > > +
> > > > > > > +		ksegment = &image->segment[i];
> > > > > > > +		kexec_dprintk("segment[%lu]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
> > > > > > > +			      i, ksegment->buf, ksegment->bufsz, ksegment->mem,
> > > > > > > +			      ksegment->memsz);
> > > > > > There has already been a print_segments() in kexec-tools/kexec/kexec.c,
> > > > > > you will get duplicated printing. That sounds not good. Have you tested
> > > > > > this?
> > > > > I have tested it, kexec-tools is the debug message printed
> > > > > in user space, while kexec_dprintk is printed
> > > > > in kernel space.
> > > > > 
> > > > > This might be helpful for verifying the accuracy of
> > > > > the data passed to the kernel.
> > > > Hmm, that's not necessary with a debug printing to verify value passed
> > > > in kernel. We should only add debug pringing when we need but lack it.
> > > > I didn't check it carefully, if you add the debug printing only for
> > > > verifying accuracy, that doesn't justify the code change.
> > > It's not entirely because of it.
> > > 
> > > Another reason is that for RISC-V, for kexec_file_load interface,
> > > kexec_image_info() was deleted at that time because the content
> > > has been printed out in generic code.
> > > 
> > > However, these contents were not printed in kexec_load because
> > > kexec_image_info was deleted. So now it has been added.
> > print_segments() in kexec-tools/kexec/kexec.c is a generic function,
> > shouldn't you make it called in kexec-tools for risc-v? I am confused by
> > the purpose of this patchset.
> There is a problem with what I expressed.
> I don't want to add print_segments to riscv.
> I want to add some debugging message(ksegment,kimage,flag) for kexec_load.
> 
> Although ksegment debugging message has been printed in kexec-tools,
> it is still helpful for debugging the kernel space function.

Sorry, I can't support that. We all prepare the loading segments for the
future jumping in kexec_tools if it's kexec_load interface. And calling
print_segments() to print those loading information is natural. Why do we
need print them two times for verifying if the printing is accuracy?
Could you explain why risc-v is special?

> > 
> > > > > > > +
> > > > > > >     		ret = kimage_load_segment(image, i);
> > > > > > >     		if (ret)
> > > > > > >     			goto out;
> > > > > > > @@ -166,6 +174,9 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
> > > > > > >     	if (ret)
> > > > > > >     		goto out;
> > > > > > > +	kexec_dprintk("kexec_load: type:%u, start:0x%lx head:0x%lx flags:0x%lx\n",
> > > > > > > +		      image->type, image->start, image->head, flags);
> > > > > > > +
> > > > > > >     	/* Install the new kernel and uninstall the old */
> > > > > > >     	image = xchg(dest_image, image);
> > > > > > > -- 
> > > > > > > 2.20.1
> > > > > > > 
> > 
> 


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 3/4] kexec: print out debugging message if required for kexec_load
  2025-11-05 13:01               ` Baoquan He
@ 2025-11-05 15:05                 ` Qiang Ma
  0 siblings, 0 replies; 22+ messages in thread
From: Qiang Ma @ 2025-11-05 15:05 UTC (permalink / raw)
  To: Baoquan He; +Cc: akpm, kexec, linux-kernel, kernel test robot


On 2025/11/5 下午9:01, Baoquan He wrote:
> On 11/05/25 at 07:28pm, Qiang Ma wrote:
>> 在 2025/11/5 16:55, Baoquan He 写道:
>>> On 11/05/25 at 04:35pm, Qiang Ma wrote:
>>>> 在 2025/11/5 15:53, Baoquan He 写道:
>>>>> On 11/05/25 at 11:41am, Qiang Ma wrote:
>>>>>> 在 2025/11/5 11:01, Baoquan He 写道:
>>>>>>> On 11/03/25 at 02:34pm, Qiang Ma wrote:
>>>>>>>> The commit a85ee18c7900 ("kexec_file: print out debugging message
>>>>>>>> if required") has added general code printing in kexec_file_load(),
>>>>>>>> but not in kexec_load().
>>>>>>>>
>>>>>>>> Especially in the RISC-V architecture, kexec_image_info() has been
>>>>>>>> removed(commit eb7622d908a0 ("kexec_file, riscv: print out debugging
>>>>>>>> message if required")). As a result, when using '-d' for the kexec_load
>>>>>>>> interface, print nothing in the kernel space. This might be helpful for
>>>>>>>> verifying the accuracy of the data passed to the kernel. Therefore,
>>>>>>>> refer to this commit a85ee18c7900 ("kexec_file: print out debugging
>>>>>>>> message if required"), debug print information has been added.
>>>>>>>>
>>>>>>>> Signed-off-by: Qiang Ma <maqianga@uniontech.com>
>>>>>>>> Reported-by: kernel test robot <lkp@intel.com>
>>>>>>>> Closes: https://lore.kernel.org/oe-kbuild-all/202510310332.6XrLe70K-lkp@intel.com/
>>>>>>>> ---
>>>>>>>>      kernel/kexec.c | 11 +++++++++++
>>>>>>>>      1 file changed, 11 insertions(+)
>>>>>>>>
>>>>>>>> diff --git a/kernel/kexec.c b/kernel/kexec.c
>>>>>>>> index c7a869d32f87..9b433b972cc1 100644
>>>>>>>> --- a/kernel/kexec.c
>>>>>>>> +++ b/kernel/kexec.c
>>>>>>>> @@ -154,7 +154,15 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
>>>>>>>>      	if (ret)
>>>>>>>>      		goto out;
>>>>>>>> +	kexec_dprintk("nr_segments = %lu\n", nr_segments);
>>>>>>>>      	for (i = 0; i < nr_segments; i++) {
>>>>>>>> +		struct kexec_segment *ksegment;
>>>>>>>> +
>>>>>>>> +		ksegment = &image->segment[i];
>>>>>>>> +		kexec_dprintk("segment[%lu]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
>>>>>>>> +			      i, ksegment->buf, ksegment->bufsz, ksegment->mem,
>>>>>>>> +			      ksegment->memsz);
>>>>>>> There has already been a print_segments() in kexec-tools/kexec/kexec.c,
>>>>>>> you will get duplicated printing. That sounds not good. Have you tested
>>>>>>> this?
>>>>>> I have tested it, kexec-tools is the debug message printed
>>>>>> in user space, while kexec_dprintk is printed
>>>>>> in kernel space.
>>>>>>
>>>>>> This might be helpful for verifying the accuracy of
>>>>>> the data passed to the kernel.
>>>>> Hmm, that's not necessary with a debug printing to verify value passed
>>>>> in kernel. We should only add debug pringing when we need but lack it.
>>>>> I didn't check it carefully, if you add the debug printing only for
>>>>> verifying accuracy, that doesn't justify the code change.
>>>> It's not entirely because of it.
>>>>
>>>> Another reason is that for RISC-V, for kexec_file_load interface,
>>>> kexec_image_info() was deleted at that time because the content
>>>> has been printed out in generic code.
>>>>
>>>> However, these contents were not printed in kexec_load because
>>>> kexec_image_info was deleted. So now it has been added.
>>> print_segments() in kexec-tools/kexec/kexec.c is a generic function,
>>> shouldn't you make it called in kexec-tools for risc-v? I am confused by
>>> the purpose of this patchset.
>> There is a problem with what I expressed.
>> I don't want to add print_segments to riscv.
>> I want to add some debugging message(ksegment,kimage,flag) for kexec_load.
>>
>> Although ksegment debugging message has been printed in kexec-tools,
>> it is still helpful for debugging the kernel space function.
> Sorry, I can't support that. We all prepare the loading segments for the
> future jumping in kexec_tools if it's kexec_load interface. And calling
> print_segments() to print those loading information is natural. Why do we
> need print them two times for verifying if the printing is accuracy?
Is it necessary to verify the user-space data after it is passed to the 
kernel space?

> Could you explain why risc-v is special?
At first, when I saw that in the RISC-V architecture,
after kexec_image_info was removed from this commit eb7622d908a0
("kexec_file, riscv: print out debugging message if required"),
I thought only kexec_file_load was taken into consideration.
However, without considering that kexec_load would call
kexec_image_info to print segment and other debugging message,
I think that since it has been deleted.

Then, I referred to kexec_file_load and added these debugging message
to the general code of kexec_load. In this way, all architectures can
print these general debugging message.

Then I can add these debugging message to the general code,
so that all architectures can print these general debugging message.
>>>>>>>> +
>>>>>>>>      		ret = kimage_load_segment(image, i);
>>>>>>>>      		if (ret)
>>>>>>>>      			goto out;
>>>>>>>> @@ -166,6 +174,9 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
>>>>>>>>      	if (ret)
>>>>>>>>      		goto out;
>>>>>>>> +	kexec_dprintk("kexec_load: type:%u, start:0x%lx head:0x%lx flags:0x%lx\n",
>>>>>>>> +		      image->type, image->start, image->head, flags);
>>>>>>>> +
>>>>>>>>      	/* Install the new kernel and uninstall the old */
>>>>>>>>      	image = xchg(dest_image, image);
>>>>>>>> -- 
>>>>>>>> 2.20.1
>>>>>>>>
>

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH v2 3/4] kexec: print out debugging message if required for kexec_load
  2025-12-19  9:31 [PATCH v2 0/4] kexec: add kexec flag to control debug printing Qiang Ma
@ 2025-12-19  9:31 ` Qiang Ma
  0 siblings, 0 replies; 22+ messages in thread
From: Qiang Ma @ 2025-12-19  9:31 UTC (permalink / raw)
  To: akpm, bhe, catalin.marinas, will
  Cc: kexec, linux-arm-kernel, linux-kernel, Qiang Ma

The commit a85ee18c7900 ("kexec_file: print out debugging message
if required") has added general code printing in kexec_file_load(),
but not in kexec_load().

As a result, when using '-d' for the kexec_load interface,
print nothing in the kernel space.

Since the segments debugging message has already been printed by the
user-space tool kexec-tools, it will not be printed here in the
kernel space.

And print out type/start/head of kimage and flags to help debug.

Signed-off-by: Qiang Ma <maqianga@uniontech.com>
---
 kernel/kexec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/kexec.c b/kernel/kexec.c
index f6c58c767eb0..37e4ac8af9f3 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -166,6 +166,9 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
 	if (ret)
 		goto out;
 
+	kexec_dprintk("kexec_load: type:%u, start:0x%lx head:0x%lx flags:0x%lx\n",
+		      image->type, image->start, image->head, flags);
+
 	/* Install the new kernel and uninstall the old */
 	image = xchg(dest_image, image);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2025-12-19  9:34 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-03  6:34 [PATCH v2 0/4] kexec: print out debugging message if required for kexec_load Qiang Ma
2025-11-03  6:34 ` [PATCH v2 1/4] kexec: Fix uninitialized struct kimage *image pointer Qiang Ma
2025-11-03  6:34 ` [PATCH v2 2/4] kexec: add kexec_core flag to control debug printing Qiang Ma
2025-11-05  3:09   ` Baoquan He
2025-11-05  4:32     ` Qiang Ma
2025-11-03  6:34 ` [PATCH v2 3/4] kexec: print out debugging message if required for kexec_load Qiang Ma
2025-11-05  3:01   ` Baoquan He
2025-11-05  3:41     ` Qiang Ma
2025-11-05  7:53       ` Baoquan He
2025-11-05  8:35         ` Qiang Ma
2025-11-05  8:55           ` Baoquan He
2025-11-05 11:28             ` Qiang Ma
2025-11-05 13:01               ` Baoquan He
2025-11-05 15:05                 ` Qiang Ma
2025-11-05  8:48         ` Qiang Ma
2025-11-03  6:34 ` [PATCH v2 4/4] kexec_file: Fix the issue of mismatch between loop variable types Qiang Ma
2025-11-05  3:05   ` Baoquan He
2025-11-05  3:47     ` Qiang Ma
2025-11-05  6:56       ` Baoquan He
2025-11-05  7:06         ` Qiang Ma
     [not found]     ` <c669d240-1ee8-4897-a30d-3efefe161085@uniontech.com>
2025-11-05  4:31       ` Qiang Ma
  -- strict thread matches above, loose matches on Subject: below --
2025-12-19  9:31 [PATCH v2 0/4] kexec: add kexec flag to control debug printing Qiang Ma
2025-12-19  9:31 ` [PATCH v2 3/4] kexec: print out debugging message if required for kexec_load Qiang Ma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox