From: tip-bot for Peter Zijlstra <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: paulmck@linux.vnet.ibm.com, tglx@linutronix.de,
peterz@infradead.org, hpa@zytor.com,
alfredoalvarezfernandez@gmail.com, sedat.dilek@gmail.com,
mingo@kernel.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, tytso@mit.edu,
torvalds@linux-foundation.org
Subject: [tip:locking/urgent] lockdep: Fix lock_chain::base size
Date: Sat, 23 Apr 2016 05:54:24 -0700 [thread overview]
Message-ID: <tip-75dd602a5198a6e5f75534db52b6e6fbaabb33d1@git.kernel.org> (raw)
In-Reply-To: <20160330093659.GS3408@twins.programming.kicks-ass.net>
Commit-ID: 75dd602a5198a6e5f75534db52b6e6fbaabb33d1
Gitweb: http://git.kernel.org/tip/75dd602a5198a6e5f75534db52b6e6fbaabb33d1
Author: Peter Zijlstra <peterz@infradead.org>
AuthorDate: Wed, 30 Mar 2016 11:36:59 +0200
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Sat, 23 Apr 2016 13:53:03 +0200
lockdep: Fix lock_chain::base size
lock_chain::base is used to store an index into the chain_hlocks[]
array, however that array contains more elements than can be indexed
using the u16.
Change the lock_chain structure to use a bitfield to encode the data
it needs and add BUILD_BUG_ON() assertions to check the fields are
wide enough.
Also, for DEBUG_LOCKDEP, assert that we don't run out of elements of
that array; as that would wreck the collision detectoring.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alfredo Alvarez Fernandez <alfredoalvarezfernandez@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sedat Dilek <sedat.dilek@gmail.com>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20160330093659.GS3408@twins.programming.kicks-ass.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
include/linux/lockdep.h | 8 +++++---
kernel/locking/lockdep.c | 24 +++++++++++++++++++++++-
kernel/locking/lockdep_proc.c | 2 ++
3 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index d026b19..d10ef06 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -196,9 +196,11 @@ struct lock_list {
* We record lock dependency chains, so that we can cache them:
*/
struct lock_chain {
- u8 irq_context;
- u8 depth;
- u16 base;
+ /* see BUILD_BUG_ON()s in lookup_chain_cache() */
+ unsigned int irq_context : 2,
+ depth : 6,
+ base : 24;
+ /* 4 byte hole */
struct hlist_node entry;
u64 chain_key;
};
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index beb06f6..78c1c0e 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -2176,15 +2176,37 @@ cache_hit:
chain->irq_context = hlock->irq_context;
i = get_first_held_lock(curr, hlock);
chain->depth = curr->lockdep_depth + 1 - i;
+
+ BUILD_BUG_ON((1UL << 24) <= ARRAY_SIZE(chain_hlocks));
+ BUILD_BUG_ON((1UL << 6) <= ARRAY_SIZE(curr->held_locks));
+ BUILD_BUG_ON((1UL << 8*sizeof(chain_hlocks[0])) <= ARRAY_SIZE(lock_classes));
+
if (likely(nr_chain_hlocks + chain->depth <= MAX_LOCKDEP_CHAIN_HLOCKS)) {
chain->base = nr_chain_hlocks;
- nr_chain_hlocks += chain->depth;
for (j = 0; j < chain->depth - 1; j++, i++) {
int lock_id = curr->held_locks[i].class_idx - 1;
chain_hlocks[chain->base + j] = lock_id;
}
chain_hlocks[chain->base + j] = class - lock_classes;
}
+
+ if (nr_chain_hlocks < MAX_LOCKDEP_CHAIN_HLOCKS)
+ nr_chain_hlocks += chain->depth;
+
+#ifdef CONFIG_DEBUG_LOCKDEP
+ /*
+ * Important for check_no_collision().
+ */
+ if (unlikely(nr_chain_hlocks > MAX_LOCKDEP_CHAIN_HLOCKS)) {
+ if (debug_locks_off_graph_unlock())
+ return 0;
+
+ print_lockdep_off("BUG: MAX_LOCKDEP_CHAIN_HLOCKS too low!");
+ dump_stack();
+ return 0;
+ }
+#endif
+
hlist_add_head_rcu(&chain->entry, hash_head);
debug_atomic_inc(chain_lookup_misses);
inc_chains();
diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
index dbb61a3..a0f61ef 100644
--- a/kernel/locking/lockdep_proc.c
+++ b/kernel/locking/lockdep_proc.c
@@ -141,6 +141,8 @@ static int lc_show(struct seq_file *m, void *v)
int i;
if (v == SEQ_START_TOKEN) {
+ if (nr_chain_hlocks > MAX_LOCKDEP_CHAIN_HLOCKS)
+ seq_printf(m, "(buggered) ");
seq_printf(m, "all lock chains:\n");
return 0;
}
prev parent reply other threads:[~2016-04-23 12:55 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-27 8:15 [Linux-v4.6-rc1] ext4: WARNING: CPU: 2 PID: 2692 at kernel/locking/lockdep.c:2017 __lock_acquire+0x180e/0x2260 Sedat Dilek
2016-03-27 8:57 ` Sedat Dilek
2016-03-27 12:03 ` Linus Torvalds
2016-03-27 13:32 ` Boqun Feng
2016-03-27 18:23 ` Theodore Ts'o
2016-03-27 19:40 ` Sedat Dilek
[not found] ` <CA+55aFwoKRpgq8OCTxUaP+8gOg-mnN3nbruYgiK32a=C5U4TkQ@mail.gmail.com>
2016-03-27 20:24 ` Sedat Dilek
2016-03-27 20:48 ` Peter Zijlstra
2016-03-27 20:59 ` Sedat Dilek
2016-03-27 21:48 ` Sedat Dilek
2016-03-28 1:05 ` Boqun Feng
2016-03-28 6:33 ` Peter Zijlstra
2016-03-29 8:47 ` Ingo Molnar
2016-03-30 9:20 ` Sedat Dilek
2016-03-30 9:36 ` Sedat Dilek
2016-03-30 9:36 ` Peter Zijlstra
2016-03-30 9:49 ` Sedat Dilek
2016-03-30 10:33 ` Sedat Dilek
2016-03-30 12:43 ` Peter Zijlstra
2016-03-30 12:46 ` Sedat Dilek
2016-03-30 13:15 ` Peter Zijlstra
2016-03-30 9:50 ` Peter Zijlstra
2016-03-30 9:59 ` Boqun Feng
2016-03-30 10:36 ` Peter Zijlstra
2016-03-30 11:07 ` Sedat Dilek
2016-03-31 15:42 ` Peter Zijlstra
2016-03-31 15:52 ` Boqun Feng
2016-04-02 6:26 ` Sedat Dilek
2016-03-30 14:06 ` Peter Zijlstra
2016-03-30 15:21 ` Sedat Dilek
2016-03-30 17:03 ` [PATCH] lockdep: print chain_key collision information Alfredo Alvarez Fernandez
2016-03-30 17:19 ` Peter Zijlstra
2016-04-01 6:36 ` [tip:core/urgent] locking/lockdep: Print " tip-bot for Alfredo Alvarez Fernandez
2016-05-10 9:09 ` Peter Zijlstra
2016-04-04 15:31 ` [Linux-v4.6-rc1] ext4: WARNING: CPU: 2 PID: 2692 at kernel/locking/lockdep.c:2017 __lock_acquire+0x180e/0x2260 Sedat Dilek
2016-04-04 16:02 ` Peter Zijlstra
2016-05-09 11:37 ` Sedat Dilek
2016-06-03 15:15 ` Sedat Dilek
2016-04-23 12:54 ` tip-bot for Peter Zijlstra [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=tip-75dd602a5198a6e5f75534db52b6e6fbaabb33d1@git.kernel.org \
--to=tipbot@zytor.com \
--cc=akpm@linux-foundation.org \
--cc=alfredoalvarezfernandez@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=sedat.dilek@gmail.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=tytso@mit.edu \
/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;
as well as URLs for NNTP newsgroup(s).