From: Peter Rosin <peda@axentia.se>
To: linux-kernel@vger.kernel.org
Cc: Peter Rosin <peda@axentia.se>, Wolfram Sang <wsa@the-dreams.de>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Will Deacon <will.deacon@arm.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Davidlohr Bueso <dave@stgolabs.net>,
linux-i2c@vger.kernel.org, Peter Chang <dpf@google.com>,
Deepa Dinamani <deepadinamani@google.com>,
John Sperbeck <jsperbeck@google.com>
Subject: Re: Problem: lockdep warning with nested instances of i2c-mux
Date: Thu, 24 May 2018 09:32:53 +0200 [thread overview]
Message-ID: <20180524073255.22495-1-peda@axentia.se> (raw)
In-Reply-To: <CAFNjLiXZk3Zigfpy9Hj2uY92sPGB7msUxoZHf6pFDOWSuBwkBA@mail.gmail.com>
On 2018-05-24 04:25, John Sperbeck wrote:
> If an i2c topology has instances of nested muxes, then a lockdep splat
> is produced when when i2c_parent_lock_bus() is called. Here is an
> example:
>
> ============================================
> WARNING: possible recursive locking detected
> --------------------------------------------
> insmod/68159 is trying to acquire lock:
> (i2c_register_adapter#2){+.+.}, at: i2c_parent_lock_bus+0x32/0x50 [i2c_mux]
>
> but task is already holding lock:
> (i2c_register_adapter#2){+.+.}, at: i2c_parent_lock_bus+0x32/0x50 [i2c_mux]
>
> other info that might help us debug this:
> Possible unsafe locking scenario:
>
> CPU0
> ----
> lock(i2c_register_adapter#2);
> lock(i2c_register_adapter#2);
>
> *** DEADLOCK ***
>
> May be due to missing lock nesting notation
>
> 1 lock held by insmod/68159:
> #0: (i2c_register_adapter#2){+.+.}, at: i2c_parent_lock_bus+0x32/0x50
> [i2c_mux]
>
> stack backtrace:
> CPU: 13 PID: 68159 Comm: insmod Tainted: G O
> Call Trace:
> dump_stack+0x67/0x98
> __lock_acquire+0x162e/0x1780
> lock_acquire+0xba/0x200
> rt_mutex_lock+0x44/0x60
> i2c_parent_lock_bus+0x32/0x50 [i2c_mux]
> i2c_parent_lock_bus+0x3e/0x50 [i2c_mux]
> i2c_smbus_xfer+0xf0/0x700
> i2c_smbus_read_byte+0x42/0x70
> my2c_init+0xa2/0x1000 [my2c]
> do_one_initcall+0x51/0x192
> do_init_module+0x62/0x216
> load_module+0x20f9/0x2b50
> SYSC_init_module+0x19a/0x1c0
> SyS_init_module+0xe/0x10
> do_syscall_64+0x6c/0x1a0
> entry_SYSCALL_64_after_hwframe+0x42/0xb7
>
>
> The warning makes sense from the lockdep detector's point-of-view because
> we are locking two instances of a single lock class. Normally, this would
> be addressed by using 'nested' variants of locks. But rt_mutex doesn't
> expose an API for that, and it's not clear how i2c-mux can know what level
> of nesting it's at anyway.
Yes, when I modified the i2c-mux locking a couple of years ago, I also
noted the absense, and even tried to implement it, but eventually gave
up. However, that was before lockdep could even track rt_mutexes. Now
it looks easy, and I will follow up with a couple of patches (only
compile-tested, please test).
> In short, I don't have an easy patch to suggest. But I'm not very
> familiar with the i2c code, and maybe I'm overlooking something that
> would help?
>
> I have code for a module that emulates a chain of an i2c adapter, two
> muxes, and a slave device to show the problem. On my system, with a
> kernel compiled with lockdep enabled, loading the module produces the
> splat. I can post it, if the issue isn't clear from my description.
Not needed, the issue is known, I just wasn't aware that lockdep had
grown knowledge of rt-mutexes.
Thanks for the report!
Cheers,
Peter
Peter Rosin (2):
rtmutex: allow specifying a subclass for nested locking
i2c: mux: annotate the nested rt_mutex usage
drivers/i2c/i2c-core-base.c | 2 +-
drivers/i2c/i2c-mux.c | 4 ++--
include/linux/rtmutex.h | 6 ++++++
kernel/locking/rtmutex.c | 29 +++++++++++++++++++++++++----
4 files changed, 34 insertions(+), 7 deletions(-)
--
2.11.0
next parent reply other threads:[~2018-05-24 7:32 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAFNjLiXZk3Zigfpy9Hj2uY92sPGB7msUxoZHf6pFDOWSuBwkBA@mail.gmail.com>
2018-05-24 7:32 ` Peter Rosin [this message]
2018-05-24 7:32 ` [PATCH 1/2] rtmutex: allow specifying a subclass for nested locking Peter Rosin
2018-05-26 8:23 ` kbuild test robot
2018-05-26 8:23 ` kbuild test robot
2018-05-26 9:26 ` kbuild test robot
2018-05-24 7:32 ` [PATCH 2/2] i2c: mux: annotate the nested rt_mutex usage Peter Rosin
2018-05-26 10:11 ` kbuild test robot
2018-05-24 8:46 ` [PATCH v2 0/2] Re: Problem: lockdep warning with nested instances of i2c-mux Peter Rosin
2018-05-24 8:46 ` [PATCH v2 1/2] rtmutex: allow specifying a subclass for nested locking Peter Rosin
2018-05-24 8:46 ` [PATCH v2 2/2] i2c: mux: annotate the nested rt_mutex usage Peter Rosin
2018-05-24 13:52 ` [PATCH v3 0/2] Re: Problem: lockdep warning with nested instances of i2c-mux Peter Rosin
2018-05-24 13:52 ` [PATCH v3 1/2] rtmutex: allow specifying a subclass for nested locking Peter Rosin
2018-05-28 5:19 ` Joel Fernandes
2018-05-28 7:17 ` Peter Zijlstra
2018-05-28 20:51 ` Joel Fernandes
2018-05-24 13:52 ` [PATCH v3 2/2] i2c: mux: annotate the nested rt_mutex usage Peter Rosin
2018-05-24 18:21 ` [PATCH v3 0/2] Re: Problem: lockdep warning with nested instances of i2c-mux John Sperbeck
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=20180524073255.22495-1-peda@axentia.se \
--to=peda@axentia.se \
--cc=akpm@linux-foundation.org \
--cc=dave@stgolabs.net \
--cc=deepadinamani@google.com \
--cc=dpf@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=jsperbeck@google.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=will.deacon@arm.com \
--cc=wsa@the-dreams.de \
/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