Skip to content

Commit 868bba5

Browse files
YuKuai-huaweiliu-song-6
authored andcommitted
md/raid5: fix a deadlock in the case that reshape is interrupted
If reshape is in progress and io across reshape_position is issued, such io will wait for reshape to make progress(see details in the case that make_stripe_request() return STRIPE_SCHEDULE_AND_RETRY). It has been reported several times that if system reboot while growing raid5 to raid6, array assemble will hang infinitely([1, 2]). This is because following deadlock is triggered: 1) a normal io is waiting for reshape to progress, this io can be from system-udevd or mdadm. 2) while assemble, mdadm tries to suspend the array, hence 'reconfig_mutex' is held and mddev_suspend() must wait for normal io to be done. 3) daemon thread can't start reshape because 'reconfig_mutex' can't be held. 1) and 3) is unbreakable because they're foundation design. In order to break 2), following is possible solutions that I can think of: a) Let mddev_suspend() fail is not a good option, because this will break many scenarios since mddev_suspend() doesn't fail before. b) Fail the io that is waiting for reshape to make progress from mddev_suspend(). c) Return false for the io that is waiting for reshape to make progress from raid5_make_request(), and these io will wait for suspend to be done in md_handle_request(), where 'active_io' is not grabbed. c) sounds better than b), however, b) is used because it's easy and straightforward, and it's verified that mdadm can assemble in this case. On the other hand, c) breaks the logic that mddev_suspend() will wait for submitted io to be completely handled. Fix the problem by checking reshape in mddev_suspend(), if reshape can't make progress and there are still some io waiting for reshape, fail those io. [1] https://lore.kernel.org/all/CAFig2csUV2QiomUhj_t3dPOgV300dbQ6XtM9ygKPdXJFSH__Nw@mail.gmail.com/ [2] https://lore.kernel.org/all/CAO2ABipzbw6QL5eNa44CQHjiVa-LTvS696Mh9QaTw+qsUKFUCw@mail.gmail.com/ Reported-by: Jove <jovetoo@gmail.com> Reported-by: David Gilmour <dgilmour76@gmail.com> Signed-off-by: Yu Kuai <yukuai3@huawei.com> Signed-off-by: Song Liu <song@kernel.org> Link: https://lore.kernel.org/r/20230512015610.821290-6-yukuai1@huaweicloud.com
1 parent 3e00777 commit 868bba5

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

drivers/md/md.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9100,6 +9100,7 @@ void md_do_sync(struct md_thread *thread)
91009100
spin_unlock(&mddev->lock);
91019101

91029102
wake_up(&resync_wait);
9103+
wake_up(&mddev->sb_wait);
91039104
md_wakeup_thread(mddev->thread);
91049105
return;
91059106
}

drivers/md/raid5.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5966,6 +5966,19 @@ static int add_all_stripe_bios(struct r5conf *conf,
59665966
return ret;
59675967
}
59685968

5969+
static bool reshape_inprogress(struct mddev *mddev)
5970+
{
5971+
return test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) &&
5972+
test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) &&
5973+
!test_bit(MD_RECOVERY_DONE, &mddev->recovery) &&
5974+
!test_bit(MD_RECOVERY_INTR, &mddev->recovery);
5975+
}
5976+
5977+
static bool reshape_disabled(struct mddev *mddev)
5978+
{
5979+
return is_md_suspended(mddev) || !md_is_rdwr(mddev);
5980+
}
5981+
59695982
static enum stripe_result make_stripe_request(struct mddev *mddev,
59705983
struct r5conf *conf, struct stripe_request_ctx *ctx,
59715984
sector_t logical_sector, struct bio *bi)
@@ -5997,7 +6010,8 @@ static enum stripe_result make_stripe_request(struct mddev *mddev,
59976010
if (ahead_of_reshape(mddev, logical_sector,
59986011
conf->reshape_safe)) {
59996012
spin_unlock_irq(&conf->device_lock);
6000-
return STRIPE_SCHEDULE_AND_RETRY;
6013+
ret = STRIPE_SCHEDULE_AND_RETRY;
6014+
goto out;
60016015
}
60026016
}
60036017
spin_unlock_irq(&conf->device_lock);
@@ -6076,6 +6090,15 @@ static enum stripe_result make_stripe_request(struct mddev *mddev,
60766090

60776091
out_release:
60786092
raid5_release_stripe(sh);
6093+
out:
6094+
if (ret == STRIPE_SCHEDULE_AND_RETRY && !reshape_inprogress(mddev) &&
6095+
reshape_disabled(mddev)) {
6096+
bi->bi_status = BLK_STS_IOERR;
6097+
ret = STRIPE_FAIL;
6098+
pr_err("md/raid456:%s: io failed across reshape position while reshape can't make progress.\n",
6099+
mdname(mddev));
6100+
}
6101+
60796102
return ret;
60806103
}
60816104

@@ -9044,6 +9067,22 @@ static int raid5_start(struct mddev *mddev)
90449067
return r5l_start(conf->log);
90459068
}
90469069

9070+
static void raid5_prepare_suspend(struct mddev *mddev)
9071+
{
9072+
struct r5conf *conf = mddev->private;
9073+
9074+
wait_event(mddev->sb_wait, !reshape_inprogress(mddev) ||
9075+
percpu_ref_is_zero(&mddev->active_io));
9076+
if (percpu_ref_is_zero(&mddev->active_io))
9077+
return;
9078+
9079+
/*
9080+
* Reshape is not in progress, and array is suspended, io that is
9081+
* waiting for reshpape can never be done.
9082+
*/
9083+
wake_up(&conf->wait_for_overlap);
9084+
}
9085+
90479086
static struct md_personality raid6_personality =
90489087
{
90499088
.name = "raid6",
@@ -9064,6 +9103,7 @@ static struct md_personality raid6_personality =
90649103
.check_reshape = raid6_check_reshape,
90659104
.start_reshape = raid5_start_reshape,
90669105
.finish_reshape = raid5_finish_reshape,
9106+
.prepare_suspend = raid5_prepare_suspend,
90679107
.quiesce = raid5_quiesce,
90689108
.takeover = raid6_takeover,
90699109
.change_consistency_policy = raid5_change_consistency_policy,
@@ -9088,6 +9128,7 @@ static struct md_personality raid5_personality =
90889128
.check_reshape = raid5_check_reshape,
90899129
.start_reshape = raid5_start_reshape,
90909130
.finish_reshape = raid5_finish_reshape,
9131+
.prepare_suspend = raid5_prepare_suspend,
90919132
.quiesce = raid5_quiesce,
90929133
.takeover = raid5_takeover,
90939134
.change_consistency_policy = raid5_change_consistency_policy,
@@ -9113,6 +9154,7 @@ static struct md_personality raid4_personality =
91139154
.check_reshape = raid5_check_reshape,
91149155
.start_reshape = raid5_start_reshape,
91159156
.finish_reshape = raid5_finish_reshape,
9157+
.prepare_suspend = raid5_prepare_suspend,
91169158
.quiesce = raid5_quiesce,
91179159
.takeover = raid4_takeover,
91189160
.change_consistency_policy = raid5_change_consistency_policy,

0 commit comments

Comments
 (0)