Commit 4402c153cb9c549cd21d6007ef0dfac50c8d148d

Authored by Jason Wessel
1 parent 5b778dadcd

kdb,debug_core: Allow the debug core to receive a panic notification

It is highly desirable to trap into kdb on panic.  The debug core will
attempt to register as the first in line for the panic notifier.

CC: Ingo Molnar <mingo@elte.hu>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>

Showing 1 changed file with 19 additions and 0 deletions Side-by-side Diff

kernel/debug/debug_core.c
... ... @@ -762,11 +762,28 @@
762 762 };
763 763 #endif
764 764  
  765 +static int kgdb_panic_event(struct notifier_block *self,
  766 + unsigned long val,
  767 + void *data)
  768 +{
  769 + if (dbg_kdb_mode)
  770 + kdb_printf("PANIC: %s\n", (char *)data);
  771 + kgdb_breakpoint();
  772 + return NOTIFY_DONE;
  773 +}
  774 +
  775 +static struct notifier_block kgdb_panic_event_nb = {
  776 + .notifier_call = kgdb_panic_event,
  777 + .priority = INT_MAX,
  778 +};
  779 +
765 780 static void kgdb_register_callbacks(void)
766 781 {
767 782 if (!kgdb_io_module_registered) {
768 783 kgdb_io_module_registered = 1;
769 784 kgdb_arch_init();
  785 + atomic_notifier_chain_register(&panic_notifier_list,
  786 + &kgdb_panic_event_nb);
770 787 #ifdef CONFIG_MAGIC_SYSRQ
771 788 register_sysrq_key('g', &sysrq_dbg_op);
772 789 #endif
... ... @@ -786,6 +803,8 @@
786 803 */
787 804 if (kgdb_io_module_registered) {
788 805 kgdb_io_module_registered = 0;
  806 + atomic_notifier_chain_unregister(&panic_notifier_list,
  807 + &kgdb_panic_event_nb);
789 808 kgdb_arch_exit();
790 809 #ifdef CONFIG_MAGIC_SYSRQ
791 810 unregister_sysrq_key('g', &sysrq_dbg_op);