public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Marcos Paulo de Souza <mpdesouza@suse.com>
Cc: 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>,
	Steven Rostedt <rostedt@goodmis.org>,
	John Ogness <john.ogness@linutronix.de>,
	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>,
	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
Subject: Re: [PATCH 06/19] printk: Introduce register_console_force
Date: Wed, 14 Jan 2026 15:22:59 +0100	[thread overview]
Message-ID: <aWemw2ZCwtAd17I1@pathway.suse.cz> (raw)
In-Reply-To: <20251227-printk-cleanup-part3-v1-6-21a291bcf197@suse.com>

On Sat 2025-12-27 09:16:13, Marcos Paulo de Souza wrote:
> The register_console_force function will register a console even if it
> wasn't specified on boot. The new function will act like all consoles
> being registered were using the CON_ENABLED flag.

I am a bit confused by the last sentence. It might be bacause I am not
a native speaker. I wonder if the following is more clear:

<proposal>
The register_console_force() function will register a console even if it
wasn't preferred via the command line, SPCR, or device tree. Currently,
certain drivers pre-set the CON_ENABLE flag to achieve this.
</proposal>

> The CON_ENABLED flag will be removed in the following patches and the
> drivers that use it will migrate to register_console_force instead.
> 
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -3858,7 +3858,7 @@ static int console_call_setup(struct console *newcon, char *options)
>   * enabled such as netconsole
>   */
>  static int try_enable_preferred_console(struct console *newcon,
> -					bool user_specified)
> +					bool user_specified, bool force)
>  {
>  	struct console_cmdline *c;
>  	int i, err;
> @@ -3896,12 +3896,15 @@ static int try_enable_preferred_console(struct console *newcon,
>  		return 0;
>  	}
>  
> +	if (force)
> +		newcon->flags |= CON_ENABLED;
> +

This makes sense because the pre-enabled CON_ENABLED flag is handled
right below.

>  	/*
>  	 * Some consoles, such as pstore and netconsole, can be enabled even
>  	 * without matching. Accept the pre-enabled consoles only when match()
>  	 * and setup() had a chance to be called.
>  	 */
> -	if (newcon->flags & CON_ENABLED && c->user_specified ==	user_specified)
> +	if (newcon->flags & CON_ENABLED && c->user_specified == user_specified)
>  		return 0;

But this location was not a good idea in the first place. It hides an unexpected
side-effect into this function. It is easy to miss. A good example is
the regression caused by the last patch in this patch set, see
https://lore.kernel.org/all/89409a0f48e6998ff6dd2245691b9954f0e1e435.camel@suse.com/

I actually have a patch removing this side-effect:

From d24cd6b812967669900f9866f6202e8b0b65325a Mon Sep 17 00:00:00 2001
From: Petr Mladek <pmladek@suse.com>
Date: Mon, 24 Nov 2025 17:34:25 +0100
Subject: [PATCH] printk/console: Do not rely on
 try_enable_preferred_console() for pre-enabled consoles

try_enable_preferred_console() has non-obvious side effects. It returns
success for pre-enabled consoles.

Move the check for pre-enabled consoles to register_console(). It makes
the handling of pre-enabled consoles more obvious.

Also it will allow call try_enable_preferred_console() only when there
is an entry in preferred_consoles[] array. But it would need some more
changes.

It is part of the code clean up. It should not change the existing
behavior.

Signed-off-by: Petr Mladek <pmladek@suse.com>
---
 kernel/printk/printk.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index abf1b93de056..d6b1d0a26217 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -3826,14 +3826,6 @@ static int try_enable_preferred_console(struct console *newcon,
 		return 0;
 	}
 
-	/*
-	 * Some consoles, such as pstore and netconsole, can be enabled even
-	 * without matching. Accept the pre-enabled consoles only when match()
-	 * and setup() had a chance to be called.
-	 */
-	if (newcon->flags & CON_ENABLED && pc->user_specified == user_specified)
-		return 0;
-
 	return -ENOENT;
 }
 
@@ -4022,6 +4014,14 @@ void register_console(struct console *newcon)
 	if (err == -ENOENT)
 		err = try_enable_preferred_console(newcon, false);
 
+	/*
+	 * Some consoles, such as pstore and netconsole, can be enabled even
+	 * without matching. Accept them at this stage when they had a chance
+	 * to match() and call setup().
+	 */
+	if (err == -ENOENT && (newcon->flags & CON_ENABLED))
+		err = 0;
+
 	/* printk() messages are not printed to the Braille console. */
 	if (err || newcon->flags & CON_BRL) {
 		if (newcon->flags & CON_NBCON)
-- 
2.52.0


It would be better to do the above change 1st. Then the @force
parameter might be checked in __register_console() directly, like:

	/*
	 * Some consoles, such as pstore and netconsole, can be enabled even
	 * without matching. Accept them at this stage when they had a chance
	 * to match() and call setup().
	 */
	if (err == -ENOENT && (force || newcon->flags & CON_ENABLED))
		err = 0;

You might just remove the check of CON_ENABLED in the last patch.
I think that this should actually fix the regression. It will
handle also the case when the console was enabled by
try_enable_default_console() and try_enable_preferred_console()
returned -ENOENT.

Note: I have some more patches which clean up this mess. But they are
      more complicated because of how the Braille console support
      is wired. They still need some love. Anyway, the above patch should
      be good enough for removing CON_ENABLED flag.

Best Regards,
Petr

  reply	other threads:[~2026-01-14 14:23 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
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 [this message]
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=aWemw2ZCwtAd17I1@pathway.suse.cz \
    --to=pmladek@suse.com \
    --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=john.ogness@linutronix.de \
    --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=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