From: Alexander Stein <alexander.stein@ew.tq-group.com>
To: Andi Shyti <andi.shyti@kernel.org>
Cc: Dong Aisheng <aisheng.dong@nxp.com>,
Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>, Wolfram Sang <wsa@kernel.org>,
Alexander Sverdlin <alexander.sverdlin@siemens.com>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
NXP Linux Team <linux-imx@nxp.com>,
linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v7 1/1] i2c: lpi2c: use clk notifier for rate changes
Date: Tue, 14 Nov 2023 13:27:11 +0100 [thread overview]
Message-ID: <2912069.e9J7NaK4W3@steina-w> (raw)
In-Reply-To: <20231110122720.cyxtnpj5k6bip3ok@zenone.zhora.eu>
Hi Andi,
Am Freitag, 10. November 2023, 13:27:20 CET schrieb Andi Shyti:
> Alexander,
>
> if you...
>
> On Thu, Nov 09, 2023 at 10:10:46AM +0100, Andi Shyti wrote:
> > On Thu, Nov 09, 2023 at 08:54:51AM +0100, Alexander Stein wrote:
> > > Am Donnerstag, 9. November 2023, 00:38:09 CET schrieb Andi Shyti:
> > > > On Tue, Nov 07, 2023 at 03:12:01PM +0100, Alexander Stein wrote:
> > > > > Instead of repeatedly calling clk_get_rate for each transfer,
> > > > > register
> > > > > a clock notifier to update the cached divider value each time the
> > > > > clock
> > > > > rate actually changes.
> > > > > There is also a lockdep splat if a I2C based clock provider needs to
> > > > > access the i2c bus while in recalc_rate(). "prepare_lock" is about
> > > > > to
> > > > > be locked recursively.
> > > > >
> > > > > Fixes: a55fa9d0e42e ("i2c: imx-lpi2c: add low power i2c bus driver")
> > > >
> > > > What's the exact fix here? Is it the lockdep warning? Is it
> > > > actually causing a real deadlock?
> > >
> > > We've seen actual deadlocks on our imx8qxp based hardware using a
> > > downstream kernel, so we have implemented as similar fix [1]. This
> > > happened using tlv320aic32x4 audio codec.
> > > The backtrace is similar, a i2c based clock provider is trying t issue
> > > an i2c transfer while adding the clock, thus 'prepare_lock' is already
> > > locked. Lockdep raises an error both for downstream kernel as well as
> > > mainline, both for tlv320aic32x4 or pcf85063.
> >
> > yes, if the clock is using the same controller then it's likely
> > that you might end up in a deadlock. This is why I like this
> > patch and I believe this shouild go in the library at some point.
> >
> > But the deadlock is not mentioned in the commit log and lockdep
> > doesn't always mean deadlock.
>
> ... improve the commit message, reporting the real deadlock case
> instead of a lockdep warning and...
I've improved the commit message about an actual deadlock.
> [...]
>
> > > > > @@ -207,7 +224,7 @@ static int lpi2c_imx_config(struct
> > > > > lpi2c_imx_struct
> > > > > *lpi2c_imx)>
> > > > >
> > > > > lpi2c_imx_set_mode(lpi2c_imx);
> > > > >
> > > > > - clk_rate = clk_get_rate(lpi2c_imx->clks[0].clk);
> > > > > + clk_rate = atomic_read(&lpi2c_imx->rate_per);
> > > > >
> > > > > if (!clk_rate)
> > > > >
> > > > > return -EINVAL;
> > > >
> > > > Doesn't seem like EINVAL, defined as "Invalid argument", is the
> > > > correct number here. As we are failing to read the clock rate, do
> > > > you think EIO is better?
> > >
> > > Well, this is already the current error code. In both the old and new
> > > code I would consider this error case as 'no clock rate provided'
> > > rather than failing to read. I would reject EIO as there is no IO
> > > transfer for retrieving the clock rate.
> >
> > It's definitely not EINVAL as we are failing not because of
> > invalid arguments. I thought of EIO because at some point the
> > clock rate has been retrieved (or set, thus i/o) and "rate_per"
> > updated accordingly. But I agree that's not the perfect value
> > either.
> >
> > I couldn't think of a better error value, though.
>
> ... find a more appropriate error number, I will ack this patch.
Thinking about this again, I think EINVAL is an appropriate error code.
The parent clock frequency is also an input for the i2c transfer. So if, for
whatever reason, that clock frequency is 0, it is an invalid value (argument).
I've checked other drivers what they do if that clock is 0. Unfortunately most
don't consider this case at all. But some do, so e.g. i2c_lpc2k_probe() or
dc_i2c_init_hw() both return EINVAL if the clk or a calculated divider is 0.
> If the deadlock you mentioned is a warning from the lockdep, then
> please remove the "Fixes:" tag.
It's not just a lockdep warning, the deadlock actually happened.
Best regards,
Alexander
> Andi
--
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
http://www.tq-group.com/
_______________________________________________
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-11-14 12:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-07 14:12 [PATCH v7 1/1] i2c: lpi2c: use clk notifier for rate changes Alexander Stein
2023-11-07 21:20 ` Andi Shyti
2023-11-08 6:46 ` Alexander Stein
2023-11-08 9:15 ` Andi Shyti
2023-11-08 9:18 ` Wolfram Sang
2023-11-08 10:26 ` Andi Shyti
2023-11-08 23:38 ` Andi Shyti
2023-11-09 7:54 ` Alexander Stein
2023-11-09 9:10 ` Andi Shyti
2023-11-10 12:27 ` Andi Shyti
2023-11-14 12:27 ` Alexander Stein [this message]
2023-12-19 16:56 ` 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=2912069.e9J7NaK4W3@steina-w \
--to=alexander.stein@ew.tq-group.com \
--cc=aisheng.dong@nxp.com \
--cc=alexander.sverdlin@siemens.com \
--cc=andi.shyti@kernel.org \
--cc=festevam@gmail.com \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-imx@nxp.com \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=wsa@kernel.org \
/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