aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/futex.c
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2017-03-22 06:35:51 -0400
committerThomas Gleixner <tglx@linutronix.de>2017-03-23 14:10:07 -0400
commit5293c2efda37775346885c7e924d4ef7018ea60b (patch)
tree77868b67d43f614989c465d06415d6e1a90f5c4b /kernel/futex.c
parentfffa954fb528963c2fb7b0c0084eb77e2be7ab52 (diff)
futex,rt_mutex: Provide futex specific rt_mutex API
Part of what makes futex_unlock_pi() intricate is that rt_mutex_futex_unlock() -> rt_mutex_slowunlock() can drop rt_mutex::wait_lock. This means it cannot rely on the atomicy of wait_lock, which would be preferred in order to not rely on hb->lock so much. The reason rt_mutex_slowunlock() needs to drop wait_lock is because it can race with the rt_mutex fastpath, however futexes have their own fast path. Since futexes already have a bunch of separate rt_mutex accessors, complete that set and implement a rt_mutex variant without fastpath for them. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: juri.lelli@arm.com Cc: bigeasy@linutronix.de Cc: xlpang@redhat.com Cc: rostedt@goodmis.org Cc: mathieu.desnoyers@efficios.com Cc: jdesfossez@efficios.com Cc: dvhart@infradead.org Cc: bristot@redhat.com Link: http://lkml.kernel.org/r/20170322104151.702962446@infradead.org Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel/futex.c')
-rw-r--r--kernel/futex.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/kernel/futex.c b/kernel/futex.c
index cc1034038285..af022919933a 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -916,7 +916,7 @@ void exit_pi_state_list(struct task_struct *curr)
916 pi_state->owner = NULL; 916 pi_state->owner = NULL;
917 raw_spin_unlock_irq(&curr->pi_lock); 917 raw_spin_unlock_irq(&curr->pi_lock);
918 918
919 rt_mutex_unlock(&pi_state->pi_mutex); 919 rt_mutex_futex_unlock(&pi_state->pi_mutex);
920 920
921 spin_unlock(&hb->lock); 921 spin_unlock(&hb->lock);
922 922
@@ -1364,20 +1364,18 @@ static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *top_waiter
1364 pi_state->owner = new_owner; 1364 pi_state->owner = new_owner;
1365 raw_spin_unlock(&new_owner->pi_lock); 1365 raw_spin_unlock(&new_owner->pi_lock);
1366 1366
1367 raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
1368
1369 deboost = rt_mutex_futex_unlock(&pi_state->pi_mutex, &wake_q);
1370
1371 /* 1367 /*
1372 * First unlock HB so the waiter does not spin on it once he got woken 1368 * We've updated the uservalue, this unlock cannot fail.
1373 * up. Second wake up the waiter before the priority is adjusted. If we
1374 * deboost first (and lose our higher priority), then the task might get
1375 * scheduled away before the wake up can take place.
1376 */ 1369 */
1370 deboost = __rt_mutex_futex_unlock(&pi_state->pi_mutex, &wake_q);
1371
1372 raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
1377 spin_unlock(&hb->lock); 1373 spin_unlock(&hb->lock);
1378 wake_up_q(&wake_q); 1374
1379 if (deboost) 1375 if (deboost) {
1376 wake_up_q(&wake_q);
1380 rt_mutex_adjust_prio(current); 1377 rt_mutex_adjust_prio(current);
1378 }
1381 1379
1382 return 0; 1380 return 0;
1383} 1381}
@@ -2253,7 +2251,7 @@ static int fixup_owner(u32 __user *uaddr, struct futex_q *q, int locked)
2253 * task acquired the rt_mutex after we removed ourself from the 2251 * task acquired the rt_mutex after we removed ourself from the
2254 * rt_mutex waiters list. 2252 * rt_mutex waiters list.
2255 */ 2253 */
2256 if (rt_mutex_trylock(&q->pi_state->pi_mutex)) { 2254 if (rt_mutex_futex_trylock(&q->pi_state->pi_mutex)) {
2257 locked = 1; 2255 locked = 1;
2258 goto out; 2256 goto out;
2259 } 2257 }
@@ -2568,7 +2566,7 @@ retry_private:
2568 if (!trylock) { 2566 if (!trylock) {
2569 ret = rt_mutex_timed_futex_lock(&q.pi_state->pi_mutex, to); 2567 ret = rt_mutex_timed_futex_lock(&q.pi_state->pi_mutex, to);
2570 } else { 2568 } else {
2571 ret = rt_mutex_trylock(&q.pi_state->pi_mutex); 2569 ret = rt_mutex_futex_trylock(&q.pi_state->pi_mutex);
2572 /* Fixup the trylock return value: */ 2570 /* Fixup the trylock return value: */
2573 ret = ret ? 0 : -EWOULDBLOCK; 2571 ret = ret ? 0 : -EWOULDBLOCK;
2574 } 2572 }
@@ -2591,7 +2589,7 @@ retry_private:
2591 * it and return the fault to userspace. 2589 * it and return the fault to userspace.
2592 */ 2590 */
2593 if (ret && (rt_mutex_owner(&q.pi_state->pi_mutex) == current)) 2591 if (ret && (rt_mutex_owner(&q.pi_state->pi_mutex) == current))
2594 rt_mutex_unlock(&q.pi_state->pi_mutex); 2592 rt_mutex_futex_unlock(&q.pi_state->pi_mutex);
2595 2593
2596 /* Unqueue and drop the lock */ 2594 /* Unqueue and drop the lock */
2597 unqueue_me_pi(&q); 2595 unqueue_me_pi(&q);
@@ -2898,7 +2896,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
2898 spin_lock(q.lock_ptr); 2896 spin_lock(q.lock_ptr);
2899 ret = fixup_pi_state_owner(uaddr2, &q, current); 2897 ret = fixup_pi_state_owner(uaddr2, &q, current);
2900 if (ret && rt_mutex_owner(&q.pi_state->pi_mutex) == current) 2898 if (ret && rt_mutex_owner(&q.pi_state->pi_mutex) == current)
2901 rt_mutex_unlock(&q.pi_state->pi_mutex); 2899 rt_mutex_futex_unlock(&q.pi_state->pi_mutex);
2902 /* 2900 /*
2903 * Drop the reference to the pi state which 2901 * Drop the reference to the pi state which
2904 * the requeue_pi() code acquired for us. 2902 * the requeue_pi() code acquired for us.
@@ -2938,7 +2936,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
2938 * userspace. 2936 * userspace.
2939 */ 2937 */
2940 if (ret && rt_mutex_owner(pi_mutex) == current) 2938 if (ret && rt_mutex_owner(pi_mutex) == current)
2941 rt_mutex_unlock(pi_mutex); 2939 rt_mutex_futex_unlock(pi_mutex);
2942 2940
2943 /* Unqueue and drop the lock. */ 2941 /* Unqueue and drop the lock. */
2944 unqueue_me_pi(&q); 2942 unqueue_me_pi(&q);