Skip to content

Commit 228ebcb

Browse files
xemulLinus Torvalds
authored andcommitted
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: Pavel 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: Ingo Molnar <mingo@elte.hu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b488893 commit 228ebcb

12 files changed

Lines changed: 41 additions & 38 deletions

File tree

‎fs/ioprio.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ asmlinkage long sys_ioprio_set(int which, int who, int ioprio)
9494
if (!who)
9595
p = current;
9696
else
97-
p = find_task_by_pid_ns(who,
98-
current->nsproxy->pid_ns);
97+
p = find_task_by_vpid(who);
9998
if (p)
10099
ret = set_task_ioprio(p, ioprio);
101100
break;
@@ -182,8 +181,7 @@ asmlinkage long sys_ioprio_get(int which, int who)
182181
if (!who)
183182
p = current;
184183
else
185-
p = find_task_by_pid_ns(who,
186-
current->nsproxy->pid_ns);
184+
p = find_task_by_vpid(who);
187185
if (p)
188186
ret = get_task_ioprio(p);
189187
break;

‎include/linux/sched.h‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,9 +1523,8 @@ extern struct pid_namespace init_pid_ns;
15231523
* type and namespace specified
15241524
* find_task_by_pid_ns():
15251525
* finds a task by its pid in the specified namespace
1526-
* find_task_by_pid_type():
1527-
* finds a task by its global id with the specified type, e.g.
1528-
* by global session id
1526+
* find_task_by_vpid():
1527+
* finds a task by its virtual pid
15291528
* find_task_by_pid():
15301529
* finds a task by its global pid
15311530
*
@@ -1535,12 +1534,10 @@ extern struct pid_namespace init_pid_ns;
15351534
extern struct task_struct *find_task_by_pid_type_ns(int type, int pid,
15361535
struct pid_namespace *ns);
15371536

1538-
#define find_task_by_pid_ns(nr, ns) \
1539-
find_task_by_pid_type_ns(PIDTYPE_PID, nr, ns)
1540-
#define find_task_by_pid_type(type, nr) \
1541-
find_task_by_pid_type_ns(type, nr, &init_pid_ns)
1542-
#define find_task_by_pid(nr) \
1543-
find_task_by_pid_type(PIDTYPE_PID, nr)
1537+
extern struct task_struct *find_task_by_pid(pid_t nr);
1538+
extern struct task_struct *find_task_by_vpid(pid_t nr);
1539+
extern struct task_struct *find_task_by_pid_ns(pid_t nr,
1540+
struct pid_namespace *ns);
15441541

15451542
extern void __set_special_pids(pid_t session, pid_t pgrp);
15461543

‎kernel/capability.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ asmlinkage long sys_capget(cap_user_header_t header, cap_user_data_t dataptr)
6363
read_lock(&tasklist_lock);
6464

6565
if (pid && pid != task_pid_vnr(current)) {
66-
target = find_task_by_pid_ns(pid,
67-
current->nsproxy->pid_ns);
66+
target = find_task_by_vpid(pid);
6867
if (!target) {
6968
ret = -ESRCH;
7069
goto out;
@@ -198,8 +197,7 @@ asmlinkage long sys_capset(cap_user_header_t header, const cap_user_data_t data)
198197
read_lock(&tasklist_lock);
199198

200199
if (pid > 0 && pid != task_pid_vnr(current)) {
201-
target = find_task_by_pid_ns(pid,
202-
current->nsproxy->pid_ns);
200+
target = find_task_by_vpid(pid);
203201
if (!target) {
204202
ret = -ESRCH;
205203
goto out;

‎kernel/futex.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,7 @@ static struct task_struct * futex_find_get_task(pid_t pid)
446446
struct task_struct *p;
447447

448448
rcu_read_lock();
449-
p = find_task_by_pid_ns(pid,
450-
current->nsproxy->pid_ns);
451-
449+
p = find_task_by_vpid(pid);
452450
if (!p || ((current->euid != p->euid) && (current->euid != p->uid)))
453451
p = ERR_PTR(-ESRCH);
454452
else
@@ -1858,8 +1856,7 @@ sys_get_robust_list(int pid, struct robust_list_head __user * __user *head_ptr,
18581856

18591857
ret = -ESRCH;
18601858
rcu_read_lock();
1861-
p = find_task_by_pid_ns(pid,
1862-
current->nsproxy->pid_ns);
1859+
p = find_task_by_vpid(pid);
18631860
if (!p)
18641861
goto err_unlock;
18651862
ret = -EPERM;

‎kernel/futex_compat.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
125125

126126
ret = -ESRCH;
127127
read_lock(&tasklist_lock);
128-
p = find_task_by_pid_ns(pid,
129-
current->nsproxy->pid_ns);
128+
p = find_task_by_vpid(pid);
130129
if (!p)
131130
goto err_unlock;
132131
ret = -EPERM;

‎kernel/pid.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,25 @@ struct task_struct *find_task_by_pid_type_ns(int type, int nr,
369369

370370
EXPORT_SYMBOL(find_task_by_pid_type_ns);
371371

372+
struct task_struct *find_task_by_pid(pid_t nr)
373+
{
374+
return find_task_by_pid_type_ns(PIDTYPE_PID, nr, &init_pid_ns);
375+
}
376+
EXPORT_SYMBOL(find_task_by_pid);
377+
378+
struct task_struct *find_task_by_vpid(pid_t vnr)
379+
{
380+
return find_task_by_pid_type_ns(PIDTYPE_PID, vnr,
381+
current->nsproxy->pid_ns);
382+
}
383+
EXPORT_SYMBOL(find_task_by_vpid);
384+
385+
struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
386+
{
387+
return find_task_by_pid_type_ns(PIDTYPE_PID, nr, ns);
388+
}
389+
EXPORT_SYMBOL(find_task_by_pid_ns);
390+
372391
struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
373392
{
374393
struct pid *pid;

‎kernel/ptrace.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,7 @@ struct task_struct *ptrace_get_task_struct(pid_t pid)
444444
return ERR_PTR(-EPERM);
445445

446446
read_lock(&tasklist_lock);
447-
child = find_task_by_pid_ns(pid,
448-
current->nsproxy->pid_ns);
447+
child = find_task_by_vpid(pid);
449448
if (child)
450449
get_task_struct(child);
451450

‎kernel/sched.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4168,8 +4168,7 @@ struct task_struct *idle_task(int cpu)
41684168
*/
41694169
static struct task_struct *find_process_by_pid(pid_t pid)
41704170
{
4171-
return pid ?
4172-
find_task_by_pid_ns(pid, current->nsproxy->pid_ns) : current;
4171+
return pid ? find_task_by_vpid(pid) : current;
41734172
}
41744173

41754174
/* Actually do priority change: must hold rq lock. */

‎kernel/signal.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2237,7 +2237,7 @@ static int do_tkill(int tgid, int pid, int sig)
22372237
info.si_uid = current->uid;
22382238

22392239
read_lock(&tasklist_lock);
2240-
p = find_task_by_pid_ns(pid, current->nsproxy->pid_ns);
2240+
p = find_task_by_vpid(pid);
22412241
if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
22422242
error = check_kill_permission(sig, &info, p);
22432243
/*

‎kernel/sys.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ asmlinkage long sys_setpriority(int which, int who, int niceval)
152152
switch (which) {
153153
case PRIO_PROCESS:
154154
if (who)
155-
p = find_task_by_pid_ns(who,
156-
current->nsproxy->pid_ns);
155+
p = find_task_by_vpid(who);
157156
else
158157
p = current;
159158
if (p)
@@ -210,8 +209,7 @@ asmlinkage long sys_getpriority(int which, int who)
210209
switch (which) {
211210
case PRIO_PROCESS:
212211
if (who)
213-
p = find_task_by_pid_ns(who,
214-
current->nsproxy->pid_ns);
212+
p = find_task_by_vpid(who);
215213
else
216214
p = current;
217215
if (p) {
@@ -1067,7 +1065,8 @@ asmlinkage long sys_setsid(void)
10671065
* session id and so the check will always fail and make it so
10681066
* init cannot successfully call setsid.
10691067
*/
1070-
if (session > 1 && find_task_by_pid_type(PIDTYPE_PGID, session))
1068+
if (session > 1 && find_task_by_pid_type_ns(PIDTYPE_PGID,
1069+
session, &init_pid_ns))
10711070
goto out;
10721071

10731072
group_leader->signal->leader = 1;

0 commit comments

Comments
 (0)