From: Mahesh Salgaonkar <mah...@linux.vnet.ibm.com>

fadump fails to register when there are holes in reserved memory area.
This can happen if user has hot-removed a memory that falls in the fadump
reserved memory area. Throw a meaningful error message to the user in
such case.

Signed-off-by: Mahesh Salgaonkar <mah...@linux.vnet.ibm.com>
---
 arch/powerpc/kernel/fadump.c |   33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index 166e71635921..44a29e4d419c 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -234,6 +234,36 @@ static int is_boot_memory_area_contiguous(void)
        return ret;
 }
 
+/*
+ * Returns 1, if there are no holes in reserved memory area,
+ * 0 otherwise.
+ */
+static int is_reserved_memory_area_contiguous(void)
+{
+       struct memblock_region *reg;
+       unsigned long start, end;
+       unsigned long d_start = fw_dump.reserve_dump_area_start;
+       unsigned long d_end = d_start + fw_dump.reserve_dump_area_size;
+       int ret = 0;
+
+       for_each_memblock(memory, reg) {
+               start = max(d_start, (unsigned long)reg->base);
+               end = min(d_end, (unsigned long)(reg->base + reg->size));
+               if (d_start < end) {
+                       /* Memory hole from d_start to start */
+                       if (start > d_start)
+                               break;
+
+                       if (end == d_end) {
+                               ret = 1;
+                               break;
+                       }
+                       d_start = end + 1;
+               }
+       }
+       return ret;
+}
+
 /* Print firmware assisted dump configurations for debugging purpose. */
 static void fadump_show_config(void)
 {
@@ -602,6 +632,9 @@ static int register_fw_dump(struct fadump_mem_struct *fdm)
                if (!is_boot_memory_area_contiguous())
                        pr_err("Can't have holes in boot memory area while "
                               "registering fadump\n");
+               else if (!is_reserved_memory_area_contiguous())
+                       pr_err("Can't have holes in reserved memory area while"
+                              " registering fadump\n");
 
                printk(KERN_ERR "Failed to register firmware-assisted kernel"
                        " dump. Parameter Error(%d).\n", rc);

Reply via email to