Skip to contentSkip to conversation

x86/crash: size the elfcorehdr reservation with NR_CPUS

PATCH Applied Ionut Nechita (Wind River) 5 participants 10 messages Sep 1 – Sep 2

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v5 cover x86/crash: size the elfcorehdr reservation with NR_CPUS

From: Ionut Nechita <[email protected]>

Hi,

The x86 crash code sizes the elfcorehdr reservation with CONFIG_NR_CPUS_DEFAULT, which is a Kconfig default and not an upper bound. The header itself carries one phdr per possible CPU, so the reservation is too small whenever NR_CPUS exceeds NR_CPUS_DEFAULT.

Patch 1 sizes it with CONFIG_NR_CPUS instead. Patch 2 fixes the two comments that still name NR_CPUS_DEFAULT.

Based on linux-next (next-20260831, base-commit 89c07d98716a1).

Changes since v4:
- Bradley Morgan's tags now use his new address, [email protected], as he asked on the v4 thread. His change of address was announced from the old one in [1] and he says the mailmap patch is already out.
- Rebased from next-20260826 onto next-20260831. No code changes; the diff is byte-identical to v2, v3 and v4.

[1] https://lore.kernel.org/all/[email protected]/

v1: https://lore.kernel.org/lkml/[email protected]/
v2: https://lore.kernel.org/lkml/[email protected]/
v3: https://lore.kernel.org/lkml/[email protected]/
v4: https://lore.kernel.org/lkml/[email protected]/

Ionut Nechita (2):
x86/crash: reserve elfcorehdr for CONFIG_NR_CPUS, not
CONFIG_NR_CPUS_DEFAULT
crash: update stale NR_CPUS_DEFAULT references in elfcorehdr sizing
docs

 arch/x86/kernel/crash.c | 6 +++---
 kernel/Kconfig.kexec    | 2 +-
 kernel/crash_core.c     | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

base-commit: 89c07d98716a13454ec3fd9f97689e812cc71bd4 --
2.55.0

#1 lore raw

PATCH v5 1/2 x86/crash: reserve elfcorehdr for CONFIG_NR_CPUS, not CONFIG_NR_CPUS_DEFAULT

From: Ionut Nechita <[email protected]>

NR_CPUS_DEFAULT is purely a Kconfig thing. Its entire purpose in life is to start NR_CPUS at a sane value. There is precisely one (buggy) reference to it outside of Kconfig in the whole kernel: the x86 crash code.

That code undersizes the elfcorehdr reservation whenever NR_CPUS exceeds NR_CPUS_DEFAULT, because the header carries one phdr per possible CPU and num_possible_cpus() is bounded by NR_CPUS. kexec_file_load(2) then fails with -EINVAL from sanity_check_segment_list(), and kexec_load(2) silently truncates the elfcorehdr, which surfaces later as a bad or unusable dump.

Size the elfcorehdr reservation with NR_CPUS instead.

Fixes ea53ad9cf73b ("x86/crash: add x86 crash hotplug support")
Assisted-by LLM
---
 arch/x86/kernel/crash.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/crash.c +3 -3
index e681ec9cf1dc..e6f23933a6df 100644
@@ -369,9 +369,9 @@ int crash_load_segments(struct kimage *image)
 	 * maximum CPUs and maximum memory ranges.
 	 */
 	if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG))
-		pnum = 2 + CONFIG_NR_CPUS_DEFAULT + CONFIG_CRASH_MAX_MEMORY_RANGES;
+		pnum = 2 + CONFIG_NR_CPUS + CONFIG_CRASH_MAX_MEMORY_RANGES;
 	else
-		pnum += 2 + CONFIG_NR_CPUS_DEFAULT;
+		pnum += 2 + CONFIG_NR_CPUS;
 
 	if (pnum < (unsigned long)PN_XNUM) {
 		kbuf.memsz = pnum * sizeof(Elf64_Phdr);
@@ -430,7 +430,7 @@ unsigned int arch_crash_get_elfcorehdr_size(void)
 	unsigned int sz;
 
 	/* kernel_map, VMCOREINFO and maximum CPUs */
-	sz = 2 + CONFIG_NR_CPUS_DEFAULT;
+	sz = 2 + CONFIG_NR_CPUS;
 	if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG))
 		sz += CONFIG_CRASH_MAX_MEMORY_RANGES;
 	sz *= sizeof(Elf64_Phdr);

base-commit: 89c07d98716a13454ec3fd9f97689e812cc71bd4

Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH v5 1/2] x86/crash: reserve elfcorehdr for CONFIG_NR_CPUS, not CONFIG_NR_CPUS_DEFAULT

Hello,

The below patch overrides the changes introduce here:
https://lore.kernel.org/all/[email protected]/

Can you please review the above patch instead?

- Sourabh Jain

Quoted 53 lines · Ionut Nechita (Wind River)

From: Ionut Nechita <[email protected]>

NR_CPUS_DEFAULT is purely a Kconfig thing. Its entire purpose in life is to start NR_CPUS at a sane value. There is precisely one (buggy) reference to it outside of Kconfig in the whole kernel: the x86 crash code.

That code undersizes the elfcorehdr reservation whenever NR_CPUS exceeds NR_CPUS_DEFAULT, because the header carries one phdr per possible CPU and num_possible_cpus() is bounded by NR_CPUS. kexec_file_load(2) then fails with -EINVAL from sanity_check_segment_list(), and kexec_load(2) silently truncates the elfcorehdr, which surfaces later as a bad or unusable dump.

Size the elfcorehdr reservation with NR_CPUS instead.

Fixes ea53ad9cf73b ("x86/crash: add x86 crash hotplug support")
Assisted-by LLM
---
  arch/x86/kernel/crash.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/crash.c +3 -3
index e681ec9cf1dc..e6f23933a6df 100644
@@ -369,9 +369,9 @@ int crash_load_segments(struct kimage *image)
  	 * maximum CPUs and maximum memory ranges.
  	 */
  	if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG))
-		pnum = 2 + CONFIG_NR_CPUS_DEFAULT + CONFIG_CRASH_MAX_MEMORY_RANGES;
+		pnum = 2 + CONFIG_NR_CPUS + CONFIG_CRASH_MAX_MEMORY_RANGES;
  	else
-		pnum += 2 + CONFIG_NR_CPUS_DEFAULT;
+		pnum += 2 + CONFIG_NR_CPUS;
 
  	if (pnum < (unsigned long)PN_XNUM) {
  		kbuf.memsz = pnum * sizeof(Elf64_Phdr);
@@ -430,7 +430,7 @@ unsigned int arch_crash_get_elfcorehdr_size(void)
  	unsigned int sz;
 
  	/* kernel_map, VMCOREINFO and maximum CPUs */
-	sz = 2 + CONFIG_NR_CPUS_DEFAULT;
+	sz = 2 + CONFIG_NR_CPUS;
  	if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG))
  		sz += CONFIG_CRASH_MAX_MEMORY_RANGES;
  	sz *= sizeof(Elf64_Phdr);

base-commit: 89c07d98716a13454ec3fd9f97689e812cc71bd4

#4 lore raw

Re: [PATCH v5 1/2] x86/crash: reserve elfcorehdr for CONFIG_NR_CPUS, not CONFIG_NR_CPUS_DEFAULT

Quoted 9 lines · Dave Hansen
Quoted 1 line · Ionut Nechita (Wind River)
Assisted-by LLM

This seems a _bit_ opaque and imprecise. Could you take a quick look through:

https://docs.kernel.org/process/generated-content.html

and try to err a bit more on the side of transparency for the next one?

Spoiler: new rule added in the docs, you no longer need to do Provider:Modelname any longer

You only have to do

Assisted-by LLM

Or

Assisted-by (Let's say checkpatch --fix?)

--- Thanks!
https://lore.kernel.org/all/[email protected]/

#5 lore raw

Re: [PATCH v5 1/2] x86/crash: reserve elfcorehdr for CONFIG_NR_CPUS, not CONFIG_NR_CPUS_DEFAULT

Quoted 4 lines · Bradley Morgan
Quoted 2 lines · Dave Hansen
Quoted 1 line · Ionut Nechita (Wind River)
Assisted-by LLM
Quoted 8 lines
Quoted 6 lines

This seems a _bit_ opaque and imprecise. Could you take a quick look through:

https://docs.kernel.org/process/generated-content.html

and try to err a bit more on the side of transparency for the next one?

Spoiler: new rule added in the docs, you no longer need to do Provider:Modelname any longer

I'm just saying, for me, "Assisted-by: LLM" is almost worthless. I'm not going to go tilting at any windmills to get that doc changed, but it seems a borderline waste of bytes.

Please just say how you used the tools. At least for things you want me to merge. Yes, I owe an Documentation/process/maintainer-tip.rst update for this.

#6 lore raw

Re: [PATCH v5 1/2] x86/crash: reserve elfcorehdr for CONFIG_NR_CPUS, not CONFIG_NR_CPUS_DEFAULT

Quoted 10 lines · Dave Hansen
Quoted 9 lines · Bradley Morgan
Quoted 7 lines · Dave Hansen
Quoted 1 line · Ionut Nechita (Wind River)
Assisted-by LLM

This seems a _bit_ opaque and imprecise. Could you take a quick look through:

https://docs.kernel.org/process/generated-content.html

Quoted 9 lines
Quoted 3 lines
Quoted 1 line

and try to err a bit more on the side of transparency for the next one?

Spoiler: new rule added in the docs, you no longer need to do

Provider:Modelname any longer

I'm just saying, for me, "Assisted-by: LLM" is almost worthless. I'm not going to go tilting at any windmills to get that doc changed, but it seems a borderline waste of bytes.

True, people argued that nobody cared what extras you used, all they needed to
know is what the base you used is. E.g: LLM

Quoted 2 lines

Please just say how you used the tools. At least for things you want me to merge.

Maybe a --- line note could be good?

E.g:

(Patch)
---
I used a LLM (Claude code?) to (discover, build, etc?) the patch.

Yes, I owe an Documentation/process/maintainer-tip.rst update

Quoted 1 line

for this.

Want me to do it? Or could you cc me

--- Thanks!
https://lore.kernel.org/all/[email protected]/

merge bot Applied
#7 lore raw

[tip: x86/kdump] x86/crash: Reserve elfcorehdr for CONFIG_NR_CPUS, not CONFIG_NR_CPUS_DEFAULT

In reply to Ionut Nechita (Wind River)
The following commit has been merged into the x86/kdump branch of tip:

The following commit has been merged into the x86/kdump branch of tip:

Commit-ID:     6664ad1026b558563702f9a1ce637df33e7c001e
Gitweb:        https://git.kernel.org/tip/6664ad1026b558563702f9a1ce637df33e7c001e
Author:        Ionut Nechita <[email protected]>
AuthorDate:    Tue, 01 Sep 2026 10:10:40 +03:00
Committer:     Dave Hansen <[email protected]>
CommitterDate: Wed, 02 Sep 2026 14:25:06 -07:00

x86/crash: Reserve elfcorehdr for CONFIG_NR_CPUS, not CONFIG_NR_CPUS_DEFAULT

NR_CPUS_DEFAULT is purely a Kconfig thing. Its entire purpose in life is to start NR_CPUS at a sane value. There is precisely one (buggy) reference to it outside of Kconfig in the whole kernel: the x86 crash code.

That code undersizes the elfcorehdr reservation whenever NR_CPUS exceeds NR_CPUS_DEFAULT, because the header carries one phdr per possible CPU and num_possible_cpus() is bounded by NR_CPUS. kexec_file_load(2) then fails with -EINVAL from sanity_check_segment_list(), and kexec_load(2) silently truncates the elfcorehdr, which surfaces later as a bad or unusable dump.

Size the elfcorehdr reservation with NR_CPUS instead.

---
 arch/x86/kernel/crash.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/crash.c +3 -3
index e681ec9..e6f2393 100644
@@ -369,9 +369,9 @@ int crash_load_segments(struct kimage *image)
 	 * maximum CPUs and maximum memory ranges.
 	 */
 	if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG))
-		pnum = 2 + CONFIG_NR_CPUS_DEFAULT + CONFIG_CRASH_MAX_MEMORY_RANGES;
+		pnum = 2 + CONFIG_NR_CPUS + CONFIG_CRASH_MAX_MEMORY_RANGES;
 	else
-		pnum += 2 + CONFIG_NR_CPUS_DEFAULT;
+		pnum += 2 + CONFIG_NR_CPUS;
 
 	if (pnum < (unsigned long)PN_XNUM) {
 		kbuf.memsz = pnum * sizeof(Elf64_Phdr);
@@ -430,7 +430,7 @@ unsigned int arch_crash_get_elfcorehdr_size(void)
 	unsigned int sz;
 
 	/* kernel_map, VMCOREINFO and maximum CPUs */
-	sz = 2 + CONFIG_NR_CPUS_DEFAULT;
+	sz = 2 + CONFIG_NR_CPUS;
 	if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG))
 		sz += CONFIG_CRASH_MAX_MEMORY_RANGES;
 	sz *= sizeof(Elf64_Phdr);
#8 lore raw

PATCH v5 2/2 crash: update stale NR_CPUS_DEFAULT references in elfcorehdr sizing docs

In reply to Ionut Nechita (Wind River)

From: Ionut Nechita <[email protected]>

The elfcorehdr reservation is now sized with NR_CPUS, but two comments still name NR_CPUS_DEFAULT: the one above crash_handle_hotplug_event() and the CRASH_MAX_MEMORY_RANGES help text.

Update both. Documentation only, no functional change.

---
 kernel/Kconfig.kexec | 2 +-
 kernel/crash_core.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
kernel/Kconfig.kexec +1 -1
index 15632358bcf7..a97ed9605602 100644
@@ -167,7 +167,7 @@ config CRASH_MAX_MEMORY_RANGES
 	  memory regions that the elfcorehdr buffer/segment can accommodate.
 	  These regions are obtained via walk_system_ram_res(); eg. the
 	  'System RAM' entries in /proc/iomem.
-	  This value is combined with NR_CPUS_DEFAULT and multiplied by
+	  This value is combined with NR_CPUS and multiplied by
 	  sizeof(Elf64_Phdr) to determine the final elfcorehdr memory buffer/
 	  segment size.
 	  The value 8192, for example, covers a (sparsely populated) 1TiB system
kernel/crash_core.c +1 -1
index 2b36aa9fade0..d0bd2d0cf899 100644
@@ -648,7 +648,7 @@ int crash_check_hotplug_support(void)
  * new list of CPUs and memory. To make changes to the elfcorehdr, it
  * should be large enough to permit a growing number of CPU and Memory
  * resources. One can estimate the elfcorehdr memory size based on
- * NR_CPUS_DEFAULT and CRASH_MAX_MEMORY_RANGES. The elfcorehdr is
+ * NR_CPUS and CRASH_MAX_MEMORY_RANGES. The elfcorehdr is
  * excluded from SHA verification by default if the architecture
  * supports crash hotplug.
  */
Signature · 1 line
2.55.0
merge bot Applied
#9 lore raw

[tip: x86/kdump] crash: Update stale NR_CPUS_DEFAULT references in elfcorehdr sizing docs

The following commit has been merged into the x86/kdump branch of tip:

The following commit has been merged into the x86/kdump branch of tip:

Commit-ID:     d949fa7b1ec54c626b656f873b95d76b8ab0d143
Gitweb:        https://git.kernel.org/tip/d949fa7b1ec54c626b656f873b95d76b8ab0d143
Author:        Ionut Nechita <[email protected]>
AuthorDate:    Tue, 01 Sep 2026 10:10:41 +03:00
Committer:     Dave Hansen <[email protected]>
CommitterDate: Wed, 02 Sep 2026 14:25:16 -07:00

crash: Update stale NR_CPUS_DEFAULT references in elfcorehdr sizing docs

The elfcorehdr reservation is now sized with NR_CPUS, but two comments still name NR_CPUS_DEFAULT: the one above crash_handle_hotplug_event() and the CRASH_MAX_MEMORY_RANGES help text.

Update both. Documentation only, no functional change.

---
 kernel/Kconfig.kexec | 2 +-
 kernel/crash_core.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
kernel/Kconfig.kexec +1 -1
index 1563235..a97ed96 100644
@@ -167,7 +167,7 @@ config CRASH_MAX_MEMORY_RANGES
 	  memory regions that the elfcorehdr buffer/segment can accommodate.
 	  These regions are obtained via walk_system_ram_res(); eg. the
 	  'System RAM' entries in /proc/iomem.
-	  This value is combined with NR_CPUS_DEFAULT and multiplied by
+	  This value is combined with NR_CPUS and multiplied by
 	  sizeof(Elf64_Phdr) to determine the final elfcorehdr memory buffer/
 	  segment size.
 	  The value 8192, for example, covers a (sparsely populated) 1TiB system
kernel/crash_core.c +1 -1
index 2b36aa9..d0bd2d0 100644
@@ -648,7 +648,7 @@ int crash_check_hotplug_support(void)
  * new list of CPUs and memory. To make changes to the elfcorehdr, it
  * should be large enough to permit a growing number of CPU and Memory
  * resources. One can estimate the elfcorehdr memory size based on
- * NR_CPUS_DEFAULT and CRASH_MAX_MEMORY_RANGES. The elfcorehdr is
+ * NR_CPUS and CRASH_MAX_MEMORY_RANGES. The elfcorehdr is
  * excluded from SHA verification by default if the architecture
  * supports crash hotplug.
  */