]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
ipc/sem.c: change memory barrier in sem_lock() to smp_rmb()
authorManfred Spraul <manfred@colorfullife.com>
Sat, 13 Dec 2014 00:58:11 +0000 (16:58 -0800)
committerJiri Slaby <jslaby@suse.cz>
Mon, 16 Feb 2015 13:56:32 +0000 (14:56 +0100)
commitb116a0436c29bd83196d1988d75521044dc36e5d
treea278cd687932047f9f5120cf462f8895a558718e
parent23b4103455d52e2ffdc4758aea29ba6d70d246ca
ipc/sem.c: change memory barrier in sem_lock() to smp_rmb()

commit 2e094abfd1f29a08a60523b42d4508281b8dee0e upstream.

When I fixed bugs in the sem_lock() logic, I was more conservative than
necessary.  Therefore it is safe to replace the smp_mb() with smp_rmb().
And: With smp_rmb(), semop() syscalls are up to 10% faster.

The race we must protect against is:

sem->lock is free
sma->complex_count = 0
sma->sem_perm.lock held by thread B

thread A:

A: spin_lock(&sem->lock)

B: sma->complex_count++; (now 1)
B: spin_unlock(&sma->sem_perm.lock);

A: spin_is_locked(&sma->sem_perm.lock);
A: XXXXX memory barrier
A: if (sma->complex_count == 0)

Thread A must read the increased complex_count value, i.e. the read must
not be reordered with the read of sem_perm.lock done by spin_is_locked().

Since it's about ordering of reads, smp_rmb() is sufficient.

[akpm@linux-foundation.org: update sem_lock() comment, from Davidlohr]
Signed-off-by: Manfred Spraul <manfred@colorfullife.com>
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Acked-by: Rafael Aquini <aquini@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
ipc/sem.c