From: "Li Youhong" <dayou5941@163.com>
To: song@kernel.org, yukuai@fygo.io
Cc: magiclinan@didiglobal.com, xiao@kernel.org,
linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
Li Youhong <liyouhong@kylinos.cn>
Subject: [PATCH v6 0/2] md: fix sync_work vs array teardown races
Date: Thu, 26 Nov 2026 16:08:21 +0800 [thread overview]
Message-ID: <20261126080821.144057-1-dayou5941@163.com> (raw)
From: Li Youhong <liyouhong@kylinos.cn>
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/20261112013523.120428-1-dayou5941@163.com/
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/20261111015027.4029184-1-dayou5941@163.com
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/20261110063045.912703-1-dayou5941@163.com
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/20261109023055.2164333-1-dayou5941@163.com
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/20261106083543.249267-1-dayou5941@163.com
next reply other threads:[~2026-11-26 8:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 8:08 Li Youhong [this message]
2026-11-26 8:23 ` Li Youhong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126080821.144057-1-dayou5941@163.com \
--to=dayou5941@163.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=liyouhong@kylinos.cn \
--cc=magiclinan@didiglobal.com \
--cc=song@kernel.org \
--cc=xiao@kernel.org \
--cc=yukuai@fygo.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®