Commit 0694c8f58a54 for kernel

commit 0694c8f58a541d56e3c71a9cacd24155f9463702
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date:   Mon Nov 23 16:47:33 2026 -0800

    sched/wait: add WQ_FLAG_POLL_EXCLUSIVE for user space waiters

    An exclusive waiter whose wake function returns a positive return value
    to indicate that it has successfully been woken up stops the wakeup
    walk, on the understanding that it will handle the event.

    However, user space consumers - like eventpoll or io_uring - want to be
    woken up, and want to avoid the thundering herd issue.  So they used an
    exclusive wait - but without any actual guarantee that they will then
    meaningfully handle the event.

    So the wakeup could be lost, and real waiters would be left pending.

    Add a separate flag for these kind of "exclusive poll" cases, which is
    effectively what these user space waiters are.  Only the first such
    entry that accepts a wakeup is woken, as now, but they don't count
    against nr_exclusive and it doesn't stop the walk.

    Wake-all (nr_exclusive == 0, including POLLFREE) still calls every entry.

    Reported-by: Mani Tofigh <mt4022@columbia.edu>
    Reviewed-by: Oleg Nesterov <oleg@redhat.com>
    Cc: Jens Axboe <axboe@kernel.dk>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Juri Lelli <juri.lelli@redhat.com>
    Cc: Vincent Guittot <vincent.guittot@linaro.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

diff --git a/include/linux/wait.h b/include/linux/wait.h
index b3e94c71cd3e..09518f8ff10c 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -21,6 +21,7 @@ int default_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int
 #define WQ_FLAG_CUSTOM		0x04
 #define WQ_FLAG_DONE		0x08
 #define WQ_FLAG_PRIORITY	0x10
+#define WQ_FLAG_POLL_EXCLUSIVE	0x20

 /*
  * A single wait-queue entry structure:
diff --git a/kernel/sched/wait.c b/kernel/sched/wait.c
index d0521b54eeb3..020cf3f77611 100644
--- a/kernel/sched/wait.c
+++ b/kernel/sched/wait.c
@@ -85,6 +85,11 @@ EXPORT_SYMBOL(remove_wait_queue);
  * may be at the head of the list, and can consume the event without any other
  * tasks being woken if it's also an exclusive task.
  *
+ * An exclusive waiter that returns >0 promises to handle the event. Pollers
+ * (EPOLLEXCLUSIVE) can't promise that, since userspace may never consume it.
+ * They use WQ_FLAG_POLL_EXCLUSIVE instead: only one of them is woken, but they
+ * never count against nr_exclusive or stop the walk.
+ *
  * There are circumstances in which we can try to wake a task which has already
  * started to run but is not in state TASK_RUNNING. try_to_wake_up() returns
  * zero in this (rare) case, and we handle it by continuing to scan the queue.
@@ -93,6 +98,7 @@ static int __wake_up_common(struct wait_queue_head *wq_head, unsigned int mode,
 			int nr_exclusive, int wake_flags, void *key)
 {
 	wait_queue_entry_t *curr, *next;
+	bool poll_woken = false;

 	lockdep_assert_held(&wq_head->lock);

@@ -100,10 +106,16 @@ static int __wake_up_common(struct wait_queue_head *wq_head, unsigned int mode,
 		unsigned flags = curr->flags;
 		int ret;

+		if ((flags & WQ_FLAG_POLL_EXCLUSIVE) && poll_woken)
+			continue;
 		ret = curr->func(curr, mode, wake_flags, key);
 		if (ret < 0)
 			break;
-		if (ret && (flags & WQ_FLAG_EXCLUSIVE) && !--nr_exclusive)
+		if (!ret)
+			continue;
+		if (flags & WQ_FLAG_POLL_EXCLUSIVE)
+			poll_woken = nr_exclusive > 0;
+		else if ((flags & WQ_FLAG_EXCLUSIVE) && !--nr_exclusive)
 			break;
 	}