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

Commit 0cee8b77 authored by Tejun Heo's avatar Tejun Heo
Browse files

cgroup: fix offlining child waiting in cgroup_subtree_control_write()



cgroup_subtree_control_write() waits for offline to complete
child-by-child before enabling a controller; however, it has a couple
bugs.

* It doesn't initialize the wait_queue_t.  This can lead to infinite
  hang on the following schedule() among other things.

* It forgets to pin the child before releasing cgroup_tree_mutex and
  performing schedule().  The child may already be gone by the time it
  wakes up and invokes finish_wait().  Pin the child being waited on.

Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarLi Zefan <lizefan@huawei.com>
parent f21a4f75
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -2594,16 +2594,18 @@ static int cgroup_subtree_control_write(struct cgroup_subsys_state *dummy_css,
			 * cases, wait till it's gone using offline_waitq.
			 */
			cgroup_for_each_live_child(child, cgrp) {
				wait_queue_t wait;
				DEFINE_WAIT(wait);

				if (!cgroup_css(child, ss))
					continue;

				cgroup_get(child);
				prepare_to_wait(&child->offline_waitq, &wait,
						TASK_UNINTERRUPTIBLE);
				mutex_unlock(&cgroup_tree_mutex);
				schedule();
				finish_wait(&child->offline_waitq, &wait);
				cgroup_put(child);
				goto retry;
			}