Skip to content

Commit b18ba3f

Browse files
Christoph Hellwiggregkh
authored andcommitted
md: fix a lock order reversal in md_alloc
[ Upstream commit 7df835a ] Commit b014089 ("md: Fix race when creating a new md device.") not only moved assigning mddev->gendisk before calling add_disk, which fixes the races described in the commit log, but also added a mddev->open_mutex critical section over add_disk and creation of the md kobj. Adding a kobject after add_disk is racy vs deleting the gendisk right after adding it, but md already prevents against that by holding a mddev->active reference. On the other hand taking this lock added a lock order reversal with what is not disk->open_mutex (used to be bdev->bd_mutex when the commit was added) for partition devices, which need that lock for the internal open for the partition scan, and a recent commit also takes it for non-partitioned devices, leading to further lockdep splatter. Fixes: b014089 ("md: Fix race when creating a new md device.") Fixes: d626338 ("block: support delayed holder registration") Reported-by: syzbot+fadc0aaf497e6a493b9f@syzkaller.appspotmail.com Signed-off-by: Christoph Hellwig <hch@lst.de> Tested-by: syzbot+fadc0aaf497e6a493b9f@syzkaller.appspotmail.com Reviewed-by: NeilBrown <neilb@suse.de> Signed-off-by: Song Liu <songliubraving@fb.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 568662e commit b18ba3f

1 file changed

Lines changed: 0 additions & 5 deletions

File tree

‎drivers/md/md.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5759,10 +5759,6 @@ static int md_alloc(dev_t dev, char *name)
57595759
disk->flags |= GENHD_FL_EXT_DEVT;
57605760
disk->events |= DISK_EVENT_MEDIA_CHANGE;
57615761
mddev->gendisk = disk;
5762-
/* As soon as we call add_disk(), another thread could get
5763-
* through to md_open, so make sure it doesn't get too far
5764-
*/
5765-
mutex_lock(&mddev->open_mutex);
57665762
add_disk(disk);
57675763

57685764
error = kobject_add(&mddev->kobj, &disk_to_dev(disk)->kobj, "%s", "md");
@@ -5777,7 +5773,6 @@ static int md_alloc(dev_t dev, char *name)
57775773
if (mddev->kobj.sd &&
57785774
sysfs_create_group(&mddev->kobj, &md_bitmap_group))
57795775
pr_debug("pointless warning\n");
5780-
mutex_unlock(&mddev->open_mutex);
57815776
abort:
57825777
mutex_unlock(&disks_mutex);
57835778
if (!error && mddev->kobj.sd) {

0 commit comments

Comments
 (0)