In kernel handling of CPU hotplug events for crash kernel
Subsystems (3)
v5 cover In kernel handling of CPU hotplug events for crash kernel
This patch series implements the crash hotplug handler on PowerPC introduced by https://lkml.org/lkml/2022/6/13/3382 patch series.
The Problem:
============
Post hotplug/DLPAR events the capture kernel holds stale information about the system. Dump collection with stale capture kernel might end up in dump capture failure or an inaccurate dump collection.
Existing solution:
==================
The existing solution to keep the capture kernel up-to-date is observe the hotplug event via udev rule and trigger a full capture kernel reload post hotplug event.
Shortcomings:
------------------------------------------------
- Leaves a window where kernel crash might not lead to successful dump collection.
- Reloading all kexec components for each hotplug is inefficient. Since only one or two kexec components need to be updated due to hotplug event reloading all kexec component is redundant.
- 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 hotplug 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.
As mentioned above this patch series implemented a PowerPC crash hotplug handler for the CPU. The crash hotplug handler memory is in our TODO list.
A couple of minor changes are required to realize the benefit of the patch series:
- disalble the udev rule:
comment out the below line in kdump udev rule file:
RHEL: /usr/lib/udev/rules.d/98-kexec.rules
# SUBSYSTEM=="cpu", ACTION=="online", GOTO="kdump_reload_cpu"
- kexec tool needs to be updated with patch for kexec_load system call to work (not needed if -s option is used during kexec panic load):
---
kexec/arch/ppc64/kexec-elf-ppc64.c +31 -1
@@ -45,6 +45,29 @@ uint64_t initrd_base, initrd_size;unsigned char reuse_initrd =0 ;const char *ramdisk; +#define MAX_CORE 256 +#define PER_CORE_NODE_SIZE 1500 + +/** +* get_crash_fdt_mem_sz() - calcuate mem size for crash kernel FDT +* @fdt: pointer to crash kernel FDT +* +* Calculate the buffer space needed to add more CPU nodes in FDT after +* capture kenrel load due to hot add events. +* +* Some assumption are made to calculate the additional buffer size needed +* to accommodate future hot add CPUs to the crash FDT. The maximum core count +* in the system would not go beyond MAX_CORE and memory needed to store per core +* date in FDT is PER_CORE_NODE_SIZE. +* +* Certainly MAX_CORE count can be replaced with possible core count and +* PER_CORE_NODE_SIZE to some standard value instead of randomly observed +* core size value on Power9 LPAR. +*/ +static unsigned int get_crash_fdt_mem_sz (void *fdt) { +return fdt_totalsize (fdt) + (PER_CORE_NODE_SIZE *MAX_CORE ); +} +int elf_ppc64_probe (const char *buf,off_t len) {struct mem_ehdr ehdr;
@@ -179,6 +202,7 @@ int elf_ppc64_load(int argc, char **argv, const char *buf, off_t len,uint64_t max_addr, hole_addr;char *seg_buf =NULL ;off_t seg_size =0 ; +unsigned int mem_sz =0 ;struct mem_phdr *phdr;size_t size;#ifdef NEED_RESERVE_DTB
@@ -329,7 +353,13 @@ int elf_ppc64_load(int argc, char **argv, const char *buf, off_t len,if (result <0 )return result; - my_dt_offset =add_buffer (info, seg_buf, seg_size, seg_size, +if (info->kexec_flags &KEXEC_ON_CRASH ) { + mem_sz =get_crash_fdt_mem_sz ((void *)seg_buf); +fdt_set_totalsize (seg_buf, mem_sz); + info->fdt_index = info->nr_segments; + } + + my_dt_offset =add_buffer (info, seg_buf, seg_size, mem_sz,0 ,0 , max_addr,-1 );#ifdef NEED_RESERVE_DTB
kexec/kexec.c +3 -0
@@ -672,6 +672,9 @@ static void update_purgatory(struct kexec_info *info)if (info->segment[i].mem == (void *)info->rhdr.rel_addr) {continue ; } +if (info->fdt_index == i) +continue ; +sha256_update (&ctx, info->segment[i].buf, info->segment[i].bufsz); nullsz = info->segment[i].memsz - info->segment[i].bufsz;
kexec/kexec.h +4 -0
@@ -169,6 +169,7 @@ struct kexec_info {int command_line_len;int skip_checks; +// Given that we might need to update mutliple kexec segments +// then having array to keep indexes of all hotplug kexec segments +// will be helpful. +unsigned int fdt_index;
};
struct arch_map_entry {
---
---
Changelog:
v1 -> v2:
- Use generic hotplug handler introduced by https://lkml.org/lkml/2022/2/9/1406, a significant change from v1.
v2 -> 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
v3 -> 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.
v4 -> 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.
---
Sourabh Jain (5):
powerpc/kexec: make update_cpus_node non-static powerpc/crash hp: update kimage_arch struct powerpc/crash hp: add crash hotplug support for kexec_file_load powerpc/crash hp: add crash hotplug support for kexec_load powerpc/crash hp: add crash page helper functions
arch/powerpc/include/asm/kexec.h | 4 + arch/powerpc/kexec/core_64.c | 169 ++++++++++++++++++++++++++++++ arch/powerpc/kexec/elf_64.c | 74 +++++++++++++ arch/powerpc/kexec/file_load_64.c | 92 +--------------- 4 files changed, 252 insertions(+), 87 deletions(-)
Signature · 7 lines
2.36.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v5 1/5 powerpc/kexec: make update_cpus_node non-static
Make the update_cpus_node function non-static and export it for usage in other kexec components.
The update_cpus_node definition is moved to core_64.c so that it can be used with both kexec_load and kexec_file_load system calls.
No functional change intended.
--- arch/powerpc/include/asm/kexec.h | 1 + arch/powerpc/kexec/core_64.c | 88 +++++++++++++++++++++++++++++++ arch/powerpc/kexec/file_load_64.c | 87 ------------------------------ 3 files changed, 89 insertions(+), 87 deletions(-)
arch/powerpc/include/asm/kexec.h +1 -0
@@ -129,6 +129,7 @@ unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image);int setup_new_fdt_ppc64 (const struct kimage *image,void *fdt,unsigned long initrd_load_addr,unsigned long initrd_len,const char *cmdline); +int update_cpus_node (void *fdt);#endif /* CONFIG_PPC64 */ #endif /* CONFIG_KEXEC_FILE */
arch/powerpc/kexec/core_64.c +88 -0
100 lines not on this page · raw message
arch/powerpc/kexec/file_load_64.c +0 -87
93 lines not on this page · raw message
Signature · 7 lines
2.36.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v5 1/5] powerpc/kexec: make update_cpus_node non-static
Quoted 7 lines · Sourabh Jain
Make the
update_cpus_nodefunction non-static and export it for usage in other kexec components.The
update_cpus_nodedefinition is moved tocore_64.cso that it can be used with bothkexec_loadandkexec_file_loadsystem calls.No functional change intended.
And FWIW
Quoted 214 lines
Signed-off-by Sourabh Jain <[email protected]>--- arch/powerpc/include/asm/kexec.h | 1 + arch/powerpc/kexec/core_64.c | 88 +++++++++++++++++++++++++++++++ arch/powerpc/kexec/file_load_64.c | 87 ------------------------------ 3 files changed, 89 insertions(+), 87 deletions(-)arch/powerpc/include/asm/kexec.h +1
-0@@ -129,6 +129,7 @@ unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image);int setup_new_fdt_ppc64 (const struct kimage *image,void *fdt,unsigned long initrd_load_addr,unsigned long initrd_len,const char *cmdline); +int update_cpus_node (void *fdt);#endif /* CONFIG_PPC64 */ #endif /* CONFIG_KEXEC_FILE */ arch/powerpc/kexec/core_64.c +88
-0@@ -16,6 +16,7 @@#include <linux/kernel.h> #include <linux/cpu.h> #include <linux/hardirq.h> +#include <linux/libfdt.h> #include <asm/page.h> #include <asm/current.h> @@ -377,6 +378,93 @@ void default_machine_kexec(struct kimage *image)/* NOTREACHED */ } +/** +* add_node_props - Reads node properties from device node structure and add +* them to fdt. +* @fdt: Flattened device tree of the kernel +* @node_offset: offset of the node to add a property at +* @dn: device node pointer +* +* Returns 0 on success, negative errno on error. +*/ +static int add_node_props (void *fdt,int node_offset,const struct device_node *dn) +{ +int ret =0 ; +struct property *pp; + +if (!dn) +return -EINVAL ; + +for_each_property_of_node (dn, pp) { + ret =fdt_setprop (fdt, node_offset, pp->name, pp->value, pp->length); +if (ret <0 ) { +pr_err ("Unable to add %s property: %s\n" , pp->name,fdt_strerror (ret)); +return ret; + } + } +return ret; +} + +/** +* update_cpus_node - Update cpus node of flattened device tree using of_root +* device node. +* @fdt: Flattened device tree of the kernel. +* +* Returns 0 on success, negative errno on error. +*/ +int update_cpus_node (void *fdt) +{ +struct device_node *cpus_node, *dn; +int cpus_offset, cpus_subnode_offset, ret =0 ; + + cpus_offset =fdt_path_offset (fdt,"/cpus" ); +if (cpus_offset <0 && cpus_offset != -FDT_ERR_NOTFOUND ) { +pr_err ("Malformed device tree: error reading /cpus node: %s\n" , +fdt_strerror (cpus_offset)); +return cpus_offset; + } + +if (cpus_offset >0 ) { + ret =fdt_del_node (fdt, cpus_offset); +if (ret <0 ) { +pr_err ("Error deleting /cpus node: %s\n" ,fdt_strerror (ret)); +return -EINVAL ; + } + } + +/* Add cpus node to fdt */ + cpus_offset =fdt_add_subnode (fdt,fdt_path_offset (fdt,"/" ),"cpus" ); +if (cpus_offset <0 ) { +pr_err ("Error creating /cpus node: %s\n" ,fdt_strerror (cpus_offset)); +return -EINVAL ; + } + +/* Add cpus node properties */ + cpus_node =of_find_node_by_path ("/cpus" ); + ret =add_node_props (fdt, cpus_offset, cpus_node); +of_node_put (cpus_node); +if (ret <0 ) +return ret; + +/* Loop through all subnodes of cpus and add them to fdt */ +for_each_node_by_type (dn,"cpu" ) { + cpus_subnode_offset =fdt_add_subnode (fdt, cpus_offset, dn->full_name); +if (cpus_subnode_offset <0 ) { +pr_err ("Unable to add %s subnode: %s\n" , dn->full_name, +fdt_strerror (cpus_subnode_offset)); + ret = cpus_subnode_offset; + goto out; + } + + ret =add_node_props (fdt, cpus_subnode_offset, dn); +if (ret <0 ) + goto out; + } +out: +of_node_put (dn); +return ret; +} +#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/file_load_64.c +0
-80@@ -951,93 +951,6 @@ unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image)return (unsigned int )(usm_entries *sizeof (u64)); } -/** -* add_node_props - Reads node properties from device node structure and add -* them to fdt. -* @fdt: Flattened device tree of the kernel -* @node_offset: offset of the node to add a property at -* @dn: device node pointer -* -* Returns 0 on success, negative errno on error. -*/ -static int add_node_props (void *fdt,int node_offset,const struct device_node *dn) -{ -int ret =0 ; -struct property *pp; - -if (!dn) -return -EINVAL ; - -for_each_property_of_node (dn, pp) { - ret =fdt_setprop (fdt, node_offset, pp->name, pp->value, pp->length); -if (ret <0 ) { -pr_err ("Unable to add %s property: %s\n" , pp->name,fdt_strerror (ret)); -return ret; - } - } -return ret; -} - -/** -* update_cpus_node - Update cpus node of flattened device tree using of_root -* device node. -* @fdt: Flattened device tree of the kernel. -* -* Returns 0 on success, negative errno on error. -*/ -static int update_cpus_node (void *fdt) -{ -struct device_node *cpus_node, *dn; -int cpus_offset, cpus_subnode_offset, ret =0 ; - - cpus_offset =fdt_path_offset (fdt,"/cpus" ); -if (cpus_offset <0 && cpus_offset != -FDT_ERR_NOTFOUND ) { -pr_err ("Malformed device tree: error reading /cpus node: %s\n" , -fdt_strerror (cpus_offset)); -return cpus_offset; - } - -if (cpus_offset >0 ) { - ret =fdt_del_node (fdt, cpus_offset); -if (ret <0 ) { -pr_err ("Error deleting /cpus node: %s\n" ,fdt_strerror (ret)); -return -EINVAL ; - } - } - -/* Add cpus node to fdt */ - cpus_offset =fdt_add_subnode (fdt,fdt_path_offset (fdt,"/" ),"cpus" ); -if (cpus_offset <0 ) { -pr_err ("Error creating /cpus node: %s\n" ,fdt_strerror (cpus_offset)); -return -EINVAL ; - } - -/* Add cpus node properties */ - cpus_node =of_find_node_by_path ("/cpus" ); - ret =add_node_props (fdt, cpus_offset, cpus_node); -of_node_put (cpus_node); -if (ret <0 ) -return ret; - -/* Loop through all subnodes of cpus and add them to fdt */ -for_each_node_by_type (dn,"cpu" ) { - cpus_subnode_offset =fdt_add_subnode (fdt, cpus_offset, dn->full_name); -if (cpus_subnode_offset <0 ) { -pr_err ("Unable to add %s subnode: %s\n" , dn->full_name, -fdt_strerror (cpus_subnode_offset)); - ret = cpus_subnode_offset; - goto out; - } - - ret =add_node_props (fdt, cpus_subnode_offset, dn); -if (ret <0 )
arch/powerpc/kexec/file_load_64.c unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image) · line 956
Quoted 10 lines
arch/powerpc/kexec/file_load_64.c +0
-7- goto out; - } -out: -of_node_put (dn); -return ret; -} -/** * setup_new_fdt_ppc64 - Update the flattend device-tree of the kernel * being loaded.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v5 1/5] powerpc/kexec: make update_cpus_node non-static
Quoted 10 lines · Laurent Dufour
Quoted 7 lines · Sourabh Jain
Make the
update_cpus_nodefunction non-static and export it for usage in other kexec components.The
update_cpus_nodedefinition is moved tocore_64.cso that it can be used with bothkexec_loadandkexec_file_loadsystem calls.No functional change intended.
And FWIW
Reviewed-by Laurent Dufour <[email protected]>
Thank you!
- Sourabh Jain
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH v5 2/5 powerpc/crash hp: update kimage_arch struct
In reply to Sourabh JainOnce the kimage is prepared the only way to identify which kexec segment holds FDT is by looping through all kexec segments. To avoid this a new member "fdt_index" is added to kimage_arch struct. The new member holds the index of FDT segment in the kexec segment array which gives direct access to FDT segment.
The fdt_index will be populated during kexec load for both kexec_load and kexec_file_load case.
--- arch/powerpc/include/asm/kexec.h | 3 +++ 1 file changed, 3 insertions(+)
arch/powerpc/include/asm/kexec.h +3 -0
@@ -106,6 +106,9 @@ extern const struct kexec_file_ops kexec_elf64_ops;struct kimage_arch {struct crash_mem *exclude_ranges; +#if defined(CONFIG_HOTPLUG_CPU ) +int fdt_index; +#endif unsigned long backup_start;void *backup_buf;void *fdt;
Signature · 7 lines
2.36.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v5 3/5 powerpc/crash hp: add crash hotplug support for kexec_file_load
In reply to Sourabh JainTwo major changes are done to enable the crash CPU hotplug handler. Firstly, updated the kexec load path to prepare kimage for hotplug changes, and secondly, implemented the arch specific crash hotplug handler.
On the kexec load path, the memsz allocation for the crash FDT segment is updated to ensure that it has sufficient buffer space to accommodate future hot add CPUs. Additionally, kimage_arch struct member fdt_index is initialized with the index of FDT segment in kexec segment array.
The crash hotplug handler updates the cpus node of crash FDT. While we update crash FDT the kexec_crash_image is marked invalid and restored after FDT update to avoid race.
Since memory crash hotplug support is not there yet the crash hotplug handler simply warns the user and returns.
--- arch/powerpc/kexec/core_64.c | 49 ++++++++++++++++++++ arch/powerpc/kexec/elf_64.c | 74 +++++++++++++++++++++++++++++++ arch/powerpc/kexec/file_load_64.c | 5 +++ 3 files changed, 128 insertions(+)
arch/powerpc/kexec/core_64.c +49 -0
@@ -465,6 +465,55 @@ int update_cpus_node(void *fdt)return ret; } +#if defined(CONFIG_HOTPLUG_CPU ) + +int crash_hotplug_support (void ) {return 1 ; } + +/** +* arch_crash_hotplug_handler() - Handle hotplug kexec segements changes FDT, elfcorehdr +* @image: the active struct kimage +* @hp_action: the hot un/plug action being handled +* @cpu: when KEXEC_CRASH_HP_ADD/REMOVE_CPU, the cpu affected +* +* To accurately reflect CPU hot un/plug changes, the FDT +* must be updated with the new list of CPUs. +*/ +void arch_crash_handle_hotplug_event (struct kimage *image, +unsigned int hp_action,unsigned int cpu) + +{ +void *fdt; + +/* No action needed for CPU hot-unplug */ +if (hp_action ==KEXEC_CRASH_HP_REMOVE_CPU ) +return ; + +/* crash update on memory hotplug is not support yet */ +if (hp_action ==KEXEC_CRASH_HP_REMOVE_MEMORY || hp_action ==KEXEC_CRASH_HP_ADD_MEMORY ) { +pr_info_once ("crash hp: crash update is not supported with memory hotplug\n" ); +return ; + } + +/* Must have valid FDT index */ +if (!image->arch.fdt_index <0 ) { +pr_err ("crash hp: unable to locate FDT segment" ); +return ; + } + + fdt =__va ((void *)image->segment[image->arch.fdt_index].mem); + +/* Temporarily invalidate the crash image while it is replaced */ +xchg (&kexec_crash_image,NULL ); + +/* update FDT to refelect changes to CPU resrouces */ +if (update_cpus_node (fdt)) +pr_err ("crash hp: 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 +74 -0
86 lines not on this page · raw message
arch/powerpc/kexec/file_load_64.c +5 -0
@@ -1116,6 +1116,11 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf,return ret; } +#if defined(CONFIG_HOTPLUG_CPU ) +/* Mark fdt_index invalid */ + image->arch.fdt_index =-1 ; +#endif +return kexec_image_probe_default (image, buf, buf_len); }
Signature · 7 lines
2.36.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v5 3/5] powerpc/crash hp: add crash hotplug support for kexec_file_load
Quoted 8 lines · Sourabh Jain
Two major changes are done to enable the crash CPU hotplug handler. Firstly, updated the kexec load path to prepare kimage for hotplug changes, and secondly, implemented the arch specific crash hotplug handler.
On the kexec load path, the memsz allocation for the crash FDT segment is updated to ensure that it has sufficient buffer space to accommodate future hot add CPUs. Additionally,
kimage_archstruct memberfdt_index
^
added ?Quoted 1 line
is initialized with the index of FDT segment in kexec segment array.
May be you should mention that the index of FDT segment is recorded to not fetch it at each hotplug operation.
Quoted 6 lines
The crash hotplug handler updates the cpus node of crash FDT. While we update crash FDT the
kexec_crash_imageis marked invalid and restored after FDT update to avoid race.Since memory crash hotplug support is not there yet the crash hotplug handler simply warns the user and returns.
It might be good to explain here why CPU hot remove operations are ignored.
Quoted 26 lines
Signed-off-by Sourabh Jain <[email protected]>--- arch/powerpc/kexec/core_64.c | 49 ++++++++++++++++++++ arch/powerpc/kexec/elf_64.c | 74 +++++++++++++++++++++++++++++++ arch/powerpc/kexec/file_load_64.c | 5 +++ 3 files changed, 128 insertions(+)arch/powerpc/kexec/core_64.c +10
-0@@ -465,6 +465,55 @@ int update_cpus_node(void *fdt)return ret; } +#if defined(CONFIG_HOTPLUG_CPU ) + +int crash_hotplug_support (void ) {return 1 ; } + +/** +* arch_crash_hotplug_handler() - Handle hotplug kexec segements changes FDT, elfcorehdr +* @image: the active struct kimage +* @hp_action: the hot un/plug action being handled +* @cpu: when KEXEC_CRASH_HP_ADD/REMOVE_CPU, the cpu affected +*
arch/powerpc/kexec/core_64.c int update_cpus_node(void *fdt) · line 487
Quoted 10 lines
arch/powerpc/kexec/core_64.c +10
-0+* To accurately reflect CPU hot un/plug changes, the FDT +* must be updated with the new list of CPUs. +*/ +void arch_crash_handle_hotplug_event (struct kimage *image, +unsigned int hp_action,unsigned int cpu) + +{ +void *fdt; + +/* No action needed for CPU hot-unplug */
Why?
I think your comment should explain why CPU hot-unplug operations are ignored?
arch/powerpc/kexec/core_64.c int update_cpus_node(void *fdt) · line 498
Quoted 11 lines
arch/powerpc/kexec/core_64.c +11
-0+if (hp_action ==KEXEC_CRASH_HP_REMOVE_CPU ) +return ; + +/* crash update on memory hotplug is not support yet */ +if (hp_action ==KEXEC_CRASH_HP_REMOVE_MEMORY || hp_action ==KEXEC_CRASH_HP_ADD_MEMORY ) { +pr_info_once ("crash hp: crash update is not supported with memory hotplug\n" ); +return ; + } + +/* Must have valid FDT index */ +if (!image->arch.fdt_index <0 ) {
if (image->arch.fdt_index >= 0) {I think this is easier to read.
Quoted 26 lines
arch/powerpc/kexec/core_64.c +18
-0+pr_err ("crash hp: unable to locate FDT segment" ); + return; + } + + fdt =__va ((void *)image->segment[image->arch.fdt_index].mem); + +/* Temporarily invalidate the crash image while it is replaced */ +xchg (&kexec_crash_image,NULL ); + +/* update FDT to refelect changes to CPU resrouces */ +if (update_cpus_node (fdt)) +pr_err ("crash hp: 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 +0
-0
arch/powerpc/kexec/elf_64.c line 28
Quoted 5 lines
arch/powerpc/kexec/elf_64.c +2
-0@@ -24,6 +24,68 @@#include <linux/slab.h> #include <linux/types.h> +#include <asm/kvm_book3s.h> +#include <asm/kvm_ppc.h>
Are these 2 KVM specifics headers really required?
arch/powerpc/kexec/elf_64.c line 38
Quoted 10 lines
arch/powerpc/kexec/elf_64.c +10
-0+ +#if defined(CONFIG_HOTPLUG_CPU ) +/** +* get_cpu_node_sz() - Calculate the space needed to store a CPU device +* type node in FDT. The calculation is done based on +* the existing CPU node in unflatten device tree. Loop +* through all the properties of the very first CPU type +* device node found in unflatten device tree and returns +* the sum of the property length and property string size +* of all properties of a CPU node.
This indentation style looks weird to me.
arch/powerpc/kexec/elf_64.c line 42
Quoted 4 lines
arch/powerpc/kexec/elf_64.c +4
-0+*/ +static int get_cpu_node_sz (void ) +{ +struct device_node *dn =NULL ;
There is no need to initialize dn here, it is assigned right after
arch/powerpc/kexec/elf_64.c line 50
Quoted 8 lines
arch/powerpc/kexec/elf_64.c +8
-0+struct property *pp; +int cpu_node_size =0 ; + + dn =of_find_node_by_type (NULL ,"cpu" ); + +if (!dn) { +pr_warn ("Unable to locate cpu device_type node.\n" ); + goto out;
You could return 0 here, and remove the initialization of cpu_node_size.
Quoted 4 lines
arch/powerpc/kexec/elf_64.c +4
-0+ } + +/* Every node in FDT starts with FDT_BEGIN_NODE and ends with +* FDT_END_NODE that takes one byte each.
arch/powerpc/kexec/elf_64.c line 64
Quoted 10 lines
arch/powerpc/kexec/elf_64.c +10
-0+*/ + cpu_node_size =2 ; + +for_each_property_of_node (dn, pp) { +/** +* For each property add two bytes extra. One for string null +* character for property name and other for FDT property start +* tag FDT_PROP. +*/ + cpu_node_size = cpu_node_size + pp->length +strlen (pp->name) +2 ;
cpu_node_size += pp->length + strlen(pp->name) + 2;
This shortens a bit that line.
Quoted 28 lines
arch/powerpc/kexec/elf_64.c +24
-0+ } + +out: +return cpu_node_size; +} + +/* +* get_crash_fdt_mem_sz() - calcuate mem size for crash kernel FDT +* @fdt: pointer to crash kernel FDT +* +* Calculate the buffer space needed to accommodate more CPU nodes in +* crash FDT post capture kernel load due to CPU hotplug events. +*/ +static unsigned int get_crash_fdt_mem_sz (void *fdt) +{ +int fdt_cpu_nodes_sz, offline_cpu_cnt; + + offline_cpu_cnt = (num_possible_cpus () -num_present_cpus ()) /MAX_SMT_THREADS ; + fdt_cpu_nodes_sz =get_cpu_node_sz () * offline_cpu_cnt; + +return fdt_totalsize (fdt) + fdt_cpu_nodes_sz; +} +#endif + static void *elf64_load(struct kimage *image, char *kernel_buf, unsigned long kernel_len, char *initrd, unsigned long initrd_len, char *cmdline,
arch/powerpc/kexec/elf_64.c static void *elf64_load(struct kimage *image, char *kernel_buf, · line 191
Quoted 7 lines
arch/powerpc/kexec/elf_64.c +4
-0@@ -123,6 +185,18 @@ static void *elf64_load(struct kimage *image, char *kernel_buf, kbuf.buf_align =PAGE_SIZE ; kbuf.top_down = true; kbuf.mem =KEXEC_BUF_MEM_UNKNOWN ; + +#if defined(CONFIG_HOTPLUG_CPU ) +if (image->type ==KEXEC_TYPE_CRASH ) { + kbuf.memsz =get_crash_fdt_mem_sz (fdt);
Why do you keep the previous assignment of kbuf.memsz few lines ago :
kbuf.buffer = fdt; kbuf.bufsz = kbuf.memsz = fdt_totalsize(fdt); <<<<< kbuf.buf_align = PAGE_SIZE; kbuf.top_down = true; kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
#if defined(CONFIG_HOTPLUG_CPU)
if (image->type == KEXEC_TYPE_CRASH) {
kbuf.memsz = get_crash_fdt_mem_sz(fdt);
fdt_set_totalsize(fdt, kbuf.memsz);
image->arch.fdt_index = image->nr_segments;
} else
#endif
{
kbuf.memsz = fdt_totalsize(fdt);
}And what about kbuf.bufsz?
arch/powerpc/kexec/elf_64.c static void *elf64_load(struct kimage *image, char *kernel_buf, · line 197
Quoted 6 lines
arch/powerpc/kexec/elf_64.c +6
-0+fdt_set_totalsize (fdt, kbuf.memsz); + image->arch.fdt_index = image->nr_segments; + } else +#endif + { + kbuf.memsz =fdt_totalsize (fdt);
Why not setting image->arch.fdt_index to -1 here?
Quoted 10 lines
arch/powerpc/kexec/elf_64.c +2
-0+ } + ret =kexec_add_buffer (&kbuf);if (ret) goto out_free_fdt;arch/powerpc/kexec/file_load_64.c +0
-0
arch/powerpc/kexec/file_load_64.c int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, · line 1121
Quoted 6 lines
arch/powerpc/kexec/file_load_64.c +3
-0@@ -1116,6 +1116,11 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf,return ret; } +#if defined(CONFIG_HOTPLUG_CPU ) +/* Mark fdt_index invalid */ + image->arch.fdt_index =-1 ;
Why doing this here instead of elf64_load()?
I think your patch only applies to the ELF image format, isn't it?
Cheers,
Laurent.
arch/powerpc/kexec/file_load_64.c int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, · line 1126
Quoted 5 lines
arch/powerpc/kexec/file_load_64.c +2
-0+#endif +return kexec_image_probe_default (image, buf, buf_len); }
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH v5 4/5 powerpc/crash hp: add crash hotplug support for kexec_load
In reply to Sourabh JainA common crash hotplug handler is used for both kexec_load and kexec_file_load, which is already implemented in earlier patches while adding support for kexec_file_load.
To enable the crash hotplug handler to work for kexec_load case the fdt_index attribute of kimage_arch needs to be populated with index of FDT segment in kexec segment array.
After loading kexec segments the FDT segment is identified by looping through all the kexec segments and fdt_index is updated accordingly.
--- arch/powerpc/kexec/core_64.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
arch/powerpc/kexec/core_64.c +25 -0
@@ -74,6 +74,31 @@ int machine_kexec_prepare(struct kimage *image)return 0 ; } +#if defined(CONFIG_HOTPLUG_CPU ) +int machine_kexec_post_load (struct kimage *kimage) +{ +int i; +void *ptr; +unsigned long mem; + +if (kimage->type !=KEXEC_TYPE_CRASH ) +return 0 ; + +/* Mark fdt_index invalid */ + kimage->arch.fdt_index =-1 ; + +for (i =0 ; i < kimage->nr_segments; i++) { + mem = kimage->segment[i].mem; + ptr =__va (mem); + +if (ptr &&fdt_magic (ptr) ==FDT_MAGIC ) + kimage->arch.fdt_index = i; + } + +return 0 ; +} +#endif +/* Called during kexec sequence with MMU off */ static notrace void copy_segments(unsigned long ind) {
Signature · 7 lines
2.36.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v5 4/5] powerpc/crash hp: add crash hotplug support for kexec_load
Quoted 26 lines · Sourabh Jain
A common crash hotplug handler is used for both
kexec_loadandkexec_file_load, which is already implemented in earlier patches while adding support forkexec_file_load.To enable the crash hotplug handler to work for
kexec_loadcase thefdt_indexattribute ofkimage_archneeds to be populated with index of FDT segment in kexec segment array.After loading kexec segments the FDT segment is identified by looping through all the kexec segments and
fdt_indexis updated accordingly.Signed-off-by Sourabh Jain <[email protected]>--- arch/powerpc/kexec/core_64.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)arch/powerpc/kexec/core_64.c +2
-0@@ -74,6 +74,31 @@ int machine_kexec_prepare(struct kimage *image)return 0 ; } +#if defined(CONFIG_HOTPLUG_CPU ) +int machine_kexec_post_load (struct kimage *kimage)
arch/powerpc/kexec/core_64.c int machine_kexec_prepare(struct kimage *image) · line 88
Quoted 10 lines
arch/powerpc/kexec/core_64.c +10
-0+{ +int i; +void *ptr; +unsigned long mem; + +if (kimage->type !=KEXEC_TYPE_CRASH ) +return 0 ; + +/* Mark fdt_index invalid */ + kimage->arch.fdt_index =-1 ;
If fdt_index should be set to -1, this should be done in machine_kexec_prepare(). Anyway, there is no need to set it to -1 because this image will not be registered in do_kexec_load() before the following loop is complete.
arch/powerpc/kexec/core_64.c int machine_kexec_prepare(struct kimage *image) · line 95
Quoted 7 lines
arch/powerpc/kexec/core_64.c +7
-0+ +for (i =0 ; i < kimage->nr_segments; i++) { + mem = kimage->segment[i].mem; + ptr =__va (mem); + +if (ptr &&fdt_magic (ptr) ==FDT_MAGIC ) + kimage->arch.fdt_index = i;
break;
there is no need to check the other segments, isn't it?
Cheers,
Laurent.
arch/powerpc/kexec/core_64.c int machine_kexec_prepare(struct kimage *image) · line 104
Quoted 9 lines
arch/powerpc/kexec/core_64.c +6
-0+ } + +return 0 ; +} +#endif +/* Called during kexec sequence with MMU off */ static notrace void copy_segments(unsigned long ind) {
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH v5 5/5 powerpc/crash hp: add crash page helper functions
In reply to Sourabh JainDefine arch_[un]map_crash_pages functions to avoid build issues due to undefined arch specific function to access crash memory pages.
A temporary patch to avoid build issues may need some changes in generic code to avoid this.
The issue is under discussion:
https://lkml.org/lkml/2022/6/20/22
--- arch/powerpc/kexec/core_64.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/powerpc/kexec/core_64.c +7 -0
@@ -492,6 +492,13 @@ int update_cpus_node(void *fdt)#if defined(CONFIG_HOTPLUG_CPU ) +void *arch_map_crash_pages (unsigned long paddr,unsigned long size) +{ +return __va (paddr); +} + +void arch_unmap_crash_pages (void **ptr) { } +int crash_hotplug_support (void ) {return 1 ; }/**
Signature · 7 lines
2.36.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v5 5/5] powerpc/crash hp: add crash page helper functions
Quoted 19 lines · Sourabh Jain
Define arch_[un]map_crash_pages functions to avoid build issues due to undefined arch specific function to access crash memory pages.
A temporary patch to avoid build issues may need some changes in generic code to avoid this.
The issue is under discussion:
https://lkml.org/lkml/2022/6/20/22Signed-off-by Sourabh Jain <[email protected]>--- arch/powerpc/kexec/core_64.c | 7 +++++++ 1 file changed, 7 insertions(+)arch/powerpc/kexec/core_64.c +0
-0
arch/powerpc/kexec/core_64.c int update_cpus_node(void *fdt) · line 498
Quoted 7 lines
arch/powerpc/kexec/core_64.c +4
-0@@ -492,6 +492,13 @@ int update_cpus_node(void *fdt)#if defined(CONFIG_HOTPLUG_CPU ) +void *arch_map_crash_pages (unsigned long paddr,unsigned long size) +{ +return __va (paddr); +}
Why not define this as an inline in the appropriate PowerPC header file?
arch/powerpc/kexec/core_64.c int update_cpus_node(void *fdt) · line 500
Quoted 2 lines
arch/powerpc/kexec/core_64.c +2
-0+ +void arch_unmap_crash_pages (void **ptr) { }
same here
arch/powerpc/kexec/core_64.c int update_cpus_node(void *fdt) · line 504
Quoted 4 lines
arch/powerpc/kexec/core_64.c +1
-0+int crash_hotplug_support (void ) {return 1 ; }/**
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec