History

kgdb: Delay "kgdbwait" to dbg_late_init() by default

Using kgdb requires at least some level of architecture-level initialization. If nothing else, it relies on the architecture to pass breakpoints / crashes onto kgdb. On some architectures this all works super early, specifically it starts working at some point in time before Linux parses early_params's. On other architectures it doesn't. A survey of a few platforms: a) x86: Presumably it all works early since "ekgdboc" is documented to work here. b) arm64: Catching crashes works; with a simple patch breakpoints can also be made to work. c) arm: Nothing in kgdb works until paging_init() -> devicemaps_init() -> early_trap_init() Let's be conservative and, by default, process "kgdbwait" (which tells the kernel to drop into the debugger ASAP at boot) a bit later at dbg_late_init() time. If an architecture has tested it and wants to re-enable super early debugging, they can select the ARCH_HAS_EARLY_DEBUG KConfig option. We'll do this for x86 to start. It should be noted that dbg_late_init() is still called quite early in the system. Note that this patch doesn't affect when kgdb runs its init. If kgdb is set to initialize early it will still initialize when parsing early_param's. This patch _only_ inhibits the initial breakpoint from "kgdbwait". This means: * Without any extra patches arm64 platforms will at least catch crashes after kgdb inits. * arm platforms will catch crashes (and could handle a hardcoded kgdb_breakpoint()) any time after early_trap_init() runs, even before dbg_late_init().

Douglas Anderson committed 6 years ago

Commit b1a57bb1 parent 68e55f63 files · +34 −10Browse files

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

Unified · Split

kernel/debug/debug_core.c+15−10
@@ -948,6 +948,14 @@ void kgdb_panic(const char *msg) · 947 unmodified lines
948948 kgdb_breakpoint();
949949 }
950950
951+static void kgdb_initial_breakpoint(void)
952+{
953+ kgdb_break_asap = 0;
954+
955+ pr_crit("Waiting for connection from remote gdb...\n");
956+ kgdb_breakpoint();
957+}
958+
951959 void __weak kgdb_arch_late(void)
952960 {
953961 }
@@ -958,6 +966,9 @@ void __init dbg_late_init(void) · 4 unmodified lines
958966 if (kgdb_io_module_registered)
959967 kgdb_arch_late();
960968 kdb_init(KDB_INIT_FULL);
969+
970+ if (kgdb_io_module_registered && kgdb_break_asap)
971+ kgdb_initial_breakpoint();
961972 }
962973
963974 static int
@@ -1053,14 +1064,6 @@ void kgdb_schedule_breakpoint(void) · 89 unmodified lines
10531064 }
10541065 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
10551066
1056−static void kgdb_initial_breakpoint(void)
1057−{
1058− kgdb_break_asap = 0;
1059−
1060− pr_crit("Waiting for connection from remote gdb...\n");
1061− kgdb_breakpoint();
1062−}
1063−
10641067 /**
10651068 * kgdb_register_io_module - register KGDB IO module
10661069 * @new_dbg_io_ops: the io ops vector
@@ -1097,7 +1100,8 @@ int kgdb_register_io_module(struct kgdb_io *new_dbg_io_ops) · 30 unmodified lines
10971100 /* Arm KGDB now. */
10981101 kgdb_register_callbacks();
10991102
1100− if (kgdb_break_asap)
1103+ if (kgdb_break_asap &&
1104+ (!dbg_is_early || IS_ENABLED(CONFIG_ARCH_HAS_EARLY_DEBUG)))
11011105 kgdb_initial_breakpoint();
11021106
11031107 return 0;
@@ -1167,7 +1171,8 @@ static int __init opt_kgdb_wait(char *str) · 63 unmodified lines
11671171 kgdb_break_asap = 1;
11681172
11691173 kdb_init(KDB_INIT_EARLY);
1170− if (kgdb_io_module_registered)
1174+ if (kgdb_io_module_registered &&
1175+ IS_ENABLED(CONFIG_ARCH_HAS_EARLY_DEBUG))
11711176 kgdb_initial_breakpoint();
11721177
11731178 return 0;