From: mturquette@linaro.org (Mike Turquette)
To: linux-arm-kernel@lists.infradead.org
Subject: Deadlock with I2C based clock providers
Date: Tue, 18 Mar 2014 16:29:17 -0700 [thread overview]
Message-ID: <20140318232917.30995.41976@quantum> (raw)
In-Reply-To: <5328499D.4040806@parkeon.com>
Quoting Martin Fuzzey (2014-03-18 06:26:53)
> Hi Mike,
>
> I have a clock provide that implements the clock operations over i2c.
>
> Although this is now possible since commit 533ddeb1e8 clk: allow
> reentrant calls into the clk framework
>
> that patch only deals with single threaded reentrancy.
>
>
> The issue I am having involves two threads:
>
> Thread A calls the i2c clock driver
> Thread B is in an unrelated driver for another I2C device on the same
> I2C bus (audio codec).
>
>
> Thread A:
> clk_set_rate(my_clk)
> clk_prepare_lock() <== Takes clock lock
> clk_change_rate()
> ops->set_rate()
> i2c_transfer()
> i2c_lock_adapter() <== Blocks on I2C bus lock
>
>
>
> Thread B:
> i2c_transfer()
> i2c_lock_adapter() <== Takes I2C bus lock
> i2c_imx_xfer()
> i2c_imx_start()
> clk_prepare_enable(i2c_clk)
> clk_prepare_lock() <== Blocks on clock lock
>
>
> The problem is that the locks are taken in the reverse order leading to
> a classic deadlock.
>
> I saw your [RFC] clk: reentrancy via per-clock locking but that seemed
> to have other problems.
>
>
> My current (horrible) workaround involves exposing clk_prepare_lock()
> and calling it from i2c_core but that obviously isn't the right solution.
A slightly less hacky (but still horrible) solution might be to move the
calls to clk_prepare_enable before calling i2c_lock_adapter().
Alternatively some trylock solution might be necessary to unwind the
locks and yield execution for a while and then try again. The clk
framework reentrancy patches are pretty irrelevant here since those were
only designed to allow reentrancy from within the same task context and
this is not an example of that. This deadlock is a more clear-cut
circular dependency between i2c and the clock framework.
Regards,
Mike
>
> Regards,
>
> Martin
>
prev parent reply other threads:[~2014-03-18 23:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-18 13:26 Deadlock with I2C based clock providers Martin Fuzzey
2014-03-18 23:29 ` Mike Turquette [this message]
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=20140318232917.30995.41976@quantum \
--to=mturquette@linaro.org \
--cc=linux-arm-kernel@lists.infradead.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