[PATCH printk v2 2/6] console: Introduce unsafe flush policy flags

From: John Ogness

Date: Wed Nov 11 2026 - 13:51:13 EST


Prepare for per-console atomic flushing policies by introducing a
new nbcon-specific console field @unsafe_flush_flags to store the
unsafe flush policies for a console. The policies are represented
by bits, specified by enum nbcon_unsafe_flush_flags.

Currently it is expected that any @unsafe_flush_flags bits are set
prior to console registration and do not change while registered.

No functional change.

Signed-off-by: John Ogness <john.ogness@xxxxxxxxxxxxx>
---
include/linux/console.h | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)

diff --git a/include/linux/console.h b/include/linux/console.h
index 06d01f1743512..beb1ee04535b7 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -194,6 +194,29 @@ enum cons_flags {
CON_NBCON_ATOMIC_UNSAFE = BIT(9),
};

+/**
+ * enum nbcon_unsafe_flush_flags - Unsafe atomic flush policy flags
+ * @NBCON_PANIC_FLUSH: In panic, unsafe flush before kexec or reboot.
+ * @NBCON_PANIC_PRINTK: In panic, unsafe flush on each printk().
+ * @NBCON_NORMAL_NOTHREAD: During normal operation, when printing
+ * kthreads are unreliable or have been shutdown,
+ * unsafe flush on each printk() or on explicit
+ * flushing.
+ * @NBCON_KDB: Unsafe flush kdb output.
+ *
+ * NBCON unsafe atomic flushing always occurs at the end of panic() before
+ * the kernel enters an infinite loop. Users may choose to perform unsafe
+ * flushing in additional scenarios where the current kernel is ending in
+ * order to increase the chances of seeing console messages, even if it is
+ * not safe to do so.
+ */
+enum nbcon_unsafe_flush_flags {
+ NBCON_PANIC_FLUSH = BIT(0),
+ NBCON_PANIC_PRINTK = BIT(1),
+ NBCON_NORMAL_NOTHREAD = BIT(2),
+ NBCON_KDB = BIT(3),
+};
+
/**
* struct nbcon_state - console state for nbcon consoles
* @atom: Compound of the state fields for atomic operations
@@ -326,6 +349,7 @@ struct nbcon_write_context {
* @data: Driver private data
* @node: hlist node for the console list
*
+ * @unsafe_flush_flags: Unsafe atomic flush policy. See enum nbcon_unsafe_flush_flags
* @nbcon_state: State for nbcon consoles
* @nbcon_seq: Sequence number of the next record for nbcon to print
* @nbcon_device_ctxt: Context available for non-printing operations
@@ -461,6 +485,8 @@ struct console {
*/
void (*device_unlock)(struct console *con, unsigned long flags);

+ unsigned int unsafe_flush_flags;
+
atomic_t __private nbcon_state;
atomic_long_t __private nbcon_seq;
struct nbcon_context __private nbcon_device_ctxt;
--
2.47.3