diff options
author | Tejun Heo <tj@kernel.org> | 2013-03-19 16:45:20 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2013-03-19 16:45:20 -0400 |
commit | 14a40ffccd6163bbcd1d6f32b28a88ffe6149fc6 (patch) | |
tree | eb61e5bf7b64c3e67f3e33fe6b07fde4ee1d4d43 /kernel/sched/core.c | |
parent | 2e109a2855bf6cf675a8b74dbd89b6492e8def42 (diff) |
sched: replace PF_THREAD_BOUND with PF_NO_SETAFFINITY
PF_THREAD_BOUND was originally used to mark kernel threads which were
bound to a specific CPU using kthread_bind() and a task with the flag
set allows cpus_allowed modifications only to itself. Workqueue is
currently abusing it to prevent userland from meddling with
cpus_allowed of workqueue workers.
What we need is a flag to prevent userland from messing with
cpus_allowed of certain kernel tasks. In kernel, anyone can
(incorrectly) squash the flag, and, for worker-type usages,
restricting cpus_allowed modification to the task itself doesn't
provide meaningful extra proection as other tasks can inject work
items to the task anyway.
This patch replaces PF_THREAD_BOUND with PF_NO_SETAFFINITY.
sched_setaffinity() checks the flag and return -EINVAL if set.
set_cpus_allowed_ptr() is no longer affected by the flag.
This will allow simplifying workqueue worker CPU affinity management.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel/sched/core.c')
-rw-r--r-- | kernel/sched/core.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 7f12624a393c..23606ee961b5 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c | |||
@@ -4126,6 +4126,10 @@ long sched_setaffinity(pid_t pid, const struct cpumask *in_mask) | |||
4126 | get_task_struct(p); | 4126 | get_task_struct(p); |
4127 | rcu_read_unlock(); | 4127 | rcu_read_unlock(); |
4128 | 4128 | ||
4129 | if (p->flags & PF_NO_SETAFFINITY) { | ||
4130 | retval = -EINVAL; | ||
4131 | goto out_put_task; | ||
4132 | } | ||
4129 | if (!alloc_cpumask_var(&cpus_allowed, GFP_KERNEL)) { | 4133 | if (!alloc_cpumask_var(&cpus_allowed, GFP_KERNEL)) { |
4130 | retval = -ENOMEM; | 4134 | retval = -ENOMEM; |
4131 | goto out_put_task; | 4135 | goto out_put_task; |
@@ -4773,11 +4777,6 @@ int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask) | |||
4773 | goto out; | 4777 | goto out; |
4774 | } | 4778 | } |
4775 | 4779 | ||
4776 | if (unlikely((p->flags & PF_THREAD_BOUND) && p != current)) { | ||
4777 | ret = -EINVAL; | ||
4778 | goto out; | ||
4779 | } | ||
4780 | |||
4781 | do_set_cpus_allowed(p, new_mask); | 4780 | do_set_cpus_allowed(p, new_mask); |
4782 | 4781 | ||
4783 | /* Can the task run on the task's current CPU? If so, we're done */ | 4782 | /* Can the task run on the task's current CPU? If so, we're done */ |