From: K Prateek Nayak <kprateek.nayak@amd.com>
To: John Stultz <jstultz@google.com>, LKML <linux-kernel@vger.kernel.org>
Cc: <syzbot+602c4720aed62576cd79@syzkaller.appspotmail.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Ingo Molnar <mingo@redhat.com>,
"Peter Zijlstra" <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
"Vincent Guittot" <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Valentin Schneider <valentin.schneider@arm.com>,
Suleiman Souhlal <suleiman@google.com>, <airlied@gmail.com>,
<mripard@kernel.org>, <simona@ffwll.ch>, <tzimmermann@suse.de>,
<dri-devel@lists.freedesktop.org>, <kernel-team@android.com>
Subject: Re: [PATCH v2] locking: Fix __clear_task_blocked_on() warning from __ww_mutex_wound() path
Date: Mon, 4 Aug 2025 10:12:50 +0530 [thread overview]
Message-ID: <6e82f186-e059-4535-a0f5-848a055058f3@amd.com> (raw)
In-Reply-To: <20250801192157.912805-1-jstultz@google.com>
Hello John,
On 8/2/2025 12:51 AM, John Stultz wrote:
> The __clear_task_blocked_on() helper added a number of sanity
> checks ensuring we hold the mutex wait lock and that the task
> we are clearing blocked_on pointer (if set) matches the mutex.
>
> However, there is an edge case in the _ww_mutex_wound() logic
> where we need to clear the blocked_on pointer for the task that
> owns the mutex, not the task that is waiting on the mutex.
>
> For this case the sanity checks aren't valid, so handle this
> by allowing a NULL lock to skip the additional checks.
>
> This was easier to miss, I realized, as the test-ww_mutex
> driver only exercises the wait-die class of ww_mutexes.
>
> I've got a follow up patch to extend the test so that it
> will exercise both.
>
> Fixes: a4f0b6fef4b0 ("locking/mutex: Add p->blocked_on wrappers for correctness checks")
> Reported-by: syzbot+602c4720aed62576cd79@syzkaller.appspotmail.com
> Reported-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Closes: https://lore.kernel.org/lkml/68894443.a00a0220.26d0e1.0015.GAE@google.com/
> Signed-off-by: John Stultz <jstultz@google.com>
I've been running this for a while and haven't seen any splats with
syzbot's C reproducer.
> ---
> v2:
> * Rewording of "lock" to "mutex" in commit and comment for
> clarity
> * Rework __clear_task_blocked_on() to use READ_ONCE and WRITE_ONCE
> so we don't trip over the WARNING if two instances race, as suggested
> by K Prateek Nayak and Maarten Lankhorst
>
> 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>
> Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
> Cc: Valentin Schneider <valentin.schneider@arm.com>
> Cc: K Prateek Nayak <kprateek.nayak@amd.com>
> Cc: Suleiman Souhlal <suleiman@google.com>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: airlied@gmail.com
> Cc: mripard@kernel.org
> Cc: simona@ffwll.ch
> Cc: tzimmermann@suse.de
> Cc: dri-devel@lists.freedesktop.org
> Cc: kernel-team@android.com
> ---
> include/linux/sched.h | 23 +++++++++++++----------
> kernel/locking/ww_mutex.h | 6 +++++-
> 2 files changed, 18 insertions(+), 11 deletions(-)
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 40d2fa90df425..700b50d29f7fe 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -2166,16 +2166,19 @@ static inline void set_task_blocked_on(struct task_struct *p, struct mutex *m)
Should we consider using WRITE_ONCE() in __set_task_blocked_on() and
use a local copy of "blocked_on" there too?
I think a set_task_blocked_on() on a separate ww_mutex can still race
with a wound on the ww_ctx which indiscriminately writes NULL to
"owner->blocked_on" and can possibly lead to a splat for:
WARN_ON_ONCE(p->blocked_on && p->blocked_on != m);
^^^^^^^^^^^^^ ^^^^^^^^^^^^^
Sees p is blocked on "m" Turns NULL as a result
already. of a concurrent wound.
A READ_ONCE() and WRITE_ONCE() in __set_task_blocked_on() should help
solve the splat in this very unlikely case too unless I'm mistaken.
Apart from that, this fix looks good. Feel free to include:
Reviewed-and-tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
--
Thanks and Regards,
Prateek
>
> static inline void __clear_task_blocked_on(struct task_struct *p, struct mutex *m)
> {
> - WARN_ON_ONCE(!m);
> - /* Currently we serialize blocked_on under the mutex::wait_lock */
> - lockdep_assert_held_once(&m->wait_lock);
> - /*
> - * There may be cases where we re-clear already cleared
> - * blocked_on relationships, but make sure we are not
> - * clearing the relationship with a different lock.
> - */
> - WARN_ON_ONCE(m && p->blocked_on && p->blocked_on != m);
> - p->blocked_on = NULL;
> + if (m) {
> + struct mutex *blocked_on = READ_ONCE(p->blocked_on);
> +
> + /* Currently we serialize blocked_on under the mutex::wait_lock */
> + lockdep_assert_held_once(&m->wait_lock);
> + /*
> + * There may be cases where we re-clear already cleared
> + * blocked_on relationships, but make sure we are not
> + * clearing the relationship with a different lock.
> + */
> + WARN_ON_ONCE(blocked_on && blocked_on != m);
> + }
> + WRITE_ONCE(p->blocked_on, NULL);
> }
next prev parent reply other threads:[~2025-08-04 4:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-01 19:21 John Stultz
2025-08-04 4:42 ` K Prateek Nayak [this message]
2025-08-05 0:10 ` [PATCH v3] " John Stultz
2025-08-05 9:27 ` Maarten Lankhorst
2025-08-11 16:21 ` Peter Zijlstra
2025-08-13 13:18 ` [tip: locking/urgent] " tip-bot2 for John Stultz
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=6e82f186-e059-4535-a0f5-848a055058f3@amd.com \
--to=kprateek.nayak@amd.com \
--cc=airlied@gmail.com \
--cc=dietmar.eggemann@arm.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jstultz@google.com \
--cc=juri.lelli@redhat.com \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mingo@redhat.com \
--cc=mripard@kernel.org \
--cc=peterz@infradead.org \
--cc=simona@ffwll.ch \
--cc=suleiman@google.com \
--cc=syzbot+602c4720aed62576cd79@syzkaller.appspotmail.com \
--cc=tzimmermann@suse.de \
--cc=valentin.schneider@arm.com \
--cc=vincent.guittot@linaro.org \
/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®