Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1508757rdb; Thu, 7 Dec 2023 00:37:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IEDPWIsAY54QHcwQggD+HCWSI3msxRRQWumulCgSSy6sODqekSdcEX/VQS0VwFPqD993EgB X-Received: by 2002:a05:6a20:a296:b0:187:b800:d2ef with SMTP id a22-20020a056a20a29600b00187b800d2efmr1625478pzl.29.1701938247719; Thu, 07 Dec 2023 00:37:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701938247; cv=none; d=google.com; s=arc-20160816; b=q8cCYTcKMKOCrDi12KmdP0D1W7KVYkVVhw7ztuWUy+rZKFUNsKifZ3+b0FegMIMJp/ YYEqkjyx8nb3+/ehvxJcrTtqr2JKsSfGOSpAxnjv7N85sWWxS7ZXnyNBgA5MIqItxiRy RCvPO6uPmAco3b6vfw7oFr5s36905384ko2EGsBx+Terqy6FIZU4lD1xgG45y0Yt34sC zMQHU3sLL7jr/uBQ+PAUP2OgoLI0ihny/MSV14rWlf976xbry1DpQCnqIxOr5ewmFdBa 6VGrFQtlXQiVxZUWZ1diiG1s/Kvy0VidohJ/q3SraSXVXqh1eJCezRnkt0h0ti9DbKyR V1Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:message-id:references :in-reply-to:subject:cc:to:from:date:dkim-signature:mime-version; bh=ItJvp86mvKeMDbvON2mlBeaPlnTZSQtaPqu7Y3Wk7gc=; fh=PuyFNg+5hg2AaE1XtTVYenw/2N96x1F1uyvY8GOkD/4=; b=S8MOTdHJmO8v+fmXH1GKwLhAFFSlwhdN6QOqRTe8XLkuagCQVxXxXJ5ZUN/UFfkRA8 Ge5aF86c1Sp56Odq61P/+KRg1+HBJtbTDVRDD1d1v2ENCu6qh2QYWx397zAP/nVTyZCj iwIOTrw3dZdlwXbDe8WhrQKa+PKN6ZDaQsNrMxDhpI/BNcHezRk/BmCs2jxx6P57Wgxq qjw4R7fI8GQTh+f9boIPfONCUphpXV9b33Ebs2cddKf6L66EUuz5Omcaq1otGo5DjJbe MkNk13nRe/H9lOMkeeRYCg5vErwg3TKNV5FGmDKJEZRM3rCLnZrOfe/GiCo0LsxjvSjL Q08Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@manjaro.org header.s=2021 header.b=apBinFhY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=manjaro.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id m184-20020a6326c1000000b005c64505cbc2si840359pgm.19.2023.12.07.00.37.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 00:37:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@manjaro.org header.s=2021 header.b=apBinFhY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=manjaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id E864980613BE; Thu, 7 Dec 2023 00:37:24 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378367AbjLGIhF (ORCPT + 99 others); Thu, 7 Dec 2023 03:37:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjLGIhC (ORCPT ); Thu, 7 Dec 2023 03:37:02 -0500 Received: from mail.manjaro.org (mail.manjaro.org [IPv6:2a01:4f8:c0c:51f3::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23A1BC6; Thu, 7 Dec 2023 00:37:06 -0800 (PST) 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 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Authentication-Results: ORIGINATING; auth=pass smtp.auth=dsimic@manjaro.org smtp.mailfrom=dsimic@manjaro.org X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 07 Dec 2023 00:37:25 -0800 (PST) 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) {