[PATCH] locking/mutex: Add p->blocked_on wrappers for correctness checks

John Stultz jstultz at google.com
Mon Aug 11 16:04:24 UTC 2025


On Mon, Aug 11, 2025 at 7:39 AM Thomas Hellström
<thomas.hellstrom at linux.intel.com> wrote:
>
> Hi Valentin,
>
> On Sat, 2025-07-12 at 03:33 +0000, Valentin Schneider wrote:
> > This lets us assert mutex::wait_lock is held whenever we access
> > p->blocked_on, as well as warn us for unexpected state changes.
> >
> > [fix conflicts, call in more places]
> > [jstultz: tweaked commit subject, reworked a good bit]
> > Signed-off-by: Valentin Schneider <valentin.schneider at arm.com>
> > Signed-off-by: Connor O'Brien <connoro at google.com>
> > Signed-off-by: John Stultz <jstultz at google.com>
> > Signed-off-by: Peter Zijlstra (Intel) <peterz at infradead.org>
> > Tested-by: K Prateek Nayak <kprateek.nayak at amd.com>
> > Link:
> > https://lkml.kernel.org/r/20250712033407.2383110-4-jstultz@google.com
> > ---
> >  include/linux/sched.h        | 64
> > ++++++++++++++++++++++++++++++++++--
> >  kernel/locking/mutex-debug.c |  4 +--
> >  kernel/locking/mutex.c       | 32 ++++++++----------
> >  kernel/locking/ww_mutex.h    |  8 ++---
> >  4 files changed, 81 insertions(+), 27 deletions(-)
> >
>
> Our CI is hitting a lot of these:
>
> https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/5826
>
> From looking at the code, the wound-wait code after wounding the mutex
> owner, wakes it up opportunistically, so that *if* it is waiting on
> another wound-wait mutex, should re-evaluate whether it should
> rollback. Ideally in this case, the blocked-on status should be removed
> by the process that was woken up?
>
> Otherwise if the wound-wait code misbehaves in doing this we need to
> fix it.

My apologies again for this one.

I've got a fix on the list, waiting to be picked up, here:
https://lore.kernel.org/lkml/20250805001026.2247040-1-jstultz@google.com/

As well as some improvements to the ww_mutex test driver to make sure
the test coverage doesn't miss this again.
https://lore.kernel.org/lkml/20250801023358.562525-1-jstultz@google.com/

thanks
-john


More information about the Intel-xe mailing list