[PATCH v9 01/11] futex: fixup futex_wait_setup [fold futex: Move futex_queue() into futex_wait_setup()]

Sebastian Andrzej Siewior posted 11 patches 9 months, 3 weeks ago
[PATCH v9 01/11] futex: fixup futex_wait_setup [fold futex: Move futex_queue() into futex_wait_setup()]
Posted by Sebastian Andrzej Siewior 9 months, 3 weeks ago
we could also make @task a bool signaling it is either NULL or current.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 kernel/futex/waitwake.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/kernel/futex/waitwake.c b/kernel/futex/waitwake.c
index 7655de59ab3d6..44034dee7a48c 100644
--- a/kernel/futex/waitwake.c
+++ b/kernel/futex/waitwake.c
@@ -571,7 +571,8 @@ int futex_wait_multiple(struct futex_vector *vs, unsigned int count,
  * @val:	the expected value
  * @flags:	futex flags (FLAGS_SHARED, etc.)
  * @q:		the associated futex_q
- * @hb:		storage for hash_bucket pointer to be returned to caller
+ * @key2:	the second futex_key if used for requeue PI
+ * task:	Task queueing this futex
  *
  * Setup the futex_q and locate the hash_bucket.  Get the futex value and
  * compare it with the expected value.  Handle atomic faults internally.
@@ -634,7 +635,7 @@ int futex_wait_setup(u32 __user *uaddr, u32 val, unsigned int flags,
 
 		if (uval != val) {
 			futex_q_unlock(hb);
-			ret = -EWOULDBLOCK;
+			return -EWOULDBLOCK;
 		}
 
 		if (key2 && futex_match(&q->key, key2)) {
@@ -648,8 +649,9 @@ int futex_wait_setup(u32 __user *uaddr, u32 val, unsigned int flags,
 		 * futex_queue() calls spin_unlock() upon completion, both serializing
 		 * access to the hash list and forcing another memory barrier.
 		 */
-		set_current_state(TASK_INTERRUPTIBLE|TASK_FREEZABLE);
-		futex_queue(q, hb, current);
+		if (task == current)
+			set_current_state(TASK_INTERRUPTIBLE|TASK_FREEZABLE);
+		futex_queue(q, hb, task);
 	}
 
 	return ret;
-- 
2.47.2
Re: [PATCH v9 01/11] futex: fixup futex_wait_setup [fold futex: Move futex_queue() into futex_wait_setup()]
Posted by Thomas Gleixner 9 months, 3 weeks ago
On Tue, Feb 25 2025 at 18:09, Sebastian Andrzej Siewior wrote:

> we could also make @task a bool signaling it is either NULL or current.

I have no idea what this change log is trying to tell me. It gives zero
information what this patch is about and the subject line is confusing
at best.

Thanks,

        tglx
Re: [PATCH v9 01/11] futex: fixup futex_wait_setup [fold futex: Move futex_queue() into futex_wait_setup()]
Posted by Sebastian Andrzej Siewior 9 months, 3 weeks ago
On 2025-02-26 09:15:02 [+0100], Thomas Gleixner wrote:
> On Tue, Feb 25 2025 at 18:09, Sebastian Andrzej Siewior wrote:
> 
> > we could also make @task a bool signaling it is either NULL or current.
> 
> I have no idea what this change log is trying to tell me. It gives zero
> information what this patch is about and the subject line is confusing
> at best.

This is meant for PeterZ as this should be folded into one of this
patches on which this series is built upon.
The argument "task" passed to futex_wait_setup() is always current or
NULL. The latter is only used by io_uring. So instead getting a task
passed and assuming it belongs to the current process we could have a
bool and enforce this.
The problem would be if things change later on and the passed task does
not belong to the current process hierarchy and would not share the same
private hash.

> Thanks,
> 
>         tglx

Sebastian