[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160601113733.GQ3190@twins.programming.kicks-ass.net>
Date: Wed, 1 Jun 2016 13:37:33 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Will Deacon <will.deacon@....com>
Cc: linux-kernel@...r.kernel.org, torvalds@...ux-foundation.org,
manfred@...orfullife.com, dave@...olabs.net,
paulmck@...ux.vnet.ibm.com, boqun.feng@...il.com,
Waiman.Long@....com, tj@...nel.org, pablo@...filter.org,
kaber@...sh.net, davem@...emloft.net, oleg@...hat.com,
netfilter-devel@...r.kernel.org, sasha.levin@...cle.com,
hofrat@...dl.org, jejb@...isc-linux.org, rth@...ddle.net,
chris@...kel.net, dhowells@...hat.com, schwidefsky@...ibm.com,
linux@...linux.org.uk, ralf@...ux-mips.org, mpe@...erman.id.au,
vgupta@...opsys.com, rkuo@...eaurora.org, james.hogan@...tec.com,
realmz6@...il.com, tony.luck@...el.com, ysato@...rs.sourceforge.jp,
cmetcalf@...lanox.com
Subject: Re: [PATCH -v3 4/8] locking, arch: Update spin_unlock_wait()
On Wed, Jun 01, 2016 at 12:24:32PM +0100, Will Deacon wrote:
> > --- a/arch/arm/include/asm/spinlock.h
> > +++ b/arch/arm/include/asm/spinlock.h
> > @@ -50,8 +50,22 @@ static inline void dsb_sev(void)
> > * memory.
> > */
> >
> > -#define arch_spin_unlock_wait(lock) \
> > - do { while (arch_spin_is_locked(lock)) cpu_relax(); } while (0)
> > +static inline void arch_spin_unlock_wait(arch_spinlock_t *lock)
> > +{
> > + u16 owner = READ_ONCE(lock->tickets.owner);
> > +
> > + smp_rmb();
>
> (so you can remove this barrier)
*poof* in a cloud of bit smoke it goes..
> > + for (;;) {
> > + arch_spinlock_t tmp = READ_ONCE(*lock);
> > +
> > + if (tmp.tickets.owner == tmp.tickets.next ||
> > + tmp.tickets.owner != owner)
>
> This is interesting... on arm64, I actually wait until I observe the
> lock being free, but here you also break if the owner has changed, on
> the assumption that an unlock happened and we just didn't explicitly
> see the lock in a free state. Now, what stops the initial read of
> owner being speculated by the CPU at the dawn of time, and this loop
> consequently returning early because at some point (before we called
> arch_spin_unlock_wait) the lock was unlocked?
The user needs to be aware; take for instance the scenario explained
here:
lkml.kernel.org/r/20160526135406.GK3192@...ns.programming.kicks-ass.net
or the PF_EXITING spin_unlock_wait in do_exit.
In both cases we only need to wait for any in-flight critical section
that might not have observed our recent change. Any further critical
sections are guaranteed to have observed our change and will behave
accordingly.
Note that other architectures already had the wait for one ticket
completion (notably x86) semantics.
Powered by blists - more mailing lists