Skip to content

Commit c0c9ed1

Browse files
committed
futex: Avoid redudant evaluation of task_pid_vnr()
The result is not going to change under us, so no need to reevaluate this over and over. Seems to be a leftover from the mechanical mass conversion of task->pid to task_pid_vnr(tsk). Signed-off-by: Thomas Gleixner <[email protected]>
1 parent 8fe8f54 commit c0c9ed1

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

kernel/futex.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ static int futex_lock_pi_atomic(u32 __user *uaddr, struct futex_hash_bucket *hb,
674674
struct task_struct *task, int set_waiters)
675675
{
676676
int lock_taken, ret, ownerdied = 0;
677-
u32 uval, newval, curval;
677+
u32 uval, newval, curval, vpid = task_pid_vnr(task);
678678

679679
retry:
680680
ret = lock_taken = 0;
@@ -684,7 +684,7 @@ static int futex_lock_pi_atomic(u32 __user *uaddr, struct futex_hash_bucket *hb,
684684
* (by doing a 0 -> TID atomic cmpxchg), while holding all
685685
* the locks. It will most likely not succeed.
686686
*/
687-
newval = task_pid_vnr(task);
687+
newval = vpid;
688688
if (set_waiters)
689689
newval |= FUTEX_WAITERS;
690690

@@ -696,7 +696,7 @@ static int futex_lock_pi_atomic(u32 __user *uaddr, struct futex_hash_bucket *hb,
696696
/*
697697
* Detect deadlocks.
698698
*/
699-
if ((unlikely((curval & FUTEX_TID_MASK) == task_pid_vnr(task))))
699+
if ((unlikely((curval & FUTEX_TID_MASK) == vpid)))
700700
return -EDEADLK;
701701

702702
/*
@@ -723,7 +723,7 @@ static int futex_lock_pi_atomic(u32 __user *uaddr, struct futex_hash_bucket *hb,
723723
*/
724724
if (unlikely(ownerdied || !(curval & FUTEX_TID_MASK))) {
725725
/* Keep the OWNER_DIED bit */
726-
newval = (curval & ~FUTEX_TID_MASK) | task_pid_vnr(task);
726+
newval = (curval & ~FUTEX_TID_MASK) | vpid;
727727
ownerdied = 0;
728728
lock_taken = 1;
729729
}
@@ -2047,9 +2047,9 @@ static int futex_unlock_pi(u32 __user *uaddr, unsigned int flags)
20472047
{
20482048
struct futex_hash_bucket *hb;
20492049
struct futex_q *this, *next;
2050-
u32 uval;
20512050
struct plist_head *head;
20522051
union futex_key key = FUTEX_KEY_INIT;
2052+
u32 uval, vpid = task_pid_vnr(current);
20532053
int ret;
20542054

20552055
retry:
@@ -2058,7 +2058,7 @@ static int futex_unlock_pi(u32 __user *uaddr, unsigned int flags)
20582058
/*
20592059
* We release only a lock we actually own:
20602060
*/
2061-
if ((uval & FUTEX_TID_MASK) != task_pid_vnr(current))
2061+
if ((uval & FUTEX_TID_MASK) != vpid)
20622062
return -EPERM;
20632063

20642064
ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &key);
@@ -2074,7 +2074,7 @@ static int futex_unlock_pi(u32 __user *uaddr, unsigned int flags)
20742074
* anyone else up:
20752075
*/
20762076
if (!(uval & FUTEX_OWNER_DIED))
2077-
uval = cmpxchg_futex_value_locked(uaddr, task_pid_vnr(current), 0);
2077+
uval = cmpxchg_futex_value_locked(uaddr, vpid, 0);
20782078

20792079

20802080
if (unlikely(uval == -EFAULT))
@@ -2083,7 +2083,7 @@ static int futex_unlock_pi(u32 __user *uaddr, unsigned int flags)
20832083
* Rare case: we managed to release the lock atomically,
20842084
* no need to wake anyone else up:
20852085
*/
2086-
if (unlikely(uval == task_pid_vnr(current)))
2086+
if (unlikely(uval == vpid))
20872087
goto out_unlock;
20882088

20892089
/*

0 commit comments

Comments
 (0)