futex: splitup and waitv syscall
Peter Zijlstra
reviewerPATCH 15/20 futex: Simplify double_lock_hb()
In reply to Peter Zijlstra--- kernel/futex/futex.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
kernel/futex/futex.h +6 -8
@@ -316,14 +316,12 @@ extern void futex_q_unlock(struct futex_static inline void double_lock_hb (struct futex_hash_bucket *hb1,struct futex_hash_bucket *hb2) { -if (hb1 <= hb2) { -spin_lock (&hb1->lock); -if (hb1 < hb2) -spin_lock_nested (&hb2->lock,SINGLE_DEPTH_NESTING ); - }else {/* hb1 > hb2 */ -spin_lock (&hb2->lock); -spin_lock_nested (&hb1->lock,SINGLE_DEPTH_NESTING ); - } +if (hb1 > hb2) +swap (hb1, hb2); + +spin_lock (&hb1->lock); +if (hb1 != hb2) +spin_lock_nested (&hb2->lock,SINGLE_DEPTH_NESTING ); } static inline void
Peter Zijlstra
reviewercover futex: splitup and waitv syscall
Hi,
Neither Thomas nor myself much liked that futex2.c nor do we think that CONFIG_ symbol makes much sense.
However, futex.c is a wee bit long and splitting it up makes sense. So I've taken the liberty to replace your initial patch with 15 of my own and then rebased the remaining patches on top of that.
Thomas, does something like this work for you?
Peter Zijlstra
reviewerPATCH 3/20 futex: Rename {,__}{,un}queue_me()
In order to prepare introducing these symbols into the global namespace; rename them:
s/\<\(__\)*\(un\)*queue_me/\1futex_\2queue/g
--- kernel/futex/core.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-)
kernel/futex/core.c +23 -23
@@ -190,7 +190,7 @@ struct futex_pi_state {* the second. * * PI futexes are typically woken before they are removed from the hash list via -* the rt_mutex code. See unqueue_me_pi(). +* the rt_mutex code. See futex_unqueue_pi(). */ struct futex_q {struct plist_node list;
@@ -260,7 +260,7 @@ enum { };static const struct futex_q futex_q_init = { -/* list gets initialized in queue_me()*/ +/* list gets initialized in futex_queue()*/ .key =FUTEX_KEY_INIT , .bitset =FUTEX_BITSET_MATCH_ANY , .requeue_state =ATOMIC_INIT (Q_REQUEUE_PI_NONE ),
@@ -1047,7 +1047,7 @@ static int attach_to_pi_state(u32 __user/* * We get here with hb->lock held, and having found a * futex_top_waiter(). This means that futex_lock_pi() of said futex_q -* has dropped the hb->lock in between queue_me() and unqueue_me_pi(), +* has dropped the hb->lock in between futex_queue() and futex_unqueue_pi(), * which in turn means that futex_lock_pi() still has a reference on * our pi_state. *
@@ -2421,7 +2421,7 @@ static inline struct futex_hash_bucket ** Increment the counter before taking the lock so that * a potential waker won't miss a to-be-slept task that is * waiting for the spinlock. This is safe as all queue_lock() -* users end up calling queue_me(). Similarly, for housekeeping, +* users end up calling futex_queue(). Similarly, for housekeeping, * decrement the counter at queue_unlock() when some error has * occurred and we don't end up adding the task to the list. */
@@ -2441,7 +2441,7 @@ queue_unlock(struct futex_hash_bucket *hhb_waiters_dec (hb); } -static inline void __queue_me (struct futex_q *q,struct futex_hash_bucket *hb) +static inline void __futex_queue (struct futex_q *q,struct futex_hash_bucket *hb) {int prio;
@@ -2461,36 +2461,36 @@ static inline void __queue_me(struct fut }/** -* queue_me() - Enqueue the futex_q on the futex_hash_bucket +* futex_queue() - Enqueue the futex_q on the futex_hash_bucket * @q: The futex_q to enqueue * @hb: The destination hash bucket * * The hb->lock must be held by the caller, and is released here. A call to -* queue_me() is typically paired with exactly one call to unqueue_me(). The -* exceptions involve the PI related operations, which may use unqueue_me_pi() +* futex_queue() is typically paired with exactly one call to futex_unqueue(). The +* exceptions involve the PI related operations, which may use futex_unqueue_pi() * or nothing if the unqueue is done as part of the wake process and the unqueue * state is implicit in the state of woken task (see futex_wait_requeue_pi() for * an example). */ -static inline void queue_me (struct futex_q *q,struct futex_hash_bucket *hb) +static inline void futex_queue (struct futex_q *q,struct futex_hash_bucket *hb) __releases(&hb->lock) { -__queue_me (q, hb); +__futex_queue (q, hb);spin_unlock (&hb->lock); }/** -* unqueue_me() - Remove the futex_q from its futex_hash_bucket +* futex_unqueue() - Remove the futex_q from its futex_hash_bucket * @q: The futex_q to unqueue * -* The q->lock_ptr must not be held by the caller. A call to unqueue_me() must -* be paired with exactly one earlier call to queue_me(). +* The q->lock_ptr must not be held by the caller. A call to futex_unqueue() must +* be paired with exactly one earlier call to futex_queue(). * * Return: * - 1 - if the futex_q was still queued (and we removed unqueued it); * - 0 - if the futex_q was already removed by the waking thread */ -static int unqueue_me (struct futex_q *q) +static int futex_unqueue (struct futex_q *q) {spinlock_t *lock_ptr;int ret =0 ;
@@ -2537,7 +2537,7 @@ static int unqueue_me(struct futex_q *q)* PI futexes can not be requeued and must remove themselves from the * hash bucket. The hash bucket lock (i.e. lock_ptr) is held. */ -static void unqueue_me_pi (struct futex_q *q) +static void futex_unqueue_pi (struct futex_q *q) {__unqueue_futex (q);
@@ -2787,7 +2787,7 @@ static int fixup_owner(u32 __user *uaddr }/** -* futex_wait_queue_me() - queue_me() and wait for wakeup, timeout, or signal +* futex_wait_queue_me() - futex_queue() and wait for wakeup, timeout, or signal * @hb: the futex hash bucket, must be locked by the caller * @q: the futex_q to queue up on * @timeout: the prepared hrtimer_sleeper, or null for no timeout
@@ -2798,11 +2798,11 @@ static void futex_wait_queue_me(struct f/* * The task state is guaranteed to be set before another task can * wake it. set_current_state() is implemented using smp_store_mb() and -* queue_me() calls spin_unlock() upon completion, both serializing +* futex_queue() calls spin_unlock() upon completion, both serializing * access to the hash list and forcing another memory barrier. */ set_current_state (TASK_INTERRUPTIBLE ); -queue_me (q, hb); +futex_queue (q, hb);/* Arm the timer */ if (timeout)
@@ -2918,12 +2918,12 @@ int futex_wait(u32 __user *uaddr, unsignif (ret) goto out; -/* queue_me and wait for wakeup, timeout, or a signal. */ +/* futex_queue and wait for wakeup, timeout, or a signal. */ futex_wait_queue_me (hb, &q, to);/* If we were woken (and unqueued), we succeeded, whatever. */ ret =0 ; -if (!unqueue_me (&q)) +if (!futex_unqueue (&q)) goto out; ret = -ETIMEDOUT ;if (to && !to->task)
@@ -3049,7 +3049,7 @@ int futex_lock_pi(u32 __user *uaddr, uns/* * Only actually queue now that the atomic ops are done: */ -__queue_me (&q, hb); +__futex_queue (&q, hb);if (trylock) { ret =rt_mutex_futex_trylock (&q.pi_state->pi_mutex);
@@ -3121,7 +3121,7 @@ int futex_lock_pi(u32 __user *uaddr, unsif (res) ret = (res <0 ) ? res :0 ; -unqueue_me_pi (&q); +futex_unqueue_pi (&q);spin_unlock (q.lock_ptr); goto out;
@@ -3479,7 +3479,7 @@ int futex_wait_requeue_pi(u32 __user *uaif (res) ret = (res <0 ) ? res :0 ; -unqueue_me_pi (&q); +futex_unqueue_pi (&q);spin_unlock (q.lock_ptr);if (ret == -EINTR ) {
Peter Zijlstra
reviewerPATCH 4/20 futex: Rename futex_wait_queue_me()
In reply to Peter ZijlstraIn order to prepare introducing these symbols into the global namespace; rename them:
s/futex_wait_queue_me/futex_wait_queue/g
--- kernel/futex/core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/futex/core.c +5 -5
@@ -2787,12 +2787,12 @@ static int fixup_owner(u32 __user *uaddr }/** -* futex_wait_queue_me() - futex_queue() and wait for wakeup, timeout, or signal +* futex_wait_queue() - futex_queue() and wait for wakeup, timeout, or signal * @hb: the futex hash bucket, must be locked by the caller * @q: the futex_q to queue up on * @timeout: the prepared hrtimer_sleeper, or null for no timeout */ -static void futex_wait_queue_me (struct futex_hash_bucket *hb,struct futex_q *q, +static void futex_wait_queue (struct futex_hash_bucket *hb,struct futex_q *q,struct hrtimer_sleeper *timeout) {/*
@@ -2919,7 +2919,7 @@ int futex_wait(u32 __user *uaddr, unsign goto out;/* futex_queue and wait for wakeup, timeout, or a signal. */ -futex_wait_queue_me (hb, &q, to); +futex_wait_queue (hb, &q, to);/* If we were woken (and unqueued), we succeeded, whatever. */ ret =0 ;
@@ -3347,7 +3347,7 @@ int handle_early_requeue_pi_wakeup(struc* without one, the pi logic would not know which task to boost/deboost, if * there was a need to. * -* We call schedule in futex_wait_queue_me() when we enqueue and return there +* We call schedule in futex_wait_queue() when we enqueue and return there * via the following-- * 1) wakeup on uaddr2 after an atomic lock acquisition by futex_requeue() * 2) wakeup on uaddr2 after a requeue
@@ -3427,7 +3427,7 @@ int futex_wait_requeue_pi(u32 __user *ua }/* Queue the futex_q, drop the hb lock, wait for wakeup. */ -futex_wait_queue_me (hb, &q, to); +futex_wait_queue (hb, &q, to);switch (futex_requeue_pi_wakeup_sync (&q)) {case Q_REQUEUE_PI_IGNORE :
Peter Zijlstra
reviewerPATCH 6/20 futex: Rename __unqueue_futex()
In reply to Peter ZijlstraIn order to prepare introducing these symbols into the global namespace; rename:
s/__unqueue_futex/__futex_unqueue/g
--- kernel/futex/core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
kernel/futex/core.c +7 -7
@@ -1470,12 +1470,12 @@ static int futex_lock_pi_atomic(u32 __us }/** -* __unqueue_futex() - Remove the futex_q from its futex_hash_bucket +* __futex_unqueue() - Remove the futex_q from its futex_hash_bucket * @q: The futex_q to unqueue * * The q->lock_ptr must not be NULL and must be held by the caller. */ -static void __unqueue_futex (struct futex_q *q) +static void __futex_unqueue (struct futex_q *q) {struct futex_hash_bucket *hb;
@@ -1502,13 +1502,13 @@ static void mark_wake_futex(struct wake_return ;get_task_struct (p); -__unqueue_futex (q); +__futex_unqueue (q);/* * The waiting task can free the futex_q as soon as q->lock_ptr = NULL * is written, without taking any locks. This is possible in the event * of a spurious wakeup, for example. A memory barrier is required here * to prevent the following store to lock_ptr from getting ahead of the -* plist_del in __unqueue_futex(). +* plist_del in __futex_unqueue(). */ smp_store_release (&q->lock_ptr,NULL );
@@ -1958,7 +1958,7 @@ void requeue_pi_wake_futex(struct futex_ { q->key = *key; -__unqueue_futex (q); +__futex_unqueue (q);WARN_ON (!q->rt_waiter); q->rt_waiter =NULL ;
@@ -2522,7 +2522,7 @@ static int futex_unqueue(struct futex_qspin_unlock (lock_ptr); goto retry; } -__unqueue_futex (q); +__futex_unqueue (q);BUG_ON (q->pi_state);
@@ -2539,7 +2539,7 @@ static int futex_unqueue(struct futex_q*/ static void futex_unqueue_pi (struct futex_q *q) { -__unqueue_futex (q); +__futex_unqueue (q);BUG_ON (!q->pi_state);put_pi_state (q->pi_state);
Peter Zijlstra
reviewerPATCH 8/20 futex: Rename: {get,cmpxchg}_futex_value_locked()
In reply to Peter ZijlstraIn order to prepare introducing these symbols into the global namespace; rename them:
s/\<\([^_ ]*\)_futex_value_locked/futex_\1_value_locked/g
--- kernel/futex/core.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
kernel/futex/core.c +15 -15
@@ -732,7 +732,7 @@ static struct futex_q *futex_top_waiter(return NULL ; } -static int cmpxchg_futex_value_locked (u32 *curval,u32 __user *uaddr, +static int futex_cmpxchg_value_locked (u32 *curval,u32 __user *uaddr,u32 uval,u32 newval) {int ret;
@@ -744,7 +744,7 @@ static int cmpxchg_futex_value_locked(u3return ret; } -static int get_futex_value_locked (u32 *dest,u32 __user *from) +static int futex_get_value_locked (u32 *dest,u32 __user *from) {int ret;
@@ -1070,7 +1070,7 @@ static int attach_to_pi_state(u32 __user* still is what we expect it to be, otherwise retry the entire * operation. */ -if (get_futex_value_locked (&uval2, uaddr)) +if (futex_get_value_locked (&uval2, uaddr)) goto out_efault;if (uval != uval2)
@@ -1220,7 +1220,7 @@ static int handle_exit_race(u32 __user ** The same logic applies to the case where the exiting task is * already gone. */ -if (get_futex_value_locked (&uval2, uaddr)) +if (futex_get_value_locked (&uval2, uaddr))return -EFAULT ;/* If the user space value has changed, try again. */
@@ -1341,7 +1341,7 @@ static int lock_pi_update_atomic(u32 __uif (unlikely (should_fail_futex (true)))return -EFAULT ; - err =cmpxchg_futex_value_locked (&curval, uaddr, uval, newval); + err =futex_cmpxchg_value_locked (&curval, uaddr, uval, newval);if (unlikely (err))return err;
@@ -1388,7 +1388,7 @@ static int futex_lock_pi_atomic(u32 __us* Read the user space value first so we can validate a few * things before proceeding further. */ -if (get_futex_value_locked (&uval, uaddr)) +if (futex_get_value_locked (&uval, uaddr))return -EFAULT ;if (unlikely (should_fail_futex (true)))
@@ -1559,7 +1559,7 @@ static int wake_futex_pi(u32 __user *uad goto out_unlock; } - ret =cmpxchg_futex_value_locked (&curval, uaddr, uval, newval); + ret =futex_cmpxchg_value_locked (&curval, uaddr, uval, newval);if (!ret && (curval != uval)) {/* * If a unconditional UNLOCK_PI operation (user space did not
@@ -2006,7 +2006,7 @@ futex_proxy_trylock_atomic(u32 __user *pu32 curval;int ret; -if (get_futex_value_locked (&curval, pifutex)) +if (futex_get_value_locked (&curval, pifutex))return -EFAULT ;if (unlikely (should_fail_futex (true)))
@@ -2182,7 +2182,7 @@ int futex_requeue(u32 __user *uaddr1, unif (likely (cmpval !=NULL )) {u32 curval; - ret =get_futex_value_locked (&curval, uaddr1); + ret =futex_get_value_locked (&curval, uaddr1);if (unlikely (ret)) {double_unlock_hb (hb1, hb2);
@@ -2628,14 +2628,14 @@ static int __fixup_pi_state_owner(u32 __if (!pi_state->owner) newtid |=FUTEX_OWNER_DIED ; - err =get_futex_value_locked (&uval, uaddr); + err =futex_get_value_locked (&uval, uaddr);if (err) goto handle_err;for (;;) { newval = (uval &FUTEX_OWNER_DIED ) | newtid; - err =cmpxchg_futex_value_locked (&curval, uaddr, uval, newval); + err =futex_cmpxchg_value_locked (&curval, uaddr, uval, newval);if (err) goto handle_err;
@@ -2872,7 +2872,7 @@ static int futex_wait_setup(u32 __user * retry_private: *hb =futex_q_lock (q); - ret =get_futex_value_locked (&uval, uaddr); + ret =futex_get_value_locked (&uval, uaddr);if (ret) {futex_q_unlock (*hb);
@@ -3250,7 +3250,7 @@ int futex_unlock_pi(u32 __user *uaddr, u* preserve the WAITERS bit not the OWNER_DIED one. We are the * owner. */ -if ((ret =cmpxchg_futex_value_locked (&curval, uaddr, uval,0 ))) { +if ((ret =futex_cmpxchg_value_locked (&curval, uaddr, uval,0 ))) {spin_unlock (&hb->lock);switch (ret) {case -EFAULT :
@@ -3588,7 +3588,7 @@ static int handle_futex_death(u32 __user* does not guarantee R/W access. If that fails we * give up and leave the futex locked. */ -if ((err =cmpxchg_futex_value_locked (&nval, uaddr, uval, mval))) { +if ((err =futex_cmpxchg_value_locked (&nval, uaddr, uval, mval))) {switch (err) {case -EFAULT :if (fault_in_user_writeable (uaddr))
@@ -3934,7 +3934,7 @@ static void __init futex_detect_cmpxchg(* implementation, the non-functional ones will return * -ENOSYS. */ -if (cmpxchg_futex_value_locked (&curval,NULL ,0 ,0 ) == -EFAULT ) +if (futex_cmpxchg_value_locked (&curval,NULL ,0 ,0 ) == -EFAULT ) futex_cmpxchg_enabled =1 ;#endif }
Peter Zijlstra
reviewerPATCH 11/20 futex: Rename: match_futex()
In reply to Peter ZijlstraIn order to prepare introducing these symbols into the global namespace; rename:
s/match_futex/futex_match/g
--- kernel/futex/core.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
kernel/futex/core.c +12 -12
@@ -324,13 +324,13 @@ static struct futex_hash_bucket *futex_h/** -* match_futex - Check whether two futex keys are equal +* futex_match - Check whether two futex keys are equal * @key1: Pointer to key1 * @key2: Pointer to key2 * * Return 1 if two futex_keys are equal, 0 otherwise. */ -static inline int match_futex (union futex_key *key1,union futex_key *key2) +static inline int futex_match (union futex_key *key1,union futex_key *key2) {return (key1 && key2 && key1->both.word == key2->both.word
@@ -381,7 +381,7 @@ futex_setup_timer(ktime_t *time, struct* a new sequence number and will _NOT_ match, even though it is the exact same * file. * -* It is important that match_futex() will never have a false-positive, esp. +* It is important that futex_match() will never have a false-positive, esp. * for PI futexes that can mess up the state. The above argues that false-negatives * are only possible for malformed programs. */
@@ -648,7 +648,7 @@ struct futex_q *futex_top_waiter(structstruct futex_q *this;plist_for_each_entry (this, &hb->chain, list) { -if (match_futex (&this->key, key)) +if (futex_match (&this->key, key))return this; }return NULL ;
@@ -808,7 +808,7 @@ int futex_wake(u32 __user *uaddr, unsignspin_lock (&hb->lock);plist_for_each_entry_safe (this, next, &hb->chain, list) { -if (match_futex (&this->key, &key)) { +if (futex_match (&this->key, &key)) {if (this->pi_state || this->rt_waiter) { ret = -EINVAL ;break ;
@@ -928,7 +928,7 @@ int futex_wake_op(u32 __user *uaddr1, un }plist_for_each_entry_safe (this, next, &hb1->chain, list) { -if (match_futex (&this->key, &key1)) { +if (futex_match (&this->key, &key1)) {if (this->pi_state || this->rt_waiter) { ret = -EINVAL ; goto out_unlock;
@@ -942,7 +942,7 @@ int futex_wake_op(u32 __user *uaddr1, unif (op_ret >0 ) { op_ret =0 ;plist_for_each_entry_safe (this, next, &hb2->chain, list) { -if (match_futex (&this->key, &key2)) { +if (futex_match (&this->key, &key2)) {if (this->pi_state || this->rt_waiter) { ret = -EINVAL ; goto out_unlock;
@@ -1199,7 +1199,7 @@ futex_proxy_trylock_atomic(u32 __user *preturn -EINVAL ;/* Ensure we requeue to the expected futex. */ -if (!match_futex (top_waiter->requeue_pi_key, key2)) +if (!futex_match (top_waiter->requeue_pi_key, key2))return -EINVAL ;/* Ensure that this does not race against an early wakeup */
@@ -1334,7 +1334,7 @@ int futex_requeue(u32 __user *uaddr1, un* The check above which compares uaddrs is not sufficient for * shared futexes. We need to compare the keys: */ -if (requeue_pi &&match_futex (&key1, &key2)) +if (requeue_pi &&futex_match (&key1, &key2))return -EINVAL ; hb1 =futex_hash (&key1);
@@ -1469,7 +1469,7 @@ int futex_requeue(u32 __user *uaddr1, unif (task_count - nr_wake >= nr_requeue)break ; -if (!match_futex (&this->key, &key1)) +if (!futex_match (&this->key, &key1))continue ;/*
@@ -1496,7 +1496,7 @@ int futex_requeue(u32 __user *uaddr1, un }/* Ensure we requeue to the expected futex for requeue_pi. */ -if (!match_futex (this->requeue_pi_key, &key2)) { +if (!futex_match (this->requeue_pi_key, &key2)) { ret = -EINVAL ;break ; }
@@ -2043,7 +2043,7 @@ int futex_wait_requeue_pi(u32 __user *ua* The check above which compares uaddrs is not sufficient for * shared futexes. We need to compare the keys: */ -if (match_futex (&q.key, &key2)) { +if (futex_match (&q.key, &key2)) {futex_q_unlock (hb); ret = -EINVAL ; goto out;
Peter Zijlstra
reviewerPATCH 5/20 futex: Rename: queue_{,un}lock()
In reply to Peter ZijlstraIn order to prepare introducing these symbols into the global namespace; rename them:
s/queue_\(un\)*lock/futex_q_\1lock/g
--- kernel/futex/core.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
kernel/futex/core.c +13 -13
@@ -132,7 +132,7 @@* * Note that a new waiter is accounted for in (a) even when it is possible that * the wait call can return error, in which case we backtrack from it in (b). -* Refer to the comment in queue_lock(). +* Refer to the comment in futex_q_lock(). * * Similarly, in order to account for waiters being requeued on another * address we always increment the waiters for the destination bucket before
@@ -2410,7 +2410,7 @@ int futex_requeue(u32 __user *uaddr1, un }/* The key must be already stored in q->key. */ -static inline struct futex_hash_bucket *queue_lock (struct futex_q *q) +static inline struct futex_hash_bucket *futex_q_lock (struct futex_q *q) __acquires(&hb->lock) {struct futex_hash_bucket *hb;
@@ -2420,9 +2420,9 @@ static inline struct futex_hash_bucket */* * Increment the counter before taking the lock so that * a potential waker won't miss a to-be-slept task that is -* waiting for the spinlock. This is safe as all queue_lock() +* waiting for the spinlock. This is safe as all futex_q_lock() * users end up calling futex_queue(). Similarly, for housekeeping, -* decrement the counter at queue_unlock() when some error has +* decrement the counter at futex_q_unlock() when some error has * occurred and we don't end up adding the task to the list. */ hb_waiters_inc (hb);/* implies smp_mb(); (A) */
@@ -2434,7 +2434,7 @@ static inline struct futex_hash_bucket * }static inline void -queue_unlock (struct futex_hash_bucket *hb) +futex_q_unlock (struct futex_hash_bucket *hb) __releases(&hb->lock) {spin_unlock (&hb->lock);
@@ -2870,12 +2870,12 @@ static int futex_wait_setup(u32 __user *return ret; retry_private: - *hb =queue_lock (q); + *hb =futex_q_lock (q); ret =get_futex_value_locked (&uval, uaddr);if (ret) { -queue_unlock (*hb); +futex_q_unlock (*hb); ret =get_user (uval, uaddr);if (ret)
@@ -2888,7 +2888,7 @@ static int futex_wait_setup(u32 __user * }if (uval != val) { -queue_unlock (*hb); +futex_q_unlock (*hb); ret = -EWOULDBLOCK ; }
@@ -3006,7 +3006,7 @@ int futex_lock_pi(u32 __user *uaddr, uns goto out; retry_private: - hb =queue_lock (&q); + hb =futex_q_lock (&q); ret =futex_lock_pi_atomic (uaddr, hb, &q.key, &q.pi_state, current, &exiting,0 );
@@ -3030,7 +3030,7 @@ int futex_lock_pi(u32 __user *uaddr, uns* exit to complete. * - EAGAIN: The user space value changed. */ -queue_unlock (hb); +futex_q_unlock (hb);/* * Handle the case where the owner is in the middle of * exiting. Wait for the exit to complete otherwise
@@ -3126,7 +3126,7 @@ int futex_lock_pi(u32 __user *uaddr, uns goto out; out_unlock_put_key: -queue_unlock (hb); +futex_q_unlock (hb); out:if (to) {
@@ -3136,7 +3136,7 @@ int futex_lock_pi(u32 __user *uaddr, unsreturn ret != -EINTR ? ret : -ERESTARTNOINTR ; uaddr_faulted: -queue_unlock (hb); +futex_q_unlock (hb); ret =fault_in_user_writeable (uaddr);if (ret)
@@ -3421,7 +3421,7 @@ int futex_wait_requeue_pi(u32 __user *ua* shared futexes. We need to compare the keys: */ if (match_futex (&q.key, &key2)) { -queue_unlock (hb); +futex_q_unlock (hb); ret = -EINVAL ; goto out; }
Peter Zijlstra
reviewerPATCH 13/20 futex: Split out requeue
In reply to Peter ZijlstraMove all the requeue bits into their own file.
--- kernel/futex/Makefile | 2 kernel/futex/core.c | 966 ------------------------------------------------- kernel/futex/futex.h | 77 +++ kernel/futex/requeue.c | 897 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 979 insertions(+), 963 deletions(-)
kernel/futex/Makefile +1 -1
@@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 -obj-y += core.o syscalls.o pi.o +obj-y += core.o syscalls.o pi.o requeue.o
kernel/futex/core.c +6 -960
1,026 lines not on this page · raw message
kernel/futex/futex.h +75 -2
109 lines not on this page · raw message
kernel/futex/requeue.c new file +897 -0
897 lines not on this page · raw message
Peter Zijlstra
reviewerPATCH 9/20 futex: Split out PI futex
In reply to Peter ZijlstraMove the PI futex implementation into it's own file.
--- kernel/futex/Makefile | 2 kernel/futex/core.c | 1502 +++----------------------------------------------- kernel/futex/futex.h | 117 +++ kernel/futex/pi.c | 1233 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1449 insertions(+), 1405 deletions(-)
kernel/futex/Makefile +1 -1
@@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 -obj-y += core.o syscalls.o +obj-y += core.o syscalls.o pi.o
kernel/futex/core.c +98 -1404
1,650 lines not on this page · raw message
kernel/futex/futex.h +117 -0
129 lines not on this page · raw message
kernel/futex/pi.c new file +1233 -0
1,217 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Peter Zijlstra
reviewerPATCH 7/20 futex: Rename hash_futex()
In reply to Peter ZijlstraIn order to prepare introducing these symbols into the global namespace; rename:
s/hash_futex/hash_futex/g
--- kernel/futex/core.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
kernel/futex/core.c +11 -11
@@ -279,7 +279,7 @@ struct futex_hash_bucket {/* * The base of the bucket array and its size are always used together -* (after initialization only in hash_futex()), so ensure that they +* (after initialization only in futex_hash()), so ensure that they * reside in the same cacheline. */ static struct {
@@ -380,13 +380,13 @@ static inline int hb_waiters_pending(str }/** -* hash_futex - Return the hash bucket in the global hash +* futex_hash - Return the hash bucket in the global hash * @key: Pointer to the futex key for which the hash is calculated * * We hash on the keys returned from get_futex_key (see below) and return the * corresponding hash bucket in the global hash. */ -static struct futex_hash_bucket *hash_futex (union futex_key *key) +static struct futex_hash_bucket *futex_hash (union futex_key *key) { u32 hash = jhash2((u32 *)key, offsetof(typeof(*key), both.offset) / 4, key->both.offset);
@@ -885,7 +885,7 @@ static void exit_pi_state_list(struct ta next = head->next; pi_state = list_entry(next, struct futex_pi_state, list); key = pi_state->key; - hb =hash_futex (&key); + hb =futex_hash (&key);/* * We can race against put_pi_state() removing itself from the
@@ -1634,7 +1634,7 @@ int futex_wake(u32 __user *uaddr, unsignif (unlikely (ret !=0 ))return ret; - hb =hash_futex (&key); + hb =futex_hash (&key);/* Make sure we really have tasks to wakeup */ if (!hb_waiters_pending (hb))
@@ -1731,8 +1731,8 @@ int futex_wake_op(u32 __user *uaddr1, unif (unlikely (ret !=0 ))return ret; - hb1 =hash_futex (&key1); - hb2 =hash_futex (&key2); + hb1 =futex_hash (&key1); + hb2 =futex_hash (&key2); retry_private:double_lock_hb (hb1, hb2);
@@ -2172,8 +2172,8 @@ int futex_requeue(u32 __user *uaddr1, unif (requeue_pi &&match_futex (&key1, &key2))return -EINVAL ; - hb1 =hash_futex (&key1); - hb2 =hash_futex (&key2); + hb1 =futex_hash (&key1); + hb2 =futex_hash (&key2); retry_private:hb_waiters_inc (hb2);
@@ -2415,7 +2415,7 @@ static inline struct futex_hash_bucket * {struct futex_hash_bucket *hb; - hb =hash_futex (&q->key); + hb =futex_hash (&q->key);/* * Increment the counter before taking the lock so that
@@ -3177,7 +3177,7 @@ int futex_unlock_pi(u32 __user *uaddr, uif (ret)return ret; - hb =hash_futex (&key); + hb =futex_hash (&key);spin_lock (&hb->lock);/*
Peter Zijlstra
reviewerPATCH 10/20 futex: Rename: hb_waiter_{inc,dec,pending}()
In reply to Peter ZijlstraIn order to prepare introducing these symbols into the global namespace; rename them:
s/hb_waiters_/futex_&/g
--- kernel/futex/core.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
kernel/futex/core.c +17 -17
@@ -115,8 +115,8 @@* waiters--; (b) unlock(hash_bucket(futex)); * * Where (A) orders the waiters increment and the futex value read through -* atomic operations (see hb_waiters_inc) and where (B) orders the write -* to futex and the waiters read (see hb_waiters_pending()). +* atomic operations (see futex_hb_waiters_inc) and where (B) orders the write +* to futex and the waiters read (see futex_hb_waiters_pending()). * * This yields the following case (where X:=waiters, Y:=futex): *
@@ -272,7 +272,7 @@ late_initcall(fail_futex_debugfs);/* * Reflects a new waiter being added to the waitqueue. */ -static inline void hb_waiters_inc (struct futex_hash_bucket *hb) +static inline void futex_hb_waiters_inc (struct futex_hash_bucket *hb) {#ifdef CONFIG_SMP atomic_inc (&hb->waiters);
@@ -287,14 +287,14 @@ static inline void hb_waiters_inc(struct* Reflects a waiter being removed from the waitqueue by wakeup * paths. */ -static inline void hb_waiters_dec (struct futex_hash_bucket *hb) +static inline void futex_hb_waiters_dec (struct futex_hash_bucket *hb) {#ifdef CONFIG_SMP atomic_dec (&hb->waiters);#endif } -static inline int hb_waiters_pending (struct futex_hash_bucket *hb) +static inline int futex_hb_waiters_pending (struct futex_hash_bucket *hb) {#ifdef CONFIG_SMP /*
@@ -723,7 +723,7 @@ static void __futex_unqueue(struct futex hb = container_of(q->lock_ptr, struct futex_hash_bucket, lock);plist_del (&q->list, &hb->chain); -hb_waiters_dec (hb); +futex_hb_waiters_dec (hb); }/*
@@ -802,7 +802,7 @@ int futex_wake(u32 __user *uaddr, unsign hb =futex_hash (&key);/* Make sure we really have tasks to wakeup */ -if (!hb_waiters_pending (hb)) +if (!futex_hb_waiters_pending (hb))return ret;spin_lock (&hb->lock);
@@ -979,8 +979,8 @@ void requeue_futex(struct futex_q *q, st*/ if (likely (&hb1->chain != &hb2->chain)) {plist_del (&q->list, &hb1->chain); -hb_waiters_dec (hb1); -hb_waiters_inc (hb2); +futex_hb_waiters_dec (hb1); +futex_hb_waiters_inc (hb2);plist_add (&q->list, &hb2->chain); q->lock_ptr = &hb2->lock; }
@@ -1341,7 +1341,7 @@ int futex_requeue(u32 __user *uaddr1, un hb2 =futex_hash (&key2); retry_private: -hb_waiters_inc (hb2); +futex_hb_waiters_inc (hb2);double_lock_hb (hb1, hb2);if (likely (cmpval !=NULL )) {
@@ -1351,7 +1351,7 @@ int futex_requeue(u32 __user *uaddr1, unif (unlikely (ret)) {double_unlock_hb (hb1, hb2); -hb_waiters_dec (hb2); +futex_hb_waiters_dec (hb2); ret =get_user (curval, uaddr1);if (ret)
@@ -1437,7 +1437,7 @@ int futex_requeue(u32 __user *uaddr1, un*/ case -EFAULT :double_unlock_hb (hb1, hb2); -hb_waiters_dec (hb2); +futex_hb_waiters_dec (hb2); ret =fault_in_user_writeable (uaddr2);if (!ret) goto retry;
@@ -1451,7 +1451,7 @@ int futex_requeue(u32 __user *uaddr1, un* - EAGAIN: The user space value changed. */ double_unlock_hb (hb1, hb2); -hb_waiters_dec (hb2); +futex_hb_waiters_dec (hb2);/* * Handle the case where the owner is in the middle of * exiting. Wait for the exit to complete otherwise
@@ -1570,7 +1570,7 @@ int futex_requeue(u32 __user *uaddr1, un out_unlock:double_unlock_hb (hb1, hb2);wake_up_q (&wake_q); -hb_waiters_dec (hb2); +futex_hb_waiters_dec (hb2);return ret ? ret : task_count; }
@@ -1600,7 +1600,7 @@ struct futex_hash_bucket *futex_q_lock(s* decrement the counter at futex_q_unlock() when some error has * occurred and we don't end up adding the task to the list. */ -hb_waiters_inc (hb);/* implies smp_mb(); (A) */ +futex_hb_waiters_inc (hb);/* implies smp_mb(); (A) */ q->lock_ptr = &hb->lock;
@@ -1612,7 +1612,7 @@ void futex_q_unlock(struct futex_hash_bu __releases(&hb->lock) {spin_unlock (&hb->lock); -hb_waiters_dec (hb); +futex_hb_waiters_dec (hb); }void __futex_queue (struct futex_q *q,struct futex_hash_bucket *hb)
@@ -1942,7 +1942,7 @@ int handle_early_requeue_pi_wakeup(struc* Unqueue the futex_q and determine which it was. */ plist_del (&q->list, &hb->chain); -hb_waiters_dec (hb); +futex_hb_waiters_dec (hb);/* Handle spurious wakeups gracefully */ ret = -EWOULDBLOCK ;
Peter Zijlstra
reviewerPATCH 12/20 futex: Rename mark_wake_futex()
In reply to Peter ZijlstraIn order to prepare introducing these symbols into the global namespace; rename:
s/mark_wake_futex/futex_wake_mark/g
--- kernel/futex/core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/futex/core.c +5 -5
@@ -732,7 +732,7 @@ static void __futex_unqueue(struct futex* must ensure to later call wake_up_q() for the actual * wakeups to occur. */ -static void mark_wake_futex (struct wake_q_head *wake_q,struct futex_q *q) +static void futex_wake_mark (struct wake_q_head *wake_q,struct futex_q *q) {struct task_struct *p = q->task;
@@ -818,7 +818,7 @@ int futex_wake(u32 __user *uaddr, unsignif (!(this->bitset & bitset))continue ; -mark_wake_futex (&wake_q, this); +futex_wake_mark (&wake_q, this);if (++ret >= nr_wake)break ; }
@@ -933,7 +933,7 @@ int futex_wake_op(u32 __user *uaddr1, un ret = -EINVAL ; goto out_unlock; } -mark_wake_futex (&wake_q, this); +futex_wake_mark (&wake_q, this);if (++ret >= nr_wake)break ; }
@@ -947,7 +947,7 @@ int futex_wake_op(u32 __user *uaddr1, un ret = -EINVAL ; goto out_unlock; } -mark_wake_futex (&wake_q, this); +futex_wake_mark (&wake_q, this);if (++op_ret >= nr_wake2)break ; }
@@ -1489,7 +1489,7 @@ int futex_requeue(u32 __user *uaddr1, un/* Plain futexes just wake or requeue and are done */ if (!requeue_pi) {if (++task_count <= nr_wake) -mark_wake_futex (&wake_q, this); +futex_wake_mark (&wake_q, this);else requeue_futex (this, hb1, hb2, &key2);continue ;
Peter Zijlstra
reviewerPATCH 2/20 futex: Split out syscalls
In reply to Peter ZijlstraPut the syscalls in their own little file.
--- kernel/futex/Makefile | 2 kernel/futex/core.c | 532 ++++++++++-------------------------------------- kernel/futex/futex.h | 58 +++++ kernel/futex/syscalls.c | 279 +++++++++++++++++++++++++ 4 files changed, 453 insertions(+), 418 deletions(-)
kernel/futex/Makefile +1 -1
@@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 -obj-y += core.o +obj-y += core.o syscalls.o
kernel/futex/core.c +115 -417
650 lines not on this page · raw message
kernel/futex/futex.h new file +58 -0
58 lines not on this page · raw message
kernel/futex/syscalls.c new file +279 -0
279 lines not on this page · raw message
Peter Zijlstra
reviewerPATCH 1/20 futex: Move to kernel/futex/
In reply to Peter ZijlstraIn preparation for splitup..
--- MAINTAINERS | 2 kernel/Makefile | 2 kernel/futex.c | 4272 -------------------------------------------------- kernel/futex/Makefile | 3 kernel/futex/core.c | 4272 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 4277 insertions(+), 4274 deletions(-)
MAINTAINERS +1 -1
@@ -7720,7 +7720,7 @@ F: Documentation/locking/*futex* F: include/asm-generic/futex.h F: include/linux/futex.h F: include/uapi/linux/futex.h -F: kernel/futex.c +F: kernel/futex/* F: tools/perf/bench/futex* F: tools/testing/selftests/futex/
kernel/Makefile +1 -1
@@ -59,7 +59,7 @@ obj-$(CONFIG_FREEZER) += freezer.o obj-$(CONFIG_PROFILING) += profile.o obj-$(CONFIG_STACKTRACE) += stacktrace.o obj-y += time/ -obj-$(CONFIG_FUTEX) += futex.o +obj-$(CONFIG_FUTEX) += futex/ obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o obj-$(CONFIG_SMP) += smp.o ifneq ($(CONFIG_SMP),y)
kernel/futex.c deleted +0 -4272
2,984 lines not on this page · raw message
kernel/futex/Makefile new file +3 -0
Lines of this file are not shown. View the raw message.
kernel/futex/core.c new file +4272 -0
4,272 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Peter Zijlstra
reviewerPATCH 14/20 futex: Split out wait/wake
In reply to Peter ZijlstraMove the wait/wake bits into their own file.
--- kernel/futex/Makefile | 2 kernel/futex/core.c | 536 ------------------------------------------------ kernel/futex/futex.h | 34 +++ kernel/futex/waitwake.c | 508 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 544 insertions(+), 536 deletions(-)
kernel/futex/Makefile +1 -1
@@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 -obj-y += core.o syscalls.o pi.o requeue.o +obj-y += core.o syscalls.o pi.o requeue.o waitwake.o
kernel/futex/core.c +1 -535
578 lines not on this page · raw message
kernel/futex/futex.h +34 -0
@@ -178,6 +178,27 @@ extern struct futex_q *futex_top_waiter(extern void __futex_unqueue (struct futex_q *q);extern void __futex_queue (struct futex_q *q,struct futex_hash_bucket *hb); +extern int futex_unqueue (struct futex_q *q); + +/** +* futex_queue() - Enqueue the futex_q on the futex_hash_bucket +* @q: The futex_q to enqueue +* @hb: The destination hash bucket +* +* The hb->lock must be held by the caller, and is released here. A call to +* futex_queue() is typically paired with exactly one call to futex_unqueue(). The +* exceptions involve the PI related operations, which may use futex_unqueue_pi() +* or nothing if the unqueue is done as part of the wake process and the unqueue +* state is implicit in the state of woken task (see futex_wait_requeue_pi() for +* an example). +*/ +static inline void futex_queue (struct futex_q *q,struct futex_hash_bucket *hb) + __releases(&hb->lock) +{ +__futex_queue (q, hb); +spin_unlock (&hb->lock); +} +extern void futex_unqueue_pi (struct futex_q *q);extern void wait_for_owner_exiting (int ret,struct task_struct *exiting);
@@ -207,6 +228,19 @@ static inline void futex_hb_waiters_dec(#endif } +static inline int futex_hb_waiters_pending (struct futex_hash_bucket *hb) +{ +#ifdef CONFIG_SMP +/* +* Full barrier (B), see the ordering comment above. +*/ +smp_mb (); +return atomic_read (&hb->waiters); +#else +return 1 ; +#endif +} +extern struct futex_hash_bucket *futex_q_lock (struct futex_q *q);extern void futex_q_unlock (struct futex_hash_bucket *hb);
kernel/futex/waitwake.c new file +508 -0
508 lines not on this page · raw message
Hi Peter,
Às 11:07 de 15/09/21, Peter Zijlstra escreveu:
Quoted 9 lines
Hi,
Neither Thomas nor myself much liked that
futex2.cnor do we think thatCONFIG_symbol makes much sense.However,
futex.cis a wee bit long and splitting it up makes sense. So I've taken the liberty to replace your initial patch with 15 of my own and then rebased the remaining patches on top of that.
Thank you for doing that. futex.c is indeed too big and I believe that this really make the code easier to read, and the way you organized makes more sense than the way I did. Maybe even robust could have a separated file?
Thanks,
André
Re: [PATCH 07/20] futex: Rename hash_futex()
In reply to Peter ZijlstraÀs 11:07 de 15/09/21, Peter Zijlstra escreveu:
Quoted 5 lines
In order to prepare introducing these symbols into the global namespace; rename:
s/hash_futex/hash_futex/g
I think you meant
s/hash_futex/futex_hash/g
Re: [PATCH 16/20] futex: Implement sys_futex_waitv()
In reply to a message not in the archiveÀs 11:07 de 15/09/21, Peter Zijlstra escreveu:
Quoted 11 lines
From: André Almeida <[email protected]>
Add support to wait on multiple futexes. This is the interface implemented by this syscall:
futex_waitv(struct
futex_waitv*waiters, unsigned intnr_futexes,
unsigned int flags, struct timespec *timo)
include/uapi/asm-generic/unistd.h __SYSCALL(__NR_memfd_secret, sys_memfd_s · line 885
Quoted 6 lines
include/uapi/asm-generic/unistd.h +3
-0@@ -880,8 +880,11 @@ __SYSCALL(__NR_memfd_secret, sys_memfd_s#define __NR_process_mrelease 448 __SYSCALL(__NR_process_mrelease, sys_process_mrelease) +#define __NR_futex_waitv 449 +__SC_COMP (__NR_futex_waitv, sys_futex_waitv) +
Oops, this should be __SYSCALL(), and not __SC_COMP(), my bad.
Peter Zijlstra
reviewerRe: [PATCH 07/20] futex: Rename hash_futex()
In reply to André AlmeidaQuoted 10 lines · André Almeida
Às 11:07 de 15/09/21, Peter Zijlstra escreveu:
Quoted 5 lines
In order to prepare introducing these symbols into the global namespace; rename:
s/hash_futex/hash_futex/g
I think you meant
s/hash_futex/futex_hash/g
I think so too :-) Clearly typing i hard...
Peter Zijlstra
reviewerRe: [PATCH 16/20] futex: Implement sys_futex_waitv()
In reply to a message not in the archiveReview
Quoted 3 lines · Peter Zijlstra
(quoted diff) +3
-0+SYSCALL_DEFINE4(futex_waitv, struct futex_waitv __user *, waiters, + unsigned int, nr_futexes, unsigned int, flags, + struct __kernel_timespec __user *, timo)
So I utterly detest timespec.. it makes no sense what so ever.
Can't we just, for new syscalls, simply use a s64 nsec argument and call it a day?
Thomas, Arnd ?
Re: [PATCH 16/20] futex: Implement sys_futex_waitv()
In reply to a message not in the archiveÀs 11:07 de 15/09/21, Peter Zijlstra escreveu:
Quoted 97 lines
From: André Almeida <[email protected]>
Add support to wait on multiple futexes. This is the interface implemented by this syscall:
futex_waitv(struct
futex_waitv*waiters, unsigned intnr_futexes,
unsigned int flags, struct timespec *timo)(quoted diff) +89
-0+/** + * futex_wait_multiple_setup - Prepare to wait and enqueue multiple futexes + * @vs: The futex list to wait on + * @count: The size of the list + * @awaken: Index of the last awoken futex, if any. Used to notify the + * caller that it can return this index to userspace (return parameter) + * + * Prepare multiple futexes in a single step and enqueue them. This may fail if + * the futex list is invalid or if any futex was already awoken. On success the + * task is ready to interruptible sleep. + * + * Return: + * - 1 - One of the futexes was awaken by another thread + * - 0 - Success + * - <0 - -EFAULT, -EWOULDBLOCK or -EINVAL + */ +static int futex_wait_multiple_setup(struct futex_vector *vs, int count, int *awaken) +{ + struct futex_hash_bucket *hb; + bool retry = false; + int ret, i; + u32 uval; + + /* + * Enqueuing multiple futexes is tricky, because we need to enqueue + * each futex in the list before dealing with the next one to avoid + * deadlocking on the hash bucket. But, before enqueuing, we need to + * make sure that current->state is TASK_INTERRUPTIBLE, so we don't + * absorb any awake events, which cannot be done before the + * get_futex_key of the next key, because it calls get_user_pages, + * which can sleep. Thus, we fetch the list of futexes keys in two + * steps, by first pinning all the memory keys in the futex key, and + * only then we read each key and queue the corresponding futex. + * + * Private futexes doesn't need to recalculate hash in retry, so skip + * get_futex_key() when retrying. + */ +retry: + for (i = 0; i < count; i++) { + if ((vs[i].w.flags & FUTEX_PRIVATE_FLAG) && retry) + continue; + + ret = get_futex_key(u64_to_user_ptr(vs[i].w.uaddr), + !(vs[i].w.flags & FUTEX_PRIVATE_FLAG), + &vs[i].q.key, FUTEX_READ); + + if (unlikely(ret)) + return ret; + } + + set_current_state(TASK_INTERRUPTIBLE); + + for (i = 0; i < count; i++) { + u32 __user *uaddr = (u32 __user *)(unsigned long)vs[i].w.uaddr; + struct futex_q *q = &vs[i].q; + u32 val = (u32)vs[i].w.val; + + hb = futex_q_lock(q); + ret = futex_get_value_locked(&uval, uaddr); + + if (!ret && uval == val) { + /* + * The bucket lock can't be held while dealing with the + * next futex. Queue each futex at this moment so hb can + * be unlocked. + */ + futex_queue(q, hb); + continue; + } + + futex_q_unlock(hb); + __set_current_state(TASK_RUNNING); + + /* + * Even if something went wrong, if we find out that a futex + * was awaken, we don't return error and return this index to + * userspace + */ + *awaken = unqueue_multiple(vs, i); + if (*awaken >= 0) + return 1; + + if (uval != val) + return -EWOULDBLOCK; + + if (ret) { + /* + * If we need to handle a page fault, we need to do so + * without any lock and any enqueued futex (otherwise
Review
Quoted 10 lines
(quoted diff) +10
-0+ * we could lose some wakeup). So we do it here, after + * undoing all the work done so far. In success, we + * retry all the work. + */ + if (get_user(uval, uaddr)) + return -EFAULT; + + retry = true; + goto retry; + }
My bad again: the last two if's should be in the reserve order. If ret != 0, the user copy didn't succeed and the value wasn't copied to uval, thus the comparison (uval != val) should happen only if ret == 0.
Quoted 4 lines
(quoted diff) +4
-0+ } + + return 0; +}
Re: [PATCH 16/20] futex: Implement sys_futex_waitv()
In reply to Peter ZijlstraQuoted 4 lines · Peter Zijlstra
I utterly detest timespec.. it makes no sense what so ever.
Can't we just, for new syscalls, simply use a s64 nsec argument and call it a day?
This would stop working in the year 2262. Not a good idea.
Any improvements on struct timespec should be a strict superset, not a subset. For example, you could advocate a signed 128-bit argument counting in units of attoseconds (10⁻¹⁸ s), the highest power-of-1000 resolution that does not lose info when converting from struct timespec. This could use __int128 on platforms that have it, a two-integer struct otherwise.
I'm not sure this is a hill I'd want to die on. That being said, it would be cool to keep up with the people in the building near mine who are researching attosecond imaging (tricky because the uncertainty principle means attosecond laser pulses must have very broad spectra). And extending struct timespec on the low end is clearly the way to go, since its high end already goes back well before the Big Bang.
I hope you don't mind my going off the deep end a bit here. Still, the point is that if we're going to improve on struct timespec then it really should be an improvement.
Às 11:07 de 15/09/21, Peter Zijlstra escreveu:
Quoted 11 lines
Hi,
Neither Thomas nor myself much liked that
futex2.cnor do we think thatCONFIG_symbol makes much sense.However,
futex.cis a wee bit long and splitting it up makes sense. So I've taken the liberty to replace your initial patch with 15 of my own and then rebased the remaining patches on top of that.Thomas, does something like this work for you?
I tested this patchset:
- On top of a full distro
- Using futex kselftests
- Running glibc's nptl tests, all 387 passed
It seems that things are working as expected. You can add my
for patches 01 - 15.
Re: [PATCH 16/20] futex: Implement sys_futex_waitv()
In reply to Peter ZijlstraQuoted 6 lines · Peter Zijlstra
Review
Quoted 3 lines · Peter Zijlstra
(quoted diff) +3
-0+SYSCALL_DEFINE4(futex_waitv, struct futex_waitv __user *, waiters, + unsigned int, nr_futexes, unsigned int, flags, + struct __kernel_timespec __user *, timo)
Quoted 6 lines
So I utterly detest timespec.. it makes no sense what so ever.
Can't we just, for new syscalls, simply use a s64 nsec argument and call it a day?
Thomas, Arnd ?
Do you mean passing the nanoseconds by value instead of a pointer? I think that would be worse, since that means having incompatible calling conventions between 32-bit and 64-bit architectures, and even between 32-bit architectures that have different requirements for 64-bit function arguments.
If we pass it by reference, there is much less to gain from changing the timespec to plain nanoseconds. I wouldn't object to that, but I don't see it helping much either. It would work for relative timeouts, but the general trend seems to be to specify timeouts as absolute times, and that would force each caller to read the time using clock_gettime() and then convert it to nanoseconds before adding the timeout.
Specifying the timeout in terms of 32-bit relative milliseconds would the way that epoll() does would be really simple, but that still feels odd.
Arnd
Re: [PATCH 16/20] futex: Implement sys_futex_waitv()
In reply to Paul EggertQuoted 7 lines · Paul Eggert
Quoted 4 lines · Peter Zijlstra
I utterly detest timespec.. it makes no sense what so ever.
Can't we just, for new syscalls, simply use a s64 nsec argument and call it a day?
This would stop working in the year 2262. Not a good idea.
Make it u64 and it stops in 2552, i.e. 584 years from now which is plenty. Lot's of the kernel internal timekeeping will stop working at that point, so that interface is the least of my worries. And TBH, my worries about the Y2552 problem are extremly close to zero.
Quoted 5 lines
Any improvements on struct timespec should be a strict superset, not a subset. For example, you could advocate a signed 128-bit argument counting in units of attoseconds (10⁻¹⁸ s), the highest power-of-1000 resolution that does not lose info when converting from struct timespec.
Which requires a 128bit division on every syscall for no value at all.
Thanks,
tglx
Re: [PATCH 16/20] futex: Implement sys_futex_waitv()
Às 11:49 de 16/09/21, Thomas Gleixner escreveu:
Quoted 8 lines · Paul Eggert
Quoted 7 lines · Peter Zijlstra
Quoted 4 lines
I utterly detest timespec.. it makes no sense what so ever.
Can't we just, for new syscalls, simply use a s64 nsec argument and call it a day?
Quoted 7 lines
Quoted 1 line
This would stop working in the year 2262. Not a good idea.
Make it u64 and it stops in 2552, i.e. 584 years from now which is plenty. Lot's of the kernel internal timekeeping will stop working at that point, so that interface is the least of my worries. And TBH, my worries about the Y2552 problem are extremly close to zero.
What do we win by using u64 instead of timespec?
Or what's so bad about timespec?