From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756106AbdLTVuh (ORCPT ); Wed, 20 Dec 2017 16:50:37 -0500 Received: from vern.gendns.com ([206.190.152.46]:49857 "EHLO vern.gendns.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754502AbdLTVug (ORCPT ); Wed, 20 Dec 2017 16:50:36 -0500 Subject: Re: [PATCH] clk: fix spin_lock/unlock imbalance on bad clk_enable() reentrancy From: David Lechner To: Michael Turquette , linux-clk@vger.kernel.org Cc: Stephen Boyd , linux-kernel@vger.kernel.org, Jerome Brunet References: <1513122223-14932-1-git-send-email-david@lechnology.com> <32ca585d-c51d-1c85-42ba-85f0b1df0a60@lechnology.com> <151372258747.45969.10121622799666696251@resonance> <3ad110cf-95ba-0d0b-53ee-f1fa2d37d7fa@lechnology.com> <151379785862.37313.908268542576551305@resonance> Message-ID: <749e4759-3511-92d4-a19a-0f72c31b1ee6@lechnology.com> Date: Wed, 20 Dec 2017 15:50:41 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vern.gendns.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lechnology.com X-Get-Message-Sender-Via: vern.gendns.com: authenticated_id: davidmain+lechnology.com/only user confirmed/virtual account not confirmed X-Authenticated-Sender: vern.gendns.com: davidmain@lechnology.com X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/20/2017 02:33 PM, David Lechner wrote: > > So, as you can see, we get 4 warnings here. There is no problem with any > clock provider or consumer (as far as I can tell). The bug here is that > spin_trylock_irqsave() always returns true on non-SMP systems, which > messes up the reference counting. > > usb20_phy_clk_enable() currently works because mach-davinci does not use > the common clock framework. However, I am trying to move it to the > common clock framework, which is how I discovered this bug. One more thing I mentioned previously, but is worth mentioning again in detail is that if you enable CONFIG_DEBUG_SPINLOCK, that changes the behavior of spin_trylock_irqsave() on non-SMP systems. It no longer always returns true and so everything works as expected in the call chain that I described previously. The difference is that with CONFIG_DEBUG_SPINLOCK=n, we have #define arch_spin_trylock(lock) ({ barrier(); (void)(lock); 1; }) But if CONFIG_DEBUG_SPINLOCK=y, then we have static inline int arch_spin_trylock(arch_spinlock_t *lock) { char oldval = lock->slock; lock->slock = 0; barrier(); return oldval > 0; } This comes from include/linux/spinlock_up.h, which is included from include/linux/spinlock.h #ifdef CONFIG_SMP # include #else # include #endif So, the question I have is: what is the actual "correct" behavior of spin_trylock_irqsave()? Is it really supposed to always return true when CONFIG_DEBUG_SPINLOCK=n and CONFIG_SMP=n or is this a bug?