public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Lockdep treats down_write_trylock like regular down_write
@ 2007-04-09  9:56 Pavel Emelianov
  2007-04-09 15:09 ` Arjan van de Ven
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Emelianov @ 2007-04-09  9:56 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Ingo Molnar, Arjan van de Ven, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 282 bytes --]

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.

[-- Attachment #2: diff-lockdep-rwsem-trylock --]
[-- Type: text/plain, Size: 356 bytes --]

--- ./kernel/rwsem.c.pbonrem	2007-03-06 19:09:50.000000000 +0300
+++ ./kernel/rwsem.c	2007-04-06 14:02:18.000000000 +0400
@@ -60,7 +60,7 @@ int down_write_trylock(struct rw_semapho
 	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;
 }
 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Lockdep treats down_write_trylock like regular down_write
  2007-04-09  9:56 [PATCH] Lockdep treats down_write_trylock like regular down_write Pavel Emelianov
@ 2007-04-09 15:09 ` Arjan van de Ven
  2007-04-10  7:37   ` Pavel Emelianov
  0 siblings, 1 reply; 3+ messages in thread
From: Arjan van de Ven @ 2007-04-09 15:09 UTC (permalink / raw)
  To: Pavel Emelianov; +Cc: Andrew Morton, Ingo Molnar, Linux Kernel Mailing List

Pavel Emelianov wrote:
> 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.

please show me why this is safe, especially if you intermix it with 
down_read()'s... like copy_to_user and co may do.

this feels like a very unsafe construct to me...

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Lockdep treats down_write_trylock like regular down_write
  2007-04-09 15:09 ` Arjan van de Ven
@ 2007-04-10  7:37   ` Pavel Emelianov
  0 siblings, 0 replies; 3+ messages in thread
From: Pavel Emelianov @ 2007-04-10  7:37 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: Andrew Morton, Ingo Molnar, Linux Kernel Mailing List

Arjan van de Ven wrote:
> Pavel Emelianov wrote:
>> 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.
> 
> please show me why this is safe, especially if you intermix it with
> down_read()'s... like copy_to_user and co may do.

This is safe as once the task locks the mm1->mmap_sem and gets
into '...' place it is *running* and will release booth semaphores
for sure.

> this feels like a very unsafe construct to me...
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-04-10  7:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-09  9:56 [PATCH] Lockdep treats down_write_trylock like regular down_write Pavel Emelianov
2007-04-09 15:09 ` Arjan van de Ven
2007-04-10  7:37   ` Pavel Emelianov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox