Commit dbfcd91f06f0e2d5564b2fd184e9c2a43675f9ab

Authored by Davidlohr Bueso
Committed by Linus Torvalds
1 parent c103a4dc4a

ipc: move rcu lock out of ipc_addid

This patchset continues the work that began in the sysv ipc semaphore
scaling series, see

  https://lkml.org/lkml/2013/3/20/546

Just like semaphores used to be, sysv shared memory and msg queues also
abuse the ipc lock, unnecessarily holding it for operations such as
permission and security checks.

This patchset mostly deals with mqueues, and while shared mem can be
done in a very similar way, I want to get these patches out in the open
first.  It also does some pending cleanups, mostly focused on the two
level locking we have in ipc code, taking care of ipc_addid() and
ipcctl_pre_down_nolock() - yes there are still functions that need to be
updated as well.

This patch:

Make all callers explicitly take and release the RCU read lock.

This addresses the two level locking seen in newary(), newseg() and
newqueue().  For the last two, explicitly unlock the ipc object and the
rcu lock, instead of calling the custom shm_unlock and msg_unlock
functions.  The next patch will deal with the open coded locking for
->perm.lock

Signed-off-by: Davidlohr Bueso <davidlohr.bueso@hp.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Rik van Riel <riel@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 3 changed files with 8 additions and 7 deletions Side-by-side Diff

... ... @@ -199,9 +199,7 @@
199 199 return retval;
200 200 }
201 201  
202   - /*
203   - * ipc_addid() locks msq
204   - */
  202 + /* ipc_addid() locks msq upon success. */
205 203 id = ipc_addid(&msg_ids(ns), &msq->q_perm, ns->msg_ctlmni);
206 204 if (id < 0) {
207 205 security_msg_queue_free(msq);
... ... @@ -218,7 +216,8 @@
218 216 INIT_LIST_HEAD(&msq->q_receivers);
219 217 INIT_LIST_HEAD(&msq->q_senders);
220 218  
221   - msg_unlock(msq);
  219 + spin_unlock(&msq->q_perm.lock);
  220 + rcu_read_unlock();
222 221  
223 222 return msq->q_perm.id;
224 223 }
... ... @@ -535,6 +535,7 @@
535 535 shp->shm_nattch = 0;
536 536 shp->shm_file = file;
537 537 shp->shm_creator = current;
  538 +
538 539 /*
539 540 * shmid gets reported as "inode#" in /proc/pid/maps.
540 541 * proc-ps tools use this. Changing this will break them.
... ... @@ -543,7 +544,9 @@
543 544  
544 545 ns->shm_tot += numpages;
545 546 error = shp->shm_perm.id;
546   - shm_unlock(shp);
  547 +
  548 + spin_unlock(&shp->shm_perm.lock);
  549 + rcu_read_unlock();
547 550 return error;
548 551  
549 552 no_id:
... ... @@ -246,9 +246,8 @@
246 246 * is returned. The 'new' entry is returned in a locked state on success.
247 247 * On failure the entry is not locked and a negative err-code is returned.
248 248 *
249   - * Called with ipc_ids.rw_mutex held as a writer.
  249 + * Called with writer ipc_ids.rw_mutex held.
250 250 */
251   -
252 251 int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
253 252 {
254 253 kuid_t euid;