diff mbox series

[1/2] powerpc/fadump: exclude memory holes while reserving memory in second kernel

Message ID 152286202560.2738.7385812464895685351.stgit@hbathini.in.ibm.com
State New
Headers show
Series [1/2] powerpc/fadump: exclude memory holes while reserving memory in second kernel | expand

Commit Message

Hari Bathini April 4, 2018, 5:13 p.m. UTC
From: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>

The second kernel, during early boot after the crash, reserves rest of
the memory above boot memory size to make sure it does not touch any of the
dump memory area. It uses memblock_reserve() that reserves the specified
memory region irrespective of memory holes present within that region.
There are chances where previous kernel would have hot removed some of
its memory leaving memory holes behind. In such cases fadump kernel reports
incorrect number of reserved pages through arch_reserved_kernel_pages()
hook causing kernel to hang or panic.

Fix this by excluding memory holes while reserving rest of the memory
above boot memory size during second kernel boot after crash.

Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com>
---
 arch/powerpc/kernel/fadump.c |   23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index 3c2c268..b5218aa 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -380,7 +380,11 @@  int __init fadump_reserve_mem(void)
 		memory_boundary = memblock_end_of_DRAM();
 
 	if (fw_dump.dump_active) {
-		printk(KERN_INFO "Firmware-assisted dump is active.\n");
+		struct memblock_region *reg;
+		unsigned long mstart, mend, msize;
+
+		pr_info("Firmware-assisted dump is active.\n");
+
 		/*
 		 * If last boot has crashed then reserve all the memory
 		 * above boot_memory_size so that we don't touch it until
@@ -389,11 +393,18 @@  int __init fadump_reserve_mem(void)
 		 */
 		base = fw_dump.boot_memory_size;
 		size = memory_boundary - base;
-		memblock_reserve(base, size);
-		printk(KERN_INFO "Reserved %ldMB of memory at %ldMB "
-				"for saving crash dump\n",
-				(unsigned long)(size >> 20),
-				(unsigned long)(base >> 20));
+		for_each_memblock(memory, reg) {
+			mstart = max_t(unsigned long, base, reg->base);
+			mend = reg->base + reg->size;
+			mend = min(base + size, mend);
+
+			if (mstart < mend) {
+				msize = mend - mstart;
+				memblock_reserve(mstart, msize);
+				pr_info("Reserved %ldMB of memory at %#016lx for saving crash dump\n",
+					(msize >> 20), mstart);
+			}
+		}
 
 		fw_dump.fadumphdr_addr =
 				be64_to_cpu(fdm_active->rmr_region.destination_address) +