diff options
author | Davidlohr Bueso <davidlohr.bueso@hp.com> | 2013-09-11 17:26:24 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-09-11 18:59:42 -0400 |
commit | d9a605e40b1376eb02b067d7690580255a0df68f (patch) | |
tree | b21254f7172ae8db6faffd9b7941d579fa421478 /ipc | |
parent | c2c737a0461e61a34676bd0bd1bc1a70a1b4e396 (diff) |
ipc: rename ids->rw_mutex
Since in some situations the lock can be shared for readers, we shouldn't
be calling it a mutex, rename it to rwsem.
Signed-off-by: Davidlohr Bueso <davidlohr.bueso@hp.com>
Tested-by: Sedat Dilek <sedat.dilek@gmail.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Manfred Spraul <manfred@colorfullife.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/msg.c | 20 | ||||
-rw-r--r-- | ipc/namespace.c | 4 | ||||
-rw-r--r-- | ipc/sem.c | 24 | ||||
-rw-r--r-- | ipc/shm.c | 56 | ||||
-rw-r--r-- | ipc/util.c | 28 | ||||
-rw-r--r-- | ipc/util.h | 4 |
6 files changed, 68 insertions, 68 deletions
@@ -172,7 +172,7 @@ static inline void msg_rmid(struct ipc_namespace *ns, struct msg_queue *s) | |||
172 | * @ns: namespace | 172 | * @ns: namespace |
173 | * @params: ptr to the structure that contains the key and msgflg | 173 | * @params: ptr to the structure that contains the key and msgflg |
174 | * | 174 | * |
175 | * Called with msg_ids.rw_mutex held (writer) | 175 | * Called with msg_ids.rwsem held (writer) |
176 | */ | 176 | */ |
177 | static int newque(struct ipc_namespace *ns, struct ipc_params *params) | 177 | static int newque(struct ipc_namespace *ns, struct ipc_params *params) |
178 | { | 178 | { |
@@ -259,8 +259,8 @@ static void expunge_all(struct msg_queue *msq, int res) | |||
259 | * removes the message queue from message queue ID IDR, and cleans up all the | 259 | * removes the message queue from message queue ID IDR, and cleans up all the |
260 | * messages associated with this queue. | 260 | * messages associated with this queue. |
261 | * | 261 | * |
262 | * msg_ids.rw_mutex (writer) and the spinlock for this message queue are held | 262 | * msg_ids.rwsem (writer) and the spinlock for this message queue are held |
263 | * before freeque() is called. msg_ids.rw_mutex remains locked on exit. | 263 | * before freeque() is called. msg_ids.rwsem remains locked on exit. |
264 | */ | 264 | */ |
265 | static void freeque(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp) | 265 | static void freeque(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp) |
266 | { | 266 | { |
@@ -282,7 +282,7 @@ static void freeque(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp) | |||
282 | } | 282 | } |
283 | 283 | ||
284 | /* | 284 | /* |
285 | * Called with msg_ids.rw_mutex and ipcp locked. | 285 | * Called with msg_ids.rwsem and ipcp locked. |
286 | */ | 286 | */ |
287 | static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg) | 287 | static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg) |
288 | { | 288 | { |
@@ -386,9 +386,9 @@ copy_msqid_from_user(struct msqid64_ds *out, void __user *buf, int version) | |||
386 | } | 386 | } |
387 | 387 | ||
388 | /* | 388 | /* |
389 | * This function handles some msgctl commands which require the rw_mutex | 389 | * This function handles some msgctl commands which require the rwsem |
390 | * to be held in write mode. | 390 | * to be held in write mode. |
391 | * NOTE: no locks must be held, the rw_mutex is taken inside this function. | 391 | * NOTE: no locks must be held, the rwsem is taken inside this function. |
392 | */ | 392 | */ |
393 | static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd, | 393 | static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd, |
394 | struct msqid_ds __user *buf, int version) | 394 | struct msqid_ds __user *buf, int version) |
@@ -403,7 +403,7 @@ static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd, | |||
403 | return -EFAULT; | 403 | return -EFAULT; |
404 | } | 404 | } |
405 | 405 | ||
406 | down_write(&msg_ids(ns).rw_mutex); | 406 | down_write(&msg_ids(ns).rwsem); |
407 | rcu_read_lock(); | 407 | rcu_read_lock(); |
408 | 408 | ||
409 | ipcp = ipcctl_pre_down_nolock(ns, &msg_ids(ns), msqid, cmd, | 409 | ipcp = ipcctl_pre_down_nolock(ns, &msg_ids(ns), msqid, cmd, |
@@ -459,7 +459,7 @@ out_unlock0: | |||
459 | out_unlock1: | 459 | out_unlock1: |
460 | rcu_read_unlock(); | 460 | rcu_read_unlock(); |
461 | out_up: | 461 | out_up: |
462 | up_write(&msg_ids(ns).rw_mutex); | 462 | up_write(&msg_ids(ns).rwsem); |
463 | return err; | 463 | return err; |
464 | } | 464 | } |
465 | 465 | ||
@@ -494,7 +494,7 @@ static int msgctl_nolock(struct ipc_namespace *ns, int msqid, | |||
494 | msginfo.msgmnb = ns->msg_ctlmnb; | 494 | msginfo.msgmnb = ns->msg_ctlmnb; |
495 | msginfo.msgssz = MSGSSZ; | 495 | msginfo.msgssz = MSGSSZ; |
496 | msginfo.msgseg = MSGSEG; | 496 | msginfo.msgseg = MSGSEG; |
497 | down_read(&msg_ids(ns).rw_mutex); | 497 | down_read(&msg_ids(ns).rwsem); |
498 | if (cmd == MSG_INFO) { | 498 | if (cmd == MSG_INFO) { |
499 | msginfo.msgpool = msg_ids(ns).in_use; | 499 | msginfo.msgpool = msg_ids(ns).in_use; |
500 | msginfo.msgmap = atomic_read(&ns->msg_hdrs); | 500 | msginfo.msgmap = atomic_read(&ns->msg_hdrs); |
@@ -505,7 +505,7 @@ static int msgctl_nolock(struct ipc_namespace *ns, int msqid, | |||
505 | msginfo.msgtql = MSGTQL; | 505 | msginfo.msgtql = MSGTQL; |
506 | } | 506 | } |
507 | max_id = ipc_get_maxid(&msg_ids(ns)); | 507 | max_id = ipc_get_maxid(&msg_ids(ns)); |
508 | up_read(&msg_ids(ns).rw_mutex); | 508 | up_read(&msg_ids(ns).rwsem); |
509 | if (copy_to_user(buf, &msginfo, sizeof(struct msginfo))) | 509 | if (copy_to_user(buf, &msginfo, sizeof(struct msginfo))) |
510 | return -EFAULT; | 510 | return -EFAULT; |
511 | return (max_id < 0) ? 0 : max_id; | 511 | return (max_id < 0) ? 0 : max_id; |
diff --git a/ipc/namespace.c b/ipc/namespace.c index 4be6581d3b7f..d43d9384bb2d 100644 --- a/ipc/namespace.c +++ b/ipc/namespace.c | |||
@@ -81,7 +81,7 @@ void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids, | |||
81 | int next_id; | 81 | int next_id; |
82 | int total, in_use; | 82 | int total, in_use; |
83 | 83 | ||
84 | down_write(&ids->rw_mutex); | 84 | down_write(&ids->rwsem); |
85 | 85 | ||
86 | in_use = ids->in_use; | 86 | in_use = ids->in_use; |
87 | 87 | ||
@@ -93,7 +93,7 @@ void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids, | |||
93 | free(ns, perm); | 93 | free(ns, perm); |
94 | total++; | 94 | total++; |
95 | } | 95 | } |
96 | up_write(&ids->rw_mutex); | 96 | up_write(&ids->rwsem); |
97 | } | 97 | } |
98 | 98 | ||
99 | static void free_ipc_ns(struct ipc_namespace *ns) | 99 | static void free_ipc_ns(struct ipc_namespace *ns) |
@@ -322,7 +322,7 @@ static inline void sem_unlock(struct sem_array *sma, int locknum) | |||
322 | } | 322 | } |
323 | 323 | ||
324 | /* | 324 | /* |
325 | * sem_lock_(check_) routines are called in the paths where the rw_mutex | 325 | * sem_lock_(check_) routines are called in the paths where the rwsem |
326 | * is not held. | 326 | * is not held. |
327 | * | 327 | * |
328 | * The caller holds the RCU read lock. | 328 | * The caller holds the RCU read lock. |
@@ -426,7 +426,7 @@ static inline void sem_rmid(struct ipc_namespace *ns, struct sem_array *s) | |||
426 | * @ns: namespace | 426 | * @ns: namespace |
427 | * @params: ptr to the structure that contains key, semflg and nsems | 427 | * @params: ptr to the structure that contains key, semflg and nsems |
428 | * | 428 | * |
429 | * Called with sem_ids.rw_mutex held (as a writer) | 429 | * Called with sem_ids.rwsem held (as a writer) |
430 | */ | 430 | */ |
431 | 431 | ||
432 | static int newary(struct ipc_namespace *ns, struct ipc_params *params) | 432 | static int newary(struct ipc_namespace *ns, struct ipc_params *params) |
@@ -492,7 +492,7 @@ static int newary(struct ipc_namespace *ns, struct ipc_params *params) | |||
492 | 492 | ||
493 | 493 | ||
494 | /* | 494 | /* |
495 | * Called with sem_ids.rw_mutex and ipcp locked. | 495 | * Called with sem_ids.rwsem and ipcp locked. |
496 | */ | 496 | */ |
497 | static inline int sem_security(struct kern_ipc_perm *ipcp, int semflg) | 497 | static inline int sem_security(struct kern_ipc_perm *ipcp, int semflg) |
498 | { | 498 | { |
@@ -503,7 +503,7 @@ static inline int sem_security(struct kern_ipc_perm *ipcp, int semflg) | |||
503 | } | 503 | } |
504 | 504 | ||
505 | /* | 505 | /* |
506 | * Called with sem_ids.rw_mutex and ipcp locked. | 506 | * Called with sem_ids.rwsem and ipcp locked. |
507 | */ | 507 | */ |
508 | static inline int sem_more_checks(struct kern_ipc_perm *ipcp, | 508 | static inline int sem_more_checks(struct kern_ipc_perm *ipcp, |
509 | struct ipc_params *params) | 509 | struct ipc_params *params) |
@@ -994,8 +994,8 @@ static int count_semzcnt (struct sem_array * sma, ushort semnum) | |||
994 | return semzcnt; | 994 | return semzcnt; |
995 | } | 995 | } |
996 | 996 | ||
997 | /* Free a semaphore set. freeary() is called with sem_ids.rw_mutex locked | 997 | /* Free a semaphore set. freeary() is called with sem_ids.rwsem locked |
998 | * as a writer and the spinlock for this semaphore set hold. sem_ids.rw_mutex | 998 | * as a writer and the spinlock for this semaphore set hold. sem_ids.rwsem |
999 | * remains locked on exit. | 999 | * remains locked on exit. |
1000 | */ | 1000 | */ |
1001 | static void freeary(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp) | 1001 | static void freeary(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp) |
@@ -1116,7 +1116,7 @@ static int semctl_nolock(struct ipc_namespace *ns, int semid, | |||
1116 | seminfo.semmnu = SEMMNU; | 1116 | seminfo.semmnu = SEMMNU; |
1117 | seminfo.semmap = SEMMAP; | 1117 | seminfo.semmap = SEMMAP; |
1118 | seminfo.semume = SEMUME; | 1118 | seminfo.semume = SEMUME; |
1119 | down_read(&sem_ids(ns).rw_mutex); | 1119 | down_read(&sem_ids(ns).rwsem); |
1120 | if (cmd == SEM_INFO) { | 1120 | if (cmd == SEM_INFO) { |
1121 | seminfo.semusz = sem_ids(ns).in_use; | 1121 | seminfo.semusz = sem_ids(ns).in_use; |
1122 | seminfo.semaem = ns->used_sems; | 1122 | seminfo.semaem = ns->used_sems; |
@@ -1125,7 +1125,7 @@ static int semctl_nolock(struct ipc_namespace *ns, int semid, | |||
1125 | seminfo.semaem = SEMAEM; | 1125 | seminfo.semaem = SEMAEM; |
1126 | } | 1126 | } |
1127 | max_id = ipc_get_maxid(&sem_ids(ns)); | 1127 | max_id = ipc_get_maxid(&sem_ids(ns)); |
1128 | up_read(&sem_ids(ns).rw_mutex); | 1128 | up_read(&sem_ids(ns).rwsem); |
1129 | if (copy_to_user(p, &seminfo, sizeof(struct seminfo))) | 1129 | if (copy_to_user(p, &seminfo, sizeof(struct seminfo))) |
1130 | return -EFAULT; | 1130 | return -EFAULT; |
1131 | return (max_id < 0) ? 0: max_id; | 1131 | return (max_id < 0) ? 0: max_id; |
@@ -1431,9 +1431,9 @@ copy_semid_from_user(struct semid64_ds *out, void __user *buf, int version) | |||
1431 | } | 1431 | } |
1432 | 1432 | ||
1433 | /* | 1433 | /* |
1434 | * This function handles some semctl commands which require the rw_mutex | 1434 | * This function handles some semctl commands which require the rwsem |
1435 | * to be held in write mode. | 1435 | * to be held in write mode. |
1436 | * NOTE: no locks must be held, the rw_mutex is taken inside this function. | 1436 | * NOTE: no locks must be held, the rwsem is taken inside this function. |
1437 | */ | 1437 | */ |
1438 | static int semctl_down(struct ipc_namespace *ns, int semid, | 1438 | static int semctl_down(struct ipc_namespace *ns, int semid, |
1439 | int cmd, int version, void __user *p) | 1439 | int cmd, int version, void __user *p) |
@@ -1448,7 +1448,7 @@ static int semctl_down(struct ipc_namespace *ns, int semid, | |||
1448 | return -EFAULT; | 1448 | return -EFAULT; |
1449 | } | 1449 | } |
1450 | 1450 | ||
1451 | down_write(&sem_ids(ns).rw_mutex); | 1451 | down_write(&sem_ids(ns).rwsem); |
1452 | rcu_read_lock(); | 1452 | rcu_read_lock(); |
1453 | 1453 | ||
1454 | ipcp = ipcctl_pre_down_nolock(ns, &sem_ids(ns), semid, cmd, | 1454 | ipcp = ipcctl_pre_down_nolock(ns, &sem_ids(ns), semid, cmd, |
@@ -1487,7 +1487,7 @@ out_unlock0: | |||
1487 | out_unlock1: | 1487 | out_unlock1: |
1488 | rcu_read_unlock(); | 1488 | rcu_read_unlock(); |
1489 | out_up: | 1489 | out_up: |
1490 | up_write(&sem_ids(ns).rw_mutex); | 1490 | up_write(&sem_ids(ns).rwsem); |
1491 | return err; | 1491 | return err; |
1492 | } | 1492 | } |
1493 | 1493 | ||
@@ -83,8 +83,8 @@ void shm_init_ns(struct ipc_namespace *ns) | |||
83 | } | 83 | } |
84 | 84 | ||
85 | /* | 85 | /* |
86 | * Called with shm_ids.rw_mutex (writer) and the shp structure locked. | 86 | * Called with shm_ids.rwsem (writer) and the shp structure locked. |
87 | * Only shm_ids.rw_mutex remains locked on exit. | 87 | * Only shm_ids.rwsem remains locked on exit. |
88 | */ | 88 | */ |
89 | static void do_shm_rmid(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp) | 89 | static void do_shm_rmid(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp) |
90 | { | 90 | { |
@@ -148,7 +148,7 @@ static inline struct shmid_kernel *shm_obtain_object_check(struct ipc_namespace | |||
148 | } | 148 | } |
149 | 149 | ||
150 | /* | 150 | /* |
151 | * shm_lock_(check_) routines are called in the paths where the rw_mutex | 151 | * shm_lock_(check_) routines are called in the paths where the rwsem |
152 | * is not necessarily held. | 152 | * is not necessarily held. |
153 | */ | 153 | */ |
154 | static inline struct shmid_kernel *shm_lock(struct ipc_namespace *ns, int id) | 154 | static inline struct shmid_kernel *shm_lock(struct ipc_namespace *ns, int id) |
@@ -205,7 +205,7 @@ static void shm_open(struct vm_area_struct *vma) | |||
205 | * @ns: namespace | 205 | * @ns: namespace |
206 | * @shp: struct to free | 206 | * @shp: struct to free |
207 | * | 207 | * |
208 | * It has to be called with shp and shm_ids.rw_mutex (writer) locked, | 208 | * It has to be called with shp and shm_ids.rwsem (writer) locked, |
209 | * but returns with shp unlocked and freed. | 209 | * but returns with shp unlocked and freed. |
210 | */ | 210 | */ |
211 | static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp) | 211 | static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp) |
@@ -253,7 +253,7 @@ static void shm_close(struct vm_area_struct *vma) | |||
253 | struct shmid_kernel *shp; | 253 | struct shmid_kernel *shp; |
254 | struct ipc_namespace *ns = sfd->ns; | 254 | struct ipc_namespace *ns = sfd->ns; |
255 | 255 | ||
256 | down_write(&shm_ids(ns).rw_mutex); | 256 | down_write(&shm_ids(ns).rwsem); |
257 | /* remove from the list of attaches of the shm segment */ | 257 | /* remove from the list of attaches of the shm segment */ |
258 | shp = shm_lock(ns, sfd->id); | 258 | shp = shm_lock(ns, sfd->id); |
259 | BUG_ON(IS_ERR(shp)); | 259 | BUG_ON(IS_ERR(shp)); |
@@ -264,10 +264,10 @@ static void shm_close(struct vm_area_struct *vma) | |||
264 | shm_destroy(ns, shp); | 264 | shm_destroy(ns, shp); |
265 | else | 265 | else |
266 | shm_unlock(shp); | 266 | shm_unlock(shp); |
267 | up_write(&shm_ids(ns).rw_mutex); | 267 | up_write(&shm_ids(ns).rwsem); |
268 | } | 268 | } |
269 | 269 | ||
270 | /* Called with ns->shm_ids(ns).rw_mutex locked */ | 270 | /* Called with ns->shm_ids(ns).rwsem locked */ |
271 | static int shm_try_destroy_current(int id, void *p, void *data) | 271 | static int shm_try_destroy_current(int id, void *p, void *data) |
272 | { | 272 | { |
273 | struct ipc_namespace *ns = data; | 273 | struct ipc_namespace *ns = data; |
@@ -298,7 +298,7 @@ static int shm_try_destroy_current(int id, void *p, void *data) | |||
298 | return 0; | 298 | return 0; |
299 | } | 299 | } |
300 | 300 | ||
301 | /* Called with ns->shm_ids(ns).rw_mutex locked */ | 301 | /* Called with ns->shm_ids(ns).rwsem locked */ |
302 | static int shm_try_destroy_orphaned(int id, void *p, void *data) | 302 | static int shm_try_destroy_orphaned(int id, void *p, void *data) |
303 | { | 303 | { |
304 | struct ipc_namespace *ns = data; | 304 | struct ipc_namespace *ns = data; |
@@ -309,7 +309,7 @@ static int shm_try_destroy_orphaned(int id, void *p, void *data) | |||
309 | * We want to destroy segments without users and with already | 309 | * We want to destroy segments without users and with already |
310 | * exit'ed originating process. | 310 | * exit'ed originating process. |
311 | * | 311 | * |
312 | * As shp->* are changed under rw_mutex, it's safe to skip shp locking. | 312 | * As shp->* are changed under rwsem, it's safe to skip shp locking. |
313 | */ | 313 | */ |
314 | if (shp->shm_creator != NULL) | 314 | if (shp->shm_creator != NULL) |
315 | return 0; | 315 | return 0; |
@@ -323,10 +323,10 @@ static int shm_try_destroy_orphaned(int id, void *p, void *data) | |||
323 | 323 | ||
324 | void shm_destroy_orphaned(struct ipc_namespace *ns) | 324 | void shm_destroy_orphaned(struct ipc_namespace *ns) |
325 | { | 325 | { |
326 | down_write(&shm_ids(ns).rw_mutex); | 326 | down_write(&shm_ids(ns).rwsem); |
327 | if (shm_ids(ns).in_use) | 327 | if (shm_ids(ns).in_use) |
328 | idr_for_each(&shm_ids(ns).ipcs_idr, &shm_try_destroy_orphaned, ns); | 328 | idr_for_each(&shm_ids(ns).ipcs_idr, &shm_try_destroy_orphaned, ns); |
329 | up_write(&shm_ids(ns).rw_mutex); | 329 | up_write(&shm_ids(ns).rwsem); |
330 | } | 330 | } |
331 | 331 | ||
332 | 332 | ||
@@ -338,10 +338,10 @@ void exit_shm(struct task_struct *task) | |||
338 | return; | 338 | return; |
339 | 339 | ||
340 | /* Destroy all already created segments, but not mapped yet */ | 340 | /* Destroy all already created segments, but not mapped yet */ |
341 | down_write(&shm_ids(ns).rw_mutex); | 341 | down_write(&shm_ids(ns).rwsem); |
342 | if (shm_ids(ns).in_use) | 342 | if (shm_ids(ns).in_use) |
343 | idr_for_each(&shm_ids(ns).ipcs_idr, &shm_try_destroy_current, ns); | 343 | idr_for_each(&shm_ids(ns).ipcs_idr, &shm_try_destroy_current, ns); |
344 | up_write(&shm_ids(ns).rw_mutex); | 344 | up_write(&shm_ids(ns).rwsem); |
345 | } | 345 | } |
346 | 346 | ||
347 | static int shm_fault(struct vm_area_struct *vma, struct vm_fault *vmf) | 347 | static int shm_fault(struct vm_area_struct *vma, struct vm_fault *vmf) |
@@ -475,7 +475,7 @@ static const struct vm_operations_struct shm_vm_ops = { | |||
475 | * @ns: namespace | 475 | * @ns: namespace |
476 | * @params: ptr to the structure that contains key, size and shmflg | 476 | * @params: ptr to the structure that contains key, size and shmflg |
477 | * | 477 | * |
478 | * Called with shm_ids.rw_mutex held as a writer. | 478 | * Called with shm_ids.rwsem held as a writer. |
479 | */ | 479 | */ |
480 | 480 | ||
481 | static int newseg(struct ipc_namespace *ns, struct ipc_params *params) | 481 | static int newseg(struct ipc_namespace *ns, struct ipc_params *params) |
@@ -583,7 +583,7 @@ no_file: | |||
583 | } | 583 | } |
584 | 584 | ||
585 | /* | 585 | /* |
586 | * Called with shm_ids.rw_mutex and ipcp locked. | 586 | * Called with shm_ids.rwsem and ipcp locked. |
587 | */ | 587 | */ |
588 | static inline int shm_security(struct kern_ipc_perm *ipcp, int shmflg) | 588 | static inline int shm_security(struct kern_ipc_perm *ipcp, int shmflg) |
589 | { | 589 | { |
@@ -594,7 +594,7 @@ static inline int shm_security(struct kern_ipc_perm *ipcp, int shmflg) | |||
594 | } | 594 | } |
595 | 595 | ||
596 | /* | 596 | /* |
597 | * Called with shm_ids.rw_mutex and ipcp locked. | 597 | * Called with shm_ids.rwsem and ipcp locked. |
598 | */ | 598 | */ |
599 | static inline int shm_more_checks(struct kern_ipc_perm *ipcp, | 599 | static inline int shm_more_checks(struct kern_ipc_perm *ipcp, |
600 | struct ipc_params *params) | 600 | struct ipc_params *params) |
@@ -707,7 +707,7 @@ static inline unsigned long copy_shminfo_to_user(void __user *buf, struct shminf | |||
707 | 707 | ||
708 | /* | 708 | /* |
709 | * Calculate and add used RSS and swap pages of a shm. | 709 | * Calculate and add used RSS and swap pages of a shm. |
710 | * Called with shm_ids.rw_mutex held as a reader | 710 | * Called with shm_ids.rwsem held as a reader |
711 | */ | 711 | */ |
712 | static void shm_add_rss_swap(struct shmid_kernel *shp, | 712 | static void shm_add_rss_swap(struct shmid_kernel *shp, |
713 | unsigned long *rss_add, unsigned long *swp_add) | 713 | unsigned long *rss_add, unsigned long *swp_add) |
@@ -734,7 +734,7 @@ static void shm_add_rss_swap(struct shmid_kernel *shp, | |||
734 | } | 734 | } |
735 | 735 | ||
736 | /* | 736 | /* |
737 | * Called with shm_ids.rw_mutex held as a reader | 737 | * Called with shm_ids.rwsem held as a reader |
738 | */ | 738 | */ |
739 | static void shm_get_stat(struct ipc_namespace *ns, unsigned long *rss, | 739 | static void shm_get_stat(struct ipc_namespace *ns, unsigned long *rss, |
740 | unsigned long *swp) | 740 | unsigned long *swp) |
@@ -763,9 +763,9 @@ static void shm_get_stat(struct ipc_namespace *ns, unsigned long *rss, | |||
763 | } | 763 | } |
764 | 764 | ||
765 | /* | 765 | /* |
766 | * This function handles some shmctl commands which require the rw_mutex | 766 | * This function handles some shmctl commands which require the rwsem |
767 | * to be held in write mode. | 767 | * to be held in write mode. |
768 | * NOTE: no locks must be held, the rw_mutex is taken inside this function. | 768 | * NOTE: no locks must be held, the rwsem is taken inside this function. |
769 | */ | 769 | */ |
770 | static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd, | 770 | static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd, |
771 | struct shmid_ds __user *buf, int version) | 771 | struct shmid_ds __user *buf, int version) |
@@ -780,7 +780,7 @@ static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd, | |||
780 | return -EFAULT; | 780 | return -EFAULT; |
781 | } | 781 | } |
782 | 782 | ||
783 | down_write(&shm_ids(ns).rw_mutex); | 783 | down_write(&shm_ids(ns).rwsem); |
784 | rcu_read_lock(); | 784 | rcu_read_lock(); |
785 | 785 | ||
786 | ipcp = ipcctl_pre_down_nolock(ns, &shm_ids(ns), shmid, cmd, | 786 | ipcp = ipcctl_pre_down_nolock(ns, &shm_ids(ns), shmid, cmd, |
@@ -819,7 +819,7 @@ out_unlock0: | |||
819 | out_unlock1: | 819 | out_unlock1: |
820 | rcu_read_unlock(); | 820 | rcu_read_unlock(); |
821 | out_up: | 821 | out_up: |
822 | up_write(&shm_ids(ns).rw_mutex); | 822 | up_write(&shm_ids(ns).rwsem); |
823 | return err; | 823 | return err; |
824 | } | 824 | } |
825 | 825 | ||
@@ -850,9 +850,9 @@ static int shmctl_nolock(struct ipc_namespace *ns, int shmid, | |||
850 | if(copy_shminfo_to_user (buf, &shminfo, version)) | 850 | if(copy_shminfo_to_user (buf, &shminfo, version)) |
851 | return -EFAULT; | 851 | return -EFAULT; |
852 | 852 | ||
853 | down_read(&shm_ids(ns).rw_mutex); | 853 | down_read(&shm_ids(ns).rwsem); |
854 | err = ipc_get_maxid(&shm_ids(ns)); | 854 | err = ipc_get_maxid(&shm_ids(ns)); |
855 | up_read(&shm_ids(ns).rw_mutex); | 855 | up_read(&shm_ids(ns).rwsem); |
856 | 856 | ||
857 | if(err<0) | 857 | if(err<0) |
858 | err = 0; | 858 | err = 0; |
@@ -863,14 +863,14 @@ static int shmctl_nolock(struct ipc_namespace *ns, int shmid, | |||
863 | struct shm_info shm_info; | 863 | struct shm_info shm_info; |
864 | 864 | ||
865 | memset(&shm_info, 0, sizeof(shm_info)); | 865 | memset(&shm_info, 0, sizeof(shm_info)); |
866 | down_read(&shm_ids(ns).rw_mutex); | 866 | down_read(&shm_ids(ns).rwsem); |
867 | shm_info.used_ids = shm_ids(ns).in_use; | 867 | shm_info.used_ids = shm_ids(ns).in_use; |
868 | shm_get_stat (ns, &shm_info.shm_rss, &shm_info.shm_swp); | 868 | shm_get_stat (ns, &shm_info.shm_rss, &shm_info.shm_swp); |
869 | shm_info.shm_tot = ns->shm_tot; | 869 | shm_info.shm_tot = ns->shm_tot; |
870 | shm_info.swap_attempts = 0; | 870 | shm_info.swap_attempts = 0; |
871 | shm_info.swap_successes = 0; | 871 | shm_info.swap_successes = 0; |
872 | err = ipc_get_maxid(&shm_ids(ns)); | 872 | err = ipc_get_maxid(&shm_ids(ns)); |
873 | up_read(&shm_ids(ns).rw_mutex); | 873 | up_read(&shm_ids(ns).rwsem); |
874 | if (copy_to_user(buf, &shm_info, sizeof(shm_info))) { | 874 | if (copy_to_user(buf, &shm_info, sizeof(shm_info))) { |
875 | err = -EFAULT; | 875 | err = -EFAULT; |
876 | goto out; | 876 | goto out; |
@@ -1169,7 +1169,7 @@ out_fput: | |||
1169 | fput(file); | 1169 | fput(file); |
1170 | 1170 | ||
1171 | out_nattch: | 1171 | out_nattch: |
1172 | down_write(&shm_ids(ns).rw_mutex); | 1172 | down_write(&shm_ids(ns).rwsem); |
1173 | shp = shm_lock(ns, shmid); | 1173 | shp = shm_lock(ns, shmid); |
1174 | BUG_ON(IS_ERR(shp)); | 1174 | BUG_ON(IS_ERR(shp)); |
1175 | shp->shm_nattch--; | 1175 | shp->shm_nattch--; |
@@ -1177,7 +1177,7 @@ out_nattch: | |||
1177 | shm_destroy(ns, shp); | 1177 | shm_destroy(ns, shp); |
1178 | else | 1178 | else |
1179 | shm_unlock(shp); | 1179 | shm_unlock(shp); |
1180 | up_write(&shm_ids(ns).rw_mutex); | 1180 | up_write(&shm_ids(ns).rwsem); |
1181 | return err; | 1181 | return err; |
1182 | 1182 | ||
1183 | out_unlock: | 1183 | out_unlock: |
diff --git a/ipc/util.c b/ipc/util.c index 2c8a93b380ba..9a1d779a20e2 100644 --- a/ipc/util.c +++ b/ipc/util.c | |||
@@ -119,7 +119,7 @@ __initcall(ipc_init); | |||
119 | 119 | ||
120 | void ipc_init_ids(struct ipc_ids *ids) | 120 | void ipc_init_ids(struct ipc_ids *ids) |
121 | { | 121 | { |
122 | init_rwsem(&ids->rw_mutex); | 122 | init_rwsem(&ids->rwsem); |
123 | 123 | ||
124 | ids->in_use = 0; | 124 | ids->in_use = 0; |
125 | ids->seq = 0; | 125 | ids->seq = 0; |
@@ -174,7 +174,7 @@ void __init ipc_init_proc_interface(const char *path, const char *header, | |||
174 | * @ids: Identifier set | 174 | * @ids: Identifier set |
175 | * @key: The key to find | 175 | * @key: The key to find |
176 | * | 176 | * |
177 | * Requires ipc_ids.rw_mutex locked. | 177 | * Requires ipc_ids.rwsem locked. |
178 | * Returns the LOCKED pointer to the ipc structure if found or NULL | 178 | * Returns the LOCKED pointer to the ipc structure if found or NULL |
179 | * if not. | 179 | * if not. |
180 | * If key is found ipc points to the owning ipc structure | 180 | * If key is found ipc points to the owning ipc structure |
@@ -208,7 +208,7 @@ static struct kern_ipc_perm *ipc_findkey(struct ipc_ids *ids, key_t key) | |||
208 | * ipc_get_maxid - get the last assigned id | 208 | * ipc_get_maxid - get the last assigned id |
209 | * @ids: IPC identifier set | 209 | * @ids: IPC identifier set |
210 | * | 210 | * |
211 | * Called with ipc_ids.rw_mutex held. | 211 | * Called with ipc_ids.rwsem held. |
212 | */ | 212 | */ |
213 | 213 | ||
214 | int ipc_get_maxid(struct ipc_ids *ids) | 214 | int ipc_get_maxid(struct ipc_ids *ids) |
@@ -246,7 +246,7 @@ int ipc_get_maxid(struct ipc_ids *ids) | |||
246 | * is returned. The 'new' entry is returned in a locked state on success. | 246 | * is returned. The 'new' entry is returned in a locked state on success. |
247 | * On failure the entry is not locked and a negative err-code is returned. | 247 | * On failure the entry is not locked and a negative err-code is returned. |
248 | * | 248 | * |
249 | * Called with writer ipc_ids.rw_mutex held. | 249 | * Called with writer ipc_ids.rwsem held. |
250 | */ | 250 | */ |
251 | int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size) | 251 | int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size) |
252 | { | 252 | { |
@@ -312,9 +312,9 @@ static int ipcget_new(struct ipc_namespace *ns, struct ipc_ids *ids, | |||
312 | { | 312 | { |
313 | int err; | 313 | int err; |
314 | 314 | ||
315 | down_write(&ids->rw_mutex); | 315 | down_write(&ids->rwsem); |
316 | err = ops->getnew(ns, params); | 316 | err = ops->getnew(ns, params); |
317 | up_write(&ids->rw_mutex); | 317 | up_write(&ids->rwsem); |
318 | return err; | 318 | return err; |
319 | } | 319 | } |
320 | 320 | ||
@@ -331,7 +331,7 @@ static int ipcget_new(struct ipc_namespace *ns, struct ipc_ids *ids, | |||
331 | * | 331 | * |
332 | * On success, the IPC id is returned. | 332 | * On success, the IPC id is returned. |
333 | * | 333 | * |
334 | * It is called with ipc_ids.rw_mutex and ipcp->lock held. | 334 | * It is called with ipc_ids.rwsem and ipcp->lock held. |
335 | */ | 335 | */ |
336 | static int ipc_check_perms(struct ipc_namespace *ns, | 336 | static int ipc_check_perms(struct ipc_namespace *ns, |
337 | struct kern_ipc_perm *ipcp, | 337 | struct kern_ipc_perm *ipcp, |
@@ -376,7 +376,7 @@ static int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids, | |||
376 | * Take the lock as a writer since we are potentially going to add | 376 | * Take the lock as a writer since we are potentially going to add |
377 | * a new entry + read locks are not "upgradable" | 377 | * a new entry + read locks are not "upgradable" |
378 | */ | 378 | */ |
379 | down_write(&ids->rw_mutex); | 379 | down_write(&ids->rwsem); |
380 | ipcp = ipc_findkey(ids, params->key); | 380 | ipcp = ipc_findkey(ids, params->key); |
381 | if (ipcp == NULL) { | 381 | if (ipcp == NULL) { |
382 | /* key not used */ | 382 | /* key not used */ |
@@ -402,7 +402,7 @@ static int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids, | |||
402 | } | 402 | } |
403 | ipc_unlock(ipcp); | 403 | ipc_unlock(ipcp); |
404 | } | 404 | } |
405 | up_write(&ids->rw_mutex); | 405 | up_write(&ids->rwsem); |
406 | 406 | ||
407 | return err; | 407 | return err; |
408 | } | 408 | } |
@@ -413,7 +413,7 @@ static int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids, | |||
413 | * @ids: IPC identifier set | 413 | * @ids: IPC identifier set |
414 | * @ipcp: ipc perm structure containing the identifier to remove | 414 | * @ipcp: ipc perm structure containing the identifier to remove |
415 | * | 415 | * |
416 | * ipc_ids.rw_mutex (as a writer) and the spinlock for this ID are held | 416 | * ipc_ids.rwsem (as a writer) and the spinlock for this ID are held |
417 | * before this function is called, and remain locked on the exit. | 417 | * before this function is called, and remain locked on the exit. |
418 | */ | 418 | */ |
419 | 419 | ||
@@ -621,7 +621,7 @@ struct kern_ipc_perm *ipc_obtain_object(struct ipc_ids *ids, int id) | |||
621 | } | 621 | } |
622 | 622 | ||
623 | /** | 623 | /** |
624 | * ipc_lock - Lock an ipc structure without rw_mutex held | 624 | * ipc_lock - Lock an ipc structure without rwsem held |
625 | * @ids: IPC identifier set | 625 | * @ids: IPC identifier set |
626 | * @id: ipc id to look for | 626 | * @id: ipc id to look for |
627 | * | 627 | * |
@@ -748,7 +748,7 @@ int ipc_update_perm(struct ipc64_perm *in, struct kern_ipc_perm *out) | |||
748 | * - performs some audit and permission check, depending on the given cmd | 748 | * - performs some audit and permission check, depending on the given cmd |
749 | * - returns a pointer to the ipc object or otherwise, the corresponding error. | 749 | * - returns a pointer to the ipc object or otherwise, the corresponding error. |
750 | * | 750 | * |
751 | * Call holding the both the rw_mutex and the rcu read lock. | 751 | * Call holding the both the rwsem and the rcu read lock. |
752 | */ | 752 | */ |
753 | struct kern_ipc_perm *ipcctl_pre_down_nolock(struct ipc_namespace *ns, | 753 | struct kern_ipc_perm *ipcctl_pre_down_nolock(struct ipc_namespace *ns, |
754 | struct ipc_ids *ids, int id, int cmd, | 754 | struct ipc_ids *ids, int id, int cmd, |
@@ -868,7 +868,7 @@ static void *sysvipc_proc_start(struct seq_file *s, loff_t *pos) | |||
868 | * Take the lock - this will be released by the corresponding | 868 | * Take the lock - this will be released by the corresponding |
869 | * call to stop(). | 869 | * call to stop(). |
870 | */ | 870 | */ |
871 | down_read(&ids->rw_mutex); | 871 | down_read(&ids->rwsem); |
872 | 872 | ||
873 | /* pos < 0 is invalid */ | 873 | /* pos < 0 is invalid */ |
874 | if (*pos < 0) | 874 | if (*pos < 0) |
@@ -895,7 +895,7 @@ static void sysvipc_proc_stop(struct seq_file *s, void *it) | |||
895 | 895 | ||
896 | ids = &iter->ns->ids[iface->ids]; | 896 | ids = &iter->ns->ids[iface->ids]; |
897 | /* Release the lock we took in start() */ | 897 | /* Release the lock we took in start() */ |
898 | up_read(&ids->rw_mutex); | 898 | up_read(&ids->rwsem); |
899 | } | 899 | } |
900 | 900 | ||
901 | static int sysvipc_proc_show(struct seq_file *s, void *it) | 901 | static int sysvipc_proc_show(struct seq_file *s, void *it) |
diff --git a/ipc/util.h b/ipc/util.h index 41a6c4d26399..0a362ffca972 100644 --- a/ipc/util.h +++ b/ipc/util.h | |||
@@ -94,10 +94,10 @@ void __init ipc_init_proc_interface(const char *path, const char *header, | |||
94 | #define ipcid_to_idx(id) ((id) % SEQ_MULTIPLIER) | 94 | #define ipcid_to_idx(id) ((id) % SEQ_MULTIPLIER) |
95 | #define ipcid_to_seqx(id) ((id) / SEQ_MULTIPLIER) | 95 | #define ipcid_to_seqx(id) ((id) / SEQ_MULTIPLIER) |
96 | 96 | ||
97 | /* must be called with ids->rw_mutex acquired for writing */ | 97 | /* must be called with ids->rwsem acquired for writing */ |
98 | int ipc_addid(struct ipc_ids *, struct kern_ipc_perm *, int); | 98 | int ipc_addid(struct ipc_ids *, struct kern_ipc_perm *, int); |
99 | 99 | ||
100 | /* must be called with ids->rw_mutex acquired for reading */ | 100 | /* must be called with ids->rwsem acquired for reading */ |
101 | int ipc_get_maxid(struct ipc_ids *); | 101 | int ipc_get_maxid(struct ipc_ids *); |
102 | 102 | ||
103 | /* must be called with both locks acquired. */ | 103 | /* must be called with both locks acquired. */ |