Lines Matching refs:pid

9  * pid-structures are backing objects for tasks sharing a given ID to chain
49 struct pid init_struct_pid = {
112 void put_pid(struct pid *pid)
116 if (!pid)
119 ns = pid->numbers[pid->level].ns;
120 if (refcount_dec_and_test(&pid->count)) {
121 kmem_cache_free(ns->pid_cachep, pid);
129 struct pid *pid = container_of(rhp, struct pid, rcu);
130 put_pid(pid);
133 void free_pid(struct pid *pid)
140 for (i = 0; i <= pid->level; i++) {
141 struct upid *upid = pid->numbers + i;
146 /* When all that is left in the pid namespace
163 call_rcu(&pid->rcu, delayed_put_pid);
166 struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
169 struct pid *pid;
187 pid = kmem_cache_alloc(ns->pid_cachep, GFP_KERNEL);
188 if (!pid)
192 pid->level = ns->level;
230 * init really needs pid 1, but after reaching the
251 pid->numbers[i].nr = nr;
252 pid->numbers[i].ns = tmp;
258 * where the child subreaper has already exited and the pid
261 * documented behavior for pid namespaces. So we can't easily
267 refcount_set(&pid->count, 1);
268 spin_lock_init(&pid->lock);
270 INIT_HLIST_HEAD(&pid->tasks[type]);
272 init_waitqueue_head(&pid->wait_pidfd);
273 INIT_HLIST_HEAD(&pid->inodes);
275 upid = pid->numbers + ns->level;
279 pid->stashed = NULL;
280 pid->ino = ++pidfs_ino;
281 for ( ; upid >= pid->numbers; --upid) {
283 idr_replace(&upid->ns->idr, pid, upid->nr);
288 return pid;
297 upid = pid->numbers + i;
301 /* On failure to allocate the first pid, reset the state */
307 kmem_cache_free(ns->pid_cachep, pid);
318 struct pid *find_pid_ns(int nr, struct pid_namespace *ns)
324 struct pid *find_vpid(int nr)
330 static struct pid **task_pid_ptr(struct task_struct *task, enum pid_type type)
342 struct pid *pid = *task_pid_ptr(task, type);
343 hlist_add_head_rcu(&task->pid_links[type], &pid->tasks[type]);
347 struct pid *new)
349 struct pid **pid_ptr = task_pid_ptr(task, type);
350 struct pid *pid;
353 pid = *pid_ptr;
359 WARN_ON_ONCE(pid_has_task(pid, PIDTYPE_PID));
360 wake_up_all(&pid->wait_pidfd);
364 if (pid_has_task(pid, tmp))
367 free_pid(pid);
376 struct pid *pid)
378 __change_pid(task, type, pid);
384 struct pid *pid1 = left->thread_pid;
385 struct pid *pid2 = right->thread_pid;
392 /* Swap the per task_struct pid */
397 WRITE_ONCE(left->pid, pid_nr(pid2));
398 WRITE_ONCE(right->pid, pid_nr(pid1));
409 struct task_struct *pid_task(struct pid *pid, enum pid_type type)
412 if (pid) {
414 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
451 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
453 struct pid *pid;
455 pid = get_pid(rcu_dereference(*task_pid_ptr(task, type)));
457 return pid;
461 struct task_struct *get_pid_task(struct pid *pid, enum pid_type type)
465 result = pid_task(pid, type);
473 struct pid *find_get_pid(pid_t nr)
475 struct pid *pid;
478 pid = get_pid(find_vpid(nr));
481 return pid;
485 pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
490 if (pid && ns->level <= pid->level) {
491 upid = &pid->numbers[ns->level];
499 pid_t pid_vnr(struct pid *pid)
501 return pid_nr_ns(pid, task_active_pid_ns(current));
527 * Used by proc to find the first pid that is greater than or equal to nr.
529 * If there is a pid at nr this function is exactly the same as find_pid_ns.
531 struct pid *find_ge_pid(int nr, struct pid_namespace *ns)
537 struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags)
540 struct pid *pid;
546 pid = pidfd_pid(f.file);
547 if (!IS_ERR(pid)) {
548 get_pid(pid);
553 return pid;
571 struct pid *pid;
574 pid = pidfd_get_pid(pidfd, &f_flags);
575 if (IS_ERR(pid))
576 return ERR_CAST(pid);
578 task = get_pid_task(pid, PIDTYPE_TGID);
579 put_pid(pid);
588 * pidfd_create() - Create a new pid file descriptor.
590 * @pid: struct pid that the pidfd will reference
593 * This creates a new pid file descriptor with the O_CLOEXEC flag set.
603 static int pidfd_create(struct pid *pid, unsigned int flags)
608 pidfd = pidfd_prepare(pid, flags, &pidfd_file);
617 * sys_pidfd_open() - Open new pid file descriptor.
619 * @pid: pid for which to retrieve a pidfd
622 * This creates a new pid file descriptor with the O_CLOEXEC flag set for
623 * the task identified by @pid. Without PIDFD_THREAD flag the target task
629 SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags)
632 struct pid *p;
637 if (pid <= 0)
640 p = find_get_pid(pid);
664 init_pid_ns.pid_cachep = kmem_cache_create("pid",
665 struct_size_t(struct pid, numbers, 1),
666 __alignof__(struct pid),
709 static int pidfd_getfd(struct pid *pid, int fd)
715 task = get_pid_task(pid, PIDTYPE_PID);
749 struct pid *pid;
761 pid = pidfd_pid(f.file);
762 if (IS_ERR(pid))
763 ret = PTR_ERR(pid);
765 ret = pidfd_getfd(pid, fd);