Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp229483imu; Tue, 27 Nov 2018 11:29:15 -0800 (PST) X-Google-Smtp-Source: AFSGD/WGI2o9+m+9yOhKhmv3Tg1mYjvfnhMErw5GYK8s+8QvKl59/nnH5HmeMSZ5F1kA2ENgnIti X-Received: by 2002:a17:902:6bc4:: with SMTP id m4mr18113671plt.93.1543346955592; Tue, 27 Nov 2018 11:29:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543346955; cv=none; d=google.com; s=arc-20160816; b=kFuc/KZs9w+mW2Z6EFZ5S/SoFaAAsOfn2eArVFB/LLfMYJcOt4o8b4kMNbiW7mmvDv rX9pW5vl5nnVDfBGaOm06Ew0rrFVe0NGhb4W1fxr6gkbCeQOjEK7k8bS4Hm8ynNPN2/M fgFINYopPU32Kju7sYrMYvHqMWkZC46OVXZesmwl6QV3BxVHMzfww4chfjwj/RnlIbnq Xx7m3bpcbUVZywS8FzZgtsZc4tWqIGy6CzI4KRdvgUjsmvpUvJJtwx2mm5cDcDeM6O3X YEj6tsLNYhwJYk688DSMkL0eYjMRoosMBtJYcx0jLqKSV/AZSOWzGAOc2ID6Maq2dkhx qXAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CV8A3/xmXPapmlglD4W9nW4QRlfphA63hmrAVlhq71o=; b=oEmYkzOzFmVFMQzcnCJMsPfcQQZQi5rRwoOCWoV5BPB9SEIEYXePXFfy5424KnHAfz qq47WrWNwmbZb41Qb7Yig7jFefFHFfm1hfmv2lmV6K+WGq92jR0Ltct02tc9bAZQ3Ksb mK+S1Hlt1FpR9uVdSl6VXXi1ZvP8ESNV6MdhgAN8c0cALrcTubP7aLCE50wP40julSyX +gmxM6l7U8Xuh4g+VJb6/ZBX/Bla9zwZdMEEGnnTUzlvUWA98scJQo8ba2a9DNNdh8eV TGM96LRPF8cTk2Z3r5wPG5tHPFHyIaji4uOECku8jFYmSLI0WNRU4UDN2J7h2XsLyewW qcmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gb3K2g6n; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i64-v6si4890858pli.135.2018.11.27.11.29.00; Tue, 27 Nov 2018 11:29:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gb3K2g6n; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731966AbeK1Ehe (ORCPT + 99 others); Tue, 27 Nov 2018 23:37:34 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:36719 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731957AbeK1Ehe (ORCPT ); Tue, 27 Nov 2018 23:37:34 -0500 Received: by mail-pg1-f193.google.com with SMTP id n2so8193564pgm.3 for ; Tue, 27 Nov 2018 09:38:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CV8A3/xmXPapmlglD4W9nW4QRlfphA63hmrAVlhq71o=; b=gb3K2g6niFv8JFCxDvjn+HbuxCuXOxxril70UBFKbQyg5NlG5DKaCqyvGuvZ/UwDIR uTF2gheCfZMfXAGOkqGLRGCsZPsBo1Ve5jNuS9nvaxQ60vPkOtYTnpKQ6ebF7WnE9RGY zqKVj3lewRXjQIKiQpCLAupba0dDUrk3Oyo9g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CV8A3/xmXPapmlglD4W9nW4QRlfphA63hmrAVlhq71o=; b=SG3fwCv3U6YV5R5dd6aVPJfnT0gXjKErZkLbBlu/yN6+b2QR+nHV6+TqTm7nlkIuI6 EHhKHtfmfyglZICQEU6lezg6UevNxgj0NOLb5E9A+rLuDutKclHjqPh16tKX1YoexHGf QnhNFKiG7vdaV5DSTx7lqxt4JXkMuPh9lfFWa0T5/VBcHQKdeTAqCSHinRgv63Tilndx RENyMxD+kbh0mZxLEMibMfTX5AEXc6lmMBpQdE8OadwwMh3Qqgl4d0ELsn4tR+BNWXz9 YdHZ2Nm1UTBQaqg1q5DZEkBSc2UEKiDTN9Wr2Mhq2dSvn+bCCO1CU8L2NlGfUQncqCud gxhw== X-Gm-Message-State: AA+aEWZNIac4rs67v4KQ6MXTHgM5SttAGJM+FcD7/rGQWsuNuqINvIZP 5CxK8BkjVSGo94wOBJpopUVKuA== X-Received: by 2002:a62:178f:: with SMTP id 137mr18229798pfx.226.1543340335945; Tue, 27 Nov 2018 09:38:55 -0800 (PST) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:c8e0:70d7:4be7:a36]) by smtp.gmail.com with ESMTPSA id b185sm4577547pga.85.2018.11.27.09.38.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 09:38:55 -0800 (PST) From: Douglas Anderson To: Jason Wessel , Daniel Thompson Cc: Will Deacon , kgdb-bugreport@lists.sourceforge.net, Peter Zijlstra , Douglas Anderson , Christophe Leroy , linux-kernel@vger.kernel.org Subject: [PATCH v6 4/4] kdb: Don't back trace on a cpu that didn't round up Date: Tue, 27 Nov 2018 09:38:39 -0800 Message-Id: <20181127173839.34328-5-dianders@chromium.org> X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-goog In-Reply-To: <20181127173839.34328-1-dianders@chromium.org> References: <20181127173839.34328-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 --- Changes in v6: None Changes in v5: None 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 1fb8b239e567..5cc608de6883 100644 --- a/kernel/debug/debug_core.c +++ b/kernel/debug/debug_core.c @@ -592,6 +592,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--; @@ -724,6 +726,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.20.0.rc0.387.gc7a69e6b6c-goog