mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: mt4022@columbia.edu, Jens Axboe <axboe@kernel.dk>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Christian Brauner <brauner@kernel.org>,
	Michal Nazarewicz <mina86@mina86.com>,
	Wen Yang <wen.yang@linux.dev>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	tz2294@columbia.edu, stable@vger.kernel.org
Subject: Re: [PATCH v2 1/2] sched/wait: Queue non-exclusive waiters at the head in do_wait_intr*()
Date: Tue, 24 Nov 2026 12:54:16 +0100	[thread overview]
Message-ID: <awV66PQWrBOKcZCE@redhat.com> (raw)
In-Reply-To: <CAHk-=wj_eqNh+gNhCQh3exrL5Pmo5hbZBcL0W-4Ah_Nw0Kegzw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2595 bytes --]

On 11/23, Linus Torvalds wrote:
>
> On Sun, 22 Nov 2026 at 16:35, Mani Tofigh via B4 Relay
> <devnull+mt4022.columbia.edu@kernel.org> wrote:
> >
> > 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.
>
> Honestly, I don't think this is the right approach.
>
> We need to fix the disaster area that is epoll, rather than work around
> more epoll bugs elsewhere and make other places more fragile and
> complex.

I agree. But to me it would be better to apply this patch from Mani,
then do something else. Not because it "fixes" the scenario described
in the changelog. As for eventfd_read(), it probably makes sense to
change it to use wait_event_interruptible_exclusive_locked_irq() at
least if !EFD_SEMAPHORE, and then we will have the same problem with
EPOLLEXCLUSIVE again.

But simply because do_wait_intr*() are wrong regardless, and the
change is trivial. And perhaps the changelog should not mention
EPOLLEXCLUSIVE at all.

> And I think we should always add new waiters to the end of the queue,
> and stop any other games. Just walk the whole queue at wakeup time.
>
> Finally, I think we should make the return value from the wakeup
> function be a bitmask, and count "exclusive" as only "we haven't seen
> this bit returned yet". And then *real* exclusive users that actually
> guarantee that they react to the wakeup return all bits set, but the
> sh*t-for-brains garbage that is "epoll" only returns its own bit set -
> so we only wake up *one* epoll user, but we wake up other users anyway,
> because epoll clearl yis lying about its "exclusivity".

Perhaps... But it is not clear how to do this gradually...

And lets forget about epoll for the moment. Lets suppose we change
__wake_up_common() to do

	list_for_each_entry_safe(curr, next, &wq_head->head, entry) {
		bool excl = curr->flags & WQ_FLAG_EXCLUSIVE;
		int ret;

		if (excl && !nr_exclusive)
			continue;
		ret = curr->func(curr, mode, wake_flags, key);
		if (ret < 0)
			break;
		if (ret && excl)
			--nr_exclusive;
	}

This will change the current behaviour if ret < 0. Say wake_page_function() does

	if (flags & WQ_FLAG_EXCLUSIVE) {
		if (test_bit(key->bit_nr, &key->folio->flags.f))
			return -1;
		...

so this logic depends on wait-queue ordering too. "ret < 0" can be encoded
in the bitmask, but it is not clear what exactly __wake_up_common() needs
to do in this case.

Can't we at least cleanup __wake_up_common() ? See the patch below, I already
sent it but it was ignored.

Oleg.


[-- Attachment #2: 0001-sched-wait-kill-leftover-bookmark-logic-in-__wake_up.patch --]
[-- Type: text/plain, Size: 1289 bytes --]

From 887e7597e23b1beb5c6ed536cb342a2daa740ce5 Mon Sep 17 00:00:00 2001
From: Oleg Nesterov <oleg@redhat.com>
Date: Thu, 12 Nov 2026 15:53:53 +0100
Subject: [PATCH] sched/wait: kill leftover bookmark logic in
 __wake_up_common()

The manual list head check and list_for_each_entry_safe_from() in
__wake_up_common() are leftovers from commit 2554db916586 ("sched/wait:
Break up long wake list walk").

This logic was later removed by commit 37acade0ce89 ("sched: remove
wait bookmarks") but the now-unnecessary list hacks were left behind.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 kernel/sched/wait.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/kernel/sched/wait.c b/kernel/sched/wait.c
index f8d6d8b9d03e..d0521b54eeb3 100644
--- a/kernel/sched/wait.c
+++ b/kernel/sched/wait.c
@@ -96,12 +96,7 @@ static int __wake_up_common(struct wait_queue_head *wq_head, unsigned int mode,
 
 	lockdep_assert_held(&wq_head->lock);
 
-	curr = list_first_entry(&wq_head->head, wait_queue_entry_t, entry);
-
-	if (&curr->entry == &wq_head->head)
-		return nr_exclusive;
-
-	list_for_each_entry_safe_from(curr, next, &wq_head->head, entry) {
+	list_for_each_entry_safe(curr, next, &wq_head->head, entry) {
 		unsigned flags = curr->flags;
 		int ret;
 
-- 
2.55.0


  reply	other threads:[~2026-11-24 11:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  0:35 [PATCH v2 0/2] " 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 23:52   ` Linus Torvalds
2026-11-24 11:54     ` Oleg Nesterov [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awV66PQWrBOKcZCE@redhat.com \
    --to=oleg@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mina86@mina86.com \
    --cc=mingo@redhat.com \
    --cc=mt4022@columbia.edu \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=tz2294@columbia.edu \
    --cc=wen.yang@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®