]> git.kernelconcepts.de Git - karo-tx-linux.git/commit
blkcg: allow blkcg_pol_mutex to be grabbed from cgroup [file] methods
authorTejun Heo <tj@kernel.org>
Thu, 9 Jul 2015 20:39:47 +0000 (16:39 -0400)
committerJens Axboe <axboe@fb.com>
Thu, 9 Jul 2015 20:41:06 +0000 (14:41 -0600)
commit838f13bf4b6737d4aec508558e45f81798fc2677
treead481dd55649a687b67b20f9f6e3926b4151881d
parenta322baad1003798312741b0cb97bd2c7511ccf61
blkcg: allow blkcg_pol_mutex to be grabbed from cgroup [file] methods

blkcg_pol_mutex primarily protects the blkcg_policy array.  It also
protects cgroup file type [un]registration during policy addition /
removal.  This puts blkcg_pol_mutex outside cgroup internal
synchronization and in turn makes it impossible to grab from blkcg's
cgroup methods as that leads to cyclic dependency.

Another problematic dependency arising from this is through cgroup
interface file deactivation.  Removing a cftype requires removing all
files of the type which in turn involves draining all on-going
invocations of the file methods.  This means that an interface file
implementation can't grab blkcg_pol_mutex as draining can lead to AA
deadlock.

blkcg_reset_stats() is already in this situation.  It currently
trylocks blkcg_pol_mutex and then unwinds and retries the whole
operation on failure, which is cumbersome at best.  It has a lengthy
comment explaining how cgroup internal synchronization is involved and
expected to be updated but as explained above this doesn't need cgroup
internal locking to deadlock.  It's a self-contained AA deadlock.

The described circular dependencies can be easily broken by moving
cftype [un]registration out of blkcg_pol_mutex and protect them with
an outer mutex.  This patch introduces blkcg_pol_register_mutex which
wraps entire policy [un]registration including cftype operations and
shrinks blkcg_pol_mutex critical section.  This also makes the trylock
dancing in blkcg_reset_stats() unnecessary.  Removed.

This patch is necessary for the following blkcg_policy_data allocation
bug fixes.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Arianna Avanzini <avanzini.arianna@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
block/blk-cgroup.c