[RESEND PATCH v5 13/31] powernv/fadump: reset metadata address during clean up

Hari Bathini hbathini at linux.ibm.com
Tue Aug 27 21:38:53 AEST 2019


During kexec boot, metadata address needs to be reset to avoid running
into errors interpreting stale metadata address, in case the kexec'ed
kernel crashes before metadata address could be setup again.

Signed-off-by: Hari Bathini <hbathini at linux.ibm.com>
---

* Added check in fadump_cleanup() function for whether FADump is supported
  before proceeding with cleanup callbacks as this function can be called
  outside FADump code in shutdown and kexec paths which could crash the
  system on machines that do not support FADump.


 arch/powerpc/kernel/fadump-common.h          |    1 +
 arch/powerpc/kernel/fadump.c                 |    5 +++++
 arch/powerpc/platforms/powernv/opal-fadump.c |   10 ++++++++++
 arch/powerpc/platforms/pseries/rtas-fadump.c |    3 +++
 4 files changed, 19 insertions(+)

diff --git a/arch/powerpc/kernel/fadump-common.h b/arch/powerpc/kernel/fadump-common.h
index 0acf412..d2dd117 100644
--- a/arch/powerpc/kernel/fadump-common.h
+++ b/arch/powerpc/kernel/fadump-common.h
@@ -120,6 +120,7 @@ struct fadump_ops {
 	int	(*fadump_register)(struct fw_dump *fadump_config);
 	int	(*fadump_unregister)(struct fw_dump *fadump_config);
 	int	(*fadump_invalidate)(struct fw_dump *fadump_config);
+	void	(*fadump_cleanup)(struct fw_dump *fadump_config);
 	int	(*fadump_process)(struct fw_dump *fadump_config);
 	void	(*fadump_region_show)(struct fw_dump *fadump_config,
 				      struct seq_file *m);
diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index a086a09..02ccfd4 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -821,6 +821,9 @@ static int register_fadump(void)
 
 void fadump_cleanup(void)
 {
+	if (!fw_dump.fadump_supported)
+		return;
+
 	/* Invalidate the registration only if dump is active. */
 	if (fw_dump.dump_active) {
 		pr_debug("Invalidating firmware-assisted dump registration\n");
@@ -830,6 +833,8 @@ void fadump_cleanup(void)
 		fw_dump.ops->fadump_unregister(&fw_dump);
 		free_crash_memory_ranges();
 	}
+
+	fw_dump.ops->fadump_cleanup(&fw_dump);
 }
 
 static void fadump_free_reserved_memory(unsigned long start_pfn,
diff --git a/arch/powerpc/platforms/powernv/opal-fadump.c b/arch/powerpc/platforms/powernv/opal-fadump.c
index e5c4700..e466f7e 100644
--- a/arch/powerpc/platforms/powernv/opal-fadump.c
+++ b/arch/powerpc/platforms/powernv/opal-fadump.c
@@ -110,6 +110,15 @@ static int opal_fadump_invalidate(struct fw_dump *fadump_conf)
 	return -EIO;
 }
 
+static void opal_fadump_cleanup(struct fw_dump *fadump_conf)
+{
+	s64 ret;
+
+	ret = opal_mpipl_register_tag(OPAL_MPIPL_TAG_KERNEL, 0);
+	if (ret != OPAL_SUCCESS)
+		pr_warn("Could not reset (%llu) kernel metadata tag!\n", ret);
+}
+
 static int __init opal_fadump_process(struct fw_dump *fadump_conf)
 {
 	return -EINVAL;
@@ -150,6 +159,7 @@ static struct fadump_ops opal_fadump_ops = {
 	.fadump_register		= opal_fadump_register,
 	.fadump_unregister		= opal_fadump_unregister,
 	.fadump_invalidate		= opal_fadump_invalidate,
+	.fadump_cleanup			= opal_fadump_cleanup,
 	.fadump_process			= opal_fadump_process,
 	.fadump_region_show		= opal_fadump_region_show,
 	.fadump_trigger			= opal_fadump_trigger,
diff --git a/arch/powerpc/platforms/pseries/rtas-fadump.c b/arch/powerpc/platforms/pseries/rtas-fadump.c
index 4111ee9..6164c5a 100644
--- a/arch/powerpc/platforms/pseries/rtas-fadump.c
+++ b/arch/powerpc/platforms/pseries/rtas-fadump.c
@@ -235,6 +235,8 @@ static int rtas_fadump_invalidate(struct fw_dump *fadump_conf)
 	return 0;
 }
 
+static void rtas_fadump_cleanup(struct fw_dump *fadump_conf) { }
+
 #define RTAS_FADUMP_GPR_MASK			0xffffff0000000000
 static inline int rtas_fadump_gpr_index(u64 id)
 {
@@ -508,6 +510,7 @@ static struct fadump_ops rtas_fadump_ops = {
 	.fadump_register		= rtas_fadump_register,
 	.fadump_unregister		= rtas_fadump_unregister,
 	.fadump_invalidate		= rtas_fadump_invalidate,
+	.fadump_cleanup			= rtas_fadump_cleanup,
 	.fadump_process			= rtas_fadump_process,
 	.fadump_region_show		= rtas_fadump_region_show,
 	.fadump_trigger			= rtas_fadump_trigger,



More information about the Linuxppc-dev mailing list