Skip to content

Commit

Permalink
ipc: move the rcu_read_lock() from sem_lock_and_putref() into callers
Browse files Browse the repository at this point in the history
This is another ipc semaphore locking cleanup, trying to make the
locking more straightforward.  We move the rcu read locking into the
callers of sem_lock_and_putref(), which in general means that we now
mostly do the rcu_read_lock() and rcu_read_unlock() in the same
function.

Mostly.  We still have the ipc_addid/newary/freeary mess, and things
like ipcctl_pre_down_nolock().

Acked-by: Davidlohr Bueso <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Al Viro <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
torvalds committed May 5, 2013
1 parent 73b2950 commit 4091fd9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ipc/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ static inline struct sem_array *sem_obtain_object_check(struct ipc_namespace *ns

static inline void sem_lock_and_putref(struct sem_array *sma)
{
rcu_read_lock();
sem_lock(sma, NULL, -1);
ipc_rcu_putref(sma);
}
Expand Down Expand Up @@ -1117,6 +1116,7 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
return -ENOMEM;
}

rcu_read_lock();
sem_lock_and_putref(sma);
if (sma->sem_perm.deleted) {
sem_unlock(sma, -1);
Expand Down Expand Up @@ -1166,6 +1166,7 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
goto out_free;
}
}
rcu_read_lock();
sem_lock_and_putref(sma);
if (sma->sem_perm.deleted) {
sem_unlock(sma, -1);
Expand Down Expand Up @@ -1451,7 +1452,7 @@ static struct sem_undo *find_alloc_undo(struct ipc_namespace *ns, int semid)
}

/* step 3: Acquire the lock on semaphore array */
/* This also does the rcu_read_lock() */
rcu_read_lock();
sem_lock_and_putref(sma);
if (sma->sem_perm.deleted) {
sem_unlock(sma, -1);
Expand Down

0 comments on commit 4091fd9

Please sign in to comment.