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 68F99C3DA6E for ; Tue, 26 Dec 2023 00:25: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: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: 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: List-Owner; bh=++aPOhee8oQWxAjioMIOXwkO73Z1tQSoCJnEgtmh32c=; b=AQfHD/s8XSVaNa mc9kIMafTCYHKWl1mK6A7jbsmnvaBAunPghgr5PAzw+kRV0t8jijDt6tj5Q/8uM5WbICGsMBR43yG CSpCpJtYmsVqsiuPUToqZx4d9JYGEs16BZK/8fLufIP+O5P1QVPuPMVQujSlXTpGg6b/BjRgb49/j NZllJ778lZQBzwcSzHoXU+f14N84YU0Qfs3ZHSb8LFCeilZacC1NBgtFZklY3KElEM56F5gXCGm8K K3lQebQB75jiyB9FPx+UZOT0T1jph9l4OmTKT6vzNRFc3+zlS+iED03wy0OmxMS7PaJe7vBko3LFk yDDqNHyY6OGWfMOUgLkg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rHvFg-00BRC6-2e; Tue, 26 Dec 2023 00:24:56 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rHvFd-00BR98-12; Tue, 26 Dec 2023 00:24:54 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 080DEB80B92; Tue, 26 Dec 2023 00:24:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FAF4C433C7; Tue, 26 Dec 2023 00:24:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703550291; bh=wEme5zOXjNS4jm4i7jwulhr8cvuV5k7DomlCN/6/p40=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HO4eJZN5coauanQ5u5psBlD5OsWEdN2F1lnM4ILOpN0V3IK2D1H67jeU2OMBDB7KT VZpDs2F5muEEzL0BWRLJp+4mLdg5GXrAdFzp84dC4GXxTqxCm72GHwOEYejuqh8fJ3 fy227KSPuS7qoKcNBySzsZQ55yUjPgv/NwE24GwUKXPDGJST6zCMeNE0VUSDsQF9DW 7PCzru3iPCk5blK+JD+ndh6xFsly5OZUE6F1/wYXsY45SKnPDTYh9CTPzQ0I51Pdpb Io79uIbVnCSvwH733q7oEnI3t6cmboWKvsqlr9EvE7NK0XQLWIaM4dp1PZ6cP0vXYk ezf/OPw6luqxw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jensen Huang , Heiko Stuebner , Andi Shyti , Wolfram Sang , Sasha Levin , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-i2c@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 10/11] i2c: rk3x: fix potential spinlock recursion on poll Date: Mon, 25 Dec 2023 19:23:59 -0500 Message-ID: <20231226002420.6303-10-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231226002420.6303-1-sashal@kernel.org> References: <20231226002420.6303-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.15.145 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231225_162453_634260_8FEF19DA X-CRM114-Status: GOOD ( 13.84 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org From: Jensen Huang [ Upstream commit 19cde9c92b8d3b7ee555d0da3bcb0232d3a784f4 ] 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. Signed-off-by: Jensen Huang Reviewed-by: Heiko Stuebner Reviewed-by: Andi Shyti Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- 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 13c14eb175e94..6abcf975a2db9 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); @@ -1301,6 +1308,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) { -- 2.43.0 _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip