From: Jeremy Allison <jallison@ciq.com>
To: jallison@ciq.com, jra@samba.org, tansuresh@google.com,
hch@lst.de, gregkh@linuxfoundation.org, rafael@kernel.org,
bhelgaas@google.com, sagi@grimberg.me
Cc: linux-nvme@lists.infradead.org
Subject: [PATCH 5/5] nvme: Add two-pass shutdown support.
Date: Wed, 3 Jan 2024 13:04:05 -0800 [thread overview]
Message-ID: <20240103210405.3593499-6-jallison@ciq.com> (raw)
In-Reply-To: <20240103210405.3593499-1-jallison@ciq.com>
This works with the two-pass shutdown mechanism setup for the PCI
drivers and participates to provide the shutdown_wait
method at the pci_driver structure level.
Adds the new NVME_DISABLE_SHUTDOWN_ASYNC to enum shutdown_type.
Changes the nvme shutdown() method to set the
NVME_CC_SHN_NORMAL bit and then return to the caller when
requested by NVME_DISABLE_SHUTDOWN_ASYNC.
nvme_shutdown_wait() is added to synchronously wait for
the NVME_CSTS_SHST_CMPLT bit.
This change speeds up the shutdown in a system which hosts
many controllers.
Signed-off-by: Jeremy Allison <jallison@ciq.com>
Signed-off-by: Tanjore Suresh <tansuresh@google.com>
---
drivers/nvme/host/core.c | 18 ++++++++++++++++--
drivers/nvme/host/nvme.h | 3 ++-
drivers/nvme/host/pci.c | 30 ++++++++++++++++++++++++++++--
3 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index c7d448f186fb..7000adea1e41 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2225,7 +2225,7 @@ int nvme_disable_ctrl(struct nvme_ctrl *ctrl, enum shutdown_type shutdown_type)
int ret;
ctrl->ctrl_config &= ~NVME_CC_SHN_MASK;
- if (shutdown_type == NVME_DISABLE_SHUTDOWN_SYNC)
+ if (shutdown_type != NVME_DISABLE_RESET)
ctrl->ctrl_config |= NVME_CC_SHN_NORMAL;
else
ctrl->ctrl_config &= ~NVME_CC_ENABLE;
@@ -2234,10 +2234,24 @@ int nvme_disable_ctrl(struct nvme_ctrl *ctrl, enum shutdown_type shutdown_type)
if (ret)
return ret;
- if (shutdown_type == NVME_DISABLE_SHUTDOWN_SYNC) {
+ switch (shutdown_type) {
+ case NVME_DISABLE_SHUTDOWN_ASYNC:
+ /*
+ * nvme_shutdown_wait() will read the reply for this.
+ */
+ return ret;
+ case NVME_DISABLE_SHUTDOWN_SYNC:
+ /*
+ * Spin on the read of the control register.
+ */
return nvme_wait_ready(ctrl, NVME_CSTS_SHST_MASK,
NVME_CSTS_SHST_CMPLT,
ctrl->shutdown_timeout, "shutdown");
+ case NVME_DISABLE_RESET:
+ /*
+ * Doing a reset here. Handle below.
+ */
+ break;
}
if (ctrl->quirks & NVME_QUIRK_DELAY_BEFORE_CHK_RDY)
msleep(NVME_QUIRK_DELAY_AMOUNT);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 8c30f9856621..43667d7a471a 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -189,7 +189,8 @@ enum {
enum shutdown_type {
NVME_DISABLE_RESET = 0,
- NVME_DISABLE_SHUTDOWN_SYNC = 1
+ NVME_DISABLE_SHUTDOWN_SYNC = 1,
+ NVME_DISABLE_SHUTDOWN_ASYNC = 2
};
static inline struct nvme_request *nvme_req(struct request *req)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 367e322dc818..9052dcf0f70c 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -2586,7 +2586,7 @@ static void nvme_dev_disable(struct nvme_dev *dev, enum shutdown_type shutdown_t
* Give the controller a chance to complete all entered requests
* if doing a safe shutdown.
*/
- if (!dead && (shutdown_type == NVME_DISABLE_SHUTDOWN_SYNC))
+ if (!dead && (shutdown_type != NVME_DISABLE_RESET))
nvme_wait_freeze_timeout(&dev->ctrl, NVME_IO_TIMEOUT);
}
@@ -3100,7 +3100,32 @@ static void nvme_shutdown(struct pci_dev *pdev)
{
struct nvme_dev *dev = pci_get_drvdata(pdev);
- nvme_disable_prepare_reset(dev, NVME_DISABLE_SHUTDOWN_SYNC);
+ nvme_disable_prepare_reset(dev, NVME_DISABLE_SHUTDOWN_ASYNC);
+}
+
+static void nvme_shutdown_wait(struct pci_dev *pdev)
+{
+ struct nvme_dev *dev = pci_get_drvdata(pdev);
+
+ mutex_lock(&dev->shutdown_lock);
+ /*
+ * Finish waiting for the shutdown request
+ * initiated in nvme_shutdown() above using
+ * NVME_DISABLE_SHUTDOWN_ASYNC.
+ */
+ nvme_wait_ready(&dev->ctrl, NVME_CSTS_SHST_MASK,
+ NVME_CSTS_SHST_CMPLT,
+ dev->ctrl.shutdown_timeout, "shutdown");
+ /*
+ * The driver will not be starting up queues again if shutting down so
+ * must flush all entered requests to their failed completion to avoid
+ * deadlocking blk-mq hot-cpu notifier.
+ */
+ nvme_unquiesce_io_queues(&dev->ctrl);
+ if (dev->ctrl.admin_q && !blk_queue_dying(dev->ctrl.admin_q))
+ nvme_unquiesce_admin_queue(&dev->ctrl);
+
+ mutex_unlock(&dev->shutdown_lock);
}
/*
@@ -3494,6 +3519,7 @@ static struct pci_driver nvme_driver = {
.probe = nvme_probe,
.remove = nvme_remove,
.shutdown = nvme_shutdown,
+ .shutdown_wait = nvme_shutdown_wait,
.driver = {
.probe_type = PROBE_PREFER_ASYNCHRONOUS,
#ifdef CONFIG_PM_SLEEP
--
2.39.3
next prev parent reply other threads:[~2024-01-03 21:04 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-03 21:04 Make NVME shutdown two-pass - Version 4 Jeremy Allison
2024-01-03 21:04 ` [PATCH 1/5] driver core: Support two-pass driver shutdown Jeremy Allison
2024-01-04 13:12 ` Sagi Grimberg
2024-01-04 17:27 ` Jeremy Allison
2024-01-03 21:04 ` [PATCH 2/5] PCI: Support two-pass shutdown Jeremy Allison
2024-01-04 18:55 ` Bjorn Helgaas
2024-01-04 19:34 ` Jeremy Allison
2024-01-03 21:04 ` [PATCH 3/5] nvme: Change 'bool shutdown' into an enum shutdown_type Jeremy Allison
2024-01-04 13:26 ` Sagi Grimberg
2024-01-04 17:43 ` Jeremy Allison
2024-01-04 18:44 ` Jeremy Allison
2024-01-08 17:42 ` Sagi Grimberg
2024-01-08 18:41 ` Jeremy Allison
2024-01-03 21:04 ` [PATCH 4/5] nvme: Export nvme_wait_ready() Jeremy Allison
2024-01-03 21:04 ` Jeremy Allison [this message]
2024-01-04 13:14 ` [PATCH 5/5] nvme: Add two-pass shutdown support Sagi Grimberg
2024-01-04 17:30 ` Jeremy Allison
2024-01-04 4:48 ` Make NVME shutdown two-pass - Version 4 Chaitanya Kulkarni
2024-01-04 6:38 ` Jeremy Allison
2024-01-04 19:00 ` Keith Busch
-- strict thread matches above, loose matches on Subject: below --
2024-01-29 18:19 Make NVME shutdown two-pass - Version 5 Jeremy Allison
2024-01-29 18:19 ` [PATCH 5/5] nvme: Add two-pass shutdown support Jeremy Allison
2024-01-30 11:15 ` Sagi Grimberg
2024-01-30 18:54 ` Jeremy Allison
2024-02-07 21:40 Make NVME shutdown two-pass - Version 6 Jeremy Allison
2024-02-07 21:40 ` [PATCH 5/5] nvme: Add two-pass shutdown support Jeremy Allison
2024-02-12 7:08 ` 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=20240103210405.3593499-6-jallison@ciq.com \
--to=jallison@ciq.com \
--cc=bhelgaas@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=hch@lst.de \
--cc=jra@samba.org \
--cc=linux-nvme@lists.infradead.org \
--cc=rafael@kernel.org \
--cc=sagi@grimberg.me \
--cc=tansuresh@google.com \
/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