On Thu, 8 May 2008 00:44:06 +0200
Andrea Arcangeli <andrea@qumranet.com> wrote:
umm...
CPU0: CPU1:
spin_lock(a->lock); spin_lock(b->lock);
spin_lock(b->lock); spin_lock(a->lock);
bad.
CPU0: CPU1:
spin_lock(global_lock) spin_lock(global_lock);
spin_lock(a->lock); spin_lock(b->lock);
spin_lock(b->lock); spin_lock(a->lock);
Is OK.
CPU0: CPU1:
spin_lock(global_lock)
spin_lock(a->lock); spin_lock(b->lock);
spin_lock(b->lock); spin_unlock(b->lock);
spin_lock(a->lock);
spin_unlock(a->lock);
also OK.
As long as all code paths which can take two-or-more locks are all covered
by the global lock there is no deadlock scenario. If a thread takes just a
single instance of one of these locks without taking the global_lock then
there is also no deadlock.
Now, if we need to take both anon_vma->lock AND i_mmap_lock in the newly
added mm_lock() thing and we also take both those locks at the same time in
regular code, we're probably screwed.
--