History

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.

Tejun Heo committed 13 years ago

Commit 14a40ff1 parent 2e109a26 files · +19 −24Browse files

Showing the changes to kernel/workqueue.c (1 of 6 files). Show all

Unified · Split

kernel/workqueue.c+3−7
@@ -1757,12 +1757,8 @@ static struct worker *create_worker(struct worker_pool *pool) · 1756 unmodified lines
17571757 set_user_nice(worker->task, pool->attrs->nice);
17581758 set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask);
17591759
1760− /*
1761− * %PF_THREAD_BOUND is used to prevent userland from meddling with
1762− * cpumask of workqueue workers. This is an abuse. We need
1763− * %PF_NO_SETAFFINITY.
1764− */
1765− worker->task->flags |= PF_THREAD_BOUND;
1760+ /* prevent userland from meddling with cpumask of workqueue workers */
1761+ worker->task->flags |= PF_NO_SETAFFINITY;
17661762
17671763 /*
17681764 * The caller is responsible for ensuring %POOL_DISASSOCIATED
@@ -3876,7 +3872,7 @@ struct workqueue_struct *__alloc_workqueue_key(const char *fmt, · 2107 unmodified lines
38763872 }
38773873
38783874 wq->rescuer = rescuer;
3879− rescuer->task->flags |= PF_THREAD_BOUND;
3875+ rescuer->task->flags |= PF_NO_SETAFFINITY;
38803876 wake_up_process(rescuer->task);
38813877 }
38823878