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/shm.c | |
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/shm.c')
-rw-r--r-- | ipc/shm.c | 56 |
1 files changed, 28 insertions, 28 deletions
@@ -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: |