md: Flush workqueue md_rdev_misc_wq in md_alloc()
authorDavid Sloan <david.sloan@eideticom.com>
Thu, 11 Aug 2022 17:14:13 +0000 (11:14 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 15 Sep 2022 09:30:01 +0000 (11:30 +0200)
commita7dff6f41e16959b27021d522575c915a0de9916
tree1c7bb30ad1a853bc124cde6450fd9968d33c232e
parent0b7058067eb8ec143f415a42d6909a28f166de5f
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 <david.sloan@eideticom.com>
[logang@deltatee.com: rewrote commit message]
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Song Liu <song@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/md/md.c