Skip to contentSkip to conversation

powerpc/kexec_file: Restore FDT size estimation for kdump kernel

PATCH Superseded Thiago Jung Bauermann 2 participants 3 messages Feb 19, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/kexec_file: Restore FDT size estimation for kdump kernel

Commit 2377c92e37fe ("powerpc/kexec_file: fix FDT size estimation for kdump kernel") fixed how elf64_load() estimates the FDT size needed by the crashdump kernel.

At the same time, commit 130b2d59cec0 ("powerpc: Use common of_kexec_alloc_and_setup_fdt()") changed the same code to use the generic function of_kexec_alloc_and_setup_fdt() to calculate the FDT size. That change made the code overestimate it a bit by counting twice the space required for the kernel command line and /chosen properties.

Therefore change kexec_fdt_totalsize_ppc64() to calculate just the extra space needed by the kdump kernel, and change the function name so that it better reflects what the function is now doing.

---
 arch/powerpc/include/asm/kexec.h  |  2 +-
 arch/powerpc/kexec/elf_64.c       |  2 +-
 arch/powerpc/kexec/file_load_64.c | 26 ++++++++------------------
 3 files changed, 10 insertions(+), 20 deletions(-)

Applies on top of next-20210219.

arch/powerpc/include/asm/kexec.h +1 -1
index baab158e215c..5a11cc8d2350 100644
@@ -128,7 +128,7 @@ 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_fdt_totalsize_ppc64(struct kimage *image);
+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);
arch/powerpc/kexec/elf_64.c +1 -1
index 0492ca6003f3..5a569bb51349 100644
@@ -104,7 +104,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
 
 	fdt = of_kexec_alloc_and_setup_fdt(image, initrd_load_addr,
 					   initrd_len, cmdline,
-					   kexec_fdt_totalsize_ppc64(image));
+					   kexec_extra_fdt_size_ppc64(image));
 	if (!fdt) {
 		pr_err("Error setting up the new device tree.\n");
 		ret = -EINVAL;
arch/powerpc/kexec/file_load_64.c +8 -18
index 3609de30a170..8541ba731908 100644
@@ -927,37 +927,27 @@ int setup_purgatory_ppc64(struct kimage *image, const void *slave_code,
 }
 
 /**
- * kexec_fdt_totalsize_ppc64 - Return the estimated size needed to setup FDT
- *                             for kexec/kdump kernel.
- * @image:                     kexec image being loaded.
+ * kexec_extra_fdt_size_ppc63 - Return the estimated size needed to setup FDT
+ *                              for kexec/kdump kernel.
+ * @image:                      kexec image being loaded.
  *
- * Returns the estimated size needed for kexec/kdump kernel FDT.
+ * Returns the estimated extra size needed for kexec/kdump kernel FDT.
  */
-unsigned int kexec_fdt_totalsize_ppc64(struct kimage *image)
+unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image)
 {
-	unsigned int fdt_size;
 	u64 usm_entries;
 
-	/*
-	 * The below estimate more than accounts for a typical kexec case where
-	 * the additional space is to accommodate things like kexec cmdline,
-	 * chosen node with properties for initrd start & end addresses and
-	 * a property to indicate kexec boot..
-	 */
-	fdt_size = fdt_totalsize(initial_boot_params) + (2 * COMMAND_LINE_SIZE);
 	if (image->type != KEXEC_TYPE_CRASH)
-		return fdt_size;
+		return 0;
 
 	/*
-	 * For kdump kernel, also account for linux,usable-memory and
+	 * For kdump kernel, account for linux,usable-memory and
 	 * linux,drconf-usable-memory properties. Get an approximate on the
 	 * number of usable memory entries and use for FDT size estimation.
 	 */
 	usm_entries = ((memblock_end_of_DRAM() / drmem_lmb_size()) +
 		       (2 * (resource_size(&crashk_res) / drmem_lmb_size())));
-	fdt_size += (unsigned int)(usm_entries * sizeof(u64));
-
-	return fdt_size;
+	return (unsigned int)(usm_entries * sizeof(u64));
 }
 
 /**

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Reviewed-by on v1 1/1
#1 lore raw

On 2/19/21 6:25 AM, Thiago Jung Bauermann wrote:

One small nit in the function header (please see below), but otherwise the change looks good.

Quoted 54 lines

Commit 2377c92e37fe ("powerpc/kexec_file: fix FDT size estimation for kdump kernel") fixed how elf64_load() estimates the FDT size needed by the crashdump kernel.

At the same time, commit 130b2d59cec0 ("powerpc: Use common of_kexec_alloc_and_setup_fdt()") changed the same code to use the generic function of_kexec_alloc_and_setup_fdt() to calculate the FDT size. That change made the code overestimate it a bit by counting twice the space required for the kernel command line and /chosen properties.

Therefore change kexec_fdt_totalsize_ppc64() to calculate just the extra space needed by the kdump kernel, and change the function name so that it better reflects what the function is now doing.

---
  arch/powerpc/include/asm/kexec.h  |  2 +-
  arch/powerpc/kexec/elf_64.c       |  2 +-
  arch/powerpc/kexec/file_load_64.c | 26 ++++++++------------------
  3 files changed, 10 insertions(+), 20 deletions(-)

Applies on top of next-20210219.

arch/powerpc/include/asm/kexec.h +1 -1
index baab158e215c..5a11cc8d2350 100644
@@ -128,7 +128,7 @@ 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_fdt_totalsize_ppc64(struct kimage *image);
+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);
arch/powerpc/kexec/elf_64.c +1 -1
index 0492ca6003f3..5a569bb51349 100644
@@ -104,7 +104,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
 
  	fdt = of_kexec_alloc_and_setup_fdt(image, initrd_load_addr,
  					   initrd_len, cmdline,
-					   kexec_fdt_totalsize_ppc64(image));
+					   kexec_extra_fdt_size_ppc64(image));
  	if (!fdt) {
  		pr_err("Error setting up the new device tree.\n");
  		ret = -EINVAL;
arch/powerpc/kexec/file_load_64.c +0 -0
index 3609de30a170..8541ba731908 100644

arch/powerpc/kexec/file_load_64.c int setup_purgatory_ppc64(struct kimage *image, const void *slave_code, · line 930

Quoted 7 lines
arch/powerpc/kexec/file_load_64.c +1 -3
@@ -927,37 +927,27 @@ int setup_purgatory_ppc64(struct kimage *image, const void *slave_code,
  }
 
  /**
- * kexec_fdt_totalsize_ppc64 - Return the estimated size needed to setup FDT
- *                             for kexec/kdump kernel.
- * @image:                     kexec image being loaded.
+ * kexec_extra_fdt_size_ppc63 - Return the estimated size needed to setup FDT

Perhaps change to

"Return the estimated additional size needed to setup FDT for kexec/kdump kernel"?

-lakshmi

Quoted 29 lines
arch/powerpc/kexec/file_load_64.c +6 -12
+ *                              for kexec/kdump kernel.
+ * @image:                      kexec image being loaded.
   *
- * Returns the estimated size needed for kexec/kdump kernel FDT.
+ * Returns the estimated extra size needed for kexec/kdump kernel FDT.
   */
-unsigned int kexec_fdt_totalsize_ppc64(struct kimage *image)
+unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image)
  {
-	unsigned int fdt_size;
  	u64 usm_entries;
 
-	/*
-	 * The below estimate more than accounts for a typical kexec case where
-	 * the additional space is to accommodate things like kexec cmdline,
-	 * chosen node with properties for initrd start & end addresses and
-	 * a property to indicate kexec boot..
-	 */
-	fdt_size = fdt_totalsize(initial_boot_params) + (2 * COMMAND_LINE_SIZE);
  	if (image->type != KEXEC_TYPE_CRASH)
-		return fdt_size;
+		return 0;
 
  	/*
-	 * For kdump kernel, also account for linux,usable-memory and
+	 * For kdump kernel, account for linux,usable-memory and
  	 * linux,drconf-usable-memory properties. Get an approximate on the
  	 * number of usable memory entries and use for FDT size estimation.

arch/powerpc/kexec/file_load_64.c int setup_purgatory_ppc64(struct kimage *image, const void *slave_code, · line 953

Quoted 10 lines
arch/powerpc/kexec/file_load_64.c +1 -3
  	 */
  	usm_entries = ((memblock_end_of_DRAM() / drmem_lmb_size()) +
  		       (2 * (resource_size(&crashk_res) / drmem_lmb_size())));
-	fdt_size += (unsigned int)(usm_entries * sizeof(u64));
-
-	return fdt_size;
+	return (unsigned int)(usm_entries * sizeof(u64));
  }
 
  /**

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#2 lore raw
Quoted 6 lines · Lakshmi Ramasubramanian

On 2/19/21 6:25 AM, Thiago Jung Bauermann wrote:

One small nit in the function header (please see below), but otherwise the change looks good.

Thanks for your review. I incorporated your suggestion and will send v2 shortly.

Quoted 12 lines

arch/powerpc/kexec/file_load_64.c int setup_purgatory_ppc64(struct kimage *image, const void *slave_code, · line 929

Quoted 9 lines
arch/powerpc/kexec/file_load_64.c +1 -3
@@ -927,37 +927,27 @@ int setup_purgatory_ppc64(struct kimage *image, const void *slave_code,
  }
    /**
- * kexec_fdt_totalsize_ppc64 - Return the estimated size needed to setup FDT
- *                             for kexec/kdump kernel.
- * @image:                     kexec image being loaded.
+ * kexec_extra_fdt_size_ppc63 - Return the estimated size needed to setup FDT

Perhaps change to

Quoted 2 lines

"Return the estimated additional size needed to setup FDT for kexec/kdump kernel"?

That's better indeed. I also hadn't noticed that I changed ppc64 to ppc63. Fixed as well.

Signature · 7 lines
Thiago Jung Bauermann
IBM Linux Technology Center

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec