mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 15:08:22 +0100	[thread overview]
Message-ID: <awbr1gCJTiLQB4he@pathway.suse.cz> (raw)
In-Reply-To: <awa28PGg8L4rEDha@pathway.suse.cz>

On Wed 2026-11-25 11:22:40, Petr Mladek wrote:
> 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.
> > 
> 
> 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()) {

The panic_on_this_cpu() check actually is not needed because
NBCON_PRIO_PANIC is used only on the panic_cpu.

Best Regards,
Petr


> 			*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

  parent reply	other threads:[~2026-11-25 14:08 UTC|newest]

Thread overview: 16+ 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
2026-11-25 13:06     ` Petr Mladek
2026-11-25 14:08     ` 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-25 14:02   ` Petr Mladek
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=awbr1gCJTiLQB4he@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®