Re: [PATCH -next] ipc/sem: prevent queue.status tearing in semop

From: Davidlohr Bueso
Date: Mon Jul 30 2018 - 18:08:45 EST


On Wed, 18 Jul 2018, Manfred Spraul wrote:

sma->use_global_lock is sometimes used with smp_load_acquire(), sometimes without.
So far, I assumed that this is safe.

The same applies for nf_conntrack_locks_all, in nf_conntrack_all_lock()

So the netfilter code is safe wrt tearing as _all_ accesses are done with
barriers and/or under spinlock.

However, this isn't always the case for sma->use_global_lock, albeit harmless.

- sem_lock(): It doesn't matter if we get the first check right as we
end up rechecking with locks held.

/*
* Initial check for use_global_lock. Just an optimization,
* no locking, no memory barrier.
*/
if (!sma->use_global_lock) {

- complexmode_enter/tryleave() are called under the ipc object lock, so that
is safe:

spin_lock()
complexmode_enter()
...
complexmode_tryleave()
spin_unlock()

- newary(): Init, no concurrency, of course.

So while I also like READ/WRITE_ONCE() calls in that it helps document the
code, I don't think we need/want want this. There's a comment there in the
first place.

Thanks,
Davidlohr