diff mbox series

[v5,4/5] powerpc/crash hp: add crash hotplug support for kexec_load

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

Commit Message

Sourabh Jain June 20, 2022, 7:01 a.m. UTC
A 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.

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

Comments

Laurent Dufour June 22, 2022, 3:25 p.m. UTC | #1
On 20/06/2022, 09:01:05, Sourabh Jain wrote:
> A 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.
> 
> Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
> ---
>  arch/powerpc/kexec/core_64.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/arch/powerpc/kexec/core_64.c b/arch/powerpc/kexec/core_64.c
> index 6d448b55dfad..373cb46bcc0e 100644
> --- a/arch/powerpc/kexec/core_64.c
> +++ b/arch/powerpc/kexec/core_64.c
> @@ -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;

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.

> +
> +	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.

> +	}
> +
> +	return 0;
> +}
> +#endif
> +
>  /* Called during kexec sequence with MMU off */
>  static notrace void copy_segments(unsigned long ind)
>  {
diff mbox series

Patch

diff --git a/arch/powerpc/kexec/core_64.c b/arch/powerpc/kexec/core_64.c
index 6d448b55dfad..373cb46bcc0e 100644
--- a/arch/powerpc/kexec/core_64.c
+++ b/arch/powerpc/kexec/core_64.c
@@ -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)
 {