[PATCH 26/28] kdb,panic,debug_core: Allow the debug core to receive a panic before smp_send_stop()

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jason Wessel
Date: Friday, February 12, 2010 - 3:35 pm

It is highly desirable to trap into kdb on panic, and in order
to do so the notifier must be called before smp_send_stop(),
else the debug_core will not be able to correctly trap
all the CPUs.

CC: Ingo Molnar <mingo@elte.hu>
CC: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
---
 kernel/debug/debug_core.c |   18 ++++++++++++++++++
 kernel/panic.c            |    7 ++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
index bfdba97..580fc3b 100644
--- a/kernel/debug/debug_core.c
+++ b/kernel/debug/debug_core.c
@@ -754,11 +754,27 @@ static struct sysrq_key_op sysrq_dbg_op = {
 };
 #endif
 
+static int kgdb_panic_event(struct notifier_block *self,
+			    unsigned long val,
+			    void *data)
+{
+	if (dbg_kdb_mode)
+		kdb_printf("PANIC: %s\n", (char *)data);
+	kgdb_breakpoint();
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block kgdb_panic_event_nb = {
+       .notifier_call  = kgdb_panic_event,
+};
+
 static void kgdb_register_callbacks(void)
 {
 	if (!kgdb_io_module_registered) {
 		kgdb_io_module_registered = 1;
 		kgdb_arch_init();
+		atomic_notifier_chain_register(&panic_notifier_list,
+					       &kgdb_panic_event_nb);
 #ifdef CONFIG_MAGIC_SYSRQ
 		register_sysrq_key('g', &sysrq_dbg_op);
 #endif
@@ -778,6 +794,8 @@ static void kgdb_unregister_callbacks(void)
 	 */
 	if (kgdb_io_module_registered) {
 		kgdb_io_module_registered = 0;
+		atomic_notifier_chain_unregister(&panic_notifier_list,
+					       &kgdb_panic_event_nb);
 		kgdb_arch_exit();
 #ifdef CONFIG_MAGIC_SYSRQ
 		unregister_sysrq_key('g', &sysrq_dbg_op);
diff --git a/kernel/panic.c b/kernel/panic.c
index c787333..428d15b 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -66,10 +66,13 @@ NORET_TYPE void panic(const char * fmt, ...)
 	 */
 	preempt_disable();
 
-	bust_spinlocks(1);
 	va_start(args, fmt);
 	vsnprintf(buf, sizeof(buf), fmt, args);
 	va_end(args);
+
+	atomic_notifier_call_chain(&panic_notifier_list, 0, buf);
+
+	bust_spinlocks(1);
 	printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
 #ifdef CONFIG_DEBUG_BUGVERBOSE
 	dump_stack();
@@ -91,8 +94,6 @@ NORET_TYPE void panic(const char * fmt, ...)
 	 */
 	smp_send_stop();
 
-	atomic_notifier_call_chain(&panic_notifier_list, 0, buf);
-
 	bust_spinlocks(0);
 
 	if (!panic_blink)
-- 
1.6.4.rc1

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/28] kgdb, kdb proposed merge for 2.6.34, Jason Wessel, (Fri Feb 12, 3:35 pm)
[PATCH 02/28] Separate the gdbstub from the debug core, Jason Wessel, (Fri Feb 12, 3:35 pm)
[PATCH 07/28] kdb: core for kgdb back end (1 of 2), Jason Wessel, (Fri Feb 12, 3:35 pm)
[PATCH 08/28] kdb: core for kgdb back end (2 of 2), Jason Wessel, (Fri Feb 12, 3:35 pm)
[PATCH 09/28] kgdb: core changes to support kdb, Jason Wessel, (Fri Feb 12, 3:35 pm)
[PATCH 16/28] kgdb: remove post_primary_code references, Jason Wessel, (Fri Feb 12, 3:35 pm)
[PATCH 17/28] x86,kgdb: Add low level debug hook, Jason Wessel, (Fri Feb 12, 3:35 pm)
[PATCH 26/28] kdb,panic,debug_core: Allow the debug core t ..., Jason Wessel, (Fri Feb 12, 3:35 pm)
Re: [PATCH 18/28] powerpc,kgdb: Introduce low level trap c ..., Benjamin Herrenschmidt, (Sun Feb 14, 4:29 pm)
Re: [PATCH 18/28] powerpc,kgdb: Introduce low level trap c ..., Benjamin Herrenschmidt, (Tue Feb 16, 3:56 pm)
Re: [PATCH 26/28] kdb,panic,debug_core: Allow the debug co ..., Eric W. Biederman, (Wed Feb 17, 9:02 pm)
Re: [PATCH 08/28] kdb: core for kgdb back end (2 of 2), Eric W. Biederman, (Wed Feb 17, 10:00 pm)
Re: [PATCH 08/28] kdb: core for kgdb back end (2 of 2), Jason Wessel, (Thu Feb 18, 8:04 am)
Re: [PATCH 08/28] kdb: core for kgdb back end (2 of 2), Eric W. Biederman, (Thu Feb 18, 9:35 am)
Re: [PATCH 08/28] kdb: core for kgdb back end (2 of 2), Jason Wessel, (Thu Feb 18, 10:06 am)
Re: [PATCH 08/28] kdb: core for kgdb back end (2 of 2), Scott Lurndal, (Thu Feb 18, 11:07 am)
Re: [PATCH 08/28] kdb: core for kgdb back end (2 of 2), Jason Wessel, (Thu Feb 18, 11:36 am)
Re: [PATCH 08/28] kdb: core for kgdb back end (2 of 2), Jason Wessel, (Thu Feb 18, 12:08 pm)