From nobody Wed Dec 17 07:25:46 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2F88C4332F for ; Sun, 12 Nov 2023 13:34:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232243AbjKLNeU (ORCPT ); Sun, 12 Nov 2023 08:34:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232144AbjKLNdq (ORCPT ); Sun, 12 Nov 2023 08:33:46 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 760814796; Sun, 12 Nov 2023 05:30:47 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4E68C433AB; Sun, 12 Nov 2023 13:30:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699795817; bh=Cms4YnTTbuEQBpW/YysiUYP4BKHKaSDMT6NsoG3U41w=; h=From:To:Cc:Subject:Date:From; b=KDZWl9MV0AezypuIO/m4955TgXuALihuBPKQeg0kHr+wtpJDZ0O8/fF6+V8gAquNS SG2ZSg/UvrZ9JshSfGHaPjXczrI5n/QkmtJTGMVv+nWcPUVOLhkzJfq2Ugh9SHPMvQ oSthcJo7giYOD2/ag4GvYyIwWIqIKj6PG5bFQ+NlgJTFvfbfbMlugLmELTz/TZWHSi T4Xk9o6O5tDewOwRcw18TnMPRriGRlYqhkZE9aHR3GsknjBu7S1j7bgIqVcB2tlMvg pZm8ZVHNzREvGDhZOhkyUC1CmoHp9pzDgLUEgZ+koIzF/bke3aqro02se7VdXjqR/7 c621Nym7VLQDg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Douglas Anderson , Daniel Thompson , Sasha Levin , jason.wessel@windriver.com, kgdb-bugreport@lists.sourceforge.net Subject: [PATCH AUTOSEL 5.4] kgdb: Flush console before entering kgdb on panic Date: Sun, 12 Nov 2023 08:30:14 -0500 Message-ID: <20231112133014.177336-1-sashal@kernel.org> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.4.260 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Douglas Anderson [ Upstream commit dd712d3d45807db9fcae28a522deee85c1f2fde6 ] When entering kdb/kgdb on a kernel panic, it was be observed that the console isn't flushed before the `kdb` prompt came up. Specifically, when using the buddy lockup detector on arm64 and running: echo HARDLOCKUP > /sys/kernel/debug/provoke-crash/DIRECT I could see: [ 26.161099] lkdtm: Performing direct entry HARDLOCKUP [ 32.499881] watchdog: Watchdog detected hard LOCKUP on cpu 6 [ 32.552865] Sending NMI from CPU 5 to CPUs 6: [ 32.557359] NMI backtrace for cpu 6 ... [backtrace for cpu 6] ... [ 32.558353] NMI backtrace for cpu 5 ... [backtrace for cpu 5] ... [ 32.867471] Sending NMI from CPU 5 to CPUs 0-4,7: [ 32.872321] NMI backtrace forP cpuANC: Hard LOCKUP Entering kdb (current=3D..., pid 0) on processor 5 due to Keyboard Entry [5]kdb> As you can see, backtraces for the other CPUs start printing and get interleaved with the kdb PANIC print. Let's replicate the commands to flush the console in the kdb panic entry point to avoid this. Signed-off-by: Douglas Anderson Link: https://lore.kernel.org/r/20230822131945.1.I5b460ae8f954e4c4f628a373d= 6e74713c06dd26f@changeid Signed-off-by: Daniel Thompson Signed-off-by: Sasha Levin --- kernel/debug/debug_core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c index f88611fadb195..1ab2e97034868 100644 --- a/kernel/debug/debug_core.c +++ b/kernel/debug/debug_core.c @@ -945,6 +945,9 @@ void kgdb_panic(const char *msg) if (panic_timeout) return; =20 + debug_locks_off(); + console_flush_on_panic(CONSOLE_FLUSH_PENDING); + if (dbg_kdb_mode) kdb_printf("PANIC: %s\n", msg); =20 --=20 2.42.0