From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756383AbcCRFzY (ORCPT ); Fri, 18 Mar 2016 01:55:24 -0400 Received: from LGEAMRELO11.lge.com ([156.147.23.51]:49405 "EHLO lgeamrelo11.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754021AbcCRFzQ (ORCPT ); Fri, 18 Mar 2016 01:55:16 -0400 X-Original-SENDERIP: 156.147.1.121 X-Original-MAILFROM: byungchul.park@lge.com X-Original-SENDERIP: 10.177.222.33 X-Original-MAILFROM: byungchul.park@lge.com Date: Fri, 18 Mar 2016 14:55:05 +0900 From: Byungchul Park To: akpm@linux-foundation.org, mingo@kernel.org Cc: linux-kernel@vger.kernel.org, akinobu.mita@gmail.com, jack@suse.cz, sergey.senozhatsky.work@gmail.com, peter@hurleysoftware.com, tglx@linutronix.de, peterz@infradead.org, rostedt@goodmis.org Subject: [PATCH] lib/spinlock_debug: Prevent a unnecessary recursive spin_dump() Message-ID: <20160318055505.GO5220@X58A-UD3R> References: <1457692627-14076-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: <1457692627-14076-1-git-send-email-byungchul.park@lge.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This can protect an infinit recursion by unnecessary warning, too. -----8<----- >>From 81f06a6f9c7f2e782267a2539c6c869d4214354c Mon Sep 17 00:00:00 2001 From: Byungchul Park Date: Fri, 18 Mar 2016 11:35:24 +0900 Subject: [PATCH] lib/spinlock_debug: Prevent a unnecessary recursive spin_dump() Printing "lockup suspected" for the same lock more than once is meaningless. Furtheremore, it can cause an infinite recursion if it's on the way printing something by printk(). Signed-off-by: Byungchul Park --- kernel/locking/spinlock_debug.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/kernel/locking/spinlock_debug.c b/kernel/locking/spinlock_debug.c index fd24588..30559c6 100644 --- a/kernel/locking/spinlock_debug.c +++ b/kernel/locking/spinlock_debug.c @@ -138,14 +138,25 @@ static void __spin_lock_debug(raw_spinlock_t *lock) { u64 i; u64 loops = loops_per_jiffy * HZ; + static raw_spinlock_t *suspected_lock = NULL; for (i = 0; i < loops; i++) { if (arch_spin_trylock(&lock->raw_lock)) return; __delay(1); } - /* lockup suspected: */ - spin_dump(lock, "lockup suspected"); + + /* + * When we suspect a lockup, it's good enough to inform it once for + * the same lock. Otherwise it could cause an infinite recursion if + * it's within printk(). + */ + if (suspected_lock != lock) { + suspected_lock = lock; + /* lockup suspected: */ + spin_dump(lock, "lockup suspected"); + suspected_lock = NULL; + } #ifdef CONFIG_SMP trigger_all_cpu_backtrace(); #endif -- 1.9.1