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/workqueue.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/workqueue.c')
-rw-r--r-- | kernel/workqueue.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 969be0b72071..39a591f65b08 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
@@ -1757,12 +1757,8 @@ static struct worker *create_worker(struct worker_pool *pool) | |||
1757 | set_user_nice(worker->task, pool->attrs->nice); | 1757 | set_user_nice(worker->task, pool->attrs->nice); |
1758 | set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask); | 1758 | set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask); |
1759 | 1759 | ||
1760 | /* | 1760 | /* prevent userland from meddling with cpumask of workqueue workers */ |
1761 | * %PF_THREAD_BOUND is used to prevent userland from meddling with | 1761 | worker->task->flags |= PF_NO_SETAFFINITY; |
1762 | * cpumask of workqueue workers. This is an abuse. We need | ||
1763 | * %PF_NO_SETAFFINITY. | ||
1764 | */ | ||
1765 | worker->task->flags |= PF_THREAD_BOUND; | ||
1766 | 1762 | ||
1767 | /* | 1763 | /* |
1768 | * The caller is responsible for ensuring %POOL_DISASSOCIATED | 1764 | * The caller is responsible for ensuring %POOL_DISASSOCIATED |
@@ -3876,7 +3872,7 @@ struct workqueue_struct *__alloc_workqueue_key(const char *fmt, | |||
3876 | } | 3872 | } |
3877 | 3873 | ||
3878 | wq->rescuer = rescuer; | 3874 | wq->rescuer = rescuer; |
3879 | rescuer->task->flags |= PF_THREAD_BOUND; | 3875 | rescuer->task->flags |= PF_NO_SETAFFINITY; |
3880 | wake_up_process(rescuer->task); | 3876 | wake_up_process(rescuer->task); |
3881 | } | 3877 | } |
3882 | 3878 | ||