Skip to content

Commit 8ab293e

Browse files
committed
Merge branch 'for-4.8-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
Pull cgroup fixes from Tejun Heo: "Three late fixes for cgroup: Two cpuset ones, one trivial and the other pretty obscure, and a cgroup core fix for a bug which impacts cgroup v2 namespace users" * 'for-4.8-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup: cgroup: fix invalid controller enable rejections with cgroup namespace cpuset: fix non static symbol warning cpuset: handle race between CPU hotplug and cpuset_hotplug_work
2 parents 08895a8 + 9157056 commit 8ab293e

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

kernel/cgroup.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3446,9 +3446,28 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
34463446
* Except for the root, subtree_control must be zero for a cgroup
34473447
* with tasks so that child cgroups don't compete against tasks.
34483448
*/
3449-
if (enable && cgroup_parent(cgrp) && !list_empty(&cgrp->cset_links)) {
3450-
ret = -EBUSY;
3451-
goto out_unlock;
3449+
if (enable && cgroup_parent(cgrp)) {
3450+
struct cgrp_cset_link *link;
3451+
3452+
/*
3453+
* Because namespaces pin csets too, @cgrp->cset_links
3454+
* might not be empty even when @cgrp is empty. Walk and
3455+
* verify each cset.
3456+
*/
3457+
spin_lock_irq(&css_set_lock);
3458+
3459+
ret = 0;
3460+
list_for_each_entry(link, &cgrp->cset_links, cset_link) {
3461+
if (css_set_populated(link->cset)) {
3462+
ret = -EBUSY;
3463+
break;
3464+
}
3465+
}
3466+
3467+
spin_unlock_irq(&css_set_lock);
3468+
3469+
if (ret)
3470+
goto out_unlock;
34523471
}
34533472

34543473
/* save and update control masks and prepare csses */
@@ -3899,7 +3918,9 @@ void cgroup_file_notify(struct cgroup_file *cfile)
38993918
* cgroup_task_count - count the number of tasks in a cgroup.
39003919
* @cgrp: the cgroup in question
39013920
*
3902-
* Return the number of tasks in the cgroup.
3921+
* Return the number of tasks in the cgroup. The returned number can be
3922+
* higher than the actual number of tasks due to css_set references from
3923+
* namespace roots and temporary usages.
39033924
*/
39043925
static int cgroup_task_count(const struct cgroup *cgrp)
39053926
{

kernel/cpuset.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,7 @@ static struct file_system_type cpuset_fs_type = {
325325
/*
326326
* Return in pmask the portion of a cpusets's cpus_allowed that
327327
* are online. If none are online, walk up the cpuset hierarchy
328-
* until we find one that does have some online cpus. The top
329-
* cpuset always has some cpus online.
328+
* until we find one that does have some online cpus.
330329
*
331330
* One way or another, we guarantee to return some non-empty subset
332331
* of cpu_online_mask.
@@ -335,8 +334,20 @@ static struct file_system_type cpuset_fs_type = {
335334
*/
336335
static void guarantee_online_cpus(struct cpuset *cs, struct cpumask *pmask)
337336
{
338-
while (!cpumask_intersects(cs->effective_cpus, cpu_online_mask))
337+
while (!cpumask_intersects(cs->effective_cpus, cpu_online_mask)) {
339338
cs = parent_cs(cs);
339+
if (unlikely(!cs)) {
340+
/*
341+
* The top cpuset doesn't have any online cpu as a
342+
* consequence of a race between cpuset_hotplug_work
343+
* and cpu hotplug notifier. But we know the top
344+
* cpuset's effective_cpus is on its way to to be
345+
* identical to cpu_online_mask.
346+
*/
347+
cpumask_copy(pmask, cpu_online_mask);
348+
return;
349+
}
350+
}
340351
cpumask_and(pmask, cs->effective_cpus, cpu_online_mask);
341352
}
342353

@@ -2074,7 +2085,7 @@ static void cpuset_bind(struct cgroup_subsys_state *root_css)
20742085
* which could have been changed by cpuset just after it inherits the
20752086
* state from the parent and before it sits on the cgroup's task list.
20762087
*/
2077-
void cpuset_fork(struct task_struct *task)
2088+
static void cpuset_fork(struct task_struct *task)
20782089
{
20792090
if (task_css_is_root(task, cpuset_cgrp_id))
20802091
return;

0 commit comments

Comments
 (0)