public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Waiman Long <waiman.long@hpe.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Jason Low <jason.low2@hpe.com>,
	Ding Tianhong <dingtianhong@huawei.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Will Deacon <Will.Deacon@arm.com>, Ingo Molnar <mingo@redhat.com>,
	Imre Deak <imre.deak@intel.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Tim Chen <tim.c.chen@linux.intel.com>,
	Terry Rudd <terry.rudd@hpe.com>,
	"Paul E. McKenney" <paulmck@us.ibm.com>,
	Jason Low <jason.low2@hp.com>,
	Chris Wilson <chris@chris-wilson.co.uk>,
	Daniel Vetter <daniel.vetter@ffwll.ch>
Subject: Re: [RFC][PATCH -v2 4/4] locking/mutex: Add lock handoff to avoid starvation
Date: Fri, 26 Aug 2016 10:30:31 -0400	[thread overview]
Message-ID: <57C05287.8000708@hpe.com> (raw)
In-Reply-To: <20160825222328.GN10138@twins.programming.kicks-ass.net>

On 08/25/2016 06:23 PM, Peter Zijlstra wrote:
> On Thu, Aug 25, 2016 at 06:00:19PM -0400, Waiman Long wrote:
>> On 08/25/2016 02:37 PM, Peter Zijlstra wrote:
>>> @@ -468,9 +496,12 @@ void __sched mutex_unlock(struct mutex *
>>>   	DEBUG_LOCKS_WARN_ON(__mutex_owner(lock) != current);
>>>   #endif
>>>
>>> -	owner = atomic_long_fetch_and(MUTEX_FLAGS,&lock->owner);
>>> +	owner = atomic_long_read(&lock->owner);
>>> +	if (!(owner&   MUTEX_FLAG_HANDOFF))
>>> +		owner = atomic_long_fetch_and(MUTEX_FLAGS,&lock->owner);
>>> +
>>>   	if (__owner_flags(owner))
>>> -		__mutex_unlock_slowpath(lock);
>>> +		__mutex_unlock_slowpath(lock, owner);
>>>   }
>>>   EXPORT_SYMBOL(mutex_unlock);
>> I don't think the race condition is fixed when we don't make sure that lock
>> handoff only happens from current=>new. The problem is due to the fact that
>> the MUTEX_FLAG_HANDOFF check in the unlock fastpath isn't serialized by the
>> wait_lock. As a result, it is possible that the owner is NULL while the
>> HANDOFF bit is set. Or an optimistic spinner may have stolen the lock in the
>> interim.
> You're right.. I'll try again tomorrow.

Actually, it is also OK to handoff from NULL=>new, but nothing else is 
appropriate.

Cheers,
Longman

  reply	other threads:[~2016-08-26 14:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-25 18:37 [RFC][PATCH -v2 0/4] locking/mutex: Rewrite basic mutex Peter Zijlstra
2016-08-25 18:37 ` [RFC][PATCH -v2 1/4] locking/drm/i915: Kill mutex trickery Peter Zijlstra
2016-08-25 19:36   ` Daniel Vetter
2016-08-25 19:59     ` Waiman Long
2016-08-25 18:37 ` [RFC][PATCH -v2 2/4] locking/mutex: Rework mutex::owner Peter Zijlstra
2016-08-25 18:37 ` [RFC][PATCH -v2 3/4] locking/mutex: Allow MUTEX_SPIN_ON_OWNER when DEBUG_MUTEXES Peter Zijlstra
2016-08-25 18:37 ` [RFC][PATCH -v2 4/4] locking/mutex: Add lock handoff to avoid starvation Peter Zijlstra
2016-08-25 22:00   ` Waiman Long
2016-08-25 22:23     ` Peter Zijlstra
2016-08-26 14:30       ` Waiman Long [this message]
2016-08-26 15:18         ` Peter Zijlstra
2016-08-26 23:40           ` Waiman Long
2016-08-29 15:41             ` Peter Zijlstra
2016-08-30 11:53               ` Peter Zijlstra
2016-08-30 22:32                 ` Waiman Long

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=57C05287.8000708@hpe.com \
    --to=waiman.long@hpe.com \
    --cc=Will.Deacon@arm.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dave@stgolabs.net \
    --cc=dingtianhong@huawei.com \
    --cc=imre.deak@intel.com \
    --cc=jason.low2@hp.com \
    --cc=jason.low2@hpe.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulmck@us.ibm.com \
    --cc=peterz@infradead.org \
    --cc=terry.rudd@hpe.com \
    --cc=tglx@linutronix.de \
    --cc=tim.c.chen@linux.intel.com \
    --cc=torvalds@linux-foundation.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