Skip to content

Commit 8c14e6a

Browse files
author
Mamatha Inamdar
committed
powerpc/kexec: make the update_cpus_node() function public
JIRA: https://issues.redhat.com/browse/RHEL-101851 commit 0857bef Author: Sourabh Jain <sourabhjain@linux.ibm.com> Date: Tue Mar 26 11:24:11 2024 +0530 powerpc/kexec: make the update_cpus_node() function public Move the update_cpus_node() from kexec/{file_load_64.c => core_64.c} to allow other kexec components to use it. Later in the series, this function is used for in-kernel updates to the kdump image during CPU/memory hotplug or online/offline events for both kexec_load and kexec_file_load syscalls. No functional changes are intended. Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com> Acked-by: Hari Bathini <hbathini@linux.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://msgid.link/20240326055413.186534-5-sourabhjain@linux.ibm.com Signed-off-by: Mamatha Inamdar <minamdar@redhat.com>
1 parent 6cce07f commit 8c14e6a

File tree

3 files changed

+95
-87
lines changed

3 files changed

+95
-87
lines changed

arch/powerpc/include/asm/kexec.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ static inline void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *))
184184

185185
#endif /* CONFIG_CRASH_DUMP */
186186

187+
#if defined(CONFIG_KEXEC_FILE) || defined(CONFIG_CRASH_DUMP)
188+
int update_cpus_node(void *fdt);
189+
#endif
190+
187191
#ifdef CONFIG_PPC_BOOK3S_64
188192
#include <asm/book3s/64/kexec.h>
189193
#endif

arch/powerpc/kexec/core_64.c

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/cpu.h>
1818
#include <linux/hardirq.h>
1919
#include <linux/of.h>
20+
#include <linux/libfdt.h>
2021

2122
#include <asm/page.h>
2223
#include <asm/current.h>
@@ -32,6 +33,7 @@
3233
#include <asm/asm-prototypes.h>
3334
#include <asm/svm.h>
3435
#include <asm/ultravisor.h>
36+
#include <asm/crashdump-ppc64.h>
3537

3638
int machine_kexec_prepare(struct kimage *image)
3739
{
@@ -430,3 +432,92 @@ static int __init export_htab_values(void)
430432
}
431433
late_initcall(export_htab_values);
432434
#endif /* CONFIG_PPC_64S_HASH_MMU */
435+
436+
#if defined(CONFIG_KEXEC_FILE) || defined(CONFIG_CRASH_DUMP)
437+
/**
438+
* add_node_props - Reads node properties from device node structure and add
439+
* them to fdt.
440+
* @fdt: Flattened device tree of the kernel
441+
* @node_offset: offset of the node to add a property at
442+
* @dn: device node pointer
443+
*
444+
* Returns 0 on success, negative errno on error.
445+
*/
446+
static int add_node_props(void *fdt, int node_offset, const struct device_node *dn)
447+
{
448+
int ret = 0;
449+
struct property *pp;
450+
451+
if (!dn)
452+
return -EINVAL;
453+
454+
for_each_property_of_node(dn, pp) {
455+
ret = fdt_setprop(fdt, node_offset, pp->name, pp->value, pp->length);
456+
if (ret < 0) {
457+
pr_err("Unable to add %s property: %s\n", pp->name, fdt_strerror(ret));
458+
return ret;
459+
}
460+
}
461+
return ret;
462+
}
463+
464+
/**
465+
* update_cpus_node - Update cpus node of flattened device tree using of_root
466+
* device node.
467+
* @fdt: Flattened device tree of the kernel.
468+
*
469+
* Returns 0 on success, negative errno on error.
470+
*/
471+
int update_cpus_node(void *fdt)
472+
{
473+
struct device_node *cpus_node, *dn;
474+
int cpus_offset, cpus_subnode_offset, ret = 0;
475+
476+
cpus_offset = fdt_path_offset(fdt, "/cpus");
477+
if (cpus_offset < 0 && cpus_offset != -FDT_ERR_NOTFOUND) {
478+
pr_err("Malformed device tree: error reading /cpus node: %s\n",
479+
fdt_strerror(cpus_offset));
480+
return cpus_offset;
481+
}
482+
483+
if (cpus_offset > 0) {
484+
ret = fdt_del_node(fdt, cpus_offset);
485+
if (ret < 0) {
486+
pr_err("Error deleting /cpus node: %s\n", fdt_strerror(ret));
487+
return -EINVAL;
488+
}
489+
}
490+
491+
/* Add cpus node to fdt */
492+
cpus_offset = fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), "cpus");
493+
if (cpus_offset < 0) {
494+
pr_err("Error creating /cpus node: %s\n", fdt_strerror(cpus_offset));
495+
return -EINVAL;
496+
}
497+
498+
/* Add cpus node properties */
499+
cpus_node = of_find_node_by_path("/cpus");
500+
ret = add_node_props(fdt, cpus_offset, cpus_node);
501+
of_node_put(cpus_node);
502+
if (ret < 0)
503+
return ret;
504+
505+
/* Loop through all subnodes of cpus and add them to fdt */
506+
for_each_node_by_type(dn, "cpu") {
507+
cpus_subnode_offset = fdt_add_subnode(fdt, cpus_offset, dn->full_name);
508+
if (cpus_subnode_offset < 0) {
509+
pr_err("Unable to add %s subnode: %s\n", dn->full_name,
510+
fdt_strerror(cpus_subnode_offset));
511+
ret = cpus_subnode_offset;
512+
goto out;
513+
}
514+
515+
ret = add_node_props(fdt, cpus_subnode_offset, dn);
516+
if (ret < 0)
517+
goto out;
518+
}
519+
out:
520+
of_node_put(dn);
521+
return ret;
522+
}
523+
#endif /* CONFIG_KEXEC_FILE || CONFIG_CRASH_DUMP */

arch/powerpc/kexec/file_load_64.c

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -835,93 +835,6 @@ unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image)
835835
return extra_size + kdump_extra_fdt_size_ppc64(image);
836836
}
837837

838-
/**
839-
* add_node_props - Reads node properties from device node structure and add
840-
* them to fdt.
841-
* @fdt: Flattened device tree of the kernel
842-
* @node_offset: offset of the node to add a property at
843-
* @dn: device node pointer
844-
*
845-
* Returns 0 on success, negative errno on error.
846-
*/
847-
static int add_node_props(void *fdt, int node_offset, const struct device_node *dn)
848-
{
849-
int ret = 0;
850-
struct property *pp;
851-
852-
if (!dn)
853-
return -EINVAL;
854-
855-
for_each_property_of_node(dn, pp) {
856-
ret = fdt_setprop(fdt, node_offset, pp->name, pp->value, pp->length);
857-
if (ret < 0) {
858-
pr_err("Unable to add %s property: %s\n", pp->name, fdt_strerror(ret));
859-
return ret;
860-
}
861-
}
862-
return ret;
863-
}
864-
865-
/**
866-
* update_cpus_node - Update cpus node of flattened device tree using of_root
867-
* device node.
868-
* @fdt: Flattened device tree of the kernel.
869-
*
870-
* Returns 0 on success, negative errno on error.
871-
*/
872-
static int update_cpus_node(void *fdt)
873-
{
874-
struct device_node *cpus_node, *dn;
875-
int cpus_offset, cpus_subnode_offset, ret = 0;
876-
877-
cpus_offset = fdt_path_offset(fdt, "/cpus");
878-
if (cpus_offset < 0 && cpus_offset != -FDT_ERR_NOTFOUND) {
879-
pr_err("Malformed device tree: error reading /cpus node: %s\n",
880-
fdt_strerror(cpus_offset));
881-
return cpus_offset;
882-
}
883-
884-
if (cpus_offset > 0) {
885-
ret = fdt_del_node(fdt, cpus_offset);
886-
if (ret < 0) {
887-
pr_err("Error deleting /cpus node: %s\n", fdt_strerror(ret));
888-
return -EINVAL;
889-
}
890-
}
891-
892-
/* Add cpus node to fdt */
893-
cpus_offset = fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), "cpus");
894-
if (cpus_offset < 0) {
895-
pr_err("Error creating /cpus node: %s\n", fdt_strerror(cpus_offset));
896-
return -EINVAL;
897-
}
898-
899-
/* Add cpus node properties */
900-
cpus_node = of_find_node_by_path("/cpus");
901-
ret = add_node_props(fdt, cpus_offset, cpus_node);
902-
of_node_put(cpus_node);
903-
if (ret < 0)
904-
return ret;
905-
906-
/* Loop through all subnodes of cpus and add them to fdt */
907-
for_each_node_by_type(dn, "cpu") {
908-
cpus_subnode_offset = fdt_add_subnode(fdt, cpus_offset, dn->full_name);
909-
if (cpus_subnode_offset < 0) {
910-
pr_err("Unable to add %s subnode: %s\n", dn->full_name,
911-
fdt_strerror(cpus_subnode_offset));
912-
ret = cpus_subnode_offset;
913-
goto out;
914-
}
915-
916-
ret = add_node_props(fdt, cpus_subnode_offset, dn);
917-
if (ret < 0)
918-
goto out;
919-
}
920-
out:
921-
of_node_put(dn);
922-
return ret;
923-
}
924-
925838
static int copy_property(void *fdt, int node_offset, const struct device_node *dn,
926839
const char *propname)
927840
{

0 commit comments

Comments
 (0)