aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/sched
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2017-09-26 13:06:43 -0500
committerEric W. Biederman <ebiederm@xmission.com>2018-07-21 10:43:12 -0500
commit2c4704756cab7cfa031ada4dab361562f0e357c0 (patch)
tree8757eb8762d60e34eeab747493759abf3f902c09 /include/linux/sched
parentkvm: Don't open code task_pid in kvm_vcpu_ioctl (diff)
downloadlinux-dev-2c4704756cab7cfa031ada4dab361562f0e357c0.tar.xz
linux-dev-2c4704756cab7cfa031ada4dab361562f0e357c0.zip
pids: Move the pgrp and session pid pointers from task_struct to signal_struct
To access these fields the code always has to go to group leader so going to signal struct is no loss and is actually a fundamental simplification. This saves a little bit of memory by only allocating the pid pointer array once instead of once for every thread, and even better this removes a few potential races caused by the fact that group_leader can be changed by de_thread, while signal_struct can not. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Diffstat (limited to 'include/linux/sched')
-rw-r--r--include/linux/sched/signal.h26
1 files changed, 23 insertions, 3 deletions
diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h
index b95a272c1ab5..2dcded16eb1e 100644
--- a/include/linux/sched/signal.h
+++ b/include/linux/sched/signal.h
@@ -146,7 +146,9 @@ struct signal_struct {
#endif
+ /* PID/PID hash table linkage. */
struct pid *leader_pid;
+ struct pid *pids[PIDTYPE_MAX];
#ifdef CONFIG_NO_HZ_FULL
atomic_t tick_dep_mask;
@@ -559,9 +561,12 @@ void walk_process_tree(struct task_struct *top, proc_visitor, void *);
static inline
struct pid *task_pid_type(struct task_struct *task, enum pid_type type)
{
- if (type != PIDTYPE_PID)
- task = task->group_leader;
- return task->pids[type].pid;
+ struct pid *pid;
+ if (type == PIDTYPE_PID)
+ pid = task_pid(task);
+ else
+ pid = task->signal->pids[type];
+ return pid;
}
static inline struct pid *task_tgid(struct task_struct *task)
@@ -569,6 +574,21 @@ static inline struct pid *task_tgid(struct task_struct *task)
return task->signal->leader_pid;
}
+/*
+ * Without tasklist or RCU lock it is not safe to dereference
+ * the result of task_pgrp/task_session even if task == current,
+ * we can race with another thread doing sys_setsid/sys_setpgid.
+ */
+static inline struct pid *task_pgrp(struct task_struct *task)
+{
+ return task->signal->pids[PIDTYPE_PGID];
+}
+
+static inline struct pid *task_session(struct task_struct *task)
+{
+ return task->signal->pids[PIDTYPE_SID];
+}
+
static inline int get_nr_threads(struct task_struct *tsk)
{
return tsk->signal->nr_threads;