Lockdep treats down_write_trylock like regular down_write
authorPavel Emelianov <xemul@sw.ru>
Tue, 8 May 2007 07:29:10 +0000 (00:29 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Tue, 8 May 2007 18:15:09 +0000 (11:15 -0700)
This causes constructions like

down_write(&mm1->mmap_sem);
if (down_write_trylock(&mm2->mmap_sem)) {
       ...
       up_write(&mm2->mmap_sem);
}
up_write(&mm1->mmap_sem);

generate a lockdep warning about circular locking dependence.

Call rwsem_acquire() with trylock set to 1.

Cc: Ingo Molnar <mingo@elte.hu>
Cc: Arjan van de Ven <arjan@infradead.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
kernel/rwsem.c

index 291ded556aa034fffb7bf7c25799e9d7bb95eaf2..9a87886b022eb42ab486cd4749a5da1043a91c36 100644 (file)
@@ -60,7 +60,7 @@ int down_write_trylock(struct rw_semaphore *sem)
        int ret = __down_write_trylock(sem);
 
        if (ret == 1)
-               rwsem_acquire(&sem->dep_map, 0, 0, _RET_IP_);
+               rwsem_acquire(&sem->dep_map, 0, 1, _RET_IP_);
        return ret;
 }