From: Petr Mladek <pmladek@suse.com>
To: John Ogness <john.ogness@linutronix.de>
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,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH printk v2 2/6] console: Introduce unsafe flush policy flags
Date: Fri, 13 Nov 2026 17:17:29 +0100 [thread overview]
Message-ID: <avc4GVqYdpL8r3Un@pathway.suse.cz> (raw)
In-Reply-To: <20261111181942.593695-3-john.ogness@linutronix.de>
On Wed 2026-11-11 19:25:18, John Ogness wrote:
> 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@linutronix.de>
> ---
> 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().
Do we need to distinguish between flush in printk() and an explicit flush?
IMHO, there is no reason. We usually call the explicit flush because
we want to trigger it. But printk(), called in the same context,
should trigger/do it as well.
> + * @NBCON_NORMAL_NOTHREAD: During normal operation, when printing
> + * kthreads are unreliable or have been shutdown,
> + * unsafe flush on each printk() or on explicit
> + * flushing.
Do we need to distinguish between panic and non-panic paths when the
kthreads do not work?
IMHO, this is more about that the system is going down and the
kthreads do not work.
Also what about emergency context when the system is about
to continue?
> + * @NBCON_KDB: Unsafe flush kdb output.
OK, let's assume that we want to set a policy where we allow
the unsafe takeover in the following contexts:
NBCON_ALLOW_UNSAFE_NEVER
NBCON_ALLOW_UNSAFE_RESTART
NBCON_ALLOW_UNSAFE_EMERGENCY
NBCON_ALLOW_UNSAFE_KDB
, where
+ NEVER might actually allow it when explicitely enabled in
nbcon_panic_flush_unsafe(). The word "never" just has a simple
semantic in the context of the other values
+ RESTART would allow the unsafe takeover in printk()/flush()
when the system is doing halt/reboot/crash_kexec...
+ EMERGENCY would allow it even in NBCON_PRIO_EMERGENCY context.
+ KDB would allow it in KDB context
And I would get the context the following way:
enum nbcon_allow_unsafe get_nbcon_allow_unsafe_request(void)
{
enum nbcon_prio prio;
/*
* The kdb check is copied from vprintk() implementation.
* We should put it into a helper.
*/
#ifdef CONFIG_KGDB_KDB
/* Allow to pass printk() to kdb but avoid a recursion. */
if (unlikely(kdb_trap_printk && kdb_printf_cpu < 0))
return NBCON_ALLOW_UNSAFE_KDB;
#endif
prio = nbcon_get_default_prio();
/* FIXME: What about SYSTEM_SUSPEND?
if (prio == NBCON_PRIO_PANIC || system_state > SYSTEM_RUNNING)
return NBCON_ALLOW_UNSAFE_RESTART;
if (prio == NBCON_PRIO_EMERGENCY)
return NBCON_ALLOW_UNSAFE_EMERGENCY;
return NBCON_ALLOW_UNSAFE_NEVER;
}
IMHO, this better fits the existing terminology and design.
And it should be much easier to understand by developers
and users.
+ *
> + * 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;
I would call it:
unsigned int allow_unsafe_policy;
> +
> atomic_t __private nbcon_state;
> atomic_long_t __private nbcon_seq;
> struct nbcon_context __private nbcon_device_ctxt;
And the net console would get initialized to:
.allow_unsafe_policy = NBCON_ALLOW_UNSAFE_RESTART | NBCON_ALLOW_UNSAFE_KDB;
And nbcon_allow_unsafe_takeover would get implemented as:
static bool nbcon_allow_unsafe_takeover(struct console *con)
{
allow_unsafe_request = get_nbcon_allow_unsafe();
if (con->allow_unsafe_policy & get_nbcon_allow_usafe_request())
return true;
return panic_nbcon_allow_unsafe_takeover;
}
What do you think, please?
Best Regards,
Petr
next prev parent reply other threads:[~2026-11-13 16:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 18:19 [PATCH printk v2 0/6] Introduce policies for unsafe flushing John Ogness
2026-11-11 18:19 ` [PATCH printk v2 1/6] printk: Introduce and specify flush reasons John Ogness
2026-11-13 15:05 ` Petr Mladek
2026-11-11 18:19 ` [PATCH printk v2 2/6] console: Introduce unsafe flush policy flags John Ogness
2026-11-13 16:17 ` Petr Mladek [this message]
2026-11-11 18:19 ` [PATCH printk v2 3/6] printk: Evaluate flush policy in nbcon_allow_unsafe_takeover() John Ogness
2026-11-11 18:19 ` [PATCH printk v2 4/6] printk: Remove nbcon_atomic_flush_unsafe() John Ogness
2026-11-11 18:19 ` [PATCH printk v2 5/6] printk: Add panic+kexec flush point John Ogness
2026-11-12 18:20 ` sashiko-bot
2026-11-11 18:19 ` [PATCH printk v2 6/6] netconsole: Always perform unsafe flushing on panic/kdb/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=avc4GVqYdpL8r3Un@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=gregkh@linuxfoundation.org \
--cc=john.ogness@linutronix.de \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=printk@lists.linux.dev \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.