lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20160912152052.GT10153@twins.programming.kicks-ass.net>
Date:   Mon, 12 Sep 2016 17:20:52 +0200
From:   Peter Zijlstra <peterz@...radead.org>
To:     Waiman Long <waiman.long@....com>
Cc:     Linus Torvalds <torvalds@...ux-foundation.org>,
        Jason Low <jason.low2@....com>,
        Ding Tianhong <dingtianhong@...wei.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Will Deacon <Will.Deacon@....com>,
        Ingo Molnar <mingo@...hat.com>,
        Imre Deak <imre.deak@...el.com>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Davidlohr Bueso <dave@...olabs.net>,
        Tim Chen <tim.c.chen@...ux.intel.com>,
        Terry Rudd <terry.rudd@....com>,
        "Paul E. McKenney" <paulmck@...ibm.com>,
        Jason Low <jason.low2@...com>
Subject: Re: [RFC][PATCH -v3 10/10] locking/mutex: Implement alternative
 HANDOFF

On Fri, Sep 09, 2016 at 06:32:04PM -0400, Waiman Long wrote:

> I have another way of catching the uncleared handoff flag. See the following
> code to see if you think that will work.
> 
> diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
> index 9492494..362ff83 100644
> --- a/kernel/locking/mutex.c
> +++ b/kernel/locking/mutex.c
> @@ -85,7 +85,13 @@ static inline bool __mutex_trylock(struct mutex *lock,
> const
> 
>         owner = atomic_long_read(&lock->owner);
>         for (;;) { /* must loop, can race against a flag */
> -               unsigned long old;
> +               unsigned long old, flags = __owner_flags(owner);
> +
> +               /*
> +                * We don't need to keep the HANDOFF flag for the waiter.
> +                */
> +               if (handoff)
> +                       flags &= ~MUTEX_FLAG_HANDOFF;
> 
>                 if (__owner_task(owner)) {
>                         if (handoff && unlikely(__owner_task(owner) == current))

I placed this condition below the __owner_task() branch.

> @@ -688,7 +694,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned
>                  * state back to RUNNING and fall through the next schedule(),
>                  * or we must see its unlock and acquire.
>                  */
> -               if (__mutex_trylock(lock, true))
> +               if (__mutex_trylock(lock, first))
>                         break;
> 
>                 spin_lock_mutex(&lock->wait_lock, flags);

Hmm, yes. I think that works.

We (the first waiter) set the flag, we clear it on try-lock, or unlock
clears it when it hands the thing off.

Much simpler. Thanks!

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ