Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3693825imu; Mon, 28 Jan 2019 09:10:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN5iMYWxgOeBvPm4FBjIUT/WhWHVz8n2FoJerngVqec7C35o/XfDMgxWktP4KHZ8p77ObI1C X-Received: by 2002:a17:902:f24:: with SMTP id 33mr22783646ply.65.1548695402944; Mon, 28 Jan 2019 09:10:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548695402; cv=none; d=google.com; s=arc-20160816; b=V0L8erM1DZ4DSqcWXY1coLalmx/de6UHMWgF8sYJ+ag+nSqBD9xwLWPsbVq63vWAGU NrmOYl2HxqScxqtPty36L+JFeou42PD4sdnWoQrLuoxal3COOW4a9kzalcf7cqGiHxrz R8oI3UNp7vw4MEvlZvKJ8YGMpZ4qF+AU6D0izQrTvqVVs2T8wPUb9GxhDECvl5AWriSQ fRdIYCGs8UdV200OPQe9MbzMOkibbUzDcV51qKq5U7ciwAlt7V3Mjagxg5IN450kgd9y Mxx+tWNsSdXY5Yq3klXbshOV2o9GJ8odEb3hR4cpiiCEfvjyEdeSvIpv1YxY8HiXCP3/ an+A== 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=wvdCju+mQ7RM28eHAm+uDj+twABHQIB5l7rOiaoFCOM=; b=thWvJITxqcztvBgegFx80MUWL/L9z+CsToArnI7d9iKTLRs+6JAPMR9ywVQE5Hdxju Sr5Tf8xfTH6w6h2dzDjzrX2Gqecjx38/LaxFC0jPc8XlMNj4R2AOMGEAm63OaHIQMJZo 36h1RrW/1wksEoYfwXChQwabEpimUwohn2kkaVyYJEZPvSO9vMtbtVupyfg/QbLZUUZA 799Yzsn+tiD5JhdtrIoRolfb0Q3vzLRMiB7ObR9FERdFHap7RF0rUM76cN44oJiz91Pe 1Ivy9rVu7ZtWxiC/yUhBolEpOAxPDaFz/mDByMiz+ibRQfsmtqGlS3XzSRKsfXYRoO4i Vcdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cwdL14RK; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 93si32863665plc.2.2019.01.28.09.09.47; Mon, 28 Jan 2019 09:10:02 -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=@kernel.org header.s=default header.b=cwdL14RK; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732944AbfA1QLT (ORCPT + 99 others); Mon, 28 Jan 2019 11:11:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:38182 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732523AbfA1QLS (ORCPT ); Mon, 28 Jan 2019 11:11:18 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 319DD2175B; Mon, 28 Jan 2019 16:11:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691877; bh=0ieo5Dib0i5Gf3gMQ2kP4sQ1hKmfL8+L68c2DTTPqlk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cwdL14RKXTv8i7SzGu63NBEF7Gwikeqi26pj30Kcvdbg+pM9usPfwro5m52Umr6+s 0XLRv8T6CJFBQs3L6CjZVI/CszNDKLfcQvZx5tf4FKq9ow0lRY77myJOX1utRG5Bm6 z+GATysyHbBsbJaSTQmvbhICOaK98jSUoFCs4nv8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Douglas Anderson , Daniel Thompson , Sasha Levin , kgdb-bugreport@lists.sourceforge.net Subject: [PATCH AUTOSEL 4.19 245/258] kdb: Don't back trace on a cpu that didn't round up Date: Mon, 28 Jan 2019 10:59:11 -0500 Message-Id: <20190128155924.51521-245-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Douglas Anderson [ Upstream commit 162bc7f5afd75b72acbe3c5f3488ef7e64a3fe36 ] 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 Acked-by: Daniel Thompson Signed-off-by: Daniel Thompson Signed-off-by: Sasha Levin --- 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 65c0f1363788..94aa9ae0007a 100644 --- a/kernel/debug/debug_core.c +++ b/kernel/debug/debug_core.c @@ -535,6 +535,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--; @@ -667,6 +669,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