From: Ingo Molnar Make printk()-ing from within the lock validation code safer by using the lockdep-recursion counter. Signed-off-by: Ingo Molnar Signed-off-by: Arjan van de Ven Signed-off-by: Andrew Morton --- kernel/printk.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff -puN kernel/printk.c~lock-validator-do-not-recurse-in-printk kernel/printk.c --- devel/kernel/printk.c~lock-validator-do-not-recurse-in-printk 2006-05-29 18:13:05.000000000 -0700 +++ devel-akpm/kernel/printk.c 2006-05-29 18:13:05.000000000 -0700 @@ -516,7 +516,9 @@ asmlinkage int vprintk(const char *fmt, zap_locks(); /* This stops the holder of console_sem just where we want him */ - spin_lock_irqsave(&logbuf_lock, flags); + local_irq_save(flags); + current->lockdep_recursion++; + spin_lock(&logbuf_lock); printk_cpu = smp_processor_id(); /* Emit the output into the temporary buffer */ @@ -572,7 +574,7 @@ asmlinkage int vprintk(const char *fmt, */ console_locked = 1; printk_cpu = UINT_MAX; - spin_unlock_irqrestore(&logbuf_lock, flags); + spin_unlock(&logbuf_lock); /* * Console drivers may assume that per-cpu resources have @@ -588,6 +590,8 @@ asmlinkage int vprintk(const char *fmt, console_locked = 0; up(&console_sem); } + current->lockdep_recursion--; + local_irq_restore(flags); } else { /* * Someone else owns the drivers. We drop the spinlock, which @@ -595,7 +599,9 @@ asmlinkage int vprintk(const char *fmt, * console drivers with the output which we just produced. */ printk_cpu = UINT_MAX; - spin_unlock_irqrestore(&logbuf_lock, flags); + spin_unlock(&logbuf_lock); + current->lockdep_recursion--; + local_irq_restore(flags); } preempt_enable(); @@ -769,7 +775,13 @@ void release_console_sem(void) up(&console_sem); spin_unlock_irqrestore(&logbuf_lock, flags); if (wake_klogd && !oops_in_progress && waitqueue_active(&log_wait)) - wake_up_interruptible(&log_wait); + /* + * If we printk from within the lock dependency code, + * from within the scheduler code, then do not lock + * up due to self-recursion: + */ + if (current->lockdep_recursion <= 1) + wake_up_interruptible(&log_wait); } EXPORT_SYMBOL(release_console_sem); _