Skip to content

Commit

Permalink
Fix locking bug in "acquire_console_semaphore_for_printk()"
Browse files Browse the repository at this point in the history
When I cleaned up printk() and split up the printk locking logic in
commit 266c2e0 ("Make printk() console
semaphore accesses sensible") I had incorrectly moved the call to
have_callable_console() outside of the console semaphore.

That was buggy.  The console semaphore protects the console_drivers list
that is used by have_callable_console().

Thanks go to Bongani Hlope who saw this as a hang on shutdown and reboot
and bisected the bug to the right commit, and tested this patch. See

	http://lkml.org/lkml/2008/4/11/315

Bisected-and-tested-by: Bongani Hlope <bonganilinux@mweb.co.za>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Linus Torvalds committed Apr 15, 2008
1 parent 0de19a4 commit 093a07e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions kernel/printk.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,21 @@ static int acquire_console_semaphore_for_printk(unsigned int cpu)
{
int retval = 0;

if (can_use_console(cpu))
retval = !try_acquire_console_sem();
if (!try_acquire_console_sem()) {
retval = 1;

/*
* If we can't use the console, we need to release
* the console semaphore by hand to avoid flushing
* the buffer. We need to hold the console semaphore
* in order to do this test safely.
*/
if (!can_use_console(cpu)) {
console_locked = 0;
up(&console_sem);
retval = 0;
}
}
printk_cpu = UINT_MAX;
spin_unlock(&logbuf_lock);
return retval;
Expand Down

0 comments on commit 093a07e

Please sign in to comment.