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 C2E8AC4167B for ; Thu, 7 Dec 2023 08:37:50 +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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-ID:References:In-Reply-To:Subject:Cc:To:From :Date:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=yoH4s7H0uZ7oj2FPbRGgLvmO+UqLdv7VHRvAePPZFIw=; b=wTDuOvgI06VYg+G1l2vGZaFkSM 0+xzEBT4rfUB9OI1i280zaR32puI+dY6J5dZIhKb4dk10PvW/Ei6i/sYQrV56iy3xTQb5CT4HYqu+ VAmGQR4uf03GxHftj71KxwfwbTRsp3lycFCmZFg8DU2NBbjzPohkdc1KI2sXvILa+IAearrnE+Tb1 zg+pPSwba5XhW/Kp69YTpEU7K0yme46HEHonrL/Kg7qn/vmypWTBGQRdfmHxgpA2XYReKTo1Qjcbx KgOS+G79DA5RLfmgWEeshE85vF0uGFVxNDiujLojCuKf1uU/IolvAy47sXO4O05Oh8tNn15+qmTG0 5zQ/7Kig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rB9sg-00CExJ-1O; Thu, 07 Dec 2023 08:37:14 +0000 Received: from mail.manjaro.org ([2a01:4f8:c0c:51f3::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rB9sb-00CEvg-2o; Thu, 07 Dec 2023 08:37:12 +0000 MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=manjaro.org; s=2021; t=1701938223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ItJvp86mvKeMDbvON2mlBeaPlnTZSQtaPqu7Y3Wk7gc=; b=apBinFhY27PhsJ07Cw8uCjWrCpuBCPMK6GzUR0aOWW5xTxRSCNgeP0H8ZpHndVXiHzIJek 7RBgE81Zb1CJwIL3wY5aosDGgdKxnSCQL5vTOreX624afVuqQDQ6tQVfxxXbOh86cFOicD mX4yi4bmZl+dyplE/4A5Vkjf7xYmPYHUdU1NDWR2+kOREsEL56pH8VOWOUv9QYMmAVLqLV rSgE6Mv+wUVyrvmjiJP09lpSFoXmNCnRl+OTWuJWn2ER71IT4bAY+epz3HDR1/717pbC/j SKXXbzGYOGXwlqw3VEY4TUQW5bRcl4q9vzzRYHKWkGoiTwHvJ67/He09CzU9sw== Date: Thu, 07 Dec 2023 09:37:03 +0100 From: Dragan Simic To: Jensen Huang Cc: Heiko Stuebner , Andi Shyti , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Osipenko , Chris Morgan , Benjamin Bara Subject: Re: [PATCH v2] i2c: rk3x: fix potential spinlock recursion on poll In-Reply-To: <20231207082200.16388-1-jensenhuang@friendlyarm.com> References: <20231207082200.16388-1-jensenhuang@friendlyarm.com> Message-ID: X-Sender: dsimic@manjaro.org Authentication-Results: ORIGINATING; auth=pass smtp.auth=dsimic@manjaro.org smtp.mailfrom=dsimic@manjaro.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231207_003710_548575_998AF9B9 X-CRM114-Status: GOOD ( 18.72 ) 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: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2023-12-07 09:21, Jensen Huang wrote: > Possible deadlock scenario (on reboot): > rk3x_i2c_xfer_common(polling) > -> rk3x_i2c_wait_xfer_poll() > -> rk3x_i2c_irq(0, i2c); > --> spin_lock(&i2c->lock); > ... > > -> rk3x_i2c_irq(0, i2c); > --> spin_lock(&i2c->lock); (deadlock here) > > Store the IRQ number and disable/enable it around the polling transfer. > This patch has been tested on NanoPC-T4. In case you haven't already seen the related discussion linked below, please have a look. I also added more people to the list of recipients, in an attempt to make everyone aware of the different approaches to solving this issue. https://lore.kernel.org/all/655177f4.050a0220.d85c9.3ba0@mx.google.com/T/#m6fc9c214452fec6681843e7f455978c35c6f6c8b > Signed-off-by: Jensen Huang > Reviewed-by: Heiko Stuebner > Reviewed-by: Andi Shyti > --- > Changes in v2: > - Add description for member 'irq' to fix build warning > > drivers/i2c/busses/i2c-rk3x.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-rk3x.c > b/drivers/i2c/busses/i2c-rk3x.c > index a044ca0c35a1..4362db7c5789 100644 > --- a/drivers/i2c/busses/i2c-rk3x.c > +++ b/drivers/i2c/busses/i2c-rk3x.c > @@ -178,6 +178,7 @@ struct rk3x_i2c_soc_data { > * @clk: function clk for rk3399 or function & Bus clks for others > * @pclk: Bus clk for rk3399 > * @clk_rate_nb: i2c clk rate change notify > + * @irq: irq number > * @t: I2C known timing information > * @lock: spinlock for the i2c bus > * @wait: the waitqueue to wait for i2c transfer > @@ -200,6 +201,7 @@ struct rk3x_i2c { > struct clk *clk; > struct clk *pclk; > struct notifier_block clk_rate_nb; > + int irq; > > /* Settings */ > struct i2c_timings t; > @@ -1087,13 +1089,18 @@ static int rk3x_i2c_xfer_common(struct > i2c_adapter *adap, > > spin_unlock_irqrestore(&i2c->lock, flags); > > - rk3x_i2c_start(i2c); > - > if (!polling) { > + rk3x_i2c_start(i2c); > + > timeout = wait_event_timeout(i2c->wait, !i2c->busy, > msecs_to_jiffies(WAIT_TIMEOUT)); > } else { > + disable_irq(i2c->irq); > + rk3x_i2c_start(i2c); > + > timeout = rk3x_i2c_wait_xfer_poll(i2c); > + > + enable_irq(i2c->irq); > } > > spin_lock_irqsave(&i2c->lock, flags); > @@ -1310,6 +1317,8 @@ static int rk3x_i2c_probe(struct platform_device > *pdev) > return ret; > } > > + i2c->irq = irq; > + > platform_set_drvdata(pdev, i2c); > > if (i2c->soc_data->calc_timings == rk3x_i2c_v0_calc_timings) { _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel