]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
powerpc/crash: adjust the elfcorehdr size
authorSourabh Jain <sourabhjain@linux.ibm.com>
Fri, 27 Feb 2026 17:18:01 +0000 (22:48 +0530)
committerMadhavan Srinivasan <maddy@linux.ibm.com>
Wed, 4 Mar 2026 05:42:48 +0000 (11:12 +0530)
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")
Reviewed-by: Hari Bathini <hbathini@linux.ibm.com>
Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Link: https://patch.msgid.link/20260227171801.2238847-1-sourabhjain@linux.ibm.com
arch/powerpc/kexec/file_load_64.c

index e7ef8b2a25546bd82df757d4ed6283a45b139842..5f6d50e4c3d4502820228e20769d5d780c665471 100644 (file)
@@ -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);