···10961096 * private futexes.10971097 */10981098static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,10991099- struct task_struct *newowner)10991099+ struct task_struct *newowner,11001100+ struct rw_semaphore *fshared)11001101{11011102 u32 newtid = task_pid_vnr(newowner) | FUTEX_WAITERS;11021103 struct futex_pi_state *pi_state = q->pi_state;11041104+ struct task_struct *oldowner = pi_state->owner;11031105 u32 uval, curval, newval;11041104- int ret;11061106+ int ret, attempt = 0;1105110711061108 /* Owner died? */11091109+ if (!pi_state->owner)11101110+ newtid |= FUTEX_OWNER_DIED;11111111+11121112+ /*11131113+ * We are here either because we stole the rtmutex from the11141114+ * pending owner or we are the pending owner which failed to11151115+ * get the rtmutex. We have to replace the pending owner TID11161116+ * in the user space variable. This must be atomic as we have11171117+ * to preserve the owner died bit here.11181118+ *11191119+ * Note: We write the user space value _before_ changing the11201120+ * pi_state because we can fault here. Imagine swapped out11211121+ * pages or a fork, which was running right before we acquired11221122+ * mmap_sem, that marked all the anonymous memory readonly for11231123+ * cow.11241124+ *11251125+ * Modifying pi_state _before_ the user space value would11261126+ * leave the pi_state in an inconsistent state when we fault11271127+ * here, because we need to drop the hash bucket lock to11281128+ * handle the fault. This might be observed in the PID check11291129+ * in lookup_pi_state.11301130+ */11311131+retry:11321132+ if (get_futex_value_locked(&uval, uaddr))11331133+ goto handle_fault;11341134+11351135+ while (1) {11361136+ newval = (uval & FUTEX_OWNER_DIED) | newtid;11371137+11381138+ curval = cmpxchg_futex_value_locked(uaddr, uval, newval);11391139+11401140+ if (curval == -EFAULT)11411141+ goto handle_fault;11421142+ if (curval == uval)11431143+ break;11441144+ uval = curval;11451145+ }11461146+11471147+ /*11481148+ * We fixed up user space. Now we need to fix the pi_state11491149+ * itself.11501150+ */11071151 if (pi_state->owner != NULL) {11081152 spin_lock_irq(&pi_state->owner->pi_lock);11091153 WARN_ON(list_empty(&pi_state->list));11101154 list_del_init(&pi_state->list);11111155 spin_unlock_irq(&pi_state->owner->pi_lock);11121112- } else11131113- newtid |= FUTEX_OWNER_DIED;11561156+ }1114115711151158 pi_state->owner = newowner;11161159···11611118 WARN_ON(!list_empty(&pi_state->list));11621119 list_add(&pi_state->list, &newowner->pi_state_list);11631120 spin_unlock_irq(&newowner->pi_lock);11211121+ return 0;1164112211651123 /*11661166- * We own it, so we have to replace the pending owner11671167- * TID. This must be atomic as we have preserve the11681168- * owner died bit here.11241124+ * To handle the page fault we need to drop the hash bucket11251125+ * lock here. That gives the other task (either the pending11261126+ * owner itself or the task which stole the rtmutex) the11271127+ * chance to try the fixup of the pi_state. So once we are11281128+ * back from handling the fault we need to check the pi_state11291129+ * after reacquiring the hash bucket lock and before trying to11301130+ * do another fixup. When the fixup has been done already we11311131+ * simply return.11691132 */11701170- ret = get_futex_value_locked(&uval, uaddr);11331133+handle_fault:11341134+ spin_unlock(q->lock_ptr);1171113511721172- while (!ret) {11731173- newval = (uval & FUTEX_OWNER_DIED) | newtid;11361136+ ret = futex_handle_fault((unsigned long)uaddr, fshared, attempt++);1174113711751175- curval = cmpxchg_futex_value_locked(uaddr, uval, newval);11381138+ spin_lock(q->lock_ptr);1176113911771177- if (curval == -EFAULT)11781178- ret = -EFAULT;11791179- if (curval == uval)11801180- break;11811181- uval = curval;11821182- }11831183- return ret;11401140+ /*11411141+ * Check if someone else fixed it for us:11421142+ */11431143+ if (pi_state->owner != oldowner)11441144+ return 0;11451145+11461146+ if (ret)11471147+ return ret;11481148+11491149+ goto retry;11841150}1185115111861152/*···15591507 * that case:15601508 */15611509 if (q.pi_state->owner != curr)15621562- ret = fixup_pi_state_owner(uaddr, &q, curr);15101510+ ret = fixup_pi_state_owner(uaddr, &q, curr, fshared);15631511 } else {15641512 /*15651513 * Catch the rare case, where the lock was released···15911539 int res;1592154015931541 owner = rt_mutex_owner(&q.pi_state->pi_mutex);15941594- res = fixup_pi_state_owner(uaddr, &q, owner);15421542+ res = fixup_pi_state_owner(uaddr, &q, owner,15431543+ fshared);1595154415961545 /* propagate -EFAULT, if the fixup failed */15971546 if (res)