]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
dm raid: protect md_stop() with 'reconfig_mutex'
authorYu Kuai <yukuai3@huawei.com>
Sat, 8 Jul 2023 09:21:53 +0000 (17:21 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Aug 2023 08:22:39 +0000 (10:22 +0200)
[ Upstream commit 7d5fff8982a2199d49ec067818af7d84d4f95ca0 ]

__md_stop_writes() and __md_stop() will modify many fields that are
protected by 'reconfig_mutex', and all the callers will grab
'reconfig_mutex' except for md_stop().

Also, update md_stop() to make certain 'reconfig_mutex' is held using
lockdep_assert_held().

Fixes: 9d09e663d550 ("dm: raid456 basic support")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/md/dm-raid.c
drivers/md/md.c

index 6d4e287350a3391f30c1ba9aa80722077b3978fd..8d489933d57923028dc2cf6dc58313468dcc9f8b 100644 (file)
@@ -3305,8 +3305,8 @@ size_check:
        return 0;
 
 bad_unlock:
-       mddev_unlock(&rs->md);
        md_stop(&rs->md);
+       mddev_unlock(&rs->md);
 bad:
        raid_set_free(rs);
 
@@ -3317,7 +3317,9 @@ static void raid_dtr(struct dm_target *ti)
 {
        struct raid_set *rs = ti->private;
 
+       mddev_lock_nointr(&rs->md);
        md_stop(&rs->md);
+       mddev_unlock(&rs->md);
        raid_set_free(rs);
 }
 
index 5a21aeedc1ba70df4af814b6dbe21c078c0ed57c..89a270d29369868d114920889564d2be7f893f59 100644 (file)
@@ -6281,6 +6281,8 @@ static void __md_stop(struct mddev *mddev)
 
 void md_stop(struct mddev *mddev)
 {
+       lockdep_assert_held(&mddev->reconfig_mutex);
+
        /* stop the array and free an attached data structures.
         * This is called from dm-raid
         */