Lines Matching full:pid
9 #include <linux/pid.h>
80 struct pid *pid_a = rb_entry(a, struct pid, pidfs_node); in pidfs_ino_cmp()
81 struct pid *pid_b = rb_entry(b, struct pid, pidfs_node); in pidfs_ino_cmp()
92 void pidfs_add_pid(struct pid *pid) in pidfs_add_pid() argument
98 * to struct pid is the inode number. in pidfs_add_pid()
100 * On 32 bit the 64 bit number assigned to struct pid is split in pidfs_add_pid()
124 pid->ino = pidfs_ino_nr; in pidfs_add_pid()
125 pid->stashed = NULL; in pidfs_add_pid()
129 rb_find_add_rcu(&pid->pidfs_node, &pidfs_ino_tree, pidfs_ino_cmp); in pidfs_add_pid()
133 void pidfs_remove_pid(struct pid *pid) in pidfs_remove_pid() argument
136 rb_erase(&pid->pidfs_node, &pidfs_ino_tree); in pidfs_remove_pid()
146 * Pid:
147 * This function will print the pid that a given pidfd refers to in the
148 * pid namespace of the procfs instance.
149 * If the pid namespace of the process is not a descendant of the pid
150 * namespace of the procfs instance 0 will be shown as its pid. This is
152 * its pid namespace.
155 * If pid namespaces are supported then this function will also print
156 * the pid of a given pidfd refers to for all descendant pid namespaces
157 * starting from the current pid namespace of the instance, i.e. the
158 * Pid field and the first entry in the NSpid field will be identical.
159 * If the pid namespace of the process is not a descendant of the pid
162 * Note that this differs from the Pid and NSpid fields in
163 * /proc/<pid>/status where Pid and NSpid are always shown relative to
164 * the pid namespace of the procfs instance. The difference becomes
165 * obvious when sending around a pidfd between pid namespaces from a
167 * present between the pid namespaces:
168 * - create two new pid namespaces ns1 and ns2 in the initial pid
170 * new pid namespace and mount procfs)
173 * - read /proc/self/fdinfo/<pidfd> and observe that both Pid and NSpid
178 struct pid *pid = pidfd_pid(f); in pidfd_show_fdinfo() local
182 if (likely(pid_has_task(pid, PIDTYPE_PID))) { in pidfd_show_fdinfo()
184 nr = pid_nr_ns(pid, ns); in pidfd_show_fdinfo()
187 seq_put_decimal_ll(m, "Pid:\t", nr); in pidfd_show_fdinfo()
194 /* If nr is non-zero it means that 'pid' is valid and that in pidfd_show_fdinfo()
195 * ns, i.e. the pid namespace associated with the procfs in pidfd_show_fdinfo()
196 * instance, is in the pid namespace hierarchy of pid. in pidfd_show_fdinfo()
199 for (i = ns->level + 1; i <= pid->level; i++) in pidfd_show_fdinfo()
200 seq_put_decimal_ll(m, "\t", pid->numbers[i].nr); in pidfd_show_fdinfo()
212 struct pid *pid = pidfd_pid(file); in pidfd_poll() local
216 poll_wait(file, &pid->wait_pidfd, pts); in pidfd_poll()
221 * and assumes the struct pid of the old thread-group leader. in pidfd_poll()
224 task = pid_task(pid, PIDTYPE_PID); in pidfd_poll()
233 static inline bool pid_in_current_pidns(const struct pid *pid) in pid_in_current_pidns() argument
237 if (ns->level <= pid->level) in pid_in_current_pidns()
238 return pid->numbers[ns->level].ns == ns; in pid_in_current_pidns()
247 struct pid *pid = pidfd_pid(file); in pidfd_info() local
265 * Restrict information retrieval to tasks within the caller's pid in pidfd_info()
268 if (!pid_in_current_pidns(pid)) in pidfd_info()
283 task = get_pid_task(pid, PIDTYPE_PID); in pidfd_info()
326 * Copy pid/tgid last, to reduce the chances the information might be in pidfd_info()
336 kinfo.pid = task_pid_vnr(task); in pidfd_info()
339 if (kinfo.pid == 0 || kinfo.tgid == 0 || (kinfo.ppid == 0 && kinfo.pid != 1)) in pidfd_info()
512 struct pid *pidfd_pid(const struct file *file) in pidfd_pid()
521 * reference to struct pid being held that won't be released until the
525 * If this struct pid is referred to by a pidfd then
527 * pid. Since we've taken a reference on it there's now an additional
529 * it again in a second and we know that the pid is kept alive anyway.
611 struct pid *pid = inode->i_private; in pidfs_evict_inode() local
614 put_pid(pid); in pidfs_evict_inode()
661 const struct pid *pid = inode->i_private; in pidfs_encode_fh() local
669 *(u64 *)fh = pid->ino; in pidfs_encode_fh()
676 const struct pid *pid = rb_entry(node, struct pid, pidfs_node); in pidfs_ino_find() local
678 if (pid_ino < pid->ino) in pidfs_ino_find()
680 if (pid_ino > pid->ino) in pidfs_ino_find()
685 /* Find a struct pid based on the inode number. */
686 static struct pid *pidfs_ino_get_pid(u64 ino) in pidfs_ino_get_pid()
688 struct pid *pid; in pidfs_ino_get_pid() local
703 pid = rb_entry(node, struct pid, pidfs_node); in pidfs_ino_get_pid()
705 /* Within our pid namespace hierarchy? */ in pidfs_ino_get_pid()
706 if (pid_vnr(pid) == 0) in pidfs_ino_get_pid()
709 return get_pid(pid); in pidfs_ino_get_pid()
719 struct pid *pid; in pidfs_fh_to_dentry() local
732 pid = pidfs_ino_get_pid(pid_ino); in pidfs_fh_to_dentry()
733 if (!pid) in pidfs_fh_to_dentry()
736 ret = path_from_stashed(&pid->stashed, pidfs_mnt, pid, &path); in pidfs_fh_to_dentry()
759 * pidfd_ino_get_pid() will verify that the struct pid is part in pidfs_export_permission()
760 * of the caller's pid namespace hierarchy. No further in pidfs_export_permission()
766 static inline bool pidfs_pid_valid(struct pid *pid, const struct path *path, in pidfs_pid_valid() argument
777 * pidfd has been allocated perform another check that the pid in pidfs_pid_valid()
781 * linkage has been established for @pid yet and the kernel is in pidfs_pid_valid()
791 * Since pidfs_exit() is called before struct pid's task linkage in pidfs_pid_valid()
793 * was already attached to struct pid and exit information was in pidfs_pid_valid()
796 if (unlikely(!pid_has_task(pid, type))) { in pidfs_pid_valid()
826 const struct pid *pid = data; in pidfs_init_inode() local
833 inode->i_ino = pidfs_ino(pid->ino); in pidfs_init_inode()
834 inode->i_generation = pidfs_gen(pid->ino); in pidfs_init_inode()
840 struct pid *pid = data; in pidfs_put_data() local
841 put_pid(pid); in pidfs_put_data()
870 struct file *pidfs_alloc_file(struct pid *pid, unsigned int flags) in pidfs_alloc_file() argument
883 ret = path_from_stashed(&pid->stashed, pidfs_mnt, get_pid(pid), &path); in pidfs_alloc_file()
887 if (!pidfs_pid_valid(pid, &path, flags)) in pidfs_alloc_file()