From patchwork Tue Dec 26 17:24:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 10133193 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4AB206037D for ; Tue, 26 Dec 2017 17:25:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F9FC2DD11 for ; Tue, 26 Dec 2017 17:25:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22F6A2DF24; Tue, 26 Dec 2017 17:25:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A14E92DD11 for ; Tue, 26 Dec 2017 17:25:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751318AbdLZRYe (ORCPT ); Tue, 26 Dec 2017 12:24:34 -0500 Received: from vern.gendns.com ([206.190.152.46]:35798 "EHLO vern.gendns.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751107AbdLZRYb (ORCPT ); Tue, 26 Dec 2017 12:24:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lechnology.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender: Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=YGOwG8ZZYz80tA1esAnhQ/vnAdNLEYIixaKy8xz+I2M=; b=LSJ+OYEr5xEjt5qvga05Q5l2m7 sXw9nSk8M2t8F/1zeKUPnzBVNrzeBSQVvFmGp5h1jSqtmw+YEf1tutnSPU4SVjkKG1eac7HrRMHSw udvn/ONRLMgqAop6rLhphDWykIePTgZO+JIHrYRWVl789P9CCW2yChxBSGNPD4hLgamcjH05KeNRH ApsvsOC8wq4pAplgfpOuc+449I6g0NqtXCstN3tzM6DUF+uxYc+yhxfk72vH6IFPhb60MgHtd1QZD spk1jQbDSjpXfacBAATghh0o/l+suVGYO0JdBZcDGNfaQBJFB/UbpXB3JL03k1COtA3FSJcKzSxS/ 6ZmSysnA==; Received: from 108-198-5-147.lightspeed.okcbok.sbcglobal.net ([108.198.5.147]:46444 helo=freyr.lechnology.com) by vern.gendns.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-SHA256:128) (Exim 4.89) (envelope-from ) id 1eTsvi-002J0B-3h; Tue, 26 Dec 2017 12:22:18 -0500 From: David Lechner To: linux-clk@vger.kernel.org Cc: David Lechner , Michael Turquette , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH] clk: fix reentrancy of clk_enable() on UP systems Date: Tue, 26 Dec 2017 11:24:22 -0600 Message-Id: <1514309062-1768-1-git-send-email-david@lechnology.com> X-Mailer: git-send-email 2.7.4 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-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Reentrant calls to clk_enable() are not working on UP systems. This is caused by the fact spin_trylock_irqsave() always returns true when CONFIG_SMP=n (and CONFIG_DEBUG_SPINLOCK=n) which causes the reference counting to not work correctly when clk_enable_lock() is called twice before clk_enable_unlock() is called (this happens when clk_enable() is called from within another clk_enable()). This introduces a new set of clk_enable_lock() and clk_enable_unlock() functions for UP systems that doesn't use spinlocks but effectively does the same thing as the SMP version of the functions. Signed-off-by: David Lechner --- Previous discussion of this issue for reference: * https://patchwork.kernel.org/patch/10108437/ * https://patchwork.kernel.org/patch/10115483/ drivers/clk/clk.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index bb1b1f9..259a77f 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -136,6 +136,8 @@ static void clk_prepare_unlock(void) mutex_unlock(&prepare_lock); } +#ifdef CONFIG_SMP + static unsigned long clk_enable_lock(void) __acquires(enable_lock) { @@ -170,6 +172,43 @@ static void clk_enable_unlock(unsigned long flags) spin_unlock_irqrestore(&enable_lock, flags); } +#else + +static unsigned long clk_enable_lock(void) + __acquires(enable_lock) +{ + unsigned long flags; + + local_irq_save(flags); + preempt_disable(); + __acquire(enable_lock); + + if (enable_refcnt++ == 0) { + WARN_ON_ONCE(enable_owner != NULL); + enable_owner = current; + } else { + WARN_ON_ONCE(enable_owner != current); + } + + return flags; +} + +static void clk_enable_unlock(unsigned long flags) + __releases(enable_lock) +{ + WARN_ON_ONCE(enable_owner != current); + WARN_ON_ONCE(enable_refcnt == 0); + + if (--enable_refcnt == 0) + enable_owner = NULL; + + __release(enable_lock); + local_irq_restore(flags); + preempt_enable(); +} + +#endif + static bool clk_core_is_prepared(struct clk_core *core) { bool ret = false;