Commit 228ebcbe authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Linus Torvalds

Uninline find_task_by_xxx set of functions

The find_task_by_something is a set of macros are used to find task by pid
depending on what kind of pid is proposed - global or virtual one.  All of
them are wrappers above the most generic one - find_task_by_pid_type_ns() -
and just substitute some args for it.

It turned out, that dereferencing the current->nsproxy->pid_ns construction
and pushing one more argument on the stack inline cause kernel text size to
grow.

This patch moves all this stuff out-of-line into kernel/pid.c.  Together
with the next patch it saves a bit less than 400 bytes from the .text
section.
Signed-off-by: default avatarPavel Emelyanov <xemul@openvz.org>
Cc: Sukadev Bhattiprolu <sukadev@us.ibm.com>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Paul Menage <menage@google.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Acked-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b488893a
...@@ -94,8 +94,7 @@ asmlinkage long sys_ioprio_set(int which, int who, int ioprio) ...@@ -94,8 +94,7 @@ asmlinkage long sys_ioprio_set(int which, int who, int ioprio)
if (!who) if (!who)
p = current; p = current;
else else
p = find_task_by_pid_ns(who, p = find_task_by_vpid(who);
current->nsproxy->pid_ns);
if (p) if (p)
ret = set_task_ioprio(p, ioprio); ret = set_task_ioprio(p, ioprio);
break; break;
...@@ -182,8 +181,7 @@ asmlinkage long sys_ioprio_get(int which, int who) ...@@ -182,8 +181,7 @@ asmlinkage long sys_ioprio_get(int which, int who)
if (!who) if (!who)
p = current; p = current;
else else
p = find_task_by_pid_ns(who, p = find_task_by_vpid(who);
current->nsproxy->pid_ns);
if (p) if (p)
ret = get_task_ioprio(p); ret = get_task_ioprio(p);
break; break;
......
...@@ -1523,9 +1523,8 @@ extern struct pid_namespace init_pid_ns; ...@@ -1523,9 +1523,8 @@ extern struct pid_namespace init_pid_ns;
* type and namespace specified * type and namespace specified
* find_task_by_pid_ns(): * find_task_by_pid_ns():
* finds a task by its pid in the specified namespace * finds a task by its pid in the specified namespace
* find_task_by_pid_type(): * find_task_by_vpid():
* finds a task by its global id with the specified type, e.g. * finds a task by its virtual pid
* by global session id
* find_task_by_pid(): * find_task_by_pid():
* finds a task by its global pid * finds a task by its global pid
* *
...@@ -1535,12 +1534,10 @@ extern struct pid_namespace init_pid_ns; ...@@ -1535,12 +1534,10 @@ extern struct pid_namespace init_pid_ns;
extern struct task_struct *find_task_by_pid_type_ns(int type, int pid, extern struct task_struct *find_task_by_pid_type_ns(int type, int pid,
struct pid_namespace *ns); struct pid_namespace *ns);
#define find_task_by_pid_ns(nr, ns) \ extern struct task_struct *find_task_by_pid(pid_t nr);
find_task_by_pid_type_ns(PIDTYPE_PID, nr, ns) extern struct task_struct *find_task_by_vpid(pid_t nr);
#define find_task_by_pid_type(type, nr) \ extern struct task_struct *find_task_by_pid_ns(pid_t nr,
find_task_by_pid_type_ns(type, nr, &init_pid_ns) struct pid_namespace *ns);
#define find_task_by_pid(nr) \
find_task_by_pid_type(PIDTYPE_PID, nr)
extern void __set_special_pids(pid_t session, pid_t pgrp); extern void __set_special_pids(pid_t session, pid_t pgrp);
......
...@@ -63,8 +63,7 @@ asmlinkage long sys_capget(cap_user_header_t header, cap_user_data_t dataptr) ...@@ -63,8 +63,7 @@ asmlinkage long sys_capget(cap_user_header_t header, cap_user_data_t dataptr)
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
if (pid && pid != task_pid_vnr(current)) { if (pid && pid != task_pid_vnr(current)) {
target = find_task_by_pid_ns(pid, target = find_task_by_vpid(pid);
current->nsproxy->pid_ns);
if (!target) { if (!target) {
ret = -ESRCH; ret = -ESRCH;
goto out; goto out;
...@@ -198,8 +197,7 @@ asmlinkage long sys_capset(cap_user_header_t header, const cap_user_data_t data) ...@@ -198,8 +197,7 @@ asmlinkage long sys_capset(cap_user_header_t header, const cap_user_data_t data)
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
if (pid > 0 && pid != task_pid_vnr(current)) { if (pid > 0 && pid != task_pid_vnr(current)) {
target = find_task_by_pid_ns(pid, target = find_task_by_vpid(pid);
current->nsproxy->pid_ns);
if (!target) { if (!target) {
ret = -ESRCH; ret = -ESRCH;
goto out; goto out;
......
...@@ -446,9 +446,7 @@ static struct task_struct * futex_find_get_task(pid_t pid) ...@@ -446,9 +446,7 @@ static struct task_struct * futex_find_get_task(pid_t pid)
struct task_struct *p; struct task_struct *p;
rcu_read_lock(); rcu_read_lock();
p = find_task_by_pid_ns(pid, p = find_task_by_vpid(pid);
current->nsproxy->pid_ns);
if (!p || ((current->euid != p->euid) && (current->euid != p->uid))) if (!p || ((current->euid != p->euid) && (current->euid != p->uid)))
p = ERR_PTR(-ESRCH); p = ERR_PTR(-ESRCH);
else else
...@@ -1858,8 +1856,7 @@ sys_get_robust_list(int pid, struct robust_list_head __user * __user *head_ptr, ...@@ -1858,8 +1856,7 @@ sys_get_robust_list(int pid, struct robust_list_head __user * __user *head_ptr,
ret = -ESRCH; ret = -ESRCH;
rcu_read_lock(); rcu_read_lock();
p = find_task_by_pid_ns(pid, p = find_task_by_vpid(pid);
current->nsproxy->pid_ns);
if (!p) if (!p)
goto err_unlock; goto err_unlock;
ret = -EPERM; ret = -EPERM;
......
...@@ -125,8 +125,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr, ...@@ -125,8 +125,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
ret = -ESRCH; ret = -ESRCH;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
p = find_task_by_pid_ns(pid, p = find_task_by_vpid(pid);
current->nsproxy->pid_ns);
if (!p) if (!p)
goto err_unlock; goto err_unlock;
ret = -EPERM; ret = -EPERM;
......
...@@ -369,6 +369,25 @@ struct task_struct *find_task_by_pid_type_ns(int type, int nr, ...@@ -369,6 +369,25 @@ struct task_struct *find_task_by_pid_type_ns(int type, int nr,
EXPORT_SYMBOL(find_task_by_pid_type_ns); EXPORT_SYMBOL(find_task_by_pid_type_ns);
struct task_struct *find_task_by_pid(pid_t nr)
{
return find_task_by_pid_type_ns(PIDTYPE_PID, nr, &init_pid_ns);
}
EXPORT_SYMBOL(find_task_by_pid);
struct task_struct *find_task_by_vpid(pid_t vnr)
{
return find_task_by_pid_type_ns(PIDTYPE_PID, vnr,
current->nsproxy->pid_ns);
}
EXPORT_SYMBOL(find_task_by_vpid);
struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
{
return find_task_by_pid_type_ns(PIDTYPE_PID, nr, ns);
}
EXPORT_SYMBOL(find_task_by_pid_ns);
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;
......
...@@ -444,8 +444,7 @@ struct task_struct *ptrace_get_task_struct(pid_t pid) ...@@ -444,8 +444,7 @@ struct task_struct *ptrace_get_task_struct(pid_t pid)
return ERR_PTR(-EPERM); return ERR_PTR(-EPERM);
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
child = find_task_by_pid_ns(pid, child = find_task_by_vpid(pid);
current->nsproxy->pid_ns);
if (child) if (child)
get_task_struct(child); get_task_struct(child);
......
...@@ -4168,8 +4168,7 @@ struct task_struct *idle_task(int cpu) ...@@ -4168,8 +4168,7 @@ struct task_struct *idle_task(int cpu)
*/ */
static struct task_struct *find_process_by_pid(pid_t pid) static struct task_struct *find_process_by_pid(pid_t pid)
{ {
return pid ? return pid ? find_task_by_vpid(pid) : current;
find_task_by_pid_ns(pid, current->nsproxy->pid_ns) : current;
} }
/* Actually do priority change: must hold rq lock. */ /* Actually do priority change: must hold rq lock. */
......
...@@ -2237,7 +2237,7 @@ static int do_tkill(int tgid, int pid, int sig) ...@@ -2237,7 +2237,7 @@ static int do_tkill(int tgid, int pid, int sig)
info.si_uid = current->uid; info.si_uid = current->uid;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
p = find_task_by_pid_ns(pid, current->nsproxy->pid_ns); p = find_task_by_vpid(pid);
if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) { if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
error = check_kill_permission(sig, &info, p); error = check_kill_permission(sig, &info, p);
/* /*
......
...@@ -152,8 +152,7 @@ asmlinkage long sys_setpriority(int which, int who, int niceval) ...@@ -152,8 +152,7 @@ asmlinkage long sys_setpriority(int which, int who, int niceval)
switch (which) { switch (which) {
case PRIO_PROCESS: case PRIO_PROCESS:
if (who) if (who)
p = find_task_by_pid_ns(who, p = find_task_by_vpid(who);
current->nsproxy->pid_ns);
else else
p = current; p = current;
if (p) if (p)
...@@ -210,8 +209,7 @@ asmlinkage long sys_getpriority(int which, int who) ...@@ -210,8 +209,7 @@ asmlinkage long sys_getpriority(int which, int who)
switch (which) { switch (which) {
case PRIO_PROCESS: case PRIO_PROCESS:
if (who) if (who)
p = find_task_by_pid_ns(who, p = find_task_by_vpid(who);
current->nsproxy->pid_ns);
else else
p = current; p = current;
if (p) { if (p) {
...@@ -1067,7 +1065,8 @@ asmlinkage long sys_setsid(void) ...@@ -1067,7 +1065,8 @@ asmlinkage long sys_setsid(void)
* session id and so the check will always fail and make it so * session id and so the check will always fail and make it so
* init cannot successfully call setsid. * init cannot successfully call setsid.
*/ */
if (session > 1 && find_task_by_pid_type(PIDTYPE_PGID, session)) if (session > 1 && find_task_by_pid_type_ns(PIDTYPE_PGID,
session, &init_pid_ns))
goto out; goto out;
group_leader->signal->leader = 1; group_leader->signal->leader = 1;
......
...@@ -941,8 +941,7 @@ asmlinkage long sys_migrate_pages(pid_t pid, unsigned long maxnode, ...@@ -941,8 +941,7 @@ asmlinkage long sys_migrate_pages(pid_t pid, unsigned long maxnode,
/* Find the mm_struct */ /* Find the mm_struct */
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
task = pid ? task = pid ? find_task_by_vpid(pid) : current;
find_task_by_pid_ns(pid, current->nsproxy->pid_ns) : current;
if (!task) { if (!task) {
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
return -ESRCH; return -ESRCH;
......
...@@ -925,8 +925,7 @@ asmlinkage long sys_move_pages(pid_t pid, unsigned long nr_pages, ...@@ -925,8 +925,7 @@ asmlinkage long sys_move_pages(pid_t pid, unsigned long nr_pages,
/* Find the mm_struct */ /* Find the mm_struct */
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
task = pid ? task = pid ? find_task_by_vpid(pid) : current;
find_task_by_pid_ns(pid, current->nsproxy->pid_ns) : current;
if (!task) { if (!task) {
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
return -ESRCH; return -ESRCH;
......
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