Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock()

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linus Torvalds
Date: Wednesday, October 8, 2008 - 8:43 am

On Wed, 8 Oct 2008, Steven Rostedt wrote:

No it is not.

Unlocking locks in non-nested order can sometimes be very much the rigth 
thing to do, and thinking otherwise is (a) naive and (b) can generate 
totally unnecessary and pointless bugs.

The thing is, sometimes you have to do it, and imposing totally made-up 
rules ("unlocks have to nest") just confuses everybody.

The FACT is, that unlocks do not have to nest cleanly. That's a rock solid 
*FACT*. The locking order matters, and the unlocking order does not.

And if you cannot accept that as a fact, and you then say "unlock order 
should matter just to keep things nice and clean", then you end up being 
screwed and/or confused when you can't hold to the unlock order.

There are many perfectly valid reasons not to unlock in reverse order. 
Don't create make-believe rules that break those reasons for no gain.

For example:
 - let's say that you have a singly-linked list of objects.
 - you need to lock all objects, do something, and then unlock all 
   objects.
 - the *only* sane way to do that is to just traverse the list twice.
 - that means that you will unlock the objects in the same order you 
   locked them, _not_ in reverse ("nested") order.
 - if you force a rule of "unlocks must be nested", then

	YOU ARE A F*CKING MORON.

It's that simple. Don't do made-up rules that have no technical reason for 
them. 

Lock ordering matters. Unlock ordering does not. It really is that simple. 
Don't confuse the issue by claiming anything else.

		Linus
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Peter Zijlstra, (Mon Aug 4, 6:03 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Roland Dreier, (Mon Aug 4, 7:07 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Peter Zijlstra, (Mon Aug 4, 7:19 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Roland Dreier, (Mon Aug 4, 7:26 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Peter Zijlstra, (Mon Aug 4, 7:32 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Dave Jones, (Mon Aug 4, 7:53 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Peter Zijlstra, (Mon Aug 4, 7:56 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Andrea Arcangeli, (Mon Aug 4, 9:26 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Peter Zijlstra, (Mon Aug 4, 9:38 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Andrea Arcangeli, (Mon Aug 4, 10:27 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Andrea Arcangeli, (Mon Aug 4, 10:46 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Jeremy Fitzhardinge, (Mon Aug 4, 11:06 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Peter Zijlstra, (Mon Aug 4, 11:48 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Peter Zijlstra, (Mon Aug 4, 11:54 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Jeremy Fitzhardinge, (Mon Aug 4, 12:26 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Linus Torvalds, (Mon Aug 4, 12:31 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Peter Zijlstra, (Mon Aug 4, 12:39 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Jeremy Fitzhardinge, (Mon Aug 4, 1:16 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), David Miller, (Mon Aug 4, 2:32 pm)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Peter Zijlstra, (Thu Aug 7, 4:25 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Steven Rostedt, (Wed Oct 8, 8:27 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Linus Torvalds, (Wed Oct 8, 8:43 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Nick Piggin, (Wed Oct 8, 8:52 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Steven Rostedt, (Wed Oct 8, 9:03 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Linus Torvalds, (Wed Oct 8, 9:19 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Steven Rostedt, (Wed Oct 8, 9:53 am)
Re: [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock(), Steven Rostedt, (Wed Oct 8, 10:18 am)