* [PATCH v1 0/3] kexec: add kexec flag to control debug printing
@ 2025-12-12 9:56 Qiang Ma
2025-12-12 9:56 ` [PATCH v1 1/3] " Qiang Ma
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Qiang Ma @ 2025-12-12 9:56 UTC (permalink / raw)
To: akpm, bhe, catalin.marinas, will
Cc: kexec, linux-arm-kernel, linux-kernel, Qiang Ma
Overview:
=========
The commit cbc2fe9d9cb2 ("kexec_file: add kexec_file flag to control
debug printing") added the kexec_file flag to control debug printing.
However, for arm64, after commit 6f8c1da071a4 ("kexec_file, arm64: print
out debugging message if required"), when using the kexec_load interface,
the kexec_image_info function is called to print debug message, but
it uses kexec_dprintk, which is only available under kexec_file,
then when specifying 'kexec -d', kexec_load interface will print nothing.
For riscv, commit eb7622d908a09 ("kexec_file, riscv: print out debugging
message if required") remove kexec_image_info(), because the content has
been printed out in generic code in kexec_file_load, but not in kexec_load.
Therefore, in order to solve the two problems mentioned above, for this
patchset, several things need to be done:
1. Enabling kexec_dprintk is available for kexec_load.
2. Add some debugging message of the deleted kexec_image_info
to generic code.
3. Remove duplicate debugging prints for arm64.
Since kexec_load and kexec_file_load are not triggered simultaneously,
we can unify the debug flag of kexec and kexec_file as kexec_dbg_print.
In this way, kexec_dprintk is available for kexec_load and kexec_file_load.
Then when specifying 'kexec -d', the debugging message using kexec_dprintk in
kexec_image_info can be printed normally.
The following are the key points of the specific changes:
1. rename kexec_file_dbg_print to kexec_dbg_print
2. Add KEXEC_DEBUG
3. Initialize kexec_dbg_print for kexec
4. Set the reset of kexec_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:
[ 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
On aarch64, the printed messages look like below:
Set CONFIG_KEXEC_FILE
[ 39.033203] kexec_file: kernel: 0000000073414684 kernel_size: 0x3123a00
[ 39.047010] kexec_file: Loaded initrd at 0x43cf0000 bufsz=0x17e0e19 memsz=0x17e1000
[ 39.047054] kexec_file: Loaded dtb at 0x23ec00000 bufsz=0x386 memsz=0x1000
[ 39.047056] kexec_file(Image): Loaded kernel at 0x40000000 bufsz=0x3123a00 memsz=0x3cf0000
[ 39.047063] kexec_file: nr_segments = 3
[ 39.047064] kexec_file: segment[0]: buf=0x0000000073414684 bufsz=0x3123a00 mem=0x40000000 memsz=0x3cf0000
[ 39.073612] kexec_file: segment[1]: buf=0x000000005cd5746b bufsz=0x17e0e19 mem=0x43cf0000 memsz=0x17e1000
[ 39.085309] kexec_file: segment[2]: buf=0x0000000084c4a0f1 bufsz=0x386 mem=0x23ec00000 memsz=0x1000
[ 39.085459] machine_kexec_post_load:155:
[ 39.085463] kexec kimage info:
[ 39.085467] kern_reloc: 0x00000001620e2000
[ 39.085468] el2_vectors: 0x0000000000000000
[ 39.085470] kexec_file: kexec_file_load: type:0, start:0x40000000 head:0x1620e4002 flags:0x8
Unset CONFIG_KEXEC_FILE:
With this patch:
[ 35.156088] machine_kexec_post_load:155:
[ 35.156097] kexec kimage info:
[ 35.156101] kern_reloc: 0x000000011c134000
[ 35.156102] el2_vectors: 0x0000000000000000
[ 35.156104] kexec: kexec_load: type:0, start:0x454d26b0 head:0x105c14002 flags:0xb70010
Without this patch:
There is no kexec print in dmesg.
Previous posts:
Link: https://lore.kernel.org/all/aTdxEvqY6Bcy7Wa1@MiWiFi-R3L-srv/
Qiang Ma (3):
kexec: add kexec flag to control debug printing
kexec: print out debugging message if required for kexec_load
arm64: kexec: Adjust the debug print of kexec_image_info
arch/arm64/kernel/machine_kexec.c | 2 --
include/linux/kexec.h | 9 +++++----
include/uapi/linux/kexec.h | 1 +
kernel/kexec.c | 4 ++++
kernel/kexec_core.c | 4 +++-
kernel/kexec_file.c | 4 +---
6 files changed, 14 insertions(+), 10 deletions(-)
--
2.20.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v1 1/3] kexec: add kexec flag to control debug printing
2025-12-12 9:56 [PATCH v1 0/3] kexec: add kexec flag to control debug printing Qiang Ma
@ 2025-12-12 9:56 ` Qiang Ma
2025-12-12 9:56 ` [PATCH v1 2/3] kexec: print out debugging message if required for kexec_load Qiang Ma
2025-12-12 9:56 ` [PATCH v1 3/3] arm64: kexec: Adjust the debug print of kexec_image_info Qiang Ma
2 siblings, 0 replies; 6+ messages in thread
From: Qiang Ma @ 2025-12-12 9:56 UTC (permalink / raw)
To: akpm, bhe, catalin.marinas, will
Cc: kexec, linux-arm-kernel, linux-kernel, Qiang Ma
The commit cbc2fe9d9cb2 ("kexec_file: add kexec_file flag to control
debug printing") added the kexec_file flag to control debug printing.
However, for arm64, after commit 6f8c1da071a4 ("kexec_file, arm64: print
out debugging message if required"), when using the kexec_load interface,
the kexec_image_info function is called to print debug message, but
it uses kexec_dprintk, which is only available under kexec_file,
then when specifying 'kexec -d', kexec_load interface will print nothing.
For riscv, commit eb7622d908a09 ("kexec_file, riscv: print out debugging
message if required") remove kexec_image_info(), because the content has
been printed out in generic code in kexec_file_load, but not in kexec_load.
Therefore, in order to solve the two problems mentioned above, for this
patchset, several things need to be done:
1. Enabling kexec_dprintk is available for kexec_load.
2. Add some debugging message of the deleted kexec_image_info
to generic code.
3. Remove duplicate debugging prints for arm64
Since kexec_load and kexec_file_load are not triggered simultaneously,
we can unify the debug flag of kexec and kexec_file as kexec_dbg_print.
In this way, kexec_dprintk is available for kexec_load and kexec_file_load.
The following are the key points of the specific changes:
1. rename kexec_file_dbg_print to kexec_dbg_print
2. Add KEXEC_DEBUG
3. Initialize kexec_dbg_print for kexec
4. Set the reset of kexec_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..23f10aec0b34 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_dbg_print;
#define kexec_dprintk(fmt, arg...) \
- do { if (kexec_file_dbg_print) pr_info(fmt, ##arg); } while (0)
+ do { if (kexec_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..f6c58c767eb0 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_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..7bc1cd4105fc 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_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_dbg_print = false;
+
if (!image)
return;
diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index eb62a9794242..3f1d6c4e8ff2 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_dbg_print = !!(flags & KEXEC_FILE_DEBUG);
image->file_mode = 1;
#ifdef CONFIG_CRASH_DUMP
--
2.20.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v1 2/3] kexec: print out debugging message if required for kexec_load
2025-12-12 9:56 [PATCH v1 0/3] kexec: add kexec flag to control debug printing Qiang Ma
2025-12-12 9:56 ` [PATCH v1 1/3] " Qiang Ma
@ 2025-12-12 9:56 ` Qiang Ma
2025-12-15 0:32 ` Andrew Morton
2025-12-12 9:56 ` [PATCH v1 3/3] arm64: kexec: Adjust the debug print of kexec_image_info Qiang Ma
2 siblings, 1 reply; 6+ messages in thread
From: Qiang Ma @ 2025-12-12 9:56 UTC (permalink / raw)
To: akpm, bhe, catalin.marinas, will
Cc: kexec, linux-arm-kernel, 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().
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>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202510310332.6XrLe70K-lkp@intel.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] 6+ messages in thread
* [PATCH v1 3/3] arm64: kexec: Adjust the debug print of kexec_image_info
2025-12-12 9:56 [PATCH v1 0/3] kexec: add kexec flag to control debug printing Qiang Ma
2025-12-12 9:56 ` [PATCH v1 1/3] " Qiang Ma
2025-12-12 9:56 ` [PATCH v1 2/3] kexec: print out debugging message if required for kexec_load Qiang Ma
@ 2025-12-12 9:56 ` Qiang Ma
2 siblings, 0 replies; 6+ messages in thread
From: Qiang Ma @ 2025-12-12 9:56 UTC (permalink / raw)
To: akpm, bhe, catalin.marinas, will
Cc: kexec, linux-arm-kernel, linux-kernel, Qiang Ma
In the previous patch, we move start/head of kimage to the
generic code, so, we remove them to avoid duplicate printing.
Signed-off-by: Qiang Ma <maqianga@uniontech.com>
---
arch/arm64/kernel/machine_kexec.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c
index 239c16e3d02f..0896e3e6a811 100644
--- a/arch/arm64/kernel/machine_kexec.c
+++ b/arch/arm64/kernel/machine_kexec.c
@@ -34,8 +34,6 @@ static void _kexec_image_info(const char *func, int line,
{
kexec_dprintk("%s:%d:\n", func, line);
kexec_dprintk(" kexec kimage info:\n");
- kexec_dprintk(" type: %d\n", kimage->type);
- kexec_dprintk(" head: %lx\n", kimage->head);
kexec_dprintk(" kern_reloc: %pa\n", &kimage->arch.kern_reloc);
kexec_dprintk(" el2_vectors: %pa\n", &kimage->arch.el2_vectors);
}
--
2.20.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v1 2/3] kexec: print out debugging message if required for kexec_load
2025-12-12 9:56 ` [PATCH v1 2/3] kexec: print out debugging message if required for kexec_load Qiang Ma
@ 2025-12-15 0:32 ` Andrew Morton
2025-12-15 4:41 ` Qiang Ma
0 siblings, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2025-12-15 0:32 UTC (permalink / raw)
To: Qiang Ma
Cc: bhe, catalin.marinas, will, kexec, linux-arm-kernel, linux-kernel,
kernel test robot
On Fri, 12 Dec 2025 17:56:48 +0800 Qiang Ma <maqianga@uniontech.com> 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().
>
> As a result, when using '-d' for the kexec_load interface,
> print nothing in the kernel space.
That doesn't sound like a thing which "kernel test robot" would detect
and report.
> 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>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202510310332.6XrLe70K-lkp@intel.com/
Oh I see, that's a warning against an earlier version of this patch.
But this is labelled "v1"!
I suggest we remove this Reported-by record.
> --- 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);
Thanks, I'll await reviewer input before proceeding with this series.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1 2/3] kexec: print out debugging message if required for kexec_load
2025-12-15 0:32 ` Andrew Morton
@ 2025-12-15 4:41 ` Qiang Ma
0 siblings, 0 replies; 6+ messages in thread
From: Qiang Ma @ 2025-12-15 4:41 UTC (permalink / raw)
To: Andrew Morton
Cc: bhe, catalin.marinas, will, kexec, linux-arm-kernel, linux-kernel,
kernel test robot
在 2025/12/15 08:32, Andrew Morton 写道:
> On Fri, 12 Dec 2025 17:56:48 +0800 Qiang Ma <maqianga@uniontech.com> 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().
>>
>> As a result, when using '-d' for the kexec_load interface,
>> print nothing in the kernel space.
> That doesn't sound like a thing which "kernel test robot" would detect
> and report.
>
>> 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>
>> Reported-by: kernel test robot <lkp@intel.com>
>> Closes: https://lore.kernel.org/oe-kbuild-all/202510310332.6XrLe70K-lkp@intel.com/
> Oh I see, that's a warning against an earlier version of this patch.
> But this is labelled "v1"!
yes.
>
> I suggest we remove this Reported-by record.
ok, I'll collect some other suggestions and fix it together in the next
version.
>> --- 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);
> Thanks, I'll await reviewer input before proceeding with this series.
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-12-15 4:43 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-12 9:56 [PATCH v1 0/3] kexec: add kexec flag to control debug printing Qiang Ma
2025-12-12 9:56 ` [PATCH v1 1/3] " Qiang Ma
2025-12-12 9:56 ` [PATCH v1 2/3] kexec: print out debugging message if required for kexec_load Qiang Ma
2025-12-15 0:32 ` Andrew Morton
2025-12-15 4:41 ` Qiang Ma
2025-12-12 9:56 ` [PATCH v1 3/3] arm64: kexec: Adjust the debug print of kexec_image_info Qiang Ma
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox