ipc: move rcu_read_unlock() out of sem_unlock() and into callers
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 3 May 2013 22:04:40 +0000 (15:04 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 4 May 2013 18:24:00 +0000 (11:24 -0700)
commit6d49dab8ae06c6d35a4d0967364a9ecbe8fdea2c
tree7f28ea59e2c52d912faf696d38e9577ffb1c29c3
parentce857229e0c3adc211944a13a5579ef84fd7b4af
ipc: move rcu_read_unlock() out of sem_unlock() and into callers

The IPC locking is a mess, and sem_unlock() unlocks not only the
semaphore spinlock, it also drops the rcu read lock.  Unlike sem_lock(),
which just gets the spin-lock, and expects the caller to get the rcu
read lock.

This all makes things very hard to follow, and it's very confusing when
you take the rcu read lock in one function, and then release it in
another.  And it has caused actual bugs: the sem_obtain_lock() function
ended up dropping the RCU read lock twice in one error path, because it
first did the sem_unlock(), and then did a rcu_read_unlock() to match
the rcu_read_lock() it had done.

This is just a totally mindless "remove rcu_read_unlock() from
sem_unlock() and add it immediately after each caller" (except for the
aforementioned bug where we did too many rcu_read_unlock(), and in
find_alloc_undo() where we just got the rcu_read_lock() to correct for
the fact that sem_unlock would immediately drop it again).

We can (and should) clean things up further, but this fixes the bug with
the minimal amount of subtlety.

Reviewed-by: Davidlohr Bueso <davidlohr.bueso@hp.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
ipc/sem.c