cgroup: break kernfs active_ref protection in cgroup directory operations
authorTejun Heo <tj@kernel.org>
Thu, 20 Mar 2014 15:10:15 +0000 (11:10 -0400)
committerTejun Heo <tj@kernel.org>
Thu, 20 Mar 2014 15:10:15 +0000 (11:10 -0400)
commite1b2dc176f2d5be7952c47a4e4e8f3b06a90db1c
tree770797e88466920af0354358e5707a2397487628
parent1b9aba49eab5e85b0d3de8ba630cda6d68546297
cgroup: break kernfs active_ref protection in cgroup directory operations

cgroup_tree_mutex should nest above the kernfs active_ref protection;
however, cgroup_create() and cgroup_rename() were grabbing
cgroup_tree_mutex while under kernfs active_ref protection.  This has
actualy possibility to lead to deadlocks in case these operations race
against cgroup_rmdir() which invokes kernfs_remove() on directory
kernfs_node while holding cgroup_tree_mutex.

Neither cgroup_create() or cgroup_rename() requires active_ref
protection.  The former already has enough synchronization through
cgroup_lock_live_group() and the latter doesn't care, so this can be
fixed by updating both functions to break all active_ref protections
before grabbing cgroup_tree_mutex.

While this patch fixes the immediate issue, it probably needs further
work in the long term - kernfs directories should enable lockdep
annotations and maybe the better way to handle this is marking
directory nodes as not needing active_ref protection rather than
breaking it in each operation.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/cgroup.c