mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Jisheng Zhang <jszhang@kernel.org>
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Jan Dabros <jsd@semihalf.com>, Andi Shyti <andi.shyti@kernel.org>,
	linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org
Subject: Re: [PATCH 1/2] i2c: designware: Avoid taking clk_prepare mutex in PM callbacks
Date: Fri, 22 Aug 2025 12:18:42 +0300	[thread overview]
Message-ID: <aKg18p9Zf9hoZHPY@smile.fi.intel.com> (raw)
In-Reply-To: <aKdKOa1jFXDHK8uI@xhacker>

On Fri, Aug 22, 2025 at 12:32:57AM +0800, Jisheng Zhang wrote:
> On Thu, Aug 21, 2025 at 04:01:55PM +0300, Andy Shevchenko wrote:
> > On Thu, Aug 21, 2025 at 03:45:43PM +0300, Jarkko Nikula wrote:
> > > On 8/20/25 7:33 PM, Jisheng Zhang wrote:
> > > > On Wed, Aug 20, 2025 at 07:05:42PM +0300, Andy Shevchenko wrote:
> > > > > On Wed, Aug 20, 2025 at 11:31:24PM +0800, Jisheng Zhang wrote:
> > > > > > This is unsafe, as the runtime PM callbacks are called from the PM
> > > > > > workqueue, so this may deadlock when handling an i2c attached clock,
> > > > > > which may already hold the clk_prepare mutex from another context.
> > > > > 
> > > > > Can you be more specific? What is the actual issue in practice?
> > > > > Do you have traces and lockdep warnings?
> > > > 
> > > > Assume we use i2c designware to control any i2c based clks, e.g the
> > > > clk-si5351.c driver. In its .clk_prepare, we'll get the prepare_lock
> > > > mutex, then we call i2c adapter to operate the regs, to runtime resume
> > > > the i2c adapter, we call clk_prepare_enable() which will try to get
> > > > the prepare_lock mutex again.
> > > > 
> > > I'd also like to see the issue here. I'm blind to see what's the relation
> > > between the clocks managed by the clk-si5351.c and clocks to the
> > > i2c-designware IP.
> 
> The key here is: all clks in the system share the same prepare_lock
> mutex, so the global prepare_lock mutex is locked by clk-si5351
> .prepare(), then in this exact .prepare(), the i2c-designware's runtime
> resume will try to lock the same prepare_lock again due to
> clk_prepare_enable()
> can you plz check clk_prepare_lock() in drivers/clk/clk.c?
> 
> And if we take a look at other i2c adapters' drivers, we'll see
> some of them have ever met this issue and already fixed it, such
> as 
> 
> i2c-exynos5, by commit 10ff4c5239a1 ("i2c: exynos5: Fix possible ABBA
> deadlock by keeping I2C clock prepared")
> 
> i2c-imx, by commit d9a22d713acb ("i2c: imx: avoid taking clk_prepare
> mutex in PM callbacks")

Why is this an I²C driver problem?

> > I believe they try to make an example when clk-si5351 is the provider of
> > the clock to I²C host controller (DesignWare).
> 
> Nope, the example case is using i2c host controller to operate the clk-si5351

Okay, so that chip is controlled over I²C, but how their clocks even related to
the I²C host controller clock?! I am sorry, I am lost here.

> > But I'm still not sure about the issues here... Without (even simulated with
> > specific delay injections) lockdep warnings it would be rather theoretical.
> 
> No, it happened in real world.

Can you provide the asked traces and lockdep warnigns and/or other stuff to see
what's going on there?

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2025-08-22  9:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-20 15:31 [PATCH 0/2] i2c: designware: Implement atomic transfer suppot Jisheng Zhang
2025-08-20 15:31 ` [PATCH 1/2] i2c: designware: Avoid taking clk_prepare mutex in PM callbacks Jisheng Zhang
2025-08-20 16:05   ` Andy Shevchenko
2025-08-20 16:33     ` Jisheng Zhang
2025-08-21 12:45       ` Jarkko Nikula
2025-08-21 13:01         ` Andy Shevchenko
2025-08-21 16:32           ` Jisheng Zhang
2025-08-22  9:18             ` Andy Shevchenko [this message]
2025-08-22  9:34               ` Andy Shevchenko
2025-08-22 13:56                 ` Jisheng Zhang
2025-08-22 23:51                 ` Jisheng Zhang
2025-08-20 15:31 ` [PATCH 2/2] i2c: designware: Implement atomic transfer suppot Jisheng Zhang
2025-08-20 17:00   ` Andy Shevchenko

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=aKg18p9Zf9hoZHPY@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=andi.shyti@kernel.org \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=jsd@semihalf.com \
    --cc=jszhang@kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.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

all inboxes | Powered by JetHome®