diff mbox series

[RFC,v4,5/5] powerpc/crash hp: add crash hotplug support for kexec_load

Message ID 20220411084357.157308-6-sourabhjain@linux.ibm.com (mailing list archive)
State RFC
Headers show
Series [RFC,v4,1/5] powerpc/kexec: make update_cpus_node non-static | expand

Checks

Context Check Description
snowpatch_ozlabs/github-powerpc_selftests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_ppctests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_kernel_qemu success Successfully ran 24 jobs.
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.
snowpatch_ozlabs/github-powerpc_clang success Successfully ran 7 jobs.

Commit Message

Sourabh Jain April 11, 2022, 8:43 a.m. UTC
The kernel changes needed for crash hotplug support for kexec_load system
calls are similar to kexec_file_load (which has already been implemented
in earlier patches) except for finding the index of the FDT segment in the
kexec segment array. Since the kexec segment array is prepared by the
kexec tool in the userspace, the kernel is not aware of at which index FDT
segment is present.

Now to enable crash hotplug support for the kexec_load case, the crash
hotplug handler is updated to identify the index at which the FDT segment
is present in the kexec segment array by comparing the first 32 bits of
every kexec segment with the FDT magic number.

Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
---
 arch/powerpc/kexec/core_64.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

Comments

Laurent Dufour April 14, 2022, 4:39 p.m. UTC | #1
On 11/04/2022, 10:43:57, Sourabh Jain wrote:
> The kernel changes needed for crash hotplug support for kexec_load system
> calls are similar to kexec_file_load (which has already been implemented
> in earlier patches) except for finding the index of the FDT segment in the
> kexec segment array. Since the kexec segment array is prepared by the
> kexec tool in the userspace, the kernel is not aware of at which index FDT
> segment is present.
> 
> Now to enable crash hotplug support for the kexec_load case, the crash
> hotplug handler is updated to identify the index at which the FDT segment
> is present in the kexec segment array by comparing the first 32 bits of
> every kexec segment with the FDT magic number.
> 
> Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
> ---
>  arch/powerpc/kexec/core_64.c | 22 +++++++++++++++++++++-
>  1 file changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/kexec/core_64.c b/arch/powerpc/kexec/core_64.c
> index 62f77cc86407..e3f224f8eb3a 100644
> --- a/arch/powerpc/kexec/core_64.c
> +++ b/arch/powerpc/kexec/core_64.c
> @@ -480,7 +480,9 @@ int update_cpus_node(void *fdt)
>  void arch_crash_hotplug_handler(struct kimage *image, unsigned int hp_action,
>  				unsigned long a, unsigned long b)
>  {
> -	void *fdt;
> +	void *fdt, *ptr;
> +	unsigned int n;
> +	unsigned long mem, memsz;
>  
>  	/* No action needed for CPU hot-unplug */
>  	if (hp_action == KEXEC_CRASH_HP_REMOVE_CPU)
> @@ -492,6 +494,24 @@ void arch_crash_hotplug_handler(struct kimage *image, unsigned int hp_action,
>  		return;
>  	}
>  
> +	/* Sine kexec segments for kexec_load system call is prepred by
           Since

FWIW,
Reviewed-by: Laurent Dufour <ldufour@linux.ibm.com>

> +	 * kexec tool in userspace we need loop through all the segments
> +	 * to find out segment index corresponds FDT segment. In case of
> +	 * kexec_file_load it is discovered during the load itself.
> +	 */
> +	if (!image->arch.fdt_index_valid) {
> +		for (n = 0; n < image->nr_segments; n++) {
> +			mem = image->segment[n].mem;
> +			memsz = image->segment[n].memsz;
> +			ptr = __va(mem);
> +			if (ptr && fdt_magic(ptr) == FDT_MAGIC) {
> +				image->arch.fdt_index = n;
> +				image->arch.fdt_index_valid = true;
> +				break;
> +			}
> +		}
> +	}
> +
>  	/* Must have valid FDT index */
>  	if (!image->arch.fdt_index_valid) {
>  		pr_err("crash hp: unable to locate FDT segment");
diff mbox series

Patch

diff --git a/arch/powerpc/kexec/core_64.c b/arch/powerpc/kexec/core_64.c
index 62f77cc86407..e3f224f8eb3a 100644
--- a/arch/powerpc/kexec/core_64.c
+++ b/arch/powerpc/kexec/core_64.c
@@ -480,7 +480,9 @@  int update_cpus_node(void *fdt)
 void arch_crash_hotplug_handler(struct kimage *image, unsigned int hp_action,
 				unsigned long a, unsigned long b)
 {
-	void *fdt;
+	void *fdt, *ptr;
+	unsigned int n;
+	unsigned long mem, memsz;
 
 	/* No action needed for CPU hot-unplug */
 	if (hp_action == KEXEC_CRASH_HP_REMOVE_CPU)
@@ -492,6 +494,24 @@  void arch_crash_hotplug_handler(struct kimage *image, unsigned int hp_action,
 		return;
 	}
 
+	/* Sine kexec segments for kexec_load system call is prepred by
+	 * kexec tool in userspace we need loop through all the segments
+	 * to find out segment index corresponds FDT segment. In case of
+	 * kexec_file_load it is discovered during the load itself.
+	 */
+	if (!image->arch.fdt_index_valid) {
+		for (n = 0; n < image->nr_segments; n++) {
+			mem = image->segment[n].mem;
+			memsz = image->segment[n].memsz;
+			ptr = __va(mem);
+			if (ptr && fdt_magic(ptr) == FDT_MAGIC) {
+				image->arch.fdt_index = n;
+				image->arch.fdt_index_valid = true;
+				break;
+			}
+		}
+	}
+
 	/* Must have valid FDT index */
 	if (!image->arch.fdt_index_valid) {
 		pr_err("crash hp: unable to locate FDT segment");