* [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop
@ 2025-08-19 21:30 Askar Safin
2025-08-19 21:30 ` [PATCH v4 1/6] " Askar Safin
` (7 more replies)
0 siblings, 8 replies; 12+ messages in thread
From: Askar Safin @ 2025-08-19 21:30 UTC (permalink / raw)
To: Andy Shevchenko, Simon Horman; +Cc: Jeremy Linton, kexec
TL;DR: this patchset fixes regression, introduced in aecc554e7b.
This patchset should be backported to all distributions, which packaged v2.0.31, otherwise
kexec doesn't work at all at my laptop with pretty common setup with v2.0.31.
v2.0.31 is broken without this patchset.
See details of this bug on my laptop in first commit message.
Okay, why the bug happens? I suspect this is because of "%lux"
string specifiers, which are totally wrong. The author meant "print (and scan) in hexademical"
here, but this specifier prints (and scans) number in decimal, followed by literal "x". Oops.
And this seems to break kexec.
The bug reproduces on kexec-tools aecc554e7ba , but
doesn't reproduce on kexec-tools 6aecc32c6db .
I. e. it is regression, introduced by aecc554e7ba .
Okay, how to fix this? Well, this is not easy. In 07821da7cf and d2f4297166 Andy Shevchenko
observed compilation warnings, when %lx is used with uint64_t, so he replaced %lx with %llx.
Then in aecc554e7b Jeremy Linton observed warnings with %llx and replaced it with %lux.
(Yes, C is nightmare.)
So, uint64_t is sometimes defined as long unsigned, and thus needs %lx, and sometimes as
long long unsigned and thus needs %llx.
How to fix this once and for all?
I see three ways.
1. uint64_t a; printf ("%llx", (unsigned long long)a);
2. uint64_t a; printf ("%" PRIx64, a);
3. uint64_t a; printf ("%w64x", a);
I think that %w64x is beautiful, but it causes compilation warnings on clang. (Facepalm.)
Also it was introduced in C23, which is too young.
"(unsigned long long)a" is the best in my opinion. This is what I used in v1.
But Andy said to me that POD conversions are evil.
PRIx64 is ugly, but this is the only option left. So this is what I used in this version.
Also this patchset fixes other misc things. See commit messages for details.
I tested on my laptop that this patchset actually fixes the bug.
v1: https://lore.kernel.org/kexec/20250805124722.11193-1-safinaskar@zohomail.com/
v2: https://lore.kernel.org/kexec/20250807032510.4211-1-safinaskar@zohomail.com/
v3: https://lore.kernel.org/kexec/20250819090505.647690-1-safinaskar@zohomail.com/
Changes since v1:
* Addressed Andy's comments
* I reproduced the bug (and tested the fix) on slightly different versions of Linux
and linux-firmware (see first commit message)
Changes since v2:
* Commit messages only
Changes since v3:
* Commit messages only
Askar Safin (6):
Fix printf string specifiers, otherwise kexec doesn't work on my
laptop
kexec/kexec-elf-exec.c: Replace %lux with %lx
kexec/arch/i386/x86-linux-setup.c: replace %d with %u
util_lib/elf_info.c: fix typo: prink -> printk
kexec/arch/i386/kexec-x86-common.c: remove duplicate <stdio.h>
kexec/arch/arm64/crashdump-arm64.c: remove extra whitespace
kexec/arch/arm64/crashdump-arm64.c | 2 +-
kexec/arch/i386/crashdump-x86.c | 3 ++-
kexec/arch/i386/kexec-x86-common.c | 4 ++--
kexec/arch/i386/x86-linux-setup.c | 3 ++-
kexec/kexec-elf-exec.c | 2 +-
util_lib/elf_info.c | 9 +++++----
6 files changed, 13 insertions(+), 10 deletions(-)
--
2.47.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v4 1/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop
2025-08-19 21:30 [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop Askar Safin
@ 2025-08-19 21:30 ` Askar Safin
2025-08-19 21:30 ` [PATCH v4 2/6] kexec/kexec-elf-exec.c: Replace %lux with %lx Askar Safin
` (6 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Askar Safin @ 2025-08-19 21:30 UTC (permalink / raw)
To: Andy Shevchenko, Simon Horman; +Cc: Jeremy Linton, kexec, Andy Shevchenko
TL;DR: this patch fixes regression.
This patch should be backported to all distributions, which packaged v2.0.31, otherwise
kexec doesn't work at all at my laptop with pretty common setup with v2.0.31.
v2.0.31 is broken without this patch.
Recently I found a bug: kexec doesn't work at my laptop.
Here is my setup:
* Laptop Dell Precision 7780
* CPU Intel Raptor Lake-S
* i915 GPU
* x86_64
* UEFI
* Linux v6.16-rc5
* linux-firmware 20250708
* kexec-tools v2.0.31
* I do kexec from this kernel to the same kernel
* Kernel is UEFI PE image
* Secure boot is disabled
* Kernel config is minimized Debian config
* I use command 'kexec --debug --kexec-syscall -l /disk/vmlinuz --initrd=/disk/initramfs.cpio.gz --append="..."', then I execute 'kexec --debug -e'
When I execute "kexec --debug -e", I see black screen instead of proper boot of kexec'd kernel.
Okay, why the bug happens? I suspect this is because of "%lux"
string specifiers, which are totally wrong. The author meant "print (and scan) in hexademical"
here, but this specifier prints (and scans) number in decimal, followed by literal "x". Oops.
And this seems to break kexec.
Changing this to "%lx" or "%llx" will not work, because uint64_t is
defined differently on different architectures. So I use PRIx64 to fix this.
I tested on my laptop that this patch actually fixes the bug.
Fixes: aecc554e7b ("Correct string specifiers")
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Askar Safin <safinaskar@zohomail.com>
---
kexec/arch/i386/crashdump-x86.c | 3 ++-
kexec/arch/i386/kexec-x86-common.c | 3 ++-
kexec/arch/i386/x86-linux-setup.c | 3 ++-
util_lib/elf_info.c | 5 +++--
4 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c
index 770e3f1..0716762 100644
--- a/kexec/arch/i386/crashdump-x86.c
+++ b/kexec/arch/i386/crashdump-x86.c
@@ -28,6 +28,7 @@
#include <string.h>
#include <stdlib.h>
#include <errno.h>
+#include <inttypes.h>
#include <limits.h>
#include <elf.h>
#include <sys/ioctl.h>
@@ -784,7 +785,7 @@ static void cmdline_add_efi(char *cmdline)
if (!acpi_rsdp)
return;
- sprintf(acpi_rsdp_buf, " acpi_rsdp=0x%lux", acpi_rsdp);
+ sprintf(acpi_rsdp_buf, " acpi_rsdp=0x%" PRIx64, acpi_rsdp);
if (strlen(cmdline) + strlen(acpi_rsdp_buf) > (COMMAND_LINE_SIZE - 1))
die("Command line overflow\n");
diff --git a/kexec/arch/i386/kexec-x86-common.c b/kexec/arch/i386/kexec-x86-common.c
index acacb45..9ba8b3f 100644
--- a/kexec/arch/i386/kexec-x86-common.c
+++ b/kexec/arch/i386/kexec-x86-common.c
@@ -30,6 +30,7 @@
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
+#include <inttypes.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/stat.h>
@@ -422,7 +423,7 @@ static uint64_t efi_get_acpi_rsdp(void) {
/* ACPI20= always goes before ACPI= */
if ((strstr(line, "ACPI20=")) || (strstr(line, "ACPI="))) {
s = strchr(line, '=') + 1;
- sscanf(s, "0x%lux", &acpi_rsdp);
+ sscanf(s, "0x%" PRIx64, &acpi_rsdp);
break;
}
}
diff --git a/kexec/arch/i386/x86-linux-setup.c b/kexec/arch/i386/x86-linux-setup.c
index 70656e3..c716e1b 100644
--- a/kexec/arch/i386/x86-linux-setup.c
+++ b/kexec/arch/i386/x86-linux-setup.c
@@ -23,6 +23,7 @@
#include <stddef.h>
#include <errno.h>
#include <limits.h>
+#include <inttypes.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/random.h>
@@ -760,7 +761,7 @@ static void add_e820_map_from_mr(struct x86_linux_param_header *real_mode,
e820[i].type = E820_RESERVED;
break;
}
- dbgprintf("%016lux-%016lux (%d)\n",
+ dbgprintf("%016" PRIx64 "-%016" PRIx64 " (%d)\n",
e820[i].addr,
e820[i].addr + e820[i].size - 1,
e820[i].type);
diff --git a/util_lib/elf_info.c b/util_lib/elf_info.c
index 5cf438c..0f03093 100644
--- a/util_lib/elf_info.c
+++ b/util_lib/elf_info.c
@@ -15,6 +15,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <inttypes.h>
#include <elf_info.h>
/* The 32bit and 64bit note headers make it clear we don't care */
@@ -890,7 +891,7 @@ static void dump_dmesg_structured(int fd, void (*handler)(char*, unsigned int))
handler(out_buf, len);
fprintf(stderr, "Cycle when parsing dmesg detected.\n");
fprintf(stderr, "The prink log_buf is most likely corrupted.\n");
- fprintf(stderr, "log_buf = 0x%lux, idx = 0x%x\n",
+ fprintf(stderr, "log_buf = 0x%" PRIx64 ", idx = 0x%x\n",
log_buf, current_idx);
exit(68);
}
@@ -904,7 +905,7 @@ static void dump_dmesg_structured(int fd, void (*handler)(char*, unsigned int))
handler(out_buf, len);
fprintf(stderr, "Index outside log_buf detected.\n");
fprintf(stderr, "The prink log_buf is most likely corrupted.\n");
- fprintf(stderr, "log_buf = 0x%lux, idx = 0x%x\n",
+ fprintf(stderr, "log_buf = 0x%" PRIx64 ", idx = 0x%x\n",
log_buf, current_idx);
exit(69);
}
--
2.47.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v4 2/6] kexec/kexec-elf-exec.c: Replace %lux with %lx
2025-08-19 21:30 [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop Askar Safin
2025-08-19 21:30 ` [PATCH v4 1/6] " Askar Safin
@ 2025-08-19 21:30 ` Askar Safin
2025-08-19 21:30 ` [PATCH v4 3/6] kexec/arch/i386/x86-linux-setup.c: replace %d with %u Askar Safin
` (5 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Askar Safin @ 2025-08-19 21:30 UTC (permalink / raw)
To: Andy Shevchenko, Simon Horman; +Cc: Jeremy Linton, kexec, Andy Shevchenko
Replace %lux, which prints a decimal number followed by literal 'x',
with %lx, which prints the hexadecimal one. The latter is more useful
for the (address) ranges.
Fixes: d6bc88c0696 ("elf: Support ELF loading with relocation")
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Askar Safin <safinaskar@zohomail.com>
---
kexec/kexec-elf-exec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kexec/kexec-elf-exec.c b/kexec/kexec-elf-exec.c
index b337642..644af8a 100644
--- a/kexec/kexec-elf-exec.c
+++ b/kexec/kexec-elf-exec.c
@@ -167,7 +167,7 @@ int elf_exec_load_relocatable(struct mem_ehdr *ehdr, struct kexec_info *info,
int result;
if (reloc_min > reloc_max) {
- fprintf(stderr, "Bad relocation range, start=%lux > end=%lux.\n", reloc_min, reloc_max);
+ fprintf(stderr, "Bad relocation range, start=%lx > end=%lx.\n", reloc_min, reloc_max);
result = -1;
goto out;
}
--
2.47.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v4 3/6] kexec/arch/i386/x86-linux-setup.c: replace %d with %u
2025-08-19 21:30 [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop Askar Safin
2025-08-19 21:30 ` [PATCH v4 1/6] " Askar Safin
2025-08-19 21:30 ` [PATCH v4 2/6] kexec/kexec-elf-exec.c: Replace %lux with %lx Askar Safin
@ 2025-08-19 21:30 ` Askar Safin
2025-08-19 21:30 ` [PATCH v4 4/6] util_lib/elf_info.c: fix typo: prink -> printk Askar Safin
` (4 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Askar Safin @ 2025-08-19 21:30 UTC (permalink / raw)
To: Andy Shevchenko, Simon Horman; +Cc: Jeremy Linton, kexec, Andy Shevchenko
...because e820[i].type is unsigned.
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Askar Safin <safinaskar@zohomail.com>
---
kexec/arch/i386/x86-linux-setup.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kexec/arch/i386/x86-linux-setup.c b/kexec/arch/i386/x86-linux-setup.c
index c716e1b..94d9dd2 100644
--- a/kexec/arch/i386/x86-linux-setup.c
+++ b/kexec/arch/i386/x86-linux-setup.c
@@ -761,7 +761,7 @@ static void add_e820_map_from_mr(struct x86_linux_param_header *real_mode,
e820[i].type = E820_RESERVED;
break;
}
- dbgprintf("%016" PRIx64 "-%016" PRIx64 " (%d)\n",
+ dbgprintf("%016" PRIx64 "-%016" PRIx64 " (%u)\n",
e820[i].addr,
e820[i].addr + e820[i].size - 1,
e820[i].type);
--
2.47.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v4 4/6] util_lib/elf_info.c: fix typo: prink -> printk
2025-08-19 21:30 [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop Askar Safin
` (2 preceding siblings ...)
2025-08-19 21:30 ` [PATCH v4 3/6] kexec/arch/i386/x86-linux-setup.c: replace %d with %u Askar Safin
@ 2025-08-19 21:30 ` Askar Safin
2025-08-19 21:30 ` [PATCH v4 5/6] kexec/arch/i386/kexec-x86-common.c: remove duplicate <stdio.h> Askar Safin
` (3 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Askar Safin @ 2025-08-19 21:30 UTC (permalink / raw)
To: Andy Shevchenko, Simon Horman; +Cc: Jeremy Linton, kexec, Andy Shevchenko
Fix typo: prink -> printk.
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Askar Safin <safinaskar@zohomail.com>
---
util_lib/elf_info.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/util_lib/elf_info.c b/util_lib/elf_info.c
index 0f03093..b005245 100644
--- a/util_lib/elf_info.c
+++ b/util_lib/elf_info.c
@@ -890,7 +890,7 @@ static void dump_dmesg_structured(int fd, void (*handler)(char*, unsigned int))
if (len && handler)
handler(out_buf, len);
fprintf(stderr, "Cycle when parsing dmesg detected.\n");
- fprintf(stderr, "The prink log_buf is most likely corrupted.\n");
+ fprintf(stderr, "The printk log_buf is most likely corrupted.\n");
fprintf(stderr, "log_buf = 0x%" PRIx64 ", idx = 0x%x\n",
log_buf, current_idx);
exit(68);
@@ -904,7 +904,7 @@ static void dump_dmesg_structured(int fd, void (*handler)(char*, unsigned int))
if (len && handler)
handler(out_buf, len);
fprintf(stderr, "Index outside log_buf detected.\n");
- fprintf(stderr, "The prink log_buf is most likely corrupted.\n");
+ fprintf(stderr, "The printk log_buf is most likely corrupted.\n");
fprintf(stderr, "log_buf = 0x%" PRIx64 ", idx = 0x%x\n",
log_buf, current_idx);
exit(69);
--
2.47.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v4 5/6] kexec/arch/i386/kexec-x86-common.c: remove duplicate <stdio.h>
2025-08-19 21:30 [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop Askar Safin
` (3 preceding siblings ...)
2025-08-19 21:30 ` [PATCH v4 4/6] util_lib/elf_info.c: fix typo: prink -> printk Askar Safin
@ 2025-08-19 21:30 ` Askar Safin
2025-08-19 21:30 ` [PATCH v4 6/6] kexec/arch/arm64/crashdump-arm64.c: remove extra whitespace Askar Safin
` (2 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Askar Safin @ 2025-08-19 21:30 UTC (permalink / raw)
To: Andy Shevchenko, Simon Horman; +Cc: Jeremy Linton, kexec, Andy Shevchenko
Remove duplicate <stdio.h>.
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Askar Safin <safinaskar@zohomail.com>
---
kexec/arch/i386/kexec-x86-common.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/kexec/arch/i386/kexec-x86-common.c b/kexec/arch/i386/kexec-x86-common.c
index 9ba8b3f..4a67ec8 100644
--- a/kexec/arch/i386/kexec-x86-common.c
+++ b/kexec/arch/i386/kexec-x86-common.c
@@ -29,7 +29,6 @@
#include <string.h>
#include <limits.h>
#include <stdlib.h>
-#include <stdio.h>
#include <inttypes.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
--
2.47.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v4 6/6] kexec/arch/arm64/crashdump-arm64.c: remove extra whitespace
2025-08-19 21:30 [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop Askar Safin
` (4 preceding siblings ...)
2025-08-19 21:30 ` [PATCH v4 5/6] kexec/arch/i386/kexec-x86-common.c: remove duplicate <stdio.h> Askar Safin
@ 2025-08-19 21:30 ` Askar Safin
2025-09-22 18:31 ` [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop Askar Safin
2025-09-26 21:09 ` Jeremy Linton
7 siblings, 0 replies; 12+ messages in thread
From: Askar Safin @ 2025-08-19 21:30 UTC (permalink / raw)
To: Andy Shevchenko, Simon Horman; +Cc: Jeremy Linton, kexec, Andy Shevchenko
Remove extra whitespace.
Fixes: aecc554e7ba8 ("Correct string specifiers")
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Askar Safin <safinaskar@zohomail.com>
---
kexec/arch/arm64/crashdump-arm64.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kexec/arch/arm64/crashdump-arm64.c b/kexec/arch/arm64/crashdump-arm64.c
index 73cb611..050dd72 100644
--- a/kexec/arch/arm64/crashdump-arm64.c
+++ b/kexec/arch/arm64/crashdump-arm64.c
@@ -1,6 +1,6 @@
/*
* ARM64 crashdump.
- * partly derived from arm implementation
+ * partly derived from arm implementation
*
* Copyright (c) 2014-2017 Linaro Limited
* Author: AKASHI Takahiro <takahiro.akashi@linaro.org>
--
2.47.2
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop
2025-08-19 21:30 [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop Askar Safin
` (5 preceding siblings ...)
2025-08-19 21:30 ` [PATCH v4 6/6] kexec/arch/arm64/crashdump-arm64.c: remove extra whitespace Askar Safin
@ 2025-09-22 18:31 ` Askar Safin
2025-09-23 2:15 ` Baoquan He
2025-09-26 21:09 ` Jeremy Linton
7 siblings, 1 reply; 12+ messages in thread
From: Askar Safin @ 2025-09-22 18:31 UTC (permalink / raw)
To: Simon Horman; +Cc: Jeremy Linton, kexec, Andy Shevchenko
Simon Horman, so what? This patchset is still not merged.
---- On Wed, 20 Aug 2025 01:30:08 +0400 Askar Safin <safinaskar@zohomail.com> wrote ---
> TL;DR: this patchset fixes regression, introduced in aecc554e7b.
> This patchset should be backported to all distributions, which packaged v2.0.31, otherwise
> kexec doesn't work at all at my laptop with pretty common setup with v2.0.31.
> v2.0.31 is broken without this patchset.
--
Askar Safin
https://types.pl/@safinaskar
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop
2025-09-22 18:31 ` [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop Askar Safin
@ 2025-09-23 2:15 ` Baoquan He
2025-09-23 13:56 ` Simon Horman
0 siblings, 1 reply; 12+ messages in thread
From: Baoquan He @ 2025-09-23 2:15 UTC (permalink / raw)
To: Askar Safin; +Cc: Simon Horman, Jeremy Linton, kexec, Andy Shevchenko
On 09/22/25 at 10:31pm, Askar Safin wrote:
> Simon Horman, so what? This patchset is still not merged.
Not sure if Simon minds the patch log, especially in patch 1. I saw the
'TL;DR' first time in a patch log.
For a problem solving patch, we better provide information like
-what is the problem;
-why it's caused;
-how you fix it;
Don't tell too long story out of the space. Refering to other already
merged commit's log is also a good way to learn that.
The fix is absolutely a great one.
Thanks
Baoquan
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop
2025-09-23 2:15 ` Baoquan He
@ 2025-09-23 13:56 ` Simon Horman
0 siblings, 0 replies; 12+ messages in thread
From: Simon Horman @ 2025-09-23 13:56 UTC (permalink / raw)
To: Baoquan He; +Cc: Askar Safin, Jeremy Linton, kexec, Andy Shevchenko
On Tue, Sep 23, 2025 at 10:15:19AM +0800, Baoquan He wrote:
> On 09/22/25 at 10:31pm, Askar Safin wrote:
> > Simon Horman, so what? This patchset is still not merged.
>
> Not sure if Simon minds the patch log, especially in patch 1. I saw the
> 'TL;DR' first time in a patch log.
>
> For a problem solving patch, we better provide information like
>
> -what is the problem;
> -why it's caused;
> -how you fix it;
>
> Don't tell too long story out of the space. Refering to other already
> merged commit's log is also a good way to learn that.
>
> The fix is absolutely a great one.
Sorry for the extended delay.
I am looking over this now.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop
2025-08-19 21:30 [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop Askar Safin
` (6 preceding siblings ...)
2025-09-22 18:31 ` [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop Askar Safin
@ 2025-09-26 21:09 ` Jeremy Linton
2025-09-29 9:50 ` Simon Horman
7 siblings, 1 reply; 12+ messages in thread
From: Jeremy Linton @ 2025-09-26 21:09 UTC (permalink / raw)
To: Askar Safin, Andy Shevchenko, Simon Horman; +Cc: kexec
Hi,
First, thanks for fixing this!
So, I've been trying to find a failure beyond the printouts being wrong
for the past couple days, and largely failed to duplicate a functional
issue.
That said, this does fix a couple printouts I checked on 32-bit 686
debian 12. Generally I think the code is ok as well and have reviewed it
but i'm going to withhold the review by tag because I still think the
commit messages could use some cleanup.
Tested-by: Jeremy Linton <jeremy.linton@arm.com>
Thanks again.
On 8/19/25 4:30 PM, Askar Safin wrote:
> TL;DR: this patchset fixes regression, introduced in aecc554e7b.
> This patchset should be backported to all distributions, which packaged v2.0.31, otherwise
> kexec doesn't work at all at my laptop with pretty common setup with v2.0.31.
> v2.0.31 is broken without this patchset.
>
> See details of this bug on my laptop in first commit message.
>
> Okay, why the bug happens? I suspect this is because of "%lux"
> string specifiers, which are totally wrong. The author meant "print (and scan) in hexademical"
> here, but this specifier prints (and scans) number in decimal, followed by literal "x". Oops.
> And this seems to break kexec.
>
> The bug reproduces on kexec-tools aecc554e7ba , but
> doesn't reproduce on kexec-tools 6aecc32c6db .
>
> I. e. it is regression, introduced by aecc554e7ba .
>
> Okay, how to fix this? Well, this is not easy. In 07821da7cf and d2f4297166 Andy Shevchenko
> observed compilation warnings, when %lx is used with uint64_t, so he replaced %lx with %llx.
>
> Then in aecc554e7b Jeremy Linton observed warnings with %llx and replaced it with %lux.
> (Yes, C is nightmare.)
>
> So, uint64_t is sometimes defined as long unsigned, and thus needs %lx, and sometimes as
> long long unsigned and thus needs %llx.
>
> How to fix this once and for all?
>
> I see three ways.
>
> 1. uint64_t a; printf ("%llx", (unsigned long long)a);
> 2. uint64_t a; printf ("%" PRIx64, a);
> 3. uint64_t a; printf ("%w64x", a);
>
> I think that %w64x is beautiful, but it causes compilation warnings on clang. (Facepalm.)
> Also it was introduced in C23, which is too young.
>
> "(unsigned long long)a" is the best in my opinion. This is what I used in v1.
> But Andy said to me that POD conversions are evil.
>
> PRIx64 is ugly, but this is the only option left. So this is what I used in this version.
>
> Also this patchset fixes other misc things. See commit messages for details.
>
> I tested on my laptop that this patchset actually fixes the bug.
>
> v1: https://lore.kernel.org/kexec/20250805124722.11193-1-safinaskar@zohomail.com/
> v2: https://lore.kernel.org/kexec/20250807032510.4211-1-safinaskar@zohomail.com/
> v3: https://lore.kernel.org/kexec/20250819090505.647690-1-safinaskar@zohomail.com/
>
> Changes since v1:
> * Addressed Andy's comments
> * I reproduced the bug (and tested the fix) on slightly different versions of Linux
> and linux-firmware (see first commit message)
>
> Changes since v2:
> * Commit messages only
>
> Changes since v3:
> * Commit messages only
>
> Askar Safin (6):
> Fix printf string specifiers, otherwise kexec doesn't work on my
> laptop
> kexec/kexec-elf-exec.c: Replace %lux with %lx
> kexec/arch/i386/x86-linux-setup.c: replace %d with %u
> util_lib/elf_info.c: fix typo: prink -> printk
> kexec/arch/i386/kexec-x86-common.c: remove duplicate <stdio.h>
> kexec/arch/arm64/crashdump-arm64.c: remove extra whitespace
>
> kexec/arch/arm64/crashdump-arm64.c | 2 +-
> kexec/arch/i386/crashdump-x86.c | 3 ++-
> kexec/arch/i386/kexec-x86-common.c | 4 ++--
> kexec/arch/i386/x86-linux-setup.c | 3 ++-
> kexec/kexec-elf-exec.c | 2 +-
> util_lib/elf_info.c | 9 +++++----
> 6 files changed, 13 insertions(+), 10 deletions(-)
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop
2025-09-26 21:09 ` Jeremy Linton
@ 2025-09-29 9:50 ` Simon Horman
0 siblings, 0 replies; 12+ messages in thread
From: Simon Horman @ 2025-09-29 9:50 UTC (permalink / raw)
To: Jeremy Linton; +Cc: Askar Safin, Andy Shevchenko, kexec
On Fri, Sep 26, 2025 at 04:09:17PM -0500, Jeremy Linton wrote:
> Hi,
>
>
> First, thanks for fixing this!
>
> So, I've been trying to find a failure beyond the printouts being wrong for
> the past couple days, and largely failed to duplicate a functional issue.
>
> That said, this does fix a couple printouts I checked on 32-bit 686 debian
> 12. Generally I think the code is ok as well and have reviewed it but i'm
> going to withhold the review by tag because I still think the commit
> messages could use some cleanup.
>
>
> Tested-by: Jeremy Linton <jeremy.linton@arm.com>
Thanks, and sorry to everyone for the extended delay on this one.
I've applied these patches for inclusion in the next release.
- kexec/arch/arm64/crashdump-arm64.c: remove extra whitespace
https://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git/commit/?id=2842172e1405
- kexec/arch/i386/kexec-x86-common.c: remove duplicate <stdio.h>
https://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git/commit/?id=c343815e7e0a
- util_lib/elf_info.c: fix typo: prink -> printk
https://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git/commit/?id=b7b2a13547a0
- kexec/arch/i386/x86-linux-setup.c: replace %d with %u
https://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git/commit/?id=9c12e71d712a
- kexec/kexec-elf-exec.c: Replace %lux with %lx
https://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git/commit/?id=c837f1971fab
- Fix printf string specifiers, otherwise kexec doesn't work on my laptop
https://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git/commit/?id=288e352ed7c8
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2025-09-29 9:51 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-19 21:30 [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop Askar Safin
2025-08-19 21:30 ` [PATCH v4 1/6] " Askar Safin
2025-08-19 21:30 ` [PATCH v4 2/6] kexec/kexec-elf-exec.c: Replace %lux with %lx Askar Safin
2025-08-19 21:30 ` [PATCH v4 3/6] kexec/arch/i386/x86-linux-setup.c: replace %d with %u Askar Safin
2025-08-19 21:30 ` [PATCH v4 4/6] util_lib/elf_info.c: fix typo: prink -> printk Askar Safin
2025-08-19 21:30 ` [PATCH v4 5/6] kexec/arch/i386/kexec-x86-common.c: remove duplicate <stdio.h> Askar Safin
2025-08-19 21:30 ` [PATCH v4 6/6] kexec/arch/arm64/crashdump-arm64.c: remove extra whitespace Askar Safin
2025-09-22 18:31 ` [PATCH v4 0/6] Fix printf string specifiers, otherwise kexec doesn't work on my laptop Askar Safin
2025-09-23 2:15 ` Baoquan He
2025-09-23 13:56 ` Simon Horman
2025-09-26 21:09 ` Jeremy Linton
2025-09-29 9:50 ` Simon Horman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.