public inbox for linuxppc-dev@ozlabs.org
 help / color / mirror / Atom feed
* [PATCH v2] powerpc/crash: adjust the elfcorehdr size
@ 2026-02-27 17:18 Sourabh Jain
  2026-03-11  2:14 ` Madhavan Srinivasan
  0 siblings, 1 reply; 2+ messages in thread
From: Sourabh Jain @ 2026-02-27 17:18 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Sourabh Jain, Madhavan Srinivasan, Mahesh Salgaonkar,
	Michael Ellerman, Ritesh Harjani (IBM), Shivang Upadhyay,
	Hari Bathini

With crash hotplug support enabled, additional memory is allocated to
the elfcorehdr kexec segment to accommodate resources added during
memory hotplug events. However, the kdump FDT is not updated with the
same size, which can result in elfcorehdr corruption in the kdump
kernel.

Update elf_headers_sz (the kimage member representing the size of the
elfcorehdr kexec segment) to reflect the total memory allocated for the
elfcorehdr segment instead of the elfcorehdr buffer size at the time of
kdump load. This allows of_kexec_alloc_and_setup_fdt() to reserve the
full elfcorehdr memory in the kdump FDT and prevents elfcorehdr
corruption.

Fixes: 849599b702ef8 ("powerpc/crash: add crash memory hotplug support")
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mahesh Salgaonkar <mahesh@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Cc: Shivang Upadhyay <shivangu@linux.ibm.com>
Reviewed-by: Hari Bathini <hbathini@linux.ibm.com>
Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
---
Changelog:

v1:
https://lore.kernel.org/all/20260218050105.391285-1-sourabhjain@linux.ibm.com/

v2:
 - Add a comment explaining why elf_headers_sz is initialized
   with memsz instead of headers_sz.
---
 arch/powerpc/kexec/file_load_64.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kexec/file_load_64.c b/arch/powerpc/kexec/file_load_64.c
index e7ef8b2a2554..5f6d50e4c3d4 100644
--- a/arch/powerpc/kexec/file_load_64.c
+++ b/arch/powerpc/kexec/file_load_64.c
@@ -450,6 +450,11 @@ static int load_elfcorehdr_segment(struct kimage *image, struct kexec_buf *kbuf)
 	kbuf->buffer = headers;
 	kbuf->mem = KEXEC_BUF_MEM_UNKNOWN;
 	kbuf->bufsz = headers_sz;
+
+	/*
+	 * Account for extra space required to accommodate additional memory
+	 * ranges in elfcorehdr due to memory hotplug events.
+	 */
 	kbuf->memsz = headers_sz + kdump_extra_elfcorehdr_size(cmem);
 	kbuf->top_down = false;
 
@@ -460,7 +465,14 @@ static int load_elfcorehdr_segment(struct kimage *image, struct kexec_buf *kbuf)
 	}
 
 	image->elf_load_addr = kbuf->mem;
-	image->elf_headers_sz = headers_sz;
+
+	/*
+	 * If CONFIG_CRASH_HOTPLUG is enabled, the elfcorehdr kexec segment
+	 * memsz can be larger than bufsz. Always initialize elf_headers_sz
+	 * with memsz. This ensures the correct size is reserved for elfcorehdr
+	 * memory in the FDT prepared for kdump.
+	 */
+	image->elf_headers_sz = kbuf->memsz;
 	image->elf_headers = headers;
 out:
 	kfree(cmem);
-- 
2.52.0



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

* Re: [PATCH v2] powerpc/crash: adjust the elfcorehdr size
  2026-02-27 17:18 [PATCH v2] powerpc/crash: adjust the elfcorehdr size Sourabh Jain
@ 2026-03-11  2:14 ` Madhavan Srinivasan
  0 siblings, 0 replies; 2+ messages in thread
From: Madhavan Srinivasan @ 2026-03-11  2:14 UTC (permalink / raw)
  To: linuxppc-dev, Sourabh Jain
  Cc: Mahesh Salgaonkar, Michael Ellerman, Ritesh Harjani (IBM),
	Shivang Upadhyay, Hari Bathini

On Fri, 27 Feb 2026 22:48:01 +0530, Sourabh Jain wrote:
> With crash hotplug support enabled, additional memory is allocated to
> the elfcorehdr kexec segment to accommodate resources added during
> memory hotplug events. However, the kdump FDT is not updated with the
> same size, which can result in elfcorehdr corruption in the kdump
> kernel.
> 
> Update elf_headers_sz (the kimage member representing the size of the
> elfcorehdr kexec segment) to reflect the total memory allocated for the
> elfcorehdr segment instead of the elfcorehdr buffer size at the time of
> kdump load. This allows of_kexec_alloc_and_setup_fdt() to reserve the
> full elfcorehdr memory in the kdump FDT and prevents elfcorehdr
> corruption.
> 
> [...]

Applied to powerpc/fixes.

[1/1] powerpc/crash: adjust the elfcorehdr size
      https://git.kernel.org/powerpc/c/04e707cb77c272cb0bb2e2e3c5c7f844d804a089

cheers


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

end of thread, other threads:[~2026-03-11  2:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-27 17:18 [PATCH v2] powerpc/crash: adjust the elfcorehdr size Sourabh Jain
2026-03-11  2:14 ` Madhavan Srinivasan

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