From: sashiko-bot@kernel.org
To: "Keith Busch" <kbusch@meta.com>, linux-nvme@lists.infradead.org
Subject: Re: [PATCH] nvme-multipath: flush every path that completed writes
Date: Mon, 30 Nov 2026 21:38:38 +0000 [thread overview]
Message-ID: <sashiko-outbox-242019@kernel.org> (raw)
In-Reply-To: <20261130211438.556153-1-kbusch@meta.com>
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] nvme-multipath: flushing unhealthy sibling paths in
nvme_mpath_flush_paths()
- [High] nvme-multipath: mempool deadlock without rescuer in
nvme_mpath_init()
- [High] nvme-multipath: data write races sibling preflush in
nvme_ns_head_submit_bio()
- [Medium] nvme-multipath: premature NVME_NS_WRITTEN clear in
nvme_mpath_flush_paths()
- [Medium] nvme-multipath: NVME_NS_WRITTEN not cleared on ns in
nvme_mpath_flush_paths()
- [Medium] nvme-multipath: REQ_NOWAIT ignored for flushes in
nvme_mpath_flush_paths()
--
commit ac6211f78b685d8e139acbc7bde856f29907dd4e
Author: Keith Busch <kbusch@kernel.org>
nvme-multipath: flush every path that completed writes
This commit tracks which namespace paths have completed writes with
NVME_NS_WRITTEN and submits chained REQ_PREFLUSH bios to each written
sibling path when a REQ_PREFLUSH bio is submitted to the multipath head.
> diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
> index 27facdbb3d4c0..cb12f05d9b532 100644
> --- a/drivers/nvme/host/multipath.c
> +++ b/drivers/nvme/host/multipath.c
> @@ -203,6 +203,10 @@ void nvme_mpath_end_request(struct request *rq)
> {
> struct nvme_ns *ns = rq->q->queuedata;
>
> + /* a Flush only covers writes completed by the controller it's sent to */
> + if (op_is_write(req_op(rq)) && !test_bit(NVME_NS_WRITTEN, &ns->flags))
> + set_bit(NVME_NS_WRITTEN, &ns->flags);
> +
> if (nvme_req(rq)->flags & NVME_MPATH_CNT_ACTIVE)
> atomic_dec_if_positive(&ns->ctrl->nr_active);
>
> @@ -563,6 +567,30 @@ static bool nvme_available_path(struct nvme_ns_head *head)
> return nvme_mpath_queue_if_no_path(head);
> }
>
> +static struct bio_set nvme_mpath_flush_bs;
> +
> +static void nvme_mpath_flush_paths(struct nvme_ns_head *head,
> + struct nvme_ns *ns, struct bio *bio)
> + __must_hold_shared(&head->srcu)
> +{
> + struct nvme_ns *sib;
> +
> + list_for_each_entry_srcu(sib, &head->list, siblings,
> + srcu_read_lock_held(&head->srcu)) {
> + struct bio *flush;
> +
> + if (sib == ns || !test_bit(NVME_NS_WRITTEN, &sib->flags) ||
> + !test_and_clear_bit(NVME_NS_WRITTEN, &sib->flags))
> + continue;
[Severity: Medium]
Does clearing NVME_NS_WRITTEN on sib before the sibling flush bio completes
let a concurrent flush finish before sib's volatile write cache is actually
flushed?
CPU0 CPU1
nvme_ns_head_submit_bio(bioA)
nvme_mpath_flush_paths()
test_and_clear_bit(..., &sib->flags)
nvme_ns_head_submit_bio(bioB)
nvme_mpath_flush_paths()
test_bit(..., &sib->flags) == 0
submit_bio_noacct(bioB) -> ns
/* bioB completes on ns before
flush on sib finishes */
submit_bio_noacct(flush) -> sib
Similarly, if a write completes on sib in nvme_mpath_end_request() while
NVME_NS_WRITTEN is still set, just before nvme_mpath_flush_paths() clears it
for an already-issued flush, that write is left without NVME_NS_WRITTEN set.
[Severity: Medium]
Because sib == ns short-circuits before test_and_clear_bit(NVME_NS_WRITTEN,
&sib->flags), doesn't NVME_NS_WRITTEN remain set on the primary path ns
that is receiving the REQ_PREFLUSH bio? If a later REQ_PREFLUSH bio
selects a different path, nvme_mpath_flush_paths() will still see
NVME_NS_WRITTEN set on ns and issue a redundant flush to it.
> +
> + flush = bio_alloc_bioset(sib->disk->part0, 0,
> + REQ_OP_WRITE | REQ_PREFLUSH | REQ_SYNC,
> + GFP_NOIO, &nvme_mpath_flush_bs);
> + bio_chain(flush, bio);
> + submit_bio_noacct(flush);
> + }
> +}
[Severity: High]
Can nvme_mpath_flush_paths() submit a chained flush bio to a sibling path
that is resetting, connecting, dead, or in an inaccessible ANA state?
Sibling namespaces remain on head->list while unavailable, and
nvme_mpath_end_request() also sets NVME_NS_WRITTEN on failed writes (including
when nvme_failover_req() zeroes nvme_req(req)->status and calls
nvme_end_req()). Because flush is submitted without REQ_NVME_MPATH or a check
on sib's state, nvme_fail_nonready_command() returns BLK_STS_RESOURCE when
sib->ctrl is resetting or connecting (stalling the parent bio on the healthy
path ns), or nvme_decide_disposition() completes flush with an error instead
of failing over, propagating -EIO to the parent bio via bio_chain().
[Severity: Medium]
Should nvme_mpath_flush_paths() propagate REQ_NOWAIT from the parent bio and
avoid GFP_NOIO when REQ_NOWAIT is set? The multipath head disk advertises
BLK_FEAT_NOWAIT, so allocating with GFP_NOIO or submitting flush without
REQ_NOWAIT can sleep in reclaim, mempool allocation, or sibling queue
submission for a non-blocking caller.
> @@ -590,6 +618,8 @@ static void nvme_ns_head_submit_bio(struct bio *bio)
> */
> bio_set_flag(bio, BIO_REMAPPED);
> bio->bi_opf |= REQ_NVME_MPATH;
> + if (bio->bi_opf & REQ_PREFLUSH)
> + nvme_mpath_flush_paths(head, ns, bio);
> trace_block_bio_remap(bio, disk_devt(ns->head->disk),
> bio->bi_iter.bi_sector);
> submit_bio_noacct(bio);
[Severity: High]
When bio carries data along with REQ_PREFLUSH (such as a filesystem journal
commit write with REQ_OP_WRITE | REQ_PREFLUSH | REQ_FUA), doesn't submitting
bio to ns concurrently with the sibling flushes allow bio's data write to reach
media on ns before sibling controllers finish flushing earlier writes?
bio_chain(flush, bio) only delays bio_endio(bio); blk_insert_flush() on ns does
not wait for the flush bios in flight on sibling queues before issuing bio's
data write.
[ ... ]
> @@ -1545,6 +1575,16 @@ void nvme_mpath_put_disk(struct nvme_ns_head *head)
> put_disk(head->disk);
> }
>
> +int nvme_mpath_init(void)
> +{
> + return bioset_init(&nvme_mpath_flush_bs, BIO_POOL_SIZE, 0, 0);
> +}
[Severity: High]
Can bio_alloc_bioset() in nvme_mpath_flush_paths() deadlock when
nvme_mpath_flush_bs is initialized without BIOSET_NEED_RESCUER?
nvme_ns_head_submit_bio() runs inside __submit_bio_noacct() with
current->bio_list active, so each submit_bio_noacct(flush) in
nvme_mpath_flush_paths() queues flush onto current->bio_list[0] without
dispatching it until nvme_ns_head_submit_bio() returns. If a namespace has
more than BIO_POOL_SIZE (2) written sibling paths (or concurrent flushes share
the global pool) under memory pressure, punt_bios_to_rescuer() does nothing
because bs->rescue_workqueue is NULL, and mempool_alloc() sleeps forever
waiting for the flush bios still sitting on current->bio_list[0] while holding
srcu_read_lock(&head->srcu).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130211438.556153-1-kbusch@meta.com?part=1
prev parent reply other threads:[~2026-11-30 21:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 21:14 [PATCH] nvme-multipath: flush every path that completed writes Keith Busch
2026-11-30 21:38 ` sashiko-bot [this message]
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=sashiko-outbox-242019@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kbusch@meta.com \
--cc=linux-nvme@lists.infradead.org \
--cc=sashiko-reviews@lists.linux.dev \
/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