Skip to contentSkip to conversation

reserved tag allocation fixups

PATCH In review Christoph Hellwig 5 participants 19 messages Mar 3, 2021 – Mar 15, 2021

Subsystems (3)
lore
Share & tools
lore
author maintainer
#1 lore raw

PATCH 1/3 nvme-fabrics: only reserve a single tag

Fabrics drivers currently reserve two tags on the admin queue. But given that the connect command is only run on a freshly created queue or after all commands have been force aborted we only need to reserve a single tag.

---
 drivers/nvme/host/fabrics.h | 7 +++++++
 drivers/nvme/host/fc.c      | 4 ++--
 drivers/nvme/host/rdma.c    | 4 ++--
 drivers/nvme/host/tcp.c     | 4 ++--
 drivers/nvme/target/loop.c  | 4 ++--
 5 files changed, 15 insertions(+), 8 deletions(-)
drivers/nvme/host/fabrics.h +7 -0
index 733010d2eafd80..888b108d87a400 100644
@@ -18,6 +18,13 @@
 /* default is -1: the fail fast mechanism is disabled  */
 #define NVMF_DEF_FAIL_FAST_TMO		-1
 
+/*
+ * Reserved one command for internal usage.  This command is used for sending
+ * the connect command, as well as for the keep alive command on the admin
+ * queue once live.
+ */
+#define NVMF_RESERVED_TAGS	1
+
 /*
  * Define a host as seen by the target.  We allocate one at boot, but also
  * allow the override it when creating controllers.  This is both to provide
drivers/nvme/host/fc.c +2 -2
index 20dadd86e98121..0f8b9784cbcd30 100644
@@ -2862,7 +2862,7 @@ nvme_fc_create_io_queues(struct nvme_fc_ctrl *ctrl)
 	memset(&ctrl->tag_set, 0, sizeof(ctrl->tag_set));
 	ctrl->tag_set.ops = &nvme_fc_mq_ops;
 	ctrl->tag_set.queue_depth = ctrl->ctrl.opts->queue_size;
-	ctrl->tag_set.reserved_tags = 1; /* fabric connect */
+	ctrl->tag_set.reserved_tags = NVMF_RESERVED_TAGS;
 	ctrl->tag_set.numa_node = ctrl->ctrl.numa_node;
 	ctrl->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
 	ctrl->tag_set.cmd_size =
@@ -3484,7 +3484,7 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
 	memset(&ctrl->admin_tag_set, 0, sizeof(ctrl->admin_tag_set));
 	ctrl->admin_tag_set.ops = &nvme_fc_admin_mq_ops;
 	ctrl->admin_tag_set.queue_depth = NVME_AQ_MQ_TAG_DEPTH;
-	ctrl->admin_tag_set.reserved_tags = 2; /* fabric connect + Keep-Alive */
+	ctrl->admin_tag_set.reserved_tags = NVMF_RESERVED_TAGS;
 	ctrl->admin_tag_set.numa_node = ctrl->ctrl.numa_node;
 	ctrl->admin_tag_set.cmd_size =
 		struct_size((struct nvme_fcp_op_w_sgl *)NULL, priv,
drivers/nvme/host/rdma.c +2 -2
index 53ac4d7442ba9c..7855103e05d25f 100644
@@ -798,7 +798,7 @@ static struct blk_mq_tag_set *nvme_rdma_alloc_tagset(struct nvme_ctrl *nctrl,
 		memset(set, 0, sizeof(*set));
 		set->ops = &nvme_rdma_admin_mq_ops;
 		set->queue_depth = NVME_AQ_MQ_TAG_DEPTH;
-		set->reserved_tags = 2; /* connect + keep-alive */
+		set->reserved_tags = NVMF_RESERVED_TAGS;
 		set->numa_node = nctrl->numa_node;
 		set->cmd_size = sizeof(struct nvme_rdma_request) +
 				NVME_RDMA_DATA_SGL_SIZE;
@@ -811,7 +811,7 @@ static struct blk_mq_tag_set *nvme_rdma_alloc_tagset(struct nvme_ctrl *nctrl,
 		memset(set, 0, sizeof(*set));
 		set->ops = &nvme_rdma_mq_ops;
 		set->queue_depth = nctrl->sqsize + 1;
-		set->reserved_tags = 1; /* fabric connect */
+		set->reserved_tags = NVMF_RESERVED_TAGS;
 		set->numa_node = nctrl->numa_node;
 		set->flags = BLK_MQ_F_SHOULD_MERGE;
 		set->cmd_size = sizeof(struct nvme_rdma_request) +
drivers/nvme/host/tcp.c +2 -2
index 69f59d2c5799b8..c535836e7065b9 100644
@@ -1575,7 +1575,7 @@ static struct blk_mq_tag_set *nvme_tcp_alloc_tagset(struct nvme_ctrl *nctrl,
 		memset(set, 0, sizeof(*set));
 		set->ops = &nvme_tcp_admin_mq_ops;
 		set->queue_depth = NVME_AQ_MQ_TAG_DEPTH;
-		set->reserved_tags = 2; /* connect + keep-alive */
+		set->reserved_tags = NVMF_RESERVED_TAGS;
 		set->numa_node = nctrl->numa_node;
 		set->flags = BLK_MQ_F_BLOCKING;
 		set->cmd_size = sizeof(struct nvme_tcp_request);
@@ -1587,7 +1587,7 @@ static struct blk_mq_tag_set *nvme_tcp_alloc_tagset(struct nvme_ctrl *nctrl,
 		memset(set, 0, sizeof(*set));
 		set->ops = &nvme_tcp_mq_ops;
 		set->queue_depth = nctrl->sqsize + 1;
-		set->reserved_tags = 1; /* fabric connect */
+		set->reserved_tags = NVMF_RESERVED_TAGS;
 		set->numa_node = nctrl->numa_node;
 		set->flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_BLOCKING;
 		set->cmd_size = sizeof(struct nvme_tcp_request);
drivers/nvme/target/loop.c +2 -2
index cb6f86572b24ad..3e189e753bcf5a 100644
@@ -349,7 +349,7 @@ static int nvme_loop_configure_admin_queue(struct nvme_loop_ctrl *ctrl)
 	memset(&ctrl->admin_tag_set, 0, sizeof(ctrl->admin_tag_set));
 	ctrl->admin_tag_set.ops = &nvme_loop_admin_mq_ops;
 	ctrl->admin_tag_set.queue_depth = NVME_AQ_MQ_TAG_DEPTH;
-	ctrl->admin_tag_set.reserved_tags = 2; /* connect + keep-alive */
+	ctrl->admin_tag_set.reserved_tags = NVMF_RESERVED_TAGS;
 	ctrl->admin_tag_set.numa_node = ctrl->ctrl.numa_node;
 	ctrl->admin_tag_set.cmd_size = sizeof(struct nvme_loop_iod) +
 		NVME_INLINE_SG_CNT * sizeof(struct scatterlist);
@@ -520,7 +520,7 @@ static int nvme_loop_create_io_queues(struct nvme_loop_ctrl *ctrl)
 	memset(&ctrl->tag_set, 0, sizeof(ctrl->tag_set));
 	ctrl->tag_set.ops = &nvme_loop_mq_ops;
 	ctrl->tag_set.queue_depth = ctrl->ctrl.opts->queue_size;
-	ctrl->tag_set.reserved_tags = 1; /* fabric connect */
+	ctrl->tag_set.reserved_tags = NVMF_RESERVED_TAGS;
 	ctrl->tag_set.numa_node = ctrl->ctrl.numa_node;
 	ctrl->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
 	ctrl->tag_set.cmd_size = sizeof(struct nvme_loop_iod) +
Signature · 7 lines
2.29.2


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] nvme-fabrics: only reserve a single tag

Quoted 6 lines · Christoph Hellwig

Fabrics drivers currently reserve two tags on the admin queue. But given that the connect command is only run on a freshly created queue or after all commands have been force aborted we only need to reserve a single tag.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

Reviewed-by on v1 1/3
#3 lore raw

Re: [PATCH 1/3] nvme-fabrics: only reserve a single tag

In reply to Christoph Hellwig
Quoted 6 lines · Christoph Hellwig

Fabrics drivers currently reserve two tags on the admin queue. But given that the connect command is only run on a freshly created queue or after all commands have been force aborted we only need to reserve a single tag.

Thanks a lot for creating a macro with nice comment, looks good.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

Reviewed-by on v1 1/3
#4 lore raw

Re: [PATCH 1/3] nvme-fabrics: only reserve a single tag

In reply to Christoph Hellwig
Quoted 5 lines · Christoph Hellwig

Fabrics drivers currently reserve two tags on the admin queue. But given that the connect command is only run on a freshly created queue or after all commands have been force aborted we only need to reserve a single tag.

Quoted 9 lines
---
  drivers/nvme/host/fabrics.h | 7 +++++++
  drivers/nvme/host/fc.c      | 4 ++--
  drivers/nvme/host/rdma.c    | 4 ++--
  drivers/nvme/host/tcp.c     | 4 ++--
  drivers/nvme/target/loop.c  | 4 ++--
  5 files changed, 15 insertions(+), 8 deletions(-)

Cheers,

Hannes

Signature · 9 lines
Dr. Hannes Reinecke                Kernel Storage Architect
[email protected]                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
maintainer
#5 lore raw

Re: [PATCH 1/3] nvme-fabrics: only reserve a single tag

In reply to Christoph Hellwig
Quoted 5 lines

Fabrics drivers currently reserve two tags on the admin queue. But given that the connect command is only run on a freshly created queue or after all commands have been force aborted we only need to reserve a single tag.

Umm, I think this would be an issue for non-mpath fabrics devices...

When we teardown the controller, we iterate over all tags and cancel them, however for non-mpath devices these actually stick around until they exhaust the retrys counter (with the hope that the controller will reconnect again) unlike the mpath case where the requests are failed-over.

Now if the admin queue is absolutely full during a reset, we won't have a keep-alive command.

One possible solution is to make sure that nvme_decide_disposition to complete a request for admin commands. However note that this means that admin commands would fail immediately when the controller resets, which is a regression from the existing behavior and we may piss off users with that...

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

author maintainer
#6 lore raw

Re: [PATCH 1/3] nvme-fabrics: only reserve a single tag

Quoted 17 lines · Sagi Grimberg
Quoted 5 lines

Fabrics drivers currently reserve two tags on the admin queue. But given that the connect command is only run on a freshly created queue or after all commands have been force aborted we only need to reserve a single tag.

Umm, I think this would be an issue for non-mpath fabrics devices...

When we teardown the controller, we iterate over all tags and cancel them, however for non-mpath devices these actually stick around until they exhaust the retrys counter (with the hope that the controller will reconnect again) unlike the mpath case where the requests are failed-over.

Now if the admin queue is absolutely full during a reset, we won't have a keep-alive command.

Quoted 6 lines

One possible solution is to make sure that nvme_decide_disposition to complete a request for admin commands. However note that this means that admin commands would fail immediately when the controller resets, which is a regression from the existing behavior and we may piss off users with that...

We never retry admin commands! And the reserved tags are set aside and not relevant to the "normal" commands.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

maintainer Reviewed-by
#7 lore raw

Re: [PATCH 1/3] nvme-fabrics: only reserve a single tag

Quoted 24 lines
Quoted 17 lines
Quoted 5 lines

Fabrics drivers currently reserve two tags on the admin queue. But given that the connect command is only run on a freshly created queue or after all commands have been force aborted we only need to reserve a single tag.

Umm, I think this would be an issue for non-mpath fabrics devices...

When we teardown the controller, we iterate over all tags and cancel them, however for non-mpath devices these actually stick around until they exhaust the retrys counter (with the hope that the controller will reconnect again) unlike the mpath case where the requests are failed-over.

Now if the admin queue is absolutely full during a reset, we won't have a keep-alive command.

Quoted 6 lines

One possible solution is to make sure that nvme_decide_disposition to complete a request for admin commands. However note that this means that admin commands would fail immediately when the controller resets, which is a regression from the existing behavior and we may piss off users with that...

Quoted 2 lines

We never retry admin commands! And the reserved tags are set aside and not relevant to the "normal" commands.

You're right, admin commands will be noretry commands. this looks good to me.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

author maintainer
#8 lore raw

PATCH 2/3 nvme: merge nvme_keep_alive into nvme_keep_alive_work

In reply to Christoph Hellwig

Merge nvme_keep_alive into its only caller to prepare for additional changes to this code.

---
 drivers/nvme/host/core.c | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)
drivers/nvme/host/core.c +8 -18
index e68a8c4ac5a6ea..bdeb3feae61899 100644
@@ -1225,28 +1225,12 @@ static void nvme_keep_alive_end_io(struct request *rq, blk_status_t status)
 		queue_delayed_work(nvme_wq, &ctrl->ka_work, ctrl->kato * HZ);
 }
 
-static int nvme_keep_alive(struct nvme_ctrl *ctrl)
-{
-	struct request *rq;
-
-	rq = nvme_alloc_request(ctrl->admin_q, &ctrl->ka_cmd,
-			BLK_MQ_REQ_RESERVED);
-	if (IS_ERR(rq))
-		return PTR_ERR(rq);
-
-	rq->timeout = ctrl->kato * HZ;
-	rq->end_io_data = ctrl;
-
-	blk_execute_rq_nowait(NULL, rq, 0, nvme_keep_alive_end_io);
-
-	return 0;
-}
-
 static void nvme_keep_alive_work(struct work_struct *work)
 {
 	struct nvme_ctrl *ctrl = container_of(to_delayed_work(work),
 			struct nvme_ctrl, ka_work);
 	bool comp_seen = ctrl->comp_seen;
+	struct request *rq;
 
 	if ((ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) && comp_seen) {
 		dev_dbg(ctrl->device,
@@ -1256,12 +1240,18 @@ static void nvme_keep_alive_work(struct work_struct *work)
 		return;
 	}
 
-	if (nvme_keep_alive(ctrl)) {
+	rq = nvme_alloc_request(ctrl->admin_q, &ctrl->ka_cmd,
+				BLK_MQ_REQ_RESERVED);
+	if (IS_ERR(rq)) {
 		/* allocation failure, reset the controller */
 		dev_err(ctrl->device, "keep-alive failed\n");
 		nvme_reset_ctrl(ctrl);
 		return;
 	}
+
+	rq->timeout = ctrl->kato * HZ;
+	rq->end_io_data = ctrl;
+	blk_execute_rq_nowait(NULL, rq, 0, nvme_keep_alive_end_io);
 }
 
 static void nvme_start_keep_alive(struct nvme_ctrl *ctrl)
Signature · 7 lines
2.29.2


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Reviewed-by on v1 2/3
#9 lore raw

Re: [PATCH 2/3] nvme: merge nvme_keep_alive into nvme_keep_alive_work

Quoted 4 lines · Christoph Hellwig

Merge nvme_keep_alive into its only caller to prepare for additional changes to this code.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

Reviewed-by on v1 2/3
#10 lore raw

Re: [PATCH 2/3] nvme: merge nvme_keep_alive into nvme_keep_alive_work

In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

Merge nvme_keep_alive into its only caller to prepare for additional changes to this code.

Looks good.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

Reviewed-by on v1 2/3
#11 lore raw

Re: [PATCH 2/3] nvme: merge nvme_keep_alive into nvme_keep_alive_work

In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

Merge nvme_keep_alive into its only caller to prepare for additional changes to this code.

Looks good.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

Reviewed-by on v1 2/3
#12 lore raw

Re: [PATCH 2/3] nvme: merge nvme_keep_alive into nvme_keep_alive_work

In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig

Merge nvme_keep_alive into its only caller to prepare for additional changes to this code.

---
  drivers/nvme/host/core.c | 26 ++++++++------------------
  1 file changed, 8 insertions(+), 18 deletions(-)

Cheers,

Hannes

Signature · 9 lines
Dr. Hannes Reinecke                Kernel Storage Architect
[email protected]                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
author maintainer
#14 lore raw

PATCH 3/3 nvme: allocate the keep alive request using BLK_MQ_REQ_NOWAIT

In reply to Christoph Hellwig

To avoid an error recovery deadlock where the keep alive work is waiting for a request and thus can't be flushed to make progress for tearing down the controller. Also print the error code returned from blk_mq_alloc_request to help debugging any future issues in this code.

Based on an earlier patch from Hannes Reinecke <[email protected]>.

---
 drivers/nvme/host/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +2 -2
index bdeb3feae61899..8a4a9fe96cdf83 100644
@@ -1241,10 +1241,10 @@ static void nvme_keep_alive_work(struct work_struct *work)
 	}
 
 	rq = nvme_alloc_request(ctrl->admin_q, &ctrl->ka_cmd,
-				BLK_MQ_REQ_RESERVED);
+				BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT);
 	if (IS_ERR(rq)) {
 		/* allocation failure, reset the controller */
-		dev_err(ctrl->device, "keep-alive failed\n");
+		dev_err(ctrl->device, "keep-alive failed: %ld\n", PTR_ERR(rq));
 		nvme_reset_ctrl(ctrl);
 		return;
 	}
Signature · 7 lines
2.29.2


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Reviewed-by on v1 3/3
#15 lore raw

Re: [PATCH 3/3] nvme: allocate the keep alive request using BLK_MQ_REQ_NOWAIT

Quoted 8 lines · Christoph Hellwig

To avoid an error recovery deadlock where the keep alive work is waiting for a request and thus can't be flushed to make progress for tearing down the controller. Also print the error code returned from blk_mq_alloc_request to help debugging any future issues in this code.

Based on an earlier patch from Hannes Reinecke <[email protected]>.

And for what's worth, our customer tested this. I've done the same patch during debugging. It fixes the deadlock as Hannes reported.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

Reviewed-by on v1 3/3
#16 lore raw

Re: [PATCH 3/3] nvme: allocate the keep alive request using BLK_MQ_REQ_NOWAIT

In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig

To avoid an error recovery deadlock where the keep alive work is waiting for a request and thus can't be flushed to make progress for tearing down the controller. Also print the error code returned from blk_mq_alloc_request to help debugging any future issues in this code.

Based on an earlier patch from Hannes Reinecke <[email protected]>.

Looks good.

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

Reviewed-by on v1 3/3
#17 lore raw

Re: [PATCH 3/3] nvme: allocate the keep alive request using BLK_MQ_REQ_NOWAIT

In reply to Christoph Hellwig
Quoted 20 lines · Christoph Hellwig

To avoid an error recovery deadlock where the keep alive work is waiting for a request and thus can't be flushed to make progress for tearing down the controller. Also print the error code returned from blk_mq_alloc_request to help debugging any future issues in this code.

Based on an earlier patch from Hannes Reinecke <[email protected]>.

---
  drivers/nvme/host/core.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +0 -0
index bdeb3feae61899..8a4a9fe96cdf83 100644
@@ -1241,10 +1241,10 @@ static void nvme_keep_alive_work(struct work_struct *work)
  	}
 

drivers/nvme/host/core.c static void nvme_keep_alive_work(struct work_struct *work) · line 1250

Quoted 10 lines
drivers/nvme/host/core.c +2 -2
  	rq = nvme_alloc_request(ctrl->admin_q, &ctrl->ka_cmd,
-				BLK_MQ_REQ_RESERVED);
+				BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT);
  	if (IS_ERR(rq)) {
  		/* allocation failure, reset the controller */
-		dev_err(ctrl->device, "keep-alive failed\n");
+		dev_err(ctrl->device, "keep-alive failed: %ld\n", PTR_ERR(rq));
  		nvme_reset_ctrl(ctrl);
  		return;
  	}

Cheers,

Hannes

Signature · 9 lines
Dr. Hannes Reinecke                Kernel Storage Architect
[email protected]                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme