• Tejun Heo's avatar
    blkcg: allow blkcg_pol_mutex to be grabbed from cgroup [file] methods · 838f13bf
    Tejun Heo authored
    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: default avatarTejun Heo <tj@kernel.org>
    Cc: Vivek Goyal <vgoyal@redhat.com>
    Cc: Arianna Avanzini <avanzini.arianna@gmail.com>
    Signed-off-by: default avatarJens Axboe <axboe@fb.com>
    838f13bf
blk-cgroup.c 31.5 KB