From patchwork Mon Oct 24 15:09:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 13017699 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 091D9ECAAA1 for ; Mon, 24 Oct 2022 15:12:32 +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=wrCekc+XhzZtRskUVBu1qUPSjMbrPJyhwrTLZLbfguM=; b=QMI081kpEmfZPY QF+ZwzIV73NEw+1cJVQYpKcZGAL+nSs6N0WD9zUnOPdN1KTc2MG0xYhQ6M02JoKCARa7HTVFqaShI Pp7+0tYeBztu57YUMLWK42ve8jC9jnSjHeNLMzVmmJjWkyIINmXCbL/JRwLJNRI2tBSVLqml740GY Ya4+AmzzAaL3H89ZZuP1ZMJYe7X5XYtftPNaAerOLIC6DE8zbFZL+0hUs+O7YMZ3MANYH94s161j9 omVVVDFScVUf4VbDED+Xv2kHulAJDKE5G5/J4fZ8XEx1vxuB0FUO7CkgR/nSFr7jz3LAK6rSV9hXJ jaaiELbP+4Z8y9T4qCsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1omz5e-0023oN-BS; Mon, 24 Oct 2022 15:10:10 +0000 Received: from phobos.denx.de ([2a01:238:438b:c500:173d:9f52:ddab:ee01]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1omz5a-0023kJ-Ef for linux-arm-kernel@lists.infradead.org; Mon, 24 Oct 2022 15:10: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 B9BB480076; Mon, 24 Oct 2022 17:09:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1666624195; bh=Yx8gNpZwSkH+u0dz5auO3h/0qkztyKzZiTPX1tvLoFU=; h=From:To:Cc:Subject:Date:From; b=XGZxABIi+H55GxLTX6rRXt74ktWxpKxOYYkieXir3zuLbfSGXrX/c8DnrhAhc78/N 4v0HMA2xYraCRBohwE8or11wObxuF2L/Fs5RY8TzQNq4x2+O8FF/UPx4ya3mRJCDLU XdKiwcaNWx9lpdKrLHTN2tyna4Dd0CHfrKsBsV4O1x4ywlTkRlCfwbQhHcptf2jZrE VWyrAkSeLqhBDpOmRuzMuwYXEQWaSrFuyXsUMTfRbILguc3NsXJC+buM31K3lV9p8I CEvogBFJh57nBxrgsRTS1i6tLjDTbcODakOtLMgAIy1XtZE1fa/dCHha3xemFOCegC spUUPudaGmyfA== 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: imx8m-blk-ctrl: Split clock prepare from clock enable in the domain Date: Mon, 24 Oct 2022 17:09:47 +0200 Message-Id: <20221024150947.10739-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-20221024_081006_900139_BDC7828F X-CRM114-Status: GOOD ( 13.33 ) 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 blkctrl 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 blkctrl: - 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 blkctrl driver always claims the prepare_lock before blk_ctrl_genpd_lock_class and the deadlock is avoided. 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/imx8mp-blk-ctrl.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/soc/imx/imx8mp-blk-ctrl.c b/drivers/soc/imx/imx8mp-blk-ctrl.c index b7d4161fcda9c..571c98b5b005b 100644 --- a/drivers/soc/imx/imx8mp-blk-ctrl.c +++ b/drivers/soc/imx/imx8mp-blk-ctrl.c @@ -393,15 +393,21 @@ static int imx8mp_blk_ctrl_power_on(struct generic_pm_domain *genpd) struct imx8mp_blk_ctrl *bc = domain->bc; int ret; + ret = clk_bulk_prepare(data->num_clks, domain->clks); + if (ret) { + dev_err(bc->dev, "failed to enable clocks\n"); + return ret; + } + /* make sure bus domain is awake */ ret = pm_runtime_resume_and_get(bc->bus_power_dev); if (ret < 0) { dev_err(bc->dev, "failed to power up bus domain\n"); - return ret; + goto rpm_put; } /* enable upstream clocks */ - ret = clk_bulk_prepare_enable(data->num_clks, domain->clks); + ret = clk_bulk_enable(data->num_clks, domain->clks); if (ret) { dev_err(bc->dev, "failed to enable clocks\n"); goto bus_put; @@ -426,9 +432,11 @@ static int imx8mp_blk_ctrl_power_on(struct generic_pm_domain *genpd) return 0; clk_disable: - clk_bulk_disable_unprepare(data->num_clks, domain->clks); + clk_bulk_disable(data->num_clks, domain->clks); bus_put: pm_runtime_put(bc->bus_power_dev); +rpm_put: + clk_bulk_unprepare(data->num_clks, domain->clks); return ret; }