Commit 6d7b2f5f9e88902b19f91d0c8a7ef58a5455f1a2
Committed by
Linus Torvalds
1 parent
db7f47cf48
Exists in
master
and in
4 other branches
cpusets: prevent PF_THREAD_BOUND tasks from attaching to non-root cpusets
Kthreads that have the PF_THREAD_BOUND bit set in their flags are bound to a specific cpu. Thus, their set of allowed cpus shall not change. This patch prevents such threads from attaching to non-root cpusets. They do not have mempolicies that restrict them to a subset of system nodes and, since their cpumask may never change, they cannot use any of the features of cpusets. The tasks will forever be a member of the root cpuset and will be returned when listing the tasks attached to that cpuset. Cc: Paul Menage <menage@google.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Dhaval Giani <dhaval@linux.vnet.ibm.com> Signed-off-by: David Rientjes <rientjes@google.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 11 additions and 8 deletions Side-by-side Diff
kernel/cpuset.c
... | ... | @@ -1342,19 +1342,22 @@ |
1342 | 1342 | struct cgroup *cont, struct task_struct *tsk) |
1343 | 1343 | { |
1344 | 1344 | struct cpuset *cs = cgroup_cs(cont); |
1345 | - int ret = 0; | |
1346 | 1345 | |
1347 | 1346 | if (cpumask_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed)) |
1348 | 1347 | return -ENOSPC; |
1349 | 1348 | |
1350 | - if (tsk->flags & PF_THREAD_BOUND) { | |
1351 | - mutex_lock(&callback_mutex); | |
1352 | - if (!cpumask_equal(&tsk->cpus_allowed, cs->cpus_allowed)) | |
1353 | - ret = -EINVAL; | |
1354 | - mutex_unlock(&callback_mutex); | |
1355 | - } | |
1349 | + /* | |
1350 | + * Kthreads bound to specific cpus cannot be moved to a new cpuset; we | |
1351 | + * cannot change their cpu affinity and isolating such threads by their | |
1352 | + * set of allowed nodes is unnecessary. Thus, cpusets are not | |
1353 | + * applicable for such threads. This prevents checking for success of | |
1354 | + * set_cpus_allowed_ptr() on all attached tasks before cpus_allowed may | |
1355 | + * be changed. | |
1356 | + */ | |
1357 | + if (tsk->flags & PF_THREAD_BOUND) | |
1358 | + return -EINVAL; | |
1356 | 1359 | |
1357 | - return ret < 0 ? ret : security_task_setscheduler(tsk, 0, NULL); | |
1360 | + return security_task_setscheduler(tsk, 0, NULL); | |
1358 | 1361 | } |
1359 | 1362 | |
1360 | 1363 | static void cpuset_attach(struct cgroup_subsys *ss, |