Lines Matching refs:shp

64 #define shm_unlock(shp)			\  argument
65 ipc_unlock(&(shp)->shm_perm)
70 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
91 struct shmid_kernel *shp; in do_shm_rmid() local
92 shp = container_of(ipcp, struct shmid_kernel, shm_perm); in do_shm_rmid()
94 if (shp->shm_nattch) { in do_shm_rmid()
95 shp->shm_perm.mode |= SHM_DEST; in do_shm_rmid()
97 shp->shm_perm.key = IPC_PRIVATE; in do_shm_rmid()
98 shm_unlock(shp); in do_shm_rmid()
100 shm_destroy(ns, shp); in do_shm_rmid()
177 struct shmid_kernel *shp = ipc_rcu_to_struct(p); in shm_rcu_free() local
179 security_shm_free(shp); in shm_rcu_free()
194 struct shmid_kernel *shp; in __shm_open() local
196 shp = shm_lock(sfd->ns, sfd->id); in __shm_open()
198 if (IS_ERR(shp)) in __shm_open()
199 return PTR_ERR(shp); in __shm_open()
201 shp->shm_atim = get_seconds(); in __shm_open()
202 shp->shm_lprid = task_tgid_vnr(current); in __shm_open()
203 shp->shm_nattch++; in __shm_open()
204 shm_unlock(shp); in __shm_open()
228 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp) in shm_destroy() argument
232 shm_file = shp->shm_file; in shm_destroy()
233 shp->shm_file = NULL; in shm_destroy()
234 ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT; in shm_destroy()
235 shm_rmid(ns, shp); in shm_destroy()
236 shm_unlock(shp); in shm_destroy()
238 shmem_lock(shm_file, 0, shp->mlock_user); in shm_destroy()
239 else if (shp->mlock_user) in shm_destroy()
241 shp->mlock_user); in shm_destroy()
243 ipc_rcu_putref(shp, shm_rcu_free); in shm_destroy()
256 static bool shm_may_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp) in shm_may_destroy() argument
258 return (shp->shm_nattch == 0) && in shm_may_destroy()
260 (shp->shm_perm.mode & SHM_DEST)); in shm_may_destroy()
273 struct shmid_kernel *shp; in shm_close() local
278 shp = shm_lock(ns, sfd->id); in shm_close()
284 if (WARN_ON_ONCE(IS_ERR(shp))) in shm_close()
287 shp->shm_lprid = task_tgid_vnr(current); in shm_close()
288 shp->shm_dtim = get_seconds(); in shm_close()
289 shp->shm_nattch--; in shm_close()
290 if (shm_may_destroy(ns, shp)) in shm_close()
291 shm_destroy(ns, shp); in shm_close()
293 shm_unlock(shp); in shm_close()
303 struct shmid_kernel *shp = container_of(ipcp, struct shmid_kernel, shm_perm); in shm_try_destroy_orphaned() local
311 if (shp->shm_creator != NULL) in shm_try_destroy_orphaned()
314 if (shm_may_destroy(ns, shp)) { in shm_try_destroy_orphaned()
315 shm_lock_by_ptr(shp); in shm_try_destroy_orphaned()
316 shm_destroy(ns, shp); in shm_try_destroy_orphaned()
333 struct shmid_kernel *shp, *n; in exit_shm() local
345 list_for_each_entry(shp, &task->sysvshm.shm_clist, shm_clist) in exit_shm()
346 shp->shm_creator = NULL; in exit_shm()
362 list_for_each_entry_safe(shp, n, &task->sysvshm.shm_clist, shm_clist) { in exit_shm()
363 shp->shm_creator = NULL; in exit_shm()
365 if (shm_may_destroy(ns, shp)) { in exit_shm()
366 shm_lock_by_ptr(shp); in exit_shm()
367 shm_destroy(ns, shp); in exit_shm()
523 struct shmid_kernel *shp; in newseg() local
540 shp = ipc_rcu_alloc(sizeof(*shp)); in newseg()
541 if (!shp) in newseg()
544 shp->shm_perm.key = key; in newseg()
545 shp->shm_perm.mode = (shmflg & S_IRWXUGO); in newseg()
546 shp->mlock_user = NULL; in newseg()
548 shp->shm_perm.security = NULL; in newseg()
549 error = security_shm_alloc(shp); in newseg()
551 ipc_rcu_putref(shp, ipc_rcu_free); in newseg()
571 &shp->mlock_user, HUGETLB_SHMFS_INODE, in newseg()
587 shp->shm_cprid = task_tgid_vnr(current); in newseg()
588 shp->shm_lprid = 0; in newseg()
589 shp->shm_atim = shp->shm_dtim = 0; in newseg()
590 shp->shm_ctim = get_seconds(); in newseg()
591 shp->shm_segsz = size; in newseg()
592 shp->shm_nattch = 0; in newseg()
593 shp->shm_file = file; in newseg()
594 shp->shm_creator = current; in newseg()
596 id = ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni); in newseg()
602 list_add(&shp->shm_clist, &current->sysvshm.shm_clist); in newseg()
608 file_inode(file)->i_ino = shp->shm_perm.id; in newseg()
611 error = shp->shm_perm.id; in newseg()
613 ipc_unlock_object(&shp->shm_perm); in newseg()
618 if (is_file_hugepages(file) && shp->mlock_user) in newseg()
619 user_shm_unlock(size, shp->mlock_user); in newseg()
622 ipc_rcu_putref(shp, shm_rcu_free); in newseg()
631 struct shmid_kernel *shp; in shm_security() local
633 shp = container_of(ipcp, struct shmid_kernel, shm_perm); in shm_security()
634 return security_shm_associate(shp, shmflg); in shm_security()
643 struct shmid_kernel *shp; in shm_more_checks() local
645 shp = container_of(ipcp, struct shmid_kernel, shm_perm); in shm_more_checks()
646 if (shp->shm_segsz < params->u.size) in shm_more_checks()
753 static void shm_add_rss_swap(struct shmid_kernel *shp, in shm_add_rss_swap() argument
758 inode = file_inode(shp->shm_file); in shm_add_rss_swap()
760 if (is_file_hugepages(shp->shm_file)) { in shm_add_rss_swap()
762 struct hstate *h = hstate_file(shp->shm_file); in shm_add_rss_swap()
793 struct shmid_kernel *shp; in shm_get_stat() local
798 shp = container_of(ipc, struct shmid_kernel, shm_perm); in shm_get_stat()
800 shm_add_rss_swap(shp, rss, swp); in shm_get_stat()
816 struct shmid_kernel *shp; in shmctl_down() local
834 shp = container_of(ipcp, struct shmid_kernel, shm_perm); in shmctl_down()
836 err = security_shm_shmctl(shp, cmd); in shmctl_down()
842 ipc_lock_object(&shp->shm_perm); in shmctl_down()
847 ipc_lock_object(&shp->shm_perm); in shmctl_down()
851 shp->shm_ctim = get_seconds(); in shmctl_down()
859 ipc_unlock_object(&shp->shm_perm); in shmctl_down()
871 struct shmid_kernel *shp; in shmctl_nolock() local
931 shp = shm_obtain_object(ns, shmid); in shmctl_nolock()
932 if (IS_ERR(shp)) { in shmctl_nolock()
933 err = PTR_ERR(shp); in shmctl_nolock()
936 result = shp->shm_perm.id; in shmctl_nolock()
938 shp = shm_obtain_object_check(ns, shmid); in shmctl_nolock()
939 if (IS_ERR(shp)) { in shmctl_nolock()
940 err = PTR_ERR(shp); in shmctl_nolock()
947 if (ipcperms(ns, &shp->shm_perm, S_IRUGO)) in shmctl_nolock()
950 err = security_shm_shmctl(shp, cmd); in shmctl_nolock()
955 kernel_to_ipc64_perm(&shp->shm_perm, &tbuf.shm_perm); in shmctl_nolock()
956 tbuf.shm_segsz = shp->shm_segsz; in shmctl_nolock()
957 tbuf.shm_atime = shp->shm_atim; in shmctl_nolock()
958 tbuf.shm_dtime = shp->shm_dtim; in shmctl_nolock()
959 tbuf.shm_ctime = shp->shm_ctim; in shmctl_nolock()
960 tbuf.shm_cpid = shp->shm_cprid; in shmctl_nolock()
961 tbuf.shm_lpid = shp->shm_lprid; in shmctl_nolock()
962 tbuf.shm_nattch = shp->shm_nattch; in shmctl_nolock()
983 struct shmid_kernel *shp; in SYSCALL_DEFINE3() local
1008 shp = shm_obtain_object_check(ns, shmid); in SYSCALL_DEFINE3()
1009 if (IS_ERR(shp)) { in SYSCALL_DEFINE3()
1010 err = PTR_ERR(shp); in SYSCALL_DEFINE3()
1014 audit_ipc_obj(&(shp->shm_perm)); in SYSCALL_DEFINE3()
1015 err = security_shm_shmctl(shp, cmd); in SYSCALL_DEFINE3()
1019 ipc_lock_object(&shp->shm_perm); in SYSCALL_DEFINE3()
1022 if (!ipc_valid_object(&shp->shm_perm)) { in SYSCALL_DEFINE3()
1029 if (!uid_eq(euid, shp->shm_perm.uid) && in SYSCALL_DEFINE3()
1030 !uid_eq(euid, shp->shm_perm.cuid)) { in SYSCALL_DEFINE3()
1040 shm_file = shp->shm_file; in SYSCALL_DEFINE3()
1047 if (!err && !(shp->shm_perm.mode & SHM_LOCKED)) { in SYSCALL_DEFINE3()
1048 shp->shm_perm.mode |= SHM_LOCKED; in SYSCALL_DEFINE3()
1049 shp->mlock_user = user; in SYSCALL_DEFINE3()
1055 if (!(shp->shm_perm.mode & SHM_LOCKED)) in SYSCALL_DEFINE3()
1057 shmem_lock(shm_file, 0, shp->mlock_user); in SYSCALL_DEFINE3()
1058 shp->shm_perm.mode &= ~SHM_LOCKED; in SYSCALL_DEFINE3()
1059 shp->mlock_user = NULL; in SYSCALL_DEFINE3()
1061 ipc_unlock_object(&shp->shm_perm); in SYSCALL_DEFINE3()
1073 ipc_unlock_object(&shp->shm_perm); in SYSCALL_DEFINE3()
1089 struct shmid_kernel *shp; in do_shmat() local
1144 shp = shm_obtain_object_check(ns, shmid); in do_shmat()
1145 if (IS_ERR(shp)) { in do_shmat()
1146 err = PTR_ERR(shp); in do_shmat()
1151 if (ipcperms(ns, &shp->shm_perm, acc_mode)) in do_shmat()
1154 err = security_shm_shmat(shp, shmaddr, shmflg); in do_shmat()
1158 ipc_lock_object(&shp->shm_perm); in do_shmat()
1161 if (!ipc_valid_object(&shp->shm_perm)) { in do_shmat()
1162 ipc_unlock_object(&shp->shm_perm); in do_shmat()
1167 path = shp->shm_file->f_path; in do_shmat()
1169 shp->shm_nattch++; in do_shmat()
1171 ipc_unlock_object(&shp->shm_perm); in do_shmat()
1182 is_file_hugepages(shp->shm_file) ? in do_shmat()
1193 file->f_mapping = shp->shm_file->f_mapping; in do_shmat()
1194 sfd->id = shp->shm_perm.id; in do_shmat()
1196 sfd->file = shp->shm_file; in do_shmat()
1228 shp = shm_lock(ns, shmid); in do_shmat()
1229 shp->shm_nattch--; in do_shmat()
1230 if (shm_may_destroy(ns, shp)) in do_shmat()
1231 shm_destroy(ns, shp); in do_shmat()
1233 shm_unlock(shp); in do_shmat()
1368 struct shmid_kernel *shp = it; in sysvipc_shm_proc_show() local
1371 shm_add_rss_swap(shp, &rss, &swp); in sysvipc_shm_proc_show()
1383 shp->shm_perm.key, in sysvipc_shm_proc_show()
1384 shp->shm_perm.id, in sysvipc_shm_proc_show()
1385 shp->shm_perm.mode, in sysvipc_shm_proc_show()
1386 shp->shm_segsz, in sysvipc_shm_proc_show()
1387 shp->shm_cprid, in sysvipc_shm_proc_show()
1388 shp->shm_lprid, in sysvipc_shm_proc_show()
1389 shp->shm_nattch, in sysvipc_shm_proc_show()
1390 from_kuid_munged(user_ns, shp->shm_perm.uid), in sysvipc_shm_proc_show()
1391 from_kgid_munged(user_ns, shp->shm_perm.gid), in sysvipc_shm_proc_show()
1392 from_kuid_munged(user_ns, shp->shm_perm.cuid), in sysvipc_shm_proc_show()
1393 from_kgid_munged(user_ns, shp->shm_perm.cgid), in sysvipc_shm_proc_show()
1394 shp->shm_atim, in sysvipc_shm_proc_show()
1395 shp->shm_dtim, in sysvipc_shm_proc_show()
1396 shp->shm_ctim, in sysvipc_shm_proc_show()