md: fix sync_work vs array teardown races
v6 cover md: fix sync_work vs array teardown races
From: Li Youhong <[email protected]>
dm-raid tears down arrays via md_stop(), which cleared mddev->pers without waiting for previously queued sync_work. That work could then call remove_spares() with pers == NULL, or keep using mddev after raid_dtr() frees it.
do_md_stop()/md_stop_writes() already call stop_sync_thread() before teardown. md_stop() needs the same wait, plus a few related holes around work_busy(), MD_RECOVERY_FROZEN on the read-only path, and event_work on the raid_ctr() error path.
This series splits the previous combined fix so the work_pending -> work_busy change can land on its own.
Li Youhong (2):
md: use work_busy() to flush sync_work in stop_sync_thread()
md: fix sync_work vs array teardown races
drivers/md/dm-raid.c | 7 +++++++ drivers/md/md.c | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 10 deletions(-)
---
v6:
- Split into two patches per review:
1/2: only replace work_pending() with work_busy() when flushing
sync_work in stop_sync_thread(); Fixes: f52f5c71f3d4.
2/2: remaining changes (md_stop wait, idle early-return gated by
work_busy(), INTR only when RUNNING, RO FROZEN check,
flush event_work on raid_ctr() error path).
- v5: https://lore.kernel.org/linux-raid/[email protected]/
v5:
- Restore idle early-return in stop_sync_thread() gated by work_busy(), so locked callers keep reconfig_mutex and do not race with do_md_run().
- Flush event_work before raid_set_free() on the raid_ctr error path (md_stop() may drop the mutex and let md_reap queue it).
- v4: https://lore.kernel.org/linux-raid/[email protected]
v4:
- Always flush_work(&sync_work) in stop_sync_thread(); do not delay clearing MD_RECOVERY_RUNNING (that can drop MD_RECOVERY_NEEDED via md_check_recovery, and does not cover the successful sync_thread registration path).
- v3: https://lore.kernel.org/linux-raid/[email protected]
v3:
- Honour MD_RECOVERY_FROZEN before queueing sync_work on the
read-only md_check_recovery() path.
- (superseded) delayed MD_RECOVERY_RUNNING clear on not_running.
- v2: https://lore.kernel.org/linux-raid/[email protected]
v2:
- Drop the pers NULL check in md_start_sync().
- Call stop_sync_thread() from md_stop() before clearing pers, matching do_md_stop()/md_stop_writes().
- v1: https://lore.kernel.org/linux-raid/[email protected]
Hi,
Sorry, this series was not sent correctly (the patches were not posted as one continuous, dependent series). Please ignore it.
I will resend a corrected v6 shortly.
Thanks,
Li Youhong