public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: John Ogness <john.ogness@linutronix.de>
To: Marcos Paulo de Souza <mpdesouza@suse.com>,
	Richard Weinberger <richard@nod.at>,
	Anton Ivanov <anton.ivanov@cambridgegreys.com>,
	Johannes Berg <johannes@sipsolutions.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jason Wessel <jason.wessel@windriver.com>,
	Daniel Thompson <danielt@kernel.org>,
	Douglas Anderson <dianders@chromium.org>,
	Petr Mladek <pmladek@suse.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Jiri Slaby <jirislaby@kernel.org>,
	Breno Leitao <leitao@debian.org>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Kees Cook <kees@kernel.org>, Tony Luck <tony.luck@intel.com>,
	"Guilherme G. Piccoli" <gpiccoli@igalia.com>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	Christophe Leroy <christophe.leroy@csgroup.eu>,
	Andreas Larsson <andreas@gaisler.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Jacky Huang <ychuang3@nuvoton.com>,
	Shan-Chun Hung <schung@nuvoton.com>,
	Laurentiu Tudor <laurentiu.tudor@nxp.com>
Cc: linux-um@lists.infradead.org, linux-kernel@vger.kernel.org,
	kgdb-bugreport@lists.sourceforge.net,
	linux-serial@vger.kernel.org, netdev@vger.kernel.org,
	linux-m68k@lists.linux-m68k.org, linux-hardening@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-fsdevel@vger.kernel.org,
	Marcos Paulo de Souza <mpdesouza@suse.com>
Subject: Re: [PATCH 02/19] printk: Introduce console_is_nbcon
Date: Fri, 30 Jan 2026 16:56:45 +0106	[thread overview]
Message-ID: <875x8j3xre.fsf@jogness.linutronix.de> (raw)
In-Reply-To: <20251227-printk-cleanup-part3-v1-2-21a291bcf197@suse.com>

On 2025-12-27, Marcos Paulo de Souza <mpdesouza@suse.com> wrote:
> Besides checking if the current console is NBCON or not, console->flags
> is also being read in order to serve as argument of the console_is_usable
> function.
>
> But CON_NBCON flag is unique: it's set just once in the console
> registration and never cleared. In this case it can be possible to read
> the flag when console_srcu_lock is held (which is the case when using
> for_each_console).
>
> This change makes possible to remove the flags argument from
> console_is_usable in the next patches.

Note that console_is_usable() now also checks for the flag
CON_NBCON_ATOMIC_UNSAFE as well.

> diff --git a/include/linux/console.h b/include/linux/console.h
> index 35c03fc4ed51..dd4ec7a5bff9 100644
> --- a/include/linux/console.h
> +++ b/include/linux/console.h
> @@ -561,6 +561,33 @@ static inline void console_srcu_write_flags(struct console *con, short flags)
>  	WRITE_ONCE(con->flags, flags);
>  }
>  
> +/**
> + * console_srcu_is_nbcon - Locklessly check whether the console is nbcon
> + * @con:	struct console pointer of console to check
> + *
> + * Requires console_srcu_read_lock to be held, which implies that @con might
> + * be a registered console. The purpose of holding console_srcu_read_lock is
> + * to guarantee that no exit/cleanup routines will run if the console
> + * is currently undergoing unregistration.
> + *
> + * If the caller is holding the console_list_lock or it is _certain_ that
> + * @con is not and will not become registered, the caller may read
> + * @con->flags directly instead.
> + *
> + * Context: Any context.
> + * Return: True when CON_NBCON flag is set.
> + */
> +static inline bool console_is_nbcon(const struct console *con)
> +{
> +	WARN_ON_ONCE(!console_srcu_read_lock_is_held());
> +
> +	/*
> +	 * The CON_NBCON flag is statically initialized and is never
> +	 * set or cleared at runtime.
> +	 */
> +	return data_race(con->flags & CON_NBCON);

If this flag is statically initialized and is never set or cleared at
runtime, why is the console_srcu_read_lock required? Why not just:

static inline bool console_is_nbcon(const struct console *con)
{
        /*
	 * The CON_NBCON flag is statically initialized and is never
	 * set or cleared at runtime.
	 */
	return data_race(con->flags & CON_NBCON);
}

And even if you do need the console_srcu_read_lock, why copy/paste the
implementation and comments of console_srcu_read_flags()? Just do:

static inline bool console_is_nbcon(const struct console *con)
{
	return console_srcu_read_flags(con) & CON_NBCON;
}

John Ogness

  parent reply	other threads:[~2026-01-30 15:50 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
2025-12-27 12:16 ` [PATCH 01/19] printk/nbcon: Use an enum to specify the required callback in console_is_usable() Marcos Paulo de Souza
2026-01-13 16:25   ` Petr Mladek
2026-01-30 15:31     ` John Ogness
2025-12-27 12:16 ` [PATCH 02/19] printk: Introduce console_is_nbcon Marcos Paulo de Souza
2026-01-13 17:37   ` Petr Mladek
2026-01-30 15:50   ` John Ogness [this message]
2025-12-27 12:16 ` [PATCH 03/19] printk: Drop flags argument from console_is_usable Marcos Paulo de Souza
2026-01-14  8:44   ` Petr Mladek
2025-12-27 12:16 ` [PATCH 04/19] printk: Reintroduce consoles_suspended global state Marcos Paulo de Souza
2026-01-14 13:12   ` Petr Mladek
2025-12-27 12:16 ` [PATCH 05/19] printk: Add more context to suspend/resume functions Marcos Paulo de Souza
2026-01-14 13:20   ` Petr Mladek
2026-01-30 17:27   ` John Ogness
2025-12-27 12:16 ` [PATCH 06/19] printk: Introduce register_console_force Marcos Paulo de Souza
2026-01-14 14:22   ` Petr Mladek
2025-12-27 12:16 ` [PATCH 07/19] drivers: netconsole: Migrate to register_console_force helper Marcos Paulo de Souza
2026-01-15 10:16   ` Petr Mladek
2025-12-27 12:16 ` [PATCH 08/19] debug: debug_core: " Marcos Paulo de Souza
2026-01-15 10:20   ` Petr Mladek
2025-12-27 12:16 ` [PATCH 09/19] m68k: emu: nfcon.c: " Marcos Paulo de Souza
2026-01-15 10:26   ` Petr Mladek
2025-12-27 12:16 ` [PATCH 10/19] fs: pstore: platform: " Marcos Paulo de Souza
2026-01-15 11:05   ` Petr Mladek
2025-12-27 12:16 ` [PATCH 11/19] powerpc: kernel: udbg: " Marcos Paulo de Souza
2026-01-15 12:13   ` Petr Mladek
2025-12-27 12:16 ` [PATCH 12/19] sparc: kernel: btext: " Marcos Paulo de Souza
2026-01-15 12:14   ` Petr Mladek
2025-12-27 12:16 ` [PATCH 13/19] um: drivers: mconsole_kern.c: " Marcos Paulo de Souza
2026-01-15 12:24   ` Petr Mladek
2025-12-27 12:16 ` [PATCH 14/19] drivers: hwtracing: stm: console.c: " Marcos Paulo de Souza
2026-01-15 12:29   ` Petr Mladek
2026-01-16 13:04   ` Alexander Shishkin
2026-01-16 13:54     ` Marcos Paulo de Souza
2025-12-27 12:16 ` [PATCH 15/19] drivers: tty: serial: mux.c: " Marcos Paulo de Souza
2026-01-16  9:59   ` Petr Mladek
2025-12-27 12:16 ` [PATCH 16/19] drivers: tty: serial: ma35d1_serial: " Marcos Paulo de Souza
2026-01-15 16:28   ` Petr Mladek
2025-12-27 12:16 ` [PATCH 17/19] drivers: tty: ehv_bytechan: " Marcos Paulo de Souza
2025-12-27 12:16 ` [PATCH 18/19] drivers: braille: console: Drop CON_ENABLED console flag Marcos Paulo de Souza
2025-12-27 12:16 ` [PATCH 19/19] printk: Remove CON_ENABLED flag Marcos Paulo de Souza
2026-01-05 12:52 ` [PATCH 00/19] printk cleanup - part 3 Daniel Thompson
2026-01-05 14:08   ` Daniel Thompson
2026-01-13 12:41     ` Marcos Paulo de Souza
2026-01-14  0:32       ` Marcos Paulo de Souza
2026-01-14  8:20         ` Petr Mladek
2026-01-14 16:38         ` Daniel Thompson
2026-01-07 10:22 ` Andreas Larsson
2026-01-12 17:53   ` Marcos Paulo de Souza
2026-02-20 11:43 ` Marcos Paulo de Souza

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=875x8j3xre.fsf@jogness.linutronix.de \
    --to=john.ogness@linutronix.de \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andreas@gaisler.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=christophe.leroy@csgroup.eu \
    --cc=danielt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=dianders@chromium.org \
    --cc=edumazet@google.com \
    --cc=geert@linux-m68k.org \
    --cc=gpiccoli@igalia.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jason.wessel@windriver.com \
    --cc=jirislaby@kernel.org \
    --cc=johannes@sipsolutions.net \
    --cc=kees@kernel.org \
    --cc=kgdb-bugreport@lists.sourceforge.net \
    --cc=kuba@kernel.org \
    --cc=laurentiu.tudor@nxp.com \
    --cc=leitao@debian.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-m68k@lists.linux-m68k.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=linux-um@lists.infradead.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=mpdesouza@suse.com \
    --cc=mpe@ellerman.id.au \
    --cc=netdev@vger.kernel.org \
    --cc=npiggin@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=pmladek@suse.com \
    --cc=richard@nod.at \
    --cc=rostedt@goodmis.org \
    --cc=schung@nuvoton.com \
    --cc=senozhatsky@chromium.org \
    --cc=sparclinux@vger.kernel.org \
    --cc=tony.luck@intel.com \
    --cc=ychuang3@nuvoton.com \
    /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