From patchwork Tue Nov 9 20:28:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 12611055 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68CCFC433FE for ; Tue, 9 Nov 2021 20:47:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 549C16103D for ; Tue, 9 Nov 2021 20:47:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244755AbhKIUuB (ORCPT ); Tue, 9 Nov 2021 15:50:01 -0500 Received: from fanzine2.igalia.com ([213.97.179.56]:33722 "EHLO fanzine.igalia.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244708AbhKIUt6 (ORCPT ); Tue, 9 Nov 2021 15:49:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=V5TlNNHK5TXkLJH4wGpBTMm1ncH3nHL5Lp6qWJm/BCI=; b=OfM5quAqtYbzRy/Sf16X+ND9GskkR3A7ApwZXs1PooXj+kP7lYXBOSLmOxcpU3o8egdVgNVe0Ys9Q4SHjsedgQO5XTQoV7SG0qqmboxRGIHMfnCD66cfGVPBAbo55AIXWqjLJg+JXVWjSE13M5CfFwn6mmaxz44j7Igp22MQmncECgMPuwE/L+c5pN0lJhm1HDXfmghBXWFUKTZovYY3bCU02v9oUyl0qM1ftSApVRqYCK5yV1AdXajwp2b55S+YRZsUNRVYkq3a8Z8GPaPh0KhKCtUQFgpmrmU1wzG+e1UtqO0DxK5s6wFwyUv2xzVRFslqm7FcTLiGc8m+Ws72zQ==; Received: from 201-95-14-182.dsl.telesp.net.br ([201.95.14.182] helo=localhost) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1mkXl0-0000Ky-4o; Tue, 09 Nov 2021 21:30:14 +0100 From: "Guilherme G. Piccoli" To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-doc@vger.kernel.org, mcgrof@kernel.org, keescook@chromium.org, yzaikin@google.com, akpm@linux-foundation.org, feng.tang@intel.com, siglesias@igalia.com, kernel@gpiccoli.net, gpiccoli@igalia.com Subject: [PATCH 1/3] docs: sysctl/kernel: Add missing bit to panic_print Date: Tue, 9 Nov 2021 17:28:46 -0300 Message-Id: <20211109202848.610874-2-gpiccoli@igalia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211109202848.610874-1-gpiccoli@igalia.com> References: <20211109202848.610874-1-gpiccoli@igalia.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Commit de6da1e8bcf0 ("panic: add an option to replay all the printk message in buffer") added a new bit to the sysctl/kernel parameter "panic_print", but the documentation was added only in kernel-parameters.txt, not in the sysctl guide. Fix it here by adding bit 5 to sysctl admin-guide documentation. Cc: Feng Tang Fixes: de6da1e8bcf0 ("panic: add an option to replay all the printk message in buffer") Signed-off-by: Guilherme G. Piccoli Reviewed-by: Feng Tang --- Documentation/admin-guide/sysctl/kernel.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst index 426162009ce9..70b7df9b081a 100644 --- a/Documentation/admin-guide/sysctl/kernel.rst +++ b/Documentation/admin-guide/sysctl/kernel.rst @@ -795,6 +795,7 @@ bit 1 print system memory info bit 2 print timer info bit 3 print locks info if ``CONFIG_LOCKDEP`` is on bit 4 print ftrace buffer +bit 5: print all printk messages in buffer ===== ============================================ So for example to print tasks and memory info on panic, user can:: From patchwork Tue Nov 9 20:28:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 12611051 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC3CEC433FE for ; Tue, 9 Nov 2021 20:47:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9DCD761207 for ; Tue, 9 Nov 2021 20:47:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244693AbhKIUtx (ORCPT ); Tue, 9 Nov 2021 15:49:53 -0500 Received: from fanzine2.igalia.com ([213.97.179.56]:33712 "EHLO fanzine.igalia.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234878AbhKIUtv (ORCPT ); Tue, 9 Nov 2021 15:49:51 -0500 X-Greylist: delayed 1063 seconds by postgrey-1.27 at vger.kernel.org; Tue, 09 Nov 2021 15:49:50 EST DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=WArqkDtu5W1DQIOZg6AY0uLA7OKIXkUD3kbNB9gSEbo=; b=Qzlp7TLRgXgDaisYpJr22SvCHecuDcA9IG1lh74ZDfzrJv0E7iJEhLwMlC5N8P2LZwRNWztVoV+UHoWOv2/0dT1SJccI2Au0veyf4dhxiMUmMIfP/2UwlwOxi5HwldblBtVhLjY76ETUfEPCy6RqqS1rq9YwsoN0IHJfmJ6zos6l0ySbRVM5zGBn4cSAb6raeB036ce2Oh7KimRSCGdgFpo4KaoshJsAUaV/ieZP6S0Niwdu4jhM6smh1170Tf7V7jFJvSgjY5ytFnlttOwI+1Wos35qE+becR6oXWAd7CMbWoJznnWMSqXemOG2XWblgfATmnifWUpvsF8cwlbFWw==; Received: from 201-95-14-182.dsl.telesp.net.br ([201.95.14.182] helo=localhost) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1mkXlF-0000Lh-QE; Tue, 09 Nov 2021 21:30:30 +0100 From: "Guilherme G. Piccoli" To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-doc@vger.kernel.org, mcgrof@kernel.org, keescook@chromium.org, yzaikin@google.com, akpm@linux-foundation.org, feng.tang@intel.com, siglesias@igalia.com, kernel@gpiccoli.net, gpiccoli@igalia.com Subject: [PATCH 2/3] panic: Add option to dump all CPUs backtraces in panic_print Date: Tue, 9 Nov 2021 17:28:47 -0300 Message-Id: <20211109202848.610874-3-gpiccoli@igalia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211109202848.610874-1-gpiccoli@igalia.com> References: <20211109202848.610874-1-gpiccoli@igalia.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Currently the "panic_print" parameter/sysctl allows some interesting debug information to be printed during a panic event. This is useful for example in cases the user cannot kdump due to resource limits, or if the user collects panic logs in a serial output (or pstore) and prefers a fast reboot instead of a kdump. Happens that currently there's no way to see all CPUs backtraces in a panic using "panic_print" on architectures that support that. We do have "oops_all_cpu_backtrace" sysctl, but although partially overlapping in the functionality, they are orthogonal in nature: "panic_print" is a panic tuning (and we have panics without oopses, like direct calls to panic() or maybe other paths that don't go through oops_enter() function), and the original purpose of "oops_all_cpu_backtrace" is to provide more information on oopses for cases in which the users desire to continue running the kernel even after an oops, i.e., used in non-panic scenarios. So, we hereby introduce an additional bit for "panic_print" to allow dumping the CPUs backtraces during a panic event. Signed-off-by: Guilherme G. Piccoli Reviewed-by: Feng Tang Reviewed-by: Petr Mladek --- Documentation/admin-guide/kernel-parameters.txt | 1 + Documentation/admin-guide/sysctl/kernel.rst | 1 + kernel/panic.c | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 0905d2cdb2d5..569d035c4332 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -3690,6 +3690,7 @@ bit 3: print locks info if CONFIG_LOCKDEP is on bit 4: print ftrace buffer bit 5: print all printk messages in buffer + bit 6: print all CPUs backtrace (if available in the arch) panic_on_taint= Bitmask for conditionally calling panic() in add_taint() Format: [,nousertaint] diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst index 70b7df9b081a..1666c1a9dbba 100644 --- a/Documentation/admin-guide/sysctl/kernel.rst +++ b/Documentation/admin-guide/sysctl/kernel.rst @@ -796,6 +796,7 @@ bit 2 print timer info bit 3 print locks info if ``CONFIG_LOCKDEP`` is on bit 4 print ftrace buffer bit 5: print all printk messages in buffer +bit 6: print all CPUs backtrace (if available in the arch) ===== ============================================ So for example to print tasks and memory info on panic, user can:: diff --git a/kernel/panic.c b/kernel/panic.c index cefd7d82366f..5da71fa4e5f1 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -65,6 +65,7 @@ EXPORT_SYMBOL_GPL(panic_timeout); #define PANIC_PRINT_LOCK_INFO 0x00000008 #define PANIC_PRINT_FTRACE_INFO 0x00000010 #define PANIC_PRINT_ALL_PRINTK_MSG 0x00000020 +#define PANIC_PRINT_ALL_CPU_BT 0x00000040 unsigned long panic_print; ATOMIC_NOTIFIER_HEAD(panic_notifier_list); @@ -151,6 +152,9 @@ static void panic_print_sys_info(void) if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG) console_flush_on_panic(CONSOLE_REPLAY_ALL); + if (panic_print & PANIC_PRINT_ALL_CPU_BT) + trigger_all_cpu_backtrace(); + if (panic_print & PANIC_PRINT_TASK_INFO) show_state(); From patchwork Tue Nov 9 20:28:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 12611057 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA953C433EF for ; Tue, 9 Nov 2021 20:47:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D11E66102A for ; Tue, 9 Nov 2021 20:47:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244739AbhKIUuD (ORCPT ); Tue, 9 Nov 2021 15:50:03 -0500 Received: from fanzine2.igalia.com ([213.97.179.56]:33726 "EHLO fanzine.igalia.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244756AbhKIUuD (ORCPT ); Tue, 9 Nov 2021 15:50:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=GfjvBUEO6CHJKx4vDHWQYbiB8efYdnD/KZ9F5VdyVnA=; b=UuS+dG94ZFZVJLJDtZgHoPYWySpSY0y+5yAHA8dRU7mJb8SBudGviFzQI2OwdHjG2FcW4N8M7DFwj9lxcewuhWkDpOhYPBX5GiR7Y4vQghfZUDhCk+vO/IFkE0y8f/MS30rTsJCKZUuuT/A3KemjU19FZ+D4IzlWhQiJopLk4t8AHEe8U62PSe5ukCJH3kfamrKoqMVA3aV+E2wWn2sxi6Qvvsz0hPWx6QR9Vh5ot3VOJYatC1iKE0E5RMVYAteojHAH8DUAqrIZag9tSf0shwWpsnCayG4NhwgWCeNcErV0OS1uCt0OG7ayiuiOoMo5buQILUUAgB2rtvjgga4yOQ==; Received: from 201-95-14-182.dsl.telesp.net.br ([201.95.14.182] helo=localhost) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1mkXlT-0000Md-Af; Tue, 09 Nov 2021 21:30:44 +0100 From: "Guilherme G. Piccoli" To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-doc@vger.kernel.org, mcgrof@kernel.org, keescook@chromium.org, yzaikin@google.com, akpm@linux-foundation.org, feng.tang@intel.com, siglesias@igalia.com, kernel@gpiccoli.net, gpiccoli@igalia.com Subject: [PATCH 3/3] panic: Allow printing extra panic information on kdump Date: Tue, 9 Nov 2021 17:28:48 -0300 Message-Id: <20211109202848.610874-4-gpiccoli@igalia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211109202848.610874-1-gpiccoli@igalia.com> References: <20211109202848.610874-1-gpiccoli@igalia.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Currently we have the "panic_print" parameter/sysctl to allow some extra information to be printed in a panic event. On the other hand, the kdump mechanism allows to kexec a new kernel to collect a memory dump for the running kernel in case of panic. Right now these options are incompatible: the user either sets the kdump or makes use of "panic_print". The code path of "panic_print" isn't reached when kdump is configured. There are situations though in which this would be interesting: for example, in systems that are very memory constrained, a handcrafted tiny kernel/initrd for kdump might be used in order to only collect the dmesg in kdump kernel. Even more common, systems with no disk space for the full (compressed) memory dump might very well rely in this functionality too, dumping only the dmesg with the additional information provided by "panic_print". So, this is what the patch does: allows both functionality to co-exist; if "panic_print" is set and the system performs a kdump, the extra information is printed on dmesg before the kexec. Some notes about the design choices here: (a) We could have introduced a sysctl or an extra bit on "panic_print" to allow enabling the co-existence of kdump and "panic_print", but seems that would be over-engineering; we have 3 cases, let's check how this patch change things: - if the user have kdump set and not "panic_print", nothing changes; - if the user have "panic_print" set and not kdump, nothing changes; - if both are enabled, now we print the extra information before kdump, which is exactly the goal of the patch (and should be the goal of the user, since they enabled both options). (b) We assume that the code path won't return from __crash_kexec() so we didn't guard against double execution of panic_print_sys_info(). Signed-off-by: Guilherme G. Piccoli --- kernel/panic.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/panic.c b/kernel/panic.c index 5da71fa4e5f1..439dbf93b406 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -243,6 +243,13 @@ void panic(const char *fmt, ...) */ kgdb_panic(buf); + /* + * If we have a kdump kernel loaded, give a chance to panic_print + * show some extra information on kernel log if it was set... + */ + if (kexec_crash_loaded()) + panic_print_sys_info(); + /* * If we have crashed and we have a crash kernel loaded let it handle * everything else.