]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
printk: nbcon: Init @nbcon_seq to highest possible
authorJohn Ogness <john.ogness@linutronix.de>
Wed, 4 Sep 2024 12:05:24 +0000 (14:11 +0206)
committerPetr Mladek <pmladek@suse.com>
Wed, 4 Sep 2024 13:56:32 +0000 (15:56 +0200)
When initializing an nbcon console, have nbcon_alloc() set
@nbcon_seq to the highest possible sequence number. For all
practical purposes, this will guarantee that the console
will have nothing to print until later when @nbcon_seq is
set to the proper initial printing value.

This will be particularly important once kthread printing is
introduced because nbcon_alloc() can create/start the kthread
before the desired initial sequence number is known.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20240904120536.115780-6-john.ogness@linutronix.de
Signed-off-by: Petr Mladek <pmladek@suse.com>
kernel/printk/nbcon.c
kernel/printk/printk_ringbuffer.h

index 88db24f9a8de40f897e2dc3b4f822521bd4f716e..bc684ff5028a3e1e42a6544aec0c7e4e6a64d5db 100644 (file)
@@ -1397,7 +1397,13 @@ bool nbcon_alloc(struct console *con)
        struct nbcon_state state = { };
 
        nbcon_state_set(con, &state);
-       atomic_long_set(&ACCESS_PRIVATE(con, nbcon_seq), 0);
+
+       /*
+        * Initialize @nbcon_seq to the highest possible sequence number so
+        * that practically speaking it will have nothing to print until a
+        * desired initial sequence number has been set via nbcon_seq_force().
+        */
+       atomic_long_set(&ACCESS_PRIVATE(con, nbcon_seq), ULSEQ_MAX(prb));
 
        if (con->flags & CON_BOOT) {
                /*
index 8de6c495cf2b7ffaf9250d479576deedcaf976fe..4ef81349d9fbe1e03e321e73685ae5c2837f46c6 100644 (file)
@@ -404,10 +404,12 @@ u64 prb_next_reserve_seq(struct printk_ringbuffer *rb);
 
 #define __u64seq_to_ulseq(u64seq) (u64seq)
 #define __ulseq_to_u64seq(rb, ulseq) (ulseq)
+#define ULSEQ_MAX(rb) (-1)
 
 #else /* CONFIG_64BIT */
 
 #define __u64seq_to_ulseq(u64seq) ((u32)u64seq)
+#define ULSEQ_MAX(rb) __u64seq_to_ulseq(prb_first_seq(rb) + 0x80000000UL)
 
 static inline u64 __ulseq_to_u64seq(struct printk_ringbuffer *rb, u32 ulseq)
 {