]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
UBUNTU: SAUCE: powerpc/fadump: set an upper limit for boot memory size (V2)
authorHari Bathini <hbathini@linux.vnet.ibm.com>
Wed, 1 Mar 2017 12:55:27 +0000 (05:55 -0700)
committerTim Gardner <tim.gardner@canonical.com>
Wed, 1 Mar 2017 12:57:13 +0000 (05:57 -0700)
BugLink: http://bugs.launchpad.net/bugs/1655241
http://patchwork.ozlabs.org/patch/732136

By default, 5% of system RAM is reserved for preserving boot memory.
Alternatively, a user can specify the amount of memory to reserve.
See Documentation/powerpc/firmware-assisted-dump.txt for details. In
addition to the memory reserved for preserving boot memory, some more
memory is reserved, to save HPTE region, CPU state data and ELF core
headers.

Memory Reservation during first kernel looks like below:

  Low memory                                        Top of memory
  0      boot memory size                                       |
  |           |                       |<--Reserved dump area -->|
  V           V                       |   Permanent Reservation V
  +-----------+----------/ /----------+---+----+-----------+----+
  |           |                       |CPU|HPTE|  DUMP     |ELF |
  +-----------+----------/ /----------+---+----+-----------+----+
        |                                           ^
        |                                           |
        \                                           /
         -------------------------------------------
          Boot memory content gets transferred to
          reserved area by firmware at the time of
          crash

This implicitly means that the sum of the sizes of boot memory, CPU
state data, HPTE region, DUMP preserving area and ELF core headers
can't be greater than the total memory size. But currently, a user is
allowed to specify any value as boot memory size. So, the above rule
is violated when a boot memory size around 50% of the total available
memory is specified. As the kernel is not handling this currently, it
may lead to undefined behavior. Fix it by setting an upper limit for
boot memory size to 25% of the total available memory. Also, instead
of using memblock_end_of_DRAM(), which doesn't take the holes, if any,
in the memory layout into account, use memblock_phys_mem_size() to
calculate the percentage of total available memory.

Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com>
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
arch/powerpc/include/asm/fadump.h
arch/powerpc/kernel/fadump.c

index 0031806475f0f1b22645336d427bfee9fd9b0462..3d5e8ef5f17c5c03613bab5f423616d2d7df956d 100644 (file)
@@ -43,6 +43,9 @@
 #define MIN_BOOT_MEM   (((RMA_END < (0x1UL << 28)) ? (0x1UL << 28) : RMA_END) \
                        + (0x1UL << 26))
 
+/* The upper limit percentage for user specified boot memory size (25%) */
+#define MAX_BOOT_MEM_RATIO                     4
+
 #define memblock_num_regions(memblock_type)    (memblock.memblock_type.cnt)
 
 /* Firmware provided dump sections */
index 8f0c7c5d93f2de840826bc22f115d5528c20ea1c..82f0ef339a4fd14c0a12e2653985c18c724ff4ba 100644 (file)
@@ -216,11 +216,25 @@ static inline unsigned long fadump_calculate_reserve_size(void)
         * Check if the size is specified through fadump_reserve_mem= cmdline
         * option. If yes, then use that.
         */
-       if (fw_dump.reserve_bootvar)
+       if (fw_dump.reserve_bootvar) {
+               unsigned long max_size;
+
+               /*
+                * Adjust if the boot memory size specified is above
+                * the upper limit.
+                */
+               max_size = memblock_phys_mem_size() / MAX_BOOT_MEM_RATIO;
+               if (fw_dump.reserve_bootvar > max_size) {
+                       fw_dump.reserve_bootvar = max_size;
+                       pr_info("Adjusted boot memory size to %luMB\n",
+                               (fw_dump.reserve_bootvar >> 20));
+               }
+
                return fw_dump.reserve_bootvar;
+       }
 
        /* divide by 20 to get 5% of value */
-       size = memblock_end_of_DRAM() / 20;
+       size = memblock_phys_mem_size() / 20;
 
        /* round it down in multiples of 256 */
        size = size & ~0x0FFFFFFFUL;