On a kernel crash, purgatory copies the first 64 KB of the crashed kernel memory to the backup memory region reserved within crashkernel memory for the kdump kernel. This ensures that the capture kernel can use the first 64 KB of memory to place the exception vectors and other required data.
However, in the elfcorehdr prepared using the kexec_file_load syscall, or the one recreated during a memory hotplug event, the offset of the program header representing the first 64 KB of memory is set to 0, whereas it should point to the backup region. This has not caused issues so far because the first 64 KB is usually identical in both the crashed and capture kernels. However, this is only an assumption and is not guaranteed to always hold true. Therefore, update the offset of the program header representing the first 64 KB of the crashed kernel memory in the elfcorehdr prepared for the kdump kernel. Testing: ======= Git Tree: https://github.com/sourabhjains/linux/commits/kdump-backup-region-offset/ The above tree contains an additional patch that introduces a new sysfs interface to dump the kdump elfcorehdr to the dmesg/console. $> cat /sys/kernel/kexec/crash_elfcorehdr_print ELF Program Header Summary: Total Program Headers: 13 (0xd) PT_LOAD segments: 4 (0x4) PT_NOTE segments: 9 (0x9) Program Headers: Index Type Offset VirtAddr PhysAddr FileSize MemSize Flags ================================================================================ 0x0 PT_NOTE 0x3fd966400 0x0 0x3fd966400 0x218 0x218 --- 0x1 PT_NOTE 0x3fd996400 0x0 0x3fd996400 0x218 0x218 --- 0x2 PT_NOTE 0x3fd9c6400 0x0 0x3fd9c6400 0x218 0x218 --- 0x3 PT_NOTE 0x3fd9f6400 0x0 0x3fd9f6400 0x218 0x218 --- 0x4 PT_NOTE 0x3fda26400 0x0 0x3fda26400 0x218 0x218 --- 0x5 PT_NOTE 0x3fda56400 0x0 0x3fda56400 0x218 0x218 --- 0x6 PT_NOTE 0x3fda86400 0x0 0x3fda86400 0x218 0x218 --- 0x7 PT_NOTE 0x3fdab6400 0x0 0x3fdab6400 0x218 0x218 --- 0x8 PT_NOTE 0xa2c0000 0x0 0xa2c0000 0x10024 0x10024 --- 0x9 PT_LOAD 0x1af40000 0xc000000000000000 0x0 0x10000 0x10000 RWX 0xa PT_LOAD 0x10000 0xc000000000010000 0x10000 0x17ff0000 0x17ff0000 RWX 0xb PT_LOAD 0x2ec70000 0xc00000002ec70000 0x2ec70000 0x1390000 0x1390000 RWX 0xc PT_LOAD 0x58000000 0xc000000058000000 0x58000000 0x3a8000000 0x3a8000000 RWX So, once kdump is successfully loaded using the kexec command, for example: $ kexec --initrd=/boot/initramfs-`uname -r`.img /boot/vmlinuz-`uname -r` --append="`cat /proc/cmdline`" -pds Running cat /sys/kernel/kexec/crash_elfcorehdr_print prints the elfcorehdr in the above format. The offset of the program header representing the first 64 KB can be easily observed. Cc: Hari Bathini <[email protected]> Cc: Madhavan Srinivasan <[email protected]> Cc: Mahesh Salgaonkar <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Ritesh Harjani (IBM) <[email protected]> Cc: Shivang Upadhyay <[email protected]> Cc: Sourabh Jain <[email protected]> Sourabh Jain (2): powerpc/crash: fix backup region offset update to eflcorehdr powerpc/crash: Update backup region offset in elfcorehdr on memory hotplug arch/powerpc/include/asm/kexec.h | 6 ++++ arch/powerpc/kexec/crash.c | 60 +++++++++++++++++++++++++++++++ arch/powerpc/kexec/file_load_64.c | 29 +-------------- 3 files changed, 67 insertions(+), 28 deletions(-) -- 2.52.0
