Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp152994yba; Mon, 1 Apr 2019 03:48:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqze+GWEAD3QgwS9fiduanQkorCaJwCSp00SZ8eLefu68rMKFC9w0oeVSDQd1LasEz8SQqi7 X-Received: by 2002:a63:4b14:: with SMTP id y20mr9767964pga.306.1554115736867; Mon, 01 Apr 2019 03:48:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554115736; cv=none; d=google.com; s=arc-20160816; b=d9vVAGD5A0PsSLs21l4nEIOw0fVsaannWDW+QJfKpuENpjyiR1GZJRE3mbmwx/jCrL hObi/MTlPHffyQVjpKVP6mSiFSux4nVHOy2SD8FTfh9RNz4ehtuJ4TFynfPRAR3uYVPS Rd3s1EghUkne2+z7zOd7zxljdSPFM72cFFbkVVg31gRzjOqEQSG73PEFCLFFyfGaqFG+ gbua0Dsw4Y5R3OYHiYa6Fg9jA8MzaRN1jQ2RDTFoKCuxxU59A2rL66MmlW5clWnT7hV9 z7XPUtPQHFCwfl5YoNFPeG6R7oOEG8pF3olOTSE2PqJNXdBKB2E9XBbUMPyaEnA2BxWY Au9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=C/5PW5xwvxV6NstGmKPJz4svLCfWkhyCxAMNGZQ2evI=; b=X59pGZ45OhuYSYUYDiJTpRq2MCxx/uu0gUmbIwc2k/wHVfvnefmr1ZICOS7wx7JIJ2 r8dcqkNn40ME/QF6Yz3lvtLAsGOmKTs7J4BqxEx534W06E27Mqi83h+67z3mGY9p7f3O inNYxwxvKijJ654FVAqsdWnQS2q9ijN5Vde24LEbXjCjkCXQMtMnWTINfyAxnwcmywMs 5fhQFNkKrSteKBn1gcZtbJwsOmyPVsjFwv3wQ2dl2AQGTDwXxsVkgRXqfpbdUzoY03La XkKR8lIQvy8oD5R/0WBdsTUvrjgoiHaYtJHznwK/vyv+sQovq4GDIR354hVAKdlkg6XR BiNg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g11si8277965plo.125.2019.04.01.03.48.41; Mon, 01 Apr 2019 03:48:56 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726542AbfDAKrZ (ORCPT + 99 others); Mon, 1 Apr 2019 06:47:25 -0400 Received: from mga09.intel.com ([134.134.136.24]:14977 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725882AbfDAKrZ (ORCPT ); Mon, 1 Apr 2019 06:47:25 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Apr 2019 03:47:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,296,1549958400"; d="scan'208";a="146975622" Received: from shbuild999.sh.intel.com ([10.239.147.118]) by orsmga002.jf.intel.com with ESMTP; 01 Apr 2019 03:47:22 -0700 From: Feng Tang To: Andrew Morton , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , linux-kernel@vger.kernel.org Cc: Kees Cook , Borislav Petkov , Feng Tang Subject: [PATCH 1/2] printk: Add an option to flush all messages on panic Date: Mon, 1 Apr 2019 18:48:03 +0800 Message-Id: <1554115684-26846-1-git-send-email-feng.tang@intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Current console_flush_on_panic() will only dump the new messages in buffer, and users may need an opportunity to check all the messages on panic which could help debugging, as user may haven't seen the log before panic due to loglevel settings. Add a flag for console_flush_on_panic() to chose whether to dump all messages. Signed-off-by: Feng Tang --- arch/powerpc/kernel/traps.c | 2 +- include/linux/console.h | 2 +- kernel/panic.c | 2 +- kernel/printk/printk.c | 9 ++++++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c index 1fd45a8..58d9580 100644 --- a/arch/powerpc/kernel/traps.c +++ b/arch/powerpc/kernel/traps.c @@ -179,7 +179,7 @@ extern void panic_flush_kmsg_end(void) kmsg_dump(KMSG_DUMP_PANIC); bust_spinlocks(0); debug_locks_off(); - console_flush_on_panic(); + console_flush_on_panic(false); } static unsigned long oops_begin(struct pt_regs *regs) diff --git a/include/linux/console.h b/include/linux/console.h index ec9bdb3..825ecf5 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -175,7 +175,7 @@ extern int console_trylock(void); extern void console_unlock(void); extern void console_conditional_schedule(void); extern void console_unblank(void); -extern void console_flush_on_panic(void); +extern void console_flush_on_panic(bool flush_all); extern struct tty_driver *console_device(int *); extern void console_stop(struct console *); extern void console_start(struct console *); diff --git a/kernel/panic.c b/kernel/panic.c index 0ae0d73..fb77e01 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -277,7 +277,7 @@ void panic(const char *fmt, ...) * panic() is not being callled from OOPS. */ debug_locks_off(); - console_flush_on_panic(); + console_flush_on_panic(false); panic_print_sys_info(); diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 02ca827..8ff099b 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2525,10 +2525,11 @@ void console_unblank(void) /** * console_flush_on_panic - flush console content on panic + * @flush_all: whether to print all messages in buffer * * Immediately output all pending messages no matter what. */ -void console_flush_on_panic(void) +void console_flush_on_panic(bool flush_all) { /* * If someone else is holding the console lock, trylock will fail @@ -2539,6 +2540,12 @@ void console_flush_on_panic(void) */ console_trylock(); console_may_schedule = 0; + + /* User may want to see all the printk messages on panic */ + if (flush_all) { + console_seq = log_first_seq; + console_idx = log_first_idx; + } console_unlock(); } -- 2.7.4