]> git.baikalelectronics.ru Git - kernel.git/commitdiff
powerpc/kexec_file: fix FDT size estimation for kdump kernel
authorHari Bathini <hbathini@linux.ibm.com>
Thu, 4 Feb 2021 11:31:10 +0000 (17:01 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 11 Feb 2021 12:35:07 +0000 (23:35 +1100)
On systems with large amount of memory, loading kdump kernel through
kexec_file_load syscall may fail with the below error:

    "Failed to update fdt with linux,drconf-usable-memory property"

This happens because the size estimation for kdump kernel's FDT does
not account for the additional space needed to setup usable memory
properties. Fix it by accounting for the space needed to include
linux,usable-memory & linux,drconf-usable-memory properties while
estimating kdump kernel's FDT size.

Fixes: 6ecd0163d360 ("powerpc/kexec_file: Add appropriate regions for memory reserve map")
Cc: stable@vger.kernel.org # v5.9+
Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/161243826811.119001.14083048209224609814.stgit@hbathini
arch/powerpc/include/asm/kexec.h
arch/powerpc/kexec/elf_64.c
arch/powerpc/kexec/file_load_64.c

index 55d6ede30c19afb7716a27ee423a3d3c58009506..9ab344d29a545957c8577b47ff34f3047559583f 100644 (file)
@@ -136,6 +136,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);
 int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
                        unsigned long initrd_load_addr,
                        unsigned long initrd_len, const char *cmdline);
index d0e459bb2f05a69bb9de7d4cffa3f4b76ed8bed5..9842e33533df154802bec1fa80de4c8c12f22bdd 100644 (file)
@@ -102,7 +102,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
                pr_debug("Loaded initrd at 0x%lx\n", initrd_load_addr);
        }
 
-       fdt_size = fdt_totalsize(initial_boot_params) * 2;
+       fdt_size = kexec_fdt_totalsize_ppc64(image);
        fdt = kmalloc(fdt_size, GFP_KERNEL);
        if (!fdt) {
                pr_err("Not enough memory for the device tree.\n");
index c69bcf9b547a8cd97ccf8d2ba9072e4c6fff13fb..02b9e4d0dc40b072ca2fad7d18e6487d9da1d4ac 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/memblock.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
+#include <asm/setup.h>
 #include <asm/drmem.h>
 #include <asm/kexec_ranges.h>
 #include <asm/crashdump-ppc64.h>
@@ -925,6 +926,40 @@ out:
        return ret;
 }
 
+/**
+ * kexec_fdt_totalsize_ppc64 - 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.
+ */
+unsigned int kexec_fdt_totalsize_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;
+
+       /*
+        * For kdump kernel, also 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;
+}
+
 /**
  * setup_new_fdt_ppc64 - Update the flattend device-tree of the kernel
  *                       being loaded.