diff options
author | Peter Zijlstra <peterz@infradead.org> | 2017-03-22 06:35:53 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2017-03-23 14:10:08 -0400 |
commit | bf92cf3a5100f5a0d5f9834787b130159397cb22 (patch) | |
tree | 8e8fd423f7cd2c6c4d847d24114a021b53fd0160 /kernel/futex.c | |
parent | 734009e96d1983ad739e5b656e03430b3660c913 (diff) |
futex: Cleanup refcounting
Add a put_pit_state() as counterpart for get_pi_state() so the refcounting
becomes consistent.
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.801778516@infradead.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel/futex.c')
-rw-r--r-- | kernel/futex.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/kernel/futex.c b/kernel/futex.c index 3e71d66cb788..3b6dbeecd91b 100644 --- a/kernel/futex.c +++ b/kernel/futex.c | |||
@@ -802,7 +802,7 @@ static int refill_pi_state_cache(void) | |||
802 | return 0; | 802 | return 0; |
803 | } | 803 | } |
804 | 804 | ||
805 | static struct futex_pi_state * alloc_pi_state(void) | 805 | static struct futex_pi_state *alloc_pi_state(void) |
806 | { | 806 | { |
807 | struct futex_pi_state *pi_state = current->pi_state_cache; | 807 | struct futex_pi_state *pi_state = current->pi_state_cache; |
808 | 808 | ||
@@ -812,6 +812,11 @@ static struct futex_pi_state * alloc_pi_state(void) | |||
812 | return pi_state; | 812 | return pi_state; |
813 | } | 813 | } |
814 | 814 | ||
815 | static void get_pi_state(struct futex_pi_state *pi_state) | ||
816 | { | ||
817 | WARN_ON_ONCE(!atomic_inc_not_zero(&pi_state->refcount)); | ||
818 | } | ||
819 | |||
815 | /* | 820 | /* |
816 | * Drops a reference to the pi_state object and frees or caches it | 821 | * Drops a reference to the pi_state object and frees or caches it |
817 | * when the last reference is gone. | 822 | * when the last reference is gone. |
@@ -856,7 +861,7 @@ static void put_pi_state(struct futex_pi_state *pi_state) | |||
856 | * Look up the task based on what TID userspace gave us. | 861 | * Look up the task based on what TID userspace gave us. |
857 | * We dont trust it. | 862 | * We dont trust it. |
858 | */ | 863 | */ |
859 | static struct task_struct * futex_find_get_task(pid_t pid) | 864 | static struct task_struct *futex_find_get_task(pid_t pid) |
860 | { | 865 | { |
861 | struct task_struct *p; | 866 | struct task_struct *p; |
862 | 867 | ||
@@ -1103,7 +1108,7 @@ static int attach_to_pi_state(u32 __user *uaddr, u32 uval, | |||
1103 | goto out_einval; | 1108 | goto out_einval; |
1104 | 1109 | ||
1105 | out_attach: | 1110 | out_attach: |
1106 | atomic_inc(&pi_state->refcount); | 1111 | get_pi_state(pi_state); |
1107 | raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock); | 1112 | raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock); |
1108 | *ps = pi_state; | 1113 | *ps = pi_state; |
1109 | return 0; | 1114 | return 0; |
@@ -1990,7 +1995,7 @@ retry_private: | |||
1990 | * refcount on the pi_state and store the pointer in | 1995 | * refcount on the pi_state and store the pointer in |
1991 | * the futex_q object of the waiter. | 1996 | * the futex_q object of the waiter. |
1992 | */ | 1997 | */ |
1993 | atomic_inc(&pi_state->refcount); | 1998 | get_pi_state(pi_state); |
1994 | this->pi_state = pi_state; | 1999 | this->pi_state = pi_state; |
1995 | ret = rt_mutex_start_proxy_lock(&pi_state->pi_mutex, | 2000 | ret = rt_mutex_start_proxy_lock(&pi_state->pi_mutex, |
1996 | this->rt_waiter, | 2001 | this->rt_waiter, |