linux-um.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] printk cleanup - part 2
@ 2025-11-21 18:50 Marcos Paulo de Souza
  2025-11-21 18:50 ` [PATCH v2 1/4] drivers: serial: kgdboc: Drop checks for CON_ENABLED and CON_BOOT Marcos Paulo de Souza
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Marcos Paulo de Souza @ 2025-11-21 18:50 UTC (permalink / raw)
  To: Petr Mladek, Steven Rostedt, John Ogness, Sergey Senozhatsky,
	Greg Kroah-Hartman, Jiri Slaby, Jason Wessel, Daniel Thompson,
	Douglas Anderson, Richard Weinberger, Anton Ivanov, Johannes Berg
  Cc: linux-kernel, linux-serial, kgdb-bugreport, linux-um,
	Marcos Paulo de Souza

The first part can be found here[1]. The proposed changes do not
change the functionality of printk, but were suggestions made by
Petr Mladek. I already have more patches for a part 3 ,but I would like
to see these ones merged first.

I did the testing with VMs, checking suspend and resume cycles, and it worked
as expected.

Thanks for reviewing!

[1]: https://lore.kernel.org/lkml/20250226-printk-renaming-v1-0-0b878577f2e6@suse.com/

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
Changes in v2:
- Squashed patches 1 and 3 (CON_SUSPEND usage) and now is the last patch
  of the series, suggested by Petr Mladek
- Moved commit 4 as the first one in the series, and it was changed to
  use console_is_usable helper, suggested by Petr Mladek
- Moved commit 5 as the second commit in the series, and adjusted to use
  console_is_usable helper, suggested by Petr Mladek
- The patch 6 was dropped, since it was implemented in a different patchset
  (https://lore.kernel.org/lkml/20250902-nbcon-kgdboc-v3-0-cd30a8106f1c@suse.com/)
- Patch 7 was moved as third patch, and is using the console_is_usable,
  suggested by Petr Mladek
- Patch 2 was dropped from this patchset, and will be included in the
  next cleanup patchset.
- Link to v1: https://lore.kernel.org/r/20250606-printk-cleanup-part2-v1-0-f427c743dda0@suse.com

---
Marcos Paulo de Souza (4):
      drivers: serial: kgdboc: Drop checks for CON_ENABLED and CON_BOOT
      arch: um: kmsg_dump: Use console_is_usable
      printk: Use console_is_usable on console_unblank
      printk: Make console_{suspend,resume} handle CON_SUSPENDED

 arch/um/kernel/kmsg_dump.c  |  2 +-
 drivers/tty/serial/kgdboc.c |  1 -
 drivers/tty/tty_io.c        |  2 +-
 kernel/printk/printk.c      | 17 +++++++----------
 4 files changed, 9 insertions(+), 13 deletions(-)
---
base-commit: 887c7f05d40eb51ba3f38fd71d5e6b4aff4bb8a2
change-id: 20250601-printk-cleanup-part2-38f8d5108099

Best regards,
--  
Marcos Paulo de Souza <mpdesouza@suse.com>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/4] drivers: serial: kgdboc: Drop checks for CON_ENABLED and CON_BOOT
  2025-11-21 18:50 [PATCH v2 0/4] printk cleanup - part 2 Marcos Paulo de Souza
@ 2025-11-21 18:50 ` Marcos Paulo de Souza
  2025-11-21 18:50 ` [PATCH v2 2/4] arch: um: kmsg_dump: Use console_is_usable Marcos Paulo de Souza
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Marcos Paulo de Souza @ 2025-11-21 18:50 UTC (permalink / raw)
  To: Petr Mladek, Steven Rostedt, John Ogness, Sergey Senozhatsky,
	Greg Kroah-Hartman, Jiri Slaby, Jason Wessel, Daniel Thompson,
	Douglas Anderson, Richard Weinberger, Anton Ivanov, Johannes Berg
  Cc: linux-kernel, linux-serial, kgdb-bugreport, linux-um,
	Marcos Paulo de Souza

The original code tried to find a console that has CON_BOOT _or_
CON_ENABLED flag set. The flag CON_ENABLED is set to all registered
consoles, so in this case this check is always true, even for the
CON_BOOT consoles.

The initial intent of the kgdboc_earlycon_init was to get a console
early (CON_BOOT) or later on in the process (CON_ENABLED). The
code was using for_each_console macro, meaning that all console structs
were previously registered on the printk() machinery. At this point,
any console found on for_each_console is safe for kgdboc_earlycon_init
to use.

Dropping the check makes the code cleaner, and avoids further confusion
by future readers of the code.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
 drivers/tty/serial/kgdboc.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
index 85f6c5a76e0f..5a955c80a853 100644
--- a/drivers/tty/serial/kgdboc.c
+++ b/drivers/tty/serial/kgdboc.c
@@ -577,7 +577,6 @@ static int __init kgdboc_earlycon_init(char *opt)
 	console_list_lock();
 	for_each_console(con) {
 		if (con->write && con->read &&
-		    (con->flags & (CON_BOOT | CON_ENABLED)) &&
 		    (!opt || !opt[0] || strcmp(con->name, opt) == 0))
 			break;
 	}

-- 
2.51.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/4] arch: um: kmsg_dump: Use console_is_usable
  2025-11-21 18:50 [PATCH v2 0/4] printk cleanup - part 2 Marcos Paulo de Souza
  2025-11-21 18:50 ` [PATCH v2 1/4] drivers: serial: kgdboc: Drop checks for CON_ENABLED and CON_BOOT Marcos Paulo de Souza
@ 2025-11-21 18:50 ` Marcos Paulo de Souza
  2025-11-21 18:50 ` [PATCH v2 3/4] printk: Use console_is_usable on console_unblank Marcos Paulo de Souza
  2025-11-21 18:50 ` [PATCH v2 4/4] printk: Make console_{suspend,resume} handle CON_SUSPENDED Marcos Paulo de Souza
  3 siblings, 0 replies; 5+ messages in thread
From: Marcos Paulo de Souza @ 2025-11-21 18:50 UTC (permalink / raw)
  To: Petr Mladek, Steven Rostedt, John Ogness, Sergey Senozhatsky,
	Greg Kroah-Hartman, Jiri Slaby, Jason Wessel, Daniel Thompson,
	Douglas Anderson, Richard Weinberger, Anton Ivanov, Johannes Berg
  Cc: linux-kernel, linux-serial, kgdb-bugreport, linux-um,
	Marcos Paulo de Souza

All consoles found on for_each_console are registered, meaning that all
of them have the CON_ENABLED flag set. Since NBCON was introduced it's
important to check if a given console also implements the NBCON callbacks.
The function console_is_usable does exactly that.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
 arch/um/kernel/kmsg_dump.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/um/kernel/kmsg_dump.c b/arch/um/kernel/kmsg_dump.c
index 419021175272..fc0f543d1d8e 100644
--- a/arch/um/kernel/kmsg_dump.c
+++ b/arch/um/kernel/kmsg_dump.c
@@ -31,7 +31,7 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper,
 		 * expected to output the crash information.
 		 */
 		if (strcmp(con->name, "ttynull") != 0 &&
-		    (console_srcu_read_flags(con) & CON_ENABLED)) {
+		    console_is_usable(con, console_srcu_read_flags(con), true)) {
 			break;
 		}
 	}

-- 
2.51.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 3/4] printk: Use console_is_usable on console_unblank
  2025-11-21 18:50 [PATCH v2 0/4] printk cleanup - part 2 Marcos Paulo de Souza
  2025-11-21 18:50 ` [PATCH v2 1/4] drivers: serial: kgdboc: Drop checks for CON_ENABLED and CON_BOOT Marcos Paulo de Souza
  2025-11-21 18:50 ` [PATCH v2 2/4] arch: um: kmsg_dump: Use console_is_usable Marcos Paulo de Souza
@ 2025-11-21 18:50 ` Marcos Paulo de Souza
  2025-11-21 18:50 ` [PATCH v2 4/4] printk: Make console_{suspend,resume} handle CON_SUSPENDED Marcos Paulo de Souza
  3 siblings, 0 replies; 5+ messages in thread
From: Marcos Paulo de Souza @ 2025-11-21 18:50 UTC (permalink / raw)
  To: Petr Mladek, Steven Rostedt, John Ogness, Sergey Senozhatsky,
	Greg Kroah-Hartman, Jiri Slaby, Jason Wessel, Daniel Thompson,
	Douglas Anderson, Richard Weinberger, Anton Ivanov, Johannes Berg
  Cc: linux-kernel, linux-serial, kgdb-bugreport, linux-um,
	Marcos Paulo de Souza

The macro for_each_console_srcu iterates over all registered consoles. It's
implied that all registered consoles have CON_ENABLED flag set, making
the check for the flag unnecessary. Call console_is_usable function to
fully verify if the given console is usable before calling the ->unblank
callback.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
 kernel/printk/printk.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index cb79d1d2e6e5..fed98a18e830 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -3374,12 +3374,10 @@ void console_unblank(void)
 	 */
 	cookie = console_srcu_read_lock();
 	for_each_console_srcu(c) {
-		short flags = console_srcu_read_flags(c);
-
-		if (flags & CON_SUSPENDED)
+		if (!console_is_usable(c, console_srcu_read_flags(c), true))
 			continue;
 
-		if ((flags & CON_ENABLED) && c->unblank) {
+		if (c->unblank) {
 			found_unblank = true;
 			break;
 		}
@@ -3416,12 +3414,10 @@ void console_unblank(void)
 
 	cookie = console_srcu_read_lock();
 	for_each_console_srcu(c) {
-		short flags = console_srcu_read_flags(c);
-
-		if (flags & CON_SUSPENDED)
+		if (!console_is_usable(c, console_srcu_read_flags(c), true))
 			continue;
 
-		if ((flags & CON_ENABLED) && c->unblank)
+		if (c->unblank)
 			c->unblank();
 	}
 	console_srcu_read_unlock(cookie);

-- 
2.51.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 4/4] printk: Make console_{suspend,resume} handle CON_SUSPENDED
  2025-11-21 18:50 [PATCH v2 0/4] printk cleanup - part 2 Marcos Paulo de Souza
                   ` (2 preceding siblings ...)
  2025-11-21 18:50 ` [PATCH v2 3/4] printk: Use console_is_usable on console_unblank Marcos Paulo de Souza
@ 2025-11-21 18:50 ` Marcos Paulo de Souza
  3 siblings, 0 replies; 5+ messages in thread
From: Marcos Paulo de Souza @ 2025-11-21 18:50 UTC (permalink / raw)
  To: Petr Mladek, Steven Rostedt, John Ogness, Sergey Senozhatsky,
	Greg Kroah-Hartman, Jiri Slaby, Jason Wessel, Daniel Thompson,
	Douglas Anderson, Richard Weinberger, Anton Ivanov, Johannes Berg
  Cc: linux-kernel, linux-serial, kgdb-bugreport, linux-um,
	Marcos Paulo de Souza

Since commit 9e70a5e109a4 ("printk: Add per-console suspended state")
the CON_SUSPENDED flag was introced, and this flag was being checked
on console_is_usable function, which returns false if the console is
suspended.

To make the behavior consistent, change show_cons_active to look for
consoles that are not suspended, instead of checking CON_ENABLED.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
 drivers/tty/tty_io.c   | 2 +-
 kernel/printk/printk.c | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index e2d92cf70eb7..1b2ce0f36010 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -3554,7 +3554,7 @@ static ssize_t show_cons_active(struct device *dev,
 			continue;
 		if (!(c->flags & CON_NBCON) && !c->write)
 			continue;
-		if ((c->flags & CON_ENABLED) == 0)
+		if (c->flags & CON_SUSPENDED)
 			continue;
 		cs[i++] = c;
 		if (i >= ARRAY_SIZE(cs))
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index fed98a18e830..fe7c956f73bd 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -3542,7 +3542,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();
 
 	/*
@@ -3555,13 +3555,14 @@ void console_suspend(struct console *console)
 }
 EXPORT_SYMBOL(console_suspend);
 
+/* Unset CON_SUSPENDED flag so the console can start printing again. */
 void console_resume(struct console *console)
 {
 	struct console_flush_type ft;
 	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();
 

-- 
2.51.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-11-21 18:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-21 18:50 [PATCH v2 0/4] printk cleanup - part 2 Marcos Paulo de Souza
2025-11-21 18:50 ` [PATCH v2 1/4] drivers: serial: kgdboc: Drop checks for CON_ENABLED and CON_BOOT Marcos Paulo de Souza
2025-11-21 18:50 ` [PATCH v2 2/4] arch: um: kmsg_dump: Use console_is_usable Marcos Paulo de Souza
2025-11-21 18:50 ` [PATCH v2 3/4] printk: Use console_is_usable on console_unblank Marcos Paulo de Souza
2025-11-21 18:50 ` [PATCH v2 4/4] printk: Make console_{suspend,resume} handle CON_SUSPENDED 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;
as well as URLs for NNTP newsgroup(s).