Lines Matching refs:ns
52 struct ipc_namespace *ns; member
62 #define shm_ids(ns) ((ns)->ids[IPC_SHM_IDS]) argument
70 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
75 void shm_init_ns(struct ipc_namespace *ns) in shm_init_ns() argument
77 ns->shm_ctlmax = SHMMAX; in shm_init_ns()
78 ns->shm_ctlall = SHMALL; in shm_init_ns()
79 ns->shm_ctlmni = SHMMNI; in shm_init_ns()
80 ns->shm_rmid_forced = 0; in shm_init_ns()
81 ns->shm_tot = 0; in shm_init_ns()
82 ipc_init_ids(&shm_ids(ns)); in shm_init_ns()
89 static void do_shm_rmid(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp) in do_shm_rmid() argument
100 shm_destroy(ns, shp); in do_shm_rmid()
104 void shm_exit_ns(struct ipc_namespace *ns) in shm_exit_ns() argument
106 free_ipcs(ns, &shm_ids(ns), do_shm_rmid); in shm_exit_ns()
107 idr_destroy(&ns->ids[IPC_SHM_IDS].ipcs_idr); in shm_exit_ns()
130 static inline struct shmid_kernel *shm_obtain_object(struct ipc_namespace *ns, int id) in shm_obtain_object() argument
132 struct kern_ipc_perm *ipcp = ipc_obtain_object(&shm_ids(ns), id); in shm_obtain_object()
140 static inline struct shmid_kernel *shm_obtain_object_check(struct ipc_namespace *ns, int id) in shm_obtain_object_check() argument
142 struct kern_ipc_perm *ipcp = ipc_obtain_object_check(&shm_ids(ns), id); in shm_obtain_object_check()
154 static inline struct shmid_kernel *shm_lock(struct ipc_namespace *ns, int id) in shm_lock() argument
156 struct kern_ipc_perm *ipcp = ipc_lock(&shm_ids(ns), id); in shm_lock()
183 static inline void shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *s) in shm_rmid() argument
186 ipc_rmid(&shm_ids(ns), &s->shm_perm); in shm_rmid()
196 shp = shm_lock(sfd->ns, sfd->id); in __shm_open()
228 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp) in shm_destroy() argument
234 ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT; in shm_destroy()
235 shm_rmid(ns, shp); in shm_destroy()
256 static bool shm_may_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp) in shm_may_destroy() argument
259 (ns->shm_rmid_forced || in shm_may_destroy()
274 struct ipc_namespace *ns = sfd->ns; in shm_close() local
276 down_write(&shm_ids(ns).rwsem); in shm_close()
278 shp = shm_lock(ns, sfd->id); in shm_close()
290 if (shm_may_destroy(ns, shp)) in shm_close()
291 shm_destroy(ns, shp); in shm_close()
295 up_write(&shm_ids(ns).rwsem); in shm_close()
301 struct ipc_namespace *ns = data; in shm_try_destroy_orphaned() local
314 if (shm_may_destroy(ns, shp)) { in shm_try_destroy_orphaned()
316 shm_destroy(ns, shp); in shm_try_destroy_orphaned()
321 void shm_destroy_orphaned(struct ipc_namespace *ns) in shm_destroy_orphaned() argument
323 down_write(&shm_ids(ns).rwsem); in shm_destroy_orphaned()
324 if (shm_ids(ns).in_use) in shm_destroy_orphaned()
325 idr_for_each(&shm_ids(ns).ipcs_idr, &shm_try_destroy_orphaned, ns); in shm_destroy_orphaned()
326 up_write(&shm_ids(ns).rwsem); in shm_destroy_orphaned()
332 struct ipc_namespace *ns = task->nsproxy->ipc_ns; in exit_shm() local
343 if (!ns->shm_rmid_forced) { in exit_shm()
344 down_read(&shm_ids(ns).rwsem); in exit_shm()
352 up_read(&shm_ids(ns).rwsem); in exit_shm()
361 down_write(&shm_ids(ns).rwsem); in exit_shm()
365 if (shm_may_destroy(ns, shp)) { in exit_shm()
367 shm_destroy(ns, shp); in exit_shm()
373 up_write(&shm_ids(ns).rwsem); in exit_shm()
441 put_ipc_ns(sfd->ns); in shm_release()
517 static int newseg(struct ipc_namespace *ns, struct ipc_params *params) in newseg() argument
530 if (size < SHMMIN || size > ns->shm_ctlmax) in newseg()
536 if (ns->shm_tot + numpages < ns->shm_tot || in newseg()
537 ns->shm_tot + numpages > ns->shm_ctlall) in newseg()
596 id = ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni); in newseg()
610 ns->shm_tot += numpages; in newseg()
654 struct ipc_namespace *ns; in SYSCALL_DEFINE3() local
662 ns = current->nsproxy->ipc_ns; in SYSCALL_DEFINE3()
668 return ipcget(ns, &shm_ids(ns), &shm_ops, &shm_params); in SYSCALL_DEFINE3()
780 static void shm_get_stat(struct ipc_namespace *ns, unsigned long *rss, in shm_get_stat() argument
789 in_use = shm_ids(ns).in_use; in shm_get_stat()
795 ipc = idr_find(&shm_ids(ns).ipcs_idr, next_id); in shm_get_stat()
811 static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd, in shmctl_down() argument
824 down_write(&shm_ids(ns).rwsem); in shmctl_down()
827 ipcp = ipcctl_pre_down_nolock(ns, &shm_ids(ns), shmid, cmd, in shmctl_down()
844 do_shm_rmid(ns, ipcp); in shmctl_down()
863 up_write(&shm_ids(ns).rwsem); in shmctl_down()
867 static int shmctl_nolock(struct ipc_namespace *ns, int shmid, in shmctl_nolock() argument
886 shminfo.shmmni = shminfo.shmseg = ns->shm_ctlmni; in shmctl_nolock()
887 shminfo.shmmax = ns->shm_ctlmax; in shmctl_nolock()
888 shminfo.shmall = ns->shm_ctlall; in shmctl_nolock()
894 down_read(&shm_ids(ns).rwsem); in shmctl_nolock()
895 err = ipc_get_maxid(&shm_ids(ns)); in shmctl_nolock()
896 up_read(&shm_ids(ns).rwsem); in shmctl_nolock()
907 down_read(&shm_ids(ns).rwsem); in shmctl_nolock()
908 shm_info.used_ids = shm_ids(ns).in_use; in shmctl_nolock()
909 shm_get_stat(ns, &shm_info.shm_rss, &shm_info.shm_swp); in shmctl_nolock()
910 shm_info.shm_tot = ns->shm_tot; in shmctl_nolock()
913 err = ipc_get_maxid(&shm_ids(ns)); in shmctl_nolock()
914 up_read(&shm_ids(ns).rwsem); in shmctl_nolock()
931 shp = shm_obtain_object(ns, shmid); in shmctl_nolock()
938 shp = shm_obtain_object_check(ns, shmid); in shmctl_nolock()
947 if (ipcperms(ns, &shp->shm_perm, S_IRUGO)) in shmctl_nolock()
985 struct ipc_namespace *ns; in SYSCALL_DEFINE3() local
991 ns = current->nsproxy->ipc_ns; in SYSCALL_DEFINE3()
998 return shmctl_nolock(ns, shmid, cmd, version, buf); in SYSCALL_DEFINE3()
1001 return shmctl_down(ns, shmid, cmd, buf, version); in SYSCALL_DEFINE3()
1008 shp = shm_obtain_object_check(ns, shmid); in SYSCALL_DEFINE3()
1027 if (!ns_capable(ns->user_ns, CAP_IPC_LOCK)) { in SYSCALL_DEFINE3()
1097 struct ipc_namespace *ns; in do_shmat() local
1142 ns = current->nsproxy->ipc_ns; in do_shmat()
1144 shp = shm_obtain_object_check(ns, shmid); in do_shmat()
1151 if (ipcperms(ns, &shp->shm_perm, acc_mode)) in do_shmat()
1195 sfd->ns = get_ipc_ns(ns); in do_shmat()
1227 down_write(&shm_ids(ns).rwsem); in do_shmat()
1228 shp = shm_lock(ns, shmid); in do_shmat()
1230 if (shm_may_destroy(ns, shp)) in do_shmat()
1231 shm_destroy(ns, shp); in do_shmat()
1234 up_write(&shm_ids(ns).rwsem); in do_shmat()