From: Boqun Feng <boqun.feng@gmail.com>
To: Michael Ellerman <mpe@ellerman.id.au>
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
Will Deacon <will.deacon@arm.com>,
Paul Mackerras <paulus@samba.org>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: Re: [v2] powerpc: spinlock: Fix spin_unlock_wait()
Date: Mon, 6 Jun 2016 12:59:59 +0800 [thread overview]
Message-ID: <20160606045959.GE23133@insomnia> (raw)
In-Reply-To: <3rNMkF2Y1sz9t4P@ozlabs.org>
[-- Attachment #1: Type: text/plain, Size: 2339 bytes --]
On Mon, Jun 06, 2016 at 02:52:05PM +1000, Michael Ellerman wrote:
> On Fri, 2016-03-06 at 03:49:48 UTC, Boqun Feng wrote:
> > There is an ordering issue with spin_unlock_wait() on powerpc, because
> > the spin_lock primitive is an ACQUIRE and an ACQUIRE is only ordering
> > the load part of the operation with memory operations following it.
>
> ...
> > diff --git a/arch/powerpc/include/asm/spinlock.h b/arch/powerpc/include/asm/spinlock.h
> > index 523673d7583c..2ed893662866 100644
> > --- a/arch/powerpc/include/asm/spinlock.h
> > +++ b/arch/powerpc/include/asm/spinlock.h
> > @@ -162,12 +181,23 @@ static inline void arch_spin_unlock(arch_spinlock_t *lock)
> > lock->slock = 0;
> > }
> >
> > -#ifdef CONFIG_PPC64
> > -extern void arch_spin_unlock_wait(arch_spinlock_t *lock);
> > -#else
> > -#define arch_spin_unlock_wait(lock) \
> > - do { while (arch_spin_is_locked(lock)) cpu_relax(); } while (0)
> > -#endif
> > +static inline void arch_spin_unlock_wait(arch_spinlock_t *lock)
> > +{
> > + smp_mb();
> > +
> > + if (!arch_spin_is_locked_sync(lock))
> > + goto out;
> > +
> > + while (!arch_spin_value_unlocked(*lock)) {
> > + HMT_low();
> > + if (SHARED_PROCESSOR)
> > + __spin_yield(lock);
> > + }
> > + HMT_medium();
> > +
> > +out:
> > + smp_mb();
> > +}
>
> I think this would actually be easier to follow if it was all just in one routine:
>
> static inline void arch_spin_unlock_wait(arch_spinlock_t *lock)
> {
> arch_spinlock_t lock_val;
>
> smp_mb();
>
> /*
> * Atomically load and store back the lock value (unchanged). This
> * ensures that our observation of the lock value is ordered with
> * respect to other lock operations.
> */
> __asm__ __volatile__(
> "1: " PPC_LWARX(%0, 0, %2, 1) "\n"
> " stwcx. %0, 0, %2\n"
> " bne- 1b\n"
> : "=&r" (lock_val), "+m" (*lock)
> : "r" (lock)
> : "cr0", "xer");
>
> if (arch_spin_value_unlocked(lock_val))
> goto out;
>
> while (!arch_spin_value_unlocked(*lock)) {
> HMT_low();
> if (SHARED_PROCESSOR)
> __spin_yield(lock);
> }
> HMT_medium();
>
> out:
> smp_mb();
> }
>
>
> Thoughts?
>
Make sense. I admit that I sort of overdesigned by introducing
arch_spin_is_locked_sync().
This version is better, thank you!
Regards,
Boqun
> cheers
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2016-06-06 4:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-03 3:49 [PATCH v2] powerpc: spinlock: Fix spin_unlock_wait() Boqun Feng
2016-06-06 4:52 ` [v2] " Michael Ellerman
2016-06-06 4:59 ` Boqun Feng [this message]
2016-06-06 11:14 ` Michael Ellerman
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=20160606045959.GE23133@insomnia \
--to=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=paulmck@linux.vnet.ibm.com \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
--cc=will.deacon@arm.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.