Skip to contentSkip to conversation

kexec: print out debugging message if required for kexec_load

PATCH Superseded Qiang Ma 2 participants 21 messages Nov 3, 2025 – Nov 5, 2025 1 message not in the archive

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Qiang Ma

author
#0 lore raw

v2 cover kexec: print out debugging message if required for kexec_load

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(-)
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH v2 1/4 kexec: Fix uninitialized struct kimage *image pointer

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.

---
 kernel/kexec.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/kexec.c +3 -1
index 28008e3d462e..9bb1f2b6b268 100644
@@ -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;
Signature · 1 line
2.20.1
author
#2 lore raw

PATCH v2 2/4 kexec: add kexec_core flag to control debug printing

In reply to 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

---
 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(-)
include/linux/kexec.h +5 -4
index ff7e231b0485..cad8b5c362af 100644
@@ -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);
include/uapi/linux/kexec.h +1 -0
index 55749cb0b81d..819c600af125 100644
@@ -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
 
 /*
kernel/kexec.c +1 -0
index 9bb1f2b6b268..c7a869d32f87 100644
@@ -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));
kernel/kexec_core.c +3 -1
index fa00b239c5d9..865f2b14f23b 100644
@@ -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;
 
kernel/kexec_file.c +1 -3
index eb62a9794242..4a24aadbad02 100644
@@ -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
Signature · 1 line
2.20.1
#3 lore raw

Re: [PATCH v2 2/4] kexec: add kexec_core flag to control debug printing

Quoted 7 lines · 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.

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.

Quoted 119 lines

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

---
 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(-)
include/linux/kexec.h +5 -4
index ff7e231b0485..cad8b5c362af 100644
@@ -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);
include/uapi/linux/kexec.h +1 -0
index 55749cb0b81d..819c600af125 100644
@@ -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
 
 /*
kernel/kexec.c +1 -0
index 9bb1f2b6b268..c7a869d32f87 100644
@@ -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));
kernel/kexec_core.c +3 -1
index fa00b239c5d9..865f2b14f23b 100644
@@ -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;
 
kernel/kexec_file.c +1 -3
index eb62a9794242..4a24aadbad02 100644
@@ -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
Signature · 1 line
2.20.1
author
#4 lore raw

Re: [PATCH v2 2/4] kexec: add kexec_core flag to control debug printing

Quoted 5 lines · Baoquan He
Quoted 4 lines · 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().

Quoted 8 lines
Quoted 3 lines

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.

Quoted 122 lines

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

Quoted 118 lines

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

---
  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(-)
include/linux/kexec.h +5 -4
index ff7e231b0485..cad8b5c362af 100644
@@ -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);
include/uapi/linux/kexec.h +1 -0
index 55749cb0b81d..819c600af125 100644
@@ -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
 
  /*
kernel/kexec.c +1 -0
index 9bb1f2b6b268..c7a869d32f87 100644
@@ -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));
kernel/kexec_core.c +3 -1
index fa00b239c5d9..865f2b14f23b 100644
@@ -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;
 
kernel/kexec_file.c +1 -3
index eb62a9794242..4a24aadbad02 100644
@@ -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
Signature · 1 line
2.20.1
author
#5 lore raw

PATCH v2 3/4 kexec: print out debugging message if required for kexec_load

In reply to 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().

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.

---
 kernel/kexec.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
kernel/kexec.c +11 -0
index c7a869d32f87..9b433b972cc1 100644
@@ -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);
 
Signature · 1 line
2.20.1
#6 lore raw
Quoted 25 lines · 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().

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.

---
 kernel/kexec.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
kernel/kexec.c +0 -0
index c7a869d32f87..9b433b972cc1 100644
@@ -154,7 +154,15 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
 	if (ret)

kernel/kexec.c static int do_kexec_load(unsigned long entry, unsigned long nr_segments, · line 164

Quoted 10 lines
kernel/kexec.c +7 -0
 		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?

Quoted 17 lines
kernel/kexec.c +4 -0
+
 		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);
 
Signature · 1 line
2.20.1
author
#7 lore raw
Quoted 28 lines · Baoquan He
Quoted 27 lines · 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().

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.

---
  kernel/kexec.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
kernel/kexec.c +0 -0
index c7a869d32f87..9b433b972cc1 100644
@@ -154,7 +154,15 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
  	if (ret)
  		goto out;
 
Quoted 11 lines

kernel/kexec.c static int do_kexec_load(unsigned long entry, unsigned long nr_segments, · line 164

Quoted 8 lines
kernel/kexec.c +7 -0
+	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.

Quoted 18 lines
Quoted 17 lines
kernel/kexec.c +4 -0
+
  		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);
 
Signature · 1 line
2.20.1
#8 lore raw
Quoted 40 lines · Qiang Ma
Quoted 30 lines · Baoquan He
Quoted 29 lines · 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().

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.

---
  kernel/kexec.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
kernel/kexec.c +2 -0
index c7a869d32f87..9b433b972cc1 100644
@@ -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;
Quoted 8 lines

kernel/kexec.c static int do_kexec_load(unsigned long entry, unsigned long nr_segments, · line 164

Quoted 5 lines
kernel/kexec.c +5 -0
+
+		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?

Quoted 6 lines

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.

Quoted 17 lines
Quoted 16 lines
Quoted 15 lines
kernel/kexec.c +4 -0
+
  		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);
Signature · 1 line
2.20.1
author
#9 lore raw
Quoted 44 lines · Baoquan He
Quoted 43 lines · Qiang Ma
Quoted 30 lines · Baoquan He
Quoted 29 lines · 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().

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.

---
   kernel/kexec.c | 11 +++++++++++
   1 file changed, 11 insertions(+)
kernel/kexec.c +2 -0
index c7a869d32f87..9b433b972cc1 100644
@@ -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;
Quoted 8 lines

kernel/kexec.c static int do_kexec_load(unsigned long entry, unsigned long nr_segments, · line 164

Quoted 5 lines
kernel/kexec.c +5 -0
+
+		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.

Quoted 6 lines
Quoted 2 lines

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.

Quoted 16 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
kernel/kexec.c +4 -0
+
   		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);
Signature · 1 line
2.20.1
#10 lore raw
Quoted 52 lines · Qiang Ma
Quoted 44 lines · Baoquan He
Quoted 43 lines · Qiang Ma
Quoted 30 lines · Baoquan He
Quoted 29 lines · 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().

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.

---
   kernel/kexec.c | 11 +++++++++++
   1 file changed, 11 insertions(+)
kernel/kexec.c +2 -0
index c7a869d32f87..9b433b972cc1 100644
@@ -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;
Quoted 8 lines

kernel/kexec.c static int do_kexec_load(unsigned long entry, unsigned long nr_segments, · line 164

Quoted 5 lines
kernel/kexec.c +5 -0
+
+		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.

Quoted 6 lines
Quoted 2 lines

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.

Quoted 8 lines

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.

Quoted 17 lines
Quoted 16 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
kernel/kexec.c +4 -0
+
   		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);
Signature · 1 line
2.20.1
author
#11 lore raw
Quoted 58 lines · Baoquan He
Quoted 57 lines · Qiang Ma
Quoted 44 lines · Baoquan He
Quoted 43 lines · Qiang Ma
Quoted 30 lines · Baoquan He
Quoted 29 lines · 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().

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.

---
    kernel/kexec.c | 11 +++++++++++
    1 file changed, 11 insertions(+)
kernel/kexec.c +2 -0
index c7a869d32f87..9b433b972cc1 100644
@@ -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;
Quoted 8 lines

kernel/kexec.c static int do_kexec_load(unsigned long entry, unsigned long nr_segments, · line 164

Quoted 5 lines
kernel/kexec.c +5 -0
+
+		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.

Quoted 6 lines
Quoted 2 lines

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.

Quoted 5 lines
Quoted 2 lines

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.

Quoted 17 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
kernel/kexec.c +4 -0
+
    		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);
Signature · 1 line
2.20.1
#12 lore raw
Quoted 65 lines · Qiang Ma
Quoted 58 lines · Baoquan He
Quoted 57 lines · Qiang Ma
Quoted 44 lines · Baoquan He
Quoted 43 lines · Qiang Ma
Quoted 30 lines · Baoquan He
Quoted 29 lines · 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().

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.

---
    kernel/kexec.c | 11 +++++++++++
    1 file changed, 11 insertions(+)
kernel/kexec.c +2 -0
index c7a869d32f87..9b433b972cc1 100644
@@ -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;
Quoted 8 lines

kernel/kexec.c static int do_kexec_load(unsigned long entry, unsigned long nr_segments, · line 163

Quoted 5 lines
kernel/kexec.c +5 -0
+
+		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.

Quoted 6 lines
Quoted 2 lines

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.

Quoted 5 lines
Quoted 2 lines

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.

Quoted 6 lines

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?

Quoted 18 lines
Quoted 17 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
kernel/kexec.c +4 -0
+
    		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);
Signature · 1 line
2.20.1
author
#13 lore raw
Quoted 69 lines · Baoquan He
Quoted 68 lines · Qiang Ma
Quoted 58 lines · Baoquan He
Quoted 57 lines · Qiang Ma
Quoted 44 lines · Baoquan He
Quoted 43 lines · Qiang Ma
Quoted 30 lines · Baoquan He
Quoted 29 lines · 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().

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.

---
     kernel/kexec.c | 11 +++++++++++
     1 file changed, 11 insertions(+)
kernel/kexec.c +2 -0
index c7a869d32f87..9b433b972cc1 100644
@@ -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;
Quoted 8 lines

kernel/kexec.c static int do_kexec_load(unsigned long entry, unsigned long nr_segments, · line 163

Quoted 5 lines
kernel/kexec.c +5 -0
+
+		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.

Quoted 6 lines
Quoted 2 lines

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.

Quoted 5 lines
Quoted 2 lines

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.

Quoted 6 lines
Quoted 2 lines

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?

Quoted 1 line

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.

Quoted 16 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
kernel/kexec.c +4 -0
+
     		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);
Signature · 1 line
2.20.1
author
#14 lore raw
In reply to Baoquan He
Quoted 44 lines · Baoquan He
Quoted 43 lines · Qiang Ma
Quoted 30 lines · Baoquan He
Quoted 29 lines · 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().

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.

---
   kernel/kexec.c | 11 +++++++++++
   1 file changed, 11 insertions(+)
kernel/kexec.c +2 -0
index c7a869d32f87..9b433b972cc1 100644
@@ -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;
Quoted 8 lines

kernel/kexec.c static int do_kexec_load(unsigned long entry, unsigned long nr_segments, · line 164

Quoted 5 lines
kernel/kexec.c +5 -0
+
+		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.

Quoted 7 lines
Quoted 2 lines

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().

Quoted 16 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
kernel/kexec.c +4 -0
+
   		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);
Signature · 1 line
2.20.1
author
#15 lore raw

PATCH v2 4/4 kexec_file: Fix the issue of mismatch between loop variable types

In reply to 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.

---
 kernel/kexec_file.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/kexec_file.c +3 -2
index 4a24aadbad02..7afdaa0efc50 100644
@@ -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);
 
Signature · 1 line
2.20.1
#16 lore raw

Re: [PATCH v2 4/4] kexec_file: Fix the issue of mismatch between loop variable types

Quoted 2 lines · 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.

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.

Quoted 32 lines
---
 kernel/kexec_file.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/kexec_file.c +3 -2
index 4a24aadbad02..7afdaa0efc50 100644
@@ -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);
 
Signature · 1 line
2.20.1
author
#17 lore raw

Re: [PATCH v2 4/4] kexec_file: Fix the issue of mismatch between loop variable types

Quoted 6 lines · Baoquan He
Quoted 2 lines · 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.

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.

Quoted 32 lines
Quoted 31 lines
---
  kernel/kexec_file.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
kernel/kexec_file.c +3 -2
index 4a24aadbad02..7afdaa0efc50 100644
@@ -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);
 
Signature · 1 line
2.20.1
#18 lore raw

Re: [PATCH v2 4/4] kexec_file: Fix the issue of mismatch between loop variable types

Quoted 9 lines · Qiang Ma
Quoted 6 lines · Baoquan He
Quoted 2 lines · 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.

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;
Quoted 30 lines
Quoted 29 lines
Quoted 28 lines
---
  kernel/kexec_file.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
kernel/kexec_file.c +3 -2
index 4a24aadbad02..7afdaa0efc50 100644
@@ -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);
Signature · 1 line
2.20.1
author
#19 lore raw

Re: [PATCH v2 4/4] kexec_file: Fix the issue of mismatch between loop variable types

Quoted 8 lines · Baoquan He
Quoted 7 lines · Qiang Ma
Quoted 6 lines · Baoquan He
Quoted 2 lines · 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.

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.

Quoted 6 lines
Quoted 1 line

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.

Quoted 29 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
---
   kernel/kexec_file.c | 5 +++--
   1 file changed, 3 insertions(+), 2 deletions(-)
kernel/kexec_file.c +3 -2
index 4a24aadbad02..7afdaa0efc50 100644
@@ -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);
Signature · 1 line
2.20.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#21 lore raw

Re: [PATCH v2 4/4] kexec_file: Fix the issue of mismatch between loop variable types

Quoted 9 lines · Qiang Ma
Quoted 6 lines · Baoquan He
Quoted 2 lines · 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.

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'.

Quoted 33 lines
Quoted 33 lines
Quoted 32 lines

---
  kernel/kexec_file.c | 5 +++--

  1 file changed, 3 insertions(+), 2 deletions(-)
kernel/kexec_file.c +0 -0
index 4a24aadbad02..7afdaa0efc50 100644
@@ -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))

kernel/kexec_file.c +1 -1
@@ -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