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
Subject: Re: [PATCH printk v4 5/8] printk: nbcon: Expand unsafe takeover check for general unsafe
Date: Wed, 25 Nov 2026 11:22:40 +0100 [thread overview]
Message-ID: <awa28PGg8L4rEDha@pathway.suse.cz> (raw)
In-Reply-To: <20261121163557.963029-6-john.ogness@linutronix.de>
On Sat 2026-11-21 17:41:53, John Ogness wrote:
> Currently nbcon_allow_unsafe_takeover() is identifying if hostile
> takeovers are permitted.
>
> In order to support unsafe flush policies for CON_NBCON_ATOMIC_UNSAFE,
> there needs to be a distinction between atomic flushing using an
> unsafe implementation or atomic flushing via hostile takeover. The
> former could be allowed in non-panic, whereas the latter is only
> allowed on the panic CPU.
>
> Rename nbcon_allow_unsafe_takeover() to nbcon_allow_unsafe() and
> change its purpose to identify if unsafe console printing (in general)
> is allowed. If yes, hostile takeover can be allowed when on the panic
> CPU.
>
> The comments for the WARN verifying no hostile takeover attempts
> during non-panic have been expanded. The detailed description will
> hopefully remind us of the necessity of restricting hostile takeovers
> to the panic CPU.
>
> This opens the door for unsafe flushing (with safe ownership) for
> non-panic situations.
>
> No functional change.
>
> --- a/kernel/printk/nbcon.c
> +++ b/kernel/printk/nbcon.c
> @@ -1682,24 +1689,31 @@ static void __nbcon_atomic_flush_pending(enum pr_flush_reason reason, u64 stop_s
> /*
> * Using variant of console_is_usable() to include consoles
> * with unsafe write_atomic() implementations. They might be
> - * allowed depending on nbcon_allow_unsafe_takeover().
> + * allowed depending on nbcon_allow_unsafe().
> */
> if (!nbcon_is_unsafe_usable(con, flags))
> continue;
>
> - allow_unsafe_takeover = nbcon_allow_unsafe_takeover(con, reason);
> + allow_unsafe = nbcon_allow_unsafe(con, reason);
>
> /*
> * Since nbcon_is_unsafe_usable() was used, ensure @con does
> * not have an unsafe write_atomic() if this context expects
> * safe printing.
> */
> - if ((flags & CON_NBCON_ATOMIC_UNSAFE) && !allow_unsafe_takeover)
> + if ((flags & CON_NBCON_ATOMIC_UNSAFE) && !allow_unsafe)
> continue;
>
> if (nbcon_seq_read(con) >= stop_seq)
> continue;
>
> + /*
> + * Even if unsafe console printing is allowed, being able to
> + * perform a hostile takeover additionally requires this CPU
> + * to be in panic.
> + */
> + allow_unsafe_takeover = allow_unsafe && panic_on_this_cpu();
I was a bit confused by this. Also I think that it is error prone. For
example, it allows to use the unsafe_takeover for
CON_NBCON_ATOMIC_UNSAFE consoles anywhere in panic(). But it should
be allowed only for the final nbcon_atomic_flush_unsafe(PR_FLUSH_HANG).
We should make this decision on a single place. I suggest to rename
nbcon_allow_unsafe_takeover() to nbcon_check_unsafe() and pass
*allow_unsafe_takeover as a parameter. I mean something like:
/**
* nbcon_check_unsafe - Check if the console is safe or some unsafe handling
* is allowed for the given context and reason.
*
* @con: The console to check
* @reason: The reason for the unsafe console printing
* @allow_unsafe_takeover: Decision whether unsafe_takeover is allowed (output)
*
* The function decides when either an unsafe write_atomic() callback is
* allowed or when all NBCON consoles are allowed to used the unsafe_takeover.
*
* Return: True, when @con is either safe in all contexts or when it is
* allowed to perform unsafe console printing.
*
* In addition. the @allow_unsafe_takeover variable is set to "true"
* when the console is allowed to perform the unsafe_takeover. Otherwise,
* the variable is set to "false".
*/
static bool nbcon_check_unsafe(struct console *con, enum pr_flush_reason reason,
bool *allow_unsafe_takeover)
{
enum nbcon_prio prio = nbcon_get_default_prio();
bool ret = false;
*allow_unsafe_takeover = false;
switch (reason) {
case PR_FLUSH_RUNTIME:
/* Never unsafe flush during runtime. */
break;
case PR_FLUSH_HANG:
/* Always unsafe flush on panic hang. */
if ((prio == NBCON_PRIO_PANIC) && panic_on_this_cpu()) {
*allow_unsafe_takeover = true;
ret = true;
}
break;
}
return ret;
}
Then we could use the following in __nbcon_atomic_flush_pending():
if (!nbcon_check_unsafe(con, reason, &allow_unsafe_takeover))
continue;
Note 1: We might want to refactor the function when we add the checks
where to allow the unsafe write_atomic() callbacks.
Note 2: I thought about calling this directly in console_is_usable_unsafe().
But it would require passing the *allow_unsafe_takeover as a
parameter which is not needed in most situations when it is called
via the console_is_usable() wrapper. But it still might make
sense if we make the parameter optional (allow NULL).
> +
> nbcon_atomic_flush_pending_con(con, stop_seq, allow_unsafe_takeover);
> }
> console_srcu_read_unlock(cookie);
Best Regards,
Petr
next prev parent reply other threads:[~2026-11-25 10:22 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 16:35 [PATCH printk v4 0/8] Introduce policies for unsafe flushing John Ogness
2026-11-21 16:35 ` [PATCH printk v4 1/8] printk: Introduce and specify flush reasons John Ogness
2026-11-21 16:35 ` [PATCH printk v4 2/8] printk: nbcon: Move unsafe takeover check to higher level John Ogness
2026-11-21 16:35 ` [PATCH printk v4 3/8] printk: Move unsafe takeover check out of console_is_usable() John Ogness
2026-11-24 16:13 ` Petr Mladek
2026-11-21 16:35 ` [PATCH printk v4 4/8] printk: nbcon: Use @reason instead of global variable to check flush policy John Ogness
2026-11-24 16:27 ` Petr Mladek
2026-11-21 16:35 ` [PATCH printk v4 5/8] printk: nbcon: Expand unsafe takeover check for general unsafe John Ogness
2026-11-25 10:22 ` Petr Mladek [this message]
2026-11-21 16:35 ` [PATCH printk v4 6/8] console: Support unsafe flushing for panic/emergency restarts John Ogness
2026-11-21 16:35 ` [PATCH printk v4 7/8] printk: Add unsafe flush points for panic+kexec and emergency_restart John Ogness
2026-11-21 16:35 ` [PATCH printk v4 8/8] netconsole: Perform unsafe flushing on panic and emergency restart John Ogness
2026-11-23 22:15 ` [PATCH printk v4 0/8] Introduce policies for unsafe flushing Gustavo Luiz Duarte
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=awa28PGg8L4rEDha@pathway.suse.cz \
--to=pmladek@suse.com \
--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 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®