Skip to content

Commit 87f2e4b

Browse files
jognesspmladek
authored andcommitted
printk: console_flush_on_panic: use srcu console list iterator
With SRCU it is now safe to traverse the console list, even if the console_trylock() failed. However, overwriting console->seq when console_trylock() failed is still an issue. Switch to SRCU iteration and document remaining issue with console->seq. Signed-off-by: John Ogness <john.ogness@linutronix.de> Reviewed-by: Petr Mladek <pmladek@suse.com> Signed-off-by: Petr Mladek <pmladek@suse.com> Link: https://lore.kernel.org/r/20221116162152.193147-20-john.ogness@linutronix.de
1 parent d792db6 commit 87f2e4b

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

kernel/printk/printk.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3050,21 +3050,22 @@ void console_flush_on_panic(enum con_flush_mode mode)
30503050
console_may_schedule = 0;
30513051

30523052
if (mode == CONSOLE_REPLAY_ALL) {
3053-
struct hlist_node *tmp;
30543053
struct console *c;
3054+
int cookie;
30553055
u64 seq;
30563056

30573057
seq = prb_first_valid_seq(prb);
3058-
/*
3059-
* This cannot use for_each_console() because it's not established
3060-
* that the current context has console locked and neither there is
3061-
* a guarantee that there is no concurrency in that case.
3062-
*
3063-
* Open code it for documentation purposes and pretend that
3064-
* it works.
3065-
*/
3066-
hlist_for_each_entry_safe(c, tmp, &console_list, node)
3058+
3059+
cookie = console_srcu_read_lock();
3060+
for_each_console_srcu(c) {
3061+
/*
3062+
* If the above console_trylock() failed, this is an
3063+
* unsynchronized assignment. But in that case, the
3064+
* kernel is in "hope and pray" mode anyway.
3065+
*/
30673066
c->seq = seq;
3067+
}
3068+
console_srcu_read_unlock(cookie);
30683069
}
30693070
console_unlock();
30703071
}

0 commit comments

Comments
 (0)