linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Alfredo Alvarez Fernandez <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: hpa@zytor.com, tglx@linutronix.de, linux-kernel@vger.kernel.org,
	alfredoalvarezfernandez@gmail.com, mingo@kernel.org,
	torvalds@linux-foundation.org, peterz@infradead.org
Subject: [tip:core/urgent] locking/lockdep: Print chain_key collision information
Date: Thu, 31 Mar 2016 23:36:43 -0700	[thread overview]
Message-ID: <tip-39e2e173fb1f900959d3a25c21c65fa88b06c6ee@git.kernel.org> (raw)
In-Reply-To: <1459357416-19190-1-git-send-email-alfredoalvarezernandez@gmail.com>

Commit-ID:  39e2e173fb1f900959d3a25c21c65fa88b06c6ee
Gitweb:     http://git.kernel.org/tip/39e2e173fb1f900959d3a25c21c65fa88b06c6ee
Author:     Alfredo Alvarez Fernandez <alfredoalvarezfernandez@gmail.com>
AuthorDate: Wed, 30 Mar 2016 19:03:36 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 31 Mar 2016 15:03:58 +0200

locking/lockdep: Print chain_key collision information

A sequence of pairs [class_idx -> corresponding chain_key iteration]
is printed for both the current held_lock chain and the cached chain.

That exposes the two different class_idx sequences that led to that
particular hash value.

This helps with debugging hash chain collision reports.

Signed-off-by: Alfredo Alvarez Fernandez <alfredoalvarezfernandez@gmail.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-fsdevel@vger.kernel.org
Cc: sedat.dilek@gmail.com
Cc: tytso@mit.edu
Link: http://lkml.kernel.org/r/1459357416-19190-1-git-send-email-alfredoalvarezernandez@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/locking/lockdep.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 77 insertions(+), 2 deletions(-)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 53ab2f8..2324ba5 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -2000,6 +2000,77 @@ static inline int get_first_held_lock(struct task_struct *curr,
 }
 
 /*
+ * Returns the next chain_key iteration
+ */
+static u64 print_chain_key_iteration(int class_idx, u64 chain_key)
+{
+	u64 new_chain_key = iterate_chain_key(chain_key, class_idx);
+
+	printk(" class_idx:%d -> chain_key:%016Lx",
+		class_idx,
+		(unsigned long long)new_chain_key);
+	return new_chain_key;
+}
+
+static void
+print_chain_keys_held_locks(struct task_struct *curr, struct held_lock *hlock_next)
+{
+	struct held_lock *hlock;
+	u64 chain_key = 0;
+	int depth = curr->lockdep_depth;
+	int i;
+
+	printk("depth: %u\n", depth + 1);
+	for (i = get_first_held_lock(curr, hlock_next); i < depth; i++) {
+		hlock = curr->held_locks + i;
+		chain_key = print_chain_key_iteration(hlock->class_idx, chain_key);
+
+		print_lock(hlock);
+	}
+
+	print_chain_key_iteration(hlock_next->class_idx, chain_key);
+	print_lock(hlock_next);
+}
+
+static void print_chain_keys_chain(struct lock_chain *chain)
+{
+	int i;
+	u64 chain_key = 0;
+	int class_id;
+
+	printk("depth: %u\n", chain->depth);
+	for (i = 0; i < chain->depth; i++) {
+		class_id = chain_hlocks[chain->base + i];
+		chain_key = print_chain_key_iteration(class_id + 1, chain_key);
+
+		print_lock_name(lock_classes + class_id);
+		printk("\n");
+	}
+}
+
+static void print_collision(struct task_struct *curr,
+			struct held_lock *hlock_next,
+			struct lock_chain *chain)
+{
+	printk("\n");
+	printk("======================\n");
+	printk("[chain_key collision ]\n");
+	print_kernel_ident();
+	printk("----------------------\n");
+	printk("%s/%d: ", current->comm, task_pid_nr(current));
+	printk("Hash chain already cached but the contents don't match!\n");
+
+	printk("Held locks:");
+	print_chain_keys_held_locks(curr, hlock_next);
+
+	printk("Locks in cached chain:");
+	print_chain_keys_chain(chain);
+
+	printk("\nstack backtrace:\n");
+	dump_stack();
+}
+
+/*
  * Checks whether the chain and the current held locks are consistent
  * in depth and also in content. If they are not it most likely means
  * that there was a collision during the calculation of the chain_key.
@@ -2014,14 +2085,18 @@ static int check_no_collision(struct task_struct *curr,
 
 	i = get_first_held_lock(curr, hlock);
 
-	if (DEBUG_LOCKS_WARN_ON(chain->depth != curr->lockdep_depth - (i - 1)))
+	if (DEBUG_LOCKS_WARN_ON(chain->depth != curr->lockdep_depth - (i - 1))) {
+		print_collision(curr, hlock, chain);
 		return 0;
+	}
 
 	for (j = 0; j < chain->depth - 1; j++, i++) {
 		id = curr->held_locks[i].class_idx - 1;
 
-		if (DEBUG_LOCKS_WARN_ON(chain_hlocks[chain->base + j] != id))
+		if (DEBUG_LOCKS_WARN_ON(chain_hlocks[chain->base + j] != id)) {
+			print_collision(curr, hlock, chain);
 			return 0;
+		}
 	}
 #endif
 	return 1;

  parent reply	other threads:[~2016-04-01  6:37 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-bot for Alfredo Alvarez Fernandez [this message]
2016-05-10  9:09                   ` [tip:core/urgent] locking/lockdep: Print " 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:locking/urgent] lockdep: Fix lock_chain::base size tip-bot for Peter Zijlstra

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-39e2e173fb1f900959d3a25c21c65fa88b06c6ee@git.kernel.org \
    --to=tipbot@zytor.com \
    --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=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).