From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] arm64: spinlock: serialise spin_unlock_wait against concurrent lockers
Date: Tue, 1 Dec 2015 16:32:33 +0000 [thread overview]
Message-ID: <20151201163232.GD27751@arm.com> (raw)
In-Reply-To: <20151201004017.GA1135@fixme-laptop.cn.ibm.com>
On Tue, Dec 01, 2015 at 08:40:17AM +0800, Boqun Feng wrote:
> Hi Will,
Hi Boqun,
> On Fri, Nov 27, 2015 at 11:44:06AM +0000, Will Deacon wrote:
> > Boqun Feng reported a rather nasty ordering issue with spin_unlock_wait
> > on architectures implementing spin_lock with LL/SC sequences and acquire
> > semantics:
> >
> > | CPU 1 CPU 2 CPU 3
> > | ================== ==================== ==============
> > | spin_unlock(&lock);
> > | spin_lock(&lock):
> > | r1 = *lock; // r1 == 0;
> > | o = READ_ONCE(object); // reordered here
> > | object = NULL;
> > | smp_mb();
> > | spin_unlock_wait(&lock);
> > | *lock = 1;
> > | smp_mb();
> > | o->dead = true;
> > | if (o) // true
> > | BUG_ON(o->dead); // true!!
> >
> > The crux of the problem is that spin_unlock_wait(&lock) can return on
> > CPU 1 whilst CPU 2 is in the process of taking the lock. This can be
> > resolved by upgrading spin_unlock_wait to a LOCK operation, forcing it
>
> I wonder whether upgrading it to a LOCK operation is necessary. Please
> see below.
>
> > to serialise against a concurrent locker and giving it acquire semantics
> > in the process (although it is not at all clear whether this is needed -
> > different callers seem to assume different things about the barrier
> > semantics and architectures are similarly disjoint in their
> > implementations of the macro).
> >
> > This patch implements spin_unlock_wait using an LL/SC sequence with
> > acquire semantics on arm64. For v8.1 systems with the LSE atomics, the
>
> IIUC, you implement this with acquire semantics because a LOCK requires
> acquire semantics, right? I get that spin_unlock_wait() becoming a LOCK
> will surely simply our analysis, because LOCK->LOCK is always globally
> ordered. But for this particular problem, seems only a relaxed LL/SC
> loop suffices, and the use of spin_unlock_wait() in do_exit() only
> requires a control dependency which could be fulfilled by a relaxed
> LL/SC loop. So the acquire semantics may be not necessary here.
>
> Am I missing something subtle here which is the reason you want to
> upgrading spin_unlock_wait() to a LOCK?
There's two things going on here:
(1) Having spin_unlock_wait do a complete LL/SC sequence (i.e. writing
to the lock, like a LOCK operation would)
(2) Giving it ACQUIRE semantics
(2) is not necessary to fix the problem you described. However, LOCK
operations do imply ACQUIRE and it's not clear to me that what the
ordering semantics are for spin_unlock_wait.
I'd really like to keep this as simple as possible. Introducing yet
another magic barrier macro that isn't well understood or widely used
feels like a major step backwards to me, so I opted to upgrade
spin_unlock_wait to LOCK on arm64 so that I no longer have to worry
about it.
Will
next prev parent reply other threads:[~2015-12-01 16:32 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-27 11:44 [PATCH] arm64: spinlock: serialise spin_unlock_wait against concurrent lockers Will Deacon
2015-11-30 15:58 ` Peter Zijlstra
2015-11-30 18:21 ` Paul E. McKenney
2015-12-01 16:40 ` Will Deacon
2015-12-03 0:11 ` Paul E. McKenney
2015-12-03 13:28 ` Peter Zijlstra
2015-12-03 16:32 ` Will Deacon
2015-12-03 17:22 ` Paul E. McKenney
2015-12-04 9:21 ` Peter Zijlstra
2015-12-04 16:07 ` Paul E. McKenney
2015-12-04 16:24 ` Will Deacon
2015-12-04 16:44 ` Paul E. McKenney
2015-12-06 7:37 ` Boqun Feng
2015-12-06 19:23 ` Paul E. McKenney
2015-12-06 23:28 ` Boqun Feng
2015-12-07 0:00 ` Paul E. McKenney
2015-12-07 0:45 ` Boqun Feng
2015-12-07 10:34 ` Peter Zijlstra
2015-12-07 15:45 ` Paul E. McKenney
2015-12-08 8:42 ` Boqun Feng
2015-12-08 19:17 ` Paul E. McKenney
2015-12-09 6:43 ` Boqun Feng
2015-12-04 9:36 ` Peter Zijlstra
2015-12-04 16:13 ` Paul E. McKenney
2015-12-07 2:12 ` Michael Ellerman
2015-12-06 8:16 ` Boqun Feng
2015-12-06 19:27 ` Paul E. McKenney
2015-12-07 0:26 ` Boqun Feng
2015-12-11 8:09 ` Boqun Feng
2015-12-11 9:46 ` Will Deacon
2015-12-11 12:20 ` Boqun Feng
2015-12-11 13:42 ` Paul E. McKenney
2015-12-11 13:54 ` Will Deacon
2015-12-01 0:40 ` Boqun Feng
2015-12-01 16:32 ` Will Deacon [this message]
2015-12-02 9:40 ` Boqun Feng
2015-12-02 11:16 ` Boqun Feng
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=20151201163232.GD27751@arm.com \
--to=will.deacon@arm.com \
--cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).