nvme: sanitize KATO setting
v4 cover nvme: sanitize KATO setting
Hi all,
here is a patchset to sanitize and expose the KATO value to sysfs. We should follow the rules outlined in the NVMe base spec for calculating the KATO value and interval.
And by exposing it to sysfs we allow userspace to identify persistent discovery controllers (which will have a non-zero KATO value); a patch for that has been sent to the nvme-cli github repository.
As usual, comments and reviews are welcome.
Changes to v2:
- Include reviews from Christoph
- Rebase on top of nvme-5.13
Hannes Reinecke (2):
nvme: sanitize KATO setting
nvme: add 'kato' sysfs attribute
drivers/nvme/host/core.c | 20 +++++++++++++++++--- drivers/nvme/host/fabrics.c | 4 +--- drivers/nvme/host/nvme.h | 1 - 3 files changed, 18 insertions(+), 7 deletions(-)
Signature · 7 lines
2.29.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v4 1/2 nvme: sanitize KATO setting
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.
--- drivers/nvme/host/core.c | 18 +++++++++++++++--- drivers/nvme/host/fabrics.c | 4 +--- drivers/nvme/host/nvme.h | 1 - 3 files changed, 16 insertions(+), 7 deletions(-)
drivers/nvme/host/core.c +15 -3
@@ -1109,6 +1109,18 @@ void nvme_execute_passthru_rq(struct request *rq) }EXPORT_SYMBOL_NS_GPL (nvme_execute_passthru_rq,NVME_TARGET_PASSTHRU ); +/* +* Recommended frequency for KATO commands per 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 [..]. +*/ +static inline void nvme_queue_keep_alive_work (struct nvme_ctrl *ctrl) +{ +queue_delayed_work (nvme_wq, &ctrl->ka_work, + ctrl->kato *HZ /2 ); +} +static void nvme_keep_alive_end_io (struct request *rq,blk_status_t status) {struct nvme_ctrl *ctrl = rq->end_io_data;
@@ -1131,7 +1143,7 @@ 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 ); +nvme_queue_keep_alive_work (ctrl); }static int nvme_keep_alive (struct nvme_ctrl *ctrl)
@@ -1161,7 +1173,7 @@ 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 ); +nvme_queue_keep_alive_work (ctrl);return ; }
@@ -1178,7 +1190,7 @@ 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 ); +nvme_queue_keep_alive_work (ctrl); }void nvme_stop_keep_alive (struct nvme_ctrl *ctrl)
drivers/nvme/host/fabrics.c +1 -3
@@ -379,10 +379,8 @@ int nvmf_connect_admin_queue(struct nvme_ctrl *ctrl)/* * Set keep-alive timeout in seconds granularity (ms * 1000) -* and add a grace period for controller kato enforcement */ - cmd.connect.kato = ctrl->kato ? -cpu_to_le32 ((ctrl->kato +NVME_KATO_GRACE ) *1000 ) :0 ; + cmd.connect.kato =cpu_to_le32 (ctrl->kato *1000 );if (ctrl->opts->disable_sqflow) cmd.connect.cattr |=NVME_CONNECT_DISABLE_SQFLOW ;
drivers/nvme/host/nvme.h +0 -1
@@ -27,7 +27,6 @@ extern unsigned int admin_timeout;#define NVME_ADMIN_TIMEOUT (admin_timeout * HZ)#define NVME_DEFAULT_KATO 5 -#define NVME_KATO_GRACE 10#ifdef CONFIG_ARCH_NO_SG_CHAIN #define NVME_INLINE_SG_CNT 0
Signature · 7 lines
2.29.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v4 2/2 nvme: add 'kato' sysfs attribute
In reply to Hannes ReineckeAdd a 'kato' controller sysfs attribute to display the current keep-alive timeout value (if any). This allows userspace to identify persistent discovery controllers, as these will have a non-zero KATO value.
--- drivers/nvme/host/core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/nvme/host/core.c +2 -0
@@ -3173,6 +3173,7 @@ nvme_show_int_function(cntlid);nvme_show_int_function (numa_node);nvme_show_int_function (queue_count);nvme_show_int_function (sqsize); +nvme_show_int_function (kato); static ssize_t nvme_sysfs_delete(struct device *dev, struct device_attribute *attr, const char *buf,
@@ -3370,6 +3371,7 @@ static struct attribute *nvme_dev_attrs[] = { &dev_attr_ctrl_loss_tmo.attr, &dev_attr_reconnect_delay.attr, &dev_attr_fast_io_fail_tmo.attr, + &dev_attr_kato.attr, NULL };
Signature · 7 lines
2.29.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Thanks,
applied to nvme-5.13.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme