History

kgdb: don't use a notifier to enter kgdb at panic; call directly

Right now kgdb/kdb hooks up to debug panics by registering for the panic notifier. This works OK except that it means that kgdb/kdb gets called _after_ the CPUs in the system are taken offline. That means that if anything important was happening on those CPUs (like something that might have contributed to the panic) you can't debug them. Specifically I ran into a case where I got a panic because a task was "blocked for more than 120 seconds" which was detected on CPU 2. I nicely got shown stack traces in the kernel log for all CPUs including CPU 0, which was running 'PID: 111 Comm: kworker/0:1H' and was in the middle of __mmc_switch(). I then ended up at the kdb prompt where switched over to kgdb to try to look at local variables of the process on CPU 0. I found that I couldn't. Digging more, I found that I had no info on any tasks running on CPUs other than CPU 2 and that asking kdb for help showed me "Error: no saved data for this cpu". This was because all the CPUs were offline. Let's move the entry of kdb/kgdb to a direct call from panic() and stop using the generic notifier. Putting a direct call in allows us to order things more properly and it also doesn't seem like we're breaking any abstractions by calling into the debugger from the panic function. Daniel said: : This patch changes the way kdump and kgdb interact with each other. : However it would seem rather odd to have both tools simultaneously armed : and, even if they were, the user still has the option to use panic_timeout : to force a kdump to happen. Thus I think the change of order is : acceptable.

Douglas Anderson committed 7 years ago

Commit 7d92bda1 parent ac7c3e43 files · +21 −20Browse files

Showing the changes to kernel/debug/debug_core.c (1 of 3 files). Show all

Unified · Split

kernel/debug/debug_core.c+11−20
@@ -893,30 +893,25 @@ static struct sysrq_key_op sysrq_dbg_op = { · 892 unmodified lines
893893 };
894894 #endif
895895
896−static int kgdb_panic_event(struct notifier_block *self,
897− unsigned long val,
898− void *data)
896+void kgdb_panic(const char *msg)
899897 {
898+ if (!kgdb_io_module_registered)
899+ return;
900+
900901 /*
901− * Avoid entering the debugger if we were triggered due to a panic
902− * We don't want to get stuck waiting for input from user in such case.
903− * panic_timeout indicates the system should automatically
902+ * We don't want to get stuck waiting for input from user if
903+ * "panic_timeout" indicates the system should automatically
904904 * reboot on panic.
905905 */
906906 if (panic_timeout)
907− return NOTIFY_DONE;
907+ return;
908908
909909 if (dbg_kdb_mode)
910− kdb_printf("PANIC: %s\n", (char *)data);
910+ kdb_printf("PANIC: %s\n", msg);
911+
911912 kgdb_breakpoint();
912− return NOTIFY_DONE;
913913 }
914914
915−static struct notifier_block kgdb_panic_event_nb = {
916− .notifier_call = kgdb_panic_event,
917− .priority = INT_MAX,
918−};
919−
920915 void __weak kgdb_arch_late(void)
921916 {
922917 }
@@ -965,8 +960,6 @@ static void kgdb_register_callbacks(void) · 42 unmodified lines
965960 kgdb_arch_late();
966961 register_module_notifier(&dbg_module_load_nb);
967962 register_reboot_notifier(&dbg_reboot_notifier);
968− atomic_notifier_chain_register(&panic_notifier_list,
969− &kgdb_panic_event_nb);
970963 #ifdef CONFIG_MAGIC_SYSRQ
971964 register_sysrq_key('g', &sysrq_dbg_op);
972965 #endif
@@ -980,16 +973,14 @@ static void kgdb_register_callbacks(void) · 7 unmodified lines
980973 static void kgdb_unregister_callbacks(void)
981974 {
982975 /*
983− * When this routine is called KGDB should unregister from the
984− * panic handler and clean up, making sure it is not handling any
976+ * When this routine is called KGDB should unregister from
977+ * handlers and clean up, making sure it is not handling any
985978 * break exceptions at the time.
986979 */
987980 if (kgdb_io_module_registered) {
988981 kgdb_io_module_registered = 0;
989982 unregister_reboot_notifier(&dbg_reboot_notifier);
990983 unregister_module_notifier(&dbg_module_load_nb);
991− atomic_notifier_chain_unregister(&panic_notifier_list,
992− &kgdb_panic_event_nb);
993984 kgdb_arch_exit();
994985 #ifdef CONFIG_MAGIC_SYSRQ
995986 unregister_sysrq_key('g', &sysrq_dbg_op);