All of lore.kernel.org
 help / color / mirror / Atom feed
From: Douglas Anderson <dianders@chromium.org>
To: Jason Wessel <jason.wessel@windriver.com>,
	Daniel Thompson <daniel.thompson@linaro.org>
Cc: kgdb-bugreport@lists.sourceforge.net,
	Peter Zijlstra <peterz@infradead.org>,
	Douglas Anderson <dianders@chromium.org>,
	Christophe Leroy <christophe.leroy@c-s.fr>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v4 4/4] kdb: Don't back trace on a cpu that didn't round up
Date: Mon, 12 Nov 2018 10:26:58 -0800	[thread overview]
Message-ID: <20181112182659.245726-5-dianders@chromium.org> (raw)
In-Reply-To: <20181112182659.245726-1-dianders@chromium.org>

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>
---

Changes in v4:
- Also clear out .debuggerinfo.
- Also clear out .debuggerinfo and .task for the master.
- Remove clearing out in kdb_stub for offline CPUs; it's now redundant.

Changes in v3:
- Don't back trace on a cpu that didn't round up new for v3.

Changes in v2: None

 kernel/debug/debug_core.c       |  4 ++++
 kernel/debug/kdb/kdb_bt.c       | 11 ++++++++++-
 kernel/debug/kdb/kdb_debugger.c |  7 -------
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
index 7e2f312fb41f..4907ac7a6250 100644
--- a/kernel/debug/debug_core.c
+++ b/kernel/debug/debug_core.c
@@ -583,6 +583,8 @@ static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs,
 				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--;
@@ -715,6 +717,8 @@ static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs,
 	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--;
diff --git a/kernel/debug/kdb/kdb_bt.c b/kernel/debug/kdb/kdb_bt.c
index 7921ae4fca8d..7e2379aa0a1e 100644
--- a/kernel/debug/kdb/kdb_bt.c
+++ b/kernel/debug/kdb/kdb_bt.c
@@ -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();
 		}
diff --git a/kernel/debug/kdb/kdb_debugger.c b/kernel/debug/kdb/kdb_debugger.c
index 15e1a7af5dd0..53a0df6e4d92 100644
--- a/kernel/debug/kdb/kdb_debugger.c
+++ b/kernel/debug/kdb/kdb_debugger.c
@@ -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);
-- 
2.19.1.930.g4563a0d9d0-goog


      parent reply	other threads:[~2018-11-12 18:27 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-12 18:26 [PATCH v4 0/4] kgdb: Fix kgdb_roundup_cpus() Douglas Anderson
2018-11-12 18:26 ` Douglas Anderson
2018-11-12 18:26 ` Douglas Anderson
2018-11-12 18:26 ` Douglas Anderson
2018-11-12 18:26 ` Douglas Anderson
2018-11-12 18:26 ` Douglas Anderson
2018-11-12 18:26 ` [PATCH v4 1/4] kgdb: Remove irq flags from roundup Douglas Anderson
2018-11-12 18:26   ` Douglas Anderson
2018-11-12 18:26   ` Douglas Anderson
2018-11-12 18:26   ` Douglas Anderson
2018-11-12 18:26   ` Douglas Anderson
2018-11-12 18:26   ` Douglas Anderson
2018-11-14 21:51   ` Will Deacon
2018-11-14 21:51     ` Will Deacon
2018-11-14 21:51     ` Will Deacon
2018-11-14 21:51     ` Will Deacon
2018-11-14 21:51     ` Will Deacon
2018-11-14 21:51     ` Will Deacon
2018-11-12 18:26 ` [PATCH v4 2/4] kgdb: Fix kgdb_roundup_cpus() for arches who used smp_call_function() Douglas Anderson
2018-11-12 18:26   ` Douglas Anderson
2018-11-12 18:26   ` Douglas Anderson
2018-11-12 18:26   ` Douglas Anderson
2018-11-12 18:26   ` Douglas Anderson
2018-11-12 18:26   ` Douglas Anderson
2018-11-14 22:07   ` Will Deacon
2018-11-14 22:07     ` Will Deacon
2018-11-14 22:07     ` Will Deacon
2018-11-14 22:07     ` Will Deacon
2018-11-14 22:07     ` Will Deacon
2018-11-14 22:07     ` Will Deacon
2018-11-27  3:52     ` Doug Anderson
2018-11-27  3:52       ` Doug Anderson
2018-11-27  3:52       ` Doug Anderson
2018-11-27  3:52       ` Doug Anderson
2018-11-27  3:52       ` Doug Anderson
2018-11-27  3:52       ` Doug Anderson
2018-11-12 18:26 ` [PATCH v4 3/4] kgdb: Don't round up a CPU that failed rounding up before Douglas Anderson
2018-11-12 18:26 ` Douglas Anderson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181112182659.245726-5-dianders@chromium.org \
    --to=dianders@chromium.org \
    --cc=christophe.leroy@c-s.fr \
    --cc=daniel.thompson@linaro.org \
    --cc=jason.wessel@windriver.com \
    --cc=kgdb-bugreport@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.