PowerPC: In-kernel handling of CPU/Memory hotplug/online/offline events for kdump kernel
Subsystems (6)
v10 cover PowerPC: In-kernel handling of CPU/Memory hotplug/online/offline events for kdump kernel
The Problem:
============
Post CPU/Memory hot plug/unplug and online/offline events the kernel holds stale information about the system. Dump collection with stale kdump kernel might end up in dump capture failure or an inaccurate dump collection.
Existing solution:
==================
The existing solution to keep the kdump kernel up-to-date by monitoring CPU/Memory hotplug/online/offline events via udev rule and trigger a full kdump kernel reload for every hotplug event.
Shortcomings:
------------------------------------------------
- Leaves a window where kernel crash might not lead to a successful dump collection.
- Reloading all kexec components for each hotplug is inefficient.
- udev rules are prone to races if hotplug events are frequent.
More about issues with an existing solution is posted here:
- https://lkml.org/lkml/2020/12/14/532
- https://lists.ozlabs.org/pipermail/linuxppc-dev/2022-February/240254.html
Proposed Solution:
==================
Instead of reloading all kexec segments on CPU/Memory hotplug/online/offline event, this patch series focuses on updating only the relevant kexec segment. Once the kexec segments are loaded in the kernel reserved area then an arch-specific hotplug handler will update the relevant kexec segment based on hotplug event type.
Series Dependencies
====================
This patch series implements the crash hotplug handler on PowerPC. The generic crash hotplug handler is introduced by https://lkml.org/lkml/2023/4/4/1136 patch series.
Git tree for testing:
=====================
The below git tree has this patch series applied on top of dependent patch series.
https://github.com/sourabhjains/linux/tree/e21-s10
To realise the feature the kdump udev rule must updated to avoid reloading of kdump reload on CPU/Memory hotplug/online/offline events.
RHEL: /usr/lib/udev/rules.d/98-kexec.rules
-SUBSYSTEM=="cpu", ACTION=="online", GOTO="kdump_reload_cpu"
-SUBSYSTEM=="memory", ACTION=="online", GOTO="kdump_reload_mem"
-SUBSYSTEM=="memory", ACTION=="offline", GOTO="kdump_reload_mem"
+SUBSYSTEM=="cpu", ATTRS{crash_hotplug}=="1", GOTO="kdump_reload_end"
+SUBSYSTEM=="memory", ATTRS{crash_hotplug}=="1", GOTO="kdump_reload_end"Note: only kexec_file_load syscall will work. For kexec_load minor changes are required in kexec tool.
---
Changelog:
v10:
- Drop the patch that adds fdt_index attribute to struct kimage_arch Find the fdt segment index when needed.
- Added more details into commits messages.
- Rebased onto 6.3.0-rc5
v9:
- Removed patch to prepare elfcorehdr crash notes for possible CPUs. The patch is moved to generic patch series that introduces generic infrastructure for in kernel crash update.
- Removed patch to pass the hotplug action type to the arch crash hotplug handler function. The generic patch series has introduced the hotplug action type in kimage struct.
- Add detail commit message for better understanding.
v8:
- Restrict fdt_index initialization to machine_kexec_post_load it work for both kexec_load and kexec_file_load.[3/8] Laurent Dufour
- Updated the logic to find the number of offline core. [6/8]
- Changed the logic to find the elfcore program header to accommodate future memory ranges due memory hotplug events. [8/8]
v7
- added a new config to configure this feature
- pass hotplug action type to arch specific handler
v6
- Added crash memory hotplug support
v5:
- Replace COFNIG_CRASH_HOTPLUG with CONFIG_HOTPLUG_CPU.
- Move fdt segment identification for kexec_load case to load path instead of crash hotplug handler
- Keep new attribute defined under kimage_arch to track FDT segment under CONFIG_HOTPLUG_CPU config.
v4:
- Update the logic to find the additional space needed for hotadd CPUs post kexec load. Refer "[RFC v4 PATCH 4/5] powerpc/crash hp: add crash hotplug support for kexec_file_load" patch to know more about the change.
- Fix a couple of typo.
- Replace pr_err to pr_info_once to warn user about memory hotplug support.
- In crash hotplug handle exit the for loop if FDT segment is found.
v3
- Move fdt_index and fdt_index_vaild variables to kimage_arch struct.
- Rebase patche on top of https://lkml.org/lkml/2022/3/3/674 [v5]
- Fixed warning reported by checpatch script
v2:
- Use generic hotplug handler introduced by https://lkml.org/lkml/2022/2/9/1406, a significant change from v1.
Sourabh Jain (5):
powerpc/kexec: turn some static helper functions public powerpc/crash: introduce a new config option CRASH_HOTPLUG powerpc/crash: add crash CPU hotplug support
crash: forward memory_notify args to arch crash hotplug handler powerpc/kexec: add crash memory hotplug support
arch/powerpc/Kconfig | 12 + arch/powerpc/include/asm/kexec.h | 10 + arch/powerpc/include/asm/kexec_ranges.h | 1 + arch/powerpc/kexec/core_64.c | 301 ++++++++++++++++++++++++ arch/powerpc/kexec/elf_64.c | 12 +- arch/powerpc/kexec/file_load_64.c | 212 ++++------------- arch/powerpc/kexec/ranges.c | 85 +++++++ arch/x86/include/asm/kexec.h | 2 +- arch/x86/kernel/crash.c | 3 +- include/linux/kexec.h | 2 +- kernel/crash_core.c | 14 +- 11 files changed, 479 insertions(+), 175 deletions(-)
Signature · 7 lines
2.39.2 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v10 1/5 powerpc/kexec: turn some static helper functions public
Move update_cpus_node and get_crash_memory_ranges functions from kexec/file_load_64.c to kexec/core_64.c to make these functions usable by other kexec components.
Later in the series, these functions are utilized to do in-kernel update to kexec segments on CPU/Memory hot plug/unplug or online/offline events for both kexec_load and kexec_file_load syscalls.
No functional change intended.
--- arch/powerpc/include/asm/kexec.h | 6 ++ arch/powerpc/kexec/core_64.c | 166 ++++++++++++++++++++++++++++++ arch/powerpc/kexec/file_load_64.c | 162 ----------------------------- 3 files changed, 172 insertions(+), 162 deletions(-)
arch/powerpc/include/asm/kexec.h +6 -0
@@ -99,6 +99,12 @@ void relocate_new_kernel(unsigned long indirection_page, unsigned long reboot_covoid kexec_copy_flush (struct kimage *image); +#ifdef CONFIG_PPC64 +struct crash_mem ; +int update_cpus_node (void *fdt); +int get_crash_memory_ranges (struct crash_mem **mem_ranges); +#endif +#if defined(CONFIG_CRASH_DUMP ) && defined(CONFIG_PPC_RTAS )void crash_free_reserved_phys_range (unsigned long begin,unsigned long end);#define crash_free_reserved_phys_range crash_free_reserved_phys_range
arch/powerpc/kexec/core_64.c +166 -0
184 lines not on this page · raw message
arch/powerpc/kexec/file_load_64.c +0 -162
174 lines not on this page · raw message
Signature · 7 lines
2.39.2 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v10 2/5 powerpc/crash: introduce a new config option CRASH_HOTPLUG
In reply to Sourabh JainDue to CPU/Memory hot plug/unplug or online/offline events the system resources changes. A similar change should reflect in the loaded kdump kernel kexec segments that describes the state of the CPU and memory of the running kernel.
If the kdump kernel kexec segments are not updated after the CPU/Memory hot plug/unplug or online/offline events and kdump kernel tries to collect the dump with the stale system resource data then this might lead to dump collection failure or an inaccurate dump collection.
The current method to keep the kdump kernel kexec segments up to date is by reloading the complete kdump kernel whenever a CPU/Memory hot plug/unplug or online/offline event is observed in userspace. Reloading the kdump kernel for every CPU/Memory hot plug/unplug or online/offline event is inefficient and creates a large window where the kdump service is not available. It can be improved by doing in-kernel updates to only necessary kdump kernel kexec segments which describe CPU and Memory resources of the running kernel to the kdump kernel.
The kernel changes related to in-kernel updates to the kdump kernel kexec segments are kept under the CRASH_HOTPLUG config option.
Later in the series, a powerpc crash hotplug handler is introduced to update the kdump kernel kexec segments on CPU/Memory hotplug events. This arch-specific handler is triggered from a generic crash handler that registers with the CPU/Memory add/remove notifiers.
The CRASH_HOTPLUG config option is enabled by default.
--- arch/powerpc/Kconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+)
arch/powerpc/Kconfig +12 -0
@@ -681,6 +681,18 @@ config CRASH_DUMP The same kernel binary can be used as production kernel and dump capture kernel. +config CRASH_HOTPLUG + bool "In-kernel update to kdump kernel on system configuration changes" + default y + depends on CRASH_DUMP && (HOTPLUG_CPU || MEMORY_HOTPLUG) + help + Quick and efficient mechanism to update the kdump kernel in the + event of CPU/Memory hot plug/unplug or online/offline events. This + approach does the in-kernel update to only necessary kexec segment + instead of unload-reload entire kdump kernel from userspace. + + If unsure, say Y. + config FA_DUMP bool "Firmware-assisted dump" depends on PPC64 && (PPC_RTAS || PPC_POWERNV)
Signature · 7 lines
2.39.2 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v10 2/5] powerpc/crash: introduce a new config option CRASH_HOTPLUG
Quoted 27 lines · Sourabh Jain
Due to CPU/Memory hot plug/unplug or online/offline events the system resources changes. A similar change should reflect in the loaded kdump kernel kexec segments that describes the state of the CPU and memory of the running kernel.
If the kdump kernel kexec segments are not updated after the CPU/Memory hot plug/unplug or online/offline events and kdump kernel tries to collect the dump with the stale system resource data then this might lead to dump collection failure or an inaccurate dump collection.
The current method to keep the kdump kernel kexec segments up to date is by reloading the complete kdump kernel whenever a CPU/Memory hot plug/unplug or online/offline event is observed in userspace. Reloading the kdump kernel for every CPU/Memory hot plug/unplug or online/offline event is inefficient and creates a large window where the kdump service is not available. It can be improved by doing in-kernel updates to only necessary kdump kernel kexec segments which describe CPU and Memory resources of the running kernel to the kdump kernel.
The kernel changes related to in-kernel updates to the kdump kernel kexec segments are kept under the
CRASH_HOTPLUGconfig option.Later in the series, a powerpc crash hotplug handler is introduced to update the kdump kernel kexec segments on CPU/Memory hotplug events. This arch-specific handler is triggered from a generic crash handler that registers with the CPU/Memory add/remove notifiers.
Quoted 4 lines
The
CRASH_HOTPLUGconfig option is enabled by default.Signed-off-by Sourabh Jain <[email protected]>Reviewed-by Laurent Dufour <[email protected]>
I can't remember having sent a review-by on that patch earlier.
Anyway, I can't find any issue with that one, so replace with:
Quoted 17 lines
--- arch/powerpc/Kconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+)arch/powerpc/Kconfig +5
-0@@ -681,6 +681,18 @@ config CRASH_DUMP The same kernel binary can be used as production kernel and dump capture kernel. +config CRASH_HOTPLUG + bool "In-kernel update to kdump kernel on system configuration changes" + default y + depends on CRASH_DUMP && (HOTPLUG_CPU || MEMORY_HOTPLUG) + help
arch/powerpc/Kconfig config CRASH_DUMP · line 698
Quoted 10 lines
arch/powerpc/Kconfig +7
-0+ Quick and efficient mechanism to update the kdump kernel in the + event of CPU/Memory hot plug/unplug or online/offline events. This + approach does the in-kernel update to only necessary kexec segment + instead of unload-reload entire kdump kernel from userspace. + + If unsure, say Y. + config FA_DUMP bool "Firmware-assisted dump" depends on PPC64 && (PPC_RTAS || PPC_POWERNV)
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v10 2/5] powerpc/crash: introduce a new config option CRASH_HOTPLUG
Quoted 28 lines · Laurent Dufour
Quoted 27 lines · Sourabh Jain
Due to CPU/Memory hot plug/unplug or online/offline events the system resources changes. A similar change should reflect in the loaded kdump kernel kexec segments that describes the state of the CPU and memory of the running kernel.
If the kdump kernel kexec segments are not updated after the CPU/Memory hot plug/unplug or online/offline events and kdump kernel tries to collect the dump with the stale system resource data then this might lead to dump collection failure or an inaccurate dump collection.
The current method to keep the kdump kernel kexec segments up to date is by reloading the complete kdump kernel whenever a CPU/Memory hot plug/unplug or online/offline event is observed in userspace. Reloading the kdump kernel for every CPU/Memory hot plug/unplug or online/offline event is inefficient and creates a large window where the kdump service is not available. It can be improved by doing in-kernel updates to only necessary kdump kernel kexec segments which describe CPU and Memory resources of the running kernel to the kdump kernel.
The kernel changes related to in-kernel updates to the kdump kernel kexec segments are kept under the
CRASH_HOTPLUGconfig option.Later in the series, a powerpc crash hotplug handler is introduced to update the kdump kernel kexec segments on CPU/Memory hotplug events. This arch-specific handler is triggered from a generic crash handler that registers with the CPU/Memory add/remove notifiers.
Quoted 8 lines
Quoted 4 lines
The
CRASH_HOTPLUGconfig option is enabled by default.Signed-off-by Sourabh Jain <[email protected]>Reviewed-by Laurent Dufour <[email protected]>I can't remember having sent a review-by on that patch earlier.
Anyway, I can't find any issue with that one, so replace with:
Reviewed-by Laurent Dufour <[email protected]>
I apologies for mistakenly applying the "Reviewed-by" tag to the entire patch series, when it was intended for only one patch. I will remove the tag in next version.
- Sourabh Jain
PATCH v10 3/5 powerpc/crash: add crash CPU hotplug support
In reply to Sourabh JainIntroduce powerpc crash hotplug handler to update the necessary kexec segments in the kernel on CPU/Memory hotplug events. Currently, these updates are done by monitoring CPU/Memory hotplug events in userspace.
A common crash hotplug handler is triggered from generic infrastructure for both CPU/Memory hotplug events. But in this patch, crash updates are handled only for CPU hotplug events. Support for the crash update on memory hotplug events is added in upcoming patches.
The elfcorehdr segment is used to exchange the CPU and other dump-related information between the kernels. Ideally, the elfcorehdr segment needs to be recreated on CPU hotplug events to reflect the changes. But on powerpc, the elfcorehdr is built with possible CPUs hence there is no need to update/recreate the elfcorehdr on CPU hotplug events.
In addition to elfcorehdr, there is another kexec segment that holds CPU data on powerpc is FDT (Flattened Device Tree). During the kdump kernel boot, it is expected that the crashing CPU must be present in FDT, else kdump kernel boot fails.
Now the only action needed on powerpc to handle the crash CPU hotplug event is to add hot added CPUs in the kdump FDT segment to avoid kdump kernel boot failure. So for the CPU hot add event, the FDT segment is updated with hot added CPU and Since there is no need to remove the hot unplugged CPUs from the FDT segment hence no action was taken for CPU hot remove event.
To accommodate a growing number of CPUs, FDT is built with additional buffer space to ensure that it can hold possible CPU nodes.
The changes done here will also work for the kexec_load system call given that the kexec tool builds the FDT segment with additional space to accommodate possible CPU nodes.
Since memory crash hotplug support is not there yet the crash hotplug the handler simply warns the user and returns.
--- arch/powerpc/include/asm/kexec.h | 4 ++ arch/powerpc/kexec/core_64.c | 61 +++++++++++++++++++++++++++++++ arch/powerpc/kexec/elf_64.c | 12 +++++- arch/powerpc/kexec/file_load_64.c | 14 +++++++ 4 files changed, 90 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/kexec.h +4 -0
@@ -103,6 +103,10 @@ void kexec_copy_flush(struct kimage *image);struct crash_mem ;int update_cpus_node (void *fdt);int get_crash_memory_ranges (struct crash_mem **mem_ranges); +#if defined(CONFIG_CRASH_HOTPLUG ) +void arch_crash_handle_hotplug_event (struct kimage *image); +#define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event +#endif #endif #if defined(CONFIG_CRASH_DUMP ) && defined(CONFIG_PPC_RTAS )
arch/powerpc/kexec/core_64.c +61 -0
67 lines not on this page · raw message
arch/powerpc/kexec/elf_64.c +11 -1
@@ -30,6 +30,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf, unsigned long cmdline_len) {int ret; +bool do_pack_fdt = true;unsigned long kernel_load_addr;unsigned long initrd_load_addr =0 , fdt_load_addr;void *fdt;
@@ -116,7 +117,16 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,if (ret) goto out_free_fdt; -fdt_pack (fdt); +#if defined(CONFIG_CRASH_HOTPLUG ) +/* +* Do not pack FDT, additional space is reserved to accommodate +* possible CPU nodes which are not yet present in the system. +*/ +if (image->type ==KEXEC_TYPE_CRASH ) + do_pack_fdt = false; +#endif +if (do_pack_fdt) +fdt_pack (fdt); kbuf.buffer = fdt; kbuf.bufsz = kbuf.memsz =fdt_totalsize (fdt);
arch/powerpc/kexec/file_load_64.c +14 -0
@@ -908,6 +908,9 @@ unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image)unsigned int cpu_nodes, extra_size =0 ;struct device_node *dn;u64 usm_entries; +#if defined(CONFIG_CRASH_HOTPLUG ) +unsigned int possible_cpu_nodes; +#endif // Budget some space for the password blob. There's already extra space // for the key name
@@ -940,6 +943,17 @@ unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image)if (cpu_nodes > boot_cpu_node_count) extra_size += (cpu_nodes - boot_cpu_node_count) *cpu_node_size (); +#if defined(CONFIG_CRASH_HOTPLUG ) +/* +* Make sure enough space is reserved to accommodate possible CPU nodes +* in the crash FDT. This allows packing possible CPU nodes which are +* not yet present in the system without regenerating the entire FDT. +*/ + possible_cpu_nodes =num_possible_cpus () / threads_per_core; +if (image->type ==KEXEC_TYPE_CRASH && possible_cpu_nodes > cpu_nodes) + extra_size += (possible_cpu_nodes - cpu_nodes) *cpu_node_size (); +#endif +return extra_size; }
Signature · 7 lines
2.39.2 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v10 3/5] powerpc/crash: add crash CPU hotplug support
Quoted 35 lines · Sourabh Jain
Introduce powerpc crash hotplug handler to update the necessary kexec segments in the kernel on CPU/Memory hotplug events. Currently, these updates are done by monitoring CPU/Memory hotplug events in userspace.
A common crash hotplug handler is triggered from generic infrastructure for both CPU/Memory hotplug events. But in this patch, crash updates are handled only for CPU hotplug events. Support for the crash update on memory hotplug events is added in upcoming patches.
The elfcorehdr segment is used to exchange the CPU and other dump-related information between the kernels. Ideally, the elfcorehdr segment needs to be recreated on CPU hotplug events to reflect the changes. But on powerpc, the elfcorehdr is built with possible CPUs hence there is no need to update/recreate the elfcorehdr on CPU hotplug events.
In addition to elfcorehdr, there is another kexec segment that holds CPU data on powerpc is FDT (Flattened Device Tree). During the kdump kernel boot, it is expected that the crashing CPU must be present in FDT, else kdump kernel boot fails.
Now the only action needed on powerpc to handle the crash CPU hotplug event is to add hot added CPUs in the kdump FDT segment to avoid kdump kernel boot failure. So for the CPU hot add event, the FDT segment is updated with hot added CPU and Since there is no need to remove the hot unplugged CPUs from the FDT segment hence no action was taken for CPU hot remove event.
To accommodate a growing number of CPUs, FDT is built with additional buffer space to ensure that it can hold possible CPU nodes.
The changes done here will also work for the
kexec_loadsystem call given that the kexec tool builds the FDT segment with additional space to accommodate possible CPU nodes.
Quoted 5 lines
Since memory crash hotplug support is not there yet the crash hotplug the handler simply warns the user and returns.
Signed-off-by Sourabh Jain <[email protected]>Reviewed-by Laurent Dufour <[email protected]
I don't remember sending a review-by on this patch earlier, do you?
Quoted 146 lines
--- arch/powerpc/include/asm/kexec.h | 4 ++ arch/powerpc/kexec/core_64.c | 61 +++++++++++++++++++++++++++++++ arch/powerpc/kexec/elf_64.c | 12 +++++- arch/powerpc/kexec/file_load_64.c | 14 +++++++ 4 files changed, 90 insertions(+), 1 deletion(-)arch/powerpc/include/asm/kexec.h +4
-0@@ -103,6 +103,10 @@ void kexec_copy_flush(struct kimage *image);struct crash_mem ;int update_cpus_node (void *fdt);int get_crash_memory_ranges (struct crash_mem **mem_ranges); +#if defined(CONFIG_CRASH_HOTPLUG ) +void arch_crash_handle_hotplug_event (struct kimage *image); +#define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event +#endif #endif #if defined(CONFIG_CRASH_DUMP ) && defined(CONFIG_PPC_RTAS )arch/powerpc/kexec/core_64.c +61
-0@@ -543,6 +543,67 @@ int update_cpus_node(void *fdt)return ret; } +#if defined(CONFIG_CRASH_HOTPLUG ) +#undef pr_fmt +#define pr_fmt (fmt) "crash hp: " fmt + +/** +* arch_crash_hotplug_handler() - Handle crash CPU/Memory hotplug events to update the +* necessary kexec segments based on the hotplug event. +* @image: the active struct kimage +* +* Update FDT segment to include newly added CPU. No action for CPU remove case. +*/ +void arch_crash_handle_hotplug_event (struct kimage *image) +{ +void *fdt, *ptr; +unsigned long mem; +int i, fdt_index =-1 ; +unsigned int hp_action = image->hp_action; + +/* +* Since the hot-unplugged CPU is already part of crash FDT, +* no action is needed for CPU remove case. +*/ +if (hp_action ==KEXEC_CRASH_HP_REMOVE_CPU ) +return ; + +/* crash update on memory hotplug events is not supported yet */ +if (hp_action ==KEXEC_CRASH_HP_REMOVE_MEMORY || hp_action ==KEXEC_CRASH_HP_ADD_MEMORY ) { +pr_info_once ("Crash update is not supported for memory hotplug\n" ); +return ; + } + +/* Find the FDT segment index in kexec segment array. */ +for (i =0 ; i < image->nr_segments; i++) { + mem = image->segment[i].mem; + ptr =__va (mem); + +if (ptr &&fdt_magic (ptr) ==FDT_MAGIC ) { + fdt_index = i; +break ; + } + } + +if (fdt_index <0 ) { +pr_err ("Unable to locate FDT segment.\n" ); +return ; + } + + fdt =__va ((void *)image->segment[fdt_index].mem); + +/* Temporarily invalidate the crash image while it is replaced */ +xchg (&kexec_crash_image,NULL ); + +/* update FDT to refelect changes in CPU resrouces */ +if (update_cpus_node (fdt)) +pr_err ("Failed to update crash FDT" ); + +/* The crash image is now valid once again */ +xchg (&kexec_crash_image, image); +} +#endif +#ifdef CONFIG_PPC_64S_HASH_MMU /* Values we need to export to the second kernel via the device tree. */ static unsigned long htab_base;arch/powerpc/kexec/elf_64.c +11
-1@@ -30,6 +30,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf, unsigned long cmdline_len) {int ret; +bool do_pack_fdt = true;unsigned long kernel_load_addr;unsigned long initrd_load_addr =0 , fdt_load_addr;void *fdt;@@ -116,7 +117,16 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,if (ret) goto out_free_fdt; -fdt_pack (fdt); +#if defined(CONFIG_CRASH_HOTPLUG ) +/* +* Do not pack FDT, additional space is reserved to accommodate +* possible CPU nodes which are not yet present in the system. +*/ +if (image->type ==KEXEC_TYPE_CRASH ) + do_pack_fdt = false; +#endif +if (do_pack_fdt) +fdt_pack (fdt); kbuf.buffer = fdt; kbuf.bufsz = kbuf.memsz =fdt_totalsize (fdt);arch/powerpc/kexec/file_load_64.c +7
-0@@ -908,6 +908,9 @@ unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image)unsigned int cpu_nodes, extra_size =0 ;struct device_node *dn;u64 usm_entries; +#if defined(CONFIG_CRASH_HOTPLUG ) +unsigned int possible_cpu_nodes; +#endif // Budget some space for the password blob. There's already extra space // for the key name @@ -940,6 +943,17 @@ unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image)if (cpu_nodes > boot_cpu_node_count) extra_size += (cpu_nodes - boot_cpu_node_count) *cpu_node_size (); +#if defined(CONFIG_CRASH_HOTPLUG ) +/* +* Make sure enough space is reserved to accommodate possible CPU nodes +* in the crash FDT. This allows packing possible CPU nodes which are
arch/powerpc/kexec/file_load_64.c unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image) · line 959
Quoted 10 lines
arch/powerpc/kexec/file_load_64.c +7
-0+* not yet present in the system without regenerating the entire FDT. +*/ + possible_cpu_nodes =num_possible_cpus () / threads_per_core; +if (image->type ==KEXEC_TYPE_CRASH && possible_cpu_nodes > cpu_nodes) + extra_size += (possible_cpu_nodes - cpu_nodes) *cpu_node_size (); +#endif +return extra_size; }
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH v10 4/5 crash: forward memory_notify args to arch crash hotplug handler
In reply to Sourabh JainOn PowePC memblock regions are used to prepare elfcorehdr which describes the memory regions of the running kernel to the kdump kernel. Since the notifier used for the memory hotplug crash handler gets initiated before the update of the memblock region happens (as depicted below) the newly prepared elfcorehdr still holds the old memory regions. If the elfcorehdr is prepared with stale memblock regions then the newly prepared elfcorehdr will still be holding stale memory regions. And dump collection with stale elfcorehdr will lead to dump collection failure or incomplete dump collection.
The sequence of actions done on PowerPC when an LMB memory hot removed:
Initiate memory hot remove
|
v
offline pages
|
v
initiate memory notify call
chain for MEM_OFFLINE event <---> Prepare new elfcorehdr and replace
it with old one
|
vupdate memblock regions
Such challenges only exist for memory remove case. For the memory add case the memory regions are updated first and then memory notify calls the arch crash hotplug handler to update the elfcorehdr.
This patch passes additional information about the hot removed LMB to the arch crash hotplug handler in the form of memory_notify object.
How passing memory_notify to arch crash hotplug handler will help?
memory_notify holds the start PFN and page count of the hot removed memory. With that base address and the size of the hot removed memory can be calculated and same can be used to avoid adding hot removed memory region to get added in the elfcorehdr.
--- arch/powerpc/include/asm/kexec.h | 2 +- arch/powerpc/kexec/core_64.c | 3 ++- arch/x86/include/asm/kexec.h | 2 +- arch/x86/kernel/crash.c | 3 ++- include/linux/kexec.h | 2 +- kernel/crash_core.c | 14 +++++++------- 6 files changed, 14 insertions(+), 12 deletions(-)
arch/powerpc/include/asm/kexec.h +1 -1
@@ -104,7 +104,7 @@ struct crash_mem;int update_cpus_node (void *fdt);int get_crash_memory_ranges (struct crash_mem **mem_ranges);#if defined(CONFIG_CRASH_HOTPLUG ) -void arch_crash_handle_hotplug_event (struct kimage *image); +void arch_crash_handle_hotplug_event (struct kimage *image,void *arg);#define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event#endif #endif
arch/powerpc/kexec/core_64.c +2 -1
@@ -551,10 +551,11 @@ int update_cpus_node(void *fdt)* arch_crash_hotplug_handler() - Handle crash CPU/Memory hotplug events to update the * necessary kexec segments based on the hotplug event. * @image: the active struct kimage +* @arg: struct memory_notify handler for memory add/remove case and NULL for CPU case. * * Update FDT segment to include newly added CPU. No action for CPU remove case. */ -void arch_crash_handle_hotplug_event (struct kimage *image) +void arch_crash_handle_hotplug_event (struct kimage *image,void *arg) {void *fdt, *ptr;unsigned long mem;
arch/x86/include/asm/kexec.h +1 -1
@@ -213,7 +213,7 @@ extern crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss;extern void kdump_nmi_shootdown_cpus (void );#ifdef CONFIG_CRASH_HOTPLUG -void arch_crash_handle_hotplug_event (struct kimage *image); +void arch_crash_handle_hotplug_event (struct kimage *image,void *arg);#define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event#ifdef CONFIG_HOTPLUG_CPU
arch/x86/kernel/crash.c +2 -1
@@ -445,11 +445,12 @@ int crash_load_segments(struct kimage *image)/** * arch_crash_handle_hotplug_event() - Handle hotplug elfcorehdr changes * @image: the active struct kimage +* @arg: struct memory_notify handler for memory add/remove case and NULL for CPU case. * * The new elfcorehdr is prepared in a kernel buffer, and then it is * written on top of the existing/old elfcorehdr. */ -void arch_crash_handle_hotplug_event (struct kimage *image) +void arch_crash_handle_hotplug_event (struct kimage *image,void *arg) {void *elfbuf =NULL , *old_elfcorehdr;unsigned long nr_mem_ranges;
include/linux/kexec.h +1 -1
@@ -506,7 +506,7 @@ static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) {#endif #ifndef arch_crash_handle_hotplug_event -static inline void arch_crash_handle_hotplug_event (struct kimage *image) { } +static inline void arch_crash_handle_hotplug_event (struct kimage *image,void *arg) { }#endif #ifndef crash_hotplug_cpu_support
kernel/crash_core.c +7 -7
@@ -718,7 +718,7 @@ subsys_initcall(crash_save_vmcoreinfo_init);* list of segments it checks (since the elfcorehdr changes and thus * would require an update to purgatory itself to update the digest). */ -static void crash_handle_hotplug_event (unsigned int hp_action,unsigned int cpu) +static void crash_handle_hotplug_event (unsigned int hp_action,unsigned int cpu,void *arg) {struct kimage *image;
@@ -775,7 +775,7 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu) image->hp_action = hp_action;/* Now invoke arch-specific update handler */ -arch_crash_handle_hotplug_event (image); +arch_crash_handle_hotplug_event (image, arg);/* No longer handling a hotplug event */ image->hp_action =KEXEC_CRASH_HP_NONE ;
@@ -789,17 +789,17 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu)kexec_unlock (); } -static int crash_memhp_notifier (struct notifier_block *nb,unsigned long val,void *v) +static int crash_memhp_notifier (struct notifier_block *nb,unsigned long val,void *arg) {switch (val) {case MEM_ONLINE :crash_handle_hotplug_event (KEXEC_CRASH_HP_ADD_MEMORY , -KEXEC_CRASH_HP_INVALID_CPU ); +KEXEC_CRASH_HP_INVALID_CPU , arg);break ;case MEM_OFFLINE :crash_handle_hotplug_event (KEXEC_CRASH_HP_REMOVE_MEMORY , -KEXEC_CRASH_HP_INVALID_CPU ); +KEXEC_CRASH_HP_INVALID_CPU , arg);break ; }return NOTIFY_OK ;
@@ -812,13 +812,13 @@ static struct notifier_block crash_memhp_nb = {static int crash_cpuhp_online (unsigned int cpu) { -crash_handle_hotplug_event (KEXEC_CRASH_HP_ADD_CPU , cpu); +crash_handle_hotplug_event (KEXEC_CRASH_HP_ADD_CPU , cpu,NULL );return 0 ; }static int crash_cpuhp_offline (unsigned int cpu) { -crash_handle_hotplug_event (KEXEC_CRASH_HP_REMOVE_CPU , cpu); +crash_handle_hotplug_event (KEXEC_CRASH_HP_REMOVE_CPU , cpu,NULL );return 0 ; }
Signature · 7 lines
2.39.2 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v10 4/5] crash: forward memory_notify args to arch crash hotplug handler
Quoted 34 lines · Sourabh Jain
On PowePC memblock regions are used to prepare elfcorehdr which describes the memory regions of the running kernel to the kdump kernel. Since the notifier used for the memory hotplug crash handler gets initiated before the update of the memblock region happens (as depicted below) the newly prepared elfcorehdr still holds the old memory regions. If the elfcorehdr is prepared with stale memblock regions then the newly prepared elfcorehdr will still be holding stale memory regions. And dump collection with stale elfcorehdr will lead to dump collection failure or incomplete dump collection.
The sequence of actions done on PowerPC when an LMB memory hot removed:
Initiate memory hot remove
| v offline pages | v initiate memory notify call chain for MEM_OFFLINE event <---> Prepare new elfcorehdr and replace it with old one | vupdate memblock regions
Such challenges only exist for memory remove case. For the memory add case the memory regions are updated first and then memory notify calls the arch crash hotplug handler to update the elfcorehdr.
This patch passes additional information about the hot removed LMB to the arch crash hotplug handler in the form of
memory_notifyobject.How passing
memory_notifyto arch crash hotplug handler will help?
Quoted 7 lines
memory_notifyholds the start PFN and page count of the hot removed memory. With that base address and the size of the hot removed memory can be calculated and same can be used to avoid adding hot removed memory region to get added in the elfcorehdr.Signed-off-by Sourabh Jain <[email protected]>Reviewed-by Laurent Dufour <[email protected]>
I don't remember sending a review-by on this patch earlier, do you?
Quoted 132 lines
--- arch/powerpc/include/asm/kexec.h | 2 +- arch/powerpc/kexec/core_64.c | 3 ++- arch/x86/include/asm/kexec.h | 2 +- arch/x86/kernel/crash.c | 3 ++- include/linux/kexec.h | 2 +- kernel/crash_core.c | 14 +++++++------- 6 files changed, 14 insertions(+), 12 deletions(-)arch/powerpc/include/asm/kexec.h +1
-1@@ -104,7 +104,7 @@ struct crash_mem;int update_cpus_node (void *fdt);int get_crash_memory_ranges (struct crash_mem **mem_ranges);#if defined(CONFIG_CRASH_HOTPLUG ) -void arch_crash_handle_hotplug_event (struct kimage *image); +void arch_crash_handle_hotplug_event (struct kimage *image,void *arg);#define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event#endif #endif arch/powerpc/kexec/core_64.c +2
-1@@ -551,10 +551,11 @@ int update_cpus_node(void *fdt)* arch_crash_hotplug_handler() - Handle crash CPU/Memory hotplug events to update the * necessary kexec segments based on the hotplug event. * @image: the active struct kimage +* @arg: struct memory_notify handler for memory add/remove case and NULL for CPU case. * * Update FDT segment to include newly added CPU. No action for CPU remove case. */ -void arch_crash_handle_hotplug_event (struct kimage *image) +void arch_crash_handle_hotplug_event (struct kimage *image,void *arg) {void *fdt, *ptr;unsigned long mem;arch/x86/include/asm/kexec.h +1
-1@@ -213,7 +213,7 @@ extern crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss;extern void kdump_nmi_shootdown_cpus (void );#ifdef CONFIG_CRASH_HOTPLUG -void arch_crash_handle_hotplug_event (struct kimage *image); +void arch_crash_handle_hotplug_event (struct kimage *image,void *arg);#define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event#ifdef CONFIG_HOTPLUG_CPU arch/x86/kernel/crash.c +2
-1@@ -445,11 +445,12 @@ int crash_load_segments(struct kimage *image)/** * arch_crash_handle_hotplug_event() - Handle hotplug elfcorehdr changes * @image: the active struct kimage +* @arg: struct memory_notify handler for memory add/remove case and NULL for CPU case. * * The new elfcorehdr is prepared in a kernel buffer, and then it is * written on top of the existing/old elfcorehdr. */ -void arch_crash_handle_hotplug_event (struct kimage *image) +void arch_crash_handle_hotplug_event (struct kimage *image,void *arg) {void *elfbuf =NULL , *old_elfcorehdr;unsigned long nr_mem_ranges;include/linux/kexec.h +1
-1@@ -506,7 +506,7 @@ static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) {#endif #ifndef arch_crash_handle_hotplug_event -static inline void arch_crash_handle_hotplug_event (struct kimage *image) { } +static inline void arch_crash_handle_hotplug_event (struct kimage *image,void *arg) { }#endif #ifndef crash_hotplug_cpu_supportkernel/crash_core.c +6
-6@@ -718,7 +718,7 @@ subsys_initcall(crash_save_vmcoreinfo_init);* list of segments it checks (since the elfcorehdr changes and thus * would require an update to purgatory itself to update the digest). */ -static void crash_handle_hotplug_event (unsigned int hp_action,unsigned int cpu) +static void crash_handle_hotplug_event (unsigned int hp_action,unsigned int cpu,void *arg) {struct kimage *image;@@ -775,7 +775,7 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu) image->hp_action = hp_action;/* Now invoke arch-specific update handler */ -arch_crash_handle_hotplug_event (image); +arch_crash_handle_hotplug_event (image, arg);/* No longer handling a hotplug event */ image->hp_action =KEXEC_CRASH_HP_NONE ;@@ -789,17 +789,17 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu)kexec_unlock (); } -static int crash_memhp_notifier (struct notifier_block *nb,unsigned long val,void *v) +static int crash_memhp_notifier (struct notifier_block *nb,unsigned long val,void *arg) {switch (val) {case MEM_ONLINE :crash_handle_hotplug_event (KEXEC_CRASH_HP_ADD_MEMORY , -KEXEC_CRASH_HP_INVALID_CPU ); +KEXEC_CRASH_HP_INVALID_CPU , arg);break ;case MEM_OFFLINE :crash_handle_hotplug_event (KEXEC_CRASH_HP_REMOVE_MEMORY , -KEXEC_CRASH_HP_INVALID_CPU ); +KEXEC_CRASH_HP_INVALID_CPU , arg);break ; }return NOTIFY_OK ;@@ -812,13 +812,13 @@ static struct notifier_block crash_memhp_nb = {static int crash_cpuhp_online (unsigned int cpu) { -crash_handle_hotplug_event (KEXEC_CRASH_HP_ADD_CPU , cpu); +crash_handle_hotplug_event (KEXEC_CRASH_HP_ADD_CPU , cpu,NULL );
kernel/crash_core.c static struct notifier_block crash_memhp_nb = { · line 824
Quoted 10 lines
kernel/crash_core.c +1
-1return 0 ; }static int crash_cpuhp_offline (unsigned int cpu) { -crash_handle_hotplug_event (KEXEC_CRASH_HP_REMOVE_CPU , cpu); +crash_handle_hotplug_event (KEXEC_CRASH_HP_REMOVE_CPU , cpu,NULL );return 0 ; }
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v10 4/5] crash: forward memory_notify args to arch crash hotplug handler
In reply to Sourabh JainQuoted 1 line · Sourabh Jain
On PowePC memblock regions are used to prepare elfcorehdr which
s/PowePC/PowerPC/
Quoted 67 lines
describes the memory regions of the running kernel to the kdump kernel. Since the notifier used for the memory hotplug crash handler gets initiated before the update of the memblock region happens (as depicted below) the newly prepared elfcorehdr still holds the old memory regions. If the elfcorehdr is prepared with stale memblock regions then the newly prepared elfcorehdr will still be holding stale memory regions. And dump collection with stale elfcorehdr will lead to dump collection failure or incomplete dump collection.
The sequence of actions done on PowerPC when an LMB memory hot removed:
Initiate memory hot remove
| v offline pages | v initiate memory notify call chain for MEM_OFFLINE event <---> Prepare new elfcorehdr and replace it with old one | vupdate memblock regions
Such challenges only exist for memory remove case. For the memory add case the memory regions are updated first and then memory notify calls the arch crash hotplug handler to update the elfcorehdr.
This patch passes additional information about the hot removed LMB to the arch crash hotplug handler in the form of
memory_notifyobject.How passing
memory_notifyto arch crash hotplug handler will help?
memory_notifyholds the start PFN and page count of the hot removed memory. With that base address and the size of the hot removed memory can be calculated and same can be used to avoid adding hot removed memory region to get added in the elfcorehdr.Signed-off-by Sourabh Jain <[email protected]>Reviewed-by Laurent Dufour <[email protected]>--- arch/powerpc/include/asm/kexec.h | 2 +- arch/powerpc/kexec/core_64.c | 3 ++- arch/x86/include/asm/kexec.h | 2 +- arch/x86/kernel/crash.c | 3 ++- include/linux/kexec.h | 2 +- kernel/crash_core.c | 14 +++++++------- 6 files changed, 14 insertions(+), 12 deletions(-)arch/powerpc/include/asm/kexec.h +1
-1@@ -104,7 +104,7 @@ struct crash_mem;int update_cpus_node (void *fdt);int get_crash_memory_ranges (struct crash_mem **mem_ranges);#if defined(CONFIG_CRASH_HOTPLUG ) -void arch_crash_handle_hotplug_event (struct kimage *image); +void arch_crash_handle_hotplug_event (struct kimage *image,void *arg);#define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event#endif #endif arch/powerpc/kexec/core_64.c +0
-0
arch/powerpc/kexec/core_64.c int update_cpus_node(void *fdt) · line 552
Quoted 2 lines
arch/powerpc/kexec/core_64.c +0
-0@@ -551,10 +551,11 @@ int update_cpus_node(void *fdt)* arch_crash_hotplug_handler() - Handle crash CPU/Memory hotplug events to update the * necessary kexec segments based on the hotplug event.
s/arch/crash_hotplug_handler/arch_crash_handle_hotplug_event/
Quoted 103 lines
arch/powerpc/kexec/core_64.c +2
-1* @image: the active struct kimage +* @arg: struct memory_notify handler for memory add/remove case and NULL for CPU case. * * Update FDT segment to include newly added CPU. No action for CPU remove case. */ -void arch_crash_handle_hotplug_event (struct kimage *image) +void arch_crash_handle_hotplug_event (struct kimage *image,void *arg) {void *fdt, *ptr;unsigned long mem;arch/x86/include/asm/kexec.h +1
-1@@ -213,7 +213,7 @@ extern crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss;extern void kdump_nmi_shootdown_cpus (void );#ifdef CONFIG_CRASH_HOTPLUG -void arch_crash_handle_hotplug_event (struct kimage *image); +void arch_crash_handle_hotplug_event (struct kimage *image,void *arg);#define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event#ifdef CONFIG_HOTPLUG_CPU arch/x86/kernel/crash.c +2
-1@@ -445,11 +445,12 @@ int crash_load_segments(struct kimage *image)/** * arch_crash_handle_hotplug_event() - Handle hotplug elfcorehdr changes * @image: the active struct kimage +* @arg: struct memory_notify handler for memory add/remove case and NULL for CPU case. * * The new elfcorehdr is prepared in a kernel buffer, and then it is * written on top of the existing/old elfcorehdr. */ -void arch_crash_handle_hotplug_event (struct kimage *image) +void arch_crash_handle_hotplug_event (struct kimage *image,void *arg) {void *elfbuf =NULL , *old_elfcorehdr;unsigned long nr_mem_ranges;include/linux/kexec.h +1
-1@@ -506,7 +506,7 @@ static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) {#endif #ifndef arch_crash_handle_hotplug_event -static inline void arch_crash_handle_hotplug_event (struct kimage *image) { } +static inline void arch_crash_handle_hotplug_event (struct kimage *image,void *arg) { }#endif #ifndef crash_hotplug_cpu_supportkernel/crash_core.c +6
-6@@ -718,7 +718,7 @@ subsys_initcall(crash_save_vmcoreinfo_init);* list of segments it checks (since the elfcorehdr changes and thus * would require an update to purgatory itself to update the digest). */ -static void crash_handle_hotplug_event (unsigned int hp_action,unsigned int cpu) +static void crash_handle_hotplug_event (unsigned int hp_action,unsigned int cpu,void *arg) {struct kimage *image;@@ -775,7 +775,7 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu) image->hp_action = hp_action;/* Now invoke arch-specific update handler */ -arch_crash_handle_hotplug_event (image); +arch_crash_handle_hotplug_event (image, arg);/* No longer handling a hotplug event */ image->hp_action =KEXEC_CRASH_HP_NONE ;@@ -789,17 +789,17 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu)kexec_unlock (); } -static int crash_memhp_notifier (struct notifier_block *nb,unsigned long val,void *v) +static int crash_memhp_notifier (struct notifier_block *nb,unsigned long val,void *arg) {switch (val) {case MEM_ONLINE :crash_handle_hotplug_event (KEXEC_CRASH_HP_ADD_MEMORY , -KEXEC_CRASH_HP_INVALID_CPU ); +KEXEC_CRASH_HP_INVALID_CPU , arg);break ;case MEM_OFFLINE :crash_handle_hotplug_event (KEXEC_CRASH_HP_REMOVE_MEMORY , -KEXEC_CRASH_HP_INVALID_CPU ); +KEXEC_CRASH_HP_INVALID_CPU , arg);break ; }return NOTIFY_OK ;@@ -812,13 +812,13 @@ static struct notifier_block crash_memhp_nb = {static int crash_cpuhp_online (unsigned int cpu) { -crash_handle_hotplug_event (KEXEC_CRASH_HP_ADD_CPU , cpu); +crash_handle_hotplug_event (KEXEC_CRASH_HP_ADD_CPU , cpu,NULL );
kernel/crash_core.c static struct notifier_block crash_memhp_nb = { · line 824
Quoted 10 lines
kernel/crash_core.c +1
-1return 0 ; }static int crash_cpuhp_offline (unsigned int cpu) { -crash_handle_hotplug_event (KEXEC_CRASH_HP_REMOVE_CPU , cpu); +crash_handle_hotplug_event (KEXEC_CRASH_HP_REMOVE_CPU , cpu,NULL );return 0 ; }
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH v10 5/5 powerpc/kexec: add crash memory hotplug support
In reply to Sourabh JainExtend PowerPC arch crash hotplug handler to support memory hotplug events. Since elfcorehdr is used to exchange the memory info between the kernels hence it needs to be recreated to reflect the changes due to memory hotplug events.
The way memory hotplug events are handled on PowerPC and the notifier call chain used in generic code to trigger the arch crash handler, the process to recreate the elfcorehdr is different for memory add and remove case.
For memory remove case the memory change notifier call chain is triggered first and then memblock regions is updated. Whereas for the memory hot add case, memblock regions are updated before invoking the memory change notifier call chain.
On PowerPC, memblock regions list is used to prepare the elfcorehdr. In case of memory hot remove the memblock regions are updated after the arch crash hotplug handler is triggered, hence an additional step is taken to ensure that memory ranges used to prepare elfcorehdr do not include hot removed memory.
When memory is hot removed it possible that memory regions count may increase. So to accommodate a growing number of memory regions, the elfcorehdr kexec segment is built with additional buffer space.
The changes done here will also work for the kexec_load system call given that the kexec tool builds the elfcoredhr with additional space to accommodate future memory regions as it is done for kexec_file_load system call in the kernel.
--- arch/powerpc/include/asm/kexec_ranges.h | 1 + arch/powerpc/kexec/core_64.c | 77 +++++++++++++++++++++- arch/powerpc/kexec/file_load_64.c | 36 ++++++++++- arch/powerpc/kexec/ranges.c | 85 +++++++++++++++++++++++++ 4 files changed, 195 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/kexec_ranges.h +1 -0
@@ -7,6 +7,7 @@void sort_memory_ranges (struct crash_mem *mrngs,bool merge);struct crash_mem *realloc_mem_ranges (struct crash_mem **mem_ranges);int add_mem_range (struct crash_mem **mem_ranges,u64 base,u64 size); +int remove_mem_range (struct crash_mem **mem_ranges,u64 base,u64 size);int add_tce_mem_ranges (struct crash_mem **mem_ranges);int add_initrd_mem_range (struct crash_mem **mem_ranges);#ifdef CONFIG_PPC_64S_HASH_MMU
arch/powerpc/kexec/core_64.c +75 -2
108 lines not on this page · raw message
arch/powerpc/kexec/file_load_64.c +34 -2
@@ -21,6 +21,8 @@#include <linux/memblock.h> #include <linux/slab.h> #include <linux/vmalloc.h> +#include <linux/elf.h> +#include <asm/setup.h> #include <asm/drmem.h> #include <asm/firmware.h>
@@ -707,6 +709,30 @@ static void update_backup_region_phdr(struct kimage *image, Elf64_Ehdr *ehdr) } } +/* get_max_phdr - Find the total number of Phdr needed to represent the +* max memory in the kdump elfcorehdr. +* +* @cmem: crash memory ranges in the system. +*/ +static int get_max_phdr (struct crash_mem *cmem) +{ +int max_lmb; + +/* In the worst case, a Phdr is needed for every other LMB to be represented +* as an individual crash range. +*/ + max_lmb =memory_hotplug_max () /2 *drmem_lmb_size (); + +/* Do not cross the Phdr max limit of the elf header. +* Avoid counting Phdr for crash ranges (cmem->nr_ranges) which +* are already part of elfcorehdr. +*/ +if (max_lmb >PN_XNUM ) +return PN_XNUM - cmem->nr_ranges; + +return max_lmb - cmem->nr_ranges; +} +/** * load_elfcorehdr_segment - Setup crash memory ranges and initialize elfcorehdr * segment needed to load kdump kernel.
@@ -738,7 +764,13 @@ static int load_elfcorehdr_segment(struct kimage *image, struct kexec_buf *kbuf) kbuf->buffer = headers; kbuf->mem =KEXEC_BUF_MEM_UNKNOWN ; - kbuf->bufsz = kbuf->memsz = headers_sz; + kbuf->bufsz = headers_sz; +/* Additional buffer space to accommodate future memory ranges */ +#if defined(CONFIG_MEMORY_HOTPLUG ) + kbuf->memsz = headers_sz +get_max_phdr (cmem) *sizeof (Elf64_Phdr); +#else + kbuf->memsz = headers_sz; +#endif kbuf->top_down = false; ret =kexec_add_buffer (kbuf);
@@ -748,7 +780,7 @@ static int load_elfcorehdr_segment(struct kimage *image, struct kexec_buf *kbuf) } image->elf_load_addr = kbuf->mem; - image->elf_headers_sz = headers_sz; + image->elf_headers_sz = kbuf->memsz; image->elf_headers = headers; out:kfree (cmem);
arch/powerpc/kexec/ranges.c +85 -0
91 lines not on this page · raw message
Signature · 7 lines
2.39.2 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v10 5/5] powerpc/kexec: add crash memory hotplug support
Quoted 25 lines · Sourabh Jain
Extend PowerPC arch crash hotplug handler to support memory hotplug events. Since elfcorehdr is used to exchange the memory info between the kernels hence it needs to be recreated to reflect the changes due to memory hotplug events.
The way memory hotplug events are handled on PowerPC and the notifier call chain used in generic code to trigger the arch crash handler, the process to recreate the elfcorehdr is different for memory add and remove case.
For memory remove case the memory change notifier call chain is triggered first and then memblock regions is updated. Whereas for the memory hot add case, memblock regions are updated before invoking the memory change notifier call chain.
On PowerPC, memblock regions list is used to prepare the elfcorehdr. In case of memory hot remove the memblock regions are updated after the arch crash hotplug handler is triggered, hence an additional step is taken to ensure that memory ranges used to prepare elfcorehdr do not include hot removed memory.
When memory is hot removed it possible that memory regions count may increase. So to accommodate a growing number of memory regions, the elfcorehdr kexec segment is built with additional buffer space.
Quoted 7 lines
The changes done here will also work for the
kexec_loadsystem call given that the kexec tool builds the elfcoredhr with additional space to accommodate future memory regions as it is done forkexec_file_loadsystem call in the kernel.Signed-off-by Sourabh Jain <[email protected]>Reviewed-by Laurent Dufour <[email protected]>
I don't remember sending a review-by on this patch earlier, do you?
Quoted 289 lines
--- arch/powerpc/include/asm/kexec_ranges.h | 1 + arch/powerpc/kexec/core_64.c | 77 +++++++++++++++++++++- arch/powerpc/kexec/file_load_64.c | 36 ++++++++++- arch/powerpc/kexec/ranges.c | 85 +++++++++++++++++++++++++ 4 files changed, 195 insertions(+), 4 deletions(-)arch/powerpc/include/asm/kexec_ranges.h +1
-0@@ -7,6 +7,7 @@void sort_memory_ranges (struct crash_mem *mrngs,bool merge);struct crash_mem *realloc_mem_ranges (struct crash_mem **mem_ranges);int add_mem_range (struct crash_mem **mem_ranges,u64 base,u64 size); +int remove_mem_range (struct crash_mem **mem_ranges,u64 base,u64 size);int add_tce_mem_ranges (struct crash_mem **mem_ranges);int add_initrd_mem_range (struct crash_mem **mem_ranges);#ifdef CONFIG_PPC_64S_HASH_MMU arch/powerpc/kexec/core_64.c +75
-2@@ -19,6 +19,7 @@#include <linux/of.h> #include <linux/libfdt.h> #include <linux/memblock.h> +#include <linux/memory.h> #include <asm/page.h> #include <asm/current.h> @@ -547,6 +548,76 @@ int update_cpus_node(void *fdt)#undef pr_fmt#define pr_fmt (fmt) "crash hp: " fmt +/** +* update_crash_elfcorehdr() - Recreate the elfcorehdr and replace it with old +* elfcorehdr in the kexec segment array. +* @image: the active struct kimage +* @arg: struct memory_notify data handler +*/ +static void update_crash_elfcorehdr (struct kimage *image,struct memory_notify *mn) +{ +int ret; +struct crash_mem *cmem =NULL ; +struct kexec_segment *ksegment; +void *ptr, *mem, *elfbuf =NULL ; +unsigned long elfsz, memsz, base_addr, size; + + ksegment = &image->segment[image->elfcorehdr_index]; + mem = (void *) ksegment->mem; + memsz = ksegment->memsz; + + ret =get_crash_memory_ranges (&cmem); +if (ret) { +pr_err ("Failed to get crash mem range\n" ); +return ; + } + +/* +* The hot unplugged memory is not yet removed from crash memory +* ranges, remove it here. +*/ +if (image->hp_action ==KEXEC_CRASH_HP_REMOVE_MEMORY ) { + base_addr =PFN_PHYS (mn->start_pfn); + size = mn->nr_pages *PAGE_SIZE ; + ret =remove_mem_range (&cmem, base_addr, size); +if (ret) { +pr_err ("Failed to remove hot-unplugged from crash memory ranges.\n" ); +return ; + } + } + + ret =crash_prepare_elf64_headers (cmem, false, &elfbuf, &elfsz); +if (ret) { +pr_err ("Failed to prepare elf header\n" ); +return ; + } + +/* +* It is unlikely that kernel hit this because elfcorehdr kexec +* segment (memsz) is built with addition space to accommodate growing +* number of crash memory ranges while loading the kdump kernel. It is +* Just to avoid any unforeseen case. +*/ +if (elfsz > memsz) { +pr_err ("Updated crash elfcorehdr elfsz %lu > memsz %lu" , elfsz, memsz); + goto out; + } + + ptr =__va (mem); +if (ptr) { +/* Temporarily invalidate the crash image while it is replaced */ +xchg (&kexec_crash_image,NULL ); + +/* Replace the old elfcorehdr with newly prepared elfcorehdr */ +memcpy ((void *)ptr, elfbuf, elfsz); + +/* The crash image is now valid once again */ +xchg (&kexec_crash_image, image); + } +out: +vfree (elfbuf); +} +/** * arch_crash_hotplug_handler() - Handle crash CPU/Memory hotplug events to update the * necessary kexec segments based on the hotplug event. @@ -554,12 +625,14 @@ int update_cpus_node(void *fdt)* @arg: struct memory_notify handler for memory add/remove case and NULL for CPU case. * * Update FDT segment to include newly added CPU. No action for CPU remove case. +* Recreate the elfcorehdr for Memory add/remove case and replace it with old one. */ void arch_crash_handle_hotplug_event (struct kimage *image,void *arg) {void *fdt, *ptr;unsigned long mem;int i, fdt_index =-1 ; +struct memory_notify *mn;unsigned int hp_action = image->hp_action;/* @@ -569,9 +642,9 @@ void arch_crash_handle_hotplug_event(struct kimage *image, void *arg)if (hp_action ==KEXEC_CRASH_HP_REMOVE_CPU )return ; -/* crash update on memory hotplug events is not supported yet */ if (hp_action ==KEXEC_CRASH_HP_REMOVE_MEMORY || hp_action ==KEXEC_CRASH_HP_ADD_MEMORY ) { -pr_info_once ("Crash update is not supported for memory hotplug\n" ); + mn = (struct memory_notify *) arg; +update_crash_elfcorehdr (image, mn);return ; }arch/powerpc/kexec/file_load_64.c +34
-2@@ -21,6 +21,8 @@#include <linux/memblock.h> #include <linux/slab.h> #include <linux/vmalloc.h> +#include <linux/elf.h> +#include <asm/setup.h> #include <asm/drmem.h> #include <asm/firmware.h> @@ -707,6 +709,30 @@ static void update_backup_region_phdr(struct kimage *image, Elf64_Ehdr *ehdr) } } +/* get_max_phdr - Find the total number of Phdr needed to represent the +* max memory in the kdump elfcorehdr. +* +* @cmem: crash memory ranges in the system. +*/ +static int get_max_phdr (struct crash_mem *cmem) +{ +int max_lmb; + +/* In the worst case, a Phdr is needed for every other LMB to be represented +* as an individual crash range. +*/ + max_lmb =memory_hotplug_max () /2 *drmem_lmb_size (); + +/* Do not cross the Phdr max limit of the elf header. +* Avoid counting Phdr for crash ranges (cmem->nr_ranges) which +* are already part of elfcorehdr. +*/ +if (max_lmb >PN_XNUM ) +return PN_XNUM - cmem->nr_ranges; + +return max_lmb - cmem->nr_ranges; +} +/** * load_elfcorehdr_segment - Setup crash memory ranges and initialize elfcorehdr * segment needed to load kdump kernel. @@ -738,7 +764,13 @@ static int load_elfcorehdr_segment(struct kimage *image, struct kexec_buf *kbuf) kbuf->buffer = headers; kbuf->mem =KEXEC_BUF_MEM_UNKNOWN ; - kbuf->bufsz = kbuf->memsz = headers_sz; + kbuf->bufsz = headers_sz; +/* Additional buffer space to accommodate future memory ranges */ +#if defined(CONFIG_MEMORY_HOTPLUG ) + kbuf->memsz = headers_sz +get_max_phdr (cmem) *sizeof (Elf64_Phdr); +#else + kbuf->memsz = headers_sz; +#endif kbuf->top_down = false; ret =kexec_add_buffer (kbuf);@@ -748,7 +780,7 @@ static int load_elfcorehdr_segment(struct kimage *image, struct kexec_buf *kbuf) } image->elf_load_addr = kbuf->mem; - image->elf_headers_sz = headers_sz; + image->elf_headers_sz = kbuf->memsz; image->elf_headers = headers; out:kfree (cmem);arch/powerpc/kexec/ranges.c +78
-0@@ -234,6 +234,91 @@ int add_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size)return __add_mem_range (mem_ranges, base, size); } +/** +* remove_mem_range - Removes the given memory range from the range list. +* @mem_ranges: Range list to remove the memory range to. +* @base: Base address of the range to remove. +* @size: Size of the memory range to remove. +* +* (Re)allocates memory, if needed. +* +* Returns 0 on success, negative errno on error. +*/ +int remove_mem_range (struct crash_mem **mem_ranges,u64 base,u64 size) +{ +u64 end; +int ret =0 ; +unsigned int i; +u64 mstart, mend; +struct crash_mem *mem_rngs = *mem_ranges; + +if (!size) +return 0 ; + +/* +* Memory range are stored as start and end address, use +* the same format to do remove operation. +*/ + end = base + size -1 ; + +for (i =0 ; i < mem_rngs->nr_ranges; i++) { + mstart = mem_rngs->ranges[i].start; + mend = mem_rngs->ranges[i].end; + +/* +* Memory range to remove is not part of this range entry +* in the memory range list +*/ +if (!(base >= mstart && end <= mend)) +continue ; + +/* +* Memory range to remove is equivalent to this entry in the +* memory range list. Remove the range entry from the list. +*/ +if (base == mstart && end == mend) { +for (; i < mem_rngs->nr_ranges -1 ; i++) { + mem_rngs->ranges[i].start = mem_rngs->ranges[i+1 ].start; + mem_rngs->ranges[i].end = mem_rngs->ranges[i+1 ].end; + } + mem_rngs->nr_ranges--; + goto out; + } +/* +* Start address of the memory range to remove and the +* current memory range entry in the list is same. Just +* move the start address of the current memory range +* entry in the list to end + 1. +*/ +else if (base == mstart) { + mem_rngs->ranges[i].start = end +1 ; + goto out; + } +/* +* End address of the memory range to remove and the +* current memory range entry in the list is same. +* Just move the end address of the current memory +* range entry in the list to base - 1. +*/ +else if (end == mend) { + mem_rngs->ranges[i].end = base -1 ; + goto out; + } +/* +* Memory range to remove is not at the edge of current +* memory range entry. Split the current memory entry into +* two half. +*/ +else { + mem_rngs->ranges[i].end = base -1 ; + size = mem_rngs->ranges[i].end - end;
arch/powerpc/kexec/ranges.c int add_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size) · line 324
Quoted 10 lines
arch/powerpc/kexec/ranges.c +7
-0+ ret =add_mem_range (mem_ranges, end +1 , size); + } + } +out: +return ret; +} +/** * add_tce_mem_ranges - Adds tce-table range to the given memory ranges list. * @mem_ranges: Range list to add the memory range(s) to.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 47 lines · Sourabh Jain
The Problem:
============
Post CPU/Memory hot plug/unplug and online/offline events the kernel holds stale information about the system. Dump collection with stale kdump kernel might end up in dump capture failure or an inaccurate dump collection.Existing solution:
==================
The existing solution to keep the kdump kernel up-to-date by monitoring CPU/Memory hotplug/online/offline events via udev rule and trigger a full kdump kernel reload for every hotplug event.Shortcomings:
------------------------------------------------
- Leaves a window where kernel crash might not lead to a successful dump collection.
- Reloading all kexec components for each hotplug is inefficient.
- udev rules are prone to races if hotplug events are frequent.More about issues with an existing solution is posted here:
- https://lkml.org/lkml/2020/12/14/532
- https://lists.ozlabs.org/pipermail/linuxppc-dev/2022-February/240254.htmlProposed Solution:
==================
Instead of reloading all kexec segments on CPU/Memory hotplug/online/offline event, this patch series focuses on updating only the relevant kexec segment. Once the kexec segments are loaded in the kernel reserved area then an arch-specific hotplug handler will update the relevant kexec segment based on hotplug event type.Series Dependencies
====================
This patch series implements the crash hotplug handler on PowerPC. The generic crash hotplug handler is introduced by https://lkml.org/lkml/2023/4/4/1136 patch series.Git tree for testing:
=====================
The below git tree has this patch series applied on top of dependent patch series.
https://github.com/sourabhjains/linux/tree/e21-s10To realise the feature the kdump udev rule must updated to avoid reloading of kdump reload on CPU/Memory hotplug/online/offline events.
Quoted 8 lines
RHEL: /usr/lib/udev/rules.d/98-kexec.rules
-SUBSYSTEM=="cpu", ACTION=="online", GOTO="kdump_reload_cpu"
-SUBSYSTEM=="memory", ACTION=="online", GOTO="kdump_reload_mem"
-SUBSYSTEM=="memory", ACTION=="offline", GOTO="kdump_reload_mem"
+SUBSYSTEM=="cpu", ATTRS{crash_hotplug}=="1", GOTO="kdump_reload_end"
+SUBSYSTEM=="memory", ATTRS{crash_hotplug}=="1", GOTO="kdump_reload_end"I didn't see in the patch series where you would have the equivalent to the following (needed for the sysfs crash_hotplug entries):
#ifdef CONFIG_HOTPLUG_CPU
static inline int crash_hotplug_cpu_support(void) { return 1; } #define crash_hotplug_cpu_support crash_hotplug_cpu_support #endif
#ifdef CONFIG_MEMORY_HOTPLUG
static inline int crash_hotplug_memory_support(void) { return 1; } #define crash_hotplug_memory_support crash_hotplug_memory_support #endif
Quoted 69 lines
Note: only
kexec_file_loadsyscall will work. Forkexec_loadminor changes are required in kexec tool.---
Changelog:v10:
- Drop the patch that addsfdt_indexattribute to structkimage_archFind the fdt segment index when needed.
- Added more details into commits messages.
- Rebased onto 6.3.0-rc5v9:
- Removed patch to prepare elfcorehdr crash notes for possible CPUs. The patch is moved to generic patch series that introduces generic infrastructure for in kernel crash update.
- Removed patch to pass the hotplug action type to the arch crash hotplug handler function. The generic patch series has introduced the hotplug action type in kimage struct.
- Add detail commit message for better understanding.v8:
- Restrictfdt_indexinitialization tomachine_kexec_post_loadit work for bothkexec_loadand kexec_file_load.[3/8] Laurent Dufour- Updated the logic to find the number of offline core. [6/8]
- Changed the logic to find the elfcore program header to accommodate future memory ranges due memory hotplug events. [8/8]
v7
- added a new config to configure this feature
- pass hotplug action type to arch specific handlerv6
- Added crash memory hotplug supportv5:
- ReplaceCOFNIG_CRASH_HOTPLUGwithCONFIG_HOTPLUG_CPU.
- Move fdt segment identification forkexec_loadcase to load path instead of crash hotplug handler
- Keep new attribute defined underkimage_archto track FDT segment underCONFIG_HOTPLUG_CPUconfig.v4:
- Update the logic to find the additional space needed for hotadd CPUs post kexec load. Refer "[RFC v4 PATCH 4/5] powerpc/crash hp: add crash hotplug support forkexec_file_load" patch to know more about the change.
- Fix a couple of typo.
- Replacepr_errtopr_info_onceto warn user about memory hotplug support.
- In crash hotplug handle exit the for loop if FDT segment is found.v3
- Movefdt_indexandfdt_index_vaildvariables tokimage_archstruct.
- Rebase patche on top of https://lkml.org/lkml/2022/3/3/674 [v5]
- Fixed warning reported by checpatch scriptv2:
- Use generic hotplug handler introduced by https://lkml.org/lkml/2022/2/9/1406, a significant change from v1.Sourabh Jain (5):
powerpc/kexec: turn some static helper functions public powerpc/crash: introduce a new config optionCRASH_HOTPLUGpowerpc/crash: add crash CPU hotplug support
crash: forwardmemory_notifyargs to arch crash hotplug handler powerpc/kexec: add crash memory hotplug support
Quoted 13 lines
arch/powerpc/Kconfig | 12 + arch/powerpc/include/asm/kexec.h | 10 + arch/powerpc/include/asm/kexec_ranges.h | 1 + arch/powerpc/kexec/core_64.c | 301 ++++++++++++++++++++++++ arch/powerpc/kexec/elf_64.c | 12 +- arch/powerpc/kexec/file_load_64.c | 212 ++++------------- arch/powerpc/kexec/ranges.c | 85 +++++++ arch/x86/include/asm/kexec.h | 2 +- arch/x86/kernel/crash.c | 3 +- include/linux/kexec.h | 2 +- kernel/crash_core.c | 14 +- 11 files changed, 479 insertions(+), 175 deletions(-)
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 66 lines · Eric DeVolder
Quoted 47 lines · Sourabh Jain
The Problem:
============
Post CPU/Memory hot plug/unplug and online/offline events the kernel holds stale information about the system. Dump collection with stale kdump kernel might end up in dump capture failure or an inaccurate dump collection.Existing solution:
==================
The existing solution to keep the kdump kernel up-to-date by monitoring CPU/Memory hotplug/online/offline events via udev rule and trigger a full kdump kernel reload for every hotplug event.Shortcomings:
------------------------------------------------
- Leaves a window where kernel crash might not lead to a successful dump collection.
- Reloading all kexec components for each hotplug is inefficient.
- udev rules are prone to races if hotplug events are frequent.More about issues with an existing solution is posted here:
- https://lkml.org/lkml/2020/12/14/532
- https://lists.ozlabs.org/pipermail/linuxppc-dev/2022-February/240254.htmlProposed Solution:
==================
Instead of reloading all kexec segments on CPU/Memory hotplug/online/offline event, this patch series focuses on updating only the relevant kexec segment. Once the kexec segments are loaded in the kernel reserved area then an arch-specific hotplug handler will update the relevant kexec segment based on hotplug event type.Series Dependencies
====================
This patch series implements the crash hotplug handler on PowerPC. The generic crash hotplug handler is introduced by https://lkml.org/lkml/2023/4/4/1136 patch series.Git tree for testing:
=====================
The below git tree has this patch series applied on top of dependent patch series.
https://github.com/sourabhjains/linux/tree/e21-s10To realise the feature the kdump udev rule must updated to avoid reloading of kdump reload on CPU/Memory hotplug/online/offline events.
Quoted 8 lines
RHEL:
/usr/lib/udev/rules.d/98-kexec.rules-SUBSYSTEM=="cpu", ACTION=="online", GOTO="kdump_reload_cpu" -SUBSYSTEM=="memory", ACTION=="online", GOTO="kdump_reload_mem" -SUBSYSTEM=="memory", ACTION=="offline", GOTO="kdump_reload_mem" +SUBSYSTEM=="cpu", ATTRS{crash_hotplug}=="1", GOTO="kdump_reload_end" +SUBSYSTEM=="memory", ATTRS{crash_hotplug}=="1", GOTO="kdump_reload_end"
I didn't see in the patch series where you would have the equivalent to the following (needed for the sysfs
crash_hotplugentries):#ifdef
CONFIG_HOTPLUG_CPU
static inline intcrash_hotplug_cpu_support(void){ return 1; } #definecrash_hotplug_cpu_supportcrash_hotplug_cpu_support#endif
Quoted 4 lines
#ifdef
CONFIG_MEMORY_HOTPLUG
static inline intcrash_hotplug_memory_support(void){ return 1; } #definecrash_hotplug_memory_supportcrash_hotplug_memory_support#endif
I missed the above diff in my testing environment. Thanks you for bringing it to my attention. I will fix this next version.
- Sourabh Jain
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec