public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
To: Petr Mladek <pmladek@suse.com>, Feng Tang <feng.tang@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	linux-kernel@vger.kernel.org, Kees Cook <keescook@chromium.org>,
	Borislav Petkov <bp@suse.de>,
	ying.huang@intel.com,
	Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Subject: Re: [PATCH v2] panic: add an option to replay all the printk message in buffer
Date: Wed, 17 Apr 2019 19:50:10 +0900	[thread overview]
Message-ID: <20190417105010.GA8492@jagdpanzerIV> (raw)
In-Reply-To: <20190417094614.GB4260@jagdpanzerIV>

On (04/17/19 18:46), Sergey Senozhatsky wrote:
> 
> Does not look too complex/ugly.

Looks simpler than adding one more global state to the
console_unlock() printing loop.

// Not tested at all //

---

diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 1fd45a8650e1..0fb785ed5ec6 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(CONSOLE_FLUSH_PENDING);
 }
 
 static unsigned long oops_begin(struct pt_regs *regs)
diff --git a/include/linux/console.h b/include/linux/console.h
index ec9bdb3d7bab..9e306eb4398a 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -175,7 +175,13 @@ 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);
+
+enum console_flush_mode {
+	CONSOLE_FLUSH_PENDING,
+	CONSOLE_FLUSH_ALL,
+};
+
+extern void console_flush_on_panic(enum console_flush_mode flush_mode);
 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 cd73af35ec66..50eacfc9bc7e 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -51,6 +51,7 @@ EXPORT_SYMBOL_GPL(panic_timeout);
 #define PANIC_PRINT_TIMER_INFO		0x00000004
 #define PANIC_PRINT_LOCK_INFO		0x00000008
 #define PANIC_PRINT_FTRACE_INFO		0x00000010
+#define PANIC_PRINT_ALL_PRINTK_MSG	0x00000020
 unsigned long panic_print;
 
 ATOMIC_NOTIFIER_HEAD(panic_notifier_list);
@@ -148,6 +149,9 @@ static void panic_print_sys_info(void)
 
 	if (panic_print & PANIC_PRINT_FTRACE_INFO)
 		ftrace_dump(DUMP_ALL);
+
+	if (panic_print & PANIC_PRINT_ALL_PRINTK_MSG)
+		console_flush_on_panic(CONSOLE_FLUSH_ALL);
 }
 
 /**
@@ -277,7 +281,7 @@ void panic(const char *fmt, ...)
 	 * panic() is not being callled from OOPS.
 	 */
 	debug_locks_off();
-	console_flush_on_panic();
+	console_flush_on_panic(CONSOLE_FLUSH_PENDING);
 
 	panic_print_sys_info();
 
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 17102fd4c136..da60a185dbbb 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2538,7 +2538,7 @@ void console_unblank(void)
  *
  * Immediately output all pending messages no matter what.
  */
-void console_flush_on_panic(void)
+void console_flush_on_panic(enum console_flush_mode flush_mode)
 {
 	/*
 	 * If someone else is holding the console lock, trylock will fail
@@ -2549,6 +2549,14 @@ void console_flush_on_panic(void)
 	 */
 	console_trylock();
 	console_may_schedule = 0;
+	if (flush_mode == CONSOLE_FLUSH_ALL) {
+		/*
+		 * Can be done under logbuf lock, but it's unlikely that
+		 * we will have any race conditions here.
+		 */
+		console_seq = log_first_seq;
+		console_idx = log_first_idx;
+	}
 	console_unlock();
 }
 
---

  reply	other threads:[~2019-04-17 10:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-10 15:37 [PATCH v2] panic: add an option to replay all the printk message in buffer Feng Tang
2019-04-17  4:19 ` Andrew Morton
2019-04-17  6:48   ` Feng Tang
2019-04-17  9:18     ` Petr Mladek
2019-04-17  9:46       ` Sergey Senozhatsky
2019-04-17 10:50         ` Sergey Senozhatsky [this message]
2019-04-17 12:24           ` Petr Mladek
2019-04-17 15:18             ` Feng Tang
2019-04-18  0:00               ` Sergey Senozhatsky
2019-04-18  7:45                 ` Petr Mladek
2019-04-18  9:00                   ` Feng Tang
2019-04-18 11:01                     ` Petr Mladek
2019-04-19  2:08                       ` Feng Tang
2019-04-18 10:50                   ` Sergey Senozhatsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190417105010.GA8492@jagdpanzerIV \
    --to=sergey.senozhatsky.work@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=bp@suse.de \
    --cc=feng.tang@intel.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=ying.huang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox