Skip to content

Commit 17cf22c

Browse files
committed
pidns: Use task_active_pid_ns where appropriate
The expressions tsk->nsproxy->pid_ns and task_active_pid_ns aka ns_of_pid(task_pid(tsk)) should have the same number of cache line misses with the practical difference that ns_of_pid(task_pid(tsk)) is released later in a processes life. Furthermore by using task_active_pid_ns it becomes trivial to write an unshare implementation for the the pid namespace. So I have used task_active_pid_ns everywhere I can. In fork since the pid has not yet been attached to the process I use ns_of_pid, to achieve the same effect. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
1 parent 49f4d8b commit 17cf22c

12 files changed

Lines changed: 16 additions & 15 deletions

File tree

arch/powerpc/platforms/cell/spufs/sched.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ static int show_spu_loadavg(struct seq_file *s, void *private)
10941094
LOAD_INT(c), LOAD_FRAC(c),
10951095
count_active_contexts(),
10961096
atomic_read(&nr_spu_contexts),
1097-
current->nsproxy->pid_ns->last_pid);
1097+
task_active_pid_ns(current)->last_pid);
10981098
return 0;
10991099
}
11001100

arch/um/drivers/mconsole_kern.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void mconsole_log(struct mc_request *req)
123123

124124
void mconsole_proc(struct mc_request *req)
125125
{
126-
struct vfsmount *mnt = current->nsproxy->pid_ns->proc_mnt;
126+
struct vfsmount *mnt = task_active_pid_ns(current)->proc_mnt;
127127
char *buf;
128128
int len;
129129
struct file *file;

drivers/staging/android/binder.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/uaccess.h>
3434
#include <linux/vmalloc.h>
3535
#include <linux/slab.h>
36+
#include <linux/pid_namespace.h>
3637

3738
#include "binder.h"
3839

@@ -2344,7 +2345,7 @@ static int binder_thread_read(struct binder_proc *proc,
23442345
if (t->from) {
23452346
struct task_struct *sender = t->from->proc->tsk;
23462347
tr.sender_pid = task_tgid_nr_ns(sender,
2347-
current->nsproxy->pid_ns);
2348+
task_active_pid_ns(current));
23482349
} else {
23492350
tr.sender_pid = 0;
23502351
}

fs/hppfs/hppfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ static int hppfs_fill_super(struct super_block *sb, void *d, int silent)
710710
struct vfsmount *proc_mnt;
711711
int err = -ENOENT;
712712

713-
proc_mnt = mntget(current->nsproxy->pid_ns->proc_mnt);
713+
proc_mnt = mntget(task_active_pid_ns(current)->proc_mnt);
714714
if (IS_ERR(proc_mnt))
715715
goto out;
716716

fs/proc/root.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static struct dentry *proc_mount(struct file_system_type *fs_type,
106106
ns = (struct pid_namespace *)data;
107107
options = NULL;
108108
} else {
109-
ns = current->nsproxy->pid_ns;
109+
ns = task_active_pid_ns(current);
110110
options = data;
111111
}
112112

kernel/cgroup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3390,7 +3390,7 @@ static struct cgroup_pidlist *cgroup_pidlist_find(struct cgroup *cgrp,
33903390
{
33913391
struct cgroup_pidlist *l;
33923392
/* don't need task_nsproxy() if we're looking at ourself */
3393-
struct pid_namespace *ns = current->nsproxy->pid_ns;
3393+
struct pid_namespace *ns = task_active_pid_ns(current);
33943394

33953395
/*
33963396
* We can't drop the pidlist_mutex before taking the l->mutex in case

kernel/events/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6155,7 +6155,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
61556155

61566156
event->parent = parent_event;
61576157

6158-
event->ns = get_pid_ns(current->nsproxy->pid_ns);
6158+
event->ns = get_pid_ns(task_active_pid_ns(current));
61596159
event->id = atomic64_inc_return(&perf_event_id);
61606160

61616161
event->state = PERF_EVENT_STATE_INACTIVE;

kernel/fork.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
14421442

14431443
if (thread_group_leader(p)) {
14441444
if (is_child_reaper(pid))
1445-
p->nsproxy->pid_ns->child_reaper = p;
1445+
ns_of_pid(pid)->child_reaper = p;
14461446

14471447
p->signal->leader_pid = pid;
14481448
p->signal->tty = tty_kref_get(current->signal->tty);

kernel/nsproxy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,
8484
goto out_ipc;
8585
}
8686

87-
new_nsp->pid_ns = copy_pid_ns(flags, task_cred_xxx(tsk, user_ns), task_active_pid_ns(tsk));
87+
new_nsp->pid_ns = copy_pid_ns(flags, task_cred_xxx(tsk, user_ns), tsk->nsproxy->pid_ns);
8888
if (IS_ERR(new_nsp->pid_ns)) {
8989
err = PTR_ERR(new_nsp->pid_ns);
9090
goto out_pid;

kernel/pid.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
345345

346346
struct pid *find_vpid(int nr)
347347
{
348-
return find_pid_ns(nr, current->nsproxy->pid_ns);
348+
return find_pid_ns(nr, task_active_pid_ns(current));
349349
}
350350
EXPORT_SYMBOL_GPL(find_vpid);
351351

@@ -429,7 +429,7 @@ struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
429429

430430
struct task_struct *find_task_by_vpid(pid_t vnr)
431431
{
432-
return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
432+
return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
433433
}
434434

435435
struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
@@ -484,7 +484,7 @@ EXPORT_SYMBOL_GPL(pid_nr_ns);
484484

485485
pid_t pid_vnr(struct pid *pid)
486486
{
487-
return pid_nr_ns(pid, current->nsproxy->pid_ns);
487+
return pid_nr_ns(pid, task_active_pid_ns(current));
488488
}
489489
EXPORT_SYMBOL_GPL(pid_vnr);
490490

@@ -495,7 +495,7 @@ pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
495495

496496
rcu_read_lock();
497497
if (!ns)
498-
ns = current->nsproxy->pid_ns;
498+
ns = task_active_pid_ns(current);
499499
if (likely(pid_alive(task))) {
500500
if (type != PIDTYPE_PID)
501501
task = task->group_leader;

0 commit comments

Comments
 (0)