Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5868950pxb; Mon, 14 Feb 2022 09:24:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJynVKbg2ffreyWx1GQO16lbIbtyP+WrsrsmGL9fmNsY9SdqZ3lb6HH2lHek2ZX2cwjvXvTd X-Received: by 2002:a17:902:9b8f:: with SMTP id y15mr7822plp.61.1644859458345; Mon, 14 Feb 2022 09:24:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644859458; cv=none; d=google.com; s=arc-20160816; b=VnbSwpH5OC8p3t3F7MmvYx3Wq3IGjbOcS1RonkLpGnXph7cpa0y9CamgWsxNWDZR6v LeSEdH11SZiEtUsESY+xuIuAZdkQFLd+Ec76BkZ03aut2jXVJ9dQqpeVWYhotSfOLBTO HGYYxOAq2nPMV+zNrd7B9bkYtUpbZHewvzWHg2db+JF3q5Tn2NREj8MpENVbrr93fpsX eph7MFXFADrh/oOgl0ykuqwa2r6DKVORBocwXdMRyBxsSNtubWIKa0OOYN0e/1ILxfHk EGzqw9glnP6MR5e1uqDvL2EbynkxsWjLxgaDjQg81eZ+gq+zVA9zaQriFPd9JKuVODeX 6R+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=V57R5a2O0zZ5gdcp4vIHQbVgGyyROcq/YIatDbB3aUU=; b=dTHWzyZWBq5/sL6w0JwSSuotsljDcWm4/RiyU161z+n573g5nhH+JAp28hq+2khHaz PKyPJWFGYZkdlf1+sMpfGgoDAPgIbq8Q2IVwTiSvcCowFMgJV4xpHeAmq+XY6ICrck5Q 8zD7izO+Ctf2ME6cSIVHAW31/uIclSqA1mAKbvPi71vYnrAfxz3ywwqlSOqVN/VltcHQ w0pWro3n6vb1rxF8p6CA1MWTnxMGjBpSDJkjPL7FCSnruYG9l8+5dKYZ83dJdG2y/N4u o5Puu3FLpne/e6A1Q+JgUc4ydsvpPeVGTjEDbO+Dw+5LS9QlgL2fFit16Ef+tIY7s1zf Y/QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=Bodhw4C6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q195si473768pfc.178.2022.02.14.09.24.00; Mon, 14 Feb 2022 09:24:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=Bodhw4C6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355016AbiBNOQe (ORCPT + 99 others); Mon, 14 Feb 2022 09:16:34 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:52364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233575AbiBNOQc (ORCPT ); Mon, 14 Feb 2022 09:16:32 -0500 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67F4AC72 for ; Mon, 14 Feb 2022 06:16:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=V57R5a2O0zZ5gdcp4vIHQbVgGyyROcq/YIatDbB3aUU=; b=Bodhw4C6EJx6HuM+psJGR5tvbD 2Z5aAwckyx0vclVEQnNQ9PK7h9WuPQGpAcdnDxpZa2g4/Se0JdrlxspAJF2HWaZLOTSqbzsdEDFaW IVidNF9bHmtvWXCKjo5pXFdUjoRRaKolsPRWhZE8S2agSZfpehediA1XPrX0jfbr20Cub0IKW3lOF fKN5XF9pnMkWMHxSoCMBUCl9DUT+Gh/UktxnK2fgYsmegLpV1YNNagi8RJ5pJCMDg7TIPbrMcm5L/ X/xSUgG/gTDuZSqkZLdHlNmIojs+6C01U+6Pt4zIwPZiln9jHA6Q4eYnkZuFM9eUNNAY2wphft9oa 4YNYBT7A==; Received: from 201-27-34-205.dsl.telesp.net.br ([201.27.34.205] helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1nJc9G-0003w2-2s; Mon, 14 Feb 2022 15:16:14 +0100 From: "Guilherme G. Piccoli" To: linux-kernel@vger.kernel.org, bhe@redhat.com, pmladek@suse.com, akpm@linux-foundation.org Cc: gpiccoli@igalia.com, anton@enomsg.org, ccross@android.com, dyoung@redhat.com, feng.tang@intel.com, john.ogness@linutronix.de, keescook@chromium.org, kernel@gpiccoli.net, kexec@lists.infradead.org, rostedt@goodmis.org, senozhatsky@chromium.org, tony.luck@intel.com, vgoyal@redhat.com Subject: [PATCH V6] panic: Move panic_print before kmsg dumpers Date: Mon, 14 Feb 2022 11:13:09 -0300 Message-Id: <20220214141308.841525-1-gpiccoli@igalia.com> X-Mailer: git-send-email 2.35.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The panic_print setting allows users to collect more information in a panic event, like memory stats, tasks, CPUs backtraces, etc. This is an interesting debug mechanism, but currently the print event happens *after* kmsg_dump(), meaning that pstore, for example, cannot collect a dmesg with the panic_print extra information. This patch changes that in 2 steps: (a) The panic_print setting allows to replay the existing kernel log buffer to the console (bit 5), besides the extra information dump. This functionality makes sense only at the end of the panic() function. So, we hereby allow to distinguish the two situations by a new boolean parameter in the function panic_print_sys_info(). (b) With the above change, we can safely call panic_print_sys_info() before kmsg_dump(), allowing to dump the extra information when using pstore or other kmsg dumpers. The additional messages from panic_print could overwrite the oldest messages when the buffer is full. The only reasonable solution is to use a large enough log buffer, hence we added an advice into the kernel parameters documentation about that. Cc: Feng Tang Cc: Petr Mladek Acked-by: Baoquan He Signed-off-by: Guilherme G. Piccoli --- V6: Implemented a small suggestion from Baoquan in the commit message; with that, added his Acked-By. (Thanks Baoquan!) Notice that this is rebased against linux-next (next-20220211 branch). V5: https://lore.kernel.org/lkml/20220211215539.822466-1-gpiccoli@igalia.com/ V4: https://lore.kernel.org/lkml/20220124203101.216051-1-gpiccoli@igalia.com/ Andrew, can we get that merged in the mm-tree, after getting [0] removed from there? This one replaces [0]. Thanks!! [0] https://ozlabs.org/~akpm/mmots/broken-out/panic-allow-printing-extra-panic-information-on-kdump.patch Documentation/admin-guide/kernel-parameters.txt | 4 ++++ kernel/panic.c | 13 +++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 3c2b3e24e8f5..2cf7078eaa95 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -3766,6 +3766,10 @@ bit 4: print ftrace buffer bit 5: print all printk messages in buffer bit 6: print all CPUs backtrace (if available in the arch) + *Be aware* that this option may print a _lot_ of lines, + so there are risks of losing older messages in the log. + Use this option carefully, maybe worth to setup a + bigger log buffer with "log_buf_len" along with this. panic_on_taint= Bitmask for conditionally calling panic() in add_taint() Format: [,nousertaint] diff --git a/kernel/panic.c b/kernel/panic.c index 3c3fb36d8d41..eb4dfb932c85 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -148,10 +148,13 @@ void nmi_panic(struct pt_regs *regs, const char *msg) } EXPORT_SYMBOL(nmi_panic); -static void panic_print_sys_info(void) +static void panic_print_sys_info(bool console_flush) { - if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG) - console_flush_on_panic(CONSOLE_REPLAY_ALL); + if (console_flush) { + if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG) + console_flush_on_panic(CONSOLE_REPLAY_ALL); + return; + } if (panic_print & PANIC_PRINT_ALL_CPU_BT) trigger_all_cpu_backtrace(); @@ -286,6 +289,8 @@ void panic(const char *fmt, ...) */ atomic_notifier_call_chain(&panic_notifier_list, 0, buf); + panic_print_sys_info(false); + kmsg_dump(KMSG_DUMP_PANIC); /* @@ -316,7 +321,7 @@ void panic(const char *fmt, ...) debug_locks_off(); console_flush_on_panic(CONSOLE_FLUSH_PENDING); - panic_print_sys_info(); + panic_print_sys_info(true); if (!panic_blink) panic_blink = no_blink; -- 2.35.0