All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Steven Rostedt <rostedt@goodmis.org>,
	Paul McKenney <paulmck@linux.vnet.ibm.com>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: check && lockdep_no_validate (Was: lockdep: Introduce wait-type checks)
Date: Thu, 16 Jan 2014 18:43:48 +0100	[thread overview]
Message-ID: <20140116174348.GA17614@redhat.com> (raw)
In-Reply-To: <20140113160705.GA7616@redhat.com>

On 01/13, Oleg Nesterov wrote:
>
> On 01/12, Peter Zijlstra wrote:
> >
> > On Thu, Jan 09, 2014 at 06:54:48PM +0100, Oleg Nesterov wrote:
> > >
> > > --- a/kernel/locking/lockdep.c
> > > +++ b/kernel/locking/lockdep.c
> > > @@ -1939,7 +1939,8 @@ check_prevs_add(struct task_struct *curr, struct held_lock *next)
> > >  		 * Only non-recursive-read entries get new dependencies
> > >  		 * added:
> > >  		 */
> > > -		if (hlock->read != 2) {
> > > +		if (hlock->read != 2 &&
> > > +		    hlock->instance->key != &__lockdep_no_validate__) {
> > >  			if (!check_prev_add(curr, hlock, next,
> > >  						distance, trylock_loop))
> > >  				return 0;
> > >
> >
> > Hmm, you are quite right indeed;
>
> Thanks!
>
> > although I would write it like:
> >
> >   if (hlock->read != 2 && hlock->check == 2)
> >
> > because the __lockdep_no_validate__ thing forces the ->check value to 1.
>
> Agreed, hlock->check == 2 looks better. But this connects to another
> patch I sent which removes hlock->check...
>
> OK, I'll wait for review on that patch, then resend this one with
> ->check or __lockdep_no_validate__ depending on the result.

And I still think that we should try to remove hlock->check, but
please forget about this for the moment. I'll try to send some
patches later in any case.


OK, lets suppose we do the change above using ->key or ->check,
doesn't matter. This will fix the already discussed pattern:

		static DEFINE_MUTEX(m1);
		static DEFINE_MUTEX(m2);
		static DEFINE_MUTEX(mx);

		lockdep_set_novalidate_class(&mx);

		// m1 -> mx -> m2
		mutex_lock(&m1);
		mutex_lock(&mx);
		mutex_lock(&m2);
		mutex_unlock(&m2);
		mutex_unlock(&mx);
		mutex_unlock(&m1);

		// m2 -> m1 ; should trigger the warning
		mutex_lock(&m2);
		mutex_lock(&m1);
		mutex_unlock(&m1);
		mutex_unlock(&m2);

before this change lockdep can't detect the trivial deadlock.

But with or without this change the following code

		static DEFINE_MUTEX(m1);
		static DEFINE_MUTEX(mx);

		lockdep_set_novalidate_class(&mx);

		// m1 -> mx
		mutex_lock(&m1);
		mutex_lock(&mx);
		mutex_unlock(&mx);
		mutex_unlock(&m1);

		// mx -> m1 ; should trigger the warning ???
		mutex_lock(&mx);
		mutex_lock(&m1);
		mutex_unlock(&m1);
		mutex_unlock(&mx);

doesn't trigger the warning too. This is correct because
lockdep_set_novalidate_class() means, well, no-validate.
The question is: do we really want to avoid all validations?

Why lockdep_set_novalidate_class() was added? Unlees I missed
something the problem is that (say) __driver_attach() can take
the "same" lock twice, drivers/base/ lacks annotations.

Perhaps we should change the meaning of lockdep_set_novalidate_class?
(perhaps with rename). What do you think about the patch below?

With this patch __lockdep_no_validate__ means "automatically nested",
although I have to remind I can hardly understand the code I am
trying to change ;)

Oleg.

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 576ba75..844d25d 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -2515,9 +2515,6 @@ mark_held_locks(struct task_struct *curr, enum mark_type mark)
 
 		BUG_ON(usage_bit >= LOCK_USAGE_STATES);
 
-		if (hlock_class(hlock)->key == __lockdep_no_validate__.subkeys)
-			continue;
-
 		if (!mark_lock(curr, hlock, usage_bit))
 			return 0;
 	}
@@ -3067,8 +3064,15 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
 	if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
 		return 0;
 
-	if (lock->key == &__lockdep_no_validate__)
-		check = 1;
+	if (lock->key == &__lockdep_no_validate__) {
+		int i;
+
+		for (i = curr->lockdep_depth; --i >= 0; ) {
+			hlock = curr->held_locks + i;
+			if (hlock->instance->key == lock->key)
+				goto nested;
+		}
+	}
 
 	if (subclass < NR_LOCKDEP_CACHING_CLASSES)
 		class = lock->class_cache[subclass];
@@ -3106,6 +3110,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
 	if (depth) {
 		hlock = curr->held_locks + depth - 1;
 		if (hlock->class_idx == class_idx && nest_lock) {
+nested:
 			if (hlock->references)
 				hlock->references++;
 			else
@@ -3282,8 +3287,9 @@ static int match_held_lock(struct held_lock *hlock, struct lockdep_map *lock)
 		 * References, but not a lock we're actually ref-counting?
 		 * State got messed up, follow the sites that change ->references
 		 * and try to make sense of it.
+		 * FIXME: s/0/novalidate/ ?
 		 */
-		if (DEBUG_LOCKS_WARN_ON(!hlock->nest_lock))
+		if (DEBUG_LOCKS_WARN_ON(0 && !hlock->nest_lock))
 			return 0;
 
 		if (hlock->class_idx == class - lock_classes + 1)


  reply	other threads:[~2014-01-16 17:44 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-09 11:15 [RFC][PATCH] lockdep: Introduce wait-type checks Peter Zijlstra
2014-01-09 11:49 ` Peter Zijlstra
2014-01-09 16:31 ` Oleg Nesterov
2014-01-09 17:08   ` Peter Zijlstra
2014-01-09 17:54     ` check && lockdep_no_validate (Was: lockdep: Introduce wait-type checks) Oleg Nesterov
2014-01-12 20:58       ` Peter Zijlstra
2014-01-13 16:07         ` Oleg Nesterov
2014-01-16 17:43           ` Oleg Nesterov [this message]
2014-01-16 18:09             ` Peter Zijlstra
2014-01-16 20:26               ` Alan Stern
2014-01-17 16:31                 ` Oleg Nesterov
2014-01-17 18:01                   ` Alan Stern
2014-01-20 18:19                     ` [PATCH 0/5] lockdep: (Was: check && lockdep_no_validate) Oleg Nesterov
2014-01-20 18:20                       ` [PATCH 1/5] lockdep: make held_lock->check and "int check" argument bool Oleg Nesterov
2014-02-10 13:32                         ` [tip:core/locking] lockdep: Make " tip-bot for Oleg Nesterov
2014-01-20 18:20                       ` [PATCH 2/5] lockdep: don't create the wrong dependency on hlock->check == 0 Oleg Nesterov
2014-02-10 13:33                         ` [tip:core/locking] lockdep: Don' t " tip-bot for Oleg Nesterov
2014-01-20 18:20                       ` [PATCH 3/5] lockdep: change mark_held_locks() to check hlock->check instead of lockdep_no_validate Oleg Nesterov
2014-02-10 13:33                         ` [tip:core/locking] lockdep: Change " tip-bot for Oleg Nesterov
2014-01-20 18:20                       ` [PATCH 4/5] lockdep: change lockdep_set_novalidate_class() to use _and_name Oleg Nesterov
2014-02-10 13:33                         ` [tip:core/locking] lockdep: Change " tip-bot for Oleg Nesterov
2014-01-20 18:20                       ` [PATCH 5/5] lockdep: pack subclass/trylock/read/check into a single argument Oleg Nesterov
2014-01-21 14:10                         ` Peter Zijlstra
2014-01-21 17:27                           ` Oleg Nesterov
2014-01-21 17:35                           ` Dave Jones
2014-01-21 18:43                             ` Oleg Nesterov
2014-01-21 18:53                               ` Steven Rostedt
2014-01-21 20:06                                 ` Oleg Nesterov
2014-01-21 19:39                               ` uninline rcu_lock_acquire/etc ? Oleg Nesterov
2014-01-22  3:54                                 ` Paul E. McKenney
2014-01-22 18:31                                   ` Oleg Nesterov
2014-01-22 19:34                                     ` Paul E. McKenney
2014-01-22 19:39                                       ` Oleg Nesterov
2014-01-20 18:37                       ` [PATCH 0/5] lockdep: (Was: check && lockdep_no_validate) Alan Stern
2014-01-20 18:54                         ` Oleg Nesterov
2014-01-20 21:42                           ` Alan Stern
2014-01-12  9:40     ` [RFC][PATCH] lockdep: Introduce wait-type checks Ingo Molnar
2014-01-12 17:45       ` [PATCH 0/1] lockdep: Kill held_lock->check and "int check" arg of __lock_acquire() Oleg Nesterov
2014-01-12 17:45         ` [PATCH 1/1] " Oleg Nesterov
2014-01-13  0:28           ` Dave Jones
2014-01-13 16:20             ` Oleg Nesterov
2014-01-13 17:06           ` Oleg Nesterov
2014-01-13 17:28             ` Peter Zijlstra
2014-01-13 18:52               ` Oleg Nesterov
2014-01-13 22:34               ` Paul E. McKenney
2014-01-12 20:00         ` [PATCH 0/1] " Peter Zijlstra
2014-01-13 18:35           ` Oleg Nesterov
2014-01-09 17:33 ` [RFC][PATCH] lockdep: Introduce wait-type checks Dave Jones
2014-01-09 22:12   ` Peter Zijlstra
2014-01-10 12:11   ` 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=20140116174348.GA17614@redhat.com \
    --to=oleg@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.