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, djeffery@redhat.com
Cc: linux-nvme@lists.infradead.org
Subject: [PATCH 5/5] nvme: Add two-pass shutdown support
Date: Wed, 7 Feb 2024 13:40:44 -0800 [thread overview]
Message-ID: <20240207214044.2374295-6-jallison@ciq.com> (raw)
In-Reply-To: <20240207214044.2374295-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.
This patch changes the nvme shutdown() method to pass
down the NVME_PCI_DISABLE_SHUTDOWN_TWOPASS enum value instead
of NVME_PCI_DISABLE_SHUTDOWN. nvme_dev_disable() is changed
to call nvme_ctrl_shutdown_start() instead of nvme_disable_ctrl()
in this case.
nvme_ctrl_shutdown_start() sets the shutdown bit,
but does not wait for completion.
The nvme_shutdown_wait() callback is added to synchronously
wait for the NVME_CSTS_SHST_CMPLT bit meaning the nvme
device has shutdown.
This change speeds up the shutdown in a system which hosts
many controllers.
Based on work by Tanjore Suresh <tansuresh@google.com>
Signed-off-by: Jeremy Allison <jallison@ciq.com>
---
drivers/nvme/host/pci.c | 39 ++++++++++++++++++++++++++++++++++++---
1 file changed, 36 insertions(+), 3 deletions(-)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 4dfc6258de07..5cf452651091 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -2607,7 +2607,14 @@ static void nvme_dev_disable(struct nvme_dev *dev,
if (!dead && dev->ctrl.queue_count > 0) {
nvme_delete_io_queues(dev);
- nvme_disable_ctrl(&dev->ctrl, shutdown);
+ /*
+ * NVME_PCI_DISABLE_SHUTDOWN_TWOPASS requests shutdown
+ * but doesn't wait for completion.
+ */
+ if (shutdown_type == NVME_PCI_DISABLE_SHUTDOWN_TWOPASS)
+ nvme_ctrl_shutdown_start(&dev->ctrl);
+ else
+ nvme_disable_ctrl(&dev->ctrl, shutdown);
nvme_poll_irqdisable(&dev->queues[0]);
}
nvme_suspend_io_queues(dev);
@@ -2625,7 +2632,7 @@ static void nvme_dev_disable(struct nvme_dev *dev,
* must flush all entered requests to their failed completion to avoid
* deadlocking blk-mq hot-cpu notifier.
*/
- if (shutdown) {
+ if (shutdown_type == NVME_PCI_DISABLE_SHUTDOWN) {
nvme_unquiesce_io_queues(&dev->ctrl);
if (dev->ctrl.admin_q && !blk_queue_dying(dev->ctrl.admin_q))
nvme_unquiesce_admin_queue(&dev->ctrl);
@@ -3128,7 +3135,32 @@ static void nvme_shutdown(struct pci_dev *pdev)
{
struct nvme_dev *dev = pci_get_drvdata(pdev);
- nvme_disable_prepare_reset(dev, NVME_PCI_DISABLE_SHUTDOWN);
+ nvme_disable_prepare_reset(dev, NVME_PCI_DISABLE_SHUTDOWN_TWOPASS);
+}
+
+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_PCI_DISABLE_SHUTDOWN_TWOPASS.
+ */
+ 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);
}
/*
@@ -3522,6 +3554,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-02-07 21:41 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-07 21:40 Make NVME shutdown two-pass - Version 6 Jeremy Allison
2024-02-07 21:40 ` [PATCH 1/5] driver core: Support two-pass driver shutdown Jeremy Allison
2024-02-07 21:40 ` [PATCH 2/5] PCI: Support two-pass shutdown Jeremy Allison
2024-02-07 21:59 ` Bjorn Helgaas
2024-02-07 22:02 ` Jeremy Allison
2024-02-07 21:40 ` [PATCH 3/5] nvme: Change 'bool shutdown' to an enum shutdown_type in nvme_dev_disable() Jeremy Allison
2024-02-12 7:01 ` Christoph Hellwig
2024-02-07 21:40 ` [PATCH 4/5] nvme: Add a new exported function nvme_ctrl_shutdown_start() Jeremy Allison
2024-02-12 7:07 ` Christoph Hellwig
2024-02-07 21:40 ` Jeremy Allison [this message]
2024-02-12 7:08 ` [PATCH 5/5] nvme: Add two-pass shutdown support Christoph Hellwig
2024-02-07 22:00 ` Make NVME shutdown two-pass - Version 6 Bjorn Helgaas
2024-02-07 22:03 ` Jeremy Allison
2024-02-08 18:02 ` David Jeffery
2024-02-08 18:28 ` Jeremy Allison
-- 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-01-03 21:04 Make NVME shutdown two-pass - Version 4 Jeremy Allison
2024-01-03 21:04 ` [PATCH 5/5] nvme: Add two-pass shutdown support Jeremy Allison
2024-01-04 13:14 ` Sagi Grimberg
2024-01-04 17:30 ` Jeremy Allison
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=20240207214044.2374295-6-jallison@ciq.com \
--to=jallison@ciq.com \
--cc=bhelgaas@google.com \
--cc=djeffery@redhat.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