• Yu Kuai's avatar
    md: fix 'delete_mutex' deadlock · 4934b640
    Yu Kuai authored
    Commit 3ce94ce5 ("md: fix duplicate filename for rdev") introduce a
    new lock 'delete_mutex', and trigger a new deadlock:
    
    t1: remove rdev			t2: sysfs writer
    
    rdev_attr_store			rdev_attr_store
     mddev_lock
     state_store
     md_kick_rdev_from_array
      lock delete_mutex
      list_add mddev->deleting
      unlock delete_mutex
     mddev_unlock
    				 mddev_lock
    				 ...
      lock delete_mutex
      kobject_del
      // wait for sysfs writers to be done
    				 mddev_unlock
    				 lock delete_mutex
    				 // wait for delete_mutex, deadlock
    
    'delete_mutex' is used to protect the list 'mddev->deleting', turns out
    that this list can be protected by 'reconfig_mutex' directly, and this
    lock can be removed.
    
    Fix this problem by removing the lock, and use 'reconfig_mutex' to
    protect the list. mddev_unlock() will move this list to a local list to
    be handled after 'reconfig_mutex' is dropped.
    
    Fixes: 3ce94ce5 ("md: fix duplicate filename for rdev")
    Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
    Signed-off-by: default avatarSong Liu <song@kernel.org>
    Link: https://lore.kernel.org/r/20230621142933.1395629-1-yukuai1@huaweicloud.com
    4934b640
md.h 28.7 KB