kdb: Don't back trace on a cpu that didn't round up
authorDouglas Anderson <dianders@chromium.org>
Wed, 5 Dec 2018 03:38:28 +0000 (19:38 -0800)
committerDaniel Thompson <daniel.thompson@linaro.org>
Sun, 30 Dec 2018 08:31:23 +0000 (08:31 +0000)
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>
kernel/debug/debug_core.c
kernel/debug/kdb/kdb_bt.c
kernel/debug/kdb/kdb_debugger.c

index 1fb8b239e56705629765fe868192424a68cc3496..5cc608de6883127e6925c6cc71ce7c89eb8b7f84 100644 (file)
@@ -592,6 +592,8 @@ return_normal:
                                arch_kgdb_ops.correct_hw_break();
                        if (trace_on)
                                tracing_on();
+                       kgdb_info[cpu].debuggerinfo = NULL;
+                       kgdb_info[cpu].task = NULL;
                        kgdb_info[cpu].exception_state &=
                                ~(DCPU_WANT_MASTER | DCPU_IS_SLAVE);
                        kgdb_info[cpu].enter_kgdb--;
@@ -724,6 +726,8 @@ kgdb_restore:
        if (trace_on)
                tracing_on();
 
+       kgdb_info[cpu].debuggerinfo = NULL;
+       kgdb_info[cpu].task = NULL;
        kgdb_info[cpu].exception_state &=
                ~(DCPU_WANT_MASTER | DCPU_IS_SLAVE);
        kgdb_info[cpu].enter_kgdb--;
index 7921ae4fca8de92513fb5b71cbc36fd96ed0e04f..7e2379aa0a1e7a2247041b497e6d747a3e05bb04 100644 (file)
@@ -186,7 +186,16 @@ kdb_bt(int argc, const char **argv)
                kdb_printf("btc: cpu status: ");
                kdb_parse("cpu\n");
                for_each_online_cpu(cpu) {
-                       sprintf(buf, "btt 0x%px\n", KDB_TSK(cpu));
+                       void *kdb_tsk = KDB_TSK(cpu);
+
+                       /* If a CPU failed to round up we could be here */
+                       if (!kdb_tsk) {
+                               kdb_printf("WARNING: no task for cpu %ld\n",
+                                          cpu);
+                               continue;
+                       }
+
+                       sprintf(buf, "btt 0x%px\n", kdb_tsk);
                        kdb_parse(buf);
                        touch_nmi_watchdog();
                }
index 15e1a7af5dd033f130ef2b4ed96cf1e2809442f5..53a0df6e4d92c9ebf59f1b4471f9be615fd5e904 100644 (file)
@@ -118,13 +118,6 @@ int kdb_stub(struct kgdb_state *ks)
        kdb_bp_remove();
        KDB_STATE_CLEAR(DOING_SS);
        KDB_STATE_SET(PAGER);
-       /* zero out any offline cpu data */
-       for_each_present_cpu(i) {
-               if (!cpu_online(i)) {
-                       kgdb_info[i].debuggerinfo = NULL;
-                       kgdb_info[i].task = NULL;
-               }
-       }
        if (ks->err_code == DIE_OOPS || reason == KDB_REASON_OOPS) {
                ks->pass_exception = 1;
                KDB_FLAG_SET(CATASTROPHIC);