Skip to content

Commit 162bc7f

Browse files
diandersDaniel Thompson
authored andcommitted
kdb: Don't back trace on a cpu that didn't round up
If you have a CPU that fails to round up and then run 'btc' you'll end up crashing in kdb becaue we dereferenced NULL. Let's add a check. It's wise to also set the task to NULL when leaving the debugger so that if we fail to round up on a later entry into the debugger we won't backtrace a stale task. Signed-off-by: Douglas Anderson <dianders@chromium.org> Acked-by: Daniel Thompson <daniel.thompson@linaro.org> Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
1 parent 87b0959 commit 162bc7f

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

‎kernel/debug/debug_core.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@ static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs,
592592
arch_kgdb_ops.correct_hw_break();
593593
if (trace_on)
594594
tracing_on();
595+
kgdb_info[cpu].debuggerinfo = NULL;
596+
kgdb_info[cpu].task = NULL;
595597
kgdb_info[cpu].exception_state &=
596598
~(DCPU_WANT_MASTER | DCPU_IS_SLAVE);
597599
kgdb_info[cpu].enter_kgdb--;
@@ -724,6 +726,8 @@ static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs,
724726
if (trace_on)
725727
tracing_on();
726728

729+
kgdb_info[cpu].debuggerinfo = NULL;
730+
kgdb_info[cpu].task = NULL;
727731
kgdb_info[cpu].exception_state &=
728732
~(DCPU_WANT_MASTER | DCPU_IS_SLAVE);
729733
kgdb_info[cpu].enter_kgdb--;

‎kernel/debug/kdb/kdb_bt.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,16 @@ kdb_bt(int argc, const char **argv)
186186
kdb_printf("btc: cpu status: ");
187187
kdb_parse("cpu\n");
188188
for_each_online_cpu(cpu) {
189-
sprintf(buf, "btt 0x%px\n", KDB_TSK(cpu));
189+
void *kdb_tsk = KDB_TSK(cpu);
190+
191+
/* If a CPU failed to round up we could be here */
192+
if (!kdb_tsk) {
193+
kdb_printf("WARNING: no task for cpu %ld\n",
194+
cpu);
195+
continue;
196+
}
197+
198+
sprintf(buf, "btt 0x%px\n", kdb_tsk);
190199
kdb_parse(buf);
191200
touch_nmi_watchdog();
192201
}

‎kernel/debug/kdb/kdb_debugger.c‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,6 @@ int kdb_stub(struct kgdb_state *ks)
118118
kdb_bp_remove();
119119
KDB_STATE_CLEAR(DOING_SS);
120120
KDB_STATE_SET(PAGER);
121-
/* zero out any offline cpu data */
122-
for_each_present_cpu(i) {
123-
if (!cpu_online(i)) {
124-
kgdb_info[i].debuggerinfo = NULL;
125-
kgdb_info[i].task = NULL;
126-
}
127-
}
128121
if (ks->err_code == DIE_OOPS || reason == KDB_REASON_OOPS) {
129122
ks->pass_exception = 1;
130123
KDB_FLAG_SET(CATASTROPHIC);

0 commit comments

Comments
 (0)