Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1473619
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 1/4] spinlock: Document memory barrier rules |
| Date | 2016-08-31 17:50 +0200 |
| Message-ID | <scfW1-4eb-7@gated-at.bofh.it> (permalink) |
| References | (1 earlier) <sb6UO-1cS-9@gated-at.bofh.it> <sbsiC-6dl-23@gated-at.bofh.it> <sbukq-7qb-35@gated-at.bofh.it> <sbv6N-7Wm-1@gated-at.bofh.it> <sc5N0-6gr-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Wed, Aug 31, 2016 at 06:59:07AM +0200, Manfred Spraul wrote:
> The barrier must ensure that taking the spinlock (as observed by another cpu
> with spin_unlock_wait()) and a following read are ordered.
>
> start condition: sma->complex_mode = false;
>
> CPU 1:
> spin_lock(&sem->lock); /* sem_nsems instances */
> smp_mb__after_spin_lock();
> if (!smp_load_acquire(&sma->complex_mode)) {
> /* fast path successful! */
> return sops->sem_num;
> }
> /* slow path, not relevant */
>
> CPU 2: (holding sma->sem_perm.lock)
>
> smp_store_mb(sma->complex_mode, true);
>
> for (i = 0; i < sma->sem_nsems; i++) {
> spin_unlock_wait(&sma->sem_base[i].lock);
> }
>
> It must not happen that both CPUs proceed:
> Either CPU1 proceeds, then CPU2 must spin in spin_unlock_wait()
> or CPU2 proceeds, then CPU1 must enter the slow path.
>
> What about this?
> /*
> * spin_lock() provides ACQUIRE semantics regarding reading the lock.
> * There are no guarantees that the store of the lock is visible before
> * any read or write operation within the protected area is performed.
> * If the store of the lock must happen first, this function is required.
> */
> #define spin_lock_store_acquire()
So I think the fundamental problem is with our atomic_*_acquire()
primitives, where we've specified that the ACQUIRE only pertains to the
LOAD of the RmW.
The spinlock implementations suffer this problem mostly because of
that (not 100% accurate but close enough).
One solution would be to simply use smp_mb__after_atomic(). The
'problem' with that is __atomic_op_acquire() defaults to using that, so
the archs that use __atomic_op_acquire() will get a double smp_mb()
(arm64 and powerpc do not use __atomic_op_acquire()).
I'm not sure we want to introduce a new primitive for this specific to
spinlocks.
Will, any opinions?
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/4] Clarify/standardize memory barriers for lock/unlock Manfred Spraul <manfred@colorfullife.com> - 2016-08-28 14:00 +0200
[PATCH 1/4] spinlock: Document memory barrier rules Manfred Spraul <manfred@colorfullife.com> - 2016-08-28 14:00 +0200
[PATCH 2/4] barrier.h: Move smp_mb__after_unlock_lock to barrier.h Manfred Spraul <manfred@colorfullife.com> - 2016-08-28 14:00 +0200
Re: [PATCH 2/4] barrier.h: Move smp_mb__after_unlock_lock to barrier.h "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-08-28 15:50 +0200
[PATCH 2/4] barrier.h: Move smp_mb__after_unlock_lock to barrier.h Manfred Spraul <manfred@colorfullife.com> - 2016-08-28 18:40 +0200
Re: [PATCH 2/4] barrier.h: Move smp_mb__after_unlock_lock to barrier.h Manfred Spraul <manfred@colorfullife.com> - 2016-08-28 20:10 +0200
Re: [PATCH 1/4] spinlock: Document memory barrier rules Peter Zijlstra <peterz@infradead.org> - 2016-08-29 12:50 +0200
Re: [PATCH 1/4] spinlock: Document memory barrier rules Manfred Spraul <manfred@colorfullife.com> - 2016-08-29 15:00 +0200
Re: [PATCH 1/4] spinlock: Document memory barrier rules Peter Zijlstra <peterz@infradead.org> - 2016-08-29 15:50 +0200
Re: [PATCH 1/4] spinlock: Document memory barrier rules Manfred Spraul <manfred@colorfullife.com> - 2016-08-31 07:00 +0200
Re: [PATCH 1/4] spinlock: Document memory barrier rules Peter Zijlstra <peterz@infradead.org> - 2016-08-31 17:50 +0200
Re: [PATCH 1/4] spinlock: Document memory barrier rules Will Deacon <will.deacon@arm.com> - 2016-08-31 18:50 +0200
Re: [PATCH 1/4] spinlock: Document memory barrier rules Manfred Spraul <manfred@colorfullife.com> - 2016-08-31 20:40 +0200
Re: [PATCH 1/4] spinlock: Document memory barrier rules Peter Zijlstra <peterz@infradead.org> - 2016-09-01 10:50 +0200
Re: [PATCH 1/4] spinlock: Document memory barrier rules Manfred Spraul <manfred@colorfullife.com> - 2016-09-01 13:10 +0200
Re: [PATCH 1/4] spinlock: Document memory barrier rules Will Deacon <will.deacon@arm.com> - 2016-09-01 13:20 +0200
Re: [PATCH 1/4] spinlock: Document memory barrier rules Peter Zijlstra <peterz@infradead.org> - 2016-09-01 14:00 +0200
Re: [PATCH 1/4] spinlock: Document memory barrier rules Boqun Feng <boqun.feng@gmail.com> - 2016-09-01 16:10 +0200
Re: [PATCH 0/4] Clarify/standardize memory barriers for lock/unlock Peter Zijlstra <peterz@infradead.org> - 2016-08-29 13:00 +0200
csiph-web