Commit bd8d7cf5 authored by Jan Kara's avatar Jan Kara Committed by Linus Torvalds

printk: fix lockdep instrumentation of console_sem

Printk calls mutex_acquire() / mutex_release() by hand to instrument
lockdep about console_sem.  However in some corner cases the
instrumentation is missing.  Fix the problem by creating helper functions
for locking / unlocking console_sem which take care of lockdep
instrumentation as well.
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Reported-by: default avatarFabio Estevam <festevam@gmail.com>
Reported-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tested-by: default avatarFabio Estevam <fabio.estevam@freescale.com>
Tested-By: default avatarValdis Kletnieks <valdis.kletnieks@vt.edu>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 608873ca
...@@ -90,6 +90,29 @@ static struct lockdep_map console_lock_dep_map = { ...@@ -90,6 +90,29 @@ static struct lockdep_map console_lock_dep_map = {
}; };
#endif #endif
/*
* Helper macros to handle lockdep when locking/unlocking console_sem. We use
* macros instead of functions so that _RET_IP_ contains useful information.
*/
#define down_console_sem() do { \
down(&console_sem);\
mutex_acquire(&console_lock_dep_map, 0, 0, _RET_IP_);\
} while (0)
static int __down_trylock_console_sem(unsigned long ip)
{
if (down_trylock(&console_sem))
return 1;
mutex_acquire(&console_lock_dep_map, 0, 1, ip);
return 0;
}
#define down_trylock_console_sem() __down_trylock_console_sem(_RET_IP_)
#define up_console_sem() do { \
mutex_release(&console_lock_dep_map, 1, _RET_IP_);\
up(&console_sem);\
} while (0)
/* /*
* This is used for debugging the mess that is the VT code by * This is used for debugging the mess that is the VT code by
* keeping track if we have the console semaphore held. It's * keeping track if we have the console semaphore held. It's
...@@ -1422,7 +1445,7 @@ static int console_trylock_for_printk(unsigned int cpu) ...@@ -1422,7 +1445,7 @@ static int console_trylock_for_printk(unsigned int cpu)
*/ */
if (!can_use_console(cpu)) { if (!can_use_console(cpu)) {
console_locked = 0; console_locked = 0;
up(&console_sem); up_console_sem();
return 0; return 0;
} }
return 1; return 1;
...@@ -1951,16 +1974,14 @@ void suspend_console(void) ...@@ -1951,16 +1974,14 @@ void suspend_console(void)
printk("Suspending console(s) (use no_console_suspend to debug)\n"); printk("Suspending console(s) (use no_console_suspend to debug)\n");
console_lock(); console_lock();
console_suspended = 1; console_suspended = 1;
up(&console_sem); up_console_sem();
mutex_release(&console_lock_dep_map, 1, _RET_IP_);
} }
void resume_console(void) void resume_console(void)
{ {
if (!console_suspend_enabled) if (!console_suspend_enabled)
return; return;
down(&console_sem); down_console_sem();
mutex_acquire(&console_lock_dep_map, 0, 0, _RET_IP_);
console_suspended = 0; console_suspended = 0;
console_unlock(); console_unlock();
} }
...@@ -2002,12 +2023,11 @@ void console_lock(void) ...@@ -2002,12 +2023,11 @@ void console_lock(void)
{ {
might_sleep(); might_sleep();
down(&console_sem); down_console_sem();
if (console_suspended) if (console_suspended)
return; return;
console_locked = 1; console_locked = 1;
console_may_schedule = 1; console_may_schedule = 1;
mutex_acquire(&console_lock_dep_map, 0, 0, _RET_IP_);
} }
EXPORT_SYMBOL(console_lock); EXPORT_SYMBOL(console_lock);
...@@ -2021,15 +2041,14 @@ EXPORT_SYMBOL(console_lock); ...@@ -2021,15 +2041,14 @@ EXPORT_SYMBOL(console_lock);
*/ */
int console_trylock(void) int console_trylock(void)
{ {
if (down_trylock(&console_sem)) if (down_trylock_console_sem())
return 0; return 0;
if (console_suspended) { if (console_suspended) {
up(&console_sem); up_console_sem();
return 0; return 0;
} }
console_locked = 1; console_locked = 1;
console_may_schedule = 0; console_may_schedule = 0;
mutex_acquire(&console_lock_dep_map, 0, 1, _RET_IP_);
return 1; return 1;
} }
EXPORT_SYMBOL(console_trylock); EXPORT_SYMBOL(console_trylock);
...@@ -2091,7 +2110,7 @@ void console_unlock(void) ...@@ -2091,7 +2110,7 @@ void console_unlock(void)
bool retry; bool retry;
if (console_suspended) { if (console_suspended) {
up(&console_sem); up_console_sem();
return; return;
} }
...@@ -2153,7 +2172,6 @@ void console_unlock(void) ...@@ -2153,7 +2172,6 @@ void console_unlock(void)
local_irq_restore(flags); local_irq_restore(flags);
} }
console_locked = 0; console_locked = 0;
mutex_release(&console_lock_dep_map, 1, _RET_IP_);
/* Release the exclusive_console once it is used */ /* Release the exclusive_console once it is used */
if (unlikely(exclusive_console)) if (unlikely(exclusive_console))
...@@ -2161,7 +2179,7 @@ void console_unlock(void) ...@@ -2161,7 +2179,7 @@ void console_unlock(void)
raw_spin_unlock(&logbuf_lock); raw_spin_unlock(&logbuf_lock);
up(&console_sem); up_console_sem();
/* /*
* Someone could have filled up the buffer again, so re-check if there's * Someone could have filled up the buffer again, so re-check if there's
...@@ -2206,7 +2224,7 @@ void console_unblank(void) ...@@ -2206,7 +2224,7 @@ void console_unblank(void)
* oops_in_progress is set to 1.. * oops_in_progress is set to 1..
*/ */
if (oops_in_progress) { if (oops_in_progress) {
if (down_trylock(&console_sem) != 0) if (down_trylock_console_sem() != 0)
return; return;
} else } else
console_lock(); console_lock();
......
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