Lines Matching refs:shp
97 #define shm_unlock(shp) \ argument
98 ipc_unlock(&(shp)->shm_perm)
103 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
124 struct shmid_kernel *shp; in do_shm_rmid() local
126 shp = container_of(ipcp, struct shmid_kernel, shm_perm); in do_shm_rmid()
127 WARN_ON(ns != shp->ns); in do_shm_rmid()
129 if (shp->shm_nattch) { in do_shm_rmid()
130 shp->shm_perm.mode |= SHM_DEST; in do_shm_rmid()
132 ipc_set_key_private(&shm_ids(ns), &shp->shm_perm); in do_shm_rmid()
133 shm_unlock(shp); in do_shm_rmid()
135 shm_destroy(ns, shp); in do_shm_rmid()
232 struct shmid_kernel *shp = container_of(ptr, struct shmid_kernel, in shm_rcu_free() local
234 security_shm_free(&shp->shm_perm); in shm_rcu_free()
235 kvfree(shp); in shm_rcu_free()
242 static inline void shm_clist_rm(struct shmid_kernel *shp) in shm_clist_rm() argument
253 if (!list_empty(&shp->shm_clist)) { in shm_clist_rm()
258 creator = shp->shm_creator; in shm_clist_rm()
265 list_del_init(&shp->shm_clist); in shm_clist_rm()
282 struct shmid_kernel *shp; in __shm_open() local
284 shp = shm_lock(sfd->ns, sfd->id); in __shm_open()
286 if (IS_ERR(shp)) in __shm_open()
287 return PTR_ERR(shp); in __shm_open()
289 if (shp->shm_file != sfd->file) { in __shm_open()
291 shm_unlock(shp); in __shm_open()
295 shp->shm_atim = ktime_get_real_seconds(); in __shm_open()
296 ipc_update_pid(&shp->shm_lprid, task_tgid(current)); in __shm_open()
297 shp->shm_nattch++; in __shm_open()
298 shm_unlock(shp); in __shm_open()
322 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp) in shm_destroy() argument
326 shm_file = shp->shm_file; in shm_destroy()
327 shp->shm_file = NULL; in shm_destroy()
328 ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT; in shm_destroy()
329 shm_rmid(shp); in shm_destroy()
330 shm_unlock(shp); in shm_destroy()
332 shmem_lock(shm_file, 0, shp->mlock_user); in shm_destroy()
333 else if (shp->mlock_user) in shm_destroy()
335 shp->mlock_user); in shm_destroy()
337 ipc_update_pid(&shp->shm_cprid, NULL); in shm_destroy()
338 ipc_update_pid(&shp->shm_lprid, NULL); in shm_destroy()
339 ipc_rcu_putref(&shp->shm_perm, shm_rcu_free); in shm_destroy()
352 static bool shm_may_destroy(struct shmid_kernel *shp) in shm_may_destroy() argument
354 return (shp->shm_nattch == 0) && in shm_may_destroy()
355 (shp->ns->shm_rmid_forced || in shm_may_destroy()
356 (shp->shm_perm.mode & SHM_DEST)); in shm_may_destroy()
369 struct shmid_kernel *shp; in shm_close() local
374 shp = shm_lock(ns, sfd->id); in shm_close()
380 if (WARN_ON_ONCE(IS_ERR(shp))) in shm_close()
383 ipc_update_pid(&shp->shm_lprid, task_tgid(current)); in shm_close()
384 shp->shm_dtim = ktime_get_real_seconds(); in shm_close()
385 shp->shm_nattch--; in shm_close()
386 if (shm_may_destroy(shp)) in shm_close()
387 shm_destroy(ns, shp); in shm_close()
389 shm_unlock(shp); in shm_close()
399 struct shmid_kernel *shp = container_of(ipcp, struct shmid_kernel, shm_perm); in shm_try_destroy_orphaned() local
407 if (!list_empty(&shp->shm_clist)) in shm_try_destroy_orphaned()
410 if (shm_may_destroy(shp)) { in shm_try_destroy_orphaned()
411 shm_lock_by_ptr(shp); in shm_try_destroy_orphaned()
412 shm_destroy(ns, shp); in shm_try_destroy_orphaned()
429 struct shmid_kernel *shp; in exit_shm() local
439 shp = list_first_entry(&task->sysvshm.shm_clist, struct shmid_kernel, in exit_shm()
449 ns = shp->ns; in exit_shm()
467 list_del_init(&shp->shm_clist); in exit_shm()
477 WARN_ON(!ipc_rcu_getref(&shp->shm_perm)); in exit_shm()
486 list_del_init(&shp->shm_clist); in exit_shm()
495 shm_lock_by_ptr(shp); in exit_shm()
500 ipc_rcu_putref(&shp->shm_perm, shm_rcu_free); in exit_shm()
502 if (ipc_valid_object(&shp->shm_perm)) { in exit_shm()
503 if (shm_may_destroy(shp)) in exit_shm()
504 shm_destroy(ns, shp); in exit_shm()
506 shm_unlock(shp); in exit_shm()
513 shm_unlock(shp); in exit_shm()
698 struct shmid_kernel *shp; in newseg() local
714 shp = kvmalloc(sizeof(*shp), GFP_KERNEL_ACCOUNT); in newseg()
715 if (unlikely(!shp)) in newseg()
718 shp->shm_perm.key = key; in newseg()
719 shp->shm_perm.mode = (shmflg & S_IRWXUGO); in newseg()
720 shp->mlock_user = NULL; in newseg()
722 shp->shm_perm.security = NULL; in newseg()
723 error = security_shm_alloc(&shp->shm_perm); in newseg()
725 kvfree(shp); in newseg()
745 &shp->mlock_user, HUGETLB_SHMFS_INODE, in newseg()
761 shp->shm_cprid = get_pid(task_tgid(current)); in newseg()
762 shp->shm_lprid = NULL; in newseg()
763 shp->shm_atim = shp->shm_dtim = 0; in newseg()
764 shp->shm_ctim = ktime_get_real_seconds(); in newseg()
765 shp->shm_segsz = size; in newseg()
766 shp->shm_nattch = 0; in newseg()
767 shp->shm_file = file; in newseg()
768 shp->shm_creator = current; in newseg()
771 error = ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni); in newseg()
775 shp->ns = ns; in newseg()
778 list_add(&shp->shm_clist, ¤t->sysvshm.shm_clist); in newseg()
785 file_inode(file)->i_ino = shp->shm_perm.id; in newseg()
788 error = shp->shm_perm.id; in newseg()
790 ipc_unlock_object(&shp->shm_perm); in newseg()
795 ipc_update_pid(&shp->shm_cprid, NULL); in newseg()
796 ipc_update_pid(&shp->shm_lprid, NULL); in newseg()
797 if (is_file_hugepages(file) && shp->mlock_user) in newseg()
798 user_shm_unlock(size, shp->mlock_user); in newseg()
800 ipc_rcu_putref(&shp->shm_perm, shm_rcu_free); in newseg()
803 call_rcu(&shp->shm_perm.rcu, shm_rcu_free); in newseg()
812 struct shmid_kernel *shp; in shm_more_checks() local
814 shp = container_of(ipcp, struct shmid_kernel, shm_perm); in shm_more_checks()
815 if (shp->shm_segsz < params->u.size) in shm_more_checks()
927 static void shm_add_rss_swap(struct shmid_kernel *shp, in shm_add_rss_swap() argument
932 inode = file_inode(shp->shm_file); in shm_add_rss_swap()
934 if (is_file_hugepages(shp->shm_file)) { in shm_add_rss_swap()
936 struct hstate *h = hstate_file(shp->shm_file); in shm_add_rss_swap()
968 struct shmid_kernel *shp; in shm_get_stat() local
973 shp = container_of(ipc, struct shmid_kernel, shm_perm); in shm_get_stat()
975 shm_add_rss_swap(shp, rss, swp); in shm_get_stat()
990 struct shmid_kernel *shp; in shmctl_down() local
1003 shp = container_of(ipcp, struct shmid_kernel, shm_perm); in shmctl_down()
1005 err = security_shm_shmctl(&shp->shm_perm, cmd); in shmctl_down()
1011 ipc_lock_object(&shp->shm_perm); in shmctl_down()
1016 ipc_lock_object(&shp->shm_perm); in shmctl_down()
1020 shp->shm_ctim = ktime_get_real_seconds(); in shmctl_down()
1028 ipc_unlock_object(&shp->shm_perm); in shmctl_down()
1078 struct shmid_kernel *shp; in shmctl_stat() local
1085 shp = shm_obtain_object(ns, shmid); in shmctl_stat()
1086 if (IS_ERR(shp)) { in shmctl_stat()
1087 err = PTR_ERR(shp); in shmctl_stat()
1091 shp = shm_obtain_object_check(ns, shmid); in shmctl_stat()
1092 if (IS_ERR(shp)) { in shmctl_stat()
1093 err = PTR_ERR(shp); in shmctl_stat()
1106 audit_ipc_obj(&shp->shm_perm); in shmctl_stat()
1109 if (ipcperms(ns, &shp->shm_perm, S_IRUGO)) in shmctl_stat()
1113 err = security_shm_shmctl(&shp->shm_perm, cmd); in shmctl_stat()
1117 ipc_lock_object(&shp->shm_perm); in shmctl_stat()
1119 if (!ipc_valid_object(&shp->shm_perm)) { in shmctl_stat()
1120 ipc_unlock_object(&shp->shm_perm); in shmctl_stat()
1125 kernel_to_ipc64_perm(&shp->shm_perm, &tbuf->shm_perm); in shmctl_stat()
1126 tbuf->shm_segsz = shp->shm_segsz; in shmctl_stat()
1127 tbuf->shm_atime = shp->shm_atim; in shmctl_stat()
1128 tbuf->shm_dtime = shp->shm_dtim; in shmctl_stat()
1129 tbuf->shm_ctime = shp->shm_ctim; in shmctl_stat()
1131 tbuf->shm_atime_high = shp->shm_atim >> 32; in shmctl_stat()
1132 tbuf->shm_dtime_high = shp->shm_dtim >> 32; in shmctl_stat()
1133 tbuf->shm_ctime_high = shp->shm_ctim >> 32; in shmctl_stat()
1135 tbuf->shm_cpid = pid_vnr(shp->shm_cprid); in shmctl_stat()
1136 tbuf->shm_lpid = pid_vnr(shp->shm_lprid); in shmctl_stat()
1137 tbuf->shm_nattch = shp->shm_nattch; in shmctl_stat()
1150 err = shp->shm_perm.id; in shmctl_stat()
1153 ipc_unlock_object(&shp->shm_perm); in shmctl_stat()
1161 struct shmid_kernel *shp; in shmctl_do_lock() local
1166 shp = shm_obtain_object_check(ns, shmid); in shmctl_do_lock()
1167 if (IS_ERR(shp)) { in shmctl_do_lock()
1168 err = PTR_ERR(shp); in shmctl_do_lock()
1172 audit_ipc_obj(&(shp->shm_perm)); in shmctl_do_lock()
1173 err = security_shm_shmctl(&shp->shm_perm, cmd); in shmctl_do_lock()
1177 ipc_lock_object(&shp->shm_perm); in shmctl_do_lock()
1180 if (!ipc_valid_object(&shp->shm_perm)) { in shmctl_do_lock()
1188 if (!uid_eq(euid, shp->shm_perm.uid) && in shmctl_do_lock()
1189 !uid_eq(euid, shp->shm_perm.cuid)) { in shmctl_do_lock()
1199 shm_file = shp->shm_file; in shmctl_do_lock()
1207 if (!err && !(shp->shm_perm.mode & SHM_LOCKED)) { in shmctl_do_lock()
1208 shp->shm_perm.mode |= SHM_LOCKED; in shmctl_do_lock()
1209 shp->mlock_user = user; in shmctl_do_lock()
1215 if (!(shp->shm_perm.mode & SHM_LOCKED)) in shmctl_do_lock()
1217 shmem_lock(shm_file, 0, shp->mlock_user); in shmctl_do_lock()
1218 shp->shm_perm.mode &= ~SHM_LOCKED; in shmctl_do_lock()
1219 shp->mlock_user = NULL; in shmctl_do_lock()
1221 ipc_unlock_object(&shp->shm_perm); in shmctl_do_lock()
1229 ipc_unlock_object(&shp->shm_perm); in shmctl_do_lock()
1515 struct shmid_kernel *shp; in do_shmat() local
1575 shp = shm_obtain_object_check(ns, shmid); in do_shmat()
1576 if (IS_ERR(shp)) { in do_shmat()
1577 err = PTR_ERR(shp); in do_shmat()
1582 if (ipcperms(ns, &shp->shm_perm, acc_mode)) in do_shmat()
1585 err = security_shm_shmat(&shp->shm_perm, shmaddr, shmflg); in do_shmat()
1589 ipc_lock_object(&shp->shm_perm); in do_shmat()
1592 if (!ipc_valid_object(&shp->shm_perm)) { in do_shmat()
1593 ipc_unlock_object(&shp->shm_perm); in do_shmat()
1607 base = get_file(shp->shm_file); in do_shmat()
1608 shp->shm_nattch++; in do_shmat()
1610 ipc_unlock_object(&shp->shm_perm); in do_shmat()
1631 sfd->id = shp->shm_perm.id; in do_shmat()
1670 shp = shm_lock(ns, shmid); in do_shmat()
1671 shp->shm_nattch--; in do_shmat()
1673 if (shm_may_destroy(shp)) in do_shmat()
1674 shm_destroy(ns, shp); in do_shmat()
1676 shm_unlock(shp); in do_shmat()
1839 struct shmid_kernel *shp; in sysvipc_shm_proc_show() local
1842 shp = container_of(ipcp, struct shmid_kernel, shm_perm); in sysvipc_shm_proc_show()
1843 shm_add_rss_swap(shp, &rss, &swp); in sysvipc_shm_proc_show()
1855 shp->shm_perm.key, in sysvipc_shm_proc_show()
1856 shp->shm_perm.id, in sysvipc_shm_proc_show()
1857 shp->shm_perm.mode, in sysvipc_shm_proc_show()
1858 shp->shm_segsz, in sysvipc_shm_proc_show()
1859 pid_nr_ns(shp->shm_cprid, pid_ns), in sysvipc_shm_proc_show()
1860 pid_nr_ns(shp->shm_lprid, pid_ns), in sysvipc_shm_proc_show()
1861 shp->shm_nattch, in sysvipc_shm_proc_show()
1862 from_kuid_munged(user_ns, shp->shm_perm.uid), in sysvipc_shm_proc_show()
1863 from_kgid_munged(user_ns, shp->shm_perm.gid), in sysvipc_shm_proc_show()
1864 from_kuid_munged(user_ns, shp->shm_perm.cuid), in sysvipc_shm_proc_show()
1865 from_kgid_munged(user_ns, shp->shm_perm.cgid), in sysvipc_shm_proc_show()
1866 shp->shm_atim, in sysvipc_shm_proc_show()
1867 shp->shm_dtim, in sysvipc_shm_proc_show()
1868 shp->shm_ctim, in sysvipc_shm_proc_show()