summaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2021-04-03 18:15:29 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-05-14 09:44:12 +0200
commitafa4de0926635d07a0431a27e5c2f504b9c1490d (patch)
tree5532a2063c783be511bee9a26f9165f833c3e254 /drivers/md
parentacdf531e77f098b807ba1b177dbf167ff0621c70 (diff)
downloadlinux-stable-afa4de0926635d07a0431a27e5c2f504b9c1490d.tar.gz
linux-stable-afa4de0926635d07a0431a27e5c2f504b9c1490d.tar.bz2
linux-stable-afa4de0926635d07a0431a27e5c2f504b9c1490d.zip
md: split mddev_find
commit 65aa97c4d2bfd76677c211b9d03ef05a98c6d68e upstream. Split mddev_find into a simple mddev_find that just finds an existing mddev by the unit number, and a more complicated mddev_find that deals with find or allocating a mddev. This turns out to fix this bug reported by Zhao Heming. ----------------------------- snip ------------------------------ commit d3374825ce57 ("md: make devices disappear when they are no longer needed.") introduced protection between mddev creating & removing. The md_open shouldn't create mddev when all_mddevs list doesn't contain mddev. With currently code logic, there will be very easy to trigger soft lockup in non-preempt env.
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/md.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 660cc5440dc5..65a9d0355a03 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -649,6 +649,22 @@ EXPORT_SYMBOL_GPL(mddev_init);
static struct mddev *mddev_find(dev_t unit)
{
+ struct mddev *mddev;
+
+ if (MAJOR(unit) != MD_MAJOR)
+ unit &= ~((1 << MdpMinorShift) - 1);
+
+ spin_lock(&all_mddevs_lock);
+ mddev = mddev_find_locked(unit);
+ if (mddev)
+ mddev_get(mddev);
+ spin_unlock(&all_mddevs_lock);
+
+ return mddev;
+}
+
+static struct mddev *mddev_find_or_alloc(dev_t unit)
+{
struct mddev *mddev, *new = NULL;
if (unit && MAJOR(unit) != MD_MAJOR)
@@ -5436,7 +5452,7 @@ static int md_alloc(dev_t dev, char *name)
* writing to /sys/module/md_mod/parameters/new_array.
*/
static DEFINE_MUTEX(disks_mutex);
- struct mddev *mddev = mddev_find(dev);
+ struct mddev *mddev = mddev_find_or_alloc(dev);
struct gendisk *disk;
int partitioned;
int shift;
@@ -6312,11 +6328,9 @@ static void autorun_devices(int part)
md_probe(dev, NULL, NULL);
mddev = mddev_find(dev);
- if (!mddev || !mddev->gendisk) {
- if (mddev)
- mddev_put(mddev);
+ if (!mddev)
break;
- }
+
if (mddev_lock(mddev))
pr_warn("md: %s locked, cannot run\n", mdname(mddev));
else if (mddev->raid_disks || mddev->major_version