diff mbox series

[v3,15/16] powernv/fadump: consider f/w load area

Message ID 156149567448.9094.13568480898134973004.stgit@hbathini.in.ibm.com (mailing list archive)
State Superseded
Headers show
Series Add FADump support on PowerNV platform | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch next (c7d64b560ce80d8c44f082eee8352f0778a73195)
snowpatch_ozlabs/checkpatch success total: 0 errors, 0 warnings, 0 checks, 145 lines checked

Commit Message

Hari Bathini June 25, 2019, 8:47 p.m. UTC
OPAL loads kernel & initrd at 512MB offset (256MB size), also exported
as ibm,opal/dump/fw-load-area. So, if boot memory size of FADump is
less than 768MB, kernel memory to be exported as '/proc/vmcore' would
be overwritten by f/w while loading kernel & initrd. To avoid such a
scenario, enforce a minimum boot memory size of 768MB on OPAL platform.

Also, skip using FADump if a newer F/W version loads kernel & initrd
above 768MB.

Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
---
 arch/powerpc/kernel/fadump-common.h          |   11 +---------
 arch/powerpc/kernel/fadump.c                 |   11 +++++++++-
 arch/powerpc/platforms/powernv/opal-fadump.c |   28 ++++++++++++++++++++++++++
 arch/powerpc/platforms/powernv/opal-fadump.h |    7 +++++++
 arch/powerpc/platforms/pseries/rtas-fadump.c |    6 ++++++
 arch/powerpc/platforms/pseries/rtas-fadump.h |   10 +++++++++
 6 files changed, 62 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/arch/powerpc/kernel/fadump-common.h b/arch/powerpc/kernel/fadump-common.h
index fea6872..64e1f9e 100644
--- a/arch/powerpc/kernel/fadump-common.h
+++ b/arch/powerpc/kernel/fadump-common.h
@@ -23,16 +23,6 @@ 
 #define RMA_START	0x0
 #define RMA_END		(ppc64_rma_size)
 
-/*
- * On some Power systems where RMO is 128MB, it still requires minimum of
- * 256MB for kernel to boot successfully. When kdump infrastructure is
- * configured to save vmcore over network, we run into OOM issue while
- * loading modules related to network setup. Hence we need additional 64M
- * of memory to avoid OOM issue.
- */
-#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
 
@@ -169,6 +159,7 @@  struct fadump_ops {
 	ulong	(*init_fadump_mem_struct)(struct fw_dump *fadump_config);
 	ulong	(*get_kernel_metadata_size)(void);
 	int	(*setup_kernel_metadata)(struct fw_dump *fadump_config);
+	ulong	(*get_bootmem_min)(void);
 	int	(*register_fadump)(struct fw_dump *fadump_config);
 	int	(*unregister_fadump)(struct fw_dump *fadump_config);
 	int	(*invalidate_fadump)(struct fw_dump *fadump_config);
diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index 569221a..d9e44c8 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -358,7 +358,8 @@  static inline unsigned long fadump_calculate_reserve_size(void)
 	if (memory_limit && size > memory_limit)
 		size = memory_limit;
 
-	return (size > MIN_BOOT_MEM ? size : MIN_BOOT_MEM);
+	return (size > fw_dump.ops->get_bootmem_min() ? size :
+		fw_dump.ops->get_bootmem_min());
 }
 
 /*
@@ -573,6 +574,14 @@  int __init fadump_reserve_mem(void)
 				ALIGN(fw_dump.boot_memory_size,
 							FADUMP_CMA_ALIGNMENT);
 #endif
+
+		if (fw_dump.boot_memory_size < fw_dump.ops->get_bootmem_min()) {
+			pr_err("Can't enable fadump with boot memory size (0x%lx) less than 0x%lx\n",
+			       fw_dump.boot_memory_size,
+			       fw_dump.ops->get_bootmem_min());
+			goto error_out;
+		}
+
 		fw_dump.rmr_source_len = fw_dump.boot_memory_size;
 		if (!fadump_get_rmr_regions()) {
 			pr_err("Too many holes in boot memory area to enable fadump\n");
diff --git a/arch/powerpc/platforms/powernv/opal-fadump.c b/arch/powerpc/platforms/powernv/opal-fadump.c
index 2c87812..51f8342 100644
--- a/arch/powerpc/platforms/powernv/opal-fadump.c
+++ b/arch/powerpc/platforms/powernv/opal-fadump.c
@@ -230,6 +230,11 @@  static int opal_setup_kernel_metadata(struct fw_dump *fadump_conf)
 	return err;
 }
 
+static ulong opal_get_bootmem_min(void)
+{
+	return OPAL_MIN_BOOT_MEM;
+}
+
 static int opal_register_fadump(struct fw_dump *fadump_conf)
 {
 	int i, err = -EIO;
@@ -516,6 +521,7 @@  static struct fadump_ops opal_fadump_ops = {
 	.init_fadump_mem_struct		= opal_init_fadump_mem_struct,
 	.get_kernel_metadata_size	= opal_get_kernel_metadata_size,
 	.setup_kernel_metadata		= opal_setup_kernel_metadata,
+	.get_bootmem_min		= opal_get_bootmem_min,
 	.register_fadump		= opal_register_fadump,
 	.unregister_fadump		= opal_unregister_fadump,
 	.invalidate_fadump		= opal_invalidate_fadump,
@@ -528,6 +534,7 @@  int __init opal_dt_scan_fadump(struct fw_dump *fadump_conf, ulong node)
 {
 	unsigned long dn;
 	const __be32 *prop;
+	int i, len;
 
 	/*
 	 * Check if Firmware-Assisted Dump is supported. if yes, check
@@ -544,6 +551,27 @@  int __init opal_dt_scan_fadump(struct fw_dump *fadump_conf, ulong node)
 		return 1;
 	}
 
+	prop = of_get_flat_dt_prop(dn, "fw-load-area", &len);
+	if (prop) {
+		/*
+		 * Each f/w load area is an (address,size) pair,
+		 * 2 cells each, totalling 4 cells per range.
+		 */
+		for (i = 0; i < len / (sizeof(*prop) * 4); i++) {
+			u64 base, end;
+
+			base = of_read_number(prop + (i * 4) + 0, 2);
+			end = base;
+			end += of_read_number(prop + (i * 4) + 2, 2);
+			if (end > OPAL_MIN_BOOT_MEM) {
+				pr_err("F/W load area: 0x%llx-0x%llx\n",
+				       base, end);
+				pr_err("F/W version not supported!\n");
+				return 1;
+			}
+		}
+	}
+
 	fadump_conf->ops		= &opal_fadump_ops;
 	fadump_conf->fadump_platform	= FADUMP_PLATFORM_POWERNV;
 	fadump_conf->fadump_supported	= 1;
diff --git a/arch/powerpc/platforms/powernv/opal-fadump.h b/arch/powerpc/platforms/powernv/opal-fadump.h
index fe293c8..400e79a 100644
--- a/arch/powerpc/platforms/powernv/opal-fadump.h
+++ b/arch/powerpc/platforms/powernv/opal-fadump.h
@@ -15,6 +15,13 @@ 
 
 #include <asm/reg.h>
 
+/*
+ * With kernel & initrd loaded at 512MB (with 256MB size), enforce a minimum
+ * boot memory size of 768MB to ensure f/w loading kernel and initrd doesn't
+ * mess with crash'ed kernel's memory during MPIPL.
+ */
+#define OPAL_MIN_BOOT_MEM	(0x30000000UL)
+
 /* FADump structure format version */
 #define FADUMP_VERSION				0x1
 
diff --git a/arch/powerpc/platforms/pseries/rtas-fadump.c b/arch/powerpc/platforms/pseries/rtas-fadump.c
index bc53a38..2d37b6d 100644
--- a/arch/powerpc/platforms/pseries/rtas-fadump.c
+++ b/arch/powerpc/platforms/pseries/rtas-fadump.c
@@ -148,6 +148,11 @@  static int pseries_setup_kernel_metadata(struct fw_dump *fadump_conf)
 	return 0;
 }
 
+static ulong pseries_get_bootmem_min(void)
+{
+	return PSERIES_MIN_BOOT_MEM;
+}
+
 static int pseries_register_fadump(struct fw_dump *fadump_conf)
 {
 	int rc, err;
@@ -479,6 +484,7 @@  static struct fadump_ops pseries_fadump_ops = {
 	.init_fadump_mem_struct		= pseries_init_fadump_mem_struct,
 	.get_kernel_metadata_size	= pseries_get_kernel_metadata_size,
 	.setup_kernel_metadata		= pseries_setup_kernel_metadata,
+	.get_bootmem_min		= pseries_get_bootmem_min,
 	.register_fadump		= pseries_register_fadump,
 	.unregister_fadump		= pseries_unregister_fadump,
 	.invalidate_fadump		= pseries_invalidate_fadump,
diff --git a/arch/powerpc/platforms/pseries/rtas-fadump.h b/arch/powerpc/platforms/pseries/rtas-fadump.h
index d61e5d9..feab2d7 100644
--- a/arch/powerpc/platforms/pseries/rtas-fadump.h
+++ b/arch/powerpc/platforms/pseries/rtas-fadump.h
@@ -13,6 +13,16 @@ 
 #ifndef __PPC64_PSERIES_FA_DUMP_H__
 #define __PPC64_PSERIES_FA_DUMP_H__
 
+/*
+ * On some Power systems where RMO is 128MB, it still requires minimum of
+ * 256MB for kernel to boot successfully. When kdump infrastructure is
+ * configured to save vmcore over network, we run into OOM issue while
+ * loading modules related to network setup. Hence we need additional 64M
+ * of memory to avoid OOM issue.
+ */
+#define PSERIES_MIN_BOOT_MEM	(((RMA_END < (0x1UL << 28)) ? (0x1UL << 28) : \
+				 RMA_END) + (0x1UL << 26))
+
 /* Firmware provided dump sections */
 #define PSERIES_FADUMP_CPU_STATE_DATA	0x0001
 #define PSERIES_FADUMP_HPTE_REGION	0x0002