Skip to content

Commit fb9fabf

Browse files
jognesspmladek
authored andcommitted
printk: nbcon: Init @nbcon_seq to highest possible
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 <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
1 parent 6cb58cf commit fb9fabf

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

kernel/printk/nbcon.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,13 @@ bool nbcon_alloc(struct console *con)
13971397
struct nbcon_state state = { };
13981398

13991399
nbcon_state_set(con, &state);
1400-
atomic_long_set(&ACCESS_PRIVATE(con, nbcon_seq), 0);
1400+
1401+
/*
1402+
* Initialize @nbcon_seq to the highest possible sequence number so
1403+
* that practically speaking it will have nothing to print until a
1404+
* desired initial sequence number has been set via nbcon_seq_force().
1405+
*/
1406+
atomic_long_set(&ACCESS_PRIVATE(con, nbcon_seq), ULSEQ_MAX(prb));
14011407

14021408
if (con->flags & CON_BOOT) {
14031409
/*

kernel/printk/printk_ringbuffer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,12 @@ u64 prb_next_reserve_seq(struct printk_ringbuffer *rb);
404404

405405
#define __u64seq_to_ulseq(u64seq) (u64seq)
406406
#define __ulseq_to_u64seq(rb, ulseq) (ulseq)
407+
#define ULSEQ_MAX(rb) (-1)
407408

408409
#else /* CONFIG_64BIT */
409410

410411
#define __u64seq_to_ulseq(u64seq) ((u32)u64seq)
412+
#define ULSEQ_MAX(rb) __u64seq_to_ulseq(prb_first_seq(rb) + 0x80000000UL)
411413

412414
static inline u64 __ulseq_to_u64seq(struct printk_ringbuffer *rb, u32 ulseq)
413415
{

0 commit comments

Comments
 (0)