mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCH] lockdep: make print_lock_name() robust against non-existing lock_class
Date: Wed, 15 Apr 2015 16:14:40 +0200	[thread overview]
Message-ID: <20150415141440.GQ23123@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1429104276-22412-1-git-send-email-bigeasy@linutronix.de>

On Wed, Apr 15, 2015 at 03:24:36PM +0200, Sebastian Andrzej Siewior wrote:
> During sysrq's show-held-locks command it is possible that hlock_class()
> returns NULL for a given lock. The result is then (after the warning):
> 
> |BUG: unable to handle kernel NULL pointer dereference at 0000001c
> |IP: [<c1088145>] get_usage_chars+0x5/0x100
> |Call Trace:
> | [<c1088263>] print_lock_name+0x23/0x60
> | [<c1576b57>] print_lock+0x5d/0x7e
> | [<c1088314>] lockdep_print_held_locks+0x74/0xe0
> | [<c1088652>] debug_show_all_locks+0x132/0x1b0
> | [<c1315c48>] sysrq_handle_showlocks+0x8/0x10
> 
> This *might* happen because the thread on the other CPU drops the lock
> after we are looking ->lockdep_depth and ->held_locks points no longer
> to a lock that is held.
> The fix here is to simply ignore it and continue.

Hmm, but in that case we might equally run into the hlock_class() debug
check which would kill all of lockdep.

Note that lock_release_nested() with CONFIG_DEBUG_LOCKDEP will actually
clear those fields.

Would something like the below work for you?

---
 kernel/locking/lockdep.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index ba77ab5f64dd..0ef89f830ff4 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -551,7 +551,18 @@ static void print_lockdep_cache(struct lockdep_map *lock)
 
 static void print_lock(struct held_lock *hlock)
 {
-	print_lock_name(hlock_class(hlock));
+	/*
+	 * We can be called locklessly through debug_show_all_locks() so be
+	 * extra careful, the hlock might have been released and cleared.
+	 */
+	unsigned int class_idx = READ_ONCE(hlock->class_idx);
+
+	if (!class_idx || (class_idx - 1) >= MAX_LOCKDEP_KEYS) {
+		printk("<RELEASED>\n");
+		return;
+	}
+
+	print_lock_name(lock_classes + class_idx - 1);
 	printk(", at: ");
 	print_ip_sym(hlock->acquire_ip);
 }

  reply	other threads:[~2015-04-15 14:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-15 13:24 Sebastian Andrzej Siewior
2015-04-15 14:14 ` Peter Zijlstra [this message]
2015-04-16 14:50   ` Sebastian Andrzej Siewior
2015-04-16 15:35     ` Peter Zijlstra
2015-04-16 15:39       ` Sebastian Andrzej Siewior
2015-04-16 15:50         ` 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=20150415141440.GQ23123@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=bigeasy@linutronix.de \
    --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