From: David Sloan Date: Thu, 11 Aug 2022 17:14:13 +0000 (-0600) Subject: md: Flush workqueue md_rdev_misc_wq in md_alloc() X-Git-Tag: v5.15.73~429 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a7dff6f41e16959b27021d522575c915a0de9916;p=platform%2Fkernel%2Flinux-rpi.git md: Flush workqueue md_rdev_misc_wq in md_alloc() [ Upstream commit 5e8daf906f890560df430d30617c692a794acb73 ] A race condition still exists when removing and re-creating md devices in test cases. However, it is only seen on some setups. The race condition was tracked down to a reference still being held to the kobject by the rdev in the md_rdev_misc_wq which will be released in rdev_delayed_delete(). md_alloc() waits for previous deletions by waiting on the md_misc_wq, but the md_rdev_misc_wq may still be holding a reference to a recently removed device. To fix this, also flush the md_rdev_misc_wq in md_alloc(). Signed-off-by: David Sloan [logang@deltatee.com: rewrote commit message] Signed-off-by: Logan Gunthorpe Signed-off-by: Song Liu Signed-off-by: Sasha Levin --- diff --git a/drivers/md/md.c b/drivers/md/md.c index c8f2e85..04e1e29 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -5651,6 +5651,7 @@ static int md_alloc(dev_t dev, char *name) * removed (mddev_delayed_delete). */ flush_workqueue(md_misc_wq); + flush_workqueue(md_rdev_misc_wq); mutex_lock(&disks_mutex); mddev = mddev_alloc(dev);