Skip to content

Commit eb7f1ed

Browse files
jognesspmladek
authored andcommitted
printk: __pr_flush: use srcu console list iterator
Use srcu console list iteration for console list traversal. Document why the console_lock is still necessary. Note that this is a preparatory change for when console_lock no longer provides synchronization for the console list. 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-17-john.ogness@linutronix.de
1 parent fc956ae commit eb7f1ed

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

kernel/printk/printk.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3561,6 +3561,7 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
35613561
struct console *c;
35623562
u64 last_diff = 0;
35633563
u64 printk_seq;
3564+
int cookie;
35643565
u64 diff;
35653566
u64 seq;
35663567

@@ -3571,9 +3572,15 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
35713572
for (;;) {
35723573
diff = 0;
35733574

3575+
/*
3576+
* Hold the console_lock to guarantee safe access to
3577+
* console->seq and to prevent changes to @console_suspended
3578+
* until all consoles have been processed.
3579+
*/
35743580
console_lock();
35753581

3576-
for_each_console(c) {
3582+
cookie = console_srcu_read_lock();
3583+
for_each_console_srcu(c) {
35773584
if (con && con != c)
35783585
continue;
35793586
if (!console_is_usable(c))
@@ -3582,6 +3589,7 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
35823589
if (printk_seq < seq)
35833590
diff += seq - printk_seq;
35843591
}
3592+
console_srcu_read_unlock(cookie);
35853593

35863594
/*
35873595
* If consoles are suspended, it cannot be expected that they

0 commit comments

Comments
 (0)