[PATCH v3 00/17] crash: Rework and add arm64 crash hotplug support
Jinjie Ruan <[email protected]>
| Newsgroups | dev.linux.lists.loongarch,org.infradead.lists.kexec,org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-kernel,org.kvack.linux-mm,org.ozlabs.lists.linuxppc-dev |
|---|---|
| Message-ID | <[email protected]> |
When CPU or memory hotplug events occur, the elfcorehdr in the kdump
image becomes stale, potentially leading to incomplete crash dumps.
Currently, userspace udev rules reload the entire kdump image upon such
events, which is inefficient and leaves kdump inactive for a long time.
Commit 247262756121 ("crash: add generic infrastructure for crash hotplug
support") introduced a kernel mechanism to update only the elfcorehdr.
This patch set implements crash hotplug support for arm64.
As Baoquan and Catalin suggested, it also addresses and fixes several
pre-existing code issues found by Sashiko AI [1][2].
The major improvements and fixes included in this series are:
- Fix several memory leaks for arm64, and similar issues on LoongArch.
- Fix TOCTOU race in crash memory range collection
- Simplify x86 related code.
- Simplify arm64 load_other_segments().
- Implement infrastructure for arm64 crash memory hotplug support.
This patch set is rebased on x86 fix [3].
TESTING
=======
Only kexec_file_load path has been tested; kexec_load is expected to
work via KEXEC_CRASH_HOTPLUG_SUPPORT flag but not yet verified.
Tested on an arm64 guest using KVM-QEMU[4] with the following
configuration:
-M virt,acpi=on,highmem=on
-m 4G,slots=256,maxmem=16G
-smp cpus=4,maxcpus=8,cores=4,threads=2,sockets=1
1. Memory Hot-Add Test
[Step 1] Load kexec first:
./kexec --kexec-file-syscall ...
[Step 2] Hotplug and online 128M memory and trigger crash:
(qemu) object_add memory-backend-ram,id=mem1,size=128M
(qemu) device_add pc-dimm,id=dimm3,memdev=mem1,addr=0x160000000
echo 1 > /sys/devices/system/memory/memory44/online
echo c > /proc/sysrq-trigger
[Step 3] Verify vmcore layout in the secondary kernel:
readelf -l /proc/vmcore
The newly added 128M memory segment (0x160000000) is successfully
recognized and populated as a LOAD segment:
LOAD 0x... 0x0000000160000000 0x08000000 0x08000000 RWE 0x0
2. Memory Hot-Remove Test
[Step 1] Add memory device and online 128M memory first:
(qemu) device_add pc-dimm,id=dimm3,memdev=mem1,addr=0x160000000
echo 1 > /sys/devices/system/memory/memory44/online
[Step 2] Load kexec, offline memory, and crash:
./kexec --kexec-file-syscall ...
echo 0 > /sys/devices/system/memory/memory44/online
echo c > /proc/sysrq-trigger
[Step 3] Verify vmcore layout:
readelf -l /proc/vmcore
Result: The 0x160000000 segment is cleanly excluded from the vmcore
program headers, and the dump completes without any hang.
3. CPU Hot-Add Test
[Step 1] Load kexec first:
./kexec --kexec-file-syscall ...
[Step 2] hotplug and online one CPU, then crash:
(qemu) device_add driver=host-arm-cpu,core-id=2,thread-id=0,id=cpu4
echo 1 > /sys/devices/system/cpu/cpu4/online
echo c > /proc/sysrq-trigger
[Step 3] Verify notes count:
readelf -n /proc/vmcore | grep -w CORE | wc -l
5
Result: Crash hotplug responds correctly; the newly plugged CPU4 is
tracked, and 5 NT_PRSTATUS notes are generated.
4. CPU Hot-Remove Test
[Step 1] Add CPU device and online it first:
(qemu) device_add driver=host-arm-cpu,core-id=2,thread-id=0,id=cpu4
echo 1 > /sys/devices/system/cpu/cpu4/online
[Step 2] Load kexec, remove CPU, and crash:
./kexec --kexec-file-syscall ...
(qemu) device_del cpu4
echo c > /proc/sysrq-trigger
[Step 3] Verify notes count:
readelf -n /proc/vmcore | grep -w CORE | wc -l
4
Result: Crash hotplug automatically updates the headers upon CPU
eviction; only 4 online CPUs are registered in the vmcore.
[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://sashiko.dev/#/patchset/20260729031235.2840255-1-ruanjinjie%40huawei.com
[3]: https://lore.kernel.org/all/[email protected]/
[4]: https://github.com/salil-mehta/qemu.git virt-cpuhp-armv8/rfc-v2
Changes in v3:
- Handle "KEXEC_CRASH_HP_REMOVE_MEMORY" action.
- Fix several pre-existing code issues reported by Sashiko AI review [3].
- Introduce crash_extra_elfcorehdr_size() and elf64_phdr_size() helper.
- Rework related crash and arch code.
- Add test method.
- v2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Split out Powerpc bugfix patch as Mike suggested.
- Use phys_to_virt() instead of __va() in update_crash_elfcorehdr().
- Convert pnum_hdr_sz() to a function.
- Only assign elfcorehdr_index after kexec_add_buffer succeeds, considering
crash_handle_hotplug_event() already performs validity check on
elfcorehdr_index:
- We can safely remove the check for CPU hotplug
in arch_crash_handle_hotplug_event().
- The elfcorehdr_index's segment mem will be valid in
update_crash_elfcorehdr(), so we can safely remove the NULL check.
- Simplify the commit message.
- v1: https://lore.kernel.org/all/[email protected]/#t
Jinjie Ruan (17):
kexec: Record allocated CMA pages to fix release size mismatch
kexec: Extract kexec_free_segment_cma() from kimage_free_cma()
arm64: kexec_file: Fix CMA page leaks in segment placement retry loops
arm64: kexec_file: Fix elf_headers memory leak in retry loop
LoongArch: kexec: Fix CMA page leaks in segment placement retry loops
LoongArch: kexec_file: Fix elf_headers memory leak in retry loop
crash_dump: Fix potential double-free of keys_header
crash: Extract crash_get_memory_ranges() helper
crash: Fix TOCTOU race in crash memory range collection
elf: Introduce elf64_phdr_size() helper
crash: Introduce crash_extra_elfcorehdr_size() helper
x86/crash: Use num_possible_cpus() for elfcorehdr size
crash: Improve elfcorehdr segment identification
x86/crash: Simplify crash_load_segments() using
crash_extra_elfcorehdr_size()
crash: Simplify CRASH_MAX_MEMORY_RANGES handling
arm64: kexec_file: Simplify load_other_segments()
arm64: crash: Add crash hotplug support
arch/arm64/Kconfig | 3 +
arch/arm64/include/asm/kexec.h | 11 ++
arch/arm64/kernel/Makefile | 2 +-
arch/arm64/kernel/crash.c | 165 +++++++++++++++++++++
arch/arm64/kernel/kexec_image.c | 1 +
arch/arm64/kernel/machine_kexec_file.c | 57 ++-----
arch/loongarch/kernel/kexec_efi.c | 1 +
arch/loongarch/kernel/machine_kexec_file.c | 10 +-
arch/powerpc/kexec/crash.c | 6 +-
arch/powerpc/kexec/file_load_64.c | 19 +--
arch/powerpc/platforms/powernv/opal-core.c | 3 +-
arch/x86/kernel/crash.c | 46 ++----
fs/proc/vmcore.c | 6 +-
include/linux/crash_core.h | 27 ++++
include/linux/elf.h | 4 +
include/linux/kexec.h | 3 +
kernel/Kconfig.kexec | 3 +-
kernel/crash_core.c | 57 ++++++-
kernel/crash_dump_dm_crypt.c | 15 +-
kernel/kexec_core.c | 26 ++--
kernel/kexec_file.c | 16 +-
21 files changed, 352 insertions(+), 129 deletions(-)
create mode 100644 arch/arm64/kernel/crash.c
--
2.34.1