From patchwork Fri Feb 6 14:13:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 5791981 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CB05ABF440 for ; Fri, 6 Feb 2015 14:15:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E2DA12011E for ; Fri, 6 Feb 2015 14:15:48 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 15187201F5 for ; Fri, 6 Feb 2015 14:15:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YJjfO-0003Hh-BY; Fri, 06 Feb 2015 14:13:54 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YJjfM-0003HP-Cp for linux-arm-kernel@bombadil.infradead.org; Fri, 06 Feb 2015 14:13:52 +0000 Received: from 178-85-85-44.dynamic.upc.nl ([178.85.85.44] helo=twins) by casper.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1YJjfI-0001sv-RB; Fri, 06 Feb 2015 14:13:48 +0000 Received: by twins (Postfix, from userid 1000) id 69A621254D6C5; Fri, 6 Feb 2015 15:13:46 +0100 (CET) Date: Fri, 6 Feb 2015 15:13:46 +0100 From: Peter Zijlstra To: Peter Ujfalusi Subject: Re: [PATCH 0/2] ARM: omap2+: omap_hwmod: Fix false lockdep warning Message-ID: <20150206141346.GP21418@twins.programming.kicks-ass.net> References: <1423226916-18804-1-git-send-email-peter.ujfalusi@ti.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1423226916-18804-1-git-send-email-peter.ujfalusi@ti.com> User-Agent: Mutt/1.5.21 (2012-12-30) Cc: paul@pwsan.com, Tony Lindgren , linux-kernel@vger.kernel.org, balbi@ti.com, mingo@redhat.com, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Fri, Feb 06, 2015 at 02:48:34PM +0200, Peter Ujfalusi wrote: > Hi, > > In case when hwmods are used in nested way the lockdep validator will print out > a warning message about possible deadlock situation: > > [ 4.514882] ============================================= > [ 4.520530] [ INFO: possible recursive locking detected ] > [ 4.526176] 3.14.30-00289-ge44872fdca8f-dirty #198 Not tainted > [ 4.532285] --------------------------------------------- > [ 4.537936] kworker/u4:1/18 is trying to acquire lock: > [ 4.543317] (&(&oh->_lock)->rlock){......}, at: [] omap_hwmod_enable+0x2c/0x58 > [ 4.552109] > [ 4.552109] but task is already holding lock: > [ 4.558216] (&(&oh->_lock)->rlock){......}, at: [] omap_hwmod_enable+0x2c/0x58 > [ 4.566999] > [ 4.566999] other info that might help us debug this: > [ 4.573831] Possible unsafe locking scenario: > [ 4.573831] > [ 4.580025] CPU0 > [ 4.582584] ---- > [ 4.585142] lock(&(&oh->_lock)->rlock); > [ 4.589544] lock(&(&oh->_lock)->rlock); > [ 4.593945] > [ 4.593945] *** DEADLOCK *** > [ 4.593945] > [ 4.600146] May be due to missing lock nesting notation > > What lockdep did not realizes is that the two oh is not the same hwmod object > and we have taken different locks. > > One example of nested hwmod usage is on DRA7xx platforms, where McASP can be > configured to use ATL clock as it's functional clock. In this case the > pm_runtime_get/put_sync call will enable the mcasp hwmod and as part of this > operation it will enable the needed clocks. Since ATL clock is needed, we will > have another pm_runtime operation from the ATL clock enable callback which > will take the atl hwmod's lock. This will be seen by lockdep as possible > deadlock situation. > > In order to notify lockdep about this, we need to switch using _nested > version of locking function and assign different subclass to those hwmods which > could be used in nested way. IFF struct omap_hwmod is always statically allocated; as I think the __init on _register() mandates, you can use the below annotation. --- arch/arm/mach-omap2/omap_hwmod.c | 1 + arch/arm/mach-omap2/omap_hwmod.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c index 9025ffffd2dc..222d654ad6fd 100644 --- a/arch/arm/mach-omap2/omap_hwmod.c +++ b/arch/arm/mach-omap2/omap_hwmod.c @@ -2698,6 +2698,7 @@ static int __init _register(struct omap_hwmod *oh) INIT_LIST_HEAD(&oh->master_ports); INIT_LIST_HEAD(&oh->slave_ports); spin_lock_init(&oh->_lock); + lockdep_set_class(&oh->_lock, &oh->hwmod_key); oh->_state = _HWMOD_STATE_REGISTERED; diff --git a/arch/arm/mach-omap2/omap_hwmod.h b/arch/arm/mach-omap2/omap_hwmod.h index 5b42fafcaf55..754bdfb3f811 100644 --- a/arch/arm/mach-omap2/omap_hwmod.h +++ b/arch/arm/mach-omap2/omap_hwmod.h @@ -689,6 +689,8 @@ struct omap_hwmod { u8 _state; u8 _postsetup_state; struct omap_hwmod *parent_hwmod; + + struct lock_class_key hwmod_key; }; struct omap_hwmod *omap_hwmod_lookup(const char *name);