aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/futex.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/futex.c')
-rw-r--r--kernel/futex.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/kernel/futex.c b/kernel/futex.c
index 3d38eaf05492..0518a0bfc746 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -821,8 +821,6 @@ static void get_pi_state(struct futex_pi_state *pi_state)
821/* 821/*
822 * Drops a reference to the pi_state object and frees or caches it 822 * Drops a reference to the pi_state object and frees or caches it
823 * when the last reference is gone. 823 * when the last reference is gone.
824 *
825 * Must be called with the hb lock held.
826 */ 824 */
827static void put_pi_state(struct futex_pi_state *pi_state) 825static void put_pi_state(struct futex_pi_state *pi_state)
828{ 826{
@@ -837,16 +835,22 @@ static void put_pi_state(struct futex_pi_state *pi_state)
837 * and has cleaned up the pi_state already 835 * and has cleaned up the pi_state already
838 */ 836 */
839 if (pi_state->owner) { 837 if (pi_state->owner) {
840 raw_spin_lock_irq(&pi_state->owner->pi_lock); 838 struct task_struct *owner;
841 list_del_init(&pi_state->list);
842 raw_spin_unlock_irq(&pi_state->owner->pi_lock);
843 839
844 rt_mutex_proxy_unlock(&pi_state->pi_mutex, pi_state->owner); 840 raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);
841 owner = pi_state->owner;
842 if (owner) {
843 raw_spin_lock(&owner->pi_lock);
844 list_del_init(&pi_state->list);
845 raw_spin_unlock(&owner->pi_lock);
846 }
847 rt_mutex_proxy_unlock(&pi_state->pi_mutex, owner);
848 raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
845 } 849 }
846 850
847 if (current->pi_state_cache) 851 if (current->pi_state_cache) {
848 kfree(pi_state); 852 kfree(pi_state);
849 else { 853 } else {
850 /* 854 /*
851 * pi_state->list is already empty. 855 * pi_state->list is already empty.
852 * clear pi_state->owner. 856 * clear pi_state->owner.
@@ -907,13 +911,14 @@ void exit_pi_state_list(struct task_struct *curr)
907 raw_spin_unlock_irq(&curr->pi_lock); 911 raw_spin_unlock_irq(&curr->pi_lock);
908 912
909 spin_lock(&hb->lock); 913 spin_lock(&hb->lock);
910 914 raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);
911 raw_spin_lock_irq(&curr->pi_lock); 915 raw_spin_lock(&curr->pi_lock);
912 /* 916 /*
913 * We dropped the pi-lock, so re-check whether this 917 * We dropped the pi-lock, so re-check whether this
914 * task still owns the PI-state: 918 * task still owns the PI-state:
915 */ 919 */
916 if (head->next != next) { 920 if (head->next != next) {
921 raw_spin_unlock(&pi_state->pi_mutex.wait_lock);
917 spin_unlock(&hb->lock); 922 spin_unlock(&hb->lock);
918 continue; 923 continue;
919 } 924 }
@@ -922,9 +927,10 @@ void exit_pi_state_list(struct task_struct *curr)
922 WARN_ON(list_empty(&pi_state->list)); 927 WARN_ON(list_empty(&pi_state->list));
923 list_del_init(&pi_state->list); 928 list_del_init(&pi_state->list);
924 pi_state->owner = NULL; 929 pi_state->owner = NULL;
925 raw_spin_unlock_irq(&curr->pi_lock); 930 raw_spin_unlock(&curr->pi_lock);
926 931
927 get_pi_state(pi_state); 932 get_pi_state(pi_state);
933 raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
928 spin_unlock(&hb->lock); 934 spin_unlock(&hb->lock);
929 935
930 rt_mutex_futex_unlock(&pi_state->pi_mutex); 936 rt_mutex_futex_unlock(&pi_state->pi_mutex);
@@ -1208,6 +1214,10 @@ static int attach_to_pi_owner(u32 uval, union futex_key *key,
1208 1214
1209 WARN_ON(!list_empty(&pi_state->list)); 1215 WARN_ON(!list_empty(&pi_state->list));
1210 list_add(&pi_state->list, &p->pi_state_list); 1216 list_add(&pi_state->list, &p->pi_state_list);
1217 /*
1218 * Assignment without holding pi_state->pi_mutex.wait_lock is safe
1219 * because there is no concurrency as the object is not published yet.
1220 */
1211 pi_state->owner = p; 1221 pi_state->owner = p;
1212 raw_spin_unlock_irq(&p->pi_lock); 1222 raw_spin_unlock_irq(&p->pi_lock);
1213 1223
@@ -2878,6 +2888,7 @@ retry:
2878 raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock); 2888 raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);
2879 spin_unlock(&hb->lock); 2889 spin_unlock(&hb->lock);
2880 2890
2891 /* drops pi_state->pi_mutex.wait_lock */
2881 ret = wake_futex_pi(uaddr, uval, pi_state); 2892 ret = wake_futex_pi(uaddr, uval, pi_state);
2882 2893
2883 put_pi_state(pi_state); 2894 put_pi_state(pi_state);