From mboxrd@z Thu Jan 1 00:00:00 1970 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 8AE7BCE8379 for ; Mon, 30 Sep 2024 18:44:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:CC:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=OF0EkRxjx2yfvIsfLJPafutYqdx+PpnWM4Um2ShLhb4=; b=NrX3gfKKzYkfku9Ep30yk4JKiJ vI67CSajsNTzYgPd+xOflZY9lLC22Vke7Oj2QFA6QIs+2zNM0yqVJsnAcRPQZRFLYLOoXPyFCW/jb qGTgUjHjklAiyFJ/Wps8NRFxTzKQcTvLEKKfSf+cfp/fZmT9JnCrKayd/gVLCrszYA8vaHJSbl1wI AzZhdp25dBx0qkFYalBX1QZ6s0DL56Bnmi+FPaMFHbOKXiSjXxUDhgteX5vKzvJqlySvE9YdiJ8df srWxN3/jeKr8f4icFZI7m3stjT7FqfiwPanKOzGX8OP12jCNAoSwHTutMfR07cKDMAlf7Zo/1Lo4O cjOVBrMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1svLNC-00000000XrA-1W9Q; Mon, 30 Sep 2024 18:43:54 +0000 Received: from mx07-00178001.pphosted.com ([185.132.182.106]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1svLLz-00000000XkZ-3zuG for linux-arm-kernel@lists.infradead.org; Mon, 30 Sep 2024 18:42:41 +0000 Received: from pps.filterd (m0288072.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48UF4bAW018825; Mon, 30 Sep 2024 20:42:22 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to; s=selector1; bh=OF0EkRxjx2yfvIsfLJPafutY qdx+PpnWM4Um2ShLhb4=; b=AODi7JnQ8n26NfVKR5wyu6c5g3gJtswanQ93QqsB +CyLF+MjoEUuxqwcK84jmP09Ve+ZC0AC/nurpJH1hyo3wxAQUoKhTLJLnRzdyr5t aiJ72lGQ1jWVsdv1dWOOiZJcQHv6rKFvcEcsLIJaDNU70Hq0IYlD88OC+AOvILtT vhrTcm0UBzupR/RJd62F3Pyb3ZoyEnAdWf46lGpCLjKkEpCaLnzw2DQUSBF6/10h 1m33ow8DxEHnNA0N1t/vvMrAJpb3XbJaV7r5SoHyeREQFDLj7+xbV+aCQIPnuIhj ySo9Amg0Lr30JCUvoLNdvBCqWlYzzKEX8ouym2lGeauhGw== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 41x77gjd4w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 Sep 2024 20:42:22 +0200 (MEST) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 6574B4005B; Mon, 30 Sep 2024 20:41:18 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 59CBC2A65AC; Mon, 30 Sep 2024 20:38:56 +0200 (CEST) Received: from gnbcxd0016.gnb.st.com (10.129.178.213) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.37; Mon, 30 Sep 2024 20:38:55 +0200 Date: Mon, 30 Sep 2024 20:38:46 +0200 From: Alain Volmat To: Marek Vasut CC: , Alexandre Torgue , Andi Shyti , Christoph Niedermaier , Maxime Coquelin , Pierre-Yves MORDRET , , , Subject: Re: [PATCH] i2c: stm32f7: Do not prepare/unprepare clock during runtime suspend/resume Message-ID: <20240930183846.GA1601582@gnbcxd0016.gnb.st.com> References: <20240928014409.633542-1-marex@denx.de> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20240928014409.633542-1-marex@denx.de> X-Disclaimer: ce message est personnel / this message is private X-Originating-IP: [10.129.178.213] X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240930_114240_317479_08A0C1AC X-CRM114-Status: GOOD ( 24.79 ) 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 Hi Marek, thanks a lot for the patch. On Sat, Sep 28, 2024 at 03:43:46AM +0200, Marek Vasut wrote: > In case there is any sort of clock controller attached to this I2C bus > controller, for example Versaclock or even an AIC32x4 I2C codec, then > an I2C transfer triggered from the clock controller clk_ops .prepare > callback may trigger a deadlock on drivers/clk/clk.c prepare_lock mutex. > > This is because the clock controller first grabs the prepare_lock mutex > and then performs the prepare operation, including its I2C access. The > I2C access resumes this I2C bus controller via .runtime_resume callback, > which calls clk_prepare_enable(), which attempts to grab the prepare_lock > mutex again and deadlocks. > > Since the clock are already prepared since probe() and unprepared in > remove(), use simple clk_enable()/clk_disable() calls to enable and > disable the clock on runtime suspend and resume, to avoid hitting the > prepare_lock mutex. > > Signed-off-by: Marek Vasut > --- > Cc: Alain Volmat > Cc: Alexandre Torgue > Cc: Andi Shyti > Cc: Christoph Niedermaier > Cc: Maxime Coquelin > Cc: Pierre-Yves MORDRET > Cc: kernel@dh-electronics.com > Cc: linux-arm-kernel@lists.infradead.org > Cc: linux-i2c@vger.kernel.org > Cc: linux-stm32@st-md-mailman.stormreply.com > --- > drivers/i2c/busses/i2c-stm32f7.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c > index cfee2d9c09de3..65c035728a4fa 100644 > --- a/drivers/i2c/busses/i2c-stm32f7.c > +++ b/drivers/i2c/busses/i2c-stm32f7.c > @@ -2395,7 +2395,7 @@ static int __maybe_unused stm32f7_i2c_runtime_suspend(struct device *dev) > struct stm32f7_i2c_dev *i2c_dev = dev_get_drvdata(dev); > > if (!stm32f7_i2c_is_slave_registered(i2c_dev)) > - clk_disable_unprepare(i2c_dev->clk); > + clk_disable(i2c_dev->clk); > > return 0; > } > @@ -2406,7 +2406,7 @@ static int __maybe_unused stm32f7_i2c_runtime_resume(struct device *dev) > int ret; > > if (!stm32f7_i2c_is_slave_registered(i2c_dev)) { > - ret = clk_prepare_enable(i2c_dev->clk); > + ret = clk_enable(i2c_dev->clk); > if (ret) { > dev_err(dev, "failed to prepare_enable clock\n"); The call now being clk_enable, could you also change the error message from prepare_enable to enable ? With that done, Acked-by: Alain Volmat Regards, Alain > return ret; > -- > 2.45.2 >