[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1217876046.3589.61.camel@twins>
Date: Mon, 04 Aug 2008 20:54:06 +0200
From: Peter Zijlstra <a.p.zijlstra@...llo.nl>
To: Jeremy Fitzhardinge <jeremy@...p.org>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
David Miller <davem@...emloft.net>, hugh@...itas.com,
mingo@...e.hu, akpm@...ux-foundation.org,
linux-kernel@...r.kernel.org, davej@...hat.com
Subject: Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock()
On Mon, 2008-08-04 at 11:06 -0700, Jeremy Fitzhardinge wrote:
> Peter Zijlstra wrote:
> > Expose the new lock protection lock.
> >
> > This can be used to annotate places where we take multiple locks of the
> > same class and avoid deadlocks by always taking another (top-level) lock
> > first.
> >
>
> OK, so the expected usage is:
>
> spin_lock(&outer_lock);
> /* take in any order */
> spin_lock_nest_lock(&inner[0], &outer_lock);
> spin_lock_nest_lock(&inner[2], &outer_lock);
> spin_lock_nest_lock(&inner[1], &outer_lock);
> ...
>
> ?
Yes (there it no requirement that the outer lock is a spinlock_t, just
that it has a ->dep_map member - so: mutex, rwsem and spinlock will do).
> And it's OK to
>
> 1. take inner locks one at a time without holding the outer lock
Yes
> 2. use plain spin_lock on inner locks when you're taking them one at
> a time, and
Yes
> 3. release the outer lock before releasing the inner locks
Only if you then release the inner locks in the reverse order you took
them - the nested release code (releasing a lock that is not on the top
of the stack) basically pops and pushes all the locks, the push will
fail if the outer lock is released.
> but it's not OK to try to use different outer locks for a given inner lock.
It doesn't validate this part - as with most lockdep annotations you can
annotate away real deadlocks.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists