From: Hannes Reinecke <hare@suse.de>
To: Christoph Hellwig <hch@lst.de>
Cc: Keith Busch <keith.busch@wdc.com>,
Sagi Grimberg <sagi@grimberg.me>, Daniel Wagner <dwagner@suse.de>,
linux-nvme@lists.infradead.org, Hannes Reinecke <hare@suse.de>,
Chao Leng <lengchao@huawei.com>
Subject: [PATCH 2/3] nvme: sanitize KATO setting
Date: Tue, 2 Mar 2021 10:26:43 +0100 [thread overview]
Message-ID: <20210302092644.80701-3-hare@suse.de> (raw)
In-Reply-To: <20210302092644.80701-1-hare@suse.de>
According to the NVMe base spec the KATO commands should be sent
at half of the KATO interval, to properly account for round-trip
times.
As we now will only ever send one KATO command per connection we
can easily use the recommended values.
This also fixes a potential issue where the request timeout for
the KATO command does not match the value in the connect command,
which might be causing spurious connection drops from the target.
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
drivers/nvme/host/core.c | 9 ++++++---
drivers/nvme/host/fabrics.c | 2 +-
drivers/nvme/host/nvme.h | 9 ++++++++-
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f890b310499e..6d096d41a82f 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1223,7 +1223,8 @@ static void nvme_keep_alive_end_io(struct request *rq, blk_status_t status)
startka = true;
spin_unlock_irqrestore(&ctrl->lock, flags);
if (startka)
- queue_delayed_work(nvme_wq, &ctrl->ka_work, ctrl->kato * HZ);
+ queue_delayed_work(nvme_wq, &ctrl->ka_work,
+ NVME_KATO_DELAY(ctrl->kato) * HZ);
}
static int nvme_keep_alive(struct nvme_ctrl *ctrl)
@@ -1258,7 +1259,8 @@ static void nvme_keep_alive_work(struct work_struct *work)
dev_dbg(ctrl->device,
"reschedule traffic based keep-alive timer\n");
ctrl->comp_seen = false;
- queue_delayed_work(nvme_wq, &ctrl->ka_work, ctrl->kato * HZ);
+ queue_delayed_work(nvme_wq, &ctrl->ka_work,
+ NVME_KATO_DELAY(ctrl->kato) * HZ);
return;
}
@@ -1275,7 +1277,8 @@ static void nvme_start_keep_alive(struct nvme_ctrl *ctrl)
if (unlikely(ctrl->kato == 0))
return;
- queue_delayed_work(nvme_wq, &ctrl->ka_work, ctrl->kato * HZ);
+ queue_delayed_work(nvme_wq, &ctrl->ka_work,
+ NVME_KATO_DELAY(ctrl->kato) * HZ);
}
void nvme_stop_keep_alive(struct nvme_ctrl *ctrl)
diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index 5dfd806fc2d2..dba32e39afbf 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c
@@ -382,7 +382,7 @@ int nvmf_connect_admin_queue(struct nvme_ctrl *ctrl)
* and add a grace period for controller kato enforcement
*/
cmd.connect.kato = ctrl->kato ?
- cpu_to_le32((ctrl->kato + NVME_KATO_GRACE) * 1000) : 0;
+ cpu_to_le32(ctrl->kato * 1000) : 0;
if (ctrl->opts->disable_sqflow)
cmd.connect.cattr |= NVME_CONNECT_DISABLE_SQFLOW;
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 23711f6b7d13..912830389997 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -27,7 +27,14 @@ extern unsigned int admin_timeout;
#define NVME_ADMIN_TIMEOUT (admin_timeout * HZ)
#define NVME_DEFAULT_KATO 5
-#define NVME_KATO_GRACE 10
+
+/*
+ * The recommended frequency for KATO commands
+ * according to NVMe 1.4 section 7.12.1:
+ * The host should send Keep Alive commands at half of the
+ * Keep Alive Timeout accounting for transport roundtrip times [..].
+ */
+#define NVME_KATO_DELAY(k) ((k) >> 1)
#ifdef CONFIG_ARCH_NO_SG_CHAIN
#define NVME_INLINE_SG_CNT 0
--
2.29.2
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
next prev parent reply other threads:[~2021-03-02 9:27 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-02 9:26 [PATCHv2 0/3] nvme: sanitize KATO handling Hannes Reinecke
2021-03-02 9:26 ` [PATCH 1/3] nvme: fixup kato deadlock Hannes Reinecke
2021-03-03 8:42 ` Christoph Hellwig
2021-03-03 12:01 ` Hannes Reinecke
2021-03-03 12:35 ` Christoph Hellwig
2021-03-03 13:11 ` Hannes Reinecke
2021-03-03 14:23 ` Hannes Reinecke
2021-03-04 8:02 ` Christoph Hellwig
2021-03-04 8:56 ` Hannes Reinecke
2021-03-02 9:26 ` Hannes Reinecke [this message]
2021-03-03 8:53 ` [PATCH 2/3] nvme: sanitize KATO setting Chao Leng
2021-03-03 12:40 ` Christoph Hellwig
2021-03-05 20:38 ` Sagi Grimberg
2021-03-08 13:11 ` Max Gurtovoy
2021-03-08 13:54 ` Hannes Reinecke
2021-03-02 9:26 ` [PATCH 3/3] nvme: add 'kato' sysfs attribute Hannes Reinecke
2021-03-05 20:38 ` Sagi Grimberg
2021-03-08 13:06 ` Max Gurtovoy
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=20210302092644.80701-3-hare@suse.de \
--to=hare@suse.de \
--cc=dwagner@suse.de \
--cc=hch@lst.de \
--cc=keith.busch@wdc.com \
--cc=lengchao@huawei.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.