From nobody Sun Jun 14 09:59:13 2026 Received: from canpmsgout08.his.huawei.com (canpmsgout08.his.huawei.com [113.46.200.223]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B7143A3E8E for ; Thu, 2 Apr 2026 08:12:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.223 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775117573; cv=none; b=plUMjjaNvhRCSvytiyrntqLXwIfqQ5//xhRhU2U5DhbKPckQrkWJUq2IKGdT06TGMDKbApU/gVxk70hlQ/SQIelWHpM4co7kAzqZyPrUj1jajGdB394PWWt0FfanASB7Y2c7QtWyjqa6KRH3hMAti8OAGBIJ+u61JXCKGYPUeKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775117573; c=relaxed/simple; bh=K/y/12xAzONG0rgPPQ38FZvzX24r3RJH3yfu1vrhybw=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=MhqMr6/07xTvaPrtIRp2v4UbnmQdpw5SjV5Vt25BFCV6j+hnL/6cvI4IX4sLqWLoUPOBtE1Ymu9qsI5HQwg9YiwsOqylt8RyRCwrxN+2Bj3gBiYqVlPPt53qoc90CtF+8kbNuyKTFtJ5IjWBvUDkmGs29y+7Ktcoiqm8alGLMdo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=t4chdBYs; arc=none smtp.client-ip=113.46.200.223 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="t4chdBYs" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=88lXO6LhSwNx1CgLSD4DNHau8+gUae1fs/ET3pHof00=; b=t4chdBYsj8B1MT94tozt+07G7Od8Mwf/4vOxamXoYdKfye/leF0OGjSM3cuaBTVjOTYH/Tt2t uxMHImbAR/Or6w8uf8NP/xSb+pvixZlQLk+TsXeuWpmoA0GURYJl7fzZjrcbWRLJFn8pRxKnEVy N5EqEa97wEVkVrlVpXrsLbY= Received: from mail.maildlp.com (unknown [172.19.162.92]) by canpmsgout08.his.huawei.com (SkyGuard) with ESMTPS id 4fmZF11BDKzmVVm; Thu, 2 Apr 2026 16:06:29 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 08BB44056E; Thu, 2 Apr 2026 16:12:41 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 2 Apr 2026 16:12:40 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , CC: Subject: [PATCH] arm64/crash: Add crash hotplug support Date: Thu, 2 Apr 2026 16:14:59 +0800 Message-ID: <20260402081459.635022-1-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf500011.china.huawei.com (7.185.36.131) Content-Type: text/plain; charset="utf-8" Due to CPU/Memory hotplug or online/offline events, the elfcorehdr (which describes the CPUs and memory of the crashed kernel) of kdump image becomes outdated. Consequently, attempting dump collection with an outdated elfcorehdr can lead to inaccurate dump collection. The current solution to address the above issue involves monitoring the CPU/Memory add/remove events in userspace using udev rules and whenever there are changes in CPU and memory resources, the entire kdump image is loaded again. The kdump image includes kernel, initrd, elfcorehdr, FDT, purgatory. Given that only elfcorehdr gets outdated due to CPU/Memory add/remove events, reloading the entire kdump image is inefficient. More importantly, kdump remains inactive for a substantial amount of time until the kdump reload completes. To address the aforementioned issue, commit 247262756121 ("crash: add generic infrastructure for crash hotplug support") added a generic infrastructure that allows architectures to selectively update the kdump image component during CPU or memory add/remove events within the kernel itself. In the event of a CPU or memory add/remove events, the generic crash hotplug event handler, crash_handle_hotplug_event(), is triggered. It then acquires the necessary locks to update the kdump image and invokes the architecture-specific crash hotplug handler, arch_crash_handle_hotplug_event(), to update the required kdump image components. [1] has supported virtual CPU hotplug in virtual machines for ARM64, allowing vCPUs to be added or removed at runtime to meet Kubernetes demands. On ARM64, only memory add/remove events are handled. Here's why: 1. Physical CPU hotplug: Not supported on ARM64 hardware. 2. ACPI vCPU hotplug (KVM virtual machine): - vCPU hotplug is implemented as a static firmware policy where all possible vCPUs are pre-described in the MADT table at boot. - The vCPU status will be automatically updated after vCPU hotplug. - No FDT or elfcorehdr update needed. 3. Device tree booted Virtual Machine vCPU hotplug: - The elfcorehdr is built using for_each_possible_cpu(), so it already includes all possible CPUs and doesn't need updates. For memory add/remove events, the elfcorehdr is updated to reflect the current memory layout. This patch adds the ARCH_SUPPORTS_CRASH_HOTPLUG config option and implements: - arch_crash_hotplug_support(): Check if hotplug update is supported - arch_crash_get_elfcorehdr_size(): Return elfcorehdr buffer size - arch_crash_handle_hotplug_event(): Handle memory hotplug events This follows the same approach as x86 commit ea53ad9cf73b ("x86/crash: add x86 crash hotplug support") and powerpc commit b741092d5976 ("powerpc/crash: add crash CPU hotplug support") and commit 849599b702ef ("powerpc/crash: add crash memory hotplug support"). The test is based on the following QEMU version: https://github.com/salil-mehta/qemu.git virt-cpuhp-armv8/rfc-v2 Replace your '-smp' argument with something like: | -smp cpus=3D1,maxcpus=3D3,cores=3D3,threads=3D1,sockets=3D1 then feed the following to the Qemu montior to hotplug vCPU; | (qemu) device_add driver=3Dhost-arm-cpu,core-id=3D1,id=3Dcpu1 | (qemu) device_del cpu1 feed the following to the Qemu montior to hotplug memory; | (qemu) object_add memory-backend-ram,id=3Dmem1,size=3D256M | (qemu) device_add pc-dimm,id=3Ddimm1,memdev=3Dmem1 | (qemu) device_del dimm1 The qemu startup configuration is as follows: qemu-system-aarch64 \ -M virt,gic-version=3D3,acpi=3Don,highmem=3Don \ -enable-kvm \ -cpu host \ -kernel Image \ -smp cpus=3D1,maxcpus=3D3,cores=3D3,threads=3D1,sockets=3D1 \ -bios /usr/share/edk2/aarch64/QEMU_EFI.fd \ -m 2G,slots=3D64,maxmem=3D16G \ -nographic \ -no-reboot \ -device virtio-rng-pci \ -append "root=3D/dev/vda rw console=3DttyAMA0 kgdboc=3DttyAMA0,115200 \ earlycon acpi=3Don crashkernel=3D512M" \ -drive if=3Dnone,file=3Dimages/rootfs.ext4,format=3Draw,id=3Dhd0 \ -device virtio-blk-device,drive=3Dhd0 \ There are two system calls, `kexec_file_load` and `kexec_load`, used to load the kdump image. Only kexec_file_load syscall way is tested now. This patch is based on following rework: https://lore.kernel.org/all/20260328074013.3589544-1-ruanjinjie@huawei.com/ Cc: Catalin Marinas Cc: Will Deacon Cc: Baoquan He Cc: "Mike Rapoport (Microsoft)" Cc: Andrew Morton Cc: Breno Leitao Cc: Kees Cook [1]: https://lore.kernel.org/all/20240529133446.28446-1-Jonathan.Cameron@hu= awei.com/ Signed-off-by: Jinjie Ruan --- arch/arm64/Kconfig | 3 + arch/arm64/include/asm/kexec.h | 11 +++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/crash.c | 125 +++++++++++++++++++++++++ arch/arm64/kernel/machine_kexec_file.c | 24 ++++- 5 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 arch/arm64/kernel/crash.c diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 38dba5f7e4d2..518bb59e7c19 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1630,6 +1630,9 @@ config ARCH_DEFAULT_CRASH_DUMP config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION def_bool CRASH_RESERVE =20 +config ARCH_SUPPORTS_CRASH_HOTPLUG + def_bool y + config TRANS_TABLE def_bool y depends on HIBERNATION || KEXEC_CORE diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 892e5bebda95..f165c094b32e 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -130,6 +130,17 @@ extern int load_other_segments(struct kimage *image, char *cmdline); #endif =20 +#ifdef CONFIG_CRASH_HOTPLUG +void arch_crash_handle_hotplug_event(struct kimage *image, void *arg); +#define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event + +int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_f= lags); +#define arch_crash_hotplug_support arch_crash_hotplug_support + +unsigned int arch_crash_get_elfcorehdr_size(void); +#define crash_get_elfcorehdr_size arch_crash_get_elfcorehdr_size +#endif + #endif /* __ASSEMBLER__ */ =20 #endif diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 76f32e424065..f66737bed1cf 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -64,6 +64,7 @@ obj-$(CONFIG_KEXEC_FILE) +=3D machine_kexec_file.o kexec= _image.o obj-$(CONFIG_ARM64_RELOC_TEST) +=3D arm64-reloc-test.o arm64-reloc-test-y :=3D reloc_test_core.o reloc_test_syms.o obj-$(CONFIG_CRASH_DUMP) +=3D crash_dump.o +obj-$(CONFIG_CRASH_HOTPLUG) +=3D crash.o obj-$(CONFIG_VMCORE_INFO) +=3D vmcore_info.o obj-$(CONFIG_ARM_SDE_INTERFACE) +=3D sdei.o obj-$(CONFIG_ARM64_PTR_AUTH) +=3D pointer_auth.o diff --git a/arch/arm64/kernel/crash.c b/arch/arm64/kernel/crash.c new file mode 100644 index 000000000000..2114375820da --- /dev/null +++ b/arch/arm64/kernel/crash.c @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Architecture specific functions for kexec based crash dumps. + */ + +#define pr_fmt(fmt) "crash hp: " fmt + +#include +#include +#include +#include + +#include + +#ifdef CONFIG_CRASH_HOTPLUG + +int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_f= lags) +{ +#ifdef CONFIG_KEXEC_FILE + if (image->file_mode) + return 1; +#endif + /* + * For kexec_load syscall, crash hotplug support requires + * KEXEC_CRASH_HOTPLUG_SUPPORT flag to be passed by userspace. + */ + return kexec_flags & KEXEC_CRASH_HOTPLUG_SUPPORT; +} + +unsigned int arch_crash_get_elfcorehdr_size(void) +{ + unsigned int phdr_cnt; + + /* A program header for possible CPUs, vmcoreinfo and kernel_map */ + phdr_cnt =3D 2 + num_possible_cpus(); + if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) + phdr_cnt +=3D CONFIG_CRASH_MAX_MEMORY_RANGES; + + return sizeof(Elf64_Ehdr) + phdr_cnt * sizeof(Elf64_Phdr); +} + +/** + * update_crash_elfcorehdr() - Recreate the elfcorehdr and replace it with= old + * elfcorehdr in the kexec segment array. + * @image: the active struct kimage + */ +static void update_crash_elfcorehdr(struct kimage *image) +{ + void *elfbuf =3D NULL, *old_elfcorehdr; + unsigned long mem, memsz; + unsigned long elfsz =3D 0; + + /* + * Create the new elfcorehdr reflecting the changes to CPU and/or + * memory resources. + */ + if (crash_prepare_headers(true, &elfbuf, &elfsz, NULL)) { + pr_err("unable to create new elfcorehdr"); + goto out; + } + + /* + * Obtain address and size of the elfcorehdr segment, and + * check it against the new elfcorehdr buffer. + */ + mem =3D image->segment[image->elfcorehdr_index].mem; + memsz =3D image->segment[image->elfcorehdr_index].memsz; + if (elfsz > memsz) { + pr_err("update elfcorehdr elfsz %lu > memsz %lu", + elfsz, memsz); + goto out; + } + + /* + * Copy new elfcorehdr over the old elfcorehdr at destination. + */ + old_elfcorehdr =3D (void *)__va(mem); + if (!old_elfcorehdr) { + pr_err("mapping elfcorehdr segment failed\n"); + goto out; + } + + /* + * Temporarily invalidate the crash image while the + * elfcorehdr is updated. + */ + xchg(&kexec_crash_image, NULL); + memcpy_flushcache(old_elfcorehdr, elfbuf, elfsz); + xchg(&kexec_crash_image, image); + pr_debug("updated elfcorehdr\n"); + +out: + vfree(elfbuf); +} + +/** + * arch_crash_handle_hotplug_event() - Handle hotplug elfcorehdr changes + * @image: a pointer to kexec_crash_image + * @arg: struct memory_notify handler for memory hotplug case and + * NULL for CPU hotplug case. + * + * Update the kdump image based on the type of hotplug event: + * - CPU add and remove: No action is needed. + * - Memory add/remove: Update the elfcorehdr to reflect the current memor= y layout. + * + * Prepare the new elfcorehdr and replace the existing elfcorehdr. + */ +void arch_crash_handle_hotplug_event(struct kimage *image, void *arg) +{ + switch (image->hp_action) { + case KEXEC_CRASH_HP_ADD_CPU: + fallthrough; + case KEXEC_CRASH_HP_REMOVE_CPU: + if (image->file_mode || image->elfcorehdr_updated) + return; + fallthrough; + case KEXEC_CRASH_HP_ADD_MEMORY: + case KEXEC_CRASH_HP_REMOVE_MEMORY: + update_crash_elfcorehdr(image); + return; + default: + pr_warn_once("Unknown hotplug action\n"); + } +} +#endif /* CONFIG_CRASH_HOTPLUG */ diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/mac= hine_kexec_file.c index a8fe7e65ef75..a40ca37f3d55 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -85,6 +85,9 @@ int load_other_segments(struct kimage *image, void *dtb =3D NULL; unsigned long initrd_load_addr =3D 0, dtb_len, orig_segments =3D image->nr_segments; +#ifdef CONFIG_CRASH_HOTPLUG + unsigned long pnum =3D 0; +#endif int ret =3D 0; =20 kbuf.image =3D image; @@ -96,7 +99,7 @@ int load_other_segments(struct kimage *image, void *headers; unsigned long headers_sz; if (image->type =3D=3D KEXEC_TYPE_CRASH) { - ret =3D crash_prepare_headers(true, &headers, &headers_sz, NULL); + ret =3D crash_prepare_headers(true, &headers, &headers_sz, &pnum); if (ret) { pr_err("Preparing elf core header failed\n"); goto out_err; @@ -106,6 +109,23 @@ int load_other_segments(struct kimage *image, kbuf.bufsz =3D headers_sz; kbuf.mem =3D KEXEC_BUF_MEM_UNKNOWN; kbuf.memsz =3D headers_sz; + +#ifdef CONFIG_CRASH_HOTPLUG + /* + * The elfcorehdr segment size accounts for VMCOREINFO, kernel_map + * maximum CPUs and maximum memory ranges. + */ + if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) + pnum =3D 2 + num_possible_cpus() + CONFIG_CRASH_MAX_MEMORY_RANGES; + else + pnum +=3D 2 + num_possible_cpus(); + + if (pnum < (unsigned long)PN_XNUM) + kbuf.memsz =3D pnum * sizeof(Elf64_Phdr) + sizeof(Elf64_Ehdr); + else + pr_err("number of Phdrs %lu exceeds max\n", pnum); +#endif + kbuf.buf_align =3D SZ_64K; /* largest supported page size */ kbuf.buf_max =3D ULONG_MAX; kbuf.top_down =3D true; @@ -117,7 +137,7 @@ int load_other_segments(struct kimage *image, } image->elf_headers =3D headers; image->elf_load_addr =3D kbuf.mem; - image->elf_headers_sz =3D headers_sz; + image->elf_headers_sz =3D kbuf.memsz; =20 kexec_dprintk("Loaded elf core header at 0x%lx bufsz=3D0x%lx memsz=3D0x%= lx\n", image->elf_load_addr, kbuf.bufsz, kbuf.memsz); --=20 2.34.1