powerpc/crash: Add only the onlined CPU's node to the crash FDT
Subsystems (5)
PATCH 1/1 powerpc/crash: Add only the onlined CPU's node to the crash FDT
A CPU coming online never changes the nodes that are already in the FDT, so add only the node of that CPU. update_crash_fdt() looks up the device node of the onlined CPU and does nothing if the FDT already has a node of that name, which is the case when an offlined CPU comes back online. Only when the node is missing, the crash image is invalidated while the node is created with fdt_add_subnode() and its properties are copied from the live device node with fdt_setprop(). All of this is done directly in update_crash_fdt().
fdt_add_subnode() inserts the node as the first child of /cpus, which is the same position a node attached to the live device tree takes, so the FDT keeps the order of the live tree.
--- arch/powerpc/kexec/crash.c | 65 +++++++++++++++++++++++++++++++------- arch/x86/kernel/crash.c | 2 +- kernel/crash_core.c | 11 +++++-- 3 files changed, 64 insertions(+), 14 deletions(-)
arch/powerpc/kexec/crash.c +54 -11
@@ -18,6 +18,7 @@#include <linux/types.h> #include <linux/libfdt.h> #include <linux/memory.h> +#include <linux/of.h> #include <asm/processor.h> #include <asm/machdep.h>
@@ -584,32 +585,71 @@ static int get_fdt_index(struct kimage *image) }/** -* update_crash_fdt - updates the cpus node of the crash FDT. +* update_crash_fdt - add the node of the onlined CPU to the crash FDT. * * @image: a pointer to kexec_crash_image +* @cpu: the CPU that was onlined +* +* The node is added as the first child of /cpus, the same position a node +* attached to the live device tree takes. Nothing is done if the FDT already +* has the node, for example when an offlined CPU comes back. */ -static void update_crash_fdt (struct kimage *image) +static void update_crash_fdt (struct kimage *image,unsigned int cpu) { +struct device_node *dn; +struct property *pp;void *fdt; -int fdt_index; +int fdt_index, cpus_offset, node_offset; + + dn =of_get_cpu_node (cpu,NULL ); +if (!dn) { +pr_err ("No device node found for CPU %u\n" , cpu); +return ; + } fdt_index =get_fdt_index (image);if (fdt_index <0 ) {pr_err ("Unable to locate FDT segment.\n" ); -return ; + goto put; } fdt =__va ((void *)image->segment[fdt_index].mem); -/* Temporarily invalidate the crash image while it is replaced */ + cpus_offset =fdt_path_offset (fdt,"/cpus" ); +if (cpus_offset <0 ) { +pr_err ("Malformed device tree: error reading /cpus node: %s\n" , +fdt_strerror (cpus_offset)); + goto put; + } + +/* Node already present, e.g. an offlined CPU came back online */ +if (fdt_subnode_offset (fdt, cpus_offset, dn->full_name) >=0 ) + goto put; + +/* Temporarily invalidate the crash image while it is updated */ xchg (&kexec_crash_image,NULL ); -/* update FDT to reflect changes in CPU resources */ -if (update_cpus_node (fdt)) -pr_err ("Failed to update crash FDT" ); + node_offset =fdt_add_subnode (fdt, cpus_offset, dn->full_name); +if (node_offset <0 ) { +pr_err ("Unable to add %s subnode: %s\n" , dn->full_name, +fdt_strerror (node_offset)); + goto out; + } +for_each_property_of_node (dn, pp) { +int 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)); +break ; + } + } +out:/* The crash image is now valid once again */ xchg (&kexec_crash_image, image); +put: +of_node_put (dn); }int arch_crash_hotplug_support (struct kimage *image,unsigned long kexec_flags)
@@ -625,10 +665,11 @@ int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags)* arch_crash_handle_hotplug_event - Handle crash CPU/Memory hotplug events to update the * necessary kexec segments based on the hotplug event. * @image: a pointer to kexec_crash_image -* @arg: struct memory_notify handler for memory hotplug case and NULL for CPU hotplug case. +* @arg: struct memory_notify handler for memory hotplug case and pointer to the +* cpu number for CPU hotplug case. * * Update the kdump image based on the type of hotplug event, represented by image->hp_action. -* CPU add: Update the FDT segment to include the newly added CPU. +* CPU add: Add the node of the newly added CPU to the FDT segment, if missing. * CPU remove: No action is needed, with the assumption that it's okay to have offline CPUs * part of the FDT. * Memory add/remove: No action is taken as this is not yet supported.
@@ -636,13 +677,15 @@ int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags)void arch_crash_handle_hotplug_event (struct kimage *image,void *arg) {struct memory_notify *mn; +unsigned int cpu;switch (image->hp_action) {case KEXEC_CRASH_HP_REMOVE_CPU :return ;case KEXEC_CRASH_HP_ADD_CPU : -update_crash_fdt (image); + cpu = *(unsigned int *)arg; +update_crash_fdt (image, cpu);break ;case KEXEC_CRASH_HP_REMOVE_MEMORY :
arch/x86/kernel/crash.c +1 -1
@@ -441,7 +441,7 @@ unsigned int arch_crash_get_elfcorehdr_size(void)* arch_crash_handle_hotplug_event() - Handle hotplug elfcorehdr changes * @image: a pointer to kexec_crash_image * @arg: struct memory_notify handler for memory hotplug case and -* NULL for CPU hotplug case. +* pointer to the cpu number (unused here) for CPU hotplug case. * * Prepare the new elfcorehdr and replace the existing elfcorehdr. */
kernel/crash_core.c +9 -2
@@ -651,6 +651,9 @@ int crash_check_hotplug_support(void)* NR_CPUS and CRASH_MAX_MEMORY_RANGES. The elfcorehdr is * excluded from SHA verification by default if the architecture * supports crash hotplug. +* +* @arg is a struct memory_notify pointer for memory hotplug events and a +* pointer to the unsigned int cpu number for CPU hotplug events. */ static void crash_handle_hotplug_event (unsigned int hp_action,unsigned int cpu,void *arg) {
@@ -676,10 +679,14 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu, goto out;if (hp_action ==KEXEC_CRASH_HP_ADD_CPU || - hp_action ==KEXEC_CRASH_HP_REMOVE_CPU ) + hp_action ==KEXEC_CRASH_HP_REMOVE_CPU ) {pr_debug ("hp_action %u, cpu %u\n" , hp_action, cpu); -else +/* CPU events are raised with no argument, the CPU number is passed instead */ +WARN_ON (arg); + arg = &cpu; + }else {pr_debug ("hp_action %u\n" , hp_action); + }/* * The elfcorehdr_index is set to -1 when the struct kimage
Signature · 1 line
2.54.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] powerpc/crash: detached DLPAR CPU nodes accumulate in crash FDT in update_crash_fdt() - [High]…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] powerpc/crash: detached DLPAR CPU nodes accumulate in crash FDT in update_crash_fdt()
- [High] powerpc/crash: incomplete CPU subnode left in FDT on fdt_setprop() failure in update_crash_fdt() --
commit f91f7035e04400925af984e21ed910579118bae0
Author: Vishal Chourasia <[email protected]>
powerpc/crash: Add only the onlined CPU's node to the crash FDT
This patch updates crash FDT handling on CPU online events to pass the onlined CPU number to arch_crash_handle_hotplug_event() and insert only that CPU's device node into the crash FDT if it is not already present, rather than rebuilding all CPU nodes via update_cpus_node().
Quoted 4 lines
arch/powerpc/kexec/crash.c +0
-0
[ ... ]
Quoted 47 lines
arch/powerpc/kexec/crash.c +25
-5@@ -584,32 +585,71 @@ static int get_fdt_index(struct kimage *image) }/** -* update_crash_fdt - updates the cpus node of the crash FDT. +* update_crash_fdt - add the node of the onlined CPU to the crash FDT. * * @image: a pointer to kexec_crash_image +* @cpu: the CPU that was onlined +* +* The node is added as the first child of /cpus, the same position a node +* attached to the live device tree takes. Nothing is done if the FDT already +* has the node, for example when an offlined CPU comes back. */ -static void update_crash_fdt (struct kimage *image) +static void update_crash_fdt (struct kimage *image,unsigned int cpu) { +struct device_node *dn; +struct property *pp;void *fdt; -int fdt_index; +int fdt_index, cpus_offset, node_offset; + + dn =of_get_cpu_node (cpu,NULL ); +if (!dn) { +pr_err ("No device node found for CPU %u\n" , cpu); +return ; + } fdt_index =get_fdt_index (image);if (fdt_index <0 ) {pr_err ("Unable to locate FDT segment.\n" ); -return ; + goto put; } fdt =__va ((void *)image->segment[fdt_index].mem); -/* Temporarily invalidate the crash image while it is replaced */ + cpus_offset =fdt_path_offset (fdt,"/cpus" ); +if (cpus_offset <0 ) { +pr_err ("Malformed device tree: error reading /cpus node: %s\n" , +fdt_strerror (cpus_offset)); + goto put; + } + +/* Node already present, e.g. an offlined CPU came back online */
arch/powerpc/kexec/crash.c static int get_fdt_index(struct kimage *image) · line 632
Quoted 10 lines
arch/powerpc/kexec/crash.c +5
-3+if (fdt_subnode_offset (fdt, cpus_offset, dn->full_name) >=0 ) + goto put; + +/* Temporarily invalidate the crash image while it is updated */ xchg (&kexec_crash_image,NULL ); -/* update FDT to reflect changes in CPU resources */ -if (update_cpus_node (fdt)) -pr_err ("Failed to update crash FDT" ); + node_offset =fdt_add_subnode (fdt, cpus_offset, dn->full_name);
[Severity: High]
What happens across DLPAR CPU removal and addition when update_crash_fdt() only appends missing CPU nodes and never removes detached ones?
On pSeries, dlpar_cpu_remove() offlines the CPU threads (where KEXEC_CRASH_HP_REMOVE_CPU is a no-op in arch_crash_handle_hotplug_event()), pseries_cpuhp_detach_nodes() detaches the CPU device_node from /cpus in the live device tree, and pseries_remove_processor() clears its bits in cpu_present_mask so those logical CPU IDs can be reused.
Previously, update_cpus_node() deleted all existing cpu subnodes under /cpus in the crash FDT and rebuilt them from the live /cpus tree, purging any detached DLPAR CPU nodes. With this change, detached CPU subnodes remain in the crash FDT indefinitely:
1. kdump_extra_fdt_size_ppc64() in arch/powerpc/kexec/file_load_64.c only budgets extra FDT space for possible_cpu_nodes concurrent CPU nodes:
if (image->type == KEXEC_TYPE_CRASH) {
possible_cpu_nodes = num_possible_cpus() / threads_per_core;
if (possible_cpu_nodes > cpu_nodes)
extra_size += (possible_cpu_nodes - cpu_nodes) * cpu_node_size();
} When a CPU is DLPAR-removed and a CPU with a different DRC index is DLPAR-added, retaining the detached node alongside the newly added node exceeds possible_cpu_nodes and causes fdt_add_subnode() or fdt_setprop() to fail with -FDT_ERR_NOSPACE.
2. Because detached nodes remain under /cpus in the crash FDT, smp_setup_cpu_maps() in the kdump kernel still iterates over them and assigns logical CPU IDs up to nr_cpu_ids, which can push valid present CPUs past nr_cpu_ids.
3. If the same DRC index is later DLPAR-added again via dlpar_configure_connector() with updated properties (such as ibm,associativity), fdt_subnode_offset(fdt, cpus_offset, dn->full_name) >= 0 matches the stale node and skips updating its properties.
Quoted 5 lines
arch/powerpc/kexec/crash.c +5
-0+if (node_offset <0 ) { +pr_err ("Unable to add %s subnode: %s\n" , dn->full_name, +fdt_strerror (node_offset)); + goto out; + }
arch/powerpc/kexec/crash.c static int get_fdt_index(struct kimage *image) · line 647
Quoted 10 lines
arch/powerpc/kexec/crash.c +9
-0+for_each_property_of_node (dn, pp) { +int 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)); +break ; + } + }
[Severity: High]
If fdt_setprop() fails partway through copying the properties in update_crash_fdt(), should node_offset be removed with fdt_del_node(fdt, node_offset) before breaking out?
Leaving the partially populated subnode under /cpus has two consequences:
1. Any subsequent update_crash_fdt() call for sibling SMT threads of the same core (or a later re-online of the CPU) sees fdt_subnode_offset(fdt, cpus_offset, dn->full_name) >= 0 and returns early without populating the missing properties.
2. If the device_type = "cpu" property was written before fdt_setprop() failed on ibm,ppc-interrupt-server#s and reg, early_init_dt_scan_cpus() in arch/powerpc/kernel/prom.c will match the partial CPU node during kdump boot, get NULL for intserv with len left uninitialized, and dereference intserv[i]:
intserv = of_get_flat_dt_prop(node, "ibm,ppc-interrupt-server#s", &len);
if (!intserv)
intserv = of_get_flat_dt_prop(node, "reg", &len);
nthreads = len / sizeof(int);
for (i = 0; i < nthreads; i++) {
if (be32_to_cpu(intserv[i]) ==
fdt_boot_cpuid_phys(initial_boot_params)) {Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 87 lines · On 04/11/26 11:22, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] powerpc/crash: detached DLPAR CPU nodes accumulate in crash FDT inupdate_crash_fdt()
- [High] powerpc/crash: incomplete CPU subnode left in FDT onfdt_setprop()failure inupdate_crash_fdt()--commit
f91f7035e04400925af984e21ed910579118bae0
Author: Vishal Chourasia <[email protected]>powerpc/crash: Add only the onlined CPU's node to the crash FDT
This patch updates crash FDT handling on CPU online events to pass the onlined CPU number to
arch_crash_handle_hotplug_event()and insert only that CPU's device node into the crash FDT if it is not already present, rather than rebuilding all CPU nodes viaupdate_cpus_node().Quoted 4 lines
arch/powerpc/kexec/crash.c +0
-0[ ... ]
Quoted 47 lines
arch/powerpc/kexec/crash.c +25
-5@@ -584,32 +585,71 @@ static int get_fdt_index(struct kimage *image) }/** -* update_crash_fdt - updates the cpus node of the crash FDT. +* update_crash_fdt - add the node of the onlined CPU to the crash FDT. * * @image: a pointer to kexec_crash_image +* @cpu: the CPU that was onlined +* +* The node is added as the first child of /cpus, the same position a node +* attached to the live device tree takes. Nothing is done if the FDT already +* has the node, for example when an offlined CPU comes back. */ -static void update_crash_fdt (struct kimage *image) +static void update_crash_fdt (struct kimage *image,unsigned int cpu) { +struct device_node *dn; +struct property *pp;void *fdt; -int fdt_index; +int fdt_index, cpus_offset, node_offset; + + dn =of_get_cpu_node (cpu,NULL ); +if (!dn) { +pr_err ("No device node found for CPU %u\n" , cpu); +return ; + } fdt_index =get_fdt_index (image);if (fdt_index <0 ) {pr_err ("Unable to locate FDT segment.\n" ); -return ; + goto put; } fdt =__va ((void *)image->segment[fdt_index].mem); -/* Temporarily invalidate the crash image while it is replaced */ + cpus_offset =fdt_path_offset (fdt,"/cpus" ); +if (cpus_offset <0 ) { +pr_err ("Malformed device tree: error reading /cpus node: %s\n" , +fdt_strerror (cpus_offset)); + goto put; + } + +/* Node already present, e.g. an offlined CPU came back online */ arch/powerpc/kexec/crash.c static int get_fdt_index(struct kimage *image) · line 632
Quoted 10 lines
arch/powerpc/kexec/crash.c +5
-3+if (fdt_subnode_offset (fdt, cpus_offset, dn->full_name) >=0 ) + goto put; + +/* Temporarily invalidate the crash image while it is updated */ xchg (&kexec_crash_image,NULL ); -/* update FDT to reflect changes in CPU resources */ -if (update_cpus_node (fdt)) -pr_err ("Failed to update crash FDT" ); + node_offset =fdt_add_subnode (fdt, cpus_offset, dn->full_name);[Severity: High]
What happens across DLPAR CPU removal and addition whenupdate_crash_fdt()only appends missing CPU nodes and never removes detached ones?On pSeries,
dlpar_cpu_remove()offlines the CPU threads (whereKEXEC_CRASH_HP_REMOVE_CPUis a no-op inarch_crash_handle_hotplug_event()),pseries_cpuhp_detach_nodes()detaches the CPUdevice_nodefrom /cpus in the live device tree, andpseries_remove_processor()clears its bits incpu_present_maskso those logical CPU IDs can be reused.
Quoted 4 lines
Previously,
update_cpus_node()deleted all existing cpu subnodes under /cpus in the crash FDT and rebuilt them from the live /cpus tree, purging any detached DLPAR CPU nodes. With this change, detached CPU subnodes remain in the crash FDT indefinitely:
As mentioned in the previous paragraph, during the CPU offline path, crash handler doesn't update the crash image and returns early. update_cpus_node() is not invoked.
Quoted 10 lines
1.
kdump_extra_fdt_size_ppc64()inarch/powerpc/kexec/file_load_64.conly budgets extra FDT space forpossible_cpu_nodesconcurrent CPU nodes:if (
image->type==KEXEC_TYPE_CRASH) {
possible_cpu_nodes=num_possible_cpus()/threads_per_core; if (possible_cpu_nodes>cpu_nodes)
extra_size+= (possible_cpu_nodes-cpu_nodes) *cpu_node_size();
}
Quoted 4 lines
When a CPU is DLPAR-removed and a CPU with a different DRC index is DLPAR-added, retaining the detached node alongside the newly added node exceeds
possible_cpu_nodesand causesfdt_add_subnode()orfdt_setprop()to fail with -FDT_ERR_NOSPACE.
Behaviour is same as before.
Quoted 39 lines
2. Because detached nodes remain under /cpus in the crash FDT,
smp_setup_cpu_maps()in the kdump kernel still iterates over them and assigns logical CPU IDs up tonr_cpu_ids, which can push valid present CPUs pastnr_cpu_ids.3. If the same DRC index is later DLPAR-added again via
dlpar_configure_connector()with updated properties (such as ibm,associativity),fdt_subnode_offset(fdt, cpus_offset, dn->full_name)>= 0 matches the stale node and skips updating its properties.Quoted 5 lines
arch/powerpc/kexec/crash.c +5
-0+if (node_offset <0 ) { +pr_err ("Unable to add %s subnode: %s\n" , dn->full_name, +fdt_strerror (node_offset)); + goto out; + }arch/powerpc/kexec/crash.c static int get_fdt_index(struct kimage *image) · line 647
Quoted 10 lines
arch/powerpc/kexec/crash.c +9
-0+for_each_property_of_node (dn, pp) { +int 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)); +break ; + } + }[Severity: High]
Iffdt_setprop()fails partway through copying the properties inupdate_crash_fdt(), shouldnode_offsetbe removed withfdt_del_node(fdt, node_offset)before breaking out?Leaving the partially populated subnode under /cpus has two consequences:
1. Any subsequent
update_crash_fdt()call for sibling SMT threads of the same core (or a later re-online of the CPU) seesfdt_subnode_offset(fdt, cpus_offset, dn->full_name)>= 0 and returns early without populating the missing properties.2. If the
device_type= "cpu" property was written beforefdt_setprop()failed
Quoted 14 lines
on ibm,ppc-interrupt-server#s and reg, early_init_dt_scan_cpus() in
arch/powerpc/kernel/prom.c will match the partial CPU node during kdump
boot, get NULL for intserv with len left uninitialized, and dereference
intserv[i]:
intserv = of_get_flat_dt_prop(node, "ibm,ppc-interrupt-server#s", &len);
if (!intserv)
intserv = of_get_flat_dt_prop(node, "reg", &len);
nthreads = len / sizeof(int);
for (i = 0; i < nthreads; i++) {
if (be32_to_cpu(intserv[i]) ==
fdt_boot_cpuid_phys(initial_boot_params)) {Similar errors on update_cpus_node() can live the crash fdt inconsistent and result in crash kernel boot hangs.
Quoted 1 line
Hi Vishal,
Quoted 93 lines · Vishal Chourasia
A CPU coming online never changes the nodes that are already in the FDT, so add only the node of that CPU.
update_crash_fdt()looks up the device node of the onlined CPU and does nothing if the FDT already has a node of that name, which is the case when an offlined CPU comes back online. Only when the node is missing, the crash image is invalidated while the node is created withfdt_add_subnode()and its properties are copied from the live device node withfdt_setprop(). All of this is done directly inupdate_crash_fdt().
fdt_add_subnode()inserts the node as the first child of /cpus, which is the same position a node attached to the live device tree takes, so the FDT keeps the order of the live tree.Signed-off-by Vishal Chourasia <[email protected]>--- arch/powerpc/kexec/crash.c | 65 +++++++++++++++++++++++++++++++------- arch/x86/kernel/crash.c | 2 +- kernel/crash_core.c | 11 +++++-- 3 files changed, 64 insertions(+), 14 deletions(-)arch/powerpc/kexec/crash.c +35
-8@@ -18,6 +18,7 @@#include <linux/types.h> #include <linux/libfdt.h> #include <linux/memory.h> +#include <linux/of.h> #include <asm/processor.h> #include <asm/machdep.h> @@ -584,32 +585,71 @@ static int get_fdt_index(struct kimage *image) }/** -* update_crash_fdt - updates the cpus node of the crash FDT. +* update_crash_fdt - add the node of the onlined CPU to the crash FDT. * * @image: a pointer to kexec_crash_image +* @cpu: the CPU that was onlined +* +* The node is added as the first child of /cpus, the same position a node +* attached to the live device tree takes. Nothing is done if the FDT already +* has the node, for example when an offlined CPU comes back. */ -static void update_crash_fdt (struct kimage *image) +static void update_crash_fdt (struct kimage *image,unsigned int cpu) { +struct device_node *dn; +struct property *pp;void *fdt; -int fdt_index; +int fdt_index, cpus_offset, node_offset; + + dn =of_get_cpu_node (cpu,NULL ); +if (!dn) { +pr_err ("No device node found for CPU %u\n" , cpu); +return ; + } fdt_index =get_fdt_index (image);if (fdt_index <0 ) {pr_err ("Unable to locate FDT segment.\n" ); -return ; + goto put; } fdt =__va ((void *)image->segment[fdt_index].mem); -/* Temporarily invalidate the crash image while it is replaced */ + cpus_offset =fdt_path_offset (fdt,"/cpus" ); +if (cpus_offset <0 ) { +pr_err ("Malformed device tree: error reading /cpus node: %s\n" , +fdt_strerror (cpus_offset)); + goto put; + } + +/* Node already present, e.g. an offlined CPU came back online */ +if (fdt_subnode_offset (fdt, cpus_offset, dn->full_name) >=0 ) + goto put; + +/* Temporarily invalidate the crash image while it is updated */ xchg (&kexec_crash_image,NULL ); -/* update FDT to reflect changes in CPU resources */ -if (update_cpus_node (fdt)) -pr_err ("Failed to update crash FDT" ); + node_offset =fdt_add_subnode (fdt, cpus_offset, dn->full_name); +if (node_offset <0 ) { +pr_err ("Unable to add %s subnode: %s\n" , dn->full_name, +fdt_strerror (node_offset)); + goto out;
arch/powerpc/kexec/crash.c static int get_fdt_index(struct kimage *image) · line 646
Quoted 10 lines
arch/powerpc/kexec/crash.c +9
-0+ } +for_each_property_of_node (dn, pp) { +int 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)); +break ; + }
If a property copy fails the loop just breaks and the image is re-validated leaving a partially populated CPU node in the FDT. The next hotplug event then sees the node as already present and never repairs it so either drop or roll back the node on failure instead.
Quoted 84 lines
arch/powerpc/kexec/crash.c +10
-3+ } +out:/* The crash image is now valid once again */ xchg (&kexec_crash_image, image); +put: +of_node_put (dn); }int arch_crash_hotplug_support (struct kimage *image,unsigned long kexec_flags)@@ -625,10 +665,11 @@ int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags)* arch_crash_handle_hotplug_event - Handle crash CPU/Memory hotplug events to update the * necessary kexec segments based on the hotplug event. * @image: a pointer to kexec_crash_image -* @arg: struct memory_notify handler for memory hotplug case and NULL for CPU hotplug case. +* @arg: struct memory_notify handler for memory hotplug case and pointer to the +* cpu number for CPU hotplug case. * * Update the kdump image based on the type of hotplug event, represented by image->hp_action. -* CPU add: Update the FDT segment to include the newly added CPU. +* CPU add: Add the node of the newly added CPU to the FDT segment, if missing. * CPU remove: No action is needed, with the assumption that it's okay to have offline CPUs * part of the FDT. * Memory add/remove: No action is taken as this is not yet supported. @@ -636,13 +677,15 @@ int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags)void arch_crash_handle_hotplug_event (struct kimage *image,void *arg) {struct memory_notify *mn; +unsigned int cpu;switch (image->hp_action) {case KEXEC_CRASH_HP_REMOVE_CPU :return ;case KEXEC_CRASH_HP_ADD_CPU : -update_crash_fdt (image); + cpu = *(unsigned int *)arg; +update_crash_fdt (image, cpu);break ;case KEXEC_CRASH_HP_REMOVE_MEMORY :arch/x86/kernel/crash.c +1
-1@@ -441,7 +441,7 @@ unsigned int arch_crash_get_elfcorehdr_size(void)* arch_crash_handle_hotplug_event() - Handle hotplug elfcorehdr changes * @image: a pointer to kexec_crash_image * @arg: struct memory_notify handler for memory hotplug case and -* NULL for CPU hotplug case. +* pointer to the cpu number (unused here) for CPU hotplug case. * * Prepare the new elfcorehdr and replace the existing elfcorehdr. */ kernel/crash_core.c +9
-2@@ -651,6 +651,9 @@ int crash_check_hotplug_support(void)* NR_CPUS and CRASH_MAX_MEMORY_RANGES. The elfcorehdr is * excluded from SHA verification by default if the architecture * supports crash hotplug. +* +* @arg is a struct memory_notify pointer for memory hotplug events and a +* pointer to the unsigned int cpu number for CPU hotplug events. */ static void crash_handle_hotplug_event (unsigned int hp_action,unsigned int cpu,void *arg) {@@ -676,10 +679,14 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu, goto out;if (hp_action ==KEXEC_CRASH_HP_ADD_CPU || - hp_action ==KEXEC_CRASH_HP_REMOVE_CPU ) + hp_action ==KEXEC_CRASH_HP_REMOVE_CPU ) {pr_debug ("hp_action %u, cpu %u\n" , hp_action, cpu); -else +/* CPU events are raised with no argument, the CPU number is passed instead */ +WARN_ON (arg); + arg = &cpu; + }else {pr_debug ("hp_action %u\n" , hp_action); + }/* * The elfcorehdr_index is set to -1 when the struct kimage
Signature · 2 lines
Regards, Mukesh Pilaniya
Hi All,
Quoted 177 lines · Vishal Chourasia
A CPU coming online never changes the nodes that are already in the FDT, so add only the node of that CPU.
update_crash_fdt()looks up the device node of the onlined CPU and does nothing if the FDT already has a node of that name, which is the case when an offlined CPU comes back online. Only when the node is missing, the crash image is invalidated while the node is created withfdt_add_subnode()and its properties are copied from the live device node withfdt_setprop(). All of this is done directly inupdate_crash_fdt().
fdt_add_subnode()inserts the node as the first child of /cpus, which is the same position a node attached to the live device tree takes, so the FDT keeps the order of the live tree.Signed-off-by Vishal Chourasia <[email protected]>--- arch/powerpc/kexec/crash.c | 65 +++++++++++++++++++++++++++++++------- arch/x86/kernel/crash.c | 2 +- kernel/crash_core.c | 11 +++++-- 3 files changed, 64 insertions(+), 14 deletions(-)arch/powerpc/kexec/crash.c +54
-11@@ -18,6 +18,7 @@#include <linux/types.h> #include <linux/libfdt.h> #include <linux/memory.h> +#include <linux/of.h> #include <asm/processor.h> #include <asm/machdep.h> @@ -584,32 +585,71 @@ static int get_fdt_index(struct kimage *image) }/** -* update_crash_fdt - updates the cpus node of the crash FDT. +* update_crash_fdt - add the node of the onlined CPU to the crash FDT. * * @image: a pointer to kexec_crash_image +* @cpu: the CPU that was onlined +* +* The node is added as the first child of /cpus, the same position a node +* attached to the live device tree takes. Nothing is done if the FDT already +* has the node, for example when an offlined CPU comes back. */ -static void update_crash_fdt (struct kimage *image) +static void update_crash_fdt (struct kimage *image,unsigned int cpu) { +struct device_node *dn; +struct property *pp;void *fdt; -int fdt_index; +int fdt_index, cpus_offset, node_offset; + + dn =of_get_cpu_node (cpu,NULL ); +if (!dn) { +pr_err ("No device node found for CPU %u\n" , cpu); +return ; + } fdt_index =get_fdt_index (image);if (fdt_index <0 ) {pr_err ("Unable to locate FDT segment.\n" ); -return ; + goto put; } fdt =__va ((void *)image->segment[fdt_index].mem); -/* Temporarily invalidate the crash image while it is replaced */ + cpus_offset =fdt_path_offset (fdt,"/cpus" ); +if (cpus_offset <0 ) { +pr_err ("Malformed device tree: error reading /cpus node: %s\n" , +fdt_strerror (cpus_offset)); + goto put; + } + +/* Node already present, e.g. an offlined CPU came back online */ +if (fdt_subnode_offset (fdt, cpus_offset, dn->full_name) >=0 ) + goto put; + +/* Temporarily invalidate the crash image while it is updated */ xchg (&kexec_crash_image,NULL ); -/* update FDT to reflect changes in CPU resources */ -if (update_cpus_node (fdt)) -pr_err ("Failed to update crash FDT" ); + node_offset =fdt_add_subnode (fdt, cpus_offset, dn->full_name); +if (node_offset <0 ) { +pr_err ("Unable to add %s subnode: %s\n" , dn->full_name, +fdt_strerror (node_offset)); + goto out; + } +for_each_property_of_node (dn, pp) { +int 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)); +break ; + } + } +out:/* The crash image is now valid once again */ xchg (&kexec_crash_image, image); +put: +of_node_put (dn); }int arch_crash_hotplug_support (struct kimage *image,unsigned long kexec_flags)@@ -625,10 +665,11 @@ int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags)* arch_crash_handle_hotplug_event - Handle crash CPU/Memory hotplug events to update the * necessary kexec segments based on the hotplug event. * @image: a pointer to kexec_crash_image -* @arg: struct memory_notify handler for memory hotplug case and NULL for CPU hotplug case. +* @arg: struct memory_notify handler for memory hotplug case and pointer to the +* cpu number for CPU hotplug case. * * Update the kdump image based on the type of hotplug event, represented by image->hp_action. -* CPU add: Update the FDT segment to include the newly added CPU. +* CPU add: Add the node of the newly added CPU to the FDT segment, if missing. * CPU remove: No action is needed, with the assumption that it's okay to have offline CPUs * part of the FDT. * Memory add/remove: No action is taken as this is not yet supported. @@ -636,13 +677,15 @@ int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags)void arch_crash_handle_hotplug_event (struct kimage *image,void *arg) {struct memory_notify *mn; +unsigned int cpu;switch (image->hp_action) {case KEXEC_CRASH_HP_REMOVE_CPU :return ;case KEXEC_CRASH_HP_ADD_CPU : -update_crash_fdt (image); + cpu = *(unsigned int *)arg; +update_crash_fdt (image, cpu);break ;case KEXEC_CRASH_HP_REMOVE_MEMORY :arch/x86/kernel/crash.c +1
-1@@ -441,7 +441,7 @@ unsigned int arch_crash_get_elfcorehdr_size(void)* arch_crash_handle_hotplug_event() - Handle hotplug elfcorehdr changes * @image: a pointer to kexec_crash_image * @arg: struct memory_notify handler for memory hotplug case and -* NULL for CPU hotplug case. +* pointer to the cpu number (unused here) for CPU hotplug case. * * Prepare the new elfcorehdr and replace the existing elfcorehdr. */ kernel/crash_core.c +4
-1@@ -651,6 +651,9 @@ int crash_check_hotplug_support(void)* NR_CPUS and CRASH_MAX_MEMORY_RANGES. The elfcorehdr is * excluded from SHA verification by default if the architecture * supports crash hotplug. +* +* @arg is a struct memory_notify pointer for memory hotplug events and a +* pointer to the unsigned int cpu number for CPU hotplug events. */ static void crash_handle_hotplug_event (unsigned int hp_action,unsigned int cpu,void *arg) {@@ -676,10 +679,14 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu, goto out;if (hp_action ==KEXEC_CRASH_HP_ADD_CPU || - hp_action ==KEXEC_CRASH_HP_REMOVE_CPU ) + hp_action ==KEXEC_CRASH_HP_REMOVE_CPU ) {pr_debug ("hp_action %u, cpu %u\n" , hp_action, cpu);
kernel/crash_core.c static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu, · line 692
Quoted 10 lines
kernel/crash_core.c +5
-1-else +/* CPU events are raised with no argument, the CPU number is passed instead */ +WARN_ON (arg); + arg = &cpu; + }else {pr_debug ("hp_action %u\n" , hp_action); + }/* * The elfcorehdr_index is set to -1 when the struct kimage
I tested the patch with the following configuration and performed performance and functional validation
Test Configuration:
-------------------
System : PowerPC LPAR
LPAR Mode : Dedicated
CPU/Memory : 50 cores / 80 GB
Kernel Version : 7.4.0-rc1
Case 1: SMT Switching Performance
---------------------------------
We measured SMT ON/OFF times with and without the patches, with expedited RCU enabled via /sys/kernel/rcu_expedited and the crash kernel image loaded (kexec_crash_loaded verified).
SMT Mode | Without Patch (s) | With Patch (s) | Improvement (%)
----------------------------------------------------------------
SMT ON | 66.331 | 6.155 | 90.72% faster SMT OFF | 6.402 | 6.339 | 0.98% faster
Observation:
With the crash kernel loaded, SMT ON takes significantly longer without the patches. The patches reduce SMT ON time by 90.72%, while SMT OFF performance remains nearly unchanged.
Case 2: Functional Validation
-----------------------------
Test 1: Crash Dump Collection
-----------------------------
After performing CPU DLPAR with the crash kernel enabled, we triggered a crash on CPU 3 using:
echo 1 > /proc/sys/kernel/sysrq
taskset -c 3 bash -c "echo c > /proc/sysrq-trigger"
Result: PASS - The crash kernel successfully collected the vmcore.
Test 2: CPU/NUMA Node Verification
----------------------------------
Verified that the newly added CPUs after DLPAR were correctly reflected in NUMA node 5, including the updated CPU count and adjusted logical CPU numbering.
Result: PASS
Overall, the patch significantly improve SMT ON performance, and both functional validation tests passed.
Regards,
Samir