* [PATCH v2 0/2] sched/wait: Queue non-exclusive waiters at the head in do_wait_intr*()
@ 2026-11-23 0:35 Mani Tofigh via B4 Relay
2026-11-23 0:35 ` [PATCH v2 1/2] " Mani Tofigh via B4 Relay
2026-11-23 0:35 ` [PATCH v2 2/2] sched/wait: Pass wq_flags to __wait_event_interruptible_locked() Mani Tofigh via B4 Relay
0 siblings, 2 replies; 5+ messages in thread
From: Mani Tofigh via B4 Relay @ 2026-11-23 0:35 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar
Cc: Oleg Nesterov, Linus Torvalds, Christian Brauner,
Michal Nazarewicz, Wen Yang, linux-fsdevel, linux-kernel, tz2294,
stable, Mani Tofigh
Patch 1 is the fix from v1, rebased on top of Linus's commit
cea5f91daa3a ("wait-event: clean up the internal helper arguments").
Patch 2 makes __wait_event_interruptible_locked() take wq_flags like
___wait_event() now does, as Oleg suggested.
Reproducer: https://github.com/manitofigh/files/blob/main/linux-repros/evexcl.c
gpiolib-cdev and cros_ec_chardev use the same helpers and can be
polled too, so this fixes them as well.
---
Changes in v2:
- Rebased on Linus's master, on top of cea5f91daa3a.
- New patch 2: pass wq_flags instead of a 0/1 "exclusive" argument (Oleg).
- Link to v1: https://patch.msgid.link/20261111-b4-sched-wait-intr-head-v1-1-17cf2af5b964@columbia.edu
- Discussion: https://lore.kernel.org/all/awMhxEuMHULvk8SA@redhat.com/
---
Mani Tofigh (2):
sched/wait: Queue non-exclusive waiters at the head in do_wait_intr*()
sched/wait: Pass wq_flags to __wait_event_interruptible_locked()
include/linux/wait.h | 11 ++++++-----
kernel/sched/wait.c | 16 ++++++++++++----
2 files changed, 18 insertions(+), 9 deletions(-)
---
base-commit: 6e4122f0242a3262512ee3e6f2e7e6de0bd5792b
change-id: 20261111-b4-sched-wait-intr-head-c5e8f0b541f4
Best regards,
--
Mani Tofigh <mt4022@columbia.edu>
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2 1/2] sched/wait: Queue non-exclusive waiters at the head in do_wait_intr*() 2026-11-23 0:35 [PATCH v2 0/2] sched/wait: Queue non-exclusive waiters at the head in do_wait_intr*() Mani Tofigh via B4 Relay @ 2026-11-23 0:35 ` Mani Tofigh via B4 Relay 2026-11-23 14:28 ` Oleg Nesterov 2026-11-23 0:35 ` [PATCH v2 2/2] sched/wait: Pass wq_flags to __wait_event_interruptible_locked() Mani Tofigh via B4 Relay 1 sibling, 1 reply; 5+ messages in thread From: Mani Tofigh via B4 Relay @ 2026-11-23 0:35 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar Cc: Oleg Nesterov, Linus Torvalds, Christian Brauner, Michal Nazarewicz, Wen Yang, linux-fsdevel, linux-kernel, tz2294, stable, Mani Tofigh From: Mani Tofigh <mt4022@columbia.edu> A task blocked in read() on an eventfd or timerfd can sleep forever while the file is readable, if an epoll(EPOLLEXCLUSIVE) watcher of the same file was added before it. eventfd and timerfd wait with wait_event_interruptible_locked_irq(). do_wait_intr_irq() adds the reader at the tail, behind the exclusive epoll entry, and __wake_up_common() stops after waking that entry. If the woken epoll task is killed or leaves without reading, nothing wakes the reader: Task E Task A Task C epoll_wait(ep, -1) /* EPOLLEXCLUSIVE */ read(efd) /* queued after E */ write(efd, 1) /* wakes E, stops */ kill(E, SIGKILL) /* still asleep, efd is readable */ A periodic timerfd doesn't wake A either, since the timer is restarted only by a read. prepare_to_wait_event() and add_wait_queue() add non-exclusive waiters at the head, which is what __wake_up_common() relies on. eventfd did the same itself before it switched to these helpers. Do the same in do_wait_intr() and do_wait_intr_irq(). This only changes the order in which non-exclusive waiters are woken. Each of them still gets every wakeup. With the fix, A is woken by the write. Fixes: 22c43c81a51e ("wait_event_interruptible_locked() interface") Cc: stable@vger.kernel.org Signed-off-by: Mani Tofigh <mt4022@columbia.edu> --- kernel/sched/wait.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/kernel/sched/wait.c b/kernel/sched/wait.c index f8d6d8b9d03e..342dec5fd937 100644 --- a/kernel/sched/wait.c +++ b/kernel/sched/wait.c @@ -319,8 +319,12 @@ EXPORT_SYMBOL(prepare_to_wait_event); */ int do_wait_intr(wait_queue_head_t *wq, wait_queue_entry_t *wait) { - if (likely(list_empty(&wait->entry))) - __add_wait_queue_entry_tail(wq, wait); + if (likely(list_empty(&wait->entry))) { + if (wait->flags & WQ_FLAG_EXCLUSIVE) + __add_wait_queue_entry_tail(wq, wait); + else + __add_wait_queue(wq, wait); + } set_current_state(TASK_INTERRUPTIBLE); if (signal_pending(current)) @@ -336,8 +340,12 @@ EXPORT_SYMBOL(do_wait_intr); int do_wait_intr_irq(wait_queue_head_t *wq, wait_queue_entry_t *wait) { - if (likely(list_empty(&wait->entry))) - __add_wait_queue_entry_tail(wq, wait); + if (likely(list_empty(&wait->entry))) { + if (wait->flags & WQ_FLAG_EXCLUSIVE) + __add_wait_queue_entry_tail(wq, wait); + else + __add_wait_queue(wq, wait); + } set_current_state(TASK_INTERRUPTIBLE); if (signal_pending(current)) -- 2.53.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] sched/wait: Queue non-exclusive waiters at the head in do_wait_intr*() 2026-11-23 0:35 ` [PATCH v2 1/2] " Mani Tofigh via B4 Relay @ 2026-11-23 14:28 ` Oleg Nesterov 0 siblings, 0 replies; 5+ messages in thread From: Oleg Nesterov @ 2026-11-23 14:28 UTC (permalink / raw) To: Mani Tofigh via B4 Relay Cc: Peter Zijlstra, Ingo Molnar, Linus Torvalds, Christian Brauner, Michal Nazarewicz, Wen Yang, linux-fsdevel, linux-kernel, tz2294, stable, Mani Tofigh On 11/22, Mani Tofigh via B4 Relay wrote: > > --- a/kernel/sched/wait.c > +++ b/kernel/sched/wait.c > @@ -319,8 +319,12 @@ EXPORT_SYMBOL(prepare_to_wait_event); > */ > int do_wait_intr(wait_queue_head_t *wq, wait_queue_entry_t *wait) > { > - if (likely(list_empty(&wait->entry))) > - __add_wait_queue_entry_tail(wq, wait); > + if (likely(list_empty(&wait->entry))) { > + if (wait->flags & WQ_FLAG_EXCLUSIVE) > + __add_wait_queue_entry_tail(wq, wait); > + else > + __add_wait_queue(wq, wait); > + } > > set_current_state(TASK_INTERRUPTIBLE); > if (signal_pending(current)) > @@ -336,8 +340,12 @@ EXPORT_SYMBOL(do_wait_intr); > > int do_wait_intr_irq(wait_queue_head_t *wq, wait_queue_entry_t *wait) > { > - if (likely(list_empty(&wait->entry))) > - __add_wait_queue_entry_tail(wq, wait); > + if (likely(list_empty(&wait->entry))) { > + if (wait->flags & WQ_FLAG_EXCLUSIVE) > + __add_wait_queue_entry_tail(wq, wait); > + else > + __add_wait_queue(wq, wait); > + } > > set_current_state(TASK_INTERRUPTIBLE); > if (signal_pending(current)) perhaps it makes sense to add the new trivial helper later, prepare_to_wait_event() can use it too. Reviewed-by: Oleg Nesterov <oleg@redhat.com> ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] sched/wait: Pass wq_flags to __wait_event_interruptible_locked() 2026-11-23 0:35 [PATCH v2 0/2] sched/wait: Queue non-exclusive waiters at the head in do_wait_intr*() Mani Tofigh via B4 Relay 2026-11-23 0:35 ` [PATCH v2 1/2] " Mani Tofigh via B4 Relay @ 2026-11-23 0:35 ` Mani Tofigh via B4 Relay 2026-11-23 14:35 ` Oleg Nesterov 1 sibling, 1 reply; 5+ messages in thread From: Mani Tofigh via B4 Relay @ 2026-11-23 0:35 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar Cc: Oleg Nesterov, Linus Torvalds, Christian Brauner, Michal Nazarewicz, Wen Yang, linux-fsdevel, linux-kernel, tz2294, Mani Tofigh From: Mani Tofigh <mt4022@columbia.edu> Commit cea5f91daa3a ("wait-event: clean up the internal helper arguments") made ___wait_event() take the wait entry's flags instead of a 0/1 argument for whether it is exclusive. __wait_event_interruptible_locked() still takes the 0/1 argument. Pass wq_flags here too, so the _exclusive_locked variants say WQ_FLAG_EXCLUSIVE rather than an unexplained 1. No functional change. Signed-off-by: Mani Tofigh <mt4022@columbia.edu> --- include/linux/wait.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/linux/wait.h b/include/linux/wait.h index b3e94c71cd3e..6c039d92c770 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h @@ -770,12 +770,11 @@ do { \ extern int do_wait_intr(wait_queue_head_t *, wait_queue_entry_t *); extern int do_wait_intr_irq(wait_queue_head_t *, wait_queue_entry_t *); -#define __wait_event_interruptible_locked(wq, condition, exclusive, fn) \ +#define __wait_event_interruptible_locked(wq, condition, wq_flags, fn) \ ({ \ int __ret; \ DEFINE_WAIT(__wait); \ - if (exclusive) \ - __wait.flags |= WQ_FLAG_EXCLUSIVE; \ + __wait.flags = (wq_flags); \ do { \ __ret = fn(&(wq), &__wait); \ if (__ret) \ @@ -870,7 +869,8 @@ extern int do_wait_intr_irq(wait_queue_head_t *, wait_queue_entry_t *); */ #define wait_event_interruptible_exclusive_locked(wq, condition) \ ((condition) \ - ? 0 : __wait_event_interruptible_locked(wq, condition, 1, do_wait_intr)) + ? 0 : __wait_event_interruptible_locked(wq, condition, \ + WQ_FLAG_EXCLUSIVE, do_wait_intr)) /** * wait_event_interruptible_exclusive_locked_irq - sleep until a condition gets true @@ -901,7 +901,8 @@ extern int do_wait_intr_irq(wait_queue_head_t *, wait_queue_entry_t *); */ #define wait_event_interruptible_exclusive_locked_irq(wq, condition) \ ((condition) \ - ? 0 : __wait_event_interruptible_locked(wq, condition, 1, do_wait_intr_irq)) + ? 0 : __wait_event_interruptible_locked(wq, condition, \ + WQ_FLAG_EXCLUSIVE, do_wait_intr_irq)) #define __wait_event_killable(wq, condition) \ -- 2.53.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] sched/wait: Pass wq_flags to __wait_event_interruptible_locked() 2026-11-23 0:35 ` [PATCH v2 2/2] sched/wait: Pass wq_flags to __wait_event_interruptible_locked() Mani Tofigh via B4 Relay @ 2026-11-23 14:35 ` Oleg Nesterov 0 siblings, 0 replies; 5+ messages in thread From: Oleg Nesterov @ 2026-11-23 14:35 UTC (permalink / raw) To: Mani Tofigh via B4 Relay Cc: Peter Zijlstra, Ingo Molnar, Linus Torvalds, Christian Brauner, Michal Nazarewicz, Wen Yang, linux-fsdevel, linux-kernel, tz2294, Mani Tofigh On 11/22, Mani Tofigh via B4 Relay wrote: > > --- a/include/linux/wait.h > +++ b/include/linux/wait.h > @@ -770,12 +770,11 @@ do { \ > extern int do_wait_intr(wait_queue_head_t *, wait_queue_entry_t *); > extern int do_wait_intr_irq(wait_queue_head_t *, wait_queue_entry_t *); > > -#define __wait_event_interruptible_locked(wq, condition, exclusive, fn) \ > +#define __wait_event_interruptible_locked(wq, condition, wq_flags, fn) \ > ({ \ > int __ret; \ > DEFINE_WAIT(__wait); \ > - if (exclusive) \ > - __wait.flags |= WQ_FLAG_EXCLUSIVE; \ > + __wait.flags = (wq_flags); \ > do { \ > __ret = fn(&(wq), &__wait); \ > if (__ret) \ > @@ -870,7 +869,8 @@ extern int do_wait_intr_irq(wait_queue_head_t *, wait_queue_entry_t *); > */ > #define wait_event_interruptible_exclusive_locked(wq, condition) \ > ((condition) \ > - ? 0 : __wait_event_interruptible_locked(wq, condition, 1, do_wait_intr)) > + ? 0 : __wait_event_interruptible_locked(wq, condition, \ > + WQ_FLAG_EXCLUSIVE, do_wait_intr)) > > /** > * wait_event_interruptible_exclusive_locked_irq - sleep until a condition gets true > @@ -901,7 +901,8 @@ extern int do_wait_intr_irq(wait_queue_head_t *, wait_queue_entry_t *); > */ > #define wait_event_interruptible_exclusive_locked_irq(wq, condition) \ > ((condition) \ > - ? 0 : __wait_event_interruptible_locked(wq, condition, 1, do_wait_intr_irq)) > + ? 0 : __wait_event_interruptible_locked(wq, condition, \ > + WQ_FLAG_EXCLUSIVE, do_wait_intr_irq)) Reviewed-by: Oleg Nesterov <oleg@redhat.com> ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-23 14:35 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-11-23 0:35 [PATCH v2 0/2] sched/wait: Queue non-exclusive waiters at the head in do_wait_intr*() Mani Tofigh via B4 Relay 2026-11-23 0:35 ` [PATCH v2 1/2] " Mani Tofigh via B4 Relay 2026-11-23 14:28 ` Oleg Nesterov 2026-11-23 0:35 ` [PATCH v2 2/2] sched/wait: Pass wq_flags to __wait_event_interruptible_locked() Mani Tofigh via B4 Relay 2026-11-23 14:35 ` Oleg Nesterov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®