From patchwork Mon Apr 24 08:06:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Stein X-Patchwork-Id: 13221822 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 4621AC7618E for ; Mon, 24 Apr 2023 08:07:55 +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=fyQdRIGFJKl4yFcZiav+LxmWXPyz1SQa5s2w42SdfYg=; b=qapDyMXuPvkYNV q5315609rN4VwBRr2zIykuLVkZMJ8Q2iIGMNMt2VorwPac3socW8omadepycn/D0RdNoMU7Myapae Nbtriel2kDVX4ebWuXiibHkV9c4ZcS66awKycFfOKmAoCPagkSSC/p+EfYp6LGb59nhgHpiAECxz4 gq5IpNWaXUEZZCPbTWQ4dNWISEKAxpwPEKDfJ7nOIohAFh408DaRs9esWtDKkEXiheyihJC2W+j1s gI+rKMs/L4Sl5h3BFaLDHeco/RkYOl5ZSHgVfheeP9U/izgEmK3F4XOYVjJ3E4U50a84qT5nMx5F7 NJoPsnnkehKzkgdrH+eA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pqrDw-00FdXe-1C; Mon, 24 Apr 2023 08:07:00 +0000 Received: from mx1.tq-group.com ([93.104.207.81]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pqrDt-00FdVX-00 for linux-arm-kernel@lists.infradead.org; Mon, 24 Apr 2023 08:06:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1682323617; x=1713859617; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=scnAd3dZROF54U3/5AvscerxaUPXYqMOCngEnPDazqU=; b=VKti6eD8DE2yq0DZw5kBLE4noKXx11WHQHSMQTILjcZ8P5jnMM1B3Y2w SlIrj4Q0gMl8mg9zYe0luwlySv12btgbpFUNHJZcn33OWUDc1cK5vkWMf fH1g+pKAO5q/pFQQY5nvA8ZD7C4vrlyL6vn5yWQUsk5O0+9H8I5hRMuz9 Gjz4nBY82pVEDOL3YIYxgY42vioxHRdQUT51yDLvkyDS2P1vwLawsurS6 +R9fVpIcTJrzIwVULAsh7rRPmCTQGA/dSYvJCUBUultzLZrIaHLwsu7F8 V/PCCsM78x7X+AZtUxHmkaRkl1TNPlqeZM8Hd68qM3ul8sExf1Ypu6VSH g==; X-IronPort-AV: E=Sophos;i="5.99,222,1677538800"; d="scan'208";a="30508005" Received: from unknown (HELO tq-pgp-pr1.tq-net.de) ([192.168.6.15]) by mx1-pgp.tq-group.com with ESMTP; 24 Apr 2023 10:06:39 +0200 Received: from mx1.tq-group.com ([192.168.6.7]) by tq-pgp-pr1.tq-net.de (PGP Universal service); Mon, 24 Apr 2023 10:06:39 +0200 X-PGP-Universal: processed; by tq-pgp-pr1.tq-net.de on Mon, 24 Apr 2023 10:06:39 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1682323599; x=1713859599; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=scnAd3dZROF54U3/5AvscerxaUPXYqMOCngEnPDazqU=; b=RYOd09THqsMsG3cwGtjbc9x4ZckghninMcqjlj48j9UqqHqOX1DJHsZw g73jcL7P7k6HE4mhG8M5hzKclDUlR8Qz5bungiom+XzVCbPZbWNep0FjV zErBAyorhtLAaoxWn5cNEs/VBkZ0aGLy5k4xI7VbKGgsDpUznOyIlMaQs uO7C/w/TtYrhxhIfDQvQTTNFi1D+eHn61ehzsiVSJu9JBABLPEIedaDJC GP0QZgaaWQv93AlWo+fIAyR+wvO67yYHtDAN0zEGKPl6y/0412QOtt+Lm WZgY9jETck8Tpt+g3myjl2Mb4nJ2T1okjskYcvy7MXDSDSZtoM+bOzD1n g==; X-IronPort-AV: E=Sophos;i="5.99,222,1677538800"; d="scan'208";a="30508004" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 24 Apr 2023 10:06:39 +0200 Received: from steina-w.tq-net.de (unknown [10.123.53.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by vtuxmail01.tq-net.de (Postfix) with ESMTPSA id BB96C280056; Mon, 24 Apr 2023 10:06:38 +0200 (CEST) From: Alexander Stein To: Dong Aisheng , Shawn Guo , Sascha Hauer , Fabio Estevam Cc: Alexander Stein , Pengutronix Kernel Team , NXP Linux Team , linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, "Sverdlin, Alexander" Subject: [PATCH 1/1] i2c: imx-lpi2c: avoid taking clk_prepare mutex in PM callbacks Date: Mon, 24 Apr 2023 10:06:27 +0200 Message-Id: <20230424080627.20564-1-alexander.stein@ew.tq-group.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230424_010657_413259_0B981F67 X-CRM114-Status: GOOD ( 14.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 This is unsafe, as the runtime PM callbacks are called from the PM workqueue, so this may deadlock when handling an i2c attached clock, which may already hold the clk_prepare mutex from another context. Signed-off-by: Alexander Stein --- This is the imx-lpi2c equivalent to commit d9a22d713acb ("i2c: imx: avoid taking clk_prepare mutex in PM callbacks"). This patch needs to be used together with [1] in order to fix the deadlock conditions. Commit message is shamlessly taken from commit d9a22d713acb. Best regards, Alexander [1] https://patchwork.ozlabs.org/project/linux-i2c/patch/20230310130815.562418-1-alexander.sverdlin@siemens.com/ drivers/i2c/busses/i2c-imx-lpi2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c index a49b14d52a98..1af0a637d7f1 100644 --- a/drivers/i2c/busses/i2c-imx-lpi2c.c +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c @@ -639,7 +639,7 @@ static int __maybe_unused lpi2c_runtime_suspend(struct device *dev) { struct lpi2c_imx_struct *lpi2c_imx = dev_get_drvdata(dev); - clk_bulk_disable_unprepare(lpi2c_imx->num_clks, lpi2c_imx->clks); + clk_bulk_disable(lpi2c_imx->num_clks, lpi2c_imx->clks); pinctrl_pm_select_sleep_state(dev); return 0; @@ -651,7 +651,7 @@ static int __maybe_unused lpi2c_runtime_resume(struct device *dev) int ret; pinctrl_pm_select_default_state(dev); - ret = clk_bulk_prepare_enable(lpi2c_imx->num_clks, lpi2c_imx->clks); + ret = clk_bulk_enable(lpi2c_imx->num_clks, lpi2c_imx->clks); if (ret) { dev_err(dev, "failed to enable I2C clock, ret=%d\n", ret); return ret;