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 v6 02/30] printk: Properly deal with nbcon consoles on seq init
Date: Mon, 27 May 2024 08:43:21 +0206 [thread overview]
Message-ID: <20240527063749.391035-3-john.ogness@linutronix.de> (raw)
In-Reply-To: <20240527063749.391035-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_init(), for legacy consoles
set con->seq.
The cleaned design should make sure that the value stays and is
set before the printing kthread is created.
Signed-off-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: John Ogness <john.ogness@linutronix.de>
---
kernel/printk/internal.h | 4 ++--
kernel/printk/nbcon.c | 10 +++-------
kernel/printk/printk.c | 41 ++++++++++++++++++++++++++++------------
3 files changed, 34 insertions(+), 21 deletions(-)
diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h
index 6c2afee5ef62..739b82adc383 100644
--- a/kernel/printk/internal.h
+++ b/kernel/printk/internal.h
@@ -75,7 +75,7 @@ u16 printk_parse_prefix(const char *text, int *level,
u64 nbcon_seq_read(struct console *con);
void nbcon_seq_force(struct console *con, u64 seq);
bool nbcon_alloc(struct console *con);
-void nbcon_init(struct console *con);
+void nbcon_init(struct console *con, u64 init_seq);
void nbcon_free(struct console *con);
#else
@@ -96,7 +96,7 @@ static inline bool printk_percpu_data_ready(void) { return false; }
static inline u64 nbcon_seq_read(struct console *con) { return 0; }
static inline void nbcon_seq_force(struct console *con, u64 seq) { }
static inline bool nbcon_alloc(struct console *con) { return false; }
-static inline void nbcon_init(struct console *con) { }
+static inline void nbcon_init(struct console *con, u64 init_seq) { }
static inline void nbcon_free(struct console *con) { }
#endif /* CONFIG_PRINTK */
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index c8093bcc01fe..de260531b0da 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;
}
/**
@@ -961,20 +958,19 @@ bool nbcon_alloc(struct console *con)
/**
* nbcon_init - Initialize the nbcon console specific data
* @con: Console to initialize
+ * @init_seq: Sequence number of the first record to be emitted
*
* nbcon_alloc() *must* be called and succeed before this function
* is called.
- *
- * This function expects that the legacy @con->seq has been set.
*/
-void nbcon_init(struct console *con)
+void nbcon_init(struct console *con, u64 init_seq)
{
struct nbcon_state state = { };
/* nbcon_alloc() must have been called and successful! */
BUG_ON(!con->pbufs);
- nbcon_seq_force(con, con->seq);
+ nbcon_seq_force(con, init_seq);
nbcon_state_set(con, &state);
}
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 6efb629fd976..4480ad2f198e 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -3348,19 +3348,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
@@ -3381,7 +3383,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.
@@ -3394,19 +3396,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() \
@@ -3438,6 +3451,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();
@@ -3515,10 +3529,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_init(newcon);
+ if (newcon->flags & CON_NBCON) {
+ nbcon_init(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-05-27 6:38 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-27 6:37 [PATCH printk v6 00/30] wire up write_atomic() printing John Ogness
2024-05-27 6:37 ` [PATCH printk v6 01/30] printk: Add notation to console_srcu locking John Ogness
2024-05-27 6:37 ` John Ogness [this message]
2024-05-27 6:37 ` [PATCH printk v6 03/30] printk: nbcon: Remove return value for write_atomic() John Ogness
2024-05-27 6:37 ` [PATCH printk v6 04/30] printk: Check printk_deferred_enter()/_exit() usage John Ogness
2024-05-27 6:37 ` [PATCH printk v6 05/30] printk: nbcon: Add detailed doc for write_atomic() John Ogness
2024-05-27 6:37 ` [PATCH printk v6 06/30] printk: nbcon: Add callbacks to synchronize with driver John Ogness
2024-05-27 6:37 ` [PATCH printk v6 07/30] printk: nbcon: Use driver synchronization while (un)registering John Ogness
2024-05-27 6:37 ` [PATCH printk v6 08/30] serial: core: Provide low-level functions to lock port John Ogness
2024-05-27 6:37 ` [PATCH printk v6 09/30] serial: core: Introduce wrapper to set @uart_port->cons John Ogness
2024-05-27 6:37 ` [PATCH printk v6 10/30] console: Improve console_srcu_read_flags() comments John Ogness
2024-05-27 6:37 ` [PATCH printk v6 11/30] nbcon: Add API to acquire context for non-printing operations John Ogness
2024-05-27 6:37 ` [PATCH printk v6 12/30] serial: core: Implement processing in port->lock wrapper John Ogness
2024-05-27 6:37 ` [PATCH printk v6 13/30] printk: nbcon: Do not rely on proxy headers John Ogness
2024-05-27 6:37 ` [PATCH printk v6 14/30] printk: nbcon: Fix kerneldoc for enums John Ogness
2024-05-27 6:37 ` [PATCH printk v6 15/30] printk: Make console_is_usable() available to nbcon John Ogness
2024-05-27 6:37 ` [PATCH printk v6 16/30] printk: Let console_is_usable() handle nbcon John Ogness
2024-05-27 6:37 ` [PATCH printk v6 17/30] printk: Add @flags argument for console_is_usable() John Ogness
2024-05-27 6:37 ` [PATCH printk v6 18/30] printk: nbcon: Add helper to assign priority based on CPU state John Ogness
2024-05-27 6:37 ` [PATCH printk v6 19/30] printk: nbcon: Provide function to flush using write_atomic() John Ogness
2024-05-28 9:30 ` Petr Mladek
2024-05-27 6:37 ` [PATCH printk v6 20/30] printk: Track registered boot consoles John Ogness
2024-05-27 6:37 ` [PATCH printk v6 21/30] printk: nbcon: Use nbcon consoles in console_flush_all() John Ogness
2024-05-27 6:37 ` [PATCH printk v6 22/30] printk: nbcon: Add unsafe flushing on panic John Ogness
2024-05-27 6:37 ` [PATCH printk v6 23/30] printk: Avoid console_lock dance if no legacy or boot consoles John Ogness
2024-05-27 6:37 ` [PATCH printk v6 24/30] printk: Track nbcon consoles John Ogness
2024-05-27 6:37 ` [PATCH printk v6 25/30] printk: Coordinate direct printing in panic John Ogness
2024-05-27 6:37 ` [PATCH printk v6 26/30] printk: nbcon: Implement emergency sections John Ogness
2024-05-28 9:57 ` Petr Mladek
2024-05-27 6:37 ` [PATCH printk v6 27/30] panic: Mark emergency section in warn John Ogness
2024-05-27 6:37 ` [PATCH printk v6 28/30] panic: Mark emergency section in oops John Ogness
2024-05-27 6:37 ` [PATCH printk v6 29/30] rcu: Mark emergency sections in rcu stalls John Ogness
2024-05-28 10:04 ` Petr Mladek
2024-05-27 6:37 ` [PATCH printk v6 30/30] lockdep: Mark emergency sections in lockdep splats John Ogness
2024-05-28 10:10 ` [PATCH printk v6 00/30] wire up write_atomic() printing Petr Mladek
2024-05-28 13:35 ` Petr Mladek
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=20240527063749.391035-3-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®