Commit 16c9a316 authored by Petr Mladek's avatar Petr Mladek Committed by Greg Kroah-Hartman
Browse files

printk: Wake klogd when passing console_lock owner

[ Upstream commit c14376de ]

wake_klogd is a local variable in console_unlock(). The information
is lost when the console_lock owner using the busy wait added by
the commit dbdda842 ("printk: Add console owner and waiter
logic to load balance console writes"). The following race is

CPU0				CPU1

  for (;;)
     /* calling console for last message */


     /* see new message */
     if (seen_seq != log_next_seq) {
	wake_klogd = true;
	seen_seq = log_next_seq;


				  if (console_trylock_spinning())
				     /* spinning */

     if (console_lock_spinning_disable_and_check()) {

				    if (seen_seq != log_next_seq) {
				    /* already seen */
				    /* nothing to do */

Result: Nobody would wakeup klogd.

One solution would be to make a global variable from wake_klogd.
But then we would need to manipulate it under a lock or so.

This patch wakes klogd also when console_lock is passed to the
spinning waiter. It looks like the right way to go. Also userspace
should have a chance to see and store any "flood" of messages.

Note that the very late klogd wake up was a historic solution.
It made sense on single CPU systems or when sys_syslog() operations
were synchronized using the big kernel lock like in v2.1.113.
But it is questionable these days.

Fixes: dbdda842 ("printk: Add console owner and waiter logic to load balance console writes")

Cc: Steven Rostedt <>
Cc: Tejun Heo <>
Suggested-by: default avatarSergey Senozhatsky <>
Reviewed-by: default avatarSergey Senozhatsky <>
Signed-off-by: default avatarPetr Mladek <>
Signed-off-by: default avatarSasha Levin <>
parent 08b7a8f8
...@@ -2393,7 +2393,7 @@ void console_unlock(void) ...@@ -2393,7 +2393,7 @@ void console_unlock(void)
if (console_lock_spinning_disable_and_check()) { if (console_lock_spinning_disable_and_check()) {
printk_safe_exit_irqrestore(flags); printk_safe_exit_irqrestore(flags);
return; goto out;
} }
printk_safe_exit_irqrestore(flags); printk_safe_exit_irqrestore(flags);
...@@ -2426,6 +2426,7 @@ void console_unlock(void) ...@@ -2426,6 +2426,7 @@ void console_unlock(void)
if (retry && console_trylock()) if (retry && console_trylock())
goto again; goto again;
if (wake_klogd) if (wake_klogd)
wake_up_klogd(); wake_up_klogd();
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment