linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvme: fix misaccounting of nvme-mpath inflight IO
@ 2025-07-15  1:28 Yu Kuai
  2025-07-15  7:49 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Yu Kuai @ 2025-07-15  1:28 UTC (permalink / raw)
  To: kbusch, axboe, hch, sagi, lengchao
  Cc: linux-nvme, linux-kernel, yukuai3, yukuai1, yi.zhang, yangerkun,
	johnny.chenyi

From: Yu Kuai <yukuai3@huawei.com>

Pprocedures for nvme-mpath IO accounting:

1) Initialize nvme_request and clear flags;
2) Set NVME_MPATH_IO_STATS and increase inflight counter when IO
   started;
3) Check NVME_MPATH_IO_STATS and decrease inflight counter when IO is
   done;

However, for the case nvme_fail_nonready_command(), both step 1) and 2)
are skipped, and if old nvme_request set NVME_MPATH_IO_STATS and then
request is reused, step 3) will still be executed, causing inflight
IO counter to be negative. Fix the problem by clearing nvme_request in
nvme_fail_nonready_command()

Fixes: ea5e5f42cd2c ("nvme-fabrics: avoid double completions in nvmf_fail_nonready_command")
Reported-by: Yi Zhang <yi.zhang@redhat.com>
Closes: https://lore.kernel.org/all/CAHj4cs_+dauobyYyP805t33WMJVzOWj=7+51p4_j9rA63D9sog@mail.gmail.com/
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/nvme/host/core.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 92697f98c601..e2233e434e5a 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -764,6 +764,10 @@ blk_status_t nvme_fail_nonready_command(struct nvme_ctrl *ctrl,
 	    !test_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags) &&
 	    !blk_noretry_request(rq) && !(rq->cmd_flags & REQ_NVME_MPATH))
 		return BLK_STS_RESOURCE;
+
+	if (!(rq->rq_flags & RQF_DONTPREP))
+		nvme_clear_nvme_request(rq);
+
 	return nvme_host_path_error(rq);
 }
 EXPORT_SYMBOL_GPL(nvme_fail_nonready_command);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] nvme: fix misaccounting of nvme-mpath inflight IO
  2025-07-15  1:28 [PATCH] nvme: fix misaccounting of nvme-mpath inflight IO Yu Kuai
@ 2025-07-15  7:49 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2025-07-15  7:49 UTC (permalink / raw)
  To: Yu Kuai
  Cc: kbusch, axboe, hch, sagi, lengchao, linux-nvme, linux-kernel,
	yukuai3, yi.zhang, yangerkun, johnny.chenyi

Thanks,

applied to nvme-6.16.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-07-15  7:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-15  1:28 [PATCH] nvme: fix misaccounting of nvme-mpath inflight IO Yu Kuai
2025-07-15  7:49 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).