[PATCH -next 2/2] md: fix potential hang for mddev_suspend()

Yu Kuai posted 2 patches 2 years, 3 months ago
[PATCH -next 2/2] md: fix potential hang for mddev_suspend()
Posted by Yu Kuai 2 years, 3 months ago
From: Yu Kuai <yukuai3@huawei.com>

Commit 72adae23a72c ("md: Change active_io to percpu") drop that if
'active_io' is decreased to 0 and array is suspended, 'sb_wait' will be
woke up. This is wrong, however, there is no regression reported and I
think this is probably because 'sb_wait' is used in many scenarios and
it's woke up from other context.

Anyway, fix this potential problem by waking up 'sb_wait' in this case.

Fixes: 72adae23a72c ("md: Change active_io to percpu")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/md/md.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 0d69b1a2e2d5..1c7eb3cfadb4 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -399,6 +399,9 @@ static bool md_array_enter(struct mddev *mddev, struct bio *bio)
 static void md_array_exit(struct mddev *mddev)
 {
 	percpu_ref_put(&mddev->active_io);
+	if (percpu_ref_is_zero(&mddev->active_io) &&
+	    wq_has_sleeper(&mddev->sb_wait))
+		wake_up(&mddev->sb_wait);
 }
 
 void md_handle_request(struct mddev *mddev, struct bio *bio)
-- 
2.39.2