Commit 2ee08260 authored by Mike Rapoport's avatar Mike Rapoport Committed by Linus Torvalds

pids: introduce find_get_task_by_vpid() helper

There are several functions that do find_task_by_vpid() followed by
get_task_struct().  We can use a helper function instead.

Link: http://lkml.kernel.org/r/1509602027-11337-1-git-send-email-rppt@linux.vnet.ibm.comSigned-off-by: default avatarMike Rapoport <rppt@linux.vnet.ibm.com>
Acked-by: default avatarOleg Nesterov <oleg@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent eab216e9
...@@ -2610,17 +2610,10 @@ pfm_get_task(pfm_context_t *ctx, pid_t pid, struct task_struct **task) ...@@ -2610,17 +2610,10 @@ pfm_get_task(pfm_context_t *ctx, pid_t pid, struct task_struct **task)
if (pid < 2) return -EPERM; if (pid < 2) return -EPERM;
if (pid != task_pid_vnr(current)) { if (pid != task_pid_vnr(current)) {
read_lock(&tasklist_lock);
p = find_task_by_vpid(pid);
/* make sure task cannot go away while we operate on it */ /* make sure task cannot go away while we operate on it */
if (p) get_task_struct(p); p = find_get_task_by_vpid(pid);
if (!p)
read_unlock(&tasklist_lock); return -ESRCH;
if (p == NULL) return -ESRCH;
} }
ret = pfm_task_incompatible(ctx, p); ret = pfm_task_incompatible(ctx, p);
......
...@@ -1489,6 +1489,11 @@ static inline struct thread_info *task_thread_info(struct task_struct *task) ...@@ -1489,6 +1489,11 @@ static inline struct thread_info *task_thread_info(struct task_struct *task)
extern struct task_struct *find_task_by_vpid(pid_t nr); extern struct task_struct *find_task_by_vpid(pid_t nr);
extern struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns); extern struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns);
/*
* find a task by its virtual pid and get the task struct
*/
extern struct task_struct *find_get_task_by_vpid(pid_t nr);
extern int wake_up_state(struct task_struct *tsk, unsigned int state); extern int wake_up_state(struct task_struct *tsk, unsigned int state);
extern int wake_up_process(struct task_struct *tsk); extern int wake_up_process(struct task_struct *tsk);
extern void wake_up_new_task(struct task_struct *tsk); extern void wake_up_new_task(struct task_struct *tsk);
......
...@@ -862,24 +862,6 @@ static void put_pi_state(struct futex_pi_state *pi_state) ...@@ -862,24 +862,6 @@ static void put_pi_state(struct futex_pi_state *pi_state)
} }
} }
/*
* Look up the task based on what TID userspace gave us.
* We dont trust it.
*/
static struct task_struct *futex_find_get_task(pid_t pid)
{
struct task_struct *p;
rcu_read_lock();
p = find_task_by_vpid(pid);
if (p)
get_task_struct(p);
rcu_read_unlock();
return p;
}
#ifdef CONFIG_FUTEX_PI #ifdef CONFIG_FUTEX_PI
/* /*
...@@ -1183,7 +1165,7 @@ static int attach_to_pi_owner(u32 uval, union futex_key *key, ...@@ -1183,7 +1165,7 @@ static int attach_to_pi_owner(u32 uval, union futex_key *key,
*/ */
if (!pid) if (!pid)
return -ESRCH; return -ESRCH;
p = futex_find_get_task(pid); p = find_get_task_by_vpid(pid);
if (!p) if (!p)
return -ESRCH; return -ESRCH;
......
...@@ -343,6 +343,19 @@ struct task_struct *find_task_by_vpid(pid_t vnr) ...@@ -343,6 +343,19 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
return find_task_by_pid_ns(vnr, task_active_pid_ns(current)); return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
} }
struct task_struct *find_get_task_by_vpid(pid_t nr)
{
struct task_struct *task;
rcu_read_lock();
task = find_task_by_vpid(nr);
if (task)
get_task_struct(task);
rcu_read_unlock();
return task;
}
struct pid *get_task_pid(struct task_struct *task, enum pid_type type) struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
{ {
struct pid *pid; struct pid *pid;
......
...@@ -1103,21 +1103,6 @@ int ptrace_request(struct task_struct *child, long request, ...@@ -1103,21 +1103,6 @@ int ptrace_request(struct task_struct *child, long request,
return ret; return ret;
} }
static struct task_struct *ptrace_get_task_struct(pid_t pid)
{
struct task_struct *child;
rcu_read_lock();
child = find_task_by_vpid(pid);
if (child)
get_task_struct(child);
rcu_read_unlock();
if (!child)
return ERR_PTR(-ESRCH);
return child;
}
#ifndef arch_ptrace_attach #ifndef arch_ptrace_attach
#define arch_ptrace_attach(child) do { } while (0) #define arch_ptrace_attach(child) do { } while (0)
#endif #endif
...@@ -1135,9 +1120,9 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr, ...@@ -1135,9 +1120,9 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
goto out; goto out;
} }
child = ptrace_get_task_struct(pid); child = find_get_task_by_vpid(pid);
if (IS_ERR(child)) { if (!child) {
ret = PTR_ERR(child); ret = -ESRCH;
goto out; goto out;
} }
...@@ -1281,9 +1266,9 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid, ...@@ -1281,9 +1266,9 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
goto out; goto out;
} }
child = ptrace_get_task_struct(pid); child = find_get_task_by_vpid(pid);
if (IS_ERR(child)) { if (!child) {
ret = PTR_ERR(child); ret = -ESRCH;
goto out; goto out;
} }
......
...@@ -194,11 +194,7 @@ static int fill_stats_for_pid(pid_t pid, struct taskstats *stats) ...@@ -194,11 +194,7 @@ static int fill_stats_for_pid(pid_t pid, struct taskstats *stats)
{ {
struct task_struct *tsk; struct task_struct *tsk;
rcu_read_lock(); tsk = find_get_task_by_vpid(pid);
tsk = find_task_by_vpid(pid);
if (tsk)
get_task_struct(tsk);
rcu_read_unlock();
if (!tsk) if (!tsk)
return -ESRCH; return -ESRCH;
fill_stats(current_user_ns(), task_active_pid_ns(current), tsk, stats); fill_stats(current_user_ns(), task_active_pid_ns(current), tsk, stats);
......
...@@ -197,11 +197,7 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter, ...@@ -197,11 +197,7 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
} }
/* Get process information */ /* Get process information */
rcu_read_lock(); task = find_get_task_by_vpid(pid);
task = find_task_by_vpid(pid);
if (task)
get_task_struct(task);
rcu_read_unlock();
if (!task) { if (!task) {
rc = -ESRCH; rc = -ESRCH;
goto free_proc_pages; goto free_proc_pages;
......
...@@ -250,15 +250,10 @@ int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3, ...@@ -250,15 +250,10 @@ int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
} else { } else {
struct task_struct *tracer; struct task_struct *tracer;
rcu_read_lock(); tracer = find_get_task_by_vpid(arg2);
tracer = find_task_by_vpid(arg2); if (!tracer) {
if (tracer)
get_task_struct(tracer);
else
rc = -EINVAL; rc = -EINVAL;
rcu_read_unlock(); } else {
if (tracer) {
rc = yama_ptracer_add(tracer, myself); rc = yama_ptracer_add(tracer, myself);
put_task_struct(tracer); put_task_struct(tracer);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment