Skip to content

Commit bff7c57

Browse files
author
Peter Zijlstra
committed
futex: Simplify double_lock_hb()
We need to make sure that all requeue operations take the hash bucket locks in the same order to avoid deadlock. Simplify the current double_lock_hb implementation by making sure hb1 is always the "smallest" bucket to avoid extra checks. [André: Add commit description] Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: André Almeida <andrealmeid@collabora.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: André Almeida <andrealmeid@collabora.com> Link: https://lore.kernel.org/r/20210923171111.300673-16-andrealmeid@collabora.com
1 parent a046f1a commit bff7c57

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

‎kernel/futex/futex.h‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,12 @@ extern int fixup_pi_owner(u32 __user *uaddr, struct futex_q *q, int locked);
239239
static inline void
240240
double_lock_hb(struct futex_hash_bucket *hb1, struct futex_hash_bucket *hb2)
241241
{
242-
if (hb1 <= hb2) {
243-
spin_lock(&hb1->lock);
244-
if (hb1 < hb2)
245-
spin_lock_nested(&hb2->lock, SINGLE_DEPTH_NESTING);
246-
} else { /* hb1 > hb2 */
247-
spin_lock(&hb2->lock);
248-
spin_lock_nested(&hb1->lock, SINGLE_DEPTH_NESTING);
249-
}
242+
if (hb1 > hb2)
243+
swap(hb1, hb2);
244+
245+
spin_lock(&hb1->lock);
246+
if (hb1 != hb2)
247+
spin_lock_nested(&hb2->lock, SINGLE_DEPTH_NESTING);
250248
}
251249

252250
static inline void

0 commit comments

Comments
 (0)