[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241218111618.268028-9-bigeasy@linutronix.de>
Date: Wed, 18 Dec 2024 12:09:46 +0100
From: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
To: linux-kernel@...r.kernel.org
Cc: André Almeida <andrealmeid@...lia.com>,
Darren Hart <dvhart@...radead.org>,
Davidlohr Bueso <dave@...olabs.net>,
Ingo Molnar <mingo@...hat.com>,
Juri Lelli <juri.lelli@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Thomas Gleixner <tglx@...utronix.de>,
Valentin Schneider <vschneid@...hat.com>,
Waiman Long <longman@...hat.com>,
Sebastian Andrzej Siewior <bigeasy@...utronix.de>
Subject: [PATCH v6 08/15] futex: Re-evaluate the hash bucket after dropping the lock
In futex_requeue() and futex_wake_op() the hash bucket lock is
dropped in the failure paths for handling page faults and other
error scenarios. After that the code jumps back to retry_private
which relocks the hash bucket[s] under the assumption that the hash
bucket pointer which was retrieved via futex_hash() is still valid.
With resizable private hash buckets, that assumption is not longer
true as the waiters can be moved to a larger hash in the meantime.
Move the retry_private label above the hashing function to handle
this correctly.
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
---
kernel/futex/requeue.c | 2 +-
kernel/futex/waitwake.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/futex/requeue.c b/kernel/futex/requeue.c
index 217cec5c8302e..31ec543e7fdb3 100644
--- a/kernel/futex/requeue.c
+++ b/kernel/futex/requeue.c
@@ -443,10 +443,10 @@ int futex_requeue(u32 __user *uaddr1, unsigned int flags1,
if (requeue_pi && futex_match(&key1, &key2))
return -EINVAL;
+retry_private:
hb1 = futex_hash(&key1);
hb2 = futex_hash(&key2);
-retry_private:
futex_hb_waiters_inc(hb2);
double_lock_hb(hb1, hb2);
diff --git a/kernel/futex/waitwake.c b/kernel/futex/waitwake.c
index 01d419efbf298..03e2f546967d8 100644
--- a/kernel/futex/waitwake.c
+++ b/kernel/futex/waitwake.c
@@ -267,10 +267,10 @@ int futex_wake_op(u32 __user *uaddr1, unsigned int flags, u32 __user *uaddr2,
if (unlikely(ret != 0))
return ret;
+retry_private:
hb1 = futex_hash(&key1);
hb2 = futex_hash(&key2);
-retry_private:
double_lock_hb(hb1, hb2);
op_ret = futex_atomic_op_inuser(op, uaddr2);
if (unlikely(op_ret < 0)) {
--
2.45.2
Powered by blists - more mailing lists