05 May, 2008

1 commit

  • Since FUTEX_FD was scheduled for removal in June 2007 lets remove it.

    Google Code search found no users for it and NGPT was abandoned in 2003
    according to IBM. futex.h is left untouched to make sure the id does
    not get reassigned. Since queue_me() has no users left it is commented
    out to avoid a warning, i didnt remove it completely since it is part of
    the internal api (matching unqueue_me())

    Signed-off-by: Eric Sesterhenn
    Signed-off-by: Rusty Russell (removed rest)
    Acked-by: Thomas Gleixner
    Signed-off-by: Linus Torvalds

    Eric Sesterhenn
     

30 Apr, 2008

1 commit

  • hrtimers have now dynamic users in the network code. Put them under
    debugobjects surveillance as well.

    Add calls to the generic object debugging infrastructure and provide fixup
    functions which allow to keep the system alive when recoverable problems have
    been detected by the object debugging core code.

    Signed-off-by: Thomas Gleixner
    Cc: Greg KH
    Cc: Randy Dunlap
    Cc: Kay Sievers
    Cc: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Thomas Gleixner
     

31 Mar, 2008

1 commit


27 Mar, 2008

1 commit


24 Feb, 2008

2 commits

  • Not all architectures implement futex_atomic_cmpxchg_inatomic(). The default
    implementation returns -ENOSYS, which is currently not handled inside of the
    futex guts.

    Futex PI calls and robust list exits with a held futex result in an endless
    loop in the futex code on architectures which have no support.

    Fixing up every place where futex_atomic_cmpxchg_inatomic() is called would
    add a fair amount of extra if/else constructs to the already complex code. It
    is also not possible to disable the robust feature before user space tries to
    register robust lists.

    Compile time disabling is not a good idea either, as there are already
    architectures with runtime detection of futex_atomic_cmpxchg_inatomic support.

    Detect the functionality at runtime instead by calling
    cmpxchg_futex_value_locked() with a NULL pointer from the futex initialization
    code. This is guaranteed to fail, but the call of
    futex_atomic_cmpxchg_inatomic() happens with pagefaults disabled.

    On architectures, which use the asm-generic implementation or have a runtime
    CPU feature detection, a -ENOSYS return value disables the PI/robust features.

    On architectures with a working implementation the call returns -EFAULT and
    the PI/robust features are enabled.

    The relevant syscalls return -ENOSYS and the robust list exit code is blocked,
    when the detection fails.

    Fixes http://lkml.org/lkml/2008/2/11/149
    Originally reported by: Lennart Buytenhek

    Signed-off-by: Thomas Gleixner
    Acked-by: Ingo Molnar
    Cc: Lennert Buytenhek
    Cc: Riku Voipio
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Thomas Gleixner
     
  • When the futex init code fails to initialize the futex pseudo file system it
    returns early without initializing the hash queues. Should the boot succeed
    then a futex syscall which tries to enqueue a waiter on the hashqueue will
    crash due to the unitilialized plist heads.

    Initialize the hash queues before the filesystem.

    Signed-off-by: Thomas Gleixner
    Acked-by: Ingo Molnar
    Cc: Lennert Buytenhek
    Cc: Riku Voipio
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Thomas Gleixner
     

15 Feb, 2008

1 commit

  • Various user space callers ask for relative timeouts. While we fixed
    that overflow issue in hrtimer_start(), the sites which convert
    relative user space values to absolute timeouts themself were uncovered.

    Instead of putting overflow checks into each place add a function
    which does the sanity checking and convert all affected callers to use
    it.

    Thanks to Frans Pop, who reported the problem and tested the fixes.

    Signed-off-by: Thomas Gleixner
    Acked-by: Ingo Molnar
    Tested-by: Frans Pop

    Thomas Gleixner
     

02 Feb, 2008

3 commits

  • To allow the implementation of optimized rw-locks in user space, glibc
    needs a possibility to select waiters for wakeup depending on a bitset
    mask.

    This requires two new futex OPs: FUTEX_WAIT_BITS and FUTEX_WAKE_BITS
    These OPs are basically the same as FUTEX_WAIT and FUTEX_WAKE plus an
    additional argument - a bitset. Further the FUTEX_WAIT_BITS OP is
    expecting an absolute timeout value instead of the relative one, which
    is used for the FUTEX_WAIT OP.

    FUTEX_WAIT_BITS calls into the kernel with a bitset. The bitset is
    stored in the futex_q structure, which is used to enqueue the waiter
    into the hashed futex waitqueue.

    FUTEX_WAKE_BITS also calls into the kernel with a bitset. The wakeup
    function logically ANDs the bitset with the bitset stored in each
    waiters futex_q structure. If the result is zero (i.e. none of the set
    bits in the bitsets is matching), then the waiter is not woken up. If
    the result is not zero (i.e. one of the set bits in the bitsets is
    matching), then the waiter is woken.

    The bitset provided by the caller must be non zero. In case the
    provided bitset is zero the kernel returns EINVAL.

    Internaly the new OPs are only extensions to the existing FUTEX_WAIT
    and FUTEX_WAKE functions. The existing OPs hand a bitset with all bits
    set into the futex_wait() and futex_wake() functions.

    Signed-off-by: Thomas Gleixner
    Signed-off-by: Ingo Molnar

    Thomas Gleixner
     
  • The WARN_ON() in the fixup return path of futex_lock_pi() can
    trigger with false positives.

    The following scenario happens:
    t1 holds the futex and t2 and t3 are blocked on the kernel side rt_mutex.
    t1 releases the futex (and the rt_mutex) and assigned t2 to be the next
    owner of the futex.

    t2 is interrupted and returns w/o acquiring the rt_mutex, before t1 can
    release the rtmutex.

    t1 releases the rtmutex and t3 becomes the pending owner of the rtmutex.

    t2 notices that it is the designated owner (user space variable) and
    fails to acquire the rt_mutex via trylock, because it is not allowed to
    steal the rt_mutex from t3. Now it looks at the rt_mutex pending owner (t3)
    and assigns the futex and the pi_state to it.

    During the fixup t4 steals the rtmutex from t3.

    t2 returns from the fixup and the owner of the rt_mutex has changed from
    t3 to t4.

    There is no need to do another round of fixups from t2. The important
    part (t2 is not returning as the user space visible owner) is
    done. The further fixups are done, before either t3 or t4 return to
    user space.

    For the user space it is not relevant which task (t3 or t4) is the real
    owner, as long as those are both in the kernel, which is guaranteed by
    the serialization of the hash bucket lock. Both tasks (which ever returns
    first to userspace - t4 because it locked the rt_mutex or t3 due to a signal)
    are going through the lock_futex_pi() return path where the ownership is
    fixed before the return to user space.

    Signed-off-by: Thomas Gleixner

    Signed-off-by: Ingo Molnar

    Thomas Gleixner
     
  • this patch:

    commit 37bb6cb4097e29ffee970065b74499cbf10603a3
    Author: Peter Zijlstra
    Date: Fri Jan 25 21:08:32 2008 +0100

    hrtimer: unlock hrtimer_wakeup

    Broke hrtimer_init_sleeper() users. It forgot to fix up the futex
    caller of this function to detect the failed queueing and messed up
    the do_nanosleep() caller in that it could leak a TASK_INTERRUPTIBLE
    state.

    Signed-off-by: Peter Zijlstra
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

09 Jan, 2008

1 commit

  • Roland Westrelin did a great analysis of a long standing thinko in the
    return path of futex_lock_pi.

    While we fixed the lock steal case long ago, which was easy to trigger,
    we never had a test case which exposed this problem and stupidly never
    thought about the reverse lock stealing scenario and the return to user
    space with a stale state.

    When a blocked tasks returns from rt_mutex_timed_locked without holding
    the rt_mutex (due to a signal or timeout) and at the same time the task
    holding the futex is releasing the futex and assigning the ownership of
    the futex to the returning task, then it might happen that a third task
    acquires the rt_mutex before the final rt_mutex_trylock() of the
    returning task happens under the futex hash bucket lock. The returning
    task returns to user space with ETIMEOUT or EINTR, but the user space
    futex value is assigned to this task. The task which acquired the
    rt_mutex fixes the user space futex value right after the hash bucket
    lock has been released by the returning task, but for a short period of
    time the user space value is wrong.

    Detailed description is available at:

    https://bugzilla.redhat.com/show_bug.cgi?id=400541

    The fix for this is the same as we do when the rt_mutex was acquired by
    a higher priority task via lock stealing from the designated new owner.
    In that case we already fix the user space value and the internal
    pi_state up before we return. This mechanism can be used to fixup the
    above corner case as well. When the returning task, which failed to
    acquire the rt_mutex, notices that it is the designated owner of the
    futex, then it fixes up the stale user space value and the pi_state,
    before returning to user space. This happens with the futex hash bucket
    lock held, so the task which acquired the rt_mutex is guaranteed to be
    blocked on the hash bucket lock. We can access the rt_mutex owner, which
    gives us the pid of the new owner, safely here as the owner is not able
    to modify (release) it while waiting on the hash bucket lock.

    Rename the "curr" argument of fixup_pi_state_owner() to "newowner" to
    avoid confusion with current and add the check for the stale state into
    the failure path of rt_mutex_trylock() in the return path of
    unlock_futex_pi(). If the situation is detected use
    fixup_pi_state_owner() to assign everything to the owner of the
    rt_mutex.

    Pointed-out-and-tested-by: Roland Westrelin
    Signed-off-by: Ingo Molnar
    Signed-off-by: Thomas Gleixner
    Signed-off-by: Linus Torvalds

    Thomas Gleixner
     

05 Dec, 2007

2 commits

  • return -EFAULT not -EINVAL. Found by review.

    Signed-off-by: Thomas Gleixner
    Signed-off-by: Ingo Molnar

    Thomas Gleixner
     
  • David Holmes found a bug in the -rt tree with respect to
    pthread_cond_timedwait. After trying his test program on the latest git
    from mainline, I found the bug was there too. The bug he was seeing
    that his test program showed, was that if one were to do a "Ctrl-Z" on a
    process that was in the pthread_cond_timedwait, and then did a "bg" on
    that process, it would return with a "-ETIMEDOUT" but early. That is,
    the timer would go off early.

    Looking into this, I found the source of the problem. And it is a rather
    nasty bug at that.

    Here's the relevant code from kernel/futex.c: (not in order in the file)

    [...]
    smlinkage long sys_futex(u32 __user *uaddr, int op, u32 val,
    struct timespec __user *utime, u32 __user *uaddr2,
    u32 val3)
    {
    struct timespec ts;
    ktime_t t, *tp = NULL;
    u32 val2 = 0;
    int cmd = op & FUTEX_CMD_MASK;

    if (utime && (cmd == FUTEX_WAIT || cmd == FUTEX_LOCK_PI)) {
    if (copy_from_user(&ts, utime, sizeof(ts)) != 0)
    return -EFAULT;
    if (!timespec_valid(&ts))
    return -EINVAL;

    t = timespec_to_ktime(ts);
    if (cmd == FUTEX_WAIT)
    t = ktime_add(ktime_get(), t);
    tp = &t;
    }
    [...]
    return do_futex(uaddr, op, val, tp, uaddr2, val2, val3);
    }

    [...]

    long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
    u32 __user *uaddr2, u32 val2, u32 val3)
    {
    int ret;
    int cmd = op & FUTEX_CMD_MASK;
    struct rw_semaphore *fshared = NULL;

    if (!(op & FUTEX_PRIVATE_FLAG))
    fshared = ¤t->mm->mmap_sem;

    switch (cmd) {
    case FUTEX_WAIT:
    ret = futex_wait(uaddr, fshared, val, timeout);

    [...]

    static int futex_wait(u32 __user *uaddr, struct rw_semaphore *fshared,
    u32 val, ktime_t *abs_time)
    {
    [...]
    struct restart_block *restart;
    restart = ¤t_thread_info()->restart_block;
    restart->fn = futex_wait_restart;
    restart->arg0 = (unsigned long)uaddr;
    restart->arg1 = (unsigned long)val;
    restart->arg2 = (unsigned long)abs_time;
    restart->arg3 = 0;
    if (fshared)
    restart->arg3 |= ARG3_SHARED;
    return -ERESTART_RESTARTBLOCK;
    [...]

    static long futex_wait_restart(struct restart_block *restart)
    {
    u32 __user *uaddr = (u32 __user *)restart->arg0;
    u32 val = (u32)restart->arg1;
    ktime_t *abs_time = (ktime_t *)restart->arg2;
    struct rw_semaphore *fshared = NULL;

    restart->fn = do_no_restart_syscall;
    if (restart->arg3 & ARG3_SHARED)
    fshared = ¤t->mm->mmap_sem;
    return (long)futex_wait(uaddr, fshared, val, abs_time);
    }

    So when the futex_wait is interrupt by a signal we break out of the
    hrtimer code and set up or return from signal. This code does not return
    back to userspace, so we set up a RESTARTBLOCK. The bug here is that we
    save the "abs_time" which is a pointer to the stack variable "ktime_t t"
    from sys_futex.

    This returns and unwinds the stack before we get to call our signal. On
    return from the signal we go to futex_wait_restart, where we update all
    the parameters for futex_wait and call it. But here we have a problem
    where abs_time is no longer valid.

    I verified this with print statements, and sure enough, what abs_time
    was set to ends up being garbage when we get to futex_wait_restart.

    The solution I did to solve this (with input from Linus Torvalds)
    was to add unions to the restart_block to allow system calls to
    use the restart with specific parameters. This way the futex code now
    saves the time in a 64bit value in the restart block instead of storing
    it on the stack.

    Note: I'm a bit nervious to add "linux/types.h" and use u32 and u64
    in thread_info.h, when there's a #ifdef __KERNEL__ just below that.
    Not sure what that is there for. If this turns out to be a problem, I've
    tested this with using "unsigned int" for u32 and "unsigned long long" for
    u64 and it worked just the same. I'm using u32 and u64 just to be
    consistent with what the futex code uses.

    Signed-off-by: Steven Rostedt
    Signed-off-by: Ingo Molnar
    Signed-off-by: Thomas Gleixner
    Acked-by: Linus Torvalds

    Steven Rostedt
     

05 Nov, 2007

1 commit


20 Oct, 2007

2 commits

  • The find_task_by_something is a set of macros are used to find task by pid
    depending on what kind of pid is proposed - global or virtual one. All of
    them are wrappers above the most generic one - find_task_by_pid_type_ns() -
    and just substitute some args for it.

    It turned out, that dereferencing the current->nsproxy->pid_ns construction
    and pushing one more argument on the stack inline cause kernel text size to
    grow.

    This patch moves all this stuff out-of-line into kernel/pid.c. Together
    with the next patch it saves a bit less than 400 bytes from the .text
    section.

    Signed-off-by: Pavel Emelyanov
    Cc: Sukadev Bhattiprolu
    Cc: Oleg Nesterov
    Cc: Paul Menage
    Cc: "Eric W. Biederman"
    Acked-by: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Pavel Emelyanov
     
  • This is the largest patch in the set. Make all (I hope) the places where
    the pid is shown to or get from user operate on the virtual pids.

    The idea is:
    - all in-kernel data structures must store either struct pid itself
    or the pid's global nr, obtained with pid_nr() call;
    - when seeking the task from kernel code with the stored id one
    should use find_task_by_pid() call that works with global pids;
    - when showing pid's numerical value to the user the virtual one
    should be used, but however when one shows task's pid outside this
    task's namespace the global one is to be used;
    - when getting the pid from userspace one need to consider this as
    the virtual one and use appropriate task/pid-searching functions.

    [akpm@linux-foundation.org: build fix]
    [akpm@linux-foundation.org: nuther build fix]
    [akpm@linux-foundation.org: yet nuther build fix]
    [akpm@linux-foundation.org: remove unneeded casts]
    Signed-off-by: Pavel Emelyanov
    Signed-off-by: Alexey Dobriyan
    Cc: Sukadev Bhattiprolu
    Cc: Oleg Nesterov
    Cc: Paul Menage
    Cc: "Eric W. Biederman"
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Pavel Emelyanov
     

19 Oct, 2007

1 commit

  • Get rid of sparse related warnings from places that use integer as NULL
    pointer.

    [akpm@linux-foundation.org: coding-style fixes]
    Signed-off-by: Stephen Hemminger
    Cc: Andi Kleen
    Cc: Jeff Garzik
    Cc: Matt Mackall
    Cc: Ian Kent
    Cc: Arnd Bergmann
    Cc: Davide Libenzi
    Cc: Stephen Smalley
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Stephen Hemminger
     

17 Oct, 2007

1 commit


01 Oct, 2007

1 commit

  • Calling handle_futex_death in exit_robust_list for the different robust
    mutexes of a thread basically frees the mutex. Another thread might grab
    the lock immediately which updates the next pointer of the mutex.
    fetch_robust_entry over the next pointer might therefore branch into the
    robust mutex list of a different thread. This can cause two problems: 1)
    some mutexes held by the dead thread are not getting freed and 2) some
    mutexs held by a different thread are freed.

    The next point need to be read before calling handle_futex_death.

    Signed-off-by: Martin Schwidefsky
    Acked-by: Ingo Molnar
    Acked-by: Thomas Gleixner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Martin Schwidefsky
     

23 Aug, 2007

1 commit


01 Aug, 2007

1 commit

  • The fourth argument of sys_futex is ignored when op == FUTEX_WAKE_OP,
    but futex_wake_op expects it as its nr_wake2 parameter.

    The only user of this operation in glibc is always passing 1, so this
    bug had no consequences so far.

    Signed-off-by: Andreas Schwab
    Cc: Ingo Molnar
    Signed-off-by: Ulrich Drepper
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andreas Schwab
     

20 Jul, 2007

1 commit

  • This patch completes Linus's wish that the fault return codes be made into
    bit flags, which I agree makes everything nicer. This requires requires
    all handle_mm_fault callers to be modified (possibly the modifications
    should go further and do things like fault accounting in handle_mm_fault --
    however that would be for another patch).

    [akpm@linux-foundation.org: fix alpha build]
    [akpm@linux-foundation.org: fix s390 build]
    [akpm@linux-foundation.org: fix sparc build]
    [akpm@linux-foundation.org: fix sparc64 build]
    [akpm@linux-foundation.org: fix ia64 build]
    Signed-off-by: Nick Piggin
    Cc: Richard Henderson
    Cc: Ivan Kokshaysky
    Cc: Russell King
    Cc: Ian Molton
    Cc: Bryan Wu
    Cc: Mikael Starvik
    Cc: David Howells
    Cc: Yoshinori Sato
    Cc: "Luck, Tony"
    Cc: Hirokazu Takata
    Cc: Geert Uytterhoeven
    Cc: Roman Zippel
    Cc: Greg Ungerer
    Cc: Matthew Wilcox
    Cc: Paul Mackerras
    Cc: Benjamin Herrenschmidt
    Cc: Heiko Carstens
    Cc: Martin Schwidefsky
    Cc: Paul Mundt
    Cc: Kazumoto Kojima
    Cc: Richard Curnow
    Cc: William Lee Irwin III
    Cc: "David S. Miller"
    Cc: Jeff Dike
    Cc: Paolo 'Blaisorblade' Giarrusso
    Cc: Miles Bader
    Cc: Chris Zankel
    Acked-by: Kyle McMartin
    Acked-by: Haavard Skinnemoen
    Acked-by: Ralf Baechle
    Acked-by: Andi Kleen
    Signed-off-by: Andrew Morton
    [ Still apparently needs some ARM and PPC loving - Linus ]
    Signed-off-by: Linus Torvalds

    Nick Piggin
     

17 Jul, 2007

1 commit

  • The recent PRIVATE and REQUEUE_PI changes to the futex code made it hard to
    read. Tidy it up.

    Signed-off-by: Thomas Gleixner
    Cc: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Thomas Gleixner
     

25 Jun, 2007

1 commit

  • The return value of futex_find_get_task() needs to be -ESRCH in case
    that the search fails. This was part of the original futex fixes and
    got accidentally dropped, when the futex-tidy-up patch was split out.

    Signed-off-by: Thomas Gleixner
    Cc: Ingo Molnar
    Cc: Stable Team
    Signed-off-by: Linus Torvalds

    Thomas Gleixner
     

19 Jun, 2007

1 commit

  • This reverts commit d0aa7a70bf03b9de9e995ab272293be1f7937822.

    It not only introduced user space visible changes to the futex syscall,
    it is also non-functional and there is no way to fix it proper before
    the 2.6.22 release.

    The breakage report ( http://lkml.org/lkml/2007/5/12/17 ) went
    unanswered, and unfortunately it turned out that the concept is not
    feasible at all. It violates the rtmutex semantics badly by introducing
    a virtual owner, which hacks around the coupling of the user-space
    pi_futex and the kernel internal rt_mutex representation.

    At the moment the only safe option is to remove it fully as it contains
    user-space visible changes to broken kernel code, which we do not want
    to expose in the 2.6.22 release.

    The patch reverts the original patch mostly 1:1, but contains a couple
    of trivial manual cleanups which were necessary due to patches, which
    touched the same area of code later.

    Verified against the glibc tests and my own PI futex tests.

    Signed-off-by: Thomas Gleixner
    Acked-by: Ingo Molnar
    Acked-by: Ulrich Drepper
    Cc: Pierre Peiffer
    Signed-off-by: Linus Torvalds

    Thomas Gleixner
     

09 Jun, 2007

1 commit

  • 1. New entries can be added to tsk->pi_state_list after task completed
    exit_pi_state_list(). The result is memory leakage and deadlocks.

    2. handle_mm_fault() is called under spinlock. The result is obvious.

    3. results in self-inflicted deadlock inside glibc.
    Sometimes futex_lock_pi returns -ESRCH, when it is not expected
    and glibc enters to for(;;) sleep() to simulate deadlock. This problem
    is quite obvious and I think the patch is right. Though it looks like
    each "if" in futex_lock_pi() got some stupid special case "else if". :-)

    4. sometimes futex_lock_pi() returns -EDEADLK,
    when nobody has the lock. The reason is also obvious (see comment
    in the patch), but correct fix is far beyond my comprehension.
    I guess someone already saw this, the chunk:

    if (rt_mutex_trylock(&q.pi_state->pi_mutex))
    ret = 0;

    is obviously from the same opera. But it does not work, because the
    rtmutex is really taken at this point: wake_futex_pi() of previous
    owner reassigned it to us. My fix works. But it looks very stupid.
    I would think about removal of shift of ownership in wake_futex_pi()
    and making all the work in context of process taking lock.

    From: Thomas Gleixner

    Fix 1) Avoid the tasklist lock variant of the exit race fix by adding
    an additional state transition to the exit code.

    This fixes also the issue, when a task with recursive segfaults
    is not able to release the futexes.

    Fix 2) Cleanup the lookup_pi_state() failure path and solve the -ESRCH
    problem finally.

    Fix 3) Solve the fixup_pi_state_owner() problem which needs to do the fixup
    in the lock protected section by using the in_atomic userspace access
    functions.

    This removes also the ugly lock drop / unqueue inside of fixup_pi_state()

    Fix 4) Fix a stale lock in the error path of futex_wake_pi()

    Added some error checks for verification.

    The -EDEADLK problem is solved by the rtmutex fixups.

    Signed-off-by: Thomas Gleixner
    Acked-by: Ingo Molnar
    Cc: Steven Rostedt
    Cc: Ulrich Drepper
    Cc: Eric Dumazet
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexey Kuznetsov
     

10 May, 2007

4 commits

  • Analysis of current linux futex code :
    --------------------------------------

    A central hash table futex_queues[] holds all contexts (futex_q) of waiting
    threads.

    Each futex_wait()/futex_wait() has to obtain a spinlock on a hash slot to
    perform lookups or insert/deletion of a futex_q.

    When a futex_wait() is done, calling thread has to :

    1) - Obtain a read lock on mmap_sem to be able to validate the user pointer
    (calling find_vma()). This validation tells us if the futex uses
    an inode based store (mapped file), or mm based store (anonymous mem)

    2) - compute a hash key

    3) - Atomic increment of reference counter on an inode or a mm_struct

    4) - lock part of futex_queues[] hash table

    5) - perform the test on value of futex.
    (rollback is value != expected_value, returns EWOULDBLOCK)
    (various loops if test triggers mm faults)

    6) queue the context into hash table, release the lock got in 4)

    7) - release the read_lock on mmap_sem

    8) Eventually unqueue the context (but rarely, as this part  may be done
    by the futex_wake())

    Futexes were designed to improve scalability but current implementation has
    various problems :

    - Central hashtable :

    This means scalability problems if many processes/threads want to use
    futexes at the same time.
    This means NUMA unbalance because this hashtable is located on one node.

    - Using mmap_sem on every futex() syscall :

    Even if mmap_sem is a rw_semaphore, up_read()/down_read() are doing atomic
    ops on mmap_sem, dirtying cache line :
    - lot of cache line ping pongs on SMP configurations.

    mmap_sem is also extensively used by mm code (page faults, mmap()/munmap())
    Highly threaded processes might suffer from mmap_sem contention.

    mmap_sem is also used by oprofile code. Enabling oprofile hurts threaded
    programs because of contention on the mmap_sem cache line.

    - Using an atomic_inc()/atomic_dec() on inode ref counter or mm ref counter:
    It's also a cache line ping pong on SMP. It also increases mmap_sem hold time
    because of cache misses.

    Most of these scalability problems come from the fact that futexes are in
    one global namespace. As we use a central hash table, we must make sure
    they are all using the same reference (given by the mm subsystem). We
    chose to force all futexes be 'shared'. This has a cost.

    But fact is POSIX defined PRIVATE and SHARED, allowing clear separation,
    and optimal performance if carefuly implemented. Time has come for linux
    to have better threading performance.

    The goal is to permit new futex commands to avoid :
    - Taking the mmap_sem semaphore, conflicting with other subsystems.
    - Modifying a ref_count on mm or an inode, still conflicting with mm or fs.

    This is possible because, for one process using PTHREAD_PROCESS_PRIVATE
    futexes, we only need to distinguish futexes by their virtual address, no
    matter the underlying mm storage is.

    If glibc wants to exploit this new infrastructure, it should use new
    _PRIVATE futex subcommands for PTHREAD_PROCESS_PRIVATE futexes. And be
    prepared to fallback on old subcommands for old kernels. Using one global
    variable with the FUTEX_PRIVATE_FLAG or 0 value should be OK.

    PTHREAD_PROCESS_SHARED futexes should still use the old subcommands.

    Compatibility with old applications is preserved, they still hit the
    scalability problems, but new applications can fly :)

    Note : the same SHARED futex (mapped on a file) can be used by old binaries
    *and* new binaries, because both binaries will use the old subcommands.

    Note : Vast majority of futexes should be using PROCESS_PRIVATE semantic,
    as this is the default semantic. Almost all applications should benefit
    of this changes (new kernel and updated libc)

    Some bench results on a Pentium M 1.6 GHz (SMP kernel on a UP machine)

    /* calling futex_wait(addr, value) with value != *addr */
    433 cycles per futex(FUTEX_WAIT) call (mixing 2 futexes)
    424 cycles per futex(FUTEX_WAIT) call (using one futex)
    334 cycles per futex(FUTEX_WAIT_PRIVATE) call (mixing 2 futexes)
    334 cycles per futex(FUTEX_WAIT_PRIVATE) call (using one futex)
    For reference :
    187 cycles per getppid() call
    188 cycles per umask() call
    181 cycles per ni_syscall() call

    Signed-off-by: Eric Dumazet
    Pierre Peiffer
    Cc: "Ulrich Drepper"
    Cc: "Nick Piggin"
    Cc: "Ingo Molnar"
    Cc: Rusty Russell
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Eric Dumazet
     
  • This patch provides the futex_requeue_pi functionality, which allows some
    threads waiting on a normal futex to be requeued on the wait-queue of a
    PI-futex.

    This provides an optimization, already used for (normal) futexes, to be used
    with the PI-futexes.

    This optimization is currently used by the glibc in pthread_broadcast, when
    using "normal" mutexes. With futex_requeue_pi, it can be used with
    PRIO_INHERIT mutexes too.

    Signed-off-by: Pierre Peiffer
    Cc: Ingo Molnar
    Cc: Ulrich Drepper
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Pierre Peiffer
     
  • This patch modifies futex_wait() to use an hrtimer + schedule() in place of
    schedule_timeout().

    schedule_timeout() is tick based, therefore the timeout granularity is the
    tick (1 ms, 4 ms or 10 ms depending on HZ). By using a high resolution timer
    for timeout wakeup, we can attain a much finer timeout granularity (in the
    microsecond range). This parallels what is already done for futex_lock_pi().

    The timeout passed to the syscall is no longer converted to jiffies and is
    therefore passed to do_futex() and futex_wait() as an absolute ktime_t
    therefore keeping nanosecond resolution.

    Also this removes the need to pass the nanoseconds timeout part to
    futex_lock_pi() in val2.

    In futex_wait(), if there is no timeout then a regular schedule() is
    performed. Otherwise, an hrtimer is fired before schedule() is called.

    [akpm@linux-foundation.org: fix `make headers_check']
    Signed-off-by: Sebastien Dugue
    Signed-off-by: Pierre Peiffer
    Cc: Ingo Molnar
    Cc: Ulrich Drepper
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Pierre Peiffer
     
  • Today, all threads waiting for a given futex are woken in FIFO order (first
    waiter woken first) instead of priority order.

    This patch makes use of plist (pirotity ordered lists) instead of simple list
    in futex_hash_bucket.

    All non-RT threads are stored with priority MAX_RT_PRIO, causing them to be
    woken last, in FIFO order (RT-threads are woken first, in priority order).

    Signed-off-by: Sebastien Dugue
    Signed-off-by: Pierre Peiffer
    Cc: Ingo Molnar
    Cc: Ulrich Drepper
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Pierre Peiffer
     

09 May, 2007

2 commits

  • LTP test sigaction_16_24 fails, because it expects sem_wait to be restarted
    if SA_RESTART is set. sem_wait is implemented with futex_wait, that
    currently doesn't support being restarted. Ulrich confirms that the call
    should be restartable.

    Implement a restart_block method to handle the relative timeout, and allow
    restarts.

    Signed-off-by: Nick Piggin
    Cc: Ulrich Drepper
    Cc: Rusty Russell
    Cc: Roland McGrath
    Cc: Oleg Nesterov
    Acked-by: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Nick Piggin
     
  • lguest uses the convenient futex infrastructure for inter-domain I/O, so
    expose get_futex_key, get_key_refs (renamed get_futex_key_refs) and
    drop_key_refs (renamed drop_futex_key_refs). Also means we need to expose the
    union that these use.

    No code changes.

    Signed-off-by: Rusty Russell
    Cc: Andi Kleen
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rusty Russell
     

17 Mar, 2007

1 commit

  • Testing of -rt by IBM uncovered a locking bug in wake_futex_pi(): the PI
    state needs to be locked before we access it.

    Signed-off-by: Ingo Molnar
    Acked-by: Thomas Gleixner
    Cc: Chuck Ebbert
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ingo Molnar
     

17 Feb, 2007

1 commit

  • - hrtimers did not use the hrtimer_restart enum and relied on the implict
    int representation. Fix the prototypes and the functions using the enums.
    - Use seperate name spaces for the enumerations
    - Convert hrtimer_restart macro to inline function
    - Add comments

    No functional changes.

    [akpm@osdl.org: fix input driver]
    Signed-off-by: Thomas Gleixner
    Signed-off-by: Ingo Molnar
    Cc: john stultz
    Cc: Roman Zippel
    Cc: Dmitry Torokhov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Thomas Gleixner
     

09 Dec, 2006

1 commit


08 Dec, 2006

5 commits

  • - move some file_operations structs into the .rodata section

    - move static strings from policy_types[] array into the .rodata section

    - fix generic seq_operations usages, so that those structs may be defined
    as "const" as well

    [akpm@osdl.org: couple of fixes]
    Signed-off-by: Helge Deller
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Helge Deller
     
  • When disassembling a kernel I found around over 90 sync Instructions from
    mb, rmb and wmb calls in the kernel and only few of those make any sense to
    me. So here's the first one - I think the wmb() in kernel/futex.c is not
    needed on uniprocessors so should become an smb_wmb().

    Signed-off-by: Ralf Baechle
    Acked-by: Ingo Molnar
    Cc: Thomas Gleixner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ralf Baechle
     
  • Check register_filesystem() and kern_mount() return values.

    Cc: Ingo Molnar
    Signed-off-by: Akinobu Mita
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Akinobu Mita
     
  • Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Burman Yan
     
  • Introduce pagefault_{disable,enable}() and use these where previously we did
    manual preempt increments/decrements to make the pagefault handler do the
    atomic thing.

    Currently they still rely on the increased preempt count, but do not rely on
    the disabled preemption, this might go away in the future.

    (NOTE: the extra barrier() in pagefault_disable might fix some holes on
    machines which have too many registers for their own good)

    [heiko.carstens@de.ibm.com: s390 fix]
    Signed-off-by: Peter Zijlstra
    Acked-by: Nick Piggin
    Cc: Martin Schwidefsky
    Signed-off-by: Heiko Carstens
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Peter Zijlstra