[PATCH] powerpc/fadump: set an upper limit for boot memory size

Subsystems: linux for powerpc (32-bit and 64-bit), the rest

STALE3452d

3 messages, 2 authors, 2017-02-21 · open the first message on its own page

[PATCH] powerpc/fadump: set an upper limit for boot memory size

From: Hari Bathini <hidden>
Date: 2017-02-15 15:30:48

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

The implicit rule here is that the sum of the sizes of boot memory,
CPU state data, HPTE region 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 closer to 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.

Signed-off-by: Hari Bathini <redacted>
---

This patch is based on top of reuse-crashkernel-parameter-for-fadump patchset
(https://lists.ozlabs.org/pipermail/linuxppc-dev/2017-January/152724.html)


 arch/powerpc/include/asm/fadump.h |    3 +++
 arch/powerpc/kernel/fadump.c      |   12 ++++++++++++
 2 files changed, 15 insertions(+)
diff --git a/arch/powerpc/include/asm/fadump.h b/arch/powerpc/include/asm/fadump.h
index 60b9108..a3de219 100644
--- a/arch/powerpc/include/asm/fadump.h
+++ b/arch/powerpc/include/asm/fadump.h
@@ -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 */
diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index de7d39a..d5107f4 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -222,6 +222,18 @@ static inline unsigned long fadump_calculate_reserve_size(void)
 				&size, &base);
 	if (ret == 0 && size > 0) {
 		fw_dump.reserve_bootvar = (unsigned long)size;
+		/*
+		 * Adjust if the boot memory size specified is above
+		 * the upper limit.
+		 */
+		if (fw_dump.reserve_bootvar >
+		    (memblock_end_of_DRAM() / MAX_BOOT_MEM_RATIO)) {
+			fw_dump.reserve_bootvar = (memblock_end_of_DRAM() /
+						   MAX_BOOT_MEM_RATIO);
+			pr_info("Adjusted boot memory size to %luMB\n",
+				(fw_dump.reserve_bootvar >> 20));
+		}
+
 		return fw_dump.reserve_bootvar;
 	}
 

Re: [PATCH] powerpc/fadump: set an upper limit for boot memory size

From: Michael Ellerman <mpe@ellerman.id.au>
Date: 2017-02-17 06:24:12

Hari Bathini [off-list ref] writes:
quoted hunk
diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index de7d39a..d5107f4 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -222,6 +222,18 @@ static inline unsigned long fadump_calculate_reserve_size(void)
 				&size, &base);
 	if (ret == 0 && size > 0) {
 		fw_dump.reserve_bootvar = (unsigned long)size;
+		/*
+		 * Adjust if the boot memory size specified is above
+		 * the upper limit.
+		 */
+		if (fw_dump.reserve_bootvar >
+		    (memblock_end_of_DRAM() / MAX_BOOT_MEM_RATIO)) {
Using memblock_end_of_DRAM() doesn't take into account the fact that you
might have holes in your memory layout.

Possibly on PowerVM that never happens, but I don't think we should
write the code to assume that, if possible.

cheers

Re: [PATCH] powerpc/fadump: set an upper limit for boot memory size

From: Hari Bathini <hidden>
Date: 2017-02-21 18:12:33

Hi Michael,


On Friday 17 February 2017 11:54 AM, Michael Ellerman wrote:
Hari Bathini [off-list ref] writes:
quoted
diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index de7d39a..d5107f4 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -222,6 +222,18 @@ static inline unsigned long fadump_calculate_reserve_size(void)
  				&size, &base);
  	if (ret == 0 && size > 0) {
  		fw_dump.reserve_bootvar = (unsigned long)size;
+		/*
+		 * Adjust if the boot memory size specified is above
+		 * the upper limit.
+		 */
+		if (fw_dump.reserve_bootvar >
+		    (memblock_end_of_DRAM() / MAX_BOOT_MEM_RATIO)) {
Using memblock_end_of_DRAM() doesn't take into account the fact that you
might have holes in your memory layout.

Possibly on PowerVM that never happens, but I don't think we should
write the code to assume that, if possible.
I think memblock_phys_mem_size() can fill in..

In the same file, memblock_end_of_DRAM() is also used when nothing
is specified through cmdline. Let me also change that and respin..

Thanks
Hari
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help