summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorArve Hjønnevåg <arve@android.com>2009-06-09 20:21:44 -0700
committerArve Hjønnevåg <arve@android.com>2010-02-03 21:26:56 -0800
commit8d4c42afa543eda97ce1bc88f160ac1e0379ec52 (patch)
treec2772447b858e96134662f83879ddd7b6ab6fb01 /kernel
parent675bed294c5136b04e283f647e5c73fb897cfd19 (diff)
futex: Restore one of the fast paths eliminated by 38d47c1b7075bd7ec3881141bb3629da58f88dab
This improves futex performance until our user-space code is fixed to use FUTEX_PRIVATE_FLAG for non-shared futexes. Signed-off-by: Arve Hjønnevåg <arve@android.com>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/futex.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/kernel/futex.c b/kernel/futex.c
index fb65e822fc41..546e13300d3b 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -222,6 +222,7 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
struct mm_struct *mm = current->mm;
struct page *page;
int err;
+ struct vm_area_struct *vma;
/*
* The futex address must be "naturally" aligned.
@@ -247,6 +248,37 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
return 0;
}
+ /*
+ * The futex is hashed differently depending on whether
+ * it's in a shared or private mapping. So check vma first.
+ */
+ vma = find_extend_vma(mm, address);
+ if (unlikely(!vma))
+ return -EFAULT;
+
+ /*
+ * Permissions.
+ */
+ if (unlikely((vma->vm_flags & (VM_IO|VM_READ)) != VM_READ))
+ return (vma->vm_flags & VM_IO) ? -EPERM : -EACCES;
+
+ /*
+ * Private mappings are handled in a simple way.
+ *
+ * NOTE: When userspace waits on a MAP_SHARED mapping, even if
+ * it's a read-only handle, it's expected that futexes attach to
+ * the object not the particular process. Therefore we use
+ * VM_MAYSHARE here, not VM_SHARED which is restricted to shared
+ * mappings of _writable_ handles.
+ */
+ if (likely(!(vma->vm_flags & VM_MAYSHARE))) {
+ key->both.offset |= FUT_OFF_MMSHARED; /* reference taken on mm */
+ key->private.mm = mm;
+ key->private.address = address;
+ get_futex_key_refs(key);
+ return 0;
+ }
+
again:
err = get_user_pages_fast(address, 1, rw == VERIFY_WRITE, &page);
if (err < 0)