Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/crash: Include Elf64_Ehdr and RAM ranges in elfcorehdr size
@ 2026-12-01 17:21 Suseendran Bhaskaran
  2026-12-01 17:28 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Suseendran Bhaskaran @ 2026-12-01 17:21 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86
  Cc: H . Peter Anvin, Andrew Morton, Baoquan He, Mike Rapoport,
	Eric DeVolder, Sourabh Jain, Jinjie Ruan, Ionut Nechita,
	Greg Thelen, kexec, linux-kernel, Suseendran Bhaskaran

arch_crash_get_elfcorehdr_size() computes the size exported via
/sys/kernel/kexec/crash_elfcorehdr_size for kexec_load() with crash
hotplug support. Unlike crash_load_segments(), it omits both
sizeof(Elf64_Ehdr) and the existing System RAM ranges when
CONFIG_MEMORY_HOTPLUG is disabled.

With --hotplug, kexec-tools overrides the elfcorehdr segment memsz with
this sysfs value and truncates bufsz if bufsz > memsz, so the loaded
elfcorehdr can be silently truncated on CONFIG_MEMORY_HOTPLUG=n systems,
and subsequent hotplug updates fail. For example, on a default
CONFIG_NR_CPUS=64 kernel with CONFIG_MEMORY_HOTPLUG=n, 64 possible CPUs,
and 10 System RAM ranges, crash_elfcorehdr_size reports 3696 bytes
(memsz 4096) and CPU offline fails with:

  crash hp: update elfcorehdr elfsz 8192 > memsz 4096

Add arch_get_system_nr_ranges() when !IS_ENABLED(CONFIG_MEMORY_HOTPLUG)
and include sizeof(Elf64_Ehdr) so arch_crash_get_elfcorehdr_size()
matches crash_load_segments(). Tested with kexec-tools 2.0.32 in QEMU
under the configuration above: crash_elfcorehdr_size reports 4488 bytes
(memsz 8192) and CPU offline updates elfcorehdr cleanly.

Gemini assisted with code analysis and the QEMU reproducer. All changes
and test results were reviewed by the author.

Fixes: a72bbec70da2 ("crash: hotplug support for kexec_load()")
Signed-off-by: Suseendran Bhaskaran <suseendranb@google.com>
---
 arch/x86/kernel/crash.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index e6f23933a6df2..49bc4bc5ebc0b 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -433,7 +433,10 @@ unsigned int arch_crash_get_elfcorehdr_size(void)
 	sz = 2 + CONFIG_NR_CPUS;
 	if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG))
 		sz += CONFIG_CRASH_MAX_MEMORY_RANGES;
+	else
+		sz += arch_get_system_nr_ranges();
 	sz *= sizeof(Elf64_Phdr);
+	sz += sizeof(Elf64_Ehdr);
 	return sz;
 }
 

base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
-- 
2.56.1.911.g883d8bcb20-goog



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

end of thread, other threads:[~2026-12-01 17:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 17:21 [PATCH] x86/crash: Include Elf64_Ehdr and RAM ranges in elfcorehdr size Suseendran Bhaskaran
2026-12-01 17:28 ` sashiko-bot

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