Commit fd5f7cde authored by Sergey Senozhatsky's avatar Sergey Senozhatsky Committed by Petr Mladek
Browse files

printk: Never set console_may_schedule in console_trylock()

This patch, basically, reverts commit 6b97a20d ("printk:
set may_schedule for some of console_trylock() callers").
That commit was a mistake, it introduced a big dependency
on the scheduler, by enabling preemption under console_sem
in printk()->console_unlock() path, which is rather too
critical. The patch did not significantly reduce the
possibilities of printk() lockups, but made it possible to
stall printk(), as has been reported by Tetsuo Handa [1].

Another issues is that preemption under console_sem also
messes up with Steven Rostedt's hand off scheme, by making
it possible to sleep with console_sem both in console_unlock()
and in vprintk_emit(), after acquiring the console_sem
ownership (anywhere between printk_safe_exit_irqrestore() in
console_trylock_spinning() and printk_safe_enter_irqsave()
in console_unlock()). This makes hand off less likely and,
at the same time, may result in a significant amount of
pending logbuf messages. Preempted console_sem owner makes
it impossible for other CPUs to emit logbuf messages, but
does not make it impossible for other CPUs to append new
messages to the logbuf.

Reinstate the old behavior and make printk() non-preemptible.
Should any printk() lockup reports arrive they must be handled
in a different way.

Fixes: 6b97a20d ("printk: set may_schedule for some of console_trylock() callers")

To: Tetsuo Handa <>
Cc: Sergey Senozhatsky <>
Cc: Tejun Heo <>
Cc: Cong Wang <>
Cc: Dave Hansen <>
Cc: Johannes Weiner <>
Cc: Mel Gorman <>
Cc: Michal Hocko <>
Cc: Vlastimil Babka <>
Cc: Peter Zijlstra <>
Cc: Linus Torvalds <>
Cc: Jan Kara <>
Cc: Mathieu Desnoyers <>
Cc: Byungchul Park <>
Cc: Pavel Machek <>
Signed-off-by: default avatarSergey Senozhatsky <>
Reported-by: default avatarTetsuo Handa <>
Reviewed-by: default avatarSteven Rostedt (VMware) <>
Signed-off-by: default avatarPetr Mladek <>
parent c162d5b4
......@@ -1888,6 +1888,12 @@ asmlinkage int vprintk_emit(int facility, int level,
/* If called from the scheduler, we can not call up(). */
if (!in_sched) {
* Disable preemption to avoid being preempted while holding
* console_sem which would prevent anyone from printing to
* console
* Try to acquire and then immediately release the console
* semaphore. The release will print out buffers and wake up
......@@ -1895,6 +1901,7 @@ asmlinkage int vprintk_emit(int facility, int level,
if (console_trylock_spinning())
return printed_len;
......@@ -2211,20 +2218,7 @@ int console_trylock(void)
return 0;
console_locked = 1;
* When PREEMPT_COUNT disabled we can't reliably detect if it's
* safe to schedule (e.g. calling printk while holding a spin_lock),
* because preempt_disable()/preempt_enable() are just barriers there
* and preempt_count() is always 0.
* RCU read sections have a separate preemption counter when
* PREEMPT_RCU enabled thus we must take extra care and check
* rcu_preempt_depth(), otherwise RCU read sections modify
* preempt_count().
console_may_schedule = !oops_in_progress &&
preemptible() &&
console_may_schedule = 0;
return 1;
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