Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8bb5ef79 authored by Tejun Heo's avatar Tejun Heo
Browse files

cgroup: make sure a parent css isn't freed before its children



There are three subsystem callbacks in css shutdown path -
css_offline(), css_released() and css_free().  Except for
css_released(), cgroup core didn't guarantee the order of invocation.
css_offline() or css_free() could be called on a parent css before its
children.  This behavior is unexpected and led to bugs in cpu and
memory controller.

The previous patch updated ordering for css_offline() which fixes the
cpu controller issue.  While there currently isn't a known bug caused
by misordering of css_free() invocations, let's fix it too for
consistency.

css_free() ordering can be trivially fixed by moving putting of the
parent css below css_free() invocation.

Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
parent aa226ff4
Loading
Loading
Loading
Loading
+4 −3
Original line number Original line Diff line number Diff line
@@ -4657,14 +4657,15 @@ static void css_free_work_fn(struct work_struct *work)


	if (ss) {
	if (ss) {
		/* css free path */
		/* css free path */
		struct cgroup_subsys_state *parent = css->parent;
		int id = css->id;
		int id = css->id;


		if (css->parent)
			css_put(css->parent);

		ss->css_free(css);
		ss->css_free(css);
		cgroup_idr_remove(&ss->css_idr, id);
		cgroup_idr_remove(&ss->css_idr, id);
		cgroup_put(cgrp);
		cgroup_put(cgrp);

		if (parent)
			css_put(parent);
	} else {
	} else {
		/* cgroup free path */
		/* cgroup free path */
		atomic_dec(&cgrp->root->nr_cgrps);
		atomic_dec(&cgrp->root->nr_cgrps);