Skip to content

Commit 8486d12

Browse files
author
Peter Zijlstra
committed
futex: Create hb scopes
Create explicit scopes for hb variables; almost pure re-indent. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 2fb2920 commit 8486d12

File tree

4 files changed

+493
-474
lines changed

4 files changed

+493
-474
lines changed

kernel/futex/core.c

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,6 @@ static void exit_pi_state_list(struct task_struct *curr)
944944
{
945945
struct list_head *next, *head = &curr->pi_state_list;
946946
struct futex_pi_state *pi_state;
947-
struct futex_hash_bucket *hb;
948947
union futex_key key = FUTEX_KEY_INIT;
949948

950949
/*
@@ -957,50 +956,54 @@ static void exit_pi_state_list(struct task_struct *curr)
957956
next = head->next;
958957
pi_state = list_entry(next, struct futex_pi_state, list);
959958
key = pi_state->key;
960-
hb = futex_hash(&key);
961-
962-
/*
963-
* We can race against put_pi_state() removing itself from the
964-
* list (a waiter going away). put_pi_state() will first
965-
* decrement the reference count and then modify the list, so
966-
* its possible to see the list entry but fail this reference
967-
* acquire.
968-
*
969-
* In that case; drop the locks to let put_pi_state() make
970-
* progress and retry the loop.
971-
*/
972-
if (!refcount_inc_not_zero(&pi_state->refcount)) {
959+
if (1) {
960+
struct futex_hash_bucket *hb;
961+
962+
hb = futex_hash(&key);
963+
964+
/*
965+
* We can race against put_pi_state() removing itself from the
966+
* list (a waiter going away). put_pi_state() will first
967+
* decrement the reference count and then modify the list, so
968+
* its possible to see the list entry but fail this reference
969+
* acquire.
970+
*
971+
* In that case; drop the locks to let put_pi_state() make
972+
* progress and retry the loop.
973+
*/
974+
if (!refcount_inc_not_zero(&pi_state->refcount)) {
975+
raw_spin_unlock_irq(&curr->pi_lock);
976+
cpu_relax();
977+
raw_spin_lock_irq(&curr->pi_lock);
978+
continue;
979+
}
973980
raw_spin_unlock_irq(&curr->pi_lock);
974-
cpu_relax();
975-
raw_spin_lock_irq(&curr->pi_lock);
976-
continue;
977-
}
978-
raw_spin_unlock_irq(&curr->pi_lock);
979981

980-
spin_lock(&hb->lock);
981-
raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);
982-
raw_spin_lock(&curr->pi_lock);
983-
/*
984-
* We dropped the pi-lock, so re-check whether this
985-
* task still owns the PI-state:
986-
*/
987-
if (head->next != next) {
988-
/* retain curr->pi_lock for the loop invariant */
989-
raw_spin_unlock(&pi_state->pi_mutex.wait_lock);
982+
spin_lock(&hb->lock);
983+
raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);
984+
raw_spin_lock(&curr->pi_lock);
985+
/*
986+
* We dropped the pi-lock, so re-check whether this
987+
* task still owns the PI-state:
988+
*/
989+
if (head->next != next) {
990+
/* retain curr->pi_lock for the loop invariant */
991+
raw_spin_unlock(&pi_state->pi_mutex.wait_lock);
992+
spin_unlock(&hb->lock);
993+
put_pi_state(pi_state);
994+
continue;
995+
}
996+
997+
WARN_ON(pi_state->owner != curr);
998+
WARN_ON(list_empty(&pi_state->list));
999+
list_del_init(&pi_state->list);
1000+
pi_state->owner = NULL;
1001+
1002+
raw_spin_unlock(&curr->pi_lock);
1003+
raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
9901004
spin_unlock(&hb->lock);
991-
put_pi_state(pi_state);
992-
continue;
9931005
}
9941006

995-
WARN_ON(pi_state->owner != curr);
996-
WARN_ON(list_empty(&pi_state->list));
997-
list_del_init(&pi_state->list);
998-
pi_state->owner = NULL;
999-
1000-
raw_spin_unlock(&curr->pi_lock);
1001-
raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
1002-
spin_unlock(&hb->lock);
1003-
10041007
rt_mutex_futex_unlock(&pi_state->pi_mutex);
10051008
put_pi_state(pi_state);
10061009

0 commit comments

Comments
 (0)