From: Peter Zijlstra <peterz@infradead.org>
To: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: Ingo Molnar <mingo@redhat.com>, LKML <linux-kernel@vger.kernel.org>
Subject: Re: lockdep: incorrect deadlock warning with two GPIO expanders
Date: Mon, 12 Sep 2016 14:09:38 +0200 [thread overview]
Message-ID: <20160912120938.GR10153@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <CAMpxmJUuj5VrzEu4YZUVxr-ZqFU4VGJpjyHimMJug23EC7j=sQ@mail.gmail.com>
On Mon, Sep 12, 2016 at 01:51:55PM +0200, Bartosz Golaszewski wrote:
> I'm trying to figure out a way of getting rid of an incorrect lockdep
> deadlock warning, but the issue is not trivial.
>
> In our hardware an I2C multiplexer is controlled by a GPIO provided by
> an expander. There's a second expander using the same device driver
> (pca953x) on one of the I2C bus segments. The diagram below presents
> the setup:
>
> - - - - -
> ------- --------- Bus segment 1 | |
> | | | |--------------- Devices
> | | SCL/SDA | | | |
> | Linux |-----------| I2C MUX | - - - - -
> | | | | | Bus segment 2
> | | | | |-------------------
> ------- | --------- |
> | | - - - - -
> ------------ | MUX GPIO | |
> | | | Devices
> | GPIO | | | |
> | Expander 1 |---- - - - - -
> | | |
> ------------ | SCL/SDA
> |
> ------------
> | |
> | GPIO |
> | Expander 2 |
> | |
> ------------
> Using mutex_lock_nested(&chip->i2c_lock, SINGLE_DEPTH_NESTING) in
> pca953x_gpio_get_value() and pca953x_gpio_direction_input/output()
> helps for reading the values or setting the direction, but doesn't do
> anything if used in pca953x_gpio_set_value() since we still end up
> taking the lock of the same subclass again.
>
> It would require some nasty hacks to figure out that a GPIO is being
> used by an I2C mux if we wanted to explicitly provide a different
> sublass in this case, but that would not fix the culprit, since the
> same problem would occur in other gpio drivers under similar
> circumstances.
>
> It seems the problem is with the way lockdep works, but I lack the
> knowledge to propose any solution.
>
> Any help & ideas are appreciated.
So I'm entirely clueless on how the device model works let alone i2c
and/or gpio. So I'm going to need some help as well. What's an SCL/SDA
for instance?
So the 'problem' is that pca953x_probe()'s mutex_init() will collapse
all mutexes it initializes into a single class. It assumes that the
locking rules for all instances will be the same.
This happens to not be true in this case.
The tricky part, and here I have absolutely no clue what so ever, is
being able to tell at pca953x_probe() time that this is so.
Once we can tell, at probe time, there are two different annotations we
could use, depending on need.
I suppose that theoretically you can keep nesting like that ad
infinitum, but I also expect that its uncommon enough, and maybe not
practical, to really nest like this -- seeing this is the first instance
of such issues.
In any case, can you tell at probe time? And how deep a nesting should
we worry about?
Seeing how this lock is specific to the driver, and there is no generic
infrastructure, I don't see how we could solve it other than on a
per-driver basis.
next prev parent reply other threads:[~2016-09-12 12:09 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-12 11:51 Bartosz Golaszewski
2016-09-12 12:09 ` Peter Zijlstra [this message]
2016-09-12 15:16 ` Bartosz Golaszewski
2016-09-12 15:33 ` Peter Zijlstra
2016-09-13 12:29 ` Linus Walleij
2016-09-15 7:51 ` Peter Zijlstra
2016-09-15 12:41 ` Linus Walleij
2016-09-15 13:20 ` Bartosz Golaszewski
2016-09-15 13:39 ` Peter Zijlstra
2016-09-15 14:08 ` Bartosz Golaszewski
2016-09-15 14:38 ` Peter Zijlstra
2016-09-15 15:23 ` Bartosz Golaszewski
2016-09-16 10:56 ` Peter Zijlstra
2016-09-16 11:14 ` Bartosz Golaszewski
2016-09-16 12:00 ` Bartosz Golaszewski
2016-09-16 14:21 ` Bartosz Golaszewski
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=20160912120938.GR10153@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bgolaszewski@baylibre.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.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
Powered by JetHome