mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: guzebing <guzebing1612@gmail.com>
To: kbusch@kernel.org, axboe@kernel.dk, hch@lst.de, sagi@grimberg.me
Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org,
	Guzebing <guzebing@bytedance.com>
Subject: [RFC PATCH 1/1] nvme-pci: detect I/O queue depth changes after reset
Date: Wed, 27 May 2026 15:53:20 +0800	[thread overview]
Message-ID: <20260527075320.3178600-2-guzebing1612@gmail.com> (raw)
In-Reply-To: <20260527075320.3178600-1-guzebing1612@gmail.com>

From: Guzebing <guzebing@bytedance.com>

Firmware activation may change the controller queue depth reported
through CAP.MQES. In the nvme-pci reset path, nvme_pci_enable()
rereads CAP and updates dev->q_depth, while existing struct nvme_queue
entries keep the old q_depth and SQ/CQ DMA addresses.

If the new depth is smaller than the existing nvmeq depth, reset recovery
would try to create I/O queues with a depth the controller no longer
accepts. Detect this before recreating I/O queues and fail the reset with
an explicit error; without this, the failure shows up later as lost I/O
queues and namespace removal.

If the new depth is larger, warn and continue with the existing queue
resources. The larger depth will not be used until the controller is
removed and probed again.

Signed-off-by: Guzebing <guzebing@bytedance.com>
---
 drivers/nvme/host/pci.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index db5fc9bf66272..4bc112f8a096e 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -3155,6 +3155,33 @@ static bool nvme_pci_update_nr_queues(struct nvme_dev *dev)
 	return true;
 }
 
+static int nvme_pci_check_reset_queue_depth(struct nvme_dev *dev)
+{
+	u32 nvmeq_q_depth;
+	u32 dev_q_depth = dev->q_depth;
+
+	if (dev->ctrl.queue_count <= 1)
+		return 0;
+
+	nvmeq_q_depth = dev->queues[1].q_depth;
+	if (nvmeq_q_depth == dev_q_depth)
+		return 0;
+
+	if (nvmeq_q_depth > dev_q_depth) {
+		dev_err(dev->ctrl.device,
+			"IO queue depth decreased after reset (%u -> %u); "
+			"live reset recovery is unsupported\n",
+			nvmeq_q_depth, dev_q_depth);
+		return -EIO;
+	}
+
+	dev_warn(dev->ctrl.device,
+		 "IO queue depth increased after reset (%u -> %u); "
+		 "remove and probe the controller again to use the new depth\n",
+		 nvmeq_q_depth, dev_q_depth);
+	return 0;
+}
+
 static int nvme_pci_enable(struct nvme_dev *dev)
 {
 	int result = -ENOMEM;
@@ -3371,6 +3398,9 @@ static void nvme_reset_work(struct work_struct *work)
 
 	mutex_lock(&dev->shutdown_lock);
 	result = nvme_pci_enable(dev);
+	if (result)
+		goto out_unlock;
+	result = nvme_pci_check_reset_queue_depth(dev);
 	if (result)
 		goto out_unlock;
 	nvme_unquiesce_admin_queue(&dev->ctrl);
-- 
2.20.1


  reply	other threads:[~2026-05-27  7:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-27  7:53 [RFC PATCH 0/1] " guzebing
2026-05-27  7:53 ` guzebing [this message]
2026-05-27 13:19 ` Christoph Hellwig
2026-05-28  1:38   ` guzebing
2026-05-28  3:03   ` Keith Busch
2026-05-28  8:44     ` Christoph Hellwig

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=20260527075320.3178600-2-guzebing1612@gmail.com \
    --to=guzebing1612@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=guzebing@bytedance.com \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /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®