[PW_SID:1072012] arm64/riscv: Add support for crashkernel CMA reservation#1666
[PW_SID:1072012] arm64/riscv: Add support for crashkernel CMA reservation#1666linux-riscv-bot wants to merge 8 commits into
Conversation
As done in commit 944a45a ("arm64: kdump: Reimplement crashkernel=X") and commit 4831be7 ("arm64/kexec: Fix missing extra range for crashkres_low.") for arm64, while implementing crashkernel=X,[high,low], riscv should have excluded the "crashk_low_res" reserved ranges from the crash kernel memory to prevent them from being exported through /proc/vmcore, and the exclusion would need an extra crash_mem range. Fixes: 5882e5a ("riscv: kdump: Implement crashkernel=X,[high,low]") Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
In get_crash_memory_ranges(), if crash_exclude_mem_range() failed after realloc_mem_ranges() has successfully allocated the cmem memory, it just returns an error but leaves cmem pointing to the allocated memory, nor is it freed in the caller update_crash_elfcorehdr(), which cause a memory leak, goto out to free the cmem. Fixes: 849599b ("powerpc/crash: add crash memory hotplug support") Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
During a memory hot-remove event, the elfcorehdr is rebuilt to exclude the removed memory. While updating the crash memory ranges for this operation, the crash memory ranges array can become unsorted. This happens because remove_mem_range() may split a memory range into two parts and append the higher-address part as a separate range at the end of the array. So far, no issues have been observed due to the unsorted crash memory ranges. However, this could lead to problems once crash memory range removal is handled by generic code, as introduced in the upcoming patches in this series. Currently, powerpc uses a platform-specific function, remove_mem_range(), to exclude hot-removed memory from the crash memory ranges. This function performs the same task as the generic crash_exclude_mem_range() in crash_core.c. The generic helper also ensures that the crash memory ranges remain sorted. So remove the redundant powerpc-specific implementation and instead call crash_exclude_mem_range_guarded() (which internally calls crash_exclude_mem_range()) to exclude the hot-removed memory ranges. Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Baoquan he <bhe@redhat.com> Cc: Jinjie Ruan <ruanjinjie@huawei.com> Cc: Hari Bathini <hbathini@linux.ibm.com> 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> Cc: linux-kernel@vger.kernel.org Acked-by: Baoquan He <bhe@redhat.com> Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
The crash memory alloc, and the exclude of crashk_res, crashk_low_res and crashk_cma memory are almost identical across different architectures, handling them in the crash core would eliminate a lot of duplication, so do them in the common code. To achieve the above goal, three architecture-specific functions are introduced: - arch_get_system_nr_ranges(). Pre-counts the max number of memory ranges. - arch_crash_populate_cmem(). Collects the memory ranges and fills them into cmem. - arch_crash_exclude_ranges(). Architecture's additional crash memory ranges exclusion, defaulting to empty. Reviewed-by: Sourabh Jain <sourabhjain@linux.ibm.com> Acked-by: Baoquan He <bhe@redhat.com> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
The crash memory exclude of crashk_res and crashk_cma memory on powerpc are almost identical to the generic crash_exclude_core_ranges(). By introducing the architecture-specific arch_crash_exclude_mem_range() function with a default implementation of crash_exclude_mem_range(), and using crash_exclude_mem_range_guarded as powerpc's separate implementation, the generic crash_exclude_core_ranges() helper function can be reused. Acked-by: Baoquan He <bhe@redhat.com> Reviewed-by: Sourabh Jain <sourabhjain@linux.ibm.com> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Commit 35c18f2 ("Add a new optional ",cma" suffix to the crashkernel= command line option") and commit ab47551 ("kdump: implement reserve_crashkernel_cma") added CMA support for kdump crashkernel reservation. Crash kernel memory reservation wastes production resources if too large, risks kdump failure if too small, and faces allocation difficulties on fragmented systems due to contiguous block constraints. The new CMA-based crashkernel reservation scheme splits the "large fixed reservation" into a "small fixed region + large CMA dynamic region": the CMA memory is available to userspace during normal operation to avoid waste, and is reclaimed for kdump upon crash—saving memory while improving reliability. So extend crashkernel CMA reservation support to arm64. The following changes are made to enable CMA reservation: - Parse and obtain the CMA reservation size along with other crashkernel parameters. - Call reserve_crashkernel_cma() to allocate the CMA region for kdump. - Include the CMA-reserved ranges for kdump kernel to use. - Exclude the CMA-reserved ranges from the crash kernel memory to prevent them from being exported through /proc/vmcore, which is already done in the crash core. Update kernel-parameters.txt to document CMA support for crashkernel on arm64 architecture. Acked-by: Rob Herring (Arm) <robh@kernel.org> Acked-by: Baoquan He <bhe@redhat.com> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Acked-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Commit 35c18f2 ("Add a new optional ",cma" suffix to the crashkernel= command line option") and commit ab47551 ("kdump: implement reserve_crashkernel_cma") added CMA support for kdump crashkernel reservation. This allows the kernel to dynamically allocate contiguous memory for crash dumping when needed, rather than permanently reserving a fixed region at boot time. So extend crashkernel CMA reservation support to riscv. The following changes are made to enable CMA reservation: - Parse and obtain the CMA reservation size along with other crashkernel parameters. - Call reserve_crashkernel_cma() to allocate the CMA region for kdump. - Include the CMA-reserved ranges for kdump kernel to use, which was already done in of_kexec_alloc_and_setup_fdt(). - Exclude the CMA-reserved ranges from the crash kernel memory to prevent them from being exported through /proc/vmcore, which was already done in the crash core. Update kernel-parameters.txt to document CMA support for crashkernel on riscv architecture. Acked-by: Baoquan He <bhe@redhat.com> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Acked-by: Paul Walmsley <pjw@kernel.org> # arch/riscv Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
…plug There is a race condition between the kexec_load() system call (crash kernel loading path) and memory hotplug operations that can lead to buffer overflow and potential kernel crash. During crash_prepare_headers(), the following steps occur: 1. arch_get_system_nr_ranges() queries current memory ranges from memblock 2. alloc_cmem() allocates buffer based on queried count 3. arch_crash_populate_cmem() populates ranges from memblock If memory hotplug occurs between step 1 and step 3, the number of ranges can increase, causing out-of-bounds write when populating cmem->ranges[]. This happens because kexec_load() uses kexec_trylock (atomic_t) while memory hotplug uses device_hotplug_lock (mutex), so they don't serialize with each other. Fix by adding lock_device_hotplug()/unlock_device_hotplug() around the critical section in crash_prepare_headers(). The lock is only acquired when CONFIG_MEMORY_HOTPLUG is enabled to avoid overhead on systems without hotplug support. Fixes: dd5f726 ("kexec: support for kexec on panic using new system call") Fixes: 3751e72 ("arm64: kexec_file: add crash dump support") Fixes: 8acea45 ("RISC-V: Support for kexec_file on panic") Fixes: 1bcca86 ("LoongArch: Add crash dump support for kexec_file") Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "[v10,1/8] riscv: kexec_file: Fix crashk_low_res not exclude bug" |
|
Patch 1: "[v10,1/8] riscv: kexec_file: Fix crashk_low_res not exclude bug" |
|
Patch 1: "[v10,1/8] riscv: kexec_file: Fix crashk_low_res not exclude bug" |
|
Patch 1: "[v10,1/8] riscv: kexec_file: Fix crashk_low_res not exclude bug" |
|
Patch 1: "[v10,1/8] riscv: kexec_file: Fix crashk_low_res not exclude bug" |
|
Patch 1: "[v10,1/8] riscv: kexec_file: Fix crashk_low_res not exclude bug" |
|
Patch 1: "[v10,1/8] riscv: kexec_file: Fix crashk_low_res not exclude bug" |
|
Patch 1: "[v10,1/8] riscv: kexec_file: Fix crashk_low_res not exclude bug" |
|
Patch 1: "[v10,1/8] riscv: kexec_file: Fix crashk_low_res not exclude bug" |
|
Patch 1: "[v10,1/8] riscv: kexec_file: Fix crashk_low_res not exclude bug" |
|
Patch 1: "[v10,1/8] riscv: kexec_file: Fix crashk_low_res not exclude bug" |
|
Patch 1: "[v10,1/8] riscv: kexec_file: Fix crashk_low_res not exclude bug" |
|
Patch 2: "[v10,2/8] powerpc/crash: Fix possible memory leak in update_crash_elfcorehdr()" |
|
Patch 2: "[v10,2/8] powerpc/crash: Fix possible memory leak in update_crash_elfcorehdr()" |
|
Patch 2: "[v10,2/8] powerpc/crash: Fix possible memory leak in update_crash_elfcorehdr()" |
|
Patch 2: "[v10,2/8] powerpc/crash: Fix possible memory leak in update_crash_elfcorehdr()" |
|
Patch 2: "[v10,2/8] powerpc/crash: Fix possible memory leak in update_crash_elfcorehdr()" |
|
Patch 2: "[v10,2/8] powerpc/crash: Fix possible memory leak in update_crash_elfcorehdr()" |
|
Patch 2: "[v10,2/8] powerpc/crash: Fix possible memory leak in update_crash_elfcorehdr()" |
|
Patch 2: "[v10,2/8] powerpc/crash: Fix possible memory leak in update_crash_elfcorehdr()" |
|
Patch 2: "[v10,2/8] powerpc/crash: Fix possible memory leak in update_crash_elfcorehdr()" |
|
Patch 2: "[v10,2/8] powerpc/crash: Fix possible memory leak in update_crash_elfcorehdr()" |
|
Patch 6: "[v10,6/8] arm64: kexec: Add support for crashkernel CMA reservation" |
|
Patch 6: "[v10,6/8] arm64: kexec: Add support for crashkernel CMA reservation" |
|
Patch 6: "[v10,6/8] arm64: kexec: Add support for crashkernel CMA reservation" |
|
Patch 6: "[v10,6/8] arm64: kexec: Add support for crashkernel CMA reservation" |
|
Patch 7: "[v10,7/8] riscv: kexec: Add support for crashkernel CMA reservation" |
|
Patch 7: "[v10,7/8] riscv: kexec: Add support for crashkernel CMA reservation" |
|
Patch 7: "[v10,7/8] riscv: kexec: Add support for crashkernel CMA reservation" |
|
Patch 7: "[v10,7/8] riscv: kexec: Add support for crashkernel CMA reservation" |
|
Patch 7: "[v10,7/8] riscv: kexec: Add support for crashkernel CMA reservation" |
|
Patch 7: "[v10,7/8] riscv: kexec: Add support for crashkernel CMA reservation" |
|
Patch 7: "[v10,7/8] riscv: kexec: Add support for crashkernel CMA reservation" |
|
Patch 7: "[v10,7/8] riscv: kexec: Add support for crashkernel CMA reservation" |
|
Patch 7: "[v10,7/8] riscv: kexec: Add support for crashkernel CMA reservation" |
|
Patch 7: "[v10,7/8] riscv: kexec: Add support for crashkernel CMA reservation" |
|
Patch 7: "[v10,7/8] riscv: kexec: Add support for crashkernel CMA reservation" |
|
Patch 7: "[v10,7/8] riscv: kexec: Add support for crashkernel CMA reservation" |
|
Patch 8: "[v10,8/8] crash: Fix race condition between crash kernel loading and memory hotplug" |
|
Patch 8: "[v10,8/8] crash: Fix race condition between crash kernel loading and memory hotplug" |
|
Patch 8: "[v10,8/8] crash: Fix race condition between crash kernel loading and memory hotplug" |
|
Patch 8: "[v10,8/8] crash: Fix race condition between crash kernel loading and memory hotplug" |
|
Patch 8: "[v10,8/8] crash: Fix race condition between crash kernel loading and memory hotplug" |
|
Patch 8: "[v10,8/8] crash: Fix race condition between crash kernel loading and memory hotplug" |
|
Patch 8: "[v10,8/8] crash: Fix race condition between crash kernel loading and memory hotplug" |
|
Patch 8: "[v10,8/8] crash: Fix race condition between crash kernel loading and memory hotplug" |
|
Patch 8: "[v10,8/8] crash: Fix race condition between crash kernel loading and memory hotplug" |
|
Patch 8: "[v10,8/8] crash: Fix race condition between crash kernel loading and memory hotplug" |
|
Patch 8: "[v10,8/8] crash: Fix race condition between crash kernel loading and memory hotplug" |
|
Patch 8: "[v10,8/8] crash: Fix race condition between crash kernel loading and memory hotplug" |
PR for series 1072012 applied to workflow__riscv__for-next
Name: arm64/riscv: Add support for crashkernel CMA reservation
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1072012
Version: 10