* [PATCH 00/19] printk cleanup - part 3
@ 2025-12-27 12:16 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
` (21 more replies)
0 siblings, 22 replies; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
The parts 1 and 2 can be found here [1] and here[2].
The changes proposed in this part 3 are mostly to clarify the usage of
the interfaces for NBCON, and use the printk helpers more broadly.
Besides it, it also introduces a new way to register consoles
and drop thes the CON_ENABLED flag. It seems too much, but in reality
the changes are not complex, and as the title says, it's basically a
cleanup without changing the functional changes.
This patchset includes a patch from part 2 that needed more work [3], as
suggested by Petr Mladek.
These changes were tested by reverting f79b163c4231
("Revert "serial: 8250: Switch to nbcon console""), and used qemu to test
suspend/resume cycles, and everything worked as expected.
PS: b4 --auto-to-cc added a bunch of people as CC, so I'm not sure if
I should remove some or not, so I'm leaving the list as it is. If the
patchset needs a v2, and you feel that you don't need to copied, just
let me know.
Thanks for checking the patches, and happy holidays!
[1]: https://lore.kernel.org/lkml/20250226-printk-renaming-v1-0-0b878577f2e6@suse.com/#t
[2]: https://lore.kernel.org/linux-serial/20251121-printk-cleanup-part2-v2-0-57b8b78647f4@suse.com/
[3]: https://lore.kernel.org/linux-serial/aSgeqM3DWvR8-cMY@pathway.suse.cz/
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
Marcos Paulo de Souza (19):
printk/nbcon: Use an enum to specify the required callback in console_is_usable()
printk: Introduce console_is_nbcon
printk: Drop flags argument from console_is_usable
printk: Reintroduce consoles_suspended global state
printk: Add more context to suspend/resume functions
printk: Introduce register_console_force
drivers: netconsole: Migrate to register_console_force helper
debug: debug_core: Migrate to register_console_force helper
m68k: emu: nfcon.c: Migrate to register_console_force helper
fs: pstore: platform: Migrate to register_console_force helper
powerpc: kernel: udbg: Migrate to register_console_force helper
sparc: kernel: btext: Migrate to register_console_force helper
um: drivers: mconsole_kern.c: Migrate to register_console_force helper
drivers: hwtracing: stm: console.c: Migrate to register_console_force helper
drivers: tty: serial: mux.c: Migrate to register_console_force helper
drivers: tty: serial: ma35d1_serial: Migrate to register_console_force helper
drivers: tty: ehv_bytechan: Migrate to register_console_force helper
drivers: braille: console: Drop CON_ENABLED console flag
printk: Remove CON_ENABLED flag
arch/m68k/emu/nfcon.c | 5 +-
arch/powerpc/kernel/udbg.c | 4 +-
arch/sparc/kernel/btext.c | 4 +-
arch/um/drivers/mconsole_kern.c | 3 +-
arch/um/kernel/kmsg_dump.c | 2 +-
drivers/accessibility/braille/braille_console.c | 1 -
drivers/hwtracing/stm/console.c | 4 +-
drivers/net/netconsole.c | 13 +--
drivers/tty/ehv_bytechan.c | 4 +-
drivers/tty/serial/ma35d1_serial.c | 4 +-
drivers/tty/serial/mux.c | 4 +-
drivers/tty/tty_io.c | 6 +-
fs/proc/consoles.c | 1 -
fs/pstore/platform.c | 6 +-
include/linux/console.h | 143 +++++++++++++++++++-----
kernel/debug/debug_core.c | 6 +-
kernel/debug/kdb/kdb_io.c | 6 +-
kernel/printk/nbcon.c | 17 +--
kernel/printk/printk.c | 140 ++++++++++++-----------
19 files changed, 230 insertions(+), 143 deletions(-)
---
base-commit: 93d65587479cfc97c0d7e41b5e8c6378ca681632
change-id: 20251202-printk-cleanup-part3-ea116b11b3a6
Best regards,
--
Marcos Paulo de Souza <mpdesouza@suse.com>
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH 01/19] printk/nbcon: Use an enum to specify the required callback in console_is_usable()
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
@ 2025-12-27 12:16 ` Marcos Paulo de Souza
2026-01-13 16:25 ` Petr Mladek
2025-12-27 12:16 ` [PATCH 02/19] printk: Introduce console_is_nbcon Marcos Paulo de Souza
` (20 subsequent siblings)
21 siblings, 1 reply; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
The current usage of console_is_usable() is clumsy. The parameter
@use_atomic is boolean and thus not self-explanatory. The function is
called twice in situations when there are no-strict requirements.
Replace it with enum nbcon_write_cb which provides a more descriptive
values for all 3 situations: atomic, thread or any.
Note that console_is_usable() checks only NBCON_USE_ATOMIC because
.write_thread() callback is mandatory. But the other two values still
make sense because they describe the intention of the caller.
Suggested-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
arch/um/kernel/kmsg_dump.c | 3 ++-
include/linux/console.h | 20 +++++++++++++++++---
kernel/debug/kdb/kdb_io.c | 2 +-
kernel/printk/nbcon.c | 8 ++++----
kernel/printk/printk.c | 16 ++++++++--------
5 files changed, 32 insertions(+), 17 deletions(-)
diff --git a/arch/um/kernel/kmsg_dump.c b/arch/um/kernel/kmsg_dump.c
index fc0f543d1d8e..8ae38308b67c 100644
--- a/arch/um/kernel/kmsg_dump.c
+++ b/arch/um/kernel/kmsg_dump.c
@@ -31,7 +31,8 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper,
* expected to output the crash information.
*/
if (strcmp(con->name, "ttynull") != 0 &&
- console_is_usable(con, console_srcu_read_flags(con), true)) {
+ console_is_usable(con, console_srcu_read_flags(con),
+ NBCON_USE_ATOMIC)) {
break;
}
}
diff --git a/include/linux/console.h b/include/linux/console.h
index fc9f5c5c1b04..35c03fc4ed51 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -202,6 +202,19 @@ enum cons_flags {
CON_NBCON_ATOMIC_UNSAFE = BIT(9),
};
+/**
+ * enum nbcon_write_cb - Defines which nbcon write() callback must be used based
+ * on the caller context.
+ * @NBCON_USE_ATOMIC: Use con->write_atomic().
+ * @NBCON_USE_THREAD: Use con->write_thread().
+ * @NBCON_USE_ANY: The caller does not have any strict requirements.
+ */
+enum nbcon_write_cb {
+ NBCON_USE_ATOMIC,
+ NBCON_USE_THREAD,
+ NBCON_USE_ANY,
+};
+
/**
* struct nbcon_state - console state for nbcon consoles
* @atom: Compound of the state fields for atomic operations
@@ -622,7 +635,8 @@ extern void nbcon_kdb_release(struct nbcon_write_context *wctxt);
* which can also play a role in deciding if @con can be used to print
* records.
*/
-static inline bool console_is_usable(struct console *con, short flags, bool use_atomic)
+static inline bool console_is_usable(struct console *con, short flags,
+ enum nbcon_write_cb nwc)
{
if (!(flags & CON_ENABLED))
return false;
@@ -631,7 +645,7 @@ static inline bool console_is_usable(struct console *con, short flags, bool use_
return false;
if (flags & CON_NBCON) {
- if (use_atomic) {
+ if (nwc & NBCON_USE_ATOMIC) {
/* The write_atomic() callback is optional. */
if (!con->write_atomic)
return false;
@@ -679,7 +693,7 @@ static inline bool nbcon_kdb_try_acquire(struct console *con,
struct nbcon_write_context *wctxt) { return false; }
static inline void nbcon_kdb_release(struct nbcon_write_context *wctxt) { }
static inline bool console_is_usable(struct console *con, short flags,
- bool use_atomic) { return false; }
+ enum nbcon_write_cb nwc) { return false; }
#endif
extern int console_set_on_cmdline;
diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
index 61c1690058ed..6ffb962392a4 100644
--- a/kernel/debug/kdb/kdb_io.c
+++ b/kernel/debug/kdb/kdb_io.c
@@ -591,7 +591,7 @@ static void kdb_msg_write(const char *msg, int msg_len)
for_each_console_srcu(c) {
short flags = console_srcu_read_flags(c);
- if (!console_is_usable(c, flags, true))
+ if (!console_is_usable(c, flags, NBCON_USE_ATOMIC))
continue;
if (c == dbg_io_ops->cons)
continue;
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index be5a04367e60..13865ef85990 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -1184,7 +1184,7 @@ static bool nbcon_kthread_should_wakeup(struct console *con, struct nbcon_contex
cookie = console_srcu_read_lock();
flags = console_srcu_read_flags(con);
- if (console_is_usable(con, flags, false)) {
+ if (console_is_usable(con, flags, NBCON_USE_THREAD)) {
/* Bring the sequence in @ctxt up to date */
ctxt->seq = nbcon_seq_read(con);
@@ -1251,7 +1251,7 @@ static int nbcon_kthread_func(void *__console)
con_flags = console_srcu_read_flags(con);
- if (console_is_usable(con, con_flags, false))
+ if (console_is_usable(con, con_flags, NBCON_USE_THREAD))
backlog = nbcon_emit_one(&wctxt, false);
console_srcu_read_unlock(cookie);
@@ -1650,7 +1650,7 @@ static void __nbcon_atomic_flush_pending(u64 stop_seq)
if (!(flags & CON_NBCON))
continue;
- if (!console_is_usable(con, flags, true))
+ if (!console_is_usable(con, flags, NBCON_USE_ATOMIC))
continue;
if (nbcon_seq_read(con) >= stop_seq)
@@ -1904,7 +1904,7 @@ void nbcon_device_release(struct console *con)
*/
cookie = console_srcu_read_lock();
printk_get_console_flush_type(&ft);
- if (console_is_usable(con, console_srcu_read_flags(con), true) &&
+ if (console_is_usable(con, console_srcu_read_flags(con), NBCON_USE_ATOMIC) &&
!ft.nbcon_offload &&
prb_read_valid(prb, nbcon_seq_read(con), NULL)) {
/*
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 7394f1b6033b..5f4b84f9562e 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -3203,7 +3203,9 @@ static bool console_flush_one_record(bool do_cond_resched, u64 *next_seq, bool *
if ((flags & CON_NBCON) && (ft.nbcon_atomic || ft.nbcon_offload))
continue;
- if (!console_is_usable(con, flags, !do_cond_resched))
+ if (!console_is_usable(con, flags,
+ do_cond_resched ? NBCON_USE_THREAD
+ : NBCON_USE_ATOMIC))
continue;
any_usable = true;
@@ -3392,7 +3394,7 @@ void console_unblank(void)
*/
cookie = console_srcu_read_lock();
for_each_console_srcu(c) {
- if (!console_is_usable(c, console_srcu_read_flags(c), true))
+ if (!console_is_usable(c, console_srcu_read_flags(c), NBCON_USE_ATOMIC))
continue;
if (c->unblank) {
@@ -3432,7 +3434,7 @@ void console_unblank(void)
cookie = console_srcu_read_lock();
for_each_console_srcu(c) {
- if (!console_is_usable(c, console_srcu_read_flags(c), true))
+ if (!console_is_usable(c, console_srcu_read_flags(c), NBCON_USE_ATOMIC))
continue;
if (c->unblank)
@@ -3633,7 +3635,7 @@ static bool legacy_kthread_should_wakeup(void)
if ((flags & CON_NBCON) && (ft.nbcon_atomic || ft.nbcon_offload))
continue;
- if (!console_is_usable(con, flags, false))
+ if (!console_is_usable(con, flags, NBCON_USE_THREAD))
continue;
if (flags & CON_NBCON) {
@@ -4204,7 +4206,7 @@ static int unregister_console_locked(struct console *console)
if (!console_is_registered_locked(console))
res = -ENODEV;
- else if (console_is_usable(console, console->flags, true))
+ else if (console_is_usable(console, console->flags, NBCON_USE_ATOMIC))
__pr_flush(console, 1000, true);
/* Disable it unconditionally */
@@ -4485,10 +4487,8 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
* that they make forward progress, so only increment
* @diff for usable consoles.
*/
- if (!console_is_usable(c, flags, true) &&
- !console_is_usable(c, flags, false)) {
+ if (!console_is_usable(c, flags, NBCON_USE_ANY))
continue;
- }
if (flags & CON_NBCON) {
printk_seq = nbcon_seq_read(c);
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 02/19] printk: Introduce console_is_nbcon
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
@ 2025-12-27 12:16 ` 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
` (19 subsequent siblings)
21 siblings, 2 replies; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
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.
Signed-off-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
include/linux/console.h | 27 +++++++++++++++++++++++++++
kernel/debug/kdb/kdb_io.c | 2 +-
kernel/printk/nbcon.c | 2 +-
kernel/printk/printk.c | 15 ++++++---------
4 files changed, 35 insertions(+), 11 deletions(-)
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);
+}
+
/* Variant of console_is_registered() when the console_list_lock is held. */
static inline bool console_is_registered_locked(const struct console *con)
{
diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
index 6ffb962392a4..d6de512b433a 100644
--- a/kernel/debug/kdb/kdb_io.c
+++ b/kernel/debug/kdb/kdb_io.c
@@ -596,7 +596,7 @@ static void kdb_msg_write(const char *msg, int msg_len)
if (c == dbg_io_ops->cons)
continue;
- if (flags & CON_NBCON) {
+ if (console_is_nbcon(c)) {
struct nbcon_write_context wctxt = { };
/*
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index 13865ef85990..f0f42e212caa 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -1647,7 +1647,7 @@ static void __nbcon_atomic_flush_pending(u64 stop_seq)
for_each_console_srcu(con) {
short flags = console_srcu_read_flags(con);
- if (!(flags & CON_NBCON))
+ if (!console_is_nbcon(con))
continue;
if (!console_is_usable(con, flags, NBCON_USE_ATOMIC))
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 5f4b84f9562e..bd0d574be3cf 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -3200,7 +3200,7 @@ static bool console_flush_one_record(bool do_cond_resched, u64 *next_seq, bool *
* nbcon consoles when the nbcon consoles cannot print via
* their atomic or threaded flushing.
*/
- if ((flags & CON_NBCON) && (ft.nbcon_atomic || ft.nbcon_offload))
+ if (console_is_nbcon(con) && (ft.nbcon_atomic || ft.nbcon_offload))
continue;
if (!console_is_usable(con, flags,
@@ -3209,7 +3209,7 @@ static bool console_flush_one_record(bool do_cond_resched, u64 *next_seq, bool *
continue;
any_usable = true;
- if (flags & CON_NBCON) {
+ if (console_is_nbcon(con)) {
progress = nbcon_legacy_emit_next_record(con, handover, cookie,
!do_cond_resched);
printk_seq = nbcon_seq_read(con);
@@ -3458,7 +3458,6 @@ void console_unblank(void)
static void __console_rewind_all(void)
{
struct console *c;
- short flags;
int cookie;
u64 seq;
@@ -3466,9 +3465,7 @@ static void __console_rewind_all(void)
cookie = console_srcu_read_lock();
for_each_console_srcu(c) {
- flags = console_srcu_read_flags(c);
-
- if (flags & CON_NBCON) {
+ if (console_is_nbcon(c)) {
nbcon_seq_force(c, seq);
} else {
/*
@@ -3632,13 +3629,13 @@ static bool legacy_kthread_should_wakeup(void)
* consoles when the nbcon consoles cannot print via their
* atomic or threaded flushing.
*/
- if ((flags & CON_NBCON) && (ft.nbcon_atomic || ft.nbcon_offload))
+ if (console_is_nbcon(con) && (ft.nbcon_atomic || ft.nbcon_offload))
continue;
if (!console_is_usable(con, flags, NBCON_USE_THREAD))
continue;
- if (flags & CON_NBCON) {
+ if (console_is_nbcon(con)) {
printk_seq = nbcon_seq_read(con);
} else {
/*
@@ -4490,7 +4487,7 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
if (!console_is_usable(c, flags, NBCON_USE_ANY))
continue;
- if (flags & CON_NBCON) {
+ if (console_is_nbcon(c)) {
printk_seq = nbcon_seq_read(c);
} else {
printk_seq = c->seq;
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 03/19] printk: Drop flags argument from console_is_usable
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
2025-12-27 12:16 ` [PATCH 02/19] printk: Introduce console_is_nbcon Marcos Paulo de Souza
@ 2025-12-27 12:16 ` 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
` (18 subsequent siblings)
21 siblings, 1 reply; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
The flags argument was also used to check if CON_NBCON was set, but their
usage was fixed in the last commit. All current users are reading the
variable just to call console_is_usable.
By calling console_srcu_read_flags inside console_is_usable makes the
code cleaner and removes one argument from the function.
Along with it, create a variant called __console_is_usable that can be
used under console_list_lock(), like unregister_console_locked.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
arch/um/kernel/kmsg_dump.c | 3 +--
include/linux/console.h | 25 +++++++++++++++++--------
kernel/debug/kdb/kdb_io.c | 4 +---
kernel/printk/nbcon.c | 15 ++++-----------
kernel/printk/printk.c | 20 +++++++-------------
5 files changed, 30 insertions(+), 37 deletions(-)
diff --git a/arch/um/kernel/kmsg_dump.c b/arch/um/kernel/kmsg_dump.c
index 8ae38308b67c..ca80232cfa2a 100644
--- a/arch/um/kernel/kmsg_dump.c
+++ b/arch/um/kernel/kmsg_dump.c
@@ -31,8 +31,7 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper,
* expected to output the crash information.
*/
if (strcmp(con->name, "ttynull") != 0 &&
- console_is_usable(con, console_srcu_read_flags(con),
- NBCON_USE_ATOMIC)) {
+ console_is_usable(con, NBCON_USE_ATOMIC)) {
break;
}
}
diff --git a/include/linux/console.h b/include/linux/console.h
index dd4ec7a5bff9..648cf10e3f93 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -656,13 +656,8 @@ extern bool nbcon_kdb_try_acquire(struct console *con,
struct nbcon_write_context *wctxt);
extern void nbcon_kdb_release(struct nbcon_write_context *wctxt);
-/*
- * Check if the given console is currently capable and allowed to print
- * records. Note that this function does not consider the current context,
- * which can also play a role in deciding if @con can be used to print
- * records.
- */
-static inline bool console_is_usable(struct console *con, short flags,
+/* Variant of console_is_usable() when the console_list_lock is held. */
+static inline bool __console_is_usable(struct console *con, short flags,
enum nbcon_write_cb nwc)
{
if (!(flags & CON_ENABLED))
@@ -707,6 +702,18 @@ static inline bool console_is_usable(struct console *con, short flags,
return true;
}
+/*
+ * Check if the given console is currently capable and allowed to print
+ * records. Note that this function does not consider the current context,
+ * which can also play a role in deciding if @con can be used to print
+ * records.
+ */
+static inline bool console_is_usable(struct console *con,
+ enum nbcon_write_cb nwc)
+{
+ return __console_is_usable(con, console_srcu_read_flags(con), nwc);
+}
+
#else
static inline void nbcon_cpu_emergency_enter(void) { }
static inline void nbcon_cpu_emergency_exit(void) { }
@@ -719,7 +726,9 @@ static inline void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt) { }
static inline bool nbcon_kdb_try_acquire(struct console *con,
struct nbcon_write_context *wctxt) { return false; }
static inline void nbcon_kdb_release(struct nbcon_write_context *wctxt) { }
-static inline bool console_is_usable(struct console *con, short flags,
+static inline bool __console_is_usable(struct console *con, short flags,
+ enum nbcon_write_cb nwc) { return false; }
+static inline bool console_is_usable(struct console *con,
enum nbcon_write_cb nwc) { return false; }
#endif
diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
index d6de512b433a..642eab746577 100644
--- a/kernel/debug/kdb/kdb_io.c
+++ b/kernel/debug/kdb/kdb_io.c
@@ -589,9 +589,7 @@ static void kdb_msg_write(const char *msg, int msg_len)
*/
cookie = console_srcu_read_lock();
for_each_console_srcu(c) {
- short flags = console_srcu_read_flags(c);
-
- if (!console_is_usable(c, flags, NBCON_USE_ATOMIC))
+ if (!console_is_usable(c, NBCON_USE_ATOMIC))
continue;
if (c == dbg_io_ops->cons)
continue;
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index f0f42e212caa..f0659c1e50ed 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -1164,7 +1164,6 @@ static bool nbcon_emit_one(struct nbcon_write_context *wctxt, bool use_atomic)
static bool nbcon_kthread_should_wakeup(struct console *con, struct nbcon_context *ctxt)
{
bool ret = false;
- short flags;
int cookie;
if (kthread_should_stop())
@@ -1183,8 +1182,7 @@ static bool nbcon_kthread_should_wakeup(struct console *con, struct nbcon_contex
cookie = console_srcu_read_lock();
- flags = console_srcu_read_flags(con);
- if (console_is_usable(con, flags, NBCON_USE_THREAD)) {
+ if (console_is_usable(con, NBCON_USE_THREAD)) {
/* Bring the sequence in @ctxt up to date */
ctxt->seq = nbcon_seq_read(con);
@@ -1209,7 +1207,6 @@ static int nbcon_kthread_func(void *__console)
.ctxt.prio = NBCON_PRIO_NORMAL,
};
struct nbcon_context *ctxt = &ACCESS_PRIVATE(&wctxt, ctxt);
- short con_flags;
bool backlog;
int cookie;
@@ -1249,9 +1246,7 @@ static int nbcon_kthread_func(void *__console)
*/
cookie = console_srcu_read_lock();
- con_flags = console_srcu_read_flags(con);
-
- if (console_is_usable(con, con_flags, NBCON_USE_THREAD))
+ if (console_is_usable(con, NBCON_USE_THREAD))
backlog = nbcon_emit_one(&wctxt, false);
console_srcu_read_unlock(cookie);
@@ -1645,12 +1640,10 @@ static void __nbcon_atomic_flush_pending(u64 stop_seq)
cookie = console_srcu_read_lock();
for_each_console_srcu(con) {
- short flags = console_srcu_read_flags(con);
-
if (!console_is_nbcon(con))
continue;
- if (!console_is_usable(con, flags, NBCON_USE_ATOMIC))
+ if (!console_is_usable(con, NBCON_USE_ATOMIC))
continue;
if (nbcon_seq_read(con) >= stop_seq)
@@ -1904,7 +1897,7 @@ void nbcon_device_release(struct console *con)
*/
cookie = console_srcu_read_lock();
printk_get_console_flush_type(&ft);
- if (console_is_usable(con, console_srcu_read_flags(con), NBCON_USE_ATOMIC) &&
+ if (console_is_usable(con, NBCON_USE_ATOMIC) &&
!ft.nbcon_offload &&
prb_read_valid(prb, nbcon_seq_read(con), NULL)) {
/*
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index bd0d574be3cf..b03ffc23c27c 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -3191,7 +3191,6 @@ static bool console_flush_one_record(bool do_cond_resched, u64 *next_seq, bool *
cookie = console_srcu_read_lock();
for_each_console_srcu(con) {
- short flags = console_srcu_read_flags(con);
u64 printk_seq;
bool progress;
@@ -3203,9 +3202,8 @@ static bool console_flush_one_record(bool do_cond_resched, u64 *next_seq, bool *
if (console_is_nbcon(con) && (ft.nbcon_atomic || ft.nbcon_offload))
continue;
- if (!console_is_usable(con, flags,
- do_cond_resched ? NBCON_USE_THREAD
- : NBCON_USE_ATOMIC))
+ if (!console_is_usable(con, do_cond_resched ? NBCON_USE_THREAD
+ : NBCON_USE_ATOMIC))
continue;
any_usable = true;
@@ -3394,7 +3392,7 @@ void console_unblank(void)
*/
cookie = console_srcu_read_lock();
for_each_console_srcu(c) {
- if (!console_is_usable(c, console_srcu_read_flags(c), NBCON_USE_ATOMIC))
+ if (!console_is_usable(c, NBCON_USE_ATOMIC))
continue;
if (c->unblank) {
@@ -3434,7 +3432,7 @@ void console_unblank(void)
cookie = console_srcu_read_lock();
for_each_console_srcu(c) {
- if (!console_is_usable(c, console_srcu_read_flags(c), NBCON_USE_ATOMIC))
+ if (!console_is_usable(c, NBCON_USE_ATOMIC))
continue;
if (c->unblank)
@@ -3621,7 +3619,6 @@ static bool legacy_kthread_should_wakeup(void)
cookie = console_srcu_read_lock();
for_each_console_srcu(con) {
- short flags = console_srcu_read_flags(con);
u64 printk_seq;
/*
@@ -3632,7 +3629,7 @@ static bool legacy_kthread_should_wakeup(void)
if (console_is_nbcon(con) && (ft.nbcon_atomic || ft.nbcon_offload))
continue;
- if (!console_is_usable(con, flags, NBCON_USE_THREAD))
+ if (!console_is_usable(con, NBCON_USE_THREAD))
continue;
if (console_is_nbcon(con)) {
@@ -4203,7 +4200,7 @@ static int unregister_console_locked(struct console *console)
if (!console_is_registered_locked(console))
res = -ENODEV;
- else if (console_is_usable(console, console->flags, NBCON_USE_ATOMIC))
+ else if (__console_is_usable(console, console->flags, NBCON_USE_ATOMIC))
__pr_flush(console, 1000, true);
/* Disable it unconditionally */
@@ -4430,7 +4427,6 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
struct console *c;
u64 last_diff = 0;
u64 printk_seq;
- short flags;
int cookie;
u64 diff;
u64 seq;
@@ -4477,14 +4473,12 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
if (con && con != c)
continue;
- flags = console_srcu_read_flags(c);
-
/*
* If consoles are not usable, it cannot be expected
* that they make forward progress, so only increment
* @diff for usable consoles.
*/
- if (!console_is_usable(c, flags, NBCON_USE_ANY))
+ if (!console_is_usable(c, NBCON_USE_ANY))
continue;
if (console_is_nbcon(c)) {
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 04/19] printk: Reintroduce consoles_suspended global state
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (2 preceding siblings ...)
2025-12-27 12:16 ` [PATCH 03/19] printk: Drop flags argument from console_is_usable Marcos Paulo de Souza
@ 2025-12-27 12:16 ` 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
` (17 subsequent siblings)
21 siblings, 1 reply; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
This change partially reverts commit 9e70a5e109a4
("printk: Add per-console suspended state"). The intent of the original
commit was to move the management of the console suspended state to the
consoles themselves to be able to use SRCU instead of console lock.
But having a global state is still useful when checking if the global
suspend was triggered by power management. This way, instead of setting
the state of each individual console, the code would only set/read from the
global state.
Along with this change, two more fixes are necessary: change
console_{suspend,resume} to set/clear CON_SUSPEND instead of setting
CON_ENABLED and change show_cons_active to call __console_is_usable to
check console usefulness.
Link: https://lore.kernel.org/lkml/844j4lepak.fsf@jogness.linutronix.de/
Signed-off-by: Petr Mladek <pmladek@suse.com>
[mpdesouza@suse.com: Adapted code related to console_is_usable]
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
drivers/tty/tty_io.c | 6 +++---
include/linux/console.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++--
kernel/printk/printk.c | 23 +++++++++++----------
3 files changed, 67 insertions(+), 15 deletions(-)
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index e2d92cf70eb7..7d2bded75b75 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -3552,9 +3552,9 @@ static ssize_t show_cons_active(struct device *dev,
for_each_console(c) {
if (!c->device)
continue;
- if (!(c->flags & CON_NBCON) && !c->write)
- continue;
- if ((c->flags & CON_ENABLED) == 0)
+ if (!__console_is_usable(c, c->flags,
+ consoles_suspended,
+ NBCON_USE_ANY))
continue;
cs[i++] = c;
if (i >= ARRAY_SIZE(cs))
diff --git a/include/linux/console.h b/include/linux/console.h
index 648cf10e3f93..caf9b0951129 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -509,6 +509,7 @@ extern void console_list_lock(void) __acquires(console_mutex);
extern void console_list_unlock(void) __releases(console_mutex);
extern struct hlist_head console_list;
+extern bool consoles_suspended;
/**
* console_srcu_read_flags - Locklessly read flags of a possibly registered
@@ -561,6 +562,47 @@ static inline void console_srcu_write_flags(struct console *con, short flags)
WRITE_ONCE(con->flags, flags);
}
+/**
+ * consoles_suspended_srcu_read - Locklessly read the global flag for
+ * suspending all consoles.
+ *
+ * The global "consoles_suspended" flag is synchronized using console_list_lock
+ * and console_srcu_read_lock. It is the same approach as CON_SUSPENDED flag.
+ * See console_srcu_read_flags() for more details.
+ *
+ * Context: Any context.
+ * Return: The current value of the global "consoles_suspended" flag.
+ */
+static inline bool consoles_suspended_srcu_read(void)
+{
+ WARN_ON_ONCE(!console_srcu_read_lock_is_held());
+
+ /*
+ * The READ_ONCE() matches the WRITE_ONCE() when "consoles_suspended"
+ * is modified with consoles_suspended_srcu_write().
+ */
+ return data_race(READ_ONCE(consoles_suspended));
+}
+
+/**
+ * consoles_suspended_srcu_write - Write the global flag for suspending
+ * all consoles.
+ * @suspend: new value to write
+ *
+ * The write must be done under the console_list_lock. The caller is responsible
+ * for calling synchronize_srcu() to make sure that all callers checking the
+ * usablility of registered consoles see the new state.
+ *
+ * Context: Any context.
+ */
+static inline void consoles_suspended_srcu_write(bool suspend)
+{
+ lockdep_assert_console_list_lock_held();
+
+ /* This matches the READ_ONCE() in consoles_suspended_srcu_read(). */
+ WRITE_ONCE(consoles_suspended, suspend);
+}
+
/**
* console_srcu_is_nbcon - Locklessly check whether the console is nbcon
* @con: struct console pointer of console to check
@@ -658,8 +700,12 @@ extern void nbcon_kdb_release(struct nbcon_write_context *wctxt);
/* Variant of console_is_usable() when the console_list_lock is held. */
static inline bool __console_is_usable(struct console *con, short flags,
- enum nbcon_write_cb nwc)
+ bool all_suspended,
+ enum nbcon_write_cb nwc)
{
+ if (all_suspended)
+ return false;
+
if (!(flags & CON_ENABLED))
return false;
@@ -711,7 +757,9 @@ static inline bool __console_is_usable(struct console *con, short flags,
static inline bool console_is_usable(struct console *con,
enum nbcon_write_cb nwc)
{
- return __console_is_usable(con, console_srcu_read_flags(con), nwc);
+ return __console_is_usable(con, console_srcu_read_flags(con),
+ consoles_suspended_srcu_read(),
+ nwc);
}
#else
@@ -727,6 +775,7 @@ static inline bool nbcon_kdb_try_acquire(struct console *con,
struct nbcon_write_context *wctxt) { return false; }
static inline void nbcon_kdb_release(struct nbcon_write_context *wctxt) { }
static inline bool __console_is_usable(struct console *con, short flags,
+ bool all_suspended,
enum nbcon_write_cb nwc) { return false; }
static inline bool console_is_usable(struct console *con,
enum nbcon_write_cb nwc) { return false; }
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index b03ffc23c27c..173c14e08afe 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -104,6 +104,13 @@ DEFINE_STATIC_SRCU(console_srcu);
*/
int __read_mostly suppress_printk;
+/*
+ * Global flag for calling down all consoles during suspend.
+ * There is also a per-console flag which is used when the related
+ * device HW gets disabled, see CON_SUSPEND.
+ */
+bool consoles_suspended;
+
#ifdef CONFIG_LOCKDEP
static struct lockdep_map console_lock_dep_map = {
.name = "console_lock"
@@ -2731,8 +2738,6 @@ MODULE_PARM_DESC(console_no_auto_verbose, "Disable console loglevel raise to hig
*/
void console_suspend_all(void)
{
- struct console *con;
-
if (console_suspend_enabled)
pr_info("Suspending console(s) (use no_console_suspend to debug)\n");
@@ -2749,8 +2754,7 @@ void console_suspend_all(void)
return;
console_list_lock();
- for_each_console(con)
- console_srcu_write_flags(con, con->flags | CON_SUSPENDED);
+ consoles_suspended_srcu_write(true);
console_list_unlock();
/*
@@ -2765,7 +2769,6 @@ void console_suspend_all(void)
void console_resume_all(void)
{
struct console_flush_type ft;
- struct console *con;
/*
* Allow queueing irq_work. After restoring console state, deferred
@@ -2776,8 +2779,7 @@ void console_resume_all(void)
if (console_suspend_enabled) {
console_list_lock();
- for_each_console(con)
- console_srcu_write_flags(con, con->flags & ~CON_SUSPENDED);
+ consoles_suspended_srcu_write(false);
console_list_unlock();
/*
@@ -3557,7 +3559,7 @@ void console_suspend(struct console *console)
{
__pr_flush(console, 1000, true);
console_list_lock();
- console_srcu_write_flags(console, console->flags & ~CON_ENABLED);
+ console_srcu_write_flags(console, console->flags | CON_SUSPENDED);
console_list_unlock();
/*
@@ -3576,7 +3578,7 @@ void console_resume(struct console *console)
bool is_nbcon;
console_list_lock();
- console_srcu_write_flags(console, console->flags | CON_ENABLED);
+ console_srcu_write_flags(console, console->flags & ~CON_SUSPENDED);
is_nbcon = console->flags & CON_NBCON;
console_list_unlock();
@@ -4200,7 +4202,8 @@ static int unregister_console_locked(struct console *console)
if (!console_is_registered_locked(console))
res = -ENODEV;
- else if (__console_is_usable(console, console->flags, NBCON_USE_ATOMIC))
+ else if (__console_is_usable(console, console->flags,
+ consoles_suspended, NBCON_USE_ATOMIC))
__pr_flush(console, 1000, true);
/* Disable it unconditionally */
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 05/19] printk: Add more context to suspend/resume functions
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (3 preceding siblings ...)
2025-12-27 12:16 ` [PATCH 04/19] printk: Reintroduce consoles_suspended global state Marcos Paulo de Souza
@ 2025-12-27 12:16 ` 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
` (16 subsequent siblings)
21 siblings, 2 replies; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
The new comments clarifies from where the functions are supposed to be
called.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
kernel/printk/printk.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 173c14e08afe..85a8b6521d9e 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2734,7 +2734,8 @@ MODULE_PARM_DESC(console_no_auto_verbose, "Disable console loglevel raise to hig
/**
* console_suspend_all - suspend the console subsystem
*
- * This disables printk() while we go into suspend states
+ * This disables printk() while we go into suspend states. Called by the power
+ * management subsystem.
*/
void console_suspend_all(void)
{
@@ -2766,6 +2767,12 @@ void console_suspend_all(void)
synchronize_srcu(&console_srcu);
}
+/**
+ * console_resume_all - resume the console subsystem
+ *
+ * This resumes printk() when the system is being restored. Called by the power
+ * management subsystem.
+ */
void console_resume_all(void)
{
struct console_flush_type ft;
@@ -3553,7 +3560,7 @@ struct tty_driver *console_device(int *index)
/*
* Prevent further output on the passed console device so that (for example)
* serial drivers can suspend console output before suspending a port, and can
- * re-enable output afterwards.
+ * re-enable output afterwards. Called by console drivers.
*/
void console_suspend(struct console *console)
{
@@ -3572,6 +3579,7 @@ void console_suspend(struct console *console)
}
EXPORT_SYMBOL(console_suspend);
+/* Resumes printing on the passed console device. Called by console drivers. */
void console_resume(struct console *console)
{
struct console_flush_type ft;
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 06/19] printk: Introduce register_console_force
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (4 preceding siblings ...)
2025-12-27 12:16 ` [PATCH 05/19] printk: Add more context to suspend/resume functions Marcos Paulo de Souza
@ 2025-12-27 12:16 ` 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
` (15 subsequent siblings)
21 siblings, 1 reply; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
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.
The CON_ENABLED flag will be removed in the following patches and the
drivers that use it will migrate to register_console_force instead.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
include/linux/console.h | 1 +
kernel/printk/printk.c | 65 ++++++++++++++++++++++++++++++++-----------------
2 files changed, 43 insertions(+), 23 deletions(-)
diff --git a/include/linux/console.h b/include/linux/console.h
index caf9b0951129..7d374a29a625 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -792,6 +792,7 @@ enum con_flush_mode {
extern int add_preferred_console(const char *name, const short idx, char *options);
extern void console_force_preferred_locked(struct console *con);
extern void register_console(struct console *);
+extern void register_console_force(struct console *c);
extern int unregister_console(struct console *);
extern void console_lock(void);
extern int console_trylock(void);
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 85a8b6521d9e..c5c05e4d0a67 100644
--- 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;
+
/*
* 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;
return -ENOENT;
@@ -4001,26 +4004,11 @@ static u64 get_init_console_seq(struct console *newcon, bool bootcon_registered)
static int unregister_console_locked(struct console *console);
-/*
- * The console driver calls this routine during kernel initialization
- * to register the console printing procedure with printk() and to
- * print any messages that were printed by the kernel before the
- * console driver was initialized.
- *
- * This can happen pretty early during the boot process (because of
- * early_printk) - sometimes before setup_arch() completes - be careful
- * of what kernel features are used - they may not be initialised yet.
- *
- * There are two types of consoles - bootconsoles (early_printk) and
- * "real" consoles (everything which is not a bootconsole) which are
- * handled differently.
- * - Any number of bootconsoles can be registered at any time.
- * - As soon as a "real" console is registered, all bootconsoles
- * will be unregistered automatically.
- * - Once a "real" console is registered, any attempt to register a
- * bootconsoles will be rejected
+/**
+ * __register_console: Register a new console
+ * @force: Register the console even if not specified on boot
*/
-void register_console(struct console *newcon)
+static void __register_console(struct console *newcon, bool force)
{
bool use_device_lock = (newcon->flags & CON_NBCON) && newcon->write_atomic;
bool bootcon_registered = false;
@@ -4080,11 +4068,11 @@ void register_console(struct console *newcon)
}
/* See if this console matches one we selected on the command line */
- err = try_enable_preferred_console(newcon, true);
+ err = try_enable_preferred_console(newcon, true, force);
/* If not, try to match against the platform default(s) */
if (err == -ENOENT)
- err = try_enable_preferred_console(newcon, false);
+ err = try_enable_preferred_console(newcon, false, force);
/* printk() messages are not printed to the Braille console. */
if (err || newcon->flags & CON_BRL) {
@@ -4185,8 +4173,39 @@ void register_console(struct console *newcon)
unlock:
console_list_unlock();
}
+
+/*
+ * The console driver calls this routine during kernel initialization
+ * to register the console printing procedure with printk() and to
+ * print any messages that were printed by the kernel before the
+ * console driver was initialized.
+ *
+ * This can happen pretty early during the boot process (because of
+ * early_printk) - sometimes before setup_arch() completes - be careful
+ * of what kernel features are used - they may not be initialised yet.
+ *
+ * There are two types of consoles - bootconsoles (early_printk) and
+ * "real" consoles (everything which is not a bootconsole) which are
+ * handled differently.
+ * - Any number of bootconsoles can be registered at any time.
+ * - As soon as a "real" console is registered, all bootconsoles
+ * will be unregistered automatically.
+ * - Once a "real" console is registered, any attempt to register a
+ * bootconsoles will be rejected
+ */
+void register_console(struct console *newcon)
+{
+ __register_console(newcon, false);
+}
EXPORT_SYMBOL(register_console);
+
+void register_console_force(struct console *newcon)
+{
+ __register_console(newcon, true);
+}
+EXPORT_SYMBOL(register_console_force);
+
/* Must be called under console_list_lock(). */
static int unregister_console_locked(struct console *console)
{
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 07/19] drivers: netconsole: Migrate to register_console_force helper
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (5 preceding siblings ...)
2025-12-27 12:16 ` [PATCH 06/19] printk: Introduce register_console_force Marcos Paulo de Souza
@ 2025-12-27 12:16 ` 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
` (14 subsequent siblings)
21 siblings, 1 reply; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
The register_console_force function was introduced to register consoles
even on the presence of default consoles, replacing the CON_ENABLE flag
that was forcing the same behavior.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
drivers/net/netconsole.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index bb6e03a92956..509ab629d95f 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -583,16 +583,14 @@ static ssize_t enabled_store(struct config_item *item,
}
if (nt->extended && !console_is_registered(&netconsole_ext)) {
- netconsole_ext.flags |= CON_ENABLED;
- register_console(&netconsole_ext);
+ register_console_force(&netconsole_ext);
}
/* User might be enabling the basic format target for the very
* first time, make sure the console is registered.
*/
if (!nt->extended && !console_is_registered(&netconsole)) {
- netconsole.flags |= CON_ENABLED;
- register_console(&netconsole);
+ register_console_force(&netconsole);
}
/*
@@ -1917,13 +1915,12 @@ static void free_param_target(struct netconsole_target *nt)
static struct console netconsole_ext = {
.name = "netcon_ext",
- .flags = CON_ENABLED | CON_EXTENDED,
+ .flags = CON_EXTENDED,
.write = write_ext_msg,
};
static struct console netconsole = {
.name = "netcon",
- .flags = CON_ENABLED,
.write = write_msg,
};
@@ -1971,9 +1968,9 @@ static int __init init_netconsole(void)
goto undonotifier;
if (console_type_needed & CONS_EXTENDED)
- register_console(&netconsole_ext);
+ register_console_force(&netconsole_ext);
if (console_type_needed & CONS_BASIC)
- register_console(&netconsole);
+ register_console_force(&netconsole);
pr_info("network logging started\n");
return err;
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 08/19] debug: debug_core: Migrate to register_console_force helper
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (6 preceding siblings ...)
2025-12-27 12:16 ` [PATCH 07/19] drivers: netconsole: Migrate to register_console_force helper Marcos Paulo de Souza
@ 2025-12-27 12:16 ` 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
` (13 subsequent siblings)
21 siblings, 1 reply; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
The register_console_force function was introduced to register consoles
even on the presence of default consoles, replacing the CON_ENABLE flag
that was forcing the same behavior.
No functional changes.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
kernel/debug/debug_core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
index 0b9495187fba..4bf736e5a059 100644
--- a/kernel/debug/debug_core.c
+++ b/kernel/debug/debug_core.c
@@ -941,7 +941,7 @@ static void kgdb_console_write(struct console *co, const char *s,
static struct console kgdbcons = {
.name = "kgdb",
.write = kgdb_console_write,
- .flags = CON_PRINTBUFFER | CON_ENABLED,
+ .flags = CON_PRINTBUFFER,
.index = -1,
};
@@ -950,7 +950,7 @@ static int __init opt_kgdb_con(char *str)
kgdb_use_con = 1;
if (kgdb_io_module_registered && !kgdb_con_registered) {
- register_console(&kgdbcons);
+ register_console_force(&kgdbcons);
kgdb_con_registered = 1;
}
@@ -1071,7 +1071,7 @@ static void kgdb_register_callbacks(void)
register_sysrq_key('g', &sysrq_dbg_op);
#endif
if (kgdb_use_con && !kgdb_con_registered) {
- register_console(&kgdbcons);
+ register_console_force(&kgdbcons);
kgdb_con_registered = 1;
}
}
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 09/19] m68k: emu: nfcon.c: Migrate to register_console_force helper
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (7 preceding siblings ...)
2025-12-27 12:16 ` [PATCH 08/19] debug: debug_core: " Marcos Paulo de Souza
@ 2025-12-27 12:16 ` 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
` (12 subsequent siblings)
21 siblings, 1 reply; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
The register_console_force function was introduced to register consoles
even on the presence of default consoles, replacing the CON_ENABLE flag
that was forcing the same behavior.
No functional changes.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
arch/m68k/emu/nfcon.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/arch/m68k/emu/nfcon.c b/arch/m68k/emu/nfcon.c
index d41260672e24..3504bbb4aedc 100644
--- a/arch/m68k/emu/nfcon.c
+++ b/arch/m68k/emu/nfcon.c
@@ -110,10 +110,9 @@ static int __init nf_debug_setup(char *arg)
/*
* The console will be enabled when debug=nfcon is specified
* as a kernel parameter. Since this is a non-standard way
- * of enabling consoles, it must be explicitly enabled.
+ * of enabling consoles, it must be explicitly forced.
*/
- nf_console.flags |= CON_ENABLED;
- register_console(&nf_console);
+ register_console_force(&nf_console);
}
return 0;
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 10/19] fs: pstore: platform: Migrate to register_console_force helper
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (8 preceding siblings ...)
2025-12-27 12:16 ` [PATCH 09/19] m68k: emu: nfcon.c: " Marcos Paulo de Souza
@ 2025-12-27 12:16 ` 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
` (11 subsequent siblings)
21 siblings, 1 reply; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
The register_console_force function was introduced to register consoles
even on the presence of default consoles, replacing the CON_ENABLE flag
that was forcing the same behavior.
No functional changes.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
fs/pstore/platform.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index f8b9c9c73997..9d42c0f2de9e 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -418,10 +418,10 @@ static void pstore_register_console(void)
sizeof(pstore_console.name));
/*
* Always initialize flags here since prior unregister_console()
- * calls may have changed settings (specifically CON_ENABLED).
+ * calls may have changed settings.
*/
- pstore_console.flags = CON_PRINTBUFFER | CON_ENABLED | CON_ANYTIME;
- register_console(&pstore_console);
+ pstore_console.flags = CON_PRINTBUFFER | CON_ANYTIME;
+ register_console_force(&pstore_console);
}
static void pstore_unregister_console(void)
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 11/19] powerpc: kernel: udbg: Migrate to register_console_force helper
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (9 preceding siblings ...)
2025-12-27 12:16 ` [PATCH 10/19] fs: pstore: platform: " Marcos Paulo de Souza
@ 2025-12-27 12:16 ` 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
` (10 subsequent siblings)
21 siblings, 1 reply; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
The register_console_force function was introduced to register consoles
even on the presence of default consoles, replacing the CON_ENABLE flag
that was forcing the same behavior.
No functional changes.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
arch/powerpc/kernel/udbg.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/kernel/udbg.c b/arch/powerpc/kernel/udbg.c
index 862b22b2b616..0f88b7697755 100644
--- a/arch/powerpc/kernel/udbg.c
+++ b/arch/powerpc/kernel/udbg.c
@@ -142,7 +142,7 @@ static void udbg_console_write(struct console *con, const char *s,
static struct console udbg_console = {
.name = "udbg",
.write = udbg_console_write,
- .flags = CON_PRINTBUFFER | CON_ENABLED | CON_BOOT | CON_ANYTIME,
+ .flags = CON_PRINTBUFFER | CON_BOOT | CON_ANYTIME,
.index = 0,
};
@@ -163,7 +163,7 @@ void __init register_early_udbg_console(void)
udbg_console.flags &= ~CON_BOOT;
}
early_console = &udbg_console;
- register_console(&udbg_console);
+ register_console_force(&udbg_console);
}
#if 0 /* if you want to use this as a regular output console */
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 12/19] sparc: kernel: btext: Migrate to register_console_force helper
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (10 preceding siblings ...)
2025-12-27 12:16 ` [PATCH 11/19] powerpc: kernel: udbg: " Marcos Paulo de Souza
@ 2025-12-27 12:16 ` 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
` (9 subsequent siblings)
21 siblings, 1 reply; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
The register_console_force function was introduced to register consoles
even on the presence of default consoles, replacing the CON_ENABLE flag
that was forcing the same behavior.
No functional changes.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
arch/sparc/kernel/btext.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/sparc/kernel/btext.c b/arch/sparc/kernel/btext.c
index 2bf558a0c568..951de7733632 100644
--- a/arch/sparc/kernel/btext.c
+++ b/arch/sparc/kernel/btext.c
@@ -301,7 +301,7 @@ static void btext_console_write(struct console *con, const char *s,
static struct console btext_console = {
.name = "btext",
.write = btext_console_write,
- .flags = CON_PRINTBUFFER | CON_ENABLED | CON_BOOT | CON_ANYTIME,
+ .flags = CON_PRINTBUFFER | CON_BOOT | CON_ANYTIME,
.index = 0,
};
@@ -320,7 +320,7 @@ int __init btext_find_display(void)
ret = btext_initialize(node);
if (!ret) {
btext_clearscreen();
- register_console(&btext_console);
+ register_console_force(&btext_console);
}
return ret;
}
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 13/19] um: drivers: mconsole_kern.c: Migrate to register_console_force helper
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (11 preceding siblings ...)
2025-12-27 12:16 ` [PATCH 12/19] sparc: kernel: btext: " Marcos Paulo de Souza
@ 2025-12-27 12:16 ` 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
` (8 subsequent siblings)
21 siblings, 1 reply; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
The register_console_force function was introduced to register consoles
even on the presence of default consoles, replacing the CON_ENABLE flag
that was forcing the same behavior.
No functional changes.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
arch/um/drivers/mconsole_kern.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/um/drivers/mconsole_kern.c b/arch/um/drivers/mconsole_kern.c
index ff4bda95b9c7..ce4f4ceb7f27 100644
--- a/arch/um/drivers/mconsole_kern.c
+++ b/arch/um/drivers/mconsole_kern.c
@@ -582,12 +582,11 @@ static void console_write(struct console *console, const char *string,
static struct console mc_console = { .name = "mc",
.write = console_write,
- .flags = CON_ENABLED,
.index = -1 };
static int mc_add_console(void)
{
- register_console(&mc_console);
+ register_console_force(&mc_console);
return 0;
}
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 14/19] drivers: hwtracing: stm: console.c: Migrate to register_console_force helper
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (12 preceding siblings ...)
2025-12-27 12:16 ` [PATCH 13/19] um: drivers: mconsole_kern.c: " Marcos Paulo de Souza
@ 2025-12-27 12:16 ` Marcos Paulo de Souza
2026-01-15 12:29 ` Petr Mladek
2026-01-16 13:04 ` Alexander Shishkin
2025-12-27 12:16 ` [PATCH 15/19] drivers: tty: serial: mux.c: " Marcos Paulo de Souza
` (7 subsequent siblings)
21 siblings, 2 replies; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
The register_console_force function was introduced to register consoles
even on the presence of default consoles, replacing the CON_ENABLE flag
that was forcing the same behavior.
No functional changes.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
drivers/hwtracing/stm/console.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/hwtracing/stm/console.c b/drivers/hwtracing/stm/console.c
index 097a00ac43a7..d3ae633e3bf1 100644
--- a/drivers/hwtracing/stm/console.c
+++ b/drivers/hwtracing/stm/console.c
@@ -42,8 +42,8 @@ static int stm_console_link(struct stm_source_data *data)
strcpy(sc->console.name, "stm_console");
sc->console.write = stm_console_write;
- sc->console.flags = CON_ENABLED | CON_PRINTBUFFER;
- register_console(&sc->console);
+ sc->console.flags = CON_PRINTBUFFER;
+ register_console_force(&sc->console);
return 0;
}
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 15/19] drivers: tty: serial: mux.c: Migrate to register_console_force helper
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (13 preceding siblings ...)
2025-12-27 12:16 ` [PATCH 14/19] drivers: hwtracing: stm: console.c: " Marcos Paulo de Souza
@ 2025-12-27 12:16 ` 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
` (6 subsequent siblings)
21 siblings, 1 reply; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
The register_console_force function was introduced to register consoles
even on the presence of default consoles, replacing the CON_ENABLE flag
that was forcing the same behavior.
No functional changes.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
drivers/tty/serial/mux.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/serial/mux.c b/drivers/tty/serial/mux.c
index b417faead20f..5a2d706b9cbc 100644
--- a/drivers/tty/serial/mux.c
+++ b/drivers/tty/serial/mux.c
@@ -390,7 +390,7 @@ static struct console mux_console = {
.write = mux_console_write,
.device = uart_console_device,
.setup = mux_console_setup,
- .flags = CON_ENABLED | CON_PRINTBUFFER,
+ .flags = CON_PRINTBUFFER,
.index = 0,
.data = &mux_driver,
};
@@ -547,7 +547,7 @@ static int __init mux_init(void)
mod_timer(&mux_timer, jiffies + MUX_POLL_DELAY);
#ifdef CONFIG_SERIAL_MUX_CONSOLE
- register_console(&mux_console);
+ register_console_force(&mux_console);
#endif
}
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 16/19] drivers: tty: serial: ma35d1_serial: Migrate to register_console_force helper
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (14 preceding siblings ...)
2025-12-27 12:16 ` [PATCH 15/19] drivers: tty: serial: mux.c: " Marcos Paulo de Souza
@ 2025-12-27 12:16 ` 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
` (5 subsequent siblings)
21 siblings, 1 reply; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
The register_console_force function was introduced to register consoles
even on the presence of default consoles, replacing the CON_ENABLE flag
that was forcing the same behavior.
No functional changes.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
drivers/tty/serial/ma35d1_serial.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/serial/ma35d1_serial.c b/drivers/tty/serial/ma35d1_serial.c
index 285b0fe41a86..d1e03dee5579 100644
--- a/drivers/tty/serial/ma35d1_serial.c
+++ b/drivers/tty/serial/ma35d1_serial.c
@@ -633,7 +633,7 @@ static struct console ma35d1serial_console = {
.write = ma35d1serial_console_write,
.device = uart_console_device,
.setup = ma35d1serial_console_setup,
- .flags = CON_PRINTBUFFER | CON_ENABLED,
+ .flags = CON_PRINTBUFFER,
.index = -1,
.data = &ma35d1serial_reg,
};
@@ -657,7 +657,7 @@ static void ma35d1serial_console_init_port(void)
static int __init ma35d1serial_console_init(void)
{
ma35d1serial_console_init_port();
- register_console(&ma35d1serial_console);
+ register_console_force(&ma35d1serial_console);
return 0;
}
console_initcall(ma35d1serial_console_init);
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 17/19] drivers: tty: ehv_bytechan: Migrate to register_console_force helper
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (15 preceding siblings ...)
2025-12-27 12:16 ` [PATCH 16/19] drivers: tty: serial: ma35d1_serial: " Marcos Paulo de Souza
@ 2025-12-27 12:16 ` Marcos Paulo de Souza
2025-12-27 12:16 ` [PATCH 18/19] drivers: braille: console: Drop CON_ENABLED console flag Marcos Paulo de Souza
` (4 subsequent siblings)
21 siblings, 0 replies; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
The register_console_force function was introduced to register consoles
even on the presence of default consoles, replacing the CON_ENABLE flag
that was forcing the same behavior.
No functional changes.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
drivers/tty/ehv_bytechan.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/ehv_bytechan.c b/drivers/tty/ehv_bytechan.c
index 69508d7a4135..a2aab48d11ae 100644
--- a/drivers/tty/ehv_bytechan.c
+++ b/drivers/tty/ehv_bytechan.c
@@ -299,7 +299,7 @@ static struct console ehv_bc_console = {
.name = "ttyEHV",
.write = ehv_bc_console_write,
.device = ehv_bc_console_device,
- .flags = CON_PRINTBUFFER | CON_ENABLED,
+ .flags = CON_PRINTBUFFER,
};
/*
@@ -331,7 +331,7 @@ static int __init ehv_bc_console_init(void)
byte channels here, either, since we only care about one. */
add_preferred_console(ehv_bc_console.name, ehv_bc_console.index, NULL);
- register_console(&ehv_bc_console);
+ register_console_force(&ehv_bc_console);
pr_info("ehv-bc: registered console driver for byte channel %u\n",
stdout_bc);
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 18/19] drivers: braille: console: Drop CON_ENABLED console flag
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (16 preceding siblings ...)
2025-12-27 12:16 ` [PATCH 17/19] drivers: tty: ehv_bytechan: " Marcos Paulo de Souza
@ 2025-12-27 12:16 ` Marcos Paulo de Souza
2025-12-27 12:16 ` [PATCH 19/19] printk: Remove CON_ENABLED flag Marcos Paulo de Souza
` (3 subsequent siblings)
21 siblings, 0 replies; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
The braille console doesn't take the same path on register_console
that other console drivers. At this point, it only registers the console
and do not receive any printk message, so we can drop the CON_ENABLED.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
drivers/accessibility/braille/braille_console.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/accessibility/braille/braille_console.c b/drivers/accessibility/braille/braille_console.c
index 06b43b678d6e..0b7ec68b305c 100644
--- a/drivers/accessibility/braille/braille_console.c
+++ b/drivers/accessibility/braille/braille_console.c
@@ -360,7 +360,6 @@ int braille_register_console(struct console *console, int index,
if (ret != 0)
return ret;
}
- console->flags |= CON_ENABLED;
console->index = index;
braille_co = console;
register_keyboard_notifier(&keyboard_notifier_block);
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH 19/19] printk: Remove CON_ENABLED flag
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (17 preceding siblings ...)
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 ` Marcos Paulo de Souza
2026-01-05 12:52 ` [PATCH 00/19] printk cleanup - part 3 Daniel Thompson
` (2 subsequent siblings)
21 siblings, 0 replies; 50+ messages in thread
From: Marcos Paulo de Souza @ 2025-12-27 12:16 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
All remaining usages of CON_ENABLED were removed from console drivers
that were being registered without being specified on boot using console=
argument.
The usefulness of the flag was questionable since at first it meant that
the console was ready to print records. Later on, console drivers started
to set the flag when registering the console to make sure that the
console would be registered even without being specified by a kernel
argument.
With the inclusion a global state for system wide suspend/resume
in place, with console_{suspend,resume} handling CON_SUSPEND, and with
console_is_usable helper being more used, the CON_ENABLED flag can be
safely removed.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
fs/proc/consoles.c | 1 -
include/linux/console.h | 27 ++++++++++-----------------
kernel/printk/printk.c | 15 ++-------------
3 files changed, 12 insertions(+), 31 deletions(-)
diff --git a/fs/proc/consoles.c b/fs/proc/consoles.c
index b7cab1ad990d..b6916ed7957b 100644
--- a/fs/proc/consoles.c
+++ b/fs/proc/consoles.c
@@ -18,7 +18,6 @@ static int show_console_dev(struct seq_file *m, void *v)
short flag;
char name;
} con_flags[] = {
- { CON_ENABLED, 'E' },
{ CON_CONSDEV, 'C' },
{ CON_BOOT, 'B' },
{ CON_NBCON, 'N' },
diff --git a/include/linux/console.h b/include/linux/console.h
index 7d374a29a625..0ab02f7ba307 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -164,9 +164,6 @@ static inline void con_debug_leave(void) { }
* consoles or read by userspace via syslog() syscall.
* @CON_CONSDEV: Indicates that the console driver is backing
* /dev/console.
- * @CON_ENABLED: Indicates if a console is allowed to print records. If
- * false, the console also will not advance to later
- * records.
* @CON_BOOT: Marks the console driver as early console driver which
* is used during boot before the real driver becomes
* available. It will be automatically unregistered
@@ -192,14 +189,13 @@ static inline void con_debug_leave(void) { }
enum cons_flags {
CON_PRINTBUFFER = BIT(0),
CON_CONSDEV = BIT(1),
- CON_ENABLED = BIT(2),
- CON_BOOT = BIT(3),
- CON_ANYTIME = BIT(4),
- CON_BRL = BIT(5),
- CON_EXTENDED = BIT(6),
- CON_SUSPENDED = BIT(7),
- CON_NBCON = BIT(8),
- CON_NBCON_ATOMIC_UNSAFE = BIT(9),
+ CON_BOOT = BIT(2),
+ CON_ANYTIME = BIT(3),
+ CON_BRL = BIT(4),
+ CON_EXTENDED = BIT(5),
+ CON_SUSPENDED = BIT(6),
+ CON_NBCON = BIT(7),
+ CON_NBCON_ATOMIC_UNSAFE = BIT(8),
};
/**
@@ -522,9 +518,9 @@ extern bool consoles_suspended;
*
* 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 the console state is valid (CON_SUSPENDED/CON_ENABLED)
- * and that no exit/cleanup routines will run if the console is currently
- * undergoing unregistration.
+ * to guarantee that the console state is valid (CON_SUSPENDED) and 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
@@ -706,9 +702,6 @@ static inline bool __console_is_usable(struct console *con, short flags,
if (all_suspended)
return false;
- if (!(flags & CON_ENABLED))
- return false;
-
if ((flags & CON_SUSPENDED))
return false;
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index c5c05e4d0a67..9cb0911997e5 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -3890,21 +3890,17 @@ static int try_enable_preferred_console(struct console *newcon,
if (err)
return err;
}
- newcon->flags |= CON_ENABLED;
if (i == preferred_console)
newcon->flags |= CON_CONSDEV;
return 0;
}
- if (force)
- newcon->flags |= CON_ENABLED;
-
/*
* 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 (force && c->user_specified == user_specified)
return 0;
return -ENOENT;
@@ -3919,8 +3915,6 @@ static void try_enable_default_console(struct console *newcon)
if (console_call_setup(newcon, NULL) != 0)
return;
- newcon->flags |= CON_ENABLED;
-
if (newcon->device)
newcon->flags |= CON_CONSDEV;
}
@@ -3977,10 +3971,8 @@ static u64 get_init_console_seq(struct console *newcon, bool bootcon_registered)
for_each_console(con) {
u64 seq;
- if (!(con->flags & CON_BOOT) ||
- !(con->flags & CON_ENABLED)) {
+ if (!(con->flags & CON_BOOT))
continue;
- }
if (con->flags & CON_NBCON)
seq = nbcon_seq_read(con);
@@ -4233,9 +4225,6 @@ static int unregister_console_locked(struct console *console)
consoles_suspended, NBCON_USE_ATOMIC))
__pr_flush(console, 1000, true);
- /* Disable it unconditionally */
- console_srcu_write_flags(console, console->flags & ~CON_ENABLED);
-
if (res < 0)
return res;
--
2.52.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* Re: [PATCH 00/19] printk cleanup - part 3
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (18 preceding siblings ...)
2025-12-27 12:16 ` [PATCH 19/19] printk: Remove CON_ENABLED flag Marcos Paulo de Souza
@ 2026-01-05 12:52 ` Daniel Thompson
2026-01-05 14:08 ` Daniel Thompson
2026-01-07 10:22 ` Andreas Larsson
2026-02-20 11:43 ` Marcos Paulo de Souza
21 siblings, 1 reply; 50+ messages in thread
From: Daniel Thompson @ 2026-01-05 12:52 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor, linux-um, linux-kernel, kgdb-bugreport,
linux-serial, netdev, linux-m68k, linux-hardening, linuxppc-dev,
sparclinux, linux-stm32, linux-arm-kernel, linux-fsdevel
Hi Marcos
On Sat, Dec 27, 2025 at 09:16:07AM -0300, Marcos Paulo de Souza wrote:
> The parts 1 and 2 can be found here [1] and here[2].
>
> The changes proposed in this part 3 are mostly to clarify the usage of
> the interfaces for NBCON, and use the printk helpers more broadly.
> Besides it, it also introduces a new way to register consoles
> and drop thes the CON_ENABLED flag. It seems too much, but in reality
> the changes are not complex, and as the title says, it's basically a
> cleanup without changing the functional changes.
I ran this patchset through the kgdb test suite and I'm afraid it is
reporting functional changes.
Specifically the earlycon support for kdb has regressed (FWIW the
problem bisects down to the final patch in the series where CON_ENABLED
is removed).
Reproduction on x86-64 KVM outside of the test suite should be easy:
make defconfig
scripts/config \
--enable DEBUG_INFO \
--enable DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT \
--enable DEBUG_FS \
--enable KALLSYMS_ALL \
--enable MAGIC_SYSRQ \
--enable KGDB \
--enable KGDB_TESTS \
--enable KGDB_KDB \
--enable KDB_KEYBOARD \
--enable LKDTM \
--enable SECURITY_LOCKDOWN_LSM
make olddefconfig
make -j$(nproc)
qemu-system-x86_64 \
-m 1G -smp 2 -nographic \
-kernel arch/x86/boot/bzImage \
-append "console=ttyS0,115200 kgdboc=ttyS0 earlycon=uart8250,io,0x3f8 kgdboc_earlycon kgdbwait"
In a successful test the kdb prompt will appear after only a few lines
of output:
~~~
[ 0.000000] Linux version 6.19.0-rc4-00020-g4b7f3b144021 (drt@wychelm) (gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44) #2 SMP PREEMPT_DYNAMIC Mon Jan 6
[ 0.000000] Command line: console=ttyS0,115200 kgdboc=ttyS0 earlycon=uart8250,io,0x3f8 kgdboc_earlycon kgdbwait
[ 0.000000] BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
[ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000003ffdffff] usable
[ 0.000000] BIOS-e820: [mem 0x000000003ffe0000-0x000000003fffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x000000fd00000000-0x000000ffffffffff] reserved
[ 0.000000] earlycon: uart8250 at I/O port 0x3f8 (options '')
[ 0.000000] printk: legacy bootconsole [uart8250] enabled
[ 0.000000] kgdboc: Going to register kgdb with earlycon 'uart'
[ 0.000000] KGDB: Registered I/O driver kgdboc_earlycon
[ 0.000000] KGDB: Waiting for connection from remote gdb...
Entering kdb (current=0x0000000000000000, pid 0) on processor 0 due to NonMaskable Interrupt @ 0xffffffff9101491f
[0]kdb>
~~~
After this patchset is applied the earlycon triggers do not work
correctly and we get:
~~~
[ 0.000000] Linux version 6.19.0-rc4-00019-g882df99205ba (drt@wychelm) (gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44) #3 SMP PREEMPT_DYNAMIC Mon Jan 6
[ 0.000000] Command line: console=ttyS0,115200 kgdboc=ttyS0 earlycon=uart8250,io,0x3f8 kgdboc_earlycon kgdbwait
[ 0.000000] BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
[ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000003ffdffff] usable
[ 0.000000] BIOS-e820: [mem 0x000000003ffe0000-0x000000003fffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x000000fd00000000-0x000000ffffffffff] reserved
[ 0.000000] earlycon: uart8250 at I/O port 0x3f8 (options '')
[ 0.000000] kgdboc: No suitable earlycon yet, will try later
...
~~~
Daniel.
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 00/19] printk cleanup - part 3
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
0 siblings, 1 reply; 50+ messages in thread
From: Daniel Thompson @ 2026-01-05 14:08 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor, linux-um, linux-kernel, kgdb-bugreport,
linux-serial, netdev, linux-m68k, linux-hardening, linuxppc-dev,
sparclinux, linux-stm32, linux-arm-kernel, linux-fsdevel
On Mon, Jan 05, 2026 at 12:52:14PM +0000, Daniel Thompson wrote:
> Hi Marcos
>
> On Sat, Dec 27, 2025 at 09:16:07AM -0300, Marcos Paulo de Souza wrote:
> > The parts 1 and 2 can be found here [1] and here[2].
> >
> > The changes proposed in this part 3 are mostly to clarify the usage of
> > the interfaces for NBCON, and use the printk helpers more broadly.
> > Besides it, it also introduces a new way to register consoles
> > and drop thes the CON_ENABLED flag. It seems too much, but in reality
> > the changes are not complex, and as the title says, it's basically a
> > cleanup without changing the functional changes.
>
> I ran this patchset through the kgdb test suite and I'm afraid it is
> reporting functional changes.
>
> Specifically the earlycon support for kdb has regressed (FWIW the
> problem bisects down to the final patch in the series where CON_ENABLED
> is removed).
>
> Reproduction on x86-64 KVM outside of the test suite should be easy:
>
> make defconfig
> scripts/config \
> --enable DEBUG_INFO \
> --enable DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT \
> --enable DEBUG_FS \
> --enable KALLSYMS_ALL \
> --enable MAGIC_SYSRQ \
> --enable KGDB \
> --enable KGDB_TESTS \
> --enable KGDB_KDB \
> --enable KDB_KEYBOARD \
> --enable LKDTM \
> --enable SECURITY_LOCKDOWN_LSM
> make olddefconfig
> make -j$(nproc)
> qemu-system-x86_64 \
> -m 1G -smp 2 -nographic \
> -kernel arch/x86/boot/bzImage \
> -append "console=ttyS0,115200 kgdboc=ttyS0 earlycon=uart8250,io,0x3f8 kgdboc_earlycon kgdbwait"
Actually I realized there was a simpler reproduction (hinted at by the
missing "printk: legacy bootconsole [uart8250] enabled" in the regressed
case). It looks like the earlycon simply doesn't work and that means the
reproduction doesn't require anything related to kgdb at all. Simply:
make defconfig
make -j$(nproc)
qemu-system-x86_64 -m 1G -smp 2 -nographic -kernel arch/x86/boot/bzImage \
-append "earlycon=uart8250,io,0x3f8"
With the part 3 patchset applied I get no output from the earlycon
(without the patch set I get the early boot messages which, as expected,
stop when tty0 comes up).
Daniel.
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 00/19] printk cleanup - part 3
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (19 preceding siblings ...)
2026-01-05 12:52 ` [PATCH 00/19] printk cleanup - part 3 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
21 siblings, 1 reply; 50+ messages in thread
From: Andreas Larsson @ 2026-01-07 10:22 UTC (permalink / raw)
To: Marcos Paulo de Souza, Richard Weinberger, Anton Ivanov,
Johannes Berg, Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel
On 2025-12-27 13:16, Marcos Paulo de Souza wrote:
> The parts 1 and 2 can be found here [1] and here[2].
>
> The changes proposed in this part 3 are mostly to clarify the usage of
> the interfaces for NBCON, and use the printk helpers more broadly.
> Besides it, it also introduces a new way to register consoles
> and drop thes the CON_ENABLED flag. It seems too much, but in reality
> the changes are not complex, and as the title says, it's basically a
> cleanup without changing the functional changes.
Hi,
Patches 7-17 all say "replacing the CON_ENABLE flag" in their
descriptions, which should rather be "replacing the CON_ENABLED flag".
Cheers,
Andreas
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 00/19] printk cleanup - part 3
2026-01-07 10:22 ` Andreas Larsson
@ 2026-01-12 17:53 ` Marcos Paulo de Souza
0 siblings, 0 replies; 50+ messages in thread
From: Marcos Paulo de Souza @ 2026-01-12 17:53 UTC (permalink / raw)
To: Andreas Larsson, Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel
On Wed, 2026-01-07 at 11:22 +0100, Andreas Larsson wrote:
> On 2025-12-27 13:16, Marcos Paulo de Souza wrote:
> > The parts 1 and 2 can be found here [1] and here[2].
> >
> > The changes proposed in this part 3 are mostly to clarify the usage
> > of
> > the interfaces for NBCON, and use the printk helpers more broadly.
> > Besides it, it also introduces a new way to register consoles
> > and drop thes the CON_ENABLED flag. It seems too much, but in
> > reality
> > the changes are not complex, and as the title says, it's basically
> > a
> > cleanup without changing the functional changes.
>
> Hi,
>
> Patches 7-17 all say "replacing the CON_ENABLE flag" in their
> descriptions, which should rather be "replacing the CON_ENABLED
> flag".
That's true, thanks for spotting!
>
> Cheers,
> Andreas
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 00/19] printk cleanup - part 3
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
0 siblings, 1 reply; 50+ messages in thread
From: Marcos Paulo de Souza @ 2026-01-13 12:41 UTC (permalink / raw)
To: Daniel Thompson
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor, linux-um, linux-kernel, kgdb-bugreport,
linux-serial, netdev, linux-m68k, linux-hardening, linuxppc-dev,
sparclinux, linux-stm32, linux-arm-kernel, linux-fsdevel
On Mon, 2026-01-05 at 14:08 +0000, Daniel Thompson wrote:
> On Mon, Jan 05, 2026 at 12:52:14PM +0000, Daniel Thompson wrote:
> > Hi Marcos
> >
> > On Sat, Dec 27, 2025 at 09:16:07AM -0300, Marcos Paulo de Souza
> > wrote:
> > > The parts 1 and 2 can be found here [1] and here[2].
> > >
> > > The changes proposed in this part 3 are mostly to clarify the
> > > usage of
> > > the interfaces for NBCON, and use the printk helpers more
> > > broadly.
> > > Besides it, it also introduces a new way to register consoles
> > > and drop thes the CON_ENABLED flag. It seems too much, but in
> > > reality
> > > the changes are not complex, and as the title says, it's
> > > basically a
> > > cleanup without changing the functional changes.
> >
> > I ran this patchset through the kgdb test suite and I'm afraid it
> > is
> > reporting functional changes.
> >
> > Specifically the earlycon support for kdb has regressed (FWIW the
> > problem bisects down to the final patch in the series where
> > CON_ENABLED
> > is removed).
> >
> > Reproduction on x86-64 KVM outside of the test suite should be
> > easy:
> >
> > make defconfig
> > scripts/config \
> > --enable DEBUG_INFO \
> > --enable DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT \
> > --enable DEBUG_FS \
> > --enable KALLSYMS_ALL \
> > --enable MAGIC_SYSRQ \
> > --enable KGDB \
> > --enable KGDB_TESTS \
> > --enable KGDB_KDB \
> > --enable KDB_KEYBOARD \
> > --enable LKDTM \
> > --enable SECURITY_LOCKDOWN_LSM
> > make olddefconfig
> > make -j$(nproc)
> > qemu-system-x86_64 \
> > -m 1G -smp 2 -nographic \
> > -kernel arch/x86/boot/bzImage \
> > -append "console=ttyS0,115200 kgdboc=ttyS0
> > earlycon=uart8250,io,0x3f8 kgdboc_earlycon kgdbwait"
>
> Actually I realized there was a simpler reproduction (hinted at by
> the
> missing "printk: legacy bootconsole [uart8250] enabled" in the
> regressed
> case). It looks like the earlycon simply doesn't work and that means
> the
> reproduction doesn't require anything related to kgdb at all. Simply:
>
> make defconfig
> make -j$(nproc)
> qemu-system-x86_64 -m 1G -smp 2 -nographic -kernel
> arch/x86/boot/bzImage \
> -append "earlycon=uart8250,io,0x3f8"
>
> With the part 3 patchset applied I get no output from the earlycon
> (without the patch set I get the early boot messages which, as
> expected,
> stop when tty0 comes up).
Hi Daniel, sorry for the late reply! Lots of things to check lately :)
Ok, I reproduced here, thanks a lot for testing kgdboc, it's a quick
way to check that the new register_console_force is not working. Let me
take a look to find what's wrong. Thanks a lot for finding this issue!
>
>
> Daniel.
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 01/19] printk/nbcon: Use an enum to specify the required callback in console_is_usable()
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
0 siblings, 1 reply; 50+ messages in thread
From: Petr Mladek @ 2026-01-13 16:25 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, Laurentiu Tudor,
linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel
On Sat 2025-12-27 09:16:08, Marcos Paulo de Souza wrote:
> The current usage of console_is_usable() is clumsy. The parameter
> @use_atomic is boolean and thus not self-explanatory. The function is
> called twice in situations when there are no-strict requirements.
>
> Replace it with enum nbcon_write_cb which provides a more descriptive
> values for all 3 situations: atomic, thread or any.
>
> Note that console_is_usable() checks only NBCON_USE_ATOMIC because
> .write_thread() callback is mandatory. But the other two values still
> make sense because they describe the intention of the caller.
>
> --- a/include/linux/console.h
> +++ b/include/linux/console.h
> @@ -202,6 +202,19 @@ enum cons_flags {
> CON_NBCON_ATOMIC_UNSAFE = BIT(9),
> };
>
> +/**
> + * enum nbcon_write_cb - Defines which nbcon write() callback must be used based
> + * on the caller context.
> + * @NBCON_USE_ATOMIC: Use con->write_atomic().
> + * @NBCON_USE_THREAD: Use con->write_thread().
> + * @NBCON_USE_ANY: The caller does not have any strict requirements.
> + */
> +enum nbcon_write_cb {
> + NBCON_USE_ATOMIC,
> + NBCON_USE_THREAD,
> + NBCON_USE_ANY,
AFAIK, this would define NBCON_USE_ATOMIC as zero. See below.
> +};
> +
> /**
> * struct nbcon_state - console state for nbcon consoles
> * @atom: Compound of the state fields for atomic operations
> @@ -622,7 +635,8 @@ extern void nbcon_kdb_release(struct nbcon_write_context *wctxt);
> * which can also play a role in deciding if @con can be used to print
> * records.
> */
> -static inline bool console_is_usable(struct console *con, short flags, bool use_atomic)
> +static inline bool console_is_usable(struct console *con, short flags,
> + enum nbcon_write_cb nwc)
> {
> if (!(flags & CON_ENABLED))
> return false;
> @@ -631,7 +645,7 @@ static inline bool console_is_usable(struct console *con, short flags, bool use_
> return false;
>
> if (flags & CON_NBCON) {
> - if (use_atomic) {
> + if (nwc & NBCON_USE_ATOMIC) {
This will always be false because NBCON_USE_ATOMIC is zero.
I think that it was defined as "0x1" in the original proposal.
Let's keep it defined by as zero and use here:
if (nwc == NBCON_USE_ATOMIC) {
Note that we do _not_ want to return "false" for "NBCON_USE_ANY"
when con->write_atomic does not exist.
> /* The write_atomic() callback is optional. */
> if (!con->write_atomic)
> return false;
Otherwise, it looks good to me.
Best Regards,
Petr
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 02/19] printk: Introduce console_is_nbcon
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
1 sibling, 0 replies; 50+ messages in thread
From: Petr Mladek @ 2026-01-13 17:37 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, Laurentiu Tudor,
linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel
On Sat 2025-12-27 09:16:09, Marcos Paulo de Souza 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.
>
> Signed-off-by: Petr Mladek <pmladek@suse.com>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
> ---
> include/linux/console.h | 27 +++++++++++++++++++++++++++
> kernel/debug/kdb/kdb_io.c | 2 +-
> kernel/printk/nbcon.c | 2 +-
> kernel/printk/printk.c | 15 ++++++---------
> 4 files changed, 35 insertions(+), 11 deletions(-)
>
> 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
There is _srcu in the function name, see below.
> + * @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)
And here it is without _srcu.
I would prefer the variant with _srcu to make it clear that it
can be called only under _srcu. Similar to console_srcu_read_flags(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);
> +}
> +
> /* Variant of console_is_registered() when the console_list_lock is held. */
> static inline bool console_is_registered_locked(const struct console *con)
> {
Otherwise, it looks good to me.
With a consistent name, feel free to use:
Reviewed-by: Petr Mladek <pmladek@suse.com>
Best Regards,
Petr
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 00/19] printk cleanup - part 3
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
0 siblings, 2 replies; 50+ messages in thread
From: Marcos Paulo de Souza @ 2026-01-14 0:32 UTC (permalink / raw)
To: Daniel Thompson
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor, linux-um, linux-kernel, kgdb-bugreport,
linux-serial, netdev, linux-m68k, linux-hardening, linuxppc-dev,
sparclinux, linux-stm32, linux-arm-kernel, linux-fsdevel
On Tue, 2026-01-13 at 09:41 -0300, Marcos Paulo de Souza wrote:
> On Mon, 2026-01-05 at 14:08 +0000, Daniel Thompson wrote:
> > On Mon, Jan 05, 2026 at 12:52:14PM +0000, Daniel Thompson wrote:
> > > Hi Marcos
> > >
> > > On Sat, Dec 27, 2025 at 09:16:07AM -0300, Marcos Paulo de Souza
> > > wrote:
> > > > The parts 1 and 2 can be found here [1] and here[2].
> > > >
> > > > The changes proposed in this part 3 are mostly to clarify the
> > > > usage of
> > > > the interfaces for NBCON, and use the printk helpers more
> > > > broadly.
> > > > Besides it, it also introduces a new way to register consoles
> > > > and drop thes the CON_ENABLED flag. It seems too much, but in
> > > > reality
> > > > the changes are not complex, and as the title says, it's
> > > > basically a
> > > > cleanup without changing the functional changes.
> > >
> > > I ran this patchset through the kgdb test suite and I'm afraid it
> > > is
> > > reporting functional changes.
> > >
> > > Specifically the earlycon support for kdb has regressed (FWIW the
> > > problem bisects down to the final patch in the series where
> > > CON_ENABLED
> > > is removed).
> > >
> > > Reproduction on x86-64 KVM outside of the test suite should be
> > > easy:
> > >
> > > make defconfig
> > > scripts/config \
> > > --enable DEBUG_INFO \
> > > --enable DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT \
> > > --enable DEBUG_FS \
> > > --enable KALLSYMS_ALL \
> > > --enable MAGIC_SYSRQ \
> > > --enable KGDB \
> > > --enable KGDB_TESTS \
> > > --enable KGDB_KDB \
> > > --enable KDB_KEYBOARD \
> > > --enable LKDTM \
> > > --enable SECURITY_LOCKDOWN_LSM
> > > make olddefconfig
> > > make -j$(nproc)
> > > qemu-system-x86_64 \
> > > -m 1G -smp 2 -nographic \
> > > -kernel arch/x86/boot/bzImage \
> > > -append "console=ttyS0,115200 kgdboc=ttyS0
> > > earlycon=uart8250,io,0x3f8 kgdboc_earlycon kgdbwait"
> >
> > Actually I realized there was a simpler reproduction (hinted at by
> > the
> > missing "printk: legacy bootconsole [uart8250] enabled" in the
> > regressed
> > case). It looks like the earlycon simply doesn't work and that
> > means
> > the
> > reproduction doesn't require anything related to kgdb at all.
> > Simply:
> >
> > make defconfig
> > make -j$(nproc)
> > qemu-system-x86_64 -m 1G -smp 2 -nographic -kernel
> > arch/x86/boot/bzImage \
> > -append "earlycon=uart8250,io,0x3f8"
> >
> > With the part 3 patchset applied I get no output from the earlycon
> > (without the patch set I get the early boot messages which, as
> > expected,
> > stop when tty0 comes up).
>
> Hi Daniel, sorry for the late reply! Lots of things to check lately
> :)
>
> Ok, I reproduced here, thanks a lot for testing kgdboc, it's a quick
> way to check that the new register_console_force is not working. Let
> me
> take a look to find what's wrong. Thanks a lot for finding this
> issue!
Ok, I did a bisect and found out that the issue lies in the last
commit, where CON_ENABLED was removed. After it, I then checked what
was wrong, since everything was being plumbed correctly (tm), and then
I found that it was not:
On _register_console, the function try_enable_default_console is called
when there are not registered consoles, and then it sets CON_ENABLED
for the console. Later on, try_enable_preferred_console it checks if
the console was specified by the user, and at the same time it had
CON_ENABLED set.
It worked by chance, but now, we don't have this flag anymore, and then
we are not _marking_ the console on try_enable_default_console so
try_enable_preferred_console returns ENOENT.
I have added logs for both cases first the case with the patchset
applied but the last one patch, and it works:
$ vng --append "console=ttyS0,115200 earlyprintk=ttyS0,115200
kgdboc=ttyS0 earlycon=uart8250,io,0x3f8 kgdboc_earlycon kgdbwait" --
verbose
Decompressing Linux... Parsing ELF... Performing relocations... done.
Booting the kernel (entry_offset: 0x000000000450d530).
XXX register_console earlyser
XXX try_enable_default_console earlyser enabled
XXX try_enable_preferred_console earlyser user_specified 1 returned -
ENOENT
XXX try_enable_preferred_console earlyser user_specified 0 returned 0
because flags was ENABLED
^^ here, returning 0 means that the console was accepted and will be
registered
XXX __register_console earlyser registered
XXX register_console uart
XXX try_enable_default_console uart enabled
XXX try_enable_preferred_console uart user_specified 1 returned -ENOENT
XXX try_enable_preferred_console uart user_specified 0 returned 0
because flags was ENABLED
XXX __register_console uart registered
^^^^ same here
Going to register kgdb with earlycon 'uart'
Entering kdb (current=0x0000000000000000, pid 0)
Now, the logs of the patchset with the last patch also applied:
Decompressing Linux... Parsing ELF... Performing relocations... done.
Booting the kernel (entry_offset: 0x000000000450d530).
XXX register_console earlyser
XXX try_enable_default_console earlyser enabled
XXX try_enable_preferred_console earlyser user_specified 1 returned -
ENOENT
XXX try_enable_preferred_console earlyser user_specified 0 returned -
ENOENT
XXX register_console uart
XXX try_enable_default_console uart enabled
XXX try_enable_preferred_console uart user_specified 1 returned -ENOENT
XXX try_enable_preferred_console uart user_specified 0 returned -ENOENT
^^^^ here, it should have registered the console
XXX console_setup hvc0
XXX __add_preferred_console hvc added, idx 0 i 0
XXX console_setup ttyS0,115200
XXX __add_preferred_console ttyS added, idx 0 i 1
Poking KASLR using RDRAND RDTSC...
XXX register_console tty
XXX try_enable_preferred_console tty user_specified 1 returned -ENOENT
XXX try_enable_preferred_console tty user_specified 0 returned -ENOENT
^^^ again, it fails because we don't flag the console with CON_ENABLED
as before.
XXX register_console hvc
XXX register_console ttyS
XXX try_enable_preferred_console ttyS user_specified 1 returned 0 with
user specified
XXX __register_console ttyS registered
[ 0.000000] Linux version 6.18.0+ (mpdesouza@daedalus) (clang
version 21.1.7, LLD 21.1.7) #374 SMP PREEMPT_RT Tue J
an 13 21:08:34 -03 2026 reserved
[ 0.000000] earlycon: uart8250 at I/O port 0x3f8 (options '')
[ 0.000000] kgdboc: No suitable earlycon yet, will try later
So, without any console kgdb is activated much later in the boot
process, as you found it.
I talked with Petr Mladek and it would need to rework the way that we
register a console, and he's already working on it. For now I believe
that we could take a look in all the patches besides the last one that
currently breaks the earlycon with kgdb and maybe other usecases.
Sorry for not catching this issue before. I'll use kgdb next time to
make sure that it keeps working :)
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 00/19] printk cleanup - part 3
2026-01-14 0:32 ` Marcos Paulo de Souza
@ 2026-01-14 8:20 ` Petr Mladek
2026-01-14 16:38 ` Daniel Thompson
1 sibling, 0 replies; 50+ messages in thread
From: Petr Mladek @ 2026-01-14 8:20 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Daniel Thompson, Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, Laurentiu Tudor,
linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel
On Tue 2026-01-13 21:32:33, Marcos Paulo de Souza wrote:
> On Tue, 2026-01-13 at 09:41 -0300, Marcos Paulo de Souza wrote:
> > On Mon, 2026-01-05 at 14:08 +0000, Daniel Thompson wrote:
> > > On Mon, Jan 05, 2026 at 12:52:14PM +0000, Daniel Thompson wrote:
> > > > Hi Marcos
> > > >
> > > > On Sat, Dec 27, 2025 at 09:16:07AM -0300, Marcos Paulo de Souza
> > > > wrote:
> > > > > The parts 1 and 2 can be found here [1] and here[2].
> > > > >
> > > > > The changes proposed in this part 3 are mostly to clarify the
> > > > > usage of
> > > > > the interfaces for NBCON, and use the printk helpers more
> > > > > broadly.
> > > > > Besides it, it also introduces a new way to register consoles
> > > > > and drop thes the CON_ENABLED flag. It seems too much, but in
> > > > > reality
> > > > > the changes are not complex, and as the title says, it's
> > > > > basically a
> > > > > cleanup without changing the functional changes.
> > > >
> > > > I ran this patchset through the kgdb test suite and I'm afraid it
> > > > is
> > > > reporting functional changes.
> > > >
> > > > Specifically the earlycon support for kdb has regressed (FWIW the
> > > > problem bisects down to the final patch in the series where
> > > > CON_ENABLED
> > > > is removed).
> > > >
> > > > Reproduction on x86-64 KVM outside of the test suite should be
> > > > easy:
> > > >
> > > > make defconfig
> > > > scripts/config \
> > > > --enable DEBUG_INFO \
> > > > --enable DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT \
> > > > --enable DEBUG_FS \
> > > > --enable KALLSYMS_ALL \
> > > > --enable MAGIC_SYSRQ \
> > > > --enable KGDB \
> > > > --enable KGDB_TESTS \
> > > > --enable KGDB_KDB \
> > > > --enable KDB_KEYBOARD \
> > > > --enable LKDTM \
> > > > --enable SECURITY_LOCKDOWN_LSM
> > > > make olddefconfig
> > > > make -j$(nproc)
> > > > qemu-system-x86_64 \
> > > > -m 1G -smp 2 -nographic \
> > > > -kernel arch/x86/boot/bzImage \
> > > > -append "console=ttyS0,115200 kgdboc=ttyS0
> > > > earlycon=uart8250,io,0x3f8 kgdboc_earlycon kgdbwait"
> > >
> > > Actually I realized there was a simpler reproduction (hinted at by
> > > the
> > > missing "printk: legacy bootconsole [uart8250] enabled" in the
> > > regressed
> > > case). It looks like the earlycon simply doesn't work and that
> > > means
> > > the
> > > reproduction doesn't require anything related to kgdb at all.
> > > Simply:
> > >
> > > make defconfig
> > > make -j$(nproc)
> > > qemu-system-x86_64 -m 1G -smp 2 -nographic -kernel
> > > arch/x86/boot/bzImage \
> > > -append "earlycon=uart8250,io,0x3f8"
> > >
> > > With the part 3 patchset applied I get no output from the earlycon
> > > (without the patch set I get the early boot messages which, as
> > > expected,
> > > stop when tty0 comes up).
> >
> > Hi Daniel, sorry for the late reply! Lots of things to check lately
> > :)
> >
> > Ok, I reproduced here, thanks a lot for testing kgdboc, it's a quick
> > way to check that the new register_console_force is not working. Let
> > me
> > take a look to find what's wrong. Thanks a lot for finding this
> > issue!
>
> Ok, I did a bisect and found out that the issue lies in the last
> commit, where CON_ENABLED was removed. After it, I then checked what
> was wrong, since everything was being plumbed correctly (tm), and then
> I found that it was not:
>
> On _register_console, the function try_enable_default_console is called
> when there are not registered consoles, and then it sets CON_ENABLED
> for the console. Later on, try_enable_preferred_console it checks if
> the console was specified by the user, and at the same time it had
> CON_ENABLED set.
>
> It worked by chance, but now, we don't have this flag anymore, and then
> we are not _marking_ the console on try_enable_default_console so
> try_enable_preferred_console returns ENOENT.
Great catch! Yeah, it worked just by chance.
> So, without any console kgdb is activated much later in the boot
> process, as you found it.
>
> I talked with Petr Mladek and it would need to rework the way that we
> register a console, and he's already working on it.
Yes, I have some patches in early stages of developnent of another
feature which would help here.
> For now I believe
> that we could take a look in all the patches besides the last one that
> currently breaks the earlycon with kgdb and maybe other usecases.
I agree. I am going to review this patchset first. Then I'll try to
clean up the patches which remove the ugly side effect from
try_enable_preferred_console(). Then we could discuss how
to move forward. It might make sense to push this patchset
first without the last patch...
> Sorry for not catching this issue before. I'll use kgdb next time to
> make sure that it keeps working :)
Do not worry at all. It was a well hidden catch. It is great that
Daniel found the regression in time...
Best Regards,
Petr
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 03/19] printk: Drop flags argument from console_is_usable
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
0 siblings, 0 replies; 50+ messages in thread
From: Petr Mladek @ 2026-01-14 8:44 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, Laurentiu Tudor,
linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel
On Sat 2025-12-27 09:16:10, Marcos Paulo de Souza wrote:
> The flags argument was also used to check if CON_NBCON was set, but their
> usage was fixed in the last commit. All current users are reading the
> variable just to call console_is_usable.
>
> By calling console_srcu_read_flags inside console_is_usable makes the
> code cleaner and removes one argument from the function.
>
> Along with it, create a variant called __console_is_usable that can be
> used under console_list_lock(), like unregister_console_locked.
>
> --- a/include/linux/console.h
> +++ b/include/linux/console.h
> @@ -656,13 +656,8 @@ extern bool nbcon_kdb_try_acquire(struct console *con,
> struct nbcon_write_context *wctxt);
> extern void nbcon_kdb_release(struct nbcon_write_context *wctxt);
>
> -/*
> - * Check if the given console is currently capable and allowed to print
> - * records. Note that this function does not consider the current context,
> - * which can also play a role in deciding if @con can be used to print
> - * records.
> - */
> -static inline bool console_is_usable(struct console *con, short flags,
> +/* Variant of console_is_usable() when the console_list_lock is held. */
Nit: The comment is a bit misleading because this function is called
also from console_is_usable() under console_srcu_read_lock().
I would say something like:
/*
* The caller must ensure that @con can't disappear either by taking
* console_list_lock() or console_srcu_read_lock(). See also
* console_is_usable().
*/
> +static inline bool __console_is_usable(struct console *con, short flags,
> enum nbcon_write_cb nwc)
> {
> if (!(flags & CON_ENABLED))
> @@ -707,6 +702,18 @@ static inline bool console_is_usable(struct console *con, short flags,
> return true;
> }
>
> +/*
> + * Check if the given console is currently capable and allowed to print
> + * records. Note that this function does not consider the current context,
> + * which can also play a role in deciding if @con can be used to print
> + * records.
And I would add here something like:
*
* Context: Must be called under console_srcu_read_lock().
> + */
> +static inline bool console_is_usable(struct console *con,
> + enum nbcon_write_cb nwc)
> +{
> + return __console_is_usable(con, console_srcu_read_flags(con), nwc);
> +}
> +
> #else
> static inline void nbcon_cpu_emergency_enter(void) { }
> static inline void nbcon_cpu_emergency_exit(void) { }
Otherwise, it looks good. It is a nice clean up.
Best Regards,
Petr
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 04/19] printk: Reintroduce consoles_suspended global state
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
0 siblings, 0 replies; 50+ messages in thread
From: Petr Mladek @ 2026-01-14 13:12 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, Laurentiu Tudor,
linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel
On Sat 2025-12-27 09:16:11, Marcos Paulo de Souza wrote:
> This change partially reverts commit 9e70a5e109a4
> ("printk: Add per-console suspended state"). The intent of the original
> commit was to move the management of the console suspended state to the
> consoles themselves to be able to use SRCU instead of console lock.
>
> But having a global state is still useful when checking if the global
> suspend was triggered by power management. This way, instead of setting
> the state of each individual console, the code would only set/read from the
> global state.
>
> Along with this change, two more fixes are necessary: change
> console_{suspend,resume} to set/clear CON_SUSPEND instead of setting
> CON_ENABLED and change show_cons_active to call __console_is_usable to
> check console usefulness.
I would invert the logic a bit. I think that the main motivation
is to replace CON_ENABLE -> CON_SUSPEND.
<proposal>
The flag CON_ENABLE is cleared when serial drivers get suspended. This
"hack" has been added by the commit 33c0d1b0c3ebb6 ("[PATCH] Serial
driver stuff") back in v2.5.28.
Stop hijacking CON_ENABLE flag and use the CON_SUSPEND flag instead.
Still allow to distinguish when:
- the backing device is being suspended, see console_suspend().
- the power management wants to calm down all consoles using
a big-hammer, see console_suspend_all().
And restore the global "consoles_suspended" flag which was removed
by the commit 9e70a5e109a4 ("printk: Add per-console suspended state").
The difference is that accesses to the new global flag are
synchronized the same way as to the CON_SUSPEND flag. It allows
to read it under console_srcu_read_lock().
Finally, use __console_is_usable() in show_cons_active(). It is the
last location where the CON_ENABLED flag was checked directly.
The patch should not change the existing behavior because all users check
the state of the console using console_is_usable().
</proposal>
> diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
> index e2d92cf70eb7..7d2bded75b75 100644
> --- a/drivers/tty/tty_io.c
> +++ b/drivers/tty/tty_io.c
> @@ -3552,9 +3552,9 @@ static ssize_t show_cons_active(struct device *dev,
> for_each_console(c) {
> if (!c->device)
> continue;
> - if (!(c->flags & CON_NBCON) && !c->write)
> - continue;
> - if ((c->flags & CON_ENABLED) == 0)
> + if (!__console_is_usable(c, c->flags,
> + consoles_suspended,
> + NBCON_USE_ANY))
It would be better to move this into a separate patch.
> continue;
> cs[i++] = c;
> if (i >= ARRAY_SIZE(cs))
Otherwise, it looks good.
Best Regards,
Petr
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 05/19] printk: Add more context to suspend/resume functions
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
1 sibling, 0 replies; 50+ messages in thread
From: Petr Mladek @ 2026-01-14 13:20 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, Laurentiu Tudor,
linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel
On Sat 2025-12-27 09:16:12, Marcos Paulo de Souza wrote:
> The new comments clarifies from where the functions are supposed to be
> called.
>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
The improved comments would have helped to understand the previous patch.
I would either merge it into the previous patch or switch the
ordering.
If this stays as a separate patch, feel free to use:
Reviewed-by: Petr Mladek <pmladek@suse.com>
Best Regards,
Petr
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 06/19] printk: Introduce register_console_force
2025-12-27 12:16 ` [PATCH 06/19] printk: Introduce register_console_force Marcos Paulo de Souza
@ 2026-01-14 14:22 ` Petr Mladek
0 siblings, 0 replies; 50+ messages in thread
From: Petr Mladek @ 2026-01-14 14:22 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, Laurentiu Tudor,
linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel
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
^ permalink raw reply related [flat|nested] 50+ messages in thread
* Re: [PATCH 00/19] printk cleanup - part 3
2026-01-14 0:32 ` Marcos Paulo de Souza
2026-01-14 8:20 ` Petr Mladek
@ 2026-01-14 16:38 ` Daniel Thompson
1 sibling, 0 replies; 50+ messages in thread
From: Daniel Thompson @ 2026-01-14 16:38 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Daniel Thompson, Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Douglas Anderson, Petr Mladek,
Steven Rostedt, John Ogness, Sergey Senozhatsky, Jiri Slaby,
Breno Leitao, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven, Kees Cook,
Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, Laurentiu Tudor,
linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel
On Tue, Jan 13, 2026 at 09:32:33PM -0300, Marcos Paulo de Souza wrote:
> I talked with Petr Mladek and it would need to rework the way that we
> register a console, and he's already working on it. For now I believe
> that we could take a look in all the patches besides the last one that
> currently breaks the earlycon with kgdb and maybe other usecases.
>
> Sorry for not catching this issue before. I'll use kgdb next time to
> make sure that it keeps working :)
As I understood things the bug was in earlycon rather then kgdb.
It was picked up by the kgdbtest suite since kgdb does some cool things
with earlycon (thanks to Doug Anderson) so I added a few earlycon tests
to the kgdbtest suite. However it wasn't kgdb itself that failed here.
So... if you want to run https://gitlab.com/daniel-thompson/kgdbtest
then certainly feel free but its probably less effort just to include
a couple of earlycon checks in your testing.
Daniel.
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 07/19] drivers: netconsole: Migrate to register_console_force helper
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
0 siblings, 0 replies; 50+ messages in thread
From: Petr Mladek @ 2026-01-15 10:16 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, linux-um,
linux-kernel, kgdb-bugreport, linux-serial, netdev, linux-m68k,
linux-hardening, linuxppc-dev, sparclinux, linux-stm32,
linux-arm-kernel, linux-fsdevel
On Sat 2025-12-27 09:16:14, Marcos Paulo de Souza wrote:
> The register_console_force function was introduced to register consoles
> even on the presence of default consoles, replacing the CON_ENABLE flag
> that was forcing the same behavior.
I would add "No functional changes." like you did in the other
similar patches ;-)
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Nice clean up!
Reviewed-by: Petr Mladek <pmladek@suse.com>
Best Regards,
Petr
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 08/19] debug: debug_core: Migrate to register_console_force helper
2025-12-27 12:16 ` [PATCH 08/19] debug: debug_core: " Marcos Paulo de Souza
@ 2026-01-15 10:20 ` Petr Mladek
0 siblings, 0 replies; 50+ messages in thread
From: Petr Mladek @ 2026-01-15 10:20 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, Laurentiu Tudor,
linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel
On Sat 2025-12-27 09:16:15, Marcos Paulo de Souza wrote:
> The register_console_force function was introduced to register consoles
> even on the presence of default consoles, replacing the CON_ENABLE flag
> that was forcing the same behavior.
>
> No functional changes.
>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
LGTM, nice cleanup!
Reviewed-by: Petr Mladek <pmladek@suse.com>
Best Regards,
Petr
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 09/19] m68k: emu: nfcon.c: Migrate to register_console_force helper
2025-12-27 12:16 ` [PATCH 09/19] m68k: emu: nfcon.c: " Marcos Paulo de Souza
@ 2026-01-15 10:26 ` Petr Mladek
0 siblings, 0 replies; 50+ messages in thread
From: Petr Mladek @ 2026-01-15 10:26 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, linux-um,
linux-kernel, kgdb-bugreport, linux-serial, netdev, linux-m68k,
linux-hardening, linuxppc-dev, sparclinux, linux-stm32,
linux-arm-kernel, linux-fsdevel
On Sat 2025-12-27 09:16:16, Marcos Paulo de Souza wrote:
> The register_console_force function was introduced to register consoles
> even on the presence of default consoles, replacing the CON_ENABLE flag
> that was forcing the same behavior.
>
> No functional changes.
>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
LGTM, nice cleanup!
Reviewed-by: Petr Mladek <pmladek@suse.com>
Best Regards,
Petr
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 10/19] fs: pstore: platform: Migrate to register_console_force helper
2025-12-27 12:16 ` [PATCH 10/19] fs: pstore: platform: " Marcos Paulo de Souza
@ 2026-01-15 11:05 ` Petr Mladek
0 siblings, 0 replies; 50+ messages in thread
From: Petr Mladek @ 2026-01-15 11:05 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, Laurentiu Tudor,
linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel
On Sat 2025-12-27 09:16:17, Marcos Paulo de Souza wrote:
> The register_console_force function was introduced to register consoles
> even on the presence of default consoles, replacing the CON_ENABLE flag
> that was forcing the same behavior.
>
> No functional changes.
> --- a/fs/pstore/platform.c
> +++ b/fs/pstore/platform.c
> @@ -418,10 +418,10 @@ static void pstore_register_console(void)
> sizeof(pstore_console.name));
> /*
> * Always initialize flags here since prior unregister_console()
> - * calls may have changed settings (specifically CON_ENABLED).
> + * calls may have changed settings.
> */
> - pstore_console.flags = CON_PRINTBUFFER | CON_ENABLED | CON_ANYTIME;
> - register_console(&pstore_console);
> + pstore_console.flags = CON_PRINTBUFFER | CON_ANYTIME;
As the original comment suggests, this was done primary because
of CON_ENABLED flag. Otherwise, the console was not registered again.
register_console() might remove CON_PRINTBUFFER when there was
a boot console and the newly registered console will get associated
with /dev/console. But I consider this a corner case. Other console
drivers ignore this scenario.
I suggest to define the two flags statically in
struct console pstore_console definition as it is done by
other console drivers. Remove this explicit dynamic assigment.
And add the following into the commit message:
<proposal>
Define the remaining console flags statically in the structure definition
as it is done by other console drivers.
The flags were re-defined primary because of the CON_ENABLED flag.
Otherwise, the re-registration failed.
The CON_PRINTBUFFER might get cleared when a boot console was registered
and the pstrore console got associated with /dev/console. In this
case, the pstore console would not re-play the entire ring buffer
on re-registration. But it is a corner case. And it actually might
be a desired behavior.
</proposal>
Otherwise, the next generations of kernel developers might think that
the re-assigment was there because of CON_PRINTBUFFER flag.
And it might cause non-necessary headaches ;-)
> + register_console_force(&pstore_console);
> }
>
> static void pstore_unregister_console(void)
Best Regards,
Petr
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 11/19] powerpc: kernel: udbg: Migrate to register_console_force helper
2025-12-27 12:16 ` [PATCH 11/19] powerpc: kernel: udbg: " Marcos Paulo de Souza
@ 2026-01-15 12:13 ` Petr Mladek
0 siblings, 0 replies; 50+ messages in thread
From: Petr Mladek @ 2026-01-15 12:13 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, linux-um,
linux-kernel, kgdb-bugreport, linux-serial, netdev, linux-m68k,
linux-hardening, linuxppc-dev, sparclinux, linux-stm32,
linux-arm-kernel, linux-fsdevel
On Sat 2025-12-27 09:16:18, Marcos Paulo de Souza wrote:
> The register_console_force function was introduced to register consoles
> even on the presence of default consoles, replacing the CON_ENABLE flag
> that was forcing the same behavior.
>
> No functional changes.
>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
LGTM, nice cleanup!
Reviewed-by: Petr Mladek <pmladek@suse.com>
Best Regards,
Petr
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 12/19] sparc: kernel: btext: Migrate to register_console_force helper
2025-12-27 12:16 ` [PATCH 12/19] sparc: kernel: btext: " Marcos Paulo de Souza
@ 2026-01-15 12:14 ` Petr Mladek
0 siblings, 0 replies; 50+ messages in thread
From: Petr Mladek @ 2026-01-15 12:14 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, linux-um,
linux-kernel, kgdb-bugreport, linux-serial, netdev, linux-m68k,
linux-hardening, linuxppc-dev, sparclinux, linux-stm32,
linux-arm-kernel, linux-fsdevel
On Sat 2025-12-27 09:16:19, Marcos Paulo de Souza wrote:
> The register_console_force function was introduced to register consoles
> even on the presence of default consoles, replacing the CON_ENABLE flag
> that was forcing the same behavior.
>
> No functional changes.
>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
LGTM, nice cleanup!
Reviewed-by: Petr Mladek <pmladek@suse.com>
Best Regards,
Petr
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 13/19] um: drivers: mconsole_kern.c: Migrate to register_console_force helper
2025-12-27 12:16 ` [PATCH 13/19] um: drivers: mconsole_kern.c: " Marcos Paulo de Souza
@ 2026-01-15 12:24 ` Petr Mladek
0 siblings, 0 replies; 50+ messages in thread
From: Petr Mladek @ 2026-01-15 12:24 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, linux-um,
linux-kernel, kgdb-bugreport, linux-serial, netdev, linux-m68k,
linux-hardening, linuxppc-dev, sparclinux, linux-stm32,
linux-arm-kernel, linux-fsdevel
On Sat 2025-12-27 09:16:20, Marcos Paulo de Souza wrote:
> The register_console_force function was introduced to register consoles
> even on the presence of default consoles, replacing the CON_ENABLE flag
> that was forcing the same behavior.
>
> No functional changes.
>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
LGTM, nice cleanup!
Reviewed-by: Petr Mladek <pmladek@suse.com>
Best Regards,
Petr
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 14/19] drivers: hwtracing: stm: console.c: Migrate to register_console_force helper
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
1 sibling, 0 replies; 50+ messages in thread
From: Petr Mladek @ 2026-01-15 12:29 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, linux-um,
linux-kernel, kgdb-bugreport, linux-serial, netdev, linux-m68k,
linux-hardening, linuxppc-dev, sparclinux, linux-stm32,
linux-arm-kernel, linux-fsdevel
On Sat 2025-12-27 09:16:21, Marcos Paulo de Souza wrote:
> The register_console_force function was introduced to register consoles
> even on the presence of default consoles, replacing the CON_ENABLE flag
> that was forcing the same behavior.
>
> No functional changes.
>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
LGTM, nice cleanup!
Reviewed-by: Petr Mladek <pmladek@suse.com>
Best Regards,
Petr
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 16/19] drivers: tty: serial: ma35d1_serial: Migrate to register_console_force helper
2025-12-27 12:16 ` [PATCH 16/19] drivers: tty: serial: ma35d1_serial: " Marcos Paulo de Souza
@ 2026-01-15 16:28 ` Petr Mladek
0 siblings, 0 replies; 50+ messages in thread
From: Petr Mladek @ 2026-01-15 16:28 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, linux-um,
linux-kernel, kgdb-bugreport, linux-serial, netdev, linux-m68k,
linux-hardening, linuxppc-dev, sparclinux, linux-stm32,
linux-arm-kernel, linux-fsdevel
On Sat 2025-12-27 09:16:23, Marcos Paulo de Souza wrote:
> The register_console_force function was introduced to register consoles
> even on the presence of default consoles, replacing the CON_ENABLE flag
> that was forcing the same behavior.
>
> No functional changes.
>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
> ---
> drivers/tty/serial/ma35d1_serial.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/tty/serial/ma35d1_serial.c b/drivers/tty/serial/ma35d1_serial.c
> index 285b0fe41a86..d1e03dee5579 100644
> --- a/drivers/tty/serial/ma35d1_serial.c
> +++ b/drivers/tty/serial/ma35d1_serial.c
> @@ -633,7 +633,7 @@ static struct console ma35d1serial_console = {
> .write = ma35d1serial_console_write,
> .device = uart_console_device,
> .setup = ma35d1serial_console_setup,
> - .flags = CON_PRINTBUFFER | CON_ENABLED,
> + .flags = CON_PRINTBUFFER,
> .index = -1,
> .data = &ma35d1serial_reg,
> };
> @@ -657,7 +657,7 @@ static void ma35d1serial_console_init_port(void)
> static int __init ma35d1serial_console_init(void)
> {
> ma35d1serial_console_init_port();
> - register_console(&ma35d1serial_console);
> + register_console_force(&ma35d1serial_console);
Sigh, I am afraid that this is not enough.
I double checked how "ma35d1serial_console" was used. I guess
that it could get registered also via the generic uart device
driver code. I see the following:
#ifdef CONFIG_SERIAL_NUVOTON_MA35D1_CONSOLE
[...]
#define MA35D1SERIAL_CONSOLE (&ma35d1serial_console)
#else
#define MA35D1SERIAL_CONSOLE NULL
#endif
static struct uart_driver ma35d1serial_reg = {
[...]
.cons = MA35D1SERIAL_CONSOLE,
[...]
};
static int __init ma35d1serial_init(void)
{
[...]
ret = uart_register_driver(&ma35d1serial_reg);
[...]
ret = platform_driver_register(&ma35d1serial_driver);
[...]
}
And the gneric code:
uart_configure_port(struct uart_driver *drv, struct uart_state *state,
struct uart_port *port)
{
[...]
/*
* If this driver supports console, and it hasn't been
* successfully registered yet, try to re-register it.
* It may be that the port was not available.
*/
if (port->cons && !console_is_registered(port->cons))
register_console(port->cons);
[...]
}
, which can called via from:
+ mux_probe()
+ uart_add_one_port()
+ serial_ctrl_register_port()
+serial_core_register_port()
+ serial_core_add_one_port()
+ uart_configure_port()
+ register_console()
Honestly, I am not 100% sure. The struct console is assigned to
.cons in struct uart_driver. And uart_configure_port() function
passes port->cons from struct uart_port *port. But I believe
that they can get assigned somewhere in the maze of
the init/probe code.
I would feel more comfortable if we kept the information as
as flag in struct console so that even the generic callbacks
could use it.
Anyway, it makes sense to create a sepate flag for this
purpose, e.g. CON_FORCE or CON_FORCE_ENABLE.
> return 0;
> }
> console_initcall(ma35d1serial_console_init);
Best Regards,
Petr
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 15/19] drivers: tty: serial: mux.c: Migrate to register_console_force helper
2025-12-27 12:16 ` [PATCH 15/19] drivers: tty: serial: mux.c: " Marcos Paulo de Souza
@ 2026-01-16 9:59 ` Petr Mladek
0 siblings, 0 replies; 50+ messages in thread
From: Petr Mladek @ 2026-01-16 9:59 UTC (permalink / raw)
To: Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Steven Rostedt, John Ogness, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, Laurentiu Tudor,
linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel
On Sat 2025-12-27 09:16:22, Marcos Paulo de Souza wrote:
> The register_console_force function was introduced to register consoles
> even on the presence of default consoles, replacing the CON_ENABLE flag
> that was forcing the same behavior.
>
> --- a/drivers/tty/serial/mux.c
> +++ b/drivers/tty/serial/mux.c
> @@ -390,7 +390,7 @@ static struct console mux_console = {
> .write = mux_console_write,
> .device = uart_console_device,
> .setup = mux_console_setup,
> - .flags = CON_ENABLED | CON_PRINTBUFFER,
> + .flags = CON_PRINTBUFFER,
> .index = 0,
> .data = &mux_driver,
> };
> @@ -547,7 +547,7 @@ static int __init mux_init(void)
> mod_timer(&mux_timer, jiffies + MUX_POLL_DELAY);
>
> #ifdef CONFIG_SERIAL_MUX_CONSOLE
> - register_console(&mux_console);
> + register_console_force(&mux_console);
The situation here is the same as in 16th patch for
ma35d1serial_console().
Also "mux_console" is assigned to
static int __init mux_probe(struct parisc_device *dev)
{
[...]
mux_driver.cons = MUX_CONSOLE;
status = uart_register_driver(&mux_driver);
[...]
status = uart_add_one_port(&mux_driver, port);
[...]
}
So, that it can get registered also by:
+ mux_probe()
+ uart_add_one_port()
+ serial_ctrl_register_port()
+ serial_core_register_port()
+ serial_core_add_one_port()
+ uart_configure_port()
+ register_console()
And we would need to pass the "force" information via CON_FORCE flag.
Best Regards,
Petr
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 14/19] drivers: hwtracing: stm: console.c: Migrate to register_console_force helper
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
1 sibling, 1 reply; 50+ messages in thread
From: Alexander Shishkin @ 2026-01-16 13:04 UTC (permalink / raw)
To: Marcos Paulo de Souza, Richard Weinberger, Anton Ivanov,
Johannes Berg, Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza, Alexander Shishkin
Marcos Paulo de Souza <mpdesouza@suse.com> writes:
> The register_console_force function was introduced to register consoles
> even on the presence of default consoles, replacing the CON_ENABLE flag
> that was forcing the same behavior.
>
> No functional changes.
>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Acked-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Should I pick this up or will you send this with the rest of the series?
Cheers,
--
Alex
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 14/19] drivers: hwtracing: stm: console.c: Migrate to register_console_force helper
2026-01-16 13:04 ` Alexander Shishkin
@ 2026-01-16 13:54 ` Marcos Paulo de Souza
0 siblings, 0 replies; 50+ messages in thread
From: Marcos Paulo de Souza @ 2026-01-16 13:54 UTC (permalink / raw)
To: Alexander Shishkin, Richard Weinberger, Anton Ivanov,
Johannes Berg, Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel
On Fri, 2026-01-16 at 14:04 +0100, Alexander Shishkin wrote:
> Marcos Paulo de Souza <mpdesouza@suse.com> writes:
>
> > The register_console_force function was introduced to register
> > consoles
> > even on the presence of default consoles, replacing the CON_ENABLE
> > flag
> > that was forcing the same behavior.
> >
> > No functional changes.
> >
> > Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
>
> Acked-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Thanks Alexander!
>
> Should I pick this up or will you send this with the rest of the
> series?
I'll need a v2, since some things will also change in other parts of
the patchset, so I would wait for the next version.
>
> Cheers,
> --
> Alex
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 01/19] printk/nbcon: Use an enum to specify the required callback in console_is_usable()
2026-01-13 16:25 ` Petr Mladek
@ 2026-01-30 15:31 ` John Ogness
0 siblings, 0 replies; 50+ messages in thread
From: John Ogness @ 2026-01-30 15:31 UTC (permalink / raw)
To: Petr Mladek, Marcos Paulo de Souza
Cc: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Steven Rostedt, Sergey Senozhatsky, Jiri Slaby,
Breno Leitao, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven, Kees Cook,
Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, Laurentiu Tudor,
linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel
On 2026-01-13, Petr Mladek <pmladek@suse.com> wrote:
> On Sat 2025-12-27 09:16:08, Marcos Paulo de Souza wrote:
>> The current usage of console_is_usable() is clumsy. The parameter
>> @use_atomic is boolean and thus not self-explanatory. The function is
>> called twice in situations when there are no-strict requirements.
>>
>> Replace it with enum nbcon_write_cb which provides a more descriptive
>> values for all 3 situations: atomic, thread or any.
>>
>> Note that console_is_usable() checks only NBCON_USE_ATOMIC because
>> .write_thread() callback is mandatory. But the other two values still
>> make sense because they describe the intention of the caller.
>>
>> --- a/include/linux/console.h
>> +++ b/include/linux/console.h
>> @@ -202,6 +202,19 @@ enum cons_flags {
>> CON_NBCON_ATOMIC_UNSAFE = BIT(9),
>> };
>>
>> +/**
>> + * enum nbcon_write_cb - Defines which nbcon write() callback must be used based
>> + * on the caller context.
>> + * @NBCON_USE_ATOMIC: Use con->write_atomic().
>> + * @NBCON_USE_THREAD: Use con->write_thread().
>> + * @NBCON_USE_ANY: The caller does not have any strict requirements.
>> + */
>> +enum nbcon_write_cb {
>> + NBCON_USE_ATOMIC,
>> + NBCON_USE_THREAD,
>> + NBCON_USE_ANY,
>
> AFAIK, this would define NBCON_USE_ATOMIC as zero. See below.
Yes, although the start value is not guaranteed. And anyway if is to be
used as bits, it should be explicitly set so (such as with enum
cons_flags).
But in reality, we only care about NBCON_USE_ATOMIC and
!NBCON_USE_ATOMIC, so I agree with your comments below about keeping it
a simple enum and not caring about the numerical value.
>> @@ -631,7 +645,7 @@ static inline bool console_is_usable(struct console *con, short flags, bool use_
>> return false;
>>
>> if (flags & CON_NBCON) {
>> - if (use_atomic) {
>> + if (nwc & NBCON_USE_ATOMIC) {
>
> Let's keep it defined by as zero and use here:
>
> if (nwc == NBCON_USE_ATOMIC) {
>
> Note that we do _not_ want to return "false" for "NBCON_USE_ANY"
> when con->write_atomic does not exist.
I agree.
If changed to "nwc == NBCON_USE_ATOMIC":
Reviewed-by: John Ogness <john.ogness@linutronix.de>
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 02/19] printk: Introduce console_is_nbcon
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
1 sibling, 0 replies; 50+ messages in thread
From: John Ogness @ 2026-01-30 15:50 UTC (permalink / raw)
To: Marcos Paulo de Souza, Richard Weinberger, Anton Ivanov,
Johannes Berg, Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
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
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 05/19] printk: Add more context to suspend/resume functions
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
1 sibling, 0 replies; 50+ messages in thread
From: John Ogness @ 2026-01-30 17:27 UTC (permalink / raw)
To: Marcos Paulo de Souza, Richard Weinberger, Anton Ivanov,
Johannes Berg, Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, Sergey Senozhatsky,
Jiri Slaby, Breno Leitao, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Geert Uytterhoeven,
Kees Cook, Tony Luck, Guilherme G. Piccoli, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Andreas Larsson, Alexander Shishkin, Maxime Coquelin,
Alexandre Torgue, Jacky Huang, Shan-Chun Hung, Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel,
Marcos Paulo de Souza
On 2025-12-27, Marcos Paulo de Souza <mpdesouza@suse.com> wrote:
> The new comments clarifies from where the functions are supposed to be
> called.
>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
> ---
> kernel/printk/printk.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 173c14e08afe..85a8b6521d9e 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -2734,7 +2734,8 @@ MODULE_PARM_DESC(console_no_auto_verbose, "Disable console loglevel raise to hig
> /**
> * console_suspend_all - suspend the console subsystem
> *
> - * This disables printk() while we go into suspend states
> + * This disables printk() while we go into suspend states. Called by the power
> + * management subsystem.
Since you are touching this comment, I would prefer to make it
technically accurate. It is not printk() that is disabled, it is console
printing that is disabled. Perhaps something like:
* Block all console printing while the system goes into suspend state.
* Called by the power management subsystem.
> */
> void console_suspend_all(void)
> {
> @@ -2766,6 +2767,12 @@ void console_suspend_all(void)
> synchronize_srcu(&console_srcu);
> }
>
> +/**
> + * console_resume_all - resume the console subsystem
> + *
> + * This resumes printk() when the system is being restored. Called by the power
> + * management subsystem.
And something similar here:
* Allow all console printing when the system resumes from suspend. Called by
* the power management system.
> + */
> void console_resume_all(void)
> {
> struct console_flush_type ft;
John Ogness
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH 00/19] printk cleanup - part 3
2025-12-27 12:16 [PATCH 00/19] printk cleanup - part 3 Marcos Paulo de Souza
` (20 preceding siblings ...)
2026-01-07 10:22 ` Andreas Larsson
@ 2026-02-20 11:43 ` Marcos Paulo de Souza
21 siblings, 0 replies; 50+ messages in thread
From: Marcos Paulo de Souza @ 2026-02-20 11:43 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg,
Greg Kroah-Hartman, Jason Wessel, Daniel Thompson,
Douglas Anderson, Petr Mladek, Steven Rostedt, John Ogness,
Sergey Senozhatsky, Jiri Slaby, Breno Leitao, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Geert Uytterhoeven, Kees Cook, Tony Luck, Guilherme G. Piccoli,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Andreas Larsson, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Jacky Huang, Shan-Chun Hung,
Laurentiu Tudor
Cc: linux-um, linux-kernel, kgdb-bugreport, linux-serial, netdev,
linux-m68k, linux-hardening, linuxppc-dev, sparclinux,
linux-stm32, linux-arm-kernel, linux-fsdevel
On Sat, 2025-12-27 at 09:16 -0300, Marcos Paulo de Souza wrote:
> The parts 1 and 2 can be found here [1] and here[2].
>
> The changes proposed in this part 3 are mostly to clarify the usage
> of
> the interfaces for NBCON, and use the printk helpers more broadly.
> Besides it, it also introduces a new way to register consoles
> and drop thes the CON_ENABLED flag. It seems too much, but in reality
> the changes are not complex, and as the title says, it's basically a
> cleanup without changing the functional changes.
>
> This patchset includes a patch from part 2 that needed more work [3],
> as
> suggested by Petr Mladek.
>
> These changes were tested by reverting f79b163c4231
> ("Revert "serial: 8250: Switch to nbcon console""), and used qemu to
> test
> suspend/resume cycles, and everything worked as expected.
>
> PS: b4 --auto-to-cc added a bunch of people as CC, so I'm not sure if
> I should remove some or not, so I'm leaving the list as it is. If the
> patchset needs a v2, and you feel that you don't need to copied, just
> let me know.
>
> Thanks for checking the patches, and happy holidays!
>
> [1]:
> https://lore.kernel.org/lkml/20250226-printk-renaming-v1-0-0b878577f2e6@suse.com/#t
> [2]:
> https://lore.kernel.org/linux-serial/20251121-printk-cleanup-part2-v2-0-57b8b78647f4@suse.com/
> [3]:
> https://lore.kernel.org/linux-serial/aSgeqM3DWvR8-cMY@pathway.suse.cz/
>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
> ---
> Marcos Paulo de Souza (19):
> printk/nbcon: Use an enum to specify the required callback in
> console_is_usable()
> printk: Introduce console_is_nbcon
> printk: Drop flags argument from console_is_usable
> printk: Reintroduce consoles_suspended global state
> printk: Add more context to suspend/resume functions
> printk: Introduce register_console_force
> drivers: netconsole: Migrate to register_console_force helper
> debug: debug_core: Migrate to register_console_force helper
> m68k: emu: nfcon.c: Migrate to register_console_force helper
> fs: pstore: platform: Migrate to register_console_force helper
> powerpc: kernel: udbg: Migrate to register_console_force helper
> sparc: kernel: btext: Migrate to register_console_force helper
> um: drivers: mconsole_kern.c: Migrate to register_console_force
> helper
> drivers: hwtracing: stm: console.c: Migrate to
> register_console_force helper
> drivers: tty: serial: mux.c: Migrate to register_console_force
> helper
> drivers: tty: serial: ma35d1_serial: Migrate to
> register_console_force helper
> drivers: tty: ehv_bytechan: Migrate to register_console_force
> helper
> drivers: braille: console: Drop CON_ENABLED console flag
> printk: Remove CON_ENABLED flag
>
> arch/m68k/emu/nfcon.c | 5 +-
> arch/powerpc/kernel/udbg.c | 4 +-
> arch/sparc/kernel/btext.c | 4 +-
> arch/um/drivers/mconsole_kern.c | 3 +-
> arch/um/kernel/kmsg_dump.c | 2 +-
> drivers/accessibility/braille/braille_console.c | 1 -
> drivers/hwtracing/stm/console.c | 4 +-
> drivers/net/netconsole.c | 13 +--
> drivers/tty/ehv_bytechan.c | 4 +-
> drivers/tty/serial/ma35d1_serial.c | 4 +-
> drivers/tty/serial/mux.c | 4 +-
> drivers/tty/tty_io.c | 6 +-
> fs/proc/consoles.c | 1 -
> fs/pstore/platform.c | 6 +-
> include/linux/console.h | 143
> +++++++++++++++++++-----
> kernel/debug/debug_core.c | 6 +-
> kernel/debug/kdb/kdb_io.c | 6 +-
> kernel/printk/nbcon.c | 17 +--
> kernel/printk/printk.c | 140 ++++++++++++--
> ---------
> 19 files changed, 230 insertions(+), 143 deletions(-)
This patchset, without the recent cleanup from Petr Mladek [1], has a
regression. I'll wait for it to be merged first before sending a new
version of this patchset. Thanks for all the reviews!
[1]:
https://lore.kernel.org/lkml/20260206165002.496724-1-pmladek@suse.com/
> ---
> base-commit: 93d65587479cfc97c0d7e41b5e8c6378ca681632
> change-id: 20251202-printk-cleanup-part3-ea116b11b3a6
>
> Best regards,
> --
> Marcos Paulo de Souza <mpdesouza@suse.com>
^ permalink raw reply [flat|nested] 50+ messages in thread
end of thread, other threads:[~2026-02-20 11:43 UTC | newest]
Thread overview: 50+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox