Fix regression bugs
Subsystems (2)
cover Fix regression bugs
Hi all
Sorry, I know this patch set conflict with Yu Kuai's patch set. But I have to send out this patch set. Now we're facing some deadlock regression problems. So it's better to figure out the root cause and fix them. But Kuai's patch set looks too complicate for me. And like we're talking in the emails, Kuai's patch set breaks some rules. It's not good to fix some problem by breaking the original logic. If we really need to break some logic. It's better to use a distinct patch set to describe why we need them.
This patch is based on linus's tree. The tag is 6.8-rc5. If this patch set can be accepted. We need to revert Kuai's patches which have been merged in Song's tree (md-6.8-20240216 tag). This patch set has three patches. The first two resolves deadlock problems. With these two patches, it can resolve most deadlock problem. The third one fixes active_io counter bug.
I have run lvm2 regression test. lvconvert-raid-reshape.sh is failed. This patch set doesn't plan to fix it. Kuai's patch set has a patch which should fix it. And there are other 4 failed cases:shell/dmsetup-integrity-keys.shshell/lvresize-fs-crypt.shshell/pvck-dump.shshell/select-report.sh
Xiao Ni (3):
Clear MD_RECOVERY_WAIT when stopping dmraid
Set MD_RECOVERY_FROZEN before stop sync thread
Missing decrease active_io for flush io
drivers/md/dm-raid.c | 2 ++ drivers/md/md.c | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-)
Signature · 1 line
2.32.0 (Apple Git-132)
RFC PATCH 1/2 dm-raid/md: Clear MD_RECOVERY_WAIT when stopping dmraid
MD_RECOVERY_WAIT is used by dmraid to delay reshape process by patch commit 644e2537fdc7 ("dm raid: fix stripe adding reshape deadlock"). Before patch commit f52f5c71f3d4b ("md: fix stopping sync thread") dmraid stopped sync thread directy by calling md_reap_sync_thread. After this patch dmraid stops sync thread asynchronously as md does. This is right. Now the dmraid stop process is like this:
1. raid_postsuspend->md_stop_writes->__md_stop_writes->stop_sync_thread. stop_sync_thread sets MD_RECOVERY_INTR and wait until MD_RECOVERY_RUNNING is cleared
2. md_do_sync finds MD_RECOVERY_WAIT is set and return. (This is the root cause for this deadlock. We hope md_do_sync can set MD_RECOVERY_DONE)
3. md thread calls md_check_recovery (This is the place to reap sync thread. Because MD_RECOVERY_DONE is not set. md thread can't reap sync thread)
4. raid_dtr stops/free struct mddev and release dmraid related resources
dmraid only sets MD_RECOVERY_WAIT but doesn't clear it. It needs to clear this bit when stopping the dmraid before stopping sync thread.
But the deadlock still can happen sometimes even MD_RECOVERY_WAIT is cleared before stopping sync thread. It's the reason stop_sync_thread only wakes up task. If the task isn't running, it still needs to wake up sync thread too.
This deadlock can be reproduced 100% by these commands:
modprobe brd rd_size=34816 rd_nr=5
while [ 1 ]; do
vgcreate test_vg /dev/ram*
lvcreate --type raid5 -L 16M -n test_lv test_vg lvconvert -y --stripes 4 /dev/test_vg/test_lv vgremove test_vg -ff
sleep 1
done
--- drivers/md/dm-raid.c | 2 ++ drivers/md/md.c | 1 + 2 files changed, 3 insertions(+)
drivers/md/dm-raid.c +2 -0
@@ -3796,6 +3796,8 @@ static void raid_postsuspend(struct dm_target *ti)struct raid_set *rs = ti->private;if (!test_and_set_bit (RT_FLAG_RS_SUSPENDED , &rs->runtime_flags)) { +if (test_bit (MD_RECOVERY_WAIT , &rs->md.recovery)) +clear_bit (MD_RECOVERY_WAIT , &rs->md.recovery);/* Writes have to be stopped before suspending to avoid deadlocks. */ if (!test_bit (MD_RECOVERY_FROZEN , &rs->md.recovery))md_stop_writes (&rs->md);
drivers/md/md.c +1 -0
@@ -4904,6 +4904,7 @@ static void stop_sync_thread(struct mddev *mddev, bool locked, bool check_seq)* never happen */ md_wakeup_thread_directly (mddev->sync_thread); +md_wakeup_thread (mddev->sync_thread);if (work_pending (&mddev->sync_work))flush_work (&mddev->sync_work);
Signature · 1 line
2.32.0 (Apple Git-132)
RFC PATCH 3/3 md: Missing decrease active_io for flush io
In reply to Xiao NiIf all flush bios finish fast, it doesn't decrease active_io. And it will stuck when stopping array.
This can be reproduced by lvm2 test shell/integrity-caching.sh. But it can't reproduce 100%.
--- drivers/md/md.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/md/md.c +5 -1
@@ -579,8 +579,12 @@ static void submit_flushes(struct work_struct *ws)rcu_read_lock (); }rcu_read_unlock (); -if (atomic_dec_and_test (&mddev->flush_pending)) +if (atomic_dec_and_test (&mddev->flush_pending)) { +/* The pair is percpu_ref_get() from md_flush_request() */ +percpu_ref_put (&mddev->active_io); +queue_work (md_wq, &mddev->flush_work); + } }static void md_submit_flush_data (struct work_struct *ws)
Signature · 1 line
2.32.0 (Apple Git-132)
RFC PATCH 2/2 md: Set MD_RECOVERY_FROZEN before stop sync thread
In reply to Xiao NiAfter patch commit f52f5c71f3d4b ("md: fix stopping sync thread"), dmraid stops sync thread asynchronously. The calling process is:dev_remove->dm_destroy->__dm_destroy->raid_postsuspend->raid_dtr
raid_postsuspend does two jobs. First, it stops sync thread. Then it suspend array. Now it can stop sync thread successfully. But it doesn't set MD_RECOVERY_FROZEN. It's introduced by patch f52f5c71f3d4b. So after raid_postsuspend, the sync thread starts again. raid_dtr can't stop the sync thread because the array is already suspended.
This can be reproduced easily by those commands:
while [ 1 ]; do
vgcreate test_vg /dev/loop0 /dev/loop1 lvcreate --type raid1 -L 400M -m 1 -n test_lv test_vg lvchange -an test_vg
vgremove test_vg -ff
done
--- drivers/md/md.c | 1 + 1 file changed, 1 insertion(+)
drivers/md/md.c +1 -0
@@ -6337,6 +6337,7 @@ static void __md_stop_writes(struct mddev *mddev)void md_stop_writes (struct mddev *mddev) {mddev_lock_nointr (mddev); +set_bit (MD_RECOVERY_FROZEN , &mddev->recovery);__md_stop_writes (mddev);mddev_unlock (mddev); }
Signature · 1 line
2.32.0 (Apple Git-132)