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,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH printk v4 3/8] printk: Move unsafe takeover check out of console_is_usable()
Date: Thu, 26 Nov 2026 10:57:20 +0106 [thread overview]
Message-ID: <87o6bb7wfb.fsf@jogness.linutronix.de> (raw)
In-Reply-To: <awW3u4xEwwbQARPl@pathway.suse.cz>
On 2026-11-24, Petr Mladek <pmladek@suse.com> wrote:
>> @@ -645,11 +639,7 @@ static inline bool console_is_usable(struct console *con, short flags, bool use_
>> if (!con->write_atomic)
>> return false;
>>
>> - /*
>> - * An unsafe write_atomic() callback is only usable
>> - * when unsafe takeovers are allowed.
>> - */
>> - if ((flags & CON_NBCON_ATOMIC_UNSAFE) && !nbcon_allow_unsafe_takeover())
>> + if (!allow_atomic_unsafe && (flags & CON_NBCON_ATOMIC_UNSAFE))
>
> This is a good example that different people have different mental mode and
> prefers another ordering of the checks ;-)
The reason for the switch was because this function becomes a helper
that operates in 2 modes: with atomic_unsafe, without atomic_unsafe. So
I felt it was appropriate to make the "mode of operation" the primary
component of the condition. But since you suggest to move away from
making this a helper, I will switch it back.
>> --- a/kernel/printk/nbcon.c
>> +++ b/kernel/printk/nbcon.c
>> @@ -1468,7 +1468,7 @@ static bool panic_nbcon_allow_unsafe_takeover;
>> * This is also used by console_is_usable() to determine if it is allowed to
>> * call write_atomic() callbacks flagged as unsafe (CON_NBCON_ATOMIC_UNSAFE).
>> */
>> -bool nbcon_allow_unsafe_takeover(void)
>> +static bool nbcon_allow_unsafe_takeover(void)
>> {
>> return panic_on_this_cpu() && panic_nbcon_allow_unsafe_takeover;
>> }
>> @@ -1672,11 +1672,24 @@ static void __nbcon_atomic_flush_pending(enum pr_flush_reason reason, u64 stop_s
>> if (!(flags & CON_NBCON))
>> continue;
>>
>> - if (!console_is_usable(con, flags, true))
>> + /*
>> + * Using variant of console_is_usable() to include consoles
>> + * with unsafe write_atomic() implementations. They might be
>> + * allowed depending on nbcon_allow_unsafe_takeover().
>> + */
>> + if (!nbcon_is_unsafe_usable(con, flags))
>> continue;
>
> The above function pretends that an unsafe takeover is enabled.
This series establishes that:
unsafe takeover != unsafe usage
At this point in the series that distinction is not yet possible. I was
attempting to:
- keep patch sizes small
- have as many "no functional changes" steps as possible
I will see what I can do here. It might be easier after following your
suggestions.
>> allow_unsafe_takeover = nbcon_allow_unsafe_takeover();
>
> Here we get the information whether it is actually allowed.
>
>> + /*
>> + * 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)
>> + continue;
>
> Here we duplicate the check from __console_is_usable() using the updated
> information.
>
> It is a bit hairy. It might be better to use the up-to-date
> information in console_is_usable*().
>
> I suggest to rename __console_is_usable() -> console_is_usable_unsafe().
> It would take 4 parameters, including @allow_unsafe_takeover.
Agreed. That is clean and fits the end of the series as well.
John
next prev parent reply other threads:[~2026-11-26 9:51 UTC|newest]
Thread overview: 21+ 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-26 9:51 ` John Ogness [this message]
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-26 9:53 ` John Ogness
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
2026-11-25 13:06 ` Petr Mladek
2026-11-25 14:08 ` Petr Mladek
2026-11-26 10:36 ` John Ogness
2026-11-21 16:35 ` [PATCH printk v4 6/8] console: Support unsafe flushing for panic/emergency restarts John Ogness
2026-11-25 14:02 ` Petr Mladek
2026-11-26 10:45 ` 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-21 16:47 ` [PATCH printk v4 0/8] Introduce policies for unsafe flushing sashiko-bot
2026-11-23 22:15 ` 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=87o6bb7wfb.fsf@jogness.linutronix.de \
--to=john.ogness@linutronix.de \
--cc=gregkh@linuxfoundation.org \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--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.