mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Kees Cook <kees@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Petr Mladek <pmladek@suse.com>
Cc: Tony Luck <tony.luck@intel.com>,
	"Guilherme G. Piccoli" <gpiccoli@igalia.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	John Ogness <john.ogness@linutronix.de>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	tzungbi@kernel.org, tfiga@chromium.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] printk: Introduce CON_BYPASS_LOGLEVEL flag
Date: Mon, 31 Aug 2026 07:03:45 +0000	[thread overview]
Message-ID: <20260831070346.3490745-2-tzungbi@kernel.org> (raw)
In-Reply-To: <20260831070346.3490745-1-tzungbi@kernel.org>

Currently, offline consoles (e.g., pstore_console backed by ramoops)
inherently rely on the global `console_loglevel` setting.  If a system
is configured with a quiet serial console, the pstore console is
silenced as well.  Consequently, during a panic or lockup, relevant
verbose logs leading up to the crash are lost.

Introduce the `CON_BYPASS_LOGLEVEL` flag to allow consoles to bypass log
level suppression.

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
 include/linux/console.h | 4 ++++
 kernel/printk/nbcon.c   | 7 +++++--
 kernel/printk/printk.c  | 6 ++++--
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/include/linux/console.h b/include/linux/console.h
index d624200cfc17..00ce21d73256 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -180,6 +180,9 @@ static inline void con_debug_leave(void) { }
  *			constraints.
  * @CON_NBCON_ATOMIC_UNSAFE: The write_atomic() callback is not safe and is
  *			therefore only used by nbcon_atomic_flush_unsafe().
+ * @CON_BYPASS_LOGLEVEL	The console bypasses loglevel filtering. Every message
+ *			in the ringbuffer is emitted, regardless of the global
+ *			console_loglevel setting.
  */
 enum cons_flags {
 	CON_PRINTBUFFER		= BIT(0),
@@ -192,6 +195,7 @@ enum cons_flags {
 	CON_SUSPENDED		= BIT(7),
 	CON_NBCON		= BIT(8),
 	CON_NBCON_ATOMIC_UNSAFE	= BIT(9),
+	CON_BYPASS_LOGLEVEL	= BIT(10),
 };
 
 /**
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index 4b03b019cd5e..bb5669cbf51b 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -981,7 +981,9 @@ static bool nbcon_emit_next_record(struct nbcon_write_context *wctxt, bool use_a
 {
 	struct nbcon_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt);
 	struct console *con = ctxt->console;
-	bool is_extended = console_srcu_read_flags(con) & CON_EXTENDED;
+	short console_flags = console_srcu_read_flags(con);
+	bool is_extended = console_flags & CON_EXTENDED;
+	bool may_suppress = !(console_flags & CON_BYPASS_LOGLEVEL);
 	struct printk_message pmsg = {
 		.pbufs = ctxt->pbufs,
 	};
@@ -1014,7 +1016,8 @@ static bool nbcon_emit_next_record(struct nbcon_write_context *wctxt, bool use_a
 	if (!nbcon_context_enter_unsafe(ctxt))
 		return false;
 
-	ctxt->backlog = printk_get_next_message(&pmsg, ctxt->seq, is_extended, true);
+	ctxt->backlog = printk_get_next_message(&pmsg, ctxt->seq, is_extended,
+						may_suppress);
 	if (!ctxt->backlog)
 		return nbcon_context_exit_unsafe(ctxt);
 
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 3fcdf4b4e2e5..b8a7a8b69af7 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -3125,7 +3125,9 @@ struct printk_buffers printk_shared_pbufs;
  */
 static bool console_emit_next_record(struct console *con, bool *handover, int cookie)
 {
-	bool is_extended = console_srcu_read_flags(con) & CON_EXTENDED;
+	short console_flags = console_srcu_read_flags(con);
+	bool is_extended = console_flags & CON_EXTENDED;
+	bool may_suppress = !(console_flags & CON_BYPASS_LOGLEVEL);
 	char *outbuf = &printk_shared_pbufs.outbuf[0];
 	struct printk_message pmsg = {
 		.pbufs = &printk_shared_pbufs,
@@ -3134,7 +3136,7 @@ static bool console_emit_next_record(struct console *con, bool *handover, int co
 
 	*handover = false;
 
-	if (!printk_get_next_message(&pmsg, con->seq, is_extended, true))
+	if (!printk_get_next_message(&pmsg, con->seq, is_extended, may_suppress))
 		return false;
 
 	con->dropped += pmsg.dropped;
-- 
2.55.0.897.gb25b4bd76c-goog


  reply	other threads:[~2026-08-31  7:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31  7:03 [PATCH 0/2] printk: Introduce loglevel bypass for pstore console Tzung-Bi Shih
2026-08-31  7:03 ` Tzung-Bi Shih [this message]
2026-08-31  7:03 ` [PATCH 2/2] pstore: Bypass loglevel suppression " Tzung-Bi Shih

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=20260831070346.3490745-2-tzungbi@kernel.org \
    --to=tzungbi@kernel.org \
    --cc=gpiccoli@igalia.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=john.ogness@linutronix.de \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=tfiga@chromium.org \
    --cc=tony.luck@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

all inboxes | Powered by JetHome®