cgroup: fix the async css offline wait logic in cgroup_subtree_control_write()
When a subsystem is offlined, its entry on @cgrp->subsys[] is cleared asynchronously. If cgroup_subtree_control_write() is requested to enable the subsystem again before the entry is cleared, it has to wait for the previous offlining to finish and clear the @cgrp->subsys[] entry before trying to enable the subsystem again. This is currently done while verifying the input enable / disable parameters. This used to be correct butf63070d350
("cgroup: make interface files visible iff enabled on cgroup->subtree_control") breaks it. The commit is one of the commits implementing subsystem dependency. Through subsystem dependency, some subsystems may be enabled and disabled implicitly in addition to the explicitly requested ones. The actual subsystems to be enabled and disabled are determined during @css_enable/disable calculation. The current offline wait logic skips the ones which are already implicitly enabled and then waits for subsystems in @enable; however, this misses the subsystems which may be implicitly enabled through dependency from @enable. If such implicitly subsystem hasn't yet finished offlining yet, the function ends up trying to create a css when its @cgrp->subsys[] slot is already occupied triggering BUG_ON() in init_and_link_css(). Fix it by moving the wait logic after @css_enable is calculated and waiting for all the subsystems in @css_enable. This fixes the above bug as the mask contains all subsystems which are to be enabled including the ones enabled through dependencies. Signed-off-by: Tejun Heo <tj@kernel.org> Fixes:f63070d350
("cgroup: make interface files visible iff enabled on cgroup->subtree_control") Acked-by: Zefan Li <lizefan@huawei.com>
This commit is contained in:
Родитель
755bf5ee86
Коммит
db6e305345
|
@ -2705,36 +2705,6 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
|
||||||
ret = -ENOENT;
|
ret = -ENOENT;
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* @ss is already enabled through dependency and
|
|
||||||
* we'll just make it visible. Skip draining.
|
|
||||||
*/
|
|
||||||
if (cgrp->child_subsys_mask & (1 << ssid))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Because css offlining is asynchronous, userland
|
|
||||||
* might try to re-enable the same controller while
|
|
||||||
* the previous instance is still around. In such
|
|
||||||
* cases, wait till it's gone using offline_waitq.
|
|
||||||
*/
|
|
||||||
cgroup_for_each_live_child(child, cgrp) {
|
|
||||||
DEFINE_WAIT(wait);
|
|
||||||
|
|
||||||
if (!cgroup_css(child, ss))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
cgroup_get(child);
|
|
||||||
prepare_to_wait(&child->offline_waitq, &wait,
|
|
||||||
TASK_UNINTERRUPTIBLE);
|
|
||||||
cgroup_kn_unlock(of->kn);
|
|
||||||
schedule();
|
|
||||||
finish_wait(&child->offline_waitq, &wait);
|
|
||||||
cgroup_put(child);
|
|
||||||
|
|
||||||
return restart_syscall();
|
|
||||||
}
|
|
||||||
} else if (disable & (1 << ssid)) {
|
} else if (disable & (1 << ssid)) {
|
||||||
if (!(cgrp->subtree_control & (1 << ssid))) {
|
if (!(cgrp->subtree_control & (1 << ssid))) {
|
||||||
disable &= ~(1 << ssid);
|
disable &= ~(1 << ssid);
|
||||||
|
@ -2780,6 +2750,34 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
|
||||||
enable |= css_enable;
|
enable |= css_enable;
|
||||||
disable |= css_disable;
|
disable |= css_disable;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Because css offlining is asynchronous, userland might try to
|
||||||
|
* re-enable the same controller while the previous instance is
|
||||||
|
* still around. In such cases, wait till it's gone using
|
||||||
|
* offline_waitq.
|
||||||
|
*/
|
||||||
|
for_each_subsys(ss, ssid) {
|
||||||
|
if (!(css_enable & (1 << ssid)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
cgroup_for_each_live_child(child, cgrp) {
|
||||||
|
DEFINE_WAIT(wait);
|
||||||
|
|
||||||
|
if (!cgroup_css(child, ss))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
cgroup_get(child);
|
||||||
|
prepare_to_wait(&child->offline_waitq, &wait,
|
||||||
|
TASK_UNINTERRUPTIBLE);
|
||||||
|
cgroup_kn_unlock(of->kn);
|
||||||
|
schedule();
|
||||||
|
finish_wait(&child->offline_waitq, &wait);
|
||||||
|
cgroup_put(child);
|
||||||
|
|
||||||
|
return restart_syscall();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cgrp->subtree_control = new_sc;
|
cgrp->subtree_control = new_sc;
|
||||||
cgrp->child_subsys_mask = new_ss;
|
cgrp->child_subsys_mask = new_ss;
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче