From patchwork Sun Oct 23 16:40:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 13016339 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A1EB4C3A59D for ; Sun, 23 Oct 2022 16:42:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=tsyC6aLQtZQjsOS4Wps7mOfKK20HDE72tFWECvcaJAA=; b=gUKPPlNXCTX6Q/ meDRxBwGhPMot+LUzJZ/no4VpgWNvCQ2q2aUc9rOdfHAODouqp5HgrDPP0sconXmp6YACEKAo2Fj1 vGu5x9YuNqDcVsosH4eC+krvKAIKtn6VHs+PCl1Zs2GUETf7/S2jv2taXxGFiDXBenKkEAjb5P0Qx YuaPwKXNVuk1R/xx6HlRCcblJ2ILju4qgDFPiRDXeHJ+Sf37M1Bfe5Vxt+WYYWEi4nhDcNOqc3BIe owsbaDMLG9KPNp84NiR2Mq09OqZaitZyYOcbO+RxDiWlqAG5qjUYnqhQdahyU9MtZmYRVy471WQu9 auifEBglBQwe44ESt0xw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ome29-00Fiyg-O0; Sun, 23 Oct 2022 16:41:09 +0000 Received: from phobos.denx.de ([85.214.62.61]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ome23-00Fixq-4I for linux-arm-kernel@lists.infradead.org; Sun, 23 Oct 2022 16:41:08 +0000 Received: from tr.lan (ip-86-49-120-218.bb.vodafone.cz [86.49.120.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 857AC848A1; Sun, 23 Oct 2022 18:40:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1666543257; bh=6JQ7AfwduSszHXHlETY0G1z0X3gKVn5kR1ZBqvsrG18=; h=From:To:Cc:Subject:Date:From; b=IMXvZF6d+Pps1gb1WrqRbrVvr6+MRVNNWbwwdbfo6C0DQhH/cLqj2S96ZCqvztr6x hiGV5uDePrZMqf9MExHrACAfHCVDTGY7ls+8/c+CHuqW5Qp4La9zQK8UnjNqqS8txc RUx4urxzzYtKeyIN8UrOUq0l3y1ddB0qC/rSH9CDHdv4g/w0WwjiOsAfi/4Wa0c3Eq p2ZJAmlBKXJq1GyLTNETxxtDFZ6DRwulFKG2nBLzh5RC0xnkDU9agRGSYRkTto5P1l swPLmrb7yFn1ykqdXqosO8a9ncMxawWBIVpnvthPPQI0Apc0DHmD/kJZhTQLOlaR++ R3YRaZAPLQ7cQ== From: Marek Vasut To: linux-arm-kernel@lists.infradead.org Cc: Marek Vasut , Fabio Estevam , Jacky Bai , Laurent Pinchart , Lucas Stach , Peng Fan , Shawn Guo , Shengjiu Wang , Stephen Boyd , linux-clk@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH] [RFC] soc: imx: gpcv2: Split clock prepare from clock enable in the domain Date: Sun, 23 Oct 2022 18:40:00 +0200 Message-Id: <20221023164000.555654-1-marex@denx.de> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221023_094103_595084_C14E6E9D X-CRM114-Status: GOOD ( 13.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org It is possible for clk_disable_unused() to trigger lockdep warning regarding lock ordering in this driver. This happens in case of the following conditions: A) clock core clk_disable_unused() triggers the following sequence in a driver which also uses GPCv2 domain: - clk_prepare_lock() -> obtains clock core prepare_lock - pm_runtime_get*() -> obtains &blk_ctrl_genpd_lock_class B) driver powers up a power domain and triggers the following sequence in GPCv2: - pm_runtime_get_sync() -> obtains &blk_ctrl_genpd_lock_class - clk_bulk_prepare_enable() -> obtains clock core prepare_lock This can lead to a deadlock in case A and B runs on separate CPUs. To avoid the deadlock, split clk_*prepare() from clk_*enable() and call the former before pm_runtime_get_sync(). This way, the GPCv2 driver always claims the prepare_lock before blk_ctrl_genpd_lock_class and the deadlock is avoided. The imx8m and imx8mp block controller drivers likely need similar fix. Signed-off-by: Marek Vasut --- Cc: Fabio Estevam Cc: Jacky Bai Cc: Laurent Pinchart Cc: Lucas Stach Cc: Peng Fan Cc: Shawn Guo Cc: Shengjiu Wang Cc: Stephen Boyd Cc: linux-clk@vger.kernel.org Cc: linux-imx@nxp.com To: linux-arm-kernel@lists.infradead.org --- drivers/soc/imx/gpcv2.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/soc/imx/gpcv2.c b/drivers/soc/imx/gpcv2.c index 88aee59730e39..ee9294ad25ba1 100644 --- a/drivers/soc/imx/gpcv2.c +++ b/drivers/soc/imx/gpcv2.c @@ -319,10 +319,16 @@ static int imx_pgc_power_up(struct generic_pm_domain *genpd) u32 reg_val, pgc; int ret; + ret = clk_bulk_prepare(domain->num_clks, domain->clks); + if (ret) { + dev_err(domain->dev, "failed to prepare reset clocks\n"); + return ret; + } + ret = pm_runtime_get_sync(domain->dev); if (ret < 0) { pm_runtime_put_noidle(domain->dev); - return ret; + goto out_clock_unprepare; } if (!IS_ERR(domain->regulator)) { @@ -338,7 +344,7 @@ static int imx_pgc_power_up(struct generic_pm_domain *genpd) reset_control_assert(domain->reset); /* Enable reset clocks for all devices in the domain */ - ret = clk_bulk_prepare_enable(domain->num_clks, domain->clks); + ret = clk_bulk_enable(domain->num_clks, domain->clks); if (ret) { dev_err(domain->dev, "failed to enable reset clocks\n"); goto out_regulator_disable; @@ -402,12 +408,14 @@ static int imx_pgc_power_up(struct generic_pm_domain *genpd) return 0; out_clk_disable: - clk_bulk_disable_unprepare(domain->num_clks, domain->clks); + clk_bulk_disable(domain->num_clks, domain->clks); out_regulator_disable: if (!IS_ERR(domain->regulator)) regulator_disable(domain->regulator); out_put_pm: pm_runtime_put(domain->dev); +out_clock_unprepare: + clk_bulk_unprepare(domain->num_clks, domain->clks); return ret; }