summaryrefslogtreecommitdiffstats
path: root/kernel/futex.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-03-06 10:17:17 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2019-03-06 10:17:17 -0500
commit3478588b5136966c80c571cf0006f08e9e5b8f04 (patch)
tree186e67cce850bbdaf91aa678406d68fb87c5597c /kernel/futex.c
parentc8f5ed6ef972ed4fd10b0c2e2baec3b6803d3c73 (diff)
parent28d49e282665e2a51cc91b716937fccfa24d80e1 (diff)
Merge branch 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull locking updates from Ingo Molnar: "The biggest part of this tree is the new auto-generated atomics API wrappers by Mark Rutland. The primary motivation was to allow instrumentation without uglifying the primary source code. The linecount increase comes from adding the auto-generated files to the Git space as well: include/asm-generic/atomic-instrumented.h | 1689 ++++++++++++++++-- include/asm-generic/atomic-long.h | 1174 ++++++++++--- include/linux/atomic-fallback.h | 2295 +++++++++++++++++++++++++ include/linux/atomic.h | 1241 +------------ I preferred this approach, so that the full call stack of the (already complex) locking APIs is still fully visible in 'git grep'. But if this is excessive we could certainly hide them. There's a separate build-time mechanism to determine whether the headers are out of date (they should never be stale if we do our job right). Anyway, nothing from this should be visible to regular kernel developers. Other changes: - Add support for dynamic keys, which removes a source of false positives in the workqueue code, among other things (Bart Van Assche) - Updates to tools/memory-model (Andrea Parri, Paul E. McKenney) - qspinlock, wake_q and lockdep micro-optimizations (Waiman Long) - misc other updates and enhancements" * 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (48 commits) locking/lockdep: Shrink struct lock_class_key locking/lockdep: Add module_param to enable consistency checks lockdep/lib/tests: Test dynamic key registration lockdep/lib/tests: Fix run_tests.sh kernel/workqueue: Use dynamic lockdep keys for workqueues locking/lockdep: Add support for dynamic keys locking/lockdep: Verify whether lock objects are small enough to be used as class keys locking/lockdep: Check data structure consistency locking/lockdep: Reuse lock chains that have been freed locking/lockdep: Fix a comment in add_chain_cache() locking/lockdep: Introduce lockdep_next_lockchain() and lock_chain_count() locking/lockdep: Reuse list entries that are no longer in use locking/lockdep: Free lock classes that are no longer in use locking/lockdep: Update two outdated comments locking/lockdep: Make it easy to detect whether or not inside a selftest locking/lockdep: Split lockdep_free_key_range() and lockdep_reset_lock() locking/lockdep: Initialize the locks_before and locks_after lists earlier locking/lockdep: Make zap_class() remove all matching lock order entries locking/lockdep: Reorder struct lock_class members locking/lockdep: Avoid that add_chain_cache() adds an invalid chain to the cache ...
Diffstat (limited to 'kernel/futex.c')
-rw-r--r--kernel/futex.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/kernel/futex.c b/kernel/futex.c
index ca58fc0a496e..c3b73b0311bc 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -68,6 +68,7 @@
68#include <linux/freezer.h> 68#include <linux/freezer.h>
69#include <linux/memblock.h> 69#include <linux/memblock.h>
70#include <linux/fault-inject.h> 70#include <linux/fault-inject.h>
71#include <linux/refcount.h>
71 72
72#include <asm/futex.h> 73#include <asm/futex.h>
73 74
@@ -212,7 +213,7 @@ struct futex_pi_state {
212 struct rt_mutex pi_mutex; 213 struct rt_mutex pi_mutex;
213 214
214 struct task_struct *owner; 215 struct task_struct *owner;
215 atomic_t refcount; 216 refcount_t refcount;
216 217
217 union futex_key key; 218 union futex_key key;
218} __randomize_layout; 219} __randomize_layout;
@@ -321,12 +322,8 @@ static int __init fail_futex_debugfs(void)
321 if (IS_ERR(dir)) 322 if (IS_ERR(dir))
322 return PTR_ERR(dir); 323 return PTR_ERR(dir);
323 324
324 if (!debugfs_create_bool("ignore-private", mode, dir, 325 debugfs_create_bool("ignore-private", mode, dir,
325 &fail_futex.ignore_private)) { 326 &fail_futex.ignore_private);
326 debugfs_remove_recursive(dir);
327 return -ENOMEM;
328 }
329
330 return 0; 327 return 0;
331} 328}
332 329
@@ -803,7 +800,7 @@ static int refill_pi_state_cache(void)
803 INIT_LIST_HEAD(&pi_state->list); 800 INIT_LIST_HEAD(&pi_state->list);
804 /* pi_mutex gets initialized later */ 801 /* pi_mutex gets initialized later */
805 pi_state->owner = NULL; 802 pi_state->owner = NULL;
806 atomic_set(&pi_state->refcount, 1); 803 refcount_set(&pi_state->refcount, 1);
807 pi_state->key = FUTEX_KEY_INIT; 804 pi_state->key = FUTEX_KEY_INIT;
808 805
809 current->pi_state_cache = pi_state; 806 current->pi_state_cache = pi_state;
@@ -823,7 +820,7 @@ static struct futex_pi_state *alloc_pi_state(void)
823 820
824static void get_pi_state(struct futex_pi_state *pi_state) 821static void get_pi_state(struct futex_pi_state *pi_state)
825{ 822{
826 WARN_ON_ONCE(!atomic_inc_not_zero(&pi_state->refcount)); 823 WARN_ON_ONCE(!refcount_inc_not_zero(&pi_state->refcount));
827} 824}
828 825
829/* 826/*
@@ -835,7 +832,7 @@ static void put_pi_state(struct futex_pi_state *pi_state)
835 if (!pi_state) 832 if (!pi_state)
836 return; 833 return;
837 834
838 if (!atomic_dec_and_test(&pi_state->refcount)) 835 if (!refcount_dec_and_test(&pi_state->refcount))
839 return; 836 return;
840 837
841 /* 838 /*
@@ -865,7 +862,7 @@ static void put_pi_state(struct futex_pi_state *pi_state)
865 * refcount is at 0 - put it back to 1. 862 * refcount is at 0 - put it back to 1.
866 */ 863 */
867 pi_state->owner = NULL; 864 pi_state->owner = NULL;
868 atomic_set(&pi_state->refcount, 1); 865 refcount_set(&pi_state->refcount, 1);
869 current->pi_state_cache = pi_state; 866 current->pi_state_cache = pi_state;
870 } 867 }
871} 868}
@@ -908,7 +905,7 @@ void exit_pi_state_list(struct task_struct *curr)
908 * In that case; drop the locks to let put_pi_state() make 905 * In that case; drop the locks to let put_pi_state() make
909 * progress and retry the loop. 906 * progress and retry the loop.
910 */ 907 */
911 if (!atomic_inc_not_zero(&pi_state->refcount)) { 908 if (!refcount_inc_not_zero(&pi_state->refcount)) {
912 raw_spin_unlock_irq(&curr->pi_lock); 909 raw_spin_unlock_irq(&curr->pi_lock);
913 cpu_relax(); 910 cpu_relax();
914 raw_spin_lock_irq(&curr->pi_lock); 911 raw_spin_lock_irq(&curr->pi_lock);
@@ -1064,7 +1061,7 @@ static int attach_to_pi_state(u32 __user *uaddr, u32 uval,
1064 * and futex_wait_requeue_pi() as it cannot go to 0 and consequently 1061 * and futex_wait_requeue_pi() as it cannot go to 0 and consequently
1065 * free pi_state before we can take a reference ourselves. 1062 * free pi_state before we can take a reference ourselves.
1066 */ 1063 */
1067 WARN_ON(!atomic_read(&pi_state->refcount)); 1064 WARN_ON(!refcount_read(&pi_state->refcount));
1068 1065
1069 /* 1066 /*
1070 * Now that we have a pi_state, we can acquire wait_lock 1067 * Now that we have a pi_state, we can acquire wait_lock
@@ -1467,8 +1464,7 @@ static void mark_wake_futex(struct wake_q_head *wake_q, struct futex_q *q)
1467 * Queue the task for later wakeup for after we've released 1464 * Queue the task for later wakeup for after we've released
1468 * the hb->lock. wake_q_add() grabs reference to p. 1465 * the hb->lock. wake_q_add() grabs reference to p.
1469 */ 1466 */
1470 wake_q_add(wake_q, p); 1467 wake_q_add_safe(wake_q, p);
1471 put_task_struct(p);
1472} 1468}
1473 1469
1474/* 1470/*