From: Peter Zijlstra <peterz@infradead.org>
To: Yao Kai <yaokai34@huawei.com>
Cc: syzbot <syzbot@kernel.org>,
syzkaller-bugs@googlegroups.com, linux-kernel@vger.kernel.org,
Ingo Molnar <mingo@redhat.com>, Thomas Gleixner <tglx@kernel.org>,
andrealmeid@igalia.com, dave@stgolabs.net, dvhart@infradead.org,
liuyongqiang13@huawei.com, syzbot@lists.linux.dev
Subject: Re: [PATCH] futex: Fix might_sleep() warning in futex_pivot_pending()
Date: Thu, 20 Aug 2026 09:33:37 +0200 [thread overview]
Message-ID: <20260820073337.GL1247881@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <681d9e21-d408-4acb-8c51-b8a86d599e0f@huawei.com>
On Tue, Aug 18, 2026 at 08:24:07PM +0800, Yao Kai wrote:
> > + __wq_head = __var_waitqueue(mm);
> > + init_wait_var_entry(&__wbq_entry, mm, 0);
> > + __wbq_entry.wq_entry.func = woken_wake_bit_function;
> > + add_wait_queue(__wq_head, &__wbq_entry.wq_entry);
> > +
> > + /*
> > + * add_wait_queue() futex_ref_put()
> > + * MB (this) MB (implied)
> > + * futex_pivot_pending() wake_up_var()
> > + * waitqueue_active()
> > + *
> > + * Notably, it must not be possible to see
> > + * !futex_pivot_pending() && !waitqueue_active().
> > + */
> > + smp_mb__after_spinlock();
>
> I still think we should use smp_mb() here, smp_mb__after_spinlock() only
> orders accesses preceding the lock acquisition against later accesses. The
> waitqueue insertion happens after that acquisition, so I don't think
> smp_mb__after_spinlock() covers it here.
I can definitely make it smp_mb() just to make you feel better, this is
not a fast path. But the smp_mb__after_spinlock() is sufficient in this
case.
Specifically, the situation is
LOCK(&waitq->lock)
[STORE] list_add()
UNLOCK(&waitq->lock)
smp_mb__after_spinlock()
LOCK(&mmph->lock)
[LOAD] refcount
UNLOCK(&mmph->lock)
That means the STORE and LOAD are separated by UNLOCK+LOCK, and on every
architecture *EXCEPT* PPC that implies smp_mb(). On PPC we need the
extra smp_mb() to 'upgrade' the LWSYNC to SYNC.
Specifically, on TSO (x86,s390,sparc64) the atomic op in LOCK implies a
full barrier, on ARM64 RELEASE+ACQUIRE is RCsc, etc.
There is a section on LOCKING in
tools/memory-model/Documentation/explanation.txt on this very subject.
> > +
> > + while (!futex_pivot_pending(mm) &&
> > + wait_woken(&__wbq_entry.wq_entry, TASK_UNINTERRUPTIBLE,
> > + MAX_SCHEDULE_TIMEOUT))
> > + /* empty */;
>
> Since MAX_SCHEDULE_TIMEOUT never returns zero, so I think this can be:
>
> while (!futex_pivot_pending(mm))
> wait_woken(&__wbq_entry.wq_entry, TASK_UNINTERRUPTIBLE,
> MAX_SCHEDULE_TIMEOUT));
Well, you missed the '&&', but that is exactly what I wrote, no?
I just put the ';' behind a comment, to indicate it was an empty loop on
purpose. Some people (and static checkers/linters/etc.) get
upset/confused if there is no body on a loop construct.
Anyway, I've tested all this, selftests/futex trips this WARN without,
and runs to completion with this patch, so it must be perfect.
Let me go write a Changelog.
next prev parent reply other threads:[~2026-08-20 7:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 6:50 [PATCH] futex: Fix might_sleep() warning in futex_pivot_pending() syzbot
2026-08-14 13:38 ` Peter Zijlstra
2026-08-17 7:29 ` Yao Kai
2026-08-18 10:46 ` Peter Zijlstra
2026-08-18 12:24 ` Yao Kai
2026-08-20 7:33 ` Peter Zijlstra [this message]
[not found] ` <2247c7e0-1466-4228-900c-c5b0677fba41@huawei.com>
2026-08-20 7:35 ` Peter Zijlstra
-- strict thread matches above, loose matches on Subject: below --
2026-08-20 7:49 Peter Zijlstra
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=20260820073337.GL1247881@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=andrealmeid@igalia.com \
--cc=dave@stgolabs.net \
--cc=dvhart@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuyongqiang13@huawei.com \
--cc=mingo@redhat.com \
--cc=syzbot@kernel.org \
--cc=syzbot@lists.linux.dev \
--cc=syzkaller-bugs@googlegroups.com \
--cc=tglx@kernel.org \
--cc=yaokai34@huawei.com \
/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