Re: [PATCH] locking/mutex: Reduce chance of setting HANDOFF bit on unlocked mutex

From: Peter Zijlstra
Date: Wed Jun 30 2021 - 10:51:44 EST


On Wed, Jun 30, 2021 at 10:43:37PM +0800, Xu, Yanfei wrote:
> > +static inline struct task_struct *__mutex_trylock_or_owner(struct mutex *lock, bool handoff)
> > {
> > unsigned long owner, curr = (unsigned long)current;
> >
> > owner = atomic_long_read(&lock->owner);
> > for (;;) { /* must loop, can race against a flag */
> > + unsigned long flags = __owner_flags(owner);
> > unsigned long task = owner & ~MUTEX_FLAGS;
> >
> > if (task) {
> > + if (flags & MUTEX_FLAG_PICKUP) {
> >
> > + if (task != curr)
> > + break;
> > +
> > + flags &= ~MUTEX_FLAG_PICKUP;
> > +
>
> Hmm.. Should we also clear HANDOFF bit here? I don't find where it is
> cleared.

Should already be gone; see __mutex_handoff().