vserver 1.9.5.x5
[linux-2.6.git] / kernel / futex.c
1 /*
2  *  Fast Userspace Mutexes (which I call "Futexes!").
3  *  (C) Rusty Russell, IBM 2002
4  *
5  *  Generalized futexes, futex requeueing, misc fixes by Ingo Molnar
6  *  (C) Copyright 2003 Red Hat Inc, All Rights Reserved
7  *
8  *  Removed page pinning, fix privately mapped COW pages and other cleanups
9  *  (C) Copyright 2003, 2004 Jamie Lokier
10  *
11  *  Thanks to Ben LaHaise for yelling "hashed waitqueues" loudly
12  *  enough at me, Linus for the original (flawed) idea, Matthew
13  *  Kirkwood for proof-of-concept implementation.
14  *
15  *  "The futexes are also cursed."
16  *  "But they come in a choice of three flavours!"
17  *
18  *  This program is free software; you can redistribute it and/or modify
19  *  it under the terms of the GNU General Public License as published by
20  *  the Free Software Foundation; either version 2 of the License, or
21  *  (at your option) any later version.
22  *
23  *  This program is distributed in the hope that it will be useful,
24  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  *  GNU General Public License for more details.
27  *
28  *  You should have received a copy of the GNU General Public License
29  *  along with this program; if not, write to the Free Software
30  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
31  */
32 #include <linux/slab.h>
33 #include <linux/poll.h>
34 #include <linux/fs.h>
35 #include <linux/file.h>
36 #include <linux/jhash.h>
37 #include <linux/init.h>
38 #include <linux/futex.h>
39 #include <linux/mount.h>
40 #include <linux/pagemap.h>
41 #include <linux/syscalls.h>
42
43 #define FUTEX_HASHBITS 8
44
45 /*
46  * Futexes are matched on equal values of this key.
47  * The key type depends on whether it's a shared or private mapping.
48  * Don't rearrange members without looking at hash_futex().
49  *
50  * offset is aligned to a multiple of sizeof(u32) (== 4) by definition.
51  * We set bit 0 to indicate if it's an inode-based key.
52  */
53 union futex_key {
54         struct {
55                 unsigned long pgoff;
56                 struct inode *inode;
57                 int offset;
58         } shared;
59         struct {
60                 unsigned long uaddr;
61                 struct mm_struct *mm;
62                 int offset;
63         } private;
64         struct {
65                 unsigned long word;
66                 void *ptr;
67                 int offset;
68         } both;
69 };
70
71 /*
72  * We use this hashed waitqueue instead of a normal wait_queue_t, so
73  * we can wake only the relevant ones (hashed queues may be shared).
74  *
75  * A futex_q has a woken state, just like tasks have TASK_RUNNING.
76  * It is considered woken when list_empty(&q->list) || q->lock_ptr == 0.
77  * The order of wakup is always to make the first condition true, then
78  * wake up q->waiters, then make the second condition true.
79  */
80 struct futex_q {
81         struct list_head list;
82         wait_queue_head_t waiters;
83
84         /* Which hash list lock to use. */
85         spinlock_t *lock_ptr;
86
87         /* Key which the futex is hashed on. */
88         union futex_key key;
89
90         /* For fd, sigio sent using these. */
91         int fd;
92         struct file *filp;
93 };
94
95 /*
96  * Split the global futex_lock into every hash list lock.
97  */
98 struct futex_hash_bucket {
99        spinlock_t              lock;
100        unsigned int         nqueued;
101        struct list_head       chain;
102 };
103
104 static struct futex_hash_bucket futex_queues[1<<FUTEX_HASHBITS];
105
106 /* Futex-fs vfsmount entry: */
107 static struct vfsmount *futex_mnt;
108
109 /*
110  * We hash on the keys returned from get_futex_key (see below).
111  */
112 static struct futex_hash_bucket *hash_futex(union futex_key *key)
113 {
114         u32 hash = jhash2((u32*)&key->both.word,
115                           (sizeof(key->both.word)+sizeof(key->both.ptr))/4,
116                           key->both.offset);
117         return &futex_queues[hash & ((1 << FUTEX_HASHBITS)-1)];
118 }
119
120 /*
121  * Return 1 if two futex_keys are equal, 0 otherwise.
122  */
123 static inline int match_futex(union futex_key *key1, union futex_key *key2)
124 {
125         return (key1->both.word == key2->both.word
126                 && key1->both.ptr == key2->both.ptr
127                 && key1->both.offset == key2->both.offset);
128 }
129
130 /*
131  * Get parameters which are the keys for a futex.
132  *
133  * For shared mappings, it's (page->index, vma->vm_file->f_dentry->d_inode,
134  * offset_within_page).  For private mappings, it's (uaddr, current->mm).
135  * We can usually work out the index without swapping in the page.
136  *
137  * Returns: 0, or negative error code.
138  * The key words are stored in *key on success.
139  *
140  * Should be called with &current->mm->mmap_sem but NOT any spinlocks.
141  */
142 static int get_futex_key(unsigned long uaddr, union futex_key *key)
143 {
144         struct mm_struct *mm = current->mm;
145         struct vm_area_struct *vma;
146         struct page *page;
147         int err;
148
149         /*
150          * The futex address must be "naturally" aligned.
151          */
152         key->both.offset = uaddr % PAGE_SIZE;
153         if (unlikely((key->both.offset % sizeof(u32)) != 0))
154                 return -EINVAL;
155         uaddr -= key->both.offset;
156
157         /*
158          * The futex is hashed differently depending on whether
159          * it's in a shared or private mapping.  So check vma first.
160          */
161         vma = find_extend_vma(mm, uaddr);
162         if (unlikely(!vma))
163                 return -EFAULT;
164
165         /*
166          * Permissions.
167          */
168         if (unlikely((vma->vm_flags & (VM_IO|VM_READ)) != VM_READ))
169                 return (vma->vm_flags & VM_IO) ? -EPERM : -EACCES;
170
171         /*
172          * Private mappings are handled in a simple way.
173          *
174          * NOTE: When userspace waits on a MAP_SHARED mapping, even if
175          * it's a read-only handle, it's expected that futexes attach to
176          * the object not the particular process.  Therefore we use
177          * VM_MAYSHARE here, not VM_SHARED which is restricted to shared
178          * mappings of _writable_ handles.
179          */
180         if (likely(!(vma->vm_flags & VM_MAYSHARE))) {
181                 key->private.mm = mm;
182                 key->private.uaddr = uaddr;
183                 return 0;
184         }
185
186         /*
187          * Linear file mappings are also simple.
188          */
189         key->shared.inode = vma->vm_file->f_dentry->d_inode;
190         key->both.offset++; /* Bit 0 of offset indicates inode-based key. */
191         if (likely(!(vma->vm_flags & VM_NONLINEAR))) {
192                 key->shared.pgoff = (((uaddr - vma->vm_start) >> PAGE_SHIFT)
193                                      + vma->vm_pgoff);
194                 return 0;
195         }
196
197         /*
198          * We could walk the page table to read the non-linear
199          * pte, and get the page index without fetching the page
200          * from swap.  But that's a lot of code to duplicate here
201          * for a rare case, so we simply fetch the page.
202          */
203
204         /*
205          * Do a quick atomic lookup first - this is the fastpath.
206          */
207         spin_lock(&current->mm->page_table_lock);
208         page = follow_page(mm, uaddr, 0);
209         if (likely(page != NULL)) {
210                 key->shared.pgoff =
211                         page->index << (PAGE_CACHE_SHIFT - PAGE_SHIFT);
212                 spin_unlock(&current->mm->page_table_lock);
213                 return 0;
214         }
215         spin_unlock(&current->mm->page_table_lock);
216
217         /*
218          * Do it the general way.
219          */
220         err = get_user_pages(current, mm, uaddr, 1, 0, 0, &page, NULL);
221         if (err >= 0) {
222                 key->shared.pgoff =
223                         page->index << (PAGE_CACHE_SHIFT - PAGE_SHIFT);
224                 put_page(page);
225                 return 0;
226         }
227         return err;
228 }
229
230 /*
231  * Take a reference to the resource addressed by a key.
232  * Can be called while holding spinlocks.
233  *
234  * NOTE: mmap_sem MUST be held between get_futex_key() and calling this
235  * function, if it is called at all.  mmap_sem keeps key->shared.inode valid.
236  */
237 static inline void get_key_refs(union futex_key *key)
238 {
239         if (key->both.ptr != 0) {
240                 if (key->both.offset & 1)
241                         atomic_inc(&key->shared.inode->i_count);
242                 else
243                         atomic_inc(&key->private.mm->mm_count);
244         }
245 }
246
247 /*
248  * Drop a reference to the resource addressed by a key.
249  * The hash bucket spinlock must not be held.
250  */
251 static void drop_key_refs(union futex_key *key)
252 {
253         if (key->both.ptr != 0) {
254                 if (key->both.offset & 1)
255                         iput(key->shared.inode);
256                 else
257                         mmdrop(key->private.mm);
258         }
259 }
260
261 static inline int get_futex_value_locked(int *dest, int __user *from)
262 {
263         int ret;
264
265         inc_preempt_count();
266         ret = __copy_from_user_inatomic(dest, from, sizeof(int));
267         dec_preempt_count();
268         preempt_check_resched();
269
270         return ret ? -EFAULT : 0;
271 }
272
273 /*
274  * The hash bucket lock must be held when this is called.
275  * Afterwards, the futex_q must not be accessed.
276  */
277 static void wake_futex(struct futex_q *q)
278 {
279         list_del_init(&q->list);
280         if (q->filp)
281                 send_sigio(&q->filp->f_owner, q->fd, POLL_IN);
282         /*
283          * The lock in wake_up_all() is a crucial memory barrier after the
284          * list_del_init() and also before assigning to q->lock_ptr.
285          */
286         wake_up_all(&q->waiters);
287         /*
288          * The waiting task can free the futex_q as soon as this is written,
289          * without taking any locks.  This must come last.
290          */
291         q->lock_ptr = NULL;
292 }
293
294 /*
295  * Wake up all waiters hashed on the physical page that is mapped
296  * to this virtual address:
297  */
298 static int futex_wake(unsigned long uaddr, int nr_wake)
299 {
300         union futex_key key;
301         struct futex_hash_bucket *bh;
302         struct list_head *head;
303         struct futex_q *this, *next;
304         int ret;
305
306         down_read(&current->mm->mmap_sem);
307
308         ret = get_futex_key(uaddr, &key);
309         if (unlikely(ret != 0))
310                 goto out;
311
312         bh = hash_futex(&key);
313         spin_lock(&bh->lock);
314         head = &bh->chain;
315
316         list_for_each_entry_safe(this, next, head, list) {
317                 if (match_futex (&this->key, &key)) {
318                         wake_futex(this);
319                         if (++ret >= nr_wake)
320                                 break;
321                 }
322         }
323
324         spin_unlock(&bh->lock);
325 out:
326         up_read(&current->mm->mmap_sem);
327         return ret;
328 }
329
330 /*
331  * Requeue all waiters hashed on one physical page to another
332  * physical page.
333  */
334 static int futex_requeue(unsigned long uaddr1, unsigned long uaddr2,
335                          int nr_wake, int nr_requeue, int *valp)
336 {
337         union futex_key key1, key2;
338         struct futex_hash_bucket *bh1, *bh2;
339         struct list_head *head1;
340         struct futex_q *this, *next;
341         int ret, drop_count = 0;
342         unsigned int nqueued;
343
344  retry:
345         down_read(&current->mm->mmap_sem);
346
347         ret = get_futex_key(uaddr1, &key1);
348         if (unlikely(ret != 0))
349                 goto out;
350         ret = get_futex_key(uaddr2, &key2);
351         if (unlikely(ret != 0))
352                 goto out;
353
354         bh1 = hash_futex(&key1);
355         bh2 = hash_futex(&key2);
356
357         nqueued = bh1->nqueued;
358         if (likely(valp != NULL)) {
359                 int curval;
360
361                 /* In order to avoid doing get_user while
362                    holding bh1->lock and bh2->lock, nqueued
363                    (monotonically increasing field) must be first
364                    read, then *uaddr1 fetched from userland and
365                    after acquiring lock nqueued field compared with
366                    the stored value.  The smp_mb () below
367                    makes sure that bh1->nqueued is read from memory
368                    before *uaddr1.  */
369                 smp_mb();
370
371                 ret = get_futex_value_locked(&curval, (int __user *)uaddr1);
372
373                 if (unlikely(ret)) {
374                         /* If we would have faulted, release mmap_sem, fault
375                          * it in and start all over again.
376                          */
377                         up_read(&current->mm->mmap_sem);
378
379                         ret = get_user(curval, (int __user *)uaddr1);
380
381                         if (!ret)
382                                 goto retry;
383
384                         return ret;
385                 }
386                 if (curval != *valp) {
387                         ret = -EAGAIN;
388                         goto out;
389                 }
390         }
391
392         if (bh1 < bh2)
393                 spin_lock(&bh1->lock);
394         spin_lock(&bh2->lock);
395         if (bh1 > bh2)
396                 spin_lock(&bh1->lock);
397
398         if (unlikely(nqueued != bh1->nqueued && valp != NULL)) {
399                 ret = -EAGAIN;
400                 goto out_unlock;
401         }
402
403         head1 = &bh1->chain;
404         list_for_each_entry_safe(this, next, head1, list) {
405                 if (!match_futex (&this->key, &key1))
406                         continue;
407                 if (++ret <= nr_wake) {
408                         wake_futex(this);
409                 } else {
410                         list_move_tail(&this->list, &bh2->chain);
411                         this->lock_ptr = &bh2->lock;
412                         this->key = key2;
413                         get_key_refs(&key2);
414                         drop_count++;
415
416                         if (ret - nr_wake >= nr_requeue)
417                                 break;
418                         /* Make sure to stop if key1 == key2 */
419                         if (head1 == &bh2->chain && head1 != &next->list)
420                                 head1 = &this->list;
421                 }
422         }
423
424 out_unlock:
425         spin_unlock(&bh1->lock);
426         if (bh1 != bh2)
427                 spin_unlock(&bh2->lock);
428
429         /* drop_key_refs() must be called outside the spinlocks. */
430         while (--drop_count >= 0)
431                 drop_key_refs(&key1);
432
433 out:
434         up_read(&current->mm->mmap_sem);
435         return ret;
436 }
437
438 /*
439  * queue_me and unqueue_me must be called as a pair, each
440  * exactly once.  They are called with the hashed spinlock held.
441  */
442
443 /* The key must be already stored in q->key. */
444 static void queue_me(struct futex_q *q, int fd, struct file *filp)
445 {
446         struct futex_hash_bucket *bh;
447
448         q->fd = fd;
449         q->filp = filp;
450
451         init_waitqueue_head(&q->waiters);
452
453         get_key_refs(&q->key);
454         bh = hash_futex(&q->key);
455         q->lock_ptr = &bh->lock;
456
457         spin_lock(&bh->lock);
458         bh->nqueued++;
459         list_add_tail(&q->list, &bh->chain);
460         spin_unlock(&bh->lock);
461 }
462
463 /* Return 1 if we were still queued (ie. 0 means we were woken) */
464 static int unqueue_me(struct futex_q *q)
465 {
466         int ret = 0;
467         spinlock_t *lock_ptr;
468
469         /* In the common case we don't take the spinlock, which is nice. */
470  retry:
471         lock_ptr = q->lock_ptr;
472         if (lock_ptr != 0) {
473                 spin_lock(lock_ptr);
474                 /*
475                  * q->lock_ptr can change between reading it and
476                  * spin_lock(), causing us to take the wrong lock.  This
477                  * corrects the race condition.
478                  *
479                  * Reasoning goes like this: if we have the wrong lock,
480                  * q->lock_ptr must have changed (maybe several times)
481                  * between reading it and the spin_lock().  It can
482                  * change again after the spin_lock() but only if it was
483                  * already changed before the spin_lock().  It cannot,
484                  * however, change back to the original value.  Therefore
485                  * we can detect whether we acquired the correct lock.
486                  */
487                 if (unlikely(lock_ptr != q->lock_ptr)) {
488                         spin_unlock(lock_ptr);
489                         goto retry;
490                 }
491                 WARN_ON(list_empty(&q->list));
492                 list_del(&q->list);
493                 spin_unlock(lock_ptr);
494                 ret = 1;
495         }
496
497         drop_key_refs(&q->key);
498         return ret;
499 }
500
501 static int futex_wait(unsigned long uaddr, int val, unsigned long time)
502 {
503         DECLARE_WAITQUEUE(wait, current);
504         int ret, curval;
505         struct futex_q q;
506
507  retry:
508         down_read(&current->mm->mmap_sem);
509
510         ret = get_futex_key(uaddr, &q.key);
511         if (unlikely(ret != 0))
512                 goto out_release_sem;
513
514         queue_me(&q, -1, NULL);
515
516         /*
517          * Access the page AFTER the futex is queued.
518          * Order is important:
519          *
520          *   Userspace waiter: val = var; if (cond(val)) futex_wait(&var, val);
521          *   Userspace waker:  if (cond(var)) { var = new; futex_wake(&var); }
522          *
523          * The basic logical guarantee of a futex is that it blocks ONLY
524          * if cond(var) is known to be true at the time of blocking, for
525          * any cond.  If we queued after testing *uaddr, that would open
526          * a race condition where we could block indefinitely with
527          * cond(var) false, which would violate the guarantee.
528          *
529          * A consequence is that futex_wait() can return zero and absorb
530          * a wakeup when *uaddr != val on entry to the syscall.  This is
531          * rare, but normal.
532          *
533          * We hold the mmap semaphore, so the mapping cannot have changed
534          * since we looked it up in get_futex_key.
535          */
536
537         ret = get_futex_value_locked(&curval, (int __user *)uaddr);
538
539         if (unlikely(ret)) {
540                 /* If we would have faulted, release mmap_sem, fault it in and
541                  * start all over again.
542                  */
543                 up_read(&current->mm->mmap_sem);
544
545                 if (!unqueue_me(&q)) /* There's a chance we got woken already */
546                         return 0;
547
548                 ret = get_user(curval, (int __user *)uaddr);
549
550                 if (!ret)
551                         goto retry;
552                 return ret;
553         }
554         if (curval != val) {
555                 ret = -EWOULDBLOCK;
556                 goto out_unqueue;
557         }
558
559         /*
560          * Now the futex is queued and we have checked the data, we
561          * don't want to hold mmap_sem while we sleep.
562          */     
563         up_read(&current->mm->mmap_sem);
564
565         /*
566          * There might have been scheduling since the queue_me(), as we
567          * cannot hold a spinlock across the get_user() in case it
568          * faults, and we cannot just set TASK_INTERRUPTIBLE state when
569          * queueing ourselves into the futex hash.  This code thus has to
570          * rely on the futex_wake() code removing us from hash when it
571          * wakes us up.
572          */
573
574         /* add_wait_queue is the barrier after __set_current_state. */
575         __set_current_state(TASK_INTERRUPTIBLE);
576         add_wait_queue(&q.waiters, &wait);
577         /*
578          * !list_empty() is safe here without any lock.
579          * q.lock_ptr != 0 is not safe, because of ordering against wakeup.
580          */
581         if (likely(!list_empty(&q.list)))
582                 time = schedule_timeout(time);
583         __set_current_state(TASK_RUNNING);
584
585         /*
586          * NOTE: we don't remove ourselves from the waitqueue because
587          * we are the only user of it.
588          */
589
590         /* If we were woken (and unqueued), we succeeded, whatever. */
591         if (!unqueue_me(&q))
592                 return 0;
593         if (time == 0)
594                 return -ETIMEDOUT;
595         /* We expect signal_pending(current), but another thread may
596          * have handled it for us already. */
597         return -EINTR;
598
599  out_unqueue:
600         /* If we were woken (and unqueued), we succeeded, whatever. */
601         if (!unqueue_me(&q))
602                 ret = 0;
603  out_release_sem:
604         up_read(&current->mm->mmap_sem);
605         return ret;
606 }
607
608 static int futex_close(struct inode *inode, struct file *filp)
609 {
610         struct futex_q *q = filp->private_data;
611
612         unqueue_me(q);
613         kfree(q);
614         return 0;
615 }
616
617 /* This is one-shot: once it's gone off you need a new fd */
618 static unsigned int futex_poll(struct file *filp,
619                                struct poll_table_struct *wait)
620 {
621         struct futex_q *q = filp->private_data;
622         int ret = 0;
623
624         poll_wait(filp, &q->waiters, wait);
625
626         /*
627          * list_empty() is safe here without any lock.
628          * q->lock_ptr != 0 is not safe, because of ordering against wakeup.
629          */
630         if (list_empty(&q->list))
631                 ret = POLLIN | POLLRDNORM;
632
633         return ret;
634 }
635
636 static struct file_operations futex_fops = {
637         .release        = futex_close,
638         .poll           = futex_poll,
639 };
640
641 /*
642  * Signal allows caller to avoid the race which would occur if they
643  * set the sigio stuff up afterwards.
644  */
645 static int futex_fd(unsigned long uaddr, int signal)
646 {
647         struct futex_q *q;
648         struct file *filp;
649         int ret, err;
650
651         ret = -EINVAL;
652         if (signal < 0 || signal > _NSIG)
653                 goto out;
654
655         ret = get_unused_fd();
656         if (ret < 0)
657                 goto out;
658         filp = get_empty_filp();
659         if (!filp) {
660                 put_unused_fd(ret);
661                 ret = -ENFILE;
662                 goto out;
663         }
664         filp->f_op = &futex_fops;
665         filp->f_vfsmnt = mntget(futex_mnt);
666         filp->f_dentry = dget(futex_mnt->mnt_root);
667         filp->f_mapping = filp->f_dentry->d_inode->i_mapping;
668
669         if (signal) {
670                 int err;
671                 err = f_setown(filp, current->pid, 1);
672                 if (err < 0) {
673                         put_unused_fd(ret);
674                         put_filp(filp);
675                         ret = err;
676                         goto out;
677                 }
678                 filp->f_owner.signum = signal;
679         }
680
681         q = kmalloc(sizeof(*q), GFP_KERNEL);
682         if (!q) {
683                 put_unused_fd(ret);
684                 put_filp(filp);
685                 ret = -ENOMEM;
686                 goto out;
687         }
688
689         down_read(&current->mm->mmap_sem);
690         err = get_futex_key(uaddr, &q->key);
691
692         if (unlikely(err != 0)) {
693                 up_read(&current->mm->mmap_sem);
694                 put_unused_fd(ret);
695                 put_filp(filp);
696                 kfree(q);
697                 return err;
698         }
699
700         /*
701          * queue_me() must be called before releasing mmap_sem, because
702          * key->shared.inode needs to be referenced while holding it.
703          */
704         filp->private_data = q;
705
706         queue_me(q, ret, filp);
707         up_read(&current->mm->mmap_sem);
708
709         /* Now we map fd to filp, so userspace can access it */
710         fd_install(ret, filp);
711 out:
712         return ret;
713 }
714
715 long do_futex(unsigned long uaddr, int op, int val, unsigned long timeout,
716                 unsigned long uaddr2, int val2, int val3)
717 {
718         int ret;
719
720         switch (op) {
721         case FUTEX_WAIT:
722                 ret = futex_wait(uaddr, val, timeout);
723                 break;
724         case FUTEX_WAKE:
725                 ret = futex_wake(uaddr, val);
726                 break;
727         case FUTEX_FD:
728                 /* non-zero val means F_SETOWN(getpid()) & F_SETSIG(val) */
729                 ret = futex_fd(uaddr, val);
730                 break;
731         case FUTEX_REQUEUE:
732                 ret = futex_requeue(uaddr, uaddr2, val, val2, NULL);
733                 break;
734         case FUTEX_CMP_REQUEUE:
735                 ret = futex_requeue(uaddr, uaddr2, val, val2, &val3);
736                 break;
737         default:
738                 ret = -ENOSYS;
739         }
740         return ret;
741 }
742
743
744 asmlinkage long sys_futex(u32 __user *uaddr, int op, int val,
745                           struct timespec __user *utime, u32 __user *uaddr2,
746                           int val3)
747 {
748         struct timespec t;
749         unsigned long timeout = MAX_SCHEDULE_TIMEOUT;
750         int val2 = 0;
751
752         if ((op == FUTEX_WAIT) && utime) {
753                 if (copy_from_user(&t, utime, sizeof(t)) != 0)
754                         return -EFAULT;
755                 timeout = timespec_to_jiffies(&t) + 1;
756         }
757         /*
758          * requeue parameter in 'utime' if op == FUTEX_REQUEUE.
759          */
760         if (op >= FUTEX_REQUEUE)
761                 val2 = (int) (unsigned long) utime;
762
763         return do_futex((unsigned long)uaddr, op, val, timeout,
764                         (unsigned long)uaddr2, val2, val3);
765 }
766
767 static struct super_block *
768 futexfs_get_sb(struct file_system_type *fs_type,
769                int flags, const char *dev_name, void *data)
770 {
771         return get_sb_pseudo(fs_type, "futex", NULL, 0xBAD1DEA);
772 }
773
774 static struct file_system_type futex_fs_type = {
775         .name           = "futexfs",
776         .get_sb         = futexfs_get_sb,
777         .kill_sb        = kill_anon_super,
778 };
779
780 static int __init init(void)
781 {
782         unsigned int i;
783
784         register_filesystem(&futex_fs_type);
785         futex_mnt = kern_mount(&futex_fs_type);
786
787         for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
788                 INIT_LIST_HEAD(&futex_queues[i].chain);
789                 spin_lock_init(&futex_queues[i].lock);
790         }
791         return 0;
792 }
793 __initcall(init);