powerpc: kexec fixes
v2 cover powerpc: kexec fixes
Patch series fixes two kexec issues.
01/02: Update extra size calculation for kexec FDT to avoid kexec load failure due to FDT_ERR_NOSPACE while including CPU nodes added post boot and reserved memory ranges.
02/02: Fix update_cpus_node/core_64.c function to include missing device nodes under /cpus node with device_type != "cpu".
Note: this patch series is rebased on top of the linux-next/master,
tag: next-20240509 to avoid the conflict with the below patch series:
https://lore.kernel.org/all/[email protected]/
Changelog:
==========
v2:
- Initialize local variable cpu_nodes before using it. 01/02
- Rebased on top of linux-next/mater tag: next-20240509.
v1:
- https://lore.kernel.org/all/[email protected]/
Sourabh Jain (2):
powerpc/kexec_file: fix extra size calculation for kexec FDT powerpc/kexec_file: fix cpus node update to FDT
arch/powerpc/include/asm/kexec.h | 6 ++-- arch/powerpc/kexec/core_64.c | 53 +++++++++++++++++++++---------- arch/powerpc/kexec/elf_64.c | 12 +++++-- arch/powerpc/kexec/file_load_64.c | 53 +++++++++++++------------------ 4 files changed, 70 insertions(+), 54 deletions(-)
Signature · 1 line
2.44.0
PATCH v2 1/2 powerpc/kexec_file: fix extra size calculation for kexec FDT
While setting up the FDT for kexec, CPU nodes that are added after the system boots and reserved memory ranges are incorporated into the initial_boot_params (base FDT).
However, they are not taken into account when determining the additional size needed for the kexec FDT. As a result, kexec fails to load, generating the following error:
[1116.774451] Error updating memory reserve map: FDT_ERR_NOSPACE
kexec_file_load failed: No such process
Therefore, consider the extra size for CPU nodes added post-system boot and reserved memory ranges while preparing the kexec FDT.
While adding a new parameter to the setup_new_fdt_ppc64 function, it was noticed that there were a couple of unused parameters, so they were removed.
---
Changelog:
Since v1:
- Initialize local variable cpu_nodes before using it. 01/02
---
arch/powerpc/include/asm/kexec.h | 6 ++-- arch/powerpc/kexec/elf_64.c | 12 +++++-- arch/powerpc/kexec/file_load_64.c | 53 +++++++++++++------------------ 3 files changed, 33 insertions(+), 38 deletions(-)
arch/powerpc/include/asm/kexec.h +2 -4
@@ -103,10 +103,8 @@ int load_crashdump_segments_ppc64(struct kimage *image,int setup_purgatory_ppc64 (struct kimage *image,const void *slave_code,const void *fdt,unsigned long kernel_load_addr,unsigned long fdt_load_addr); -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); +unsigned int kexec_extra_fdt_size_ppc64 (struct kimage *image,struct crash_mem *rmem); +int setup_new_fdt_ppc64 (const struct kimage *image,void *fdt,struct crash_mem *rmem);#endif /* CONFIG_PPC64 */ #endif /* CONFIG_KEXEC_FILE */
arch/powerpc/kexec/elf_64.c +9 -3
@@ -23,6 +23,7 @@#include <linux/of_fdt.h> #include <linux/slab.h> #include <linux/types.h> +#include <asm/kexec_ranges.h> static void *elf64_load(struct kimage *image, char *kernel_buf, unsigned long kernel_len, char *initrd,
@@ -36,6 +37,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,const void *slave_code;struct elfhdr ehdr;char *modified_cmdline =NULL ; +struct crash_mem *rmem =NULL ;struct kexec_elf_info elf_info;struct kexec_buf kbuf = { .image = image, .buf_min =0 , .buf_max = ppc64_rma_size };
@@ -102,17 +104,20 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,kexec_dprintk ("Loaded initrd at 0x%lx\n" , initrd_load_addr); } + ret =get_reserved_memory_ranges (&rmem); +if (ret) + goto out; + fdt =of_kexec_alloc_and_setup_fdt (image, initrd_load_addr, initrd_len, cmdline, -kexec_extra_fdt_size_ppc64 (image)); +kexec_extra_fdt_size_ppc64 (image, rmem));if (!fdt) {pr_err ("Error setting up the new device tree.\n" ); ret = -EINVAL ; goto out; } - ret =setup_new_fdt_ppc64 (image, fdt, initrd_load_addr, - initrd_len, cmdline); + ret =setup_new_fdt_ppc64 (image, fdt, rmem);if (ret) goto out_free_fdt;
@@ -146,6 +151,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf, out_free_fdt:kvfree (fdt); out: +kfree (rmem);kfree (modified_cmdline);kexec_free_elf_info (&elf_info);
arch/powerpc/kexec/file_load_64.c +22 -31
101 lines not on this page · raw message
Signature · 1 line
2.44.0
PATCH v2 2/2 powerpc/kexec_file: fix cpus node update to FDT
In reply to Sourabh JainWhile updating the cpus node, commit 40c753993e3a ("powerpc/kexec_file:
Use current CPU info while setting up FDT") first deletes all subnodes
under the /cpus node. However, while adding sub-nodes back, it missed adding cpus subnodes whose device_type != "cpu", such as l2-cache*, l3-cache*, ibm,powerpc-cpu-features.
Fix this by only deleting cpus sub-nodes of device_type == "cpus" and then adding all available nodes with device_type == "cpu".
---
* No changes in v2.
---
arch/powerpc/kexec/core_64.c | 53 +++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 16 deletions(-)
arch/powerpc/kexec/core_64.c +37 -16
@@ -456,9 +456,15 @@ static int add_node_props(void *fdt, int node_offset, const struct device_node ** @fdt: Flattened device tree of the kernel. * * Returns 0 on success, negative errno on error. +* +* Note: expecting no subnodes under /cpus/<node> with device_type == "cpu". +* If this changes, update this function to include them. */ int update_cpus_node (void *fdt) { +int prev_node_offset; +const char *device_type; +const struct fdt_property *prop;struct device_node *cpus_node, *dn;int cpus_offset, cpus_subnode_offset, ret =0 ;
@@ -469,30 +475,44 @@ int update_cpus_node(void *fdt)return cpus_offset; } -if (cpus_offset >0 ) { - ret =fdt_del_node (fdt, cpus_offset); + prev_node_offset = cpus_offset; +/* Delete sub-nodes of /cpus node with device_type == "cpu" */ +for (cpus_subnode_offset =fdt_first_subnode (fdt, cpus_offset); cpus_subnode_offset >=0 ;) { +/* Ignore nodes that do not have a device_type property or device_type != "cpu" */ + prop =fdt_get_property (fdt, cpus_subnode_offset,"device_type" ,NULL ); +if (!prop ||strcmp (prop->data,"cpu" )) { + prev_node_offset = cpus_subnode_offset; + goto next_node; + } + + ret =fdt_del_node (fdt, cpus_subnode_offset);if (ret <0 ) { -pr_err ("Error deleting /cpus node: %s\n" ,fdt_strerror (ret)); -return -EINVAL ; +pr_err ("Failed to delete a cpus sub-node: %s\n" ,fdt_strerror (ret)); +return ret; } +next_node: +if (prev_node_offset == cpus_offset) + cpus_subnode_offset =fdt_first_subnode (fdt, cpus_offset); +else + cpus_subnode_offset =fdt_next_subnode (fdt, prev_node_offset); } -/* 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)); + cpus_node =of_find_node_by_path ("/cpus" ); +/* Fail here to avoid kexec/kdump kernel boot hung */ +if (!cpus_node) { +pr_err ("No /cpus node found\n" );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; +/* Add all /cpus sub-nodes of device_type == "cpu" to FDT */ +for_each_child_of_node (cpus_node, dn) { +/* Ignore device nodes that do not have a device_type property +* or device_type != "cpu". +*/ + device_type =of_get_property (dn,"device_type" ,NULL ); +if (!device_type ||strcmp (device_type,"cpu" )) +continue ; -/* 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,
@@ -506,6 +526,7 @@ int update_cpus_node(void *fdt) goto out; } out: +of_node_put (cpus_node);of_node_put (dn);return ret; }
Signature · 1 line
2.44.0
Michael Ellerman
AppliedQuoted 10 lines · Sourabh Jain
Patch series fixes two kexec issues.
01/02: Update extra size calculation for kexec FDT to avoid kexec load failure due to
FDT_ERR_NOSPACEwhile including CPU nodes added post boot and reserved memory ranges.02/02: Fix
update_cpus_node/core_64.cfunction to include missing device nodes under /cpus node withdevice_type!= "cpu".[...]
Applied to powerpc/next.
[1/2] powerpc/kexec_file: fix extra size calculation for kexec FDT
https://git.kernel.org/powerpc/c/0d3ff067331ef84e7e7f49537d768881042ed5ba [2/2] powerpc/kexec_file: fix cpus node update to FDT https://git.kernel.org/powerpc/c/932bed41217059638c78a75411b7893b121d2162
cheers