From: Dragan Simic <dsimic@manjaro.org>
To: Jensen Huang <jensenhuang@friendlyarm.com>
Cc: Heiko Stuebner <heiko@sntech.de>,
Andi Shyti <andi.shyti@kernel.org>,
linux-arm-kernel@lists.infradead.org,
linux-rockchip@lists.infradead.org, linux-i2c@vger.kernel.org,
linux-kernel@vger.kernel.org,
Dmitry Osipenko <dmitry.osipenko@collabora.com>,
Chris Morgan <macroalpha82@gmail.com>,
Benjamin Bara <bbara93@gmail.com>
Subject: Re: [PATCH v2] i2c: rk3x: fix potential spinlock recursion on poll
Date: Thu, 07 Dec 2023 09:37:03 +0100 [thread overview]
Message-ID: <ebf6cf8ec3b5befd673d295061fa2738@manjaro.org> (raw)
In-Reply-To: <20231207082200.16388-1-jensenhuang@friendlyarm.com>
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 interrupt>
> -> 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 <jensenhuang@friendlyarm.com>
> Reviewed-by: Heiko Stuebner <heiko@sntech.de>
> Reviewed-by: Andi Shyti <andi.shyti@kernel.org>
> ---
> 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
next prev parent reply other threads:[~2023-12-07 8:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-07 8:21 [PATCH v2] i2c: rk3x: fix potential spinlock recursion on poll Jensen Huang
2023-12-07 8:37 ` Dragan Simic [this message]
2023-12-07 9:25 ` Jensen Huang
2023-12-07 14:10 ` Dragan Simic
2023-12-07 16:00 ` Dmitry Osipenko
2023-12-08 8:53 ` Jensen Huang
2023-12-08 12:17 ` Dmitry Osipenko
2023-12-22 8:22 ` Jensen Huang
2023-12-19 17:23 ` Wolfram Sang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ebf6cf8ec3b5befd673d295061fa2738@manjaro.org \
--to=dsimic@manjaro.org \
--cc=andi.shyti@kernel.org \
--cc=bbara93@gmail.com \
--cc=dmitry.osipenko@collabora.com \
--cc=heiko@sntech.de \
--cc=jensenhuang@friendlyarm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=macroalpha82@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox