diff options
author | Peter Zijlstra <a.p.zijlstra@chello.nl> | 2011-06-07 05:15:33 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2011-06-07 06:50:02 -0400 |
commit | 0b5e1c5255e7ee8670e077e8224e5c2281229a5b (patch) | |
tree | eb6f967b14d69553e380ab2f13a2dcd8789e865e /kernel/printk.c | |
parent | 59c5f46fbe01a00eedf54a23789634438bb80603 (diff) |
printk: Release console_sem after logbuf_lock
Release console_sem after unlocking the logbuf_lock so that we don't
generate wakeups while holding logbuf_lock. This avoids some lock
inversion troubles once we remove the lockdep_off bits between
logbuf_lock and rq->lock (prints while holding rq->lock vs doing
wakeups while holding logbuf_lock).
There's of course still an actual deadlock where the printk()s under
rq->lock will issue a wakeup from the up() call, but lockdep won't
warn about that since semaphores are not tracked.
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Link: http://lkml.kernel.org/n/tip-j8swthl12u73h4znbvitljzd@git.kernel.org
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/printk.c')
-rw-r--r-- | kernel/printk.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/kernel/printk.c b/kernel/printk.c index 35185392173f..751e7b84e9e3 100644 --- a/kernel/printk.c +++ b/kernel/printk.c | |||
@@ -782,7 +782,7 @@ static inline int can_use_console(unsigned int cpu) | |||
782 | static int console_trylock_for_printk(unsigned int cpu) | 782 | static int console_trylock_for_printk(unsigned int cpu) |
783 | __releases(&logbuf_lock) | 783 | __releases(&logbuf_lock) |
784 | { | 784 | { |
785 | int retval = 0; | 785 | int retval = 0, wake = 0; |
786 | 786 | ||
787 | if (console_trylock()) { | 787 | if (console_trylock()) { |
788 | retval = 1; | 788 | retval = 1; |
@@ -795,12 +795,14 @@ static int console_trylock_for_printk(unsigned int cpu) | |||
795 | */ | 795 | */ |
796 | if (!can_use_console(cpu)) { | 796 | if (!can_use_console(cpu)) { |
797 | console_locked = 0; | 797 | console_locked = 0; |
798 | up(&console_sem); | 798 | wake = 1; |
799 | retval = 0; | 799 | retval = 0; |
800 | } | 800 | } |
801 | } | 801 | } |
802 | printk_cpu = UINT_MAX; | 802 | printk_cpu = UINT_MAX; |
803 | spin_unlock(&logbuf_lock); | 803 | spin_unlock(&logbuf_lock); |
804 | if (wake) | ||
805 | up(&console_sem); | ||
804 | return retval; | 806 | return retval; |
805 | } | 807 | } |
806 | static const char recursion_bug_msg [] = | 808 | static const char recursion_bug_msg [] = |
@@ -1271,8 +1273,8 @@ void console_unlock(void) | |||
1271 | if (unlikely(exclusive_console)) | 1273 | if (unlikely(exclusive_console)) |
1272 | exclusive_console = NULL; | 1274 | exclusive_console = NULL; |
1273 | 1275 | ||
1274 | up(&console_sem); | ||
1275 | spin_unlock_irqrestore(&logbuf_lock, flags); | 1276 | spin_unlock_irqrestore(&logbuf_lock, flags); |
1277 | up(&console_sem); | ||
1276 | if (wake_klogd) | 1278 | if (wake_klogd) |
1277 | wake_up_klogd(); | 1279 | wake_up_klogd(); |
1278 | } | 1280 | } |