Lines Matching refs:shp
88 #define shm_unlock(shp) \ argument
89 ipc_unlock(&(shp)->shm_perm)
94 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
115 struct shmid_kernel *shp; in do_shm_rmid() local
117 shp = container_of(ipcp, struct shmid_kernel, shm_perm); in do_shm_rmid()
119 if (shp->shm_nattch) { in do_shm_rmid()
120 shp->shm_perm.mode |= SHM_DEST; in do_shm_rmid()
122 ipc_set_key_private(&shm_ids(ns), &shp->shm_perm); in do_shm_rmid()
123 shm_unlock(shp); in do_shm_rmid()
125 shm_destroy(ns, shp); in do_shm_rmid()
222 struct shmid_kernel *shp = container_of(ptr, struct shmid_kernel, in shm_rcu_free() local
224 security_shm_free(&shp->shm_perm); in shm_rcu_free()
225 kvfree(shp); in shm_rcu_free()
239 struct shmid_kernel *shp; in __shm_open() local
241 shp = shm_lock(sfd->ns, sfd->id); in __shm_open()
243 if (IS_ERR(shp)) in __shm_open()
244 return PTR_ERR(shp); in __shm_open()
246 if (shp->shm_file != sfd->file) { in __shm_open()
248 shm_unlock(shp); in __shm_open()
252 shp->shm_atim = ktime_get_real_seconds(); in __shm_open()
253 ipc_update_pid(&shp->shm_lprid, task_tgid(current)); in __shm_open()
254 shp->shm_nattch++; in __shm_open()
255 shm_unlock(shp); in __shm_open()
279 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp) in shm_destroy() argument
283 shm_file = shp->shm_file; in shm_destroy()
284 shp->shm_file = NULL; in shm_destroy()
285 ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT; in shm_destroy()
286 shm_rmid(ns, shp); in shm_destroy()
287 shm_unlock(shp); in shm_destroy()
289 shmem_lock(shm_file, 0, shp->mlock_user); in shm_destroy()
290 else if (shp->mlock_user) in shm_destroy()
292 shp->mlock_user); in shm_destroy()
294 ipc_update_pid(&shp->shm_cprid, NULL); in shm_destroy()
295 ipc_update_pid(&shp->shm_lprid, NULL); in shm_destroy()
296 ipc_rcu_putref(&shp->shm_perm, shm_rcu_free); in shm_destroy()
309 static bool shm_may_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp) in shm_may_destroy() argument
311 return (shp->shm_nattch == 0) && in shm_may_destroy()
313 (shp->shm_perm.mode & SHM_DEST)); in shm_may_destroy()
326 struct shmid_kernel *shp; in shm_close() local
331 shp = shm_lock(ns, sfd->id); in shm_close()
337 if (WARN_ON_ONCE(IS_ERR(shp))) in shm_close()
340 ipc_update_pid(&shp->shm_lprid, task_tgid(current)); in shm_close()
341 shp->shm_dtim = ktime_get_real_seconds(); in shm_close()
342 shp->shm_nattch--; in shm_close()
343 if (shm_may_destroy(ns, shp)) in shm_close()
344 shm_destroy(ns, shp); in shm_close()
346 shm_unlock(shp); in shm_close()
356 struct shmid_kernel *shp = container_of(ipcp, struct shmid_kernel, shm_perm); in shm_try_destroy_orphaned() local
364 if (shp->shm_creator != NULL) in shm_try_destroy_orphaned()
367 if (shm_may_destroy(ns, shp)) { in shm_try_destroy_orphaned()
368 shm_lock_by_ptr(shp); in shm_try_destroy_orphaned()
369 shm_destroy(ns, shp); in shm_try_destroy_orphaned()
386 struct shmid_kernel *shp, *n; in exit_shm() local
398 list_for_each_entry(shp, &task->sysvshm.shm_clist, shm_clist) in exit_shm()
399 shp->shm_creator = NULL; in exit_shm()
415 list_for_each_entry_safe(shp, n, &task->sysvshm.shm_clist, shm_clist) { in exit_shm()
416 shp->shm_creator = NULL; in exit_shm()
418 if (shm_may_destroy(ns, shp)) { in exit_shm()
419 shm_lock_by_ptr(shp); in exit_shm()
420 shm_destroy(ns, shp); in exit_shm()
606 struct shmid_kernel *shp; in newseg() local
622 shp = kvmalloc(sizeof(*shp), GFP_KERNEL); in newseg()
623 if (unlikely(!shp)) in newseg()
626 shp->shm_perm.key = key; in newseg()
627 shp->shm_perm.mode = (shmflg & S_IRWXUGO); in newseg()
628 shp->mlock_user = NULL; in newseg()
630 shp->shm_perm.security = NULL; in newseg()
631 error = security_shm_alloc(&shp->shm_perm); in newseg()
633 kvfree(shp); in newseg()
653 &shp->mlock_user, HUGETLB_SHMFS_INODE, in newseg()
669 shp->shm_cprid = get_pid(task_tgid(current)); in newseg()
670 shp->shm_lprid = NULL; in newseg()
671 shp->shm_atim = shp->shm_dtim = 0; in newseg()
672 shp->shm_ctim = ktime_get_real_seconds(); in newseg()
673 shp->shm_segsz = size; in newseg()
674 shp->shm_nattch = 0; in newseg()
675 shp->shm_file = file; in newseg()
676 shp->shm_creator = current; in newseg()
679 error = ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni); in newseg()
683 list_add(&shp->shm_clist, ¤t->sysvshm.shm_clist); in newseg()
689 file_inode(file)->i_ino = shp->shm_perm.id; in newseg()
692 error = shp->shm_perm.id; in newseg()
694 ipc_unlock_object(&shp->shm_perm); in newseg()
699 ipc_update_pid(&shp->shm_cprid, NULL); in newseg()
700 ipc_update_pid(&shp->shm_lprid, NULL); in newseg()
701 if (is_file_hugepages(file) && shp->mlock_user) in newseg()
702 user_shm_unlock(size, shp->mlock_user); in newseg()
704 ipc_rcu_putref(&shp->shm_perm, shm_rcu_free); in newseg()
707 call_rcu(&shp->shm_perm.rcu, shm_rcu_free); in newseg()
716 struct shmid_kernel *shp; in shm_more_checks() local
718 shp = container_of(ipcp, struct shmid_kernel, shm_perm); in shm_more_checks()
719 if (shp->shm_segsz < params->u.size) in shm_more_checks()
831 static void shm_add_rss_swap(struct shmid_kernel *shp, in shm_add_rss_swap() argument
836 inode = file_inode(shp->shm_file); in shm_add_rss_swap()
838 if (is_file_hugepages(shp->shm_file)) { in shm_add_rss_swap()
840 struct hstate *h = hstate_file(shp->shm_file); in shm_add_rss_swap()
872 struct shmid_kernel *shp; in shm_get_stat() local
877 shp = container_of(ipc, struct shmid_kernel, shm_perm); in shm_get_stat()
879 shm_add_rss_swap(shp, rss, swp); in shm_get_stat()
894 struct shmid_kernel *shp; in shmctl_down() local
907 shp = container_of(ipcp, struct shmid_kernel, shm_perm); in shmctl_down()
909 err = security_shm_shmctl(&shp->shm_perm, cmd); in shmctl_down()
915 ipc_lock_object(&shp->shm_perm); in shmctl_down()
920 ipc_lock_object(&shp->shm_perm); in shmctl_down()
924 shp->shm_ctim = ktime_get_real_seconds(); in shmctl_down()
932 ipc_unlock_object(&shp->shm_perm); in shmctl_down()
982 struct shmid_kernel *shp; in shmctl_stat() local
989 shp = shm_obtain_object(ns, shmid); in shmctl_stat()
990 if (IS_ERR(shp)) { in shmctl_stat()
991 err = PTR_ERR(shp); in shmctl_stat()
995 shp = shm_obtain_object_check(ns, shmid); in shmctl_stat()
996 if (IS_ERR(shp)) { in shmctl_stat()
997 err = PTR_ERR(shp); in shmctl_stat()
1010 audit_ipc_obj(&shp->shm_perm); in shmctl_stat()
1013 if (ipcperms(ns, &shp->shm_perm, S_IRUGO)) in shmctl_stat()
1017 err = security_shm_shmctl(&shp->shm_perm, cmd); in shmctl_stat()
1021 ipc_lock_object(&shp->shm_perm); in shmctl_stat()
1023 if (!ipc_valid_object(&shp->shm_perm)) { in shmctl_stat()
1024 ipc_unlock_object(&shp->shm_perm); in shmctl_stat()
1029 kernel_to_ipc64_perm(&shp->shm_perm, &tbuf->shm_perm); in shmctl_stat()
1030 tbuf->shm_segsz = shp->shm_segsz; in shmctl_stat()
1031 tbuf->shm_atime = shp->shm_atim; in shmctl_stat()
1032 tbuf->shm_dtime = shp->shm_dtim; in shmctl_stat()
1033 tbuf->shm_ctime = shp->shm_ctim; in shmctl_stat()
1035 tbuf->shm_atime_high = shp->shm_atim >> 32; in shmctl_stat()
1036 tbuf->shm_dtime_high = shp->shm_dtim >> 32; in shmctl_stat()
1037 tbuf->shm_ctime_high = shp->shm_ctim >> 32; in shmctl_stat()
1039 tbuf->shm_cpid = pid_vnr(shp->shm_cprid); in shmctl_stat()
1040 tbuf->shm_lpid = pid_vnr(shp->shm_lprid); in shmctl_stat()
1041 tbuf->shm_nattch = shp->shm_nattch; in shmctl_stat()
1054 err = shp->shm_perm.id; in shmctl_stat()
1057 ipc_unlock_object(&shp->shm_perm); in shmctl_stat()
1065 struct shmid_kernel *shp; in shmctl_do_lock() local
1070 shp = shm_obtain_object_check(ns, shmid); in shmctl_do_lock()
1071 if (IS_ERR(shp)) { in shmctl_do_lock()
1072 err = PTR_ERR(shp); in shmctl_do_lock()
1076 audit_ipc_obj(&(shp->shm_perm)); in shmctl_do_lock()
1077 err = security_shm_shmctl(&shp->shm_perm, cmd); in shmctl_do_lock()
1081 ipc_lock_object(&shp->shm_perm); in shmctl_do_lock()
1084 if (!ipc_valid_object(&shp->shm_perm)) { in shmctl_do_lock()
1092 if (!uid_eq(euid, shp->shm_perm.uid) && in shmctl_do_lock()
1093 !uid_eq(euid, shp->shm_perm.cuid)) { in shmctl_do_lock()
1103 shm_file = shp->shm_file; in shmctl_do_lock()
1111 if (!err && !(shp->shm_perm.mode & SHM_LOCKED)) { in shmctl_do_lock()
1112 shp->shm_perm.mode |= SHM_LOCKED; in shmctl_do_lock()
1113 shp->mlock_user = user; in shmctl_do_lock()
1119 if (!(shp->shm_perm.mode & SHM_LOCKED)) in shmctl_do_lock()
1121 shmem_lock(shm_file, 0, shp->mlock_user); in shmctl_do_lock()
1122 shp->shm_perm.mode &= ~SHM_LOCKED; in shmctl_do_lock()
1123 shp->mlock_user = NULL; in shmctl_do_lock()
1125 ipc_unlock_object(&shp->shm_perm); in shmctl_do_lock()
1133 ipc_unlock_object(&shp->shm_perm); in shmctl_do_lock()
1419 struct shmid_kernel *shp; in do_shmat() local
1479 shp = shm_obtain_object_check(ns, shmid); in do_shmat()
1480 if (IS_ERR(shp)) { in do_shmat()
1481 err = PTR_ERR(shp); in do_shmat()
1486 if (ipcperms(ns, &shp->shm_perm, acc_mode)) in do_shmat()
1489 err = security_shm_shmat(&shp->shm_perm, shmaddr, shmflg); in do_shmat()
1493 ipc_lock_object(&shp->shm_perm); in do_shmat()
1496 if (!ipc_valid_object(&shp->shm_perm)) { in do_shmat()
1497 ipc_unlock_object(&shp->shm_perm); in do_shmat()
1511 base = get_file(shp->shm_file); in do_shmat()
1512 shp->shm_nattch++; in do_shmat()
1514 ipc_unlock_object(&shp->shm_perm); in do_shmat()
1535 sfd->id = shp->shm_perm.id; in do_shmat()
1574 shp = shm_lock(ns, shmid); in do_shmat()
1575 shp->shm_nattch--; in do_shmat()
1576 if (shm_may_destroy(ns, shp)) in do_shmat()
1577 shm_destroy(ns, shp); in do_shmat()
1579 shm_unlock(shp); in do_shmat()
1742 struct shmid_kernel *shp; in sysvipc_shm_proc_show() local
1745 shp = container_of(ipcp, struct shmid_kernel, shm_perm); in sysvipc_shm_proc_show()
1746 shm_add_rss_swap(shp, &rss, &swp); in sysvipc_shm_proc_show()
1758 shp->shm_perm.key, in sysvipc_shm_proc_show()
1759 shp->shm_perm.id, in sysvipc_shm_proc_show()
1760 shp->shm_perm.mode, in sysvipc_shm_proc_show()
1761 shp->shm_segsz, in sysvipc_shm_proc_show()
1762 pid_nr_ns(shp->shm_cprid, pid_ns), in sysvipc_shm_proc_show()
1763 pid_nr_ns(shp->shm_lprid, pid_ns), in sysvipc_shm_proc_show()
1764 shp->shm_nattch, in sysvipc_shm_proc_show()
1765 from_kuid_munged(user_ns, shp->shm_perm.uid), in sysvipc_shm_proc_show()
1766 from_kgid_munged(user_ns, shp->shm_perm.gid), in sysvipc_shm_proc_show()
1767 from_kuid_munged(user_ns, shp->shm_perm.cuid), in sysvipc_shm_proc_show()
1768 from_kgid_munged(user_ns, shp->shm_perm.cgid), in sysvipc_shm_proc_show()
1769 shp->shm_atim, in sysvipc_shm_proc_show()
1770 shp->shm_dtim, in sysvipc_shm_proc_show()
1771 shp->shm_ctim, in sysvipc_shm_proc_show()