All of lore.kernel.org
 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 4/8] printk: nbcon: Use @reason instead of global variable to check flush policy
Date: Tue, 24 Nov 2026 17:27:44 +0100	[thread overview]
Message-ID: <awW7AFsiUkhRWdqy@pathway.suse.cz> (raw)
In-Reply-To: <20261121163557.963029-5-john.ogness@linutronix.de>

On Sat 2026-11-21 17:41:52, John Ogness wrote:
> Currently nbcon_allow_unsafe_takeover() is a hack, relying on the
> temporary setting of a global variable @panic_nbcon_allow_unsafe_takeover
> as a gate to determine if unsafe flushing is allowed. This hack works
> because unsafe flushing is only performed at the end of panic().
> However, this hack is _not_ sufficient if unsafe flushing is to be
> allowed in other contexts.
> 
> Since at the end of panic() nbcon_atomic_flush_unsafe() is called with
> the @reason PR_FLUSH_HANG, it is possible to identify when unsafe
> atomic flushing is allowed using:
> 
> 	PR_FLUSH_HANG && panic_on_this_cpu()
> 
> rather than:
> 
> 	panic_nbcon_allow_unsafe_takeover && panic_on_this_cpu()
> 
> This allows removing the global variable hack and opens the door for
> unsafe flushing to be allowed in other contexts.
> 
> Provide nbcon_allow_unsafe_takeover() the flush @reason to implement
> the check.
> 
> No functional change.
> 
> --- a/kernel/printk/nbcon.c
> +++ b/kernel/printk/nbcon.c
> @@ -1453,24 +1453,31 @@ enum nbcon_prio nbcon_get_default_prio(void)
>  	return NBCON_PRIO_NORMAL;
>  }
>  
> -/*
> - * Track if it is allowed to perform unsafe hostile takeovers of console
> - * ownership. When true, console drivers might perform unsafe actions while
> - * printing. It is externally available via nbcon_allow_unsafe_takeover().
> - */
> -static bool panic_nbcon_allow_unsafe_takeover;
> -
>  /**
>   * nbcon_allow_unsafe_takeover - Check if unsafe console takeovers are allowed
> + *					for a specified console and reason
>   *
> - * Return:	True, when it is permitted to perform unsafe console printing
> + * @con:	The console to check
> + * @reason:	The reason for the 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).
> + * Return:	True, when @con is allowed to perform unsafe console printing
>   */
> -static bool nbcon_allow_unsafe_takeover(void)
> +static bool nbcon_allow_unsafe_takeover(struct console *con, enum pr_flush_reason reason)

Nit: It seems that the @con parameter is not used in this version.
     So, it might trigger a warning during bisection.

>  {
> -	return panic_on_this_cpu() && panic_nbcon_allow_unsafe_takeover;
> +	enum nbcon_prio prio = nbcon_get_default_prio();
> +	bool allow = false;
> +
> +	switch (reason) {
> +	case PR_FLUSH_RUNTIME:
> +		/* Never unsafe flush during runtime. */
> +		break;
> +	case PR_FLUSH_HANG:
> +		/* Always unsafe flush on panic hang. */
> +		allow = (prio == NBCON_PRIO_PANIC);
> +		break;
> +	}
> +
> +	return allow;
>  }

Otherwise, the logic looks correct.

Best Regards,
Petr

  reply	other threads:[~2026-11-24 16:27 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
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 [this message]
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=awW7AFsiUkhRWdqy@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 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.