From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756866AbcAOJa7 (ORCPT ); Fri, 15 Jan 2016 04:30:59 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35055 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754914AbcAOJaz (ORCPT ); Fri, 15 Jan 2016 04:30:55 -0500 Date: Fri, 15 Jan 2016 10:30:50 +0100 From: Ingo Molnar To: Byungchul Park Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, akinobu.mita@gmail.com, jack@suse.cz, torvalds@linux-foundation.org, Peter Zijlstra Subject: Re: [PATCH] lib/spinlock_debug.c: prevent deadlock in spin_dump() by console_sem Message-ID: <20160115093050.GA22063@gmail.com> References: <1452849881-27982-1-git-send-email-byungchul.park@lge.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1452849881-27982-1-git-send-email-byungchul.park@lge.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Byungchul Park wrote: > Deadlock occured when using CONFIG_DEBUG_SPINLOCK, in spin_dump(). > Backtrace prints printk() -> console_trylock() -> do_raw_spin_lock() -> > spin_dump() -> printk()... infinitely. > > If spin_bug() is called from a function like printk() which is using > console lock, we should prevent the debug spinlock code from calling > printk() any more in the context. > > Signed-off-by: Byungchul Park > --- > kernel/locking/spinlock_debug.c | 10 ++++++++++ > kernel/printk/printk.c | 5 +++++ > 2 files changed, 15 insertions(+) > > diff --git a/kernel/locking/spinlock_debug.c b/kernel/locking/spinlock_debug.c > index 0374a59..b339c5e 100644 > --- a/kernel/locking/spinlock_debug.c > +++ b/kernel/locking/spinlock_debug.c > @@ -67,11 +67,21 @@ static void spin_dump(raw_spinlock_t *lock, const char *msg) > dump_stack(); > } > > +extern int is_console_lock(raw_spinlock_t *lock); > + > static void spin_bug(raw_spinlock_t *lock, const char *msg) > { > if (!debug_locks_off()) > return; > > + /* > + * If this function is called from a function like printk() > + * which is trying console lock, we cannot call printk() any > + * more. Or it's obviously deadlock! Small spelling nit, the last sentence is not correct, pick one of these variants: 'It's an obvious deadlock.' 'It's obviously a deadlock.' Thanks, Ingo