public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Robust Futex update
@ 2005-10-13  0:00 David Singleton
  2005-10-14  5:35 ` Ingo Molnar
  2005-10-14  5:45 ` Ingo Molnar
  0 siblings, 2 replies; 4+ messages in thread
From: David Singleton @ 2005-10-13  0:00 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: robustmutexes, linux-kernel

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

Ingo,
    here 's a patch for 2.6.14-rc4-rt1 that fixes two things:

1) Deregister futex returns -EBUSY instead of -EINVAL if a thread tries 
to deregister a pthread_mutex that another thread has locked.

2)  Make the fast path robust.  If a pthread_mutex is only locked in 
user space we need to clear the owner when
the thread dies.  This makes both the 'rt_mutex is locked in the kernel' 
and the 'pthread_mutex is only locked in user space'
paths robust.

David

[-- Attachment #2: patch-2.6.14-rc4-rt1-rf1 --]
[-- Type: text/plain, Size: 2226 bytes --]

Index: linux-2.6.13/kernel/futex.c
===================================================================
--- linux-2.6.13.orig/kernel/futex.c
+++ linux-2.6.13/kernel/futex.c
@@ -1354,18 +1354,25 @@ static void find_owned_futex(struct vm_a
 		if (uaddr == 0)
 			continue;
 
+		up(&mapping->robust_sem);
+		up_read(&current->mm->mmap_sem);
+		value = futex_get_user(uaddr);
+		if (this->futex_mutex.mutex_attr & FUTEX_ATTR_ROBUST)
+			value |= FUTEX_OWNER_DIED;
 		if (rt_mutex_owned_by(&this->futex_mutex, ti)) {
-			up(&mapping->robust_sem);
-			up_read(&current->mm->mmap_sem);
-			if (this->futex_mutex.mutex_attr & FUTEX_ATTR_ROBUST) {
-	 			value = futex_get_user(uaddr);
-				value |= FUTEX_OWNER_DIED;
- 				futex_put_user(value, uaddr);
-			}
+			futex_put_user(value, uaddr);
 			up_futex(&this->futex_mutex);
-			down(&mapping->robust_sem);
-			down_read(&current->mm->mmap_sem);
+		} else if ((value & FUTEX_PID) == current->pid) {
+			/*
+			 * this bit is for the fast path.  If the lock is only
+			 * locked in user space wee need to unlock it
+			 * for the exiting thread.
+			 */
+			value &= ~FUTEX_PID;
+			futex_put_user(value, uaddr);
 		}
+		down(&mapping->robust_sem);
+		down_read(&current->mm->mmap_sem);
 	}
 
 	up(&mapping->robust_sem);
@@ -1524,7 +1531,7 @@ static int futex_deregister(unsigned lon
 			if (rt_mutex_owned_by(&this->futex_mutex, ti)) {
 				up_futex(&this->futex_mutex);
 			} else if (rt_mutex_owner(&this->futex_mutex) != NULL) {
-				ret = -EINVAL;
+				ret = -EBUSY;
 				break;
 			}
 			list_del(&this->list);
Index: linux-2.6.13/include/linux/futex.h
===================================================================
--- linux-2.6.13.orig/include/linux/futex.h
+++ linux-2.6.13/include/linux/futex.h
@@ -1,8 +1,6 @@
 #ifndef _LINUX_FUTEX_H
 #define _LINUX_FUTEX_H
 
-#include <linux/fs.h>
-
 /* Second argument to futex syscall */
 
 
Index: linux-2.6.13/kernel/rt.c
===================================================================
--- linux-2.6.13.orig/kernel/rt.c
+++ linux-2.6.13/kernel/rt.c
@@ -47,6 +47,7 @@
 #include <linux/syscalls.h>
 #include <linux/interrupt.h>
 #include <linux/plist.h>
+#include <linux/fs.h>
 #include <linux/futex.h>
 
 #define CAPTURE_LOCK

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

* Re: Robust Futex update
  2005-10-13  0:00 Robust Futex update David Singleton
@ 2005-10-14  5:35 ` Ingo Molnar
  2005-10-14  5:45 ` Ingo Molnar
  1 sibling, 0 replies; 4+ messages in thread
From: Ingo Molnar @ 2005-10-14  5:35 UTC (permalink / raw)
  To: David Singleton; +Cc: robustmutexes, linux-kernel


* David Singleton <dsingleton@mvista.com> wrote:

> Ingo,
>    here 's a patch for 2.6.14-rc4-rt1 that fixes two things:
> 
> 1) Deregister futex returns -EBUSY instead of -EINVAL if a thread 
> tries to deregister a pthread_mutex that another thread has locked.
> 
> 2) Make the fast path robust.  If a pthread_mutex is only locked in 
> user space we need to clear the owner when the thread dies.  This 
> makes both the 'rt_mutex is locked in the kernel' and the 
> 'pthread_mutex is only locked in user space' paths robust.

thanks, applied.

	Ingo

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

* Re: Robust Futex update
  2005-10-13  0:00 Robust Futex update David Singleton
  2005-10-14  5:35 ` Ingo Molnar
@ 2005-10-14  5:45 ` Ingo Molnar
  2005-10-14 17:40   ` Khem Raj
  1 sibling, 1 reply; 4+ messages in thread
From: Ingo Molnar @ 2005-10-14  5:45 UTC (permalink / raw)
  To: David Singleton; +Cc: robustmutexes, linux-kernel


* David Singleton <dsingleton@mvista.com> wrote:

> Index: linux-2.6.13/include/linux/futex.h
> ===================================================================
> --- linux-2.6.13.orig/include/linux/futex.h
> +++ linux-2.6.13/include/linux/futex.h
> @@ -1,8 +1,6 @@
>  #ifndef _LINUX_FUTEX_H
>  #define _LINUX_FUTEX_H
>  
> -#include <linux/fs.h>
> -
>  /* Second argument to futex syscall */
>  

this chunk broke the build, so i added the #include back. Really, the 
robust mutex glibc patches should _NOT_ automatically include the 
kernel's futex.h file. If they do so and rely on an installed 
kernel-headers package then they are broken. Just copy the file into the 
glibc tree and remove the #include line.

	Ingo

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

* Re: Robust Futex update
  2005-10-14  5:45 ` Ingo Molnar
@ 2005-10-14 17:40   ` Khem Raj
  0 siblings, 0 replies; 4+ messages in thread
From: Khem Raj @ 2005-10-14 17:40 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: David Singleton, robustmutexes, linux-kernel

Hi Ingo

As we pass same flags from glibc to kernel we thought it will be good to 
have defines in one place to avoid going out of sync in future.
glibc already has dependency on kernel headers. So were looking for ways 
to fix futex.h in kernel so that glibc can use it. But if it is not 
feasible then we can define these flags inside glibc headers. Only 
additional burden will be that these headers will be required to be 
synced whenever there is any change pertaining to them(mostly the defines.)

Thanks

Khem

Ingo Molnar wrote:

>* David Singleton <dsingleton@mvista.com> wrote:
>
>  
>
>>Index: linux-2.6.13/include/linux/futex.h
>>===================================================================
>>--- linux-2.6.13.orig/include/linux/futex.h
>>+++ linux-2.6.13/include/linux/futex.h
>>@@ -1,8 +1,6 @@
>> #ifndef _LINUX_FUTEX_H
>> #define _LINUX_FUTEX_H
>> 
>>-#include <linux/fs.h>
>>-
>> /* Second argument to futex syscall */
>> 
>>    
>>
>
>this chunk broke the build, so i added the #include back. Really, the 
>robust mutex glibc patches should _NOT_ automatically include the 
>kernel's futex.h file. If they do so and rely on an installed 
>kernel-headers package then they are broken. Just copy the file into the 
>glibc tree and remove the #include line.
>
>	Ingo
>  
>
>------------------------------------------------------------------------
>
>_______________________________________________
>robustmutexes mailing list
>robustmutexes@lists.osdl.org
>https://lists.osdl.org/mailman/listinfo/robustmutexes
>  
>

-- 
Khem Raj <kraj@mvista.com>
MontaVista Software, Inc.
www.mvista.com


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

end of thread, other threads:[~2005-10-14 17:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-13  0:00 Robust Futex update David Singleton
2005-10-14  5:35 ` Ingo Molnar
2005-10-14  5:45 ` Ingo Molnar
2005-10-14 17:40   ` Khem Raj

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