From: John Ogness <john.ogness@linutronix.de>
To: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
Ryan Roberts <ryan.roberts@arm.com>,
Breno Leitao <leitao@debian.org>,
printk@lists.linux.dev, linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Rio <rioo.tsukatsukii@gmail.com>,
Danilo Krummrich <dakr@kernel.org>,
Aaron Tomlin <atomlin@atomlin.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Alessandro Carminati <acarmina@redhat.com>,
Pnina Feder <pnina.feder@mobileye.com>,
Gal Pressman <gal@nvidia.com>
Subject: [PATCH printk v3 1/7] printk: Introduce and specify flush reasons
Date: Thu, 19 Nov 2026 00:09:37 +0106 [thread overview]
Message-ID: <20261118230345.808560-2-john.ogness@linutronix.de> (raw)
In-Reply-To: <20261118230345.808560-1-john.ogness@linutronix.de>
Prepare for per-console unsafe atomic flushing policies by
introducing enum pr_flush_reason to classify various reasons
for performing a printk backlog flush. Specify the reason for
nbcon_atomic_flush_unsafe().
Propagate the reason down to __nbcon_atomic_flush_pending(),
where consoles are selected for atomic flushing.
Update the nbcon_atomic_flush_unsafe() and
__nbcon_atomic_flush_pending() call sites to specify the flush
reason.
Note that PR_FLUSH_RUNTIME is used for cases where the reason
for the flush is not clearly defined.
No functional change.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
include/linux/printk.h | 17 +++++++++++++++--
kernel/panic.c | 2 +-
kernel/printk/nbcon.c | 11 +++++++----
3 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/include/linux/printk.h b/include/linux/printk.h
index f594c1266bfd4..68cf51db5f0ea 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -145,6 +145,19 @@ void early_printk(const char *s, ...) { }
struct dev_printk_info;
+/**
+ * enum pr_flush_reason - Reason for a flush
+ * @PR_FLUSH_RUNTIME: A flush while the kernel is running
+ * @PR_FLUSH_HANG: The kernel is ending and will enter an infinite loop
+ *
+ * Flush reasons are used to determine if unsafe atomic flushing should be
+ * performed, based on individual console policies.
+ */
+enum pr_flush_reason {
+ PR_FLUSH_RUNTIME,
+ PR_FLUSH_HANG,
+};
+
#ifdef CONFIG_PRINTK
asmlinkage __printf(4, 0)
int vprintk_emit(int facility, int level,
@@ -207,7 +220,7 @@ void console_try_replay_all(void);
void printk_legacy_allow_panic_sync(void);
extern bool nbcon_device_try_acquire(struct console *con);
extern void nbcon_device_release(struct console *con);
-void nbcon_atomic_flush_unsafe(void);
+void nbcon_atomic_flush_unsafe(enum pr_flush_reason reason);
bool pr_flush(int timeout_ms, bool reset_on_progress);
#else
static inline __printf(1, 0)
@@ -318,7 +331,7 @@ static inline void nbcon_device_release(struct console *con)
{
}
-static inline void nbcon_atomic_flush_unsafe(void)
+static inline void nbcon_atomic_flush_unsafe(enum pr_flush_reason reason)
{
}
diff --git a/kernel/panic.c b/kernel/panic.c
index a4dbb6b8cd2bf..21d0ca892c64f 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -765,7 +765,7 @@ void vpanic(const char *fmt, va_list args)
* Explicitly flush the kernel log buffer one last time.
*/
console_flush_on_panic(CONSOLE_FLUSH_PENDING);
- nbcon_atomic_flush_unsafe();
+ nbcon_atomic_flush_unsafe(PR_FLUSH_HANG);
local_irq_enable();
for (i = 0; ; i += PANIC_TIMER_STEP) {
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index 5f8afaca88665..72fb49ade6fe5 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -1652,9 +1652,10 @@ static void nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq)
/**
* __nbcon_atomic_flush_pending - Flush all nbcon consoles using their
* write_atomic() callback
+ * @reason: The reason for the flush
* @stop_seq: Flush up until this record
*/
-static void __nbcon_atomic_flush_pending(u64 stop_seq)
+static void __nbcon_atomic_flush_pending(enum pr_flush_reason reason, u64 stop_seq)
{
struct console *con;
int cookie;
@@ -1688,20 +1689,22 @@ static void __nbcon_atomic_flush_pending(u64 stop_seq)
*/
void nbcon_atomic_flush_pending(void)
{
- __nbcon_atomic_flush_pending(prb_next_reserve_seq(prb));
+ __nbcon_atomic_flush_pending(PR_FLUSH_RUNTIME, prb_next_reserve_seq(prb));
}
/**
* nbcon_atomic_flush_unsafe - Flush all nbcon consoles using their
* write_atomic() callback and allowing unsafe hostile takeovers
*
+ * @reason: The reason for the flush
+ *
* Flush the backlog up through the currently newest record. Unsafe hostile
* takeovers will be performed, if necessary.
*/
-void nbcon_atomic_flush_unsafe(void)
+void nbcon_atomic_flush_unsafe(enum pr_flush_reason reason)
{
panic_nbcon_allow_unsafe_takeover = true;
- __nbcon_atomic_flush_pending(prb_next_reserve_seq(prb));
+ __nbcon_atomic_flush_pending(reason, prb_next_reserve_seq(prb));
panic_nbcon_allow_unsafe_takeover = false;
}
--
2.47.3
next prev parent reply other threads:[~2026-11-18 23:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 23:03 [PATCH printk v3 0/7] Introduce policies for unsafe flushing John Ogness
2026-11-18 23:03 ` John Ogness [this message]
2026-11-18 23:03 ` [PATCH printk v3 2/7] printk: nbcon: Move unsafe takeover check to higher level John Ogness
2026-11-18 23:03 ` [PATCH printk v3 3/7] printk: Move unsafe takeover check out of console_is_usable() John Ogness
2026-11-18 23:03 ` [PATCH printk v3 4/7] printk: Use @reason instead of global variable to check flush policy John Ogness
2026-11-18 23:03 ` [PATCH printk v3 5/7] console: Support unsafe flushing for panic/emergency restarts John Ogness
2026-11-18 23:03 ` [PATCH printk v3 6/7] printk: Add unsafe flush points for panic+kexec and emergency_restart John Ogness
2026-11-18 23:03 ` [PATCH printk v3 7/7] netconsole: Perform unsafe flushing on panic and emergency restart John Ogness
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=20261118230345.808560-2-john.ogness@linutronix.de \
--to=john.ogness@linutronix.de \
--cc=acarmina@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=atomlin@atomlin.com \
--cc=dakr@kernel.org \
--cc=gal@nvidia.com \
--cc=gregkh@linuxfoundation.org \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=pnina.feder@mobileye.com \
--cc=printk@lists.linux.dev \
--cc=rioo.tsukatsukii@gmail.com \
--cc=rostedt@goodmis.org \
--cc=ryan.roberts@arm.com \
--cc=senozhatsky@chromium.org \
/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®