Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp2539773rdb; Mon, 25 Dec 2023 16:39:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IFHFkiBZcpumquAm3bc/UmG7pmkh7b5GQiOHXO76EI4tb0vMzpyTGOgvLyUGBlFKLqtONOQ X-Received: by 2002:a05:6871:726:b0:204:5b42:c949 with SMTP id f38-20020a056871072600b002045b42c949mr5264225oap.72.1703551168791; Mon, 25 Dec 2023 16:39:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703551168; cv=none; d=google.com; s=arc-20160816; b=SLeWhkIVWuLIdDnl8GwHXfc8Gu9SGP4GOcRbbvfmh3HMTsYlkYC6N97E4P5m1Pwjyn c6s/D+l2YwreN3oHrZdCNnJAtA4JrPsnnEn+Ih/ZqXsYGj/VRspury7m51SIMuF2rIhu 1iSIeNS1A2ocXH3xgKhrQMreV5PJGsxOnZ1O8gdrpUDTRKdiMWSTQqCRz93UXXdMEoGR /fKcnXG+GpPx8cvnin0h5/nSTK5o7U5Lp2AyW3NnzBtej3VjvdRcmVs/6C+nK1NqcPZx BZ1kjxPKCMFNQdnDa170ukG5j5BukOD4ko4jpcdpO2bXg8A4HB9/bnldubegAhMCwyJd 1svQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=NmMwHWHZCNMO4B5llxosTS2+jQQaJZbxPNifX9gukFc=; fh=LIDWV1MSTVab6MD/c/rq1f4uY+kOexZTaBv8Zbzm3NA=; b=JBOETu3vcFxZljWEIonLf+dpahuRD2mcYkQxAV1eXUh86we0kmIKcT9gIN8JMiWn+b 1CQKRui34WTOM5tFOUJKJ4p0rc7vvdrXYCV3oJ+lbS7PKhkEb8eeR0IKQtaDFeyRYVIf V/qiYL1gdQ61kP27nhW1DZEdyE1xnettSdBYZXLGYT8CxQ/zN3HLu7QbigukqOPTJAIQ BGsxC7bEpQTJAtvRvgE15G++8N0QFbAzGjWuqlzdRqzLqiZ2D//R3K4awzDr9kzvctji biAa42kNLSf/H80XgNIbLltVC+M0robJ9HSY16pRU96ihUD59aZQxvK7x8mPKMFcvHHc lJgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Xn+mjAuP; spf=pass (google.com: domain of linux-kernel+bounces-11251-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11251-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q82-20020a632a55000000b005cdf7387492si6257303pgq.263.2023.12.25.16.39.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Dec 2023 16:39:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11251-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Xn+mjAuP; spf=pass (google.com: domain of linux-kernel+bounces-11251-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11251-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0302A2832B9 for ; Tue, 26 Dec 2023 00:35:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 820B059141; Tue, 26 Dec 2023 00:23:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Xn+mjAuP" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF4DF58ACE; Tue, 26 Dec 2023 00:23:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3158EC433C7; Tue, 26 Dec 2023 00:23:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703550227; bh=FBRWW3QeNKpq2d2kD1Mri1FwSWkwhDCdTR7YPU2Q7Vs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xn+mjAuPenji47juFYKL6QvHXdfx9MhtI1MLcGCVzl7bxz++B3TjegyaDzV7etNj9 A2QWHvNhTqYyrW+pmkzGnXbymqc9VYfdjM6fN66u61mYK7xdqVAbxDtI/FEBhoZkP4 bthHif4LJyb8NHXl78LciANNcowG+Ud/pIafQDCmJxnoVI146t60Fq5SisCUj24EZX E51nTRY8l+P+kmCatIn0km996EHipNJSJYghaX69xDM4KTXHpNnAV5tShc0ez/RRAV NlEl7Ju5Obxhy/vdkBw6ucgVV/6ysKGmc+4XR8Shvqj7SVsSIc6zUB4w1TRyNQ6r29 aKkjvoh7J0u9Q== 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 6.1 19/24] i2c: rk3x: fix potential spinlock recursion on poll Date: Mon, 25 Dec 2023 19:22:12 -0500 Message-ID: <20231226002255.5730-19-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231226002255.5730-1-sashal@kernel.org> References: <20231226002255.5730-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.69 Content-Transfer-Encoding: 8bit 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 b31cf4f18f854..6aa4f1f062401 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) { -- 2.43.0