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
948 kgdb_breakpoint();948 kgdb_breakpoint();
949}949}
950 950
951static 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
951void __weak kgdb_arch_late(void)959void __weak kgdb_arch_late(void)
952{960{
953}961}
@@ -958,6 +966,9 @@ void __init dbg_late_init(void) · 4 unmodified lines
958 if (kgdb_io_module_registered)966 if (kgdb_io_module_registered)
959 kgdb_arch_late();967 kgdb_arch_late();
960 kdb_init(KDB_INIT_FULL);968 kdb_init(KDB_INIT_FULL);
969
970 if (kgdb_io_module_registered && kgdb_break_asap)
971 kgdb_initial_breakpoint();
961}972}
962 973
963static int974static int
@@ -1053,14 +1064,6 @@ void kgdb_schedule_breakpoint(void) · 89 unmodified lines
1053}1064}
1054EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);1065EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
1055 1066
1056static 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
1064/**1067/**
1065 * kgdb_register_io_module - register KGDB IO module1068 * kgdb_register_io_module - register KGDB IO module
1066 * @new_dbg_io_ops: the io ops vector1069 * @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
1097 /* Arm KGDB now. */1100 /* Arm KGDB now. */
1098 kgdb_register_callbacks();1101 kgdb_register_callbacks();
1099 1102
1100 if (kgdb_break_asap)1103 if (kgdb_break_asap &&
1104 (!dbg_is_early || IS_ENABLED(CONFIG_ARCH_HAS_EARLY_DEBUG)))
1101 kgdb_initial_breakpoint();1105 kgdb_initial_breakpoint();
1102 1106
1103 return 0;1107 return 0;
@@ -1167,7 +1171,8 @@ static int __init opt_kgdb_wait(char *str) · 63 unmodified lines
1167 kgdb_break_asap = 1;1171 kgdb_break_asap = 1;
1168 1172
1169 kdb_init(KDB_INIT_EARLY);1173 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))
1171 kgdb_initial_breakpoint();1176 kgdb_initial_breakpoint();
1172 1177
1173 return 0;1178 return 0;