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 kfree(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()
280 struct shmid_kernel *shp; in __shm_open() local
282 shp = shm_lock(sfd->ns, sfd->id); in __shm_open()
284 if (IS_ERR(shp)) in __shm_open()
285 return PTR_ERR(shp); in __shm_open()
287 if (shp->shm_file != sfd->file) { in __shm_open()
289 shm_unlock(shp); in __shm_open()
293 shp->shm_atim = ktime_get_real_seconds(); in __shm_open()
294 ipc_update_pid(&shp->shm_lprid, task_tgid(current)); in __shm_open()
295 shp->shm_nattch++; in __shm_open()
296 shm_unlock(shp); in __shm_open()
328 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp) in shm_destroy() argument
332 shm_file = shp->shm_file; in shm_destroy()
333 shp->shm_file = NULL; in shm_destroy()
334 ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT; in shm_destroy()
335 shm_rmid(shp); in shm_destroy()
336 shm_unlock(shp); in shm_destroy()
338 shmem_lock(shm_file, 0, shp->mlock_ucounts); in shm_destroy()
340 ipc_update_pid(&shp->shm_cprid, NULL); in shm_destroy()
341 ipc_update_pid(&shp->shm_lprid, NULL); in shm_destroy()
342 ipc_rcu_putref(&shp->shm_perm, shm_rcu_free); in shm_destroy()
355 static bool shm_may_destroy(struct shmid_kernel *shp) in shm_may_destroy() argument
357 return (shp->shm_nattch == 0) && in shm_may_destroy()
358 (shp->ns->shm_rmid_forced || in shm_may_destroy()
359 (shp->shm_perm.mode & SHM_DEST)); in shm_may_destroy()
370 struct shmid_kernel *shp; in __shm_close() local
375 shp = shm_lock(ns, sfd->id); in __shm_close()
381 if (WARN_ON_ONCE(IS_ERR(shp))) in __shm_close()
384 ipc_update_pid(&shp->shm_lprid, task_tgid(current)); in __shm_close()
385 shp->shm_dtim = ktime_get_real_seconds(); in __shm_close()
386 shp->shm_nattch--; in __shm_close()
387 if (shm_may_destroy(shp)) in __shm_close()
388 shm_destroy(ns, shp); in __shm_close()
390 shm_unlock(shp); in __shm_close()
412 struct shmid_kernel *shp = container_of(ipcp, struct shmid_kernel, shm_perm); in shm_try_destroy_orphaned() local
420 if (!list_empty(&shp->shm_clist)) in shm_try_destroy_orphaned()
423 if (shm_may_destroy(shp)) { in shm_try_destroy_orphaned()
424 shm_lock_by_ptr(shp); in shm_try_destroy_orphaned()
425 shm_destroy(ns, shp); in shm_try_destroy_orphaned()
442 struct shmid_kernel *shp; in exit_shm() local
452 shp = list_first_entry(&task->sysvshm.shm_clist, struct shmid_kernel, in exit_shm()
462 ns = shp->ns; in exit_shm()
480 list_del_init(&shp->shm_clist); in exit_shm()
490 WARN_ON(!ipc_rcu_getref(&shp->shm_perm)); in exit_shm()
499 list_del_init(&shp->shm_clist); in exit_shm()
508 shm_lock_by_ptr(shp); in exit_shm()
513 ipc_rcu_putref(&shp->shm_perm, shm_rcu_free); in exit_shm()
515 if (ipc_valid_object(&shp->shm_perm)) { in exit_shm()
516 if (shm_may_destroy(shp)) in exit_shm()
517 shm_destroy(ns, shp); in exit_shm()
519 shm_unlock(shp); in exit_shm()
526 shm_unlock(shp); in exit_shm()
711 struct shmid_kernel *shp; in newseg() local
727 shp = kmalloc(sizeof(*shp), GFP_KERNEL_ACCOUNT); in newseg()
728 if (unlikely(!shp)) in newseg()
731 shp->shm_perm.key = key; in newseg()
732 shp->shm_perm.mode = (shmflg & S_IRWXUGO); in newseg()
733 shp->mlock_ucounts = NULL; in newseg()
735 shp->shm_perm.security = NULL; in newseg()
736 error = security_shm_alloc(&shp->shm_perm); in newseg()
738 kfree(shp); in newseg()
773 shp->shm_cprid = get_pid(task_tgid(current)); in newseg()
774 shp->shm_lprid = NULL; in newseg()
775 shp->shm_atim = shp->shm_dtim = 0; in newseg()
776 shp->shm_ctim = ktime_get_real_seconds(); in newseg()
777 shp->shm_segsz = size; in newseg()
778 shp->shm_nattch = 0; in newseg()
779 shp->shm_file = file; in newseg()
780 shp->shm_creator = current; in newseg()
783 error = ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni); in newseg()
787 shp->ns = ns; in newseg()
790 list_add(&shp->shm_clist, &current->sysvshm.shm_clist); in newseg()
797 file_inode(file)->i_ino = shp->shm_perm.id; in newseg()
800 error = shp->shm_perm.id; in newseg()
802 ipc_unlock_object(&shp->shm_perm); in newseg()
807 ipc_update_pid(&shp->shm_cprid, NULL); in newseg()
808 ipc_update_pid(&shp->shm_lprid, NULL); in newseg()
810 ipc_rcu_putref(&shp->shm_perm, shm_rcu_free); in newseg()
813 call_rcu(&shp->shm_perm.rcu, shm_rcu_free); in newseg()
822 struct shmid_kernel *shp; in shm_more_checks() local
824 shp = container_of(ipcp, struct shmid_kernel, shm_perm); in shm_more_checks()
825 if (shp->shm_segsz < params->u.size) in shm_more_checks()
937 static void shm_add_rss_swap(struct shmid_kernel *shp, in shm_add_rss_swap() argument
942 inode = file_inode(shp->shm_file); in shm_add_rss_swap()
944 if (is_file_hugepages(shp->shm_file)) { in shm_add_rss_swap()
946 struct hstate *h = hstate_file(shp->shm_file); in shm_add_rss_swap()
978 struct shmid_kernel *shp; in shm_get_stat() local
983 shp = container_of(ipc, struct shmid_kernel, shm_perm); in shm_get_stat()
985 shm_add_rss_swap(shp, rss, swp); in shm_get_stat()
1000 struct shmid_kernel *shp; in shmctl_down() local
1013 shp = container_of(ipcp, struct shmid_kernel, shm_perm); in shmctl_down()
1015 err = security_shm_shmctl(&shp->shm_perm, cmd); in shmctl_down()
1021 ipc_lock_object(&shp->shm_perm); in shmctl_down()
1026 ipc_lock_object(&shp->shm_perm); in shmctl_down()
1030 shp->shm_ctim = ktime_get_real_seconds(); in shmctl_down()
1038 ipc_unlock_object(&shp->shm_perm); in shmctl_down()
1088 struct shmid_kernel *shp; in shmctl_stat() local
1095 shp = shm_obtain_object(ns, shmid); in shmctl_stat()
1096 if (IS_ERR(shp)) { in shmctl_stat()
1097 err = PTR_ERR(shp); in shmctl_stat()
1101 shp = shm_obtain_object_check(ns, shmid); in shmctl_stat()
1102 if (IS_ERR(shp)) { in shmctl_stat()
1103 err = PTR_ERR(shp); in shmctl_stat()
1116 audit_ipc_obj(&shp->shm_perm); in shmctl_stat()
1119 if (ipcperms(ns, &shp->shm_perm, S_IRUGO)) in shmctl_stat()
1123 err = security_shm_shmctl(&shp->shm_perm, cmd); in shmctl_stat()
1127 ipc_lock_object(&shp->shm_perm); in shmctl_stat()
1129 if (!ipc_valid_object(&shp->shm_perm)) { in shmctl_stat()
1130 ipc_unlock_object(&shp->shm_perm); in shmctl_stat()
1135 kernel_to_ipc64_perm(&shp->shm_perm, &tbuf->shm_perm); in shmctl_stat()
1136 tbuf->shm_segsz = shp->shm_segsz; in shmctl_stat()
1137 tbuf->shm_atime = shp->shm_atim; in shmctl_stat()
1138 tbuf->shm_dtime = shp->shm_dtim; in shmctl_stat()
1139 tbuf->shm_ctime = shp->shm_ctim; in shmctl_stat()
1141 tbuf->shm_atime_high = shp->shm_atim >> 32; in shmctl_stat()
1142 tbuf->shm_dtime_high = shp->shm_dtim >> 32; in shmctl_stat()
1143 tbuf->shm_ctime_high = shp->shm_ctim >> 32; in shmctl_stat()
1145 tbuf->shm_cpid = pid_vnr(shp->shm_cprid); in shmctl_stat()
1146 tbuf->shm_lpid = pid_vnr(shp->shm_lprid); in shmctl_stat()
1147 tbuf->shm_nattch = shp->shm_nattch; in shmctl_stat()
1160 err = shp->shm_perm.id; in shmctl_stat()
1163 ipc_unlock_object(&shp->shm_perm); in shmctl_stat()
1171 struct shmid_kernel *shp; in shmctl_do_lock() local
1176 shp = shm_obtain_object_check(ns, shmid); in shmctl_do_lock()
1177 if (IS_ERR(shp)) { in shmctl_do_lock()
1178 err = PTR_ERR(shp); in shmctl_do_lock()
1182 audit_ipc_obj(&(shp->shm_perm)); in shmctl_do_lock()
1183 err = security_shm_shmctl(&shp->shm_perm, cmd); in shmctl_do_lock()
1187 ipc_lock_object(&shp->shm_perm); in shmctl_do_lock()
1190 if (!ipc_valid_object(&shp->shm_perm)) { in shmctl_do_lock()
1198 if (!uid_eq(euid, shp->shm_perm.uid) && in shmctl_do_lock()
1199 !uid_eq(euid, shp->shm_perm.cuid)) { in shmctl_do_lock()
1209 shm_file = shp->shm_file; in shmctl_do_lock()
1217 if (!err && !(shp->shm_perm.mode & SHM_LOCKED)) { in shmctl_do_lock()
1218 shp->shm_perm.mode |= SHM_LOCKED; in shmctl_do_lock()
1219 shp->mlock_ucounts = ucounts; in shmctl_do_lock()
1225 if (!(shp->shm_perm.mode & SHM_LOCKED)) in shmctl_do_lock()
1227 shmem_lock(shm_file, 0, shp->mlock_ucounts); in shmctl_do_lock()
1228 shp->shm_perm.mode &= ~SHM_LOCKED; in shmctl_do_lock()
1229 shp->mlock_ucounts = NULL; in shmctl_do_lock()
1231 ipc_unlock_object(&shp->shm_perm); in shmctl_do_lock()
1239 ipc_unlock_object(&shp->shm_perm); in shmctl_do_lock()
1525 struct shmid_kernel *shp; in do_shmat() local
1585 shp = shm_obtain_object_check(ns, shmid); in do_shmat()
1586 if (IS_ERR(shp)) { in do_shmat()
1587 err = PTR_ERR(shp); in do_shmat()
1592 if (ipcperms(ns, &shp->shm_perm, acc_mode)) in do_shmat()
1595 err = security_shm_shmat(&shp->shm_perm, shmaddr, shmflg); in do_shmat()
1599 ipc_lock_object(&shp->shm_perm); in do_shmat()
1602 if (!ipc_valid_object(&shp->shm_perm)) { in do_shmat()
1603 ipc_unlock_object(&shp->shm_perm); in do_shmat()
1617 base = get_file(shp->shm_file); in do_shmat()
1618 shp->shm_nattch++; in do_shmat()
1620 ipc_unlock_object(&shp->shm_perm); in do_shmat()
1641 sfd->id = shp->shm_perm.id; in do_shmat()
1680 shp = shm_lock(ns, shmid); in do_shmat()
1681 shp->shm_nattch--; in do_shmat()
1683 if (shm_may_destroy(shp)) in do_shmat()
1684 shm_destroy(ns, shp); in do_shmat()
1686 shm_unlock(shp); in do_shmat()
1848 struct shmid_kernel *shp; in sysvipc_shm_proc_show() local
1851 shp = container_of(ipcp, struct shmid_kernel, shm_perm); in sysvipc_shm_proc_show()
1852 shm_add_rss_swap(shp, &rss, &swp); in sysvipc_shm_proc_show()
1864 shp->shm_perm.key, in sysvipc_shm_proc_show()
1865 shp->shm_perm.id, in sysvipc_shm_proc_show()
1866 shp->shm_perm.mode, in sysvipc_shm_proc_show()
1867 shp->shm_segsz, in sysvipc_shm_proc_show()
1868 pid_nr_ns(shp->shm_cprid, pid_ns), in sysvipc_shm_proc_show()
1869 pid_nr_ns(shp->shm_lprid, pid_ns), in sysvipc_shm_proc_show()
1870 shp->shm_nattch, in sysvipc_shm_proc_show()
1871 from_kuid_munged(user_ns, shp->shm_perm.uid), in sysvipc_shm_proc_show()
1872 from_kgid_munged(user_ns, shp->shm_perm.gid), in sysvipc_shm_proc_show()
1873 from_kuid_munged(user_ns, shp->shm_perm.cuid), in sysvipc_shm_proc_show()
1874 from_kgid_munged(user_ns, shp->shm_perm.cgid), in sysvipc_shm_proc_show()
1875 shp->shm_atim, in sysvipc_shm_proc_show()
1876 shp->shm_dtim, in sysvipc_shm_proc_show()
1877 shp->shm_ctim, in sysvipc_shm_proc_show()