From: John Ogness <john.ogness@linutronix.de>
To: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org
Subject: [PATCH printk v7 03/35] printk: Properly deal with nbcon consoles on seq init
Date: Sun, 4 Aug 2024 02:57:06 +0206 [thread overview]
Message-ID: <20240804005138.3722656-4-john.ogness@linutronix.de> (raw)
In-Reply-To: <20240804005138.3722656-1-john.ogness@linutronix.de>
From: Petr Mladek <pmladek@suse.com>
If a non-boot console is registering and boot consoles exist,
the consoles are flushed before being unregistered. This allows
the non-boot console to continue where the boot console left
off.
If for whatever reason flushing fails, the lowest seq found from
any of the enabled boot consoles is used. Until now con->seq was
checked. However, if it is an nbcon boot console, the function
nbcon_seq_read() must be used to read seq because con->seq is
not updated for nbcon consoles.
Check if it is an nbcon boot console and if so call
nbcon_seq_read() to read seq.
Also, avoid usage of con->seq as temporary storage of the
starting record. Instead, rename console_init_seq() to
get_init_console_seq() and just return the value. For nbcon
consoles set the sequence via nbcon_seq_force(), for legacy
consoles set con->seq.
The cleaned design should make sure that the value stays and is
set before the console is added to the console list. It also
unifies the sequence number initialization for legacy and nbcon
consoles.
Signed-off-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: John Ogness <john.ogness@linutronix.de>
---
kernel/printk/nbcon.c | 3 ---
kernel/printk/printk.c | 41 +++++++++++++++++++++++++++++------------
2 files changed, 29 insertions(+), 15 deletions(-)
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index 670692dc9b10..776746d20fc0 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -172,9 +172,6 @@ void nbcon_seq_force(struct console *con, u64 seq)
u64 valid_seq = max_t(u64, seq, prb_first_valid_seq(prb));
atomic_long_set(&ACCESS_PRIVATE(con, nbcon_seq), __u64seq_to_ulseq(valid_seq));
-
- /* Clear con->seq since nbcon consoles use con->nbcon_seq instead. */
- con->seq = 0;
}
/**
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 15c61c9ea87e..6ac333938ffc 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -3448,19 +3448,21 @@ static void try_enable_default_console(struct console *newcon)
newcon->flags |= CON_CONSDEV;
}
-static void console_init_seq(struct console *newcon, bool bootcon_registered)
+/* Return the starting sequence number for a newly registered console. */
+static u64 get_init_console_seq(struct console *newcon, bool bootcon_registered)
{
struct console *con;
bool handover;
+ u64 init_seq;
if (newcon->flags & (CON_PRINTBUFFER | CON_BOOT)) {
/* Get a consistent copy of @syslog_seq. */
mutex_lock(&syslog_lock);
- newcon->seq = syslog_seq;
+ init_seq = syslog_seq;
mutex_unlock(&syslog_lock);
} else {
/* Begin with next message added to ringbuffer. */
- newcon->seq = prb_next_seq(prb);
+ init_seq = prb_next_seq(prb);
/*
* If any enabled boot consoles are due to be unregistered
@@ -3481,7 +3483,7 @@ static void console_init_seq(struct console *newcon, bool bootcon_registered)
* Flush all consoles and set the console to start at
* the next unprinted sequence number.
*/
- if (!console_flush_all(true, &newcon->seq, &handover)) {
+ if (!console_flush_all(true, &init_seq, &handover)) {
/*
* Flushing failed. Just choose the lowest
* sequence of the enabled boot consoles.
@@ -3494,19 +3496,30 @@ static void console_init_seq(struct console *newcon, bool bootcon_registered)
if (handover)
console_lock();
- newcon->seq = prb_next_seq(prb);
+ init_seq = prb_next_seq(prb);
for_each_console(con) {
- if ((con->flags & CON_BOOT) &&
- (con->flags & CON_ENABLED) &&
- con->seq < newcon->seq) {
- newcon->seq = con->seq;
+ u64 seq;
+
+ if (!(con->flags & CON_BOOT) ||
+ !(con->flags & CON_ENABLED)) {
+ continue;
}
+
+ if (con->flags & CON_NBCON)
+ seq = nbcon_seq_read(con);
+ else
+ seq = con->seq;
+
+ if (seq < init_seq)
+ init_seq = seq;
}
}
console_unlock();
}
}
+
+ return init_seq;
}
#define console_first() \
@@ -3538,6 +3551,7 @@ void register_console(struct console *newcon)
struct console *con;
bool bootcon_registered = false;
bool realcon_registered = false;
+ u64 init_seq;
int err;
console_list_lock();
@@ -3615,10 +3629,13 @@ void register_console(struct console *newcon)
}
newcon->dropped = 0;
- console_init_seq(newcon, bootcon_registered);
+ init_seq = get_init_console_seq(newcon, bootcon_registered);
- if (newcon->flags & CON_NBCON)
- nbcon_seq_force(newcon, newcon->seq);
+ if (newcon->flags & CON_NBCON) {
+ nbcon_seq_force(newcon, init_seq);
+ } else {
+ newcon->seq = init_seq;
+ }
/*
* Put this console in the list - keep the
--
2.39.2
next prev parent reply other threads:[~2024-08-04 0:51 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-04 0:51 [PATCH printk v7 00/35] wire up write_atomic() printing John Ogness
2024-08-04 0:51 ` [PATCH printk v7 01/35] printk: Add notation to console_srcu locking John Ogness
2024-08-04 0:51 ` [PATCH printk v7 02/35] printk: nbcon: Consolidate alloc() and init() John Ogness
2024-08-05 14:39 ` Petr Mladek
2024-08-04 0:51 ` John Ogness [this message]
2024-08-04 0:51 ` [PATCH printk v7 04/35] printk: Check printk_deferred_enter()/_exit() usage John Ogness
2024-08-04 0:51 ` [PATCH printk v7 05/35] printk: nbcon: Clarify rules of the owner/waiter matching John Ogness
2024-08-04 0:51 ` [PATCH printk v7 06/35] printk: nbcon: Remove return value for write_atomic() John Ogness
2024-08-04 0:51 ` [PATCH printk v7 07/35] printk: nbcon: Add detailed doc " John Ogness
2024-08-04 0:51 ` [PATCH printk v7 08/35] printk: nbcon: Add callbacks to synchronize with driver John Ogness
2024-08-04 0:51 ` [PATCH printk v7 09/35] printk: nbcon: Use driver synchronization while (un)registering John Ogness
2024-08-04 0:51 ` [PATCH printk v7 10/35] serial: core: Provide low-level functions to lock port John Ogness
2024-08-04 0:51 ` [PATCH printk v7 11/35] serial: core: Introduce wrapper to set @uart_port->cons John Ogness
2024-08-04 0:51 ` [PATCH printk v7 12/35] console: Improve console_srcu_read_flags() comments John Ogness
2024-08-04 0:51 ` [PATCH printk v7 13/35] nbcon: Add API to acquire context for non-printing operations John Ogness
2024-08-04 0:51 ` [PATCH printk v7 14/35] serial: core: Acquire nbcon context in port->lock wrapper John Ogness
2024-08-04 0:51 ` [PATCH printk v7 15/35] printk: nbcon: Do not rely on proxy headers John Ogness
2024-08-04 0:51 ` [PATCH printk v7 16/35] printk: Make console_is_usable() available to nbcon.c John Ogness
2024-08-04 0:51 ` [PATCH printk v7 17/35] printk: Let console_is_usable() handle nbcon John Ogness
2024-08-04 0:51 ` [PATCH printk v7 18/35] printk: Add @flags argument for console_is_usable() John Ogness
2024-08-04 0:51 ` [PATCH printk v7 19/35] printk: nbcon: Add helper to assign priority based on CPU state John Ogness
2024-08-04 0:51 ` [PATCH printk v7 20/35] printk: nbcon: Provide function to flush using write_atomic() John Ogness
2024-08-05 14:59 ` Petr Mladek
2024-08-04 0:51 ` [PATCH printk v7 21/35] printk: Track registered boot consoles John Ogness
2024-08-04 0:51 ` [PATCH printk v7 22/35] printk: nbcon: Use nbcon consoles in console_flush_all() John Ogness
2024-08-04 0:51 ` [PATCH printk v7 23/35] printk: Add is_printk_legacy_deferred() John Ogness
2024-08-05 15:03 ` Petr Mladek
2024-08-04 0:51 ` [PATCH printk v7 24/35] printk: nbcon: Flush new records on device_release() John Ogness
2024-08-05 15:31 ` Petr Mladek
2024-08-07 1:15 ` John Ogness
2024-08-07 12:48 ` Petr Mladek
2024-08-04 0:51 ` [PATCH printk v7 25/35] printk: Flush nbcon consoles first on panic John Ogness
2024-08-06 8:31 ` Petr Mladek
2024-08-04 0:51 ` [PATCH printk v7 26/35] printk: nbcon: Add unsafe flushing " John Ogness
2024-08-04 0:51 ` [PATCH printk v7 27/35] printk: Avoid console_lock dance if no legacy or boot consoles John Ogness
2024-08-06 8:40 ` Petr Mladek
2024-08-04 0:51 ` [PATCH printk v7 28/35] printk: Track nbcon consoles John Ogness
2024-08-04 0:51 ` [PATCH printk v7 29/35] printk: Coordinate direct printing in panic John Ogness
2024-08-06 9:59 ` Petr Mladek
2024-08-06 17:29 ` Linus Torvalds
2024-08-06 12:17 ` Petr Mladek
2024-08-04 0:51 ` [PATCH printk v7 30/35] printk: Add helper for flush type logic John Ogness
2024-08-07 11:39 ` Petr Mladek
2024-08-07 14:11 ` John Ogness
2024-08-08 9:03 ` Petr Mladek
2024-08-04 0:51 ` [PATCH printk v7 31/35] printk: nbcon: Implement emergency sections John Ogness
2024-08-07 12:52 ` Petr Mladek
2024-08-04 0:51 ` [PATCH printk v7 32/35] panic: Mark emergency section in warn John Ogness
2024-08-04 0:51 ` [PATCH printk v7 33/35] panic: Mark emergency section in oops John Ogness
2024-08-04 0:51 ` [PATCH printk v7 34/35] rcu: Mark emergency sections in rcu stalls John Ogness
2024-08-04 0:51 ` [PATCH printk v7 35/35] lockdep: Mark emergency sections in lockdep splats John Ogness
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240804005138.3722656-4-john.ogness@linutronix.de \
--to=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®