Skip to content

Commit d38b4d2

Browse files
committed
Merge tag 'nvme-5.12-20210319' of git://git.infradead.org/nvme into block-5.12
Pull NVMe updates from Christoph: "nvme fixes for 5.12 - fix tag allocation for keep alive - fix a unit mismatch for the Write Zeroes limits - various TCP transport fixes (Sagi Grimberg, Elad Grupi) - fix iosqes and iocqes validation for discovery controllers (Sagi Grimberg)" * tag 'nvme-5.12-20210319' of git://git.infradead.org/nvme: nvmet-tcp: fix kmap leak when data digest in use nvmet: don't check iosqes,iocqes for discovery controllers nvme-rdma: fix possible hang when failing to set io queues nvme-tcp: fix possible hang when failing to set io queues nvme-tcp: fix misuse of __smp_processor_id with preemption enabled nvme-tcp: fix a NULL deref when receiving a 0-length r2t PDU nvme: fix Write Zeroes limitations nvme: allocate the keep alive request using BLK_MQ_REQ_NOWAIT nvme: merge nvme_keep_alive into nvme_keep_alive_work nvme-fabrics: only reserve a single tag
2 parents 1e28eed + bac0445 commit d38b4d2

File tree

8 files changed

+69
-60
lines changed

8 files changed

+69
-60
lines changed

drivers/nvme/host/core.c

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,28 +1226,12 @@ static void nvme_keep_alive_end_io(struct request *rq, blk_status_t status)
12261226
queue_delayed_work(nvme_wq, &ctrl->ka_work, ctrl->kato * HZ);
12271227
}
12281228

1229-
static int nvme_keep_alive(struct nvme_ctrl *ctrl)
1230-
{
1231-
struct request *rq;
1232-
1233-
rq = nvme_alloc_request(ctrl->admin_q, &ctrl->ka_cmd,
1234-
BLK_MQ_REQ_RESERVED);
1235-
if (IS_ERR(rq))
1236-
return PTR_ERR(rq);
1237-
1238-
rq->timeout = ctrl->kato * HZ;
1239-
rq->end_io_data = ctrl;
1240-
1241-
blk_execute_rq_nowait(NULL, rq, 0, nvme_keep_alive_end_io);
1242-
1243-
return 0;
1244-
}
1245-
12461229
static void nvme_keep_alive_work(struct work_struct *work)
12471230
{
12481231
struct nvme_ctrl *ctrl = container_of(to_delayed_work(work),
12491232
struct nvme_ctrl, ka_work);
12501233
bool comp_seen = ctrl->comp_seen;
1234+
struct request *rq;
12511235

12521236
if ((ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) && comp_seen) {
12531237
dev_dbg(ctrl->device,
@@ -1257,12 +1241,18 @@ static void nvme_keep_alive_work(struct work_struct *work)
12571241
return;
12581242
}
12591243

1260-
if (nvme_keep_alive(ctrl)) {
1244+
rq = nvme_alloc_request(ctrl->admin_q, &ctrl->ka_cmd,
1245+
BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT);
1246+
if (IS_ERR(rq)) {
12611247
/* allocation failure, reset the controller */
1262-
dev_err(ctrl->device, "keep-alive failed\n");
1248+
dev_err(ctrl->device, "keep-alive failed: %ld\n", PTR_ERR(rq));
12631249
nvme_reset_ctrl(ctrl);
12641250
return;
12651251
}
1252+
1253+
rq->timeout = ctrl->kato * HZ;
1254+
rq->end_io_data = ctrl;
1255+
blk_execute_rq_nowait(NULL, rq, 0, nvme_keep_alive_end_io);
12661256
}
12671257

12681258
static void nvme_start_keep_alive(struct nvme_ctrl *ctrl)
@@ -1964,30 +1954,18 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)
19641954
blk_queue_max_write_zeroes_sectors(queue, UINT_MAX);
19651955
}
19661956

1967-
static void nvme_config_write_zeroes(struct gendisk *disk, struct nvme_ns *ns)
1957+
/*
1958+
* Even though NVMe spec explicitly states that MDTS is not applicable to the
1959+
* write-zeroes, we are cautious and limit the size to the controllers
1960+
* max_hw_sectors value, which is based on the MDTS field and possibly other
1961+
* limiting factors.
1962+
*/
1963+
static void nvme_config_write_zeroes(struct request_queue *q,
1964+
struct nvme_ctrl *ctrl)
19681965
{
1969-
u64 max_blocks;
1970-
1971-
if (!(ns->ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) ||
1972-
(ns->ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES))
1973-
return;
1974-
/*
1975-
* Even though NVMe spec explicitly states that MDTS is not
1976-
* applicable to the write-zeroes:- "The restriction does not apply to
1977-
* commands that do not transfer data between the host and the
1978-
* controller (e.g., Write Uncorrectable ro Write Zeroes command).".
1979-
* In order to be more cautious use controller's max_hw_sectors value
1980-
* to configure the maximum sectors for the write-zeroes which is
1981-
* configured based on the controller's MDTS field in the
1982-
* nvme_init_identify() if available.
1983-
*/
1984-
if (ns->ctrl->max_hw_sectors == UINT_MAX)
1985-
max_blocks = (u64)USHRT_MAX + 1;
1986-
else
1987-
max_blocks = ns->ctrl->max_hw_sectors + 1;
1988-
1989-
blk_queue_max_write_zeroes_sectors(disk->queue,
1990-
nvme_lba_to_sect(ns, max_blocks));
1966+
if ((ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) &&
1967+
!(ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES))
1968+
blk_queue_max_write_zeroes_sectors(q, ctrl->max_hw_sectors);
19911969
}
19921970

19931971
static bool nvme_ns_ids_valid(struct nvme_ns_ids *ids)
@@ -2159,7 +2137,7 @@ static void nvme_update_disk_info(struct gendisk *disk,
21592137
set_capacity_and_notify(disk, capacity);
21602138

21612139
nvme_config_discard(disk, ns);
2162-
nvme_config_write_zeroes(disk, ns);
2140+
nvme_config_write_zeroes(disk->queue, ns->ctrl);
21632141

21642142
set_disk_ro(disk, (id->nsattr & NVME_NS_ATTR_RO) ||
21652143
test_bit(NVME_NS_FORCE_RO, &ns->flags));

drivers/nvme/host/fabrics.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
/* default is -1: the fail fast mechanism is disabled */
1919
#define NVMF_DEF_FAIL_FAST_TMO -1
2020

21+
/*
22+
* Reserved one command for internal usage. This command is used for sending
23+
* the connect command, as well as for the keep alive command on the admin
24+
* queue once live.
25+
*/
26+
#define NVMF_RESERVED_TAGS 1
27+
2128
/*
2229
* Define a host as seen by the target. We allocate one at boot, but also
2330
* allow the override it when creating controllers. This is both to provide

drivers/nvme/host/fc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2863,7 +2863,7 @@ nvme_fc_create_io_queues(struct nvme_fc_ctrl *ctrl)
28632863
memset(&ctrl->tag_set, 0, sizeof(ctrl->tag_set));
28642864
ctrl->tag_set.ops = &nvme_fc_mq_ops;
28652865
ctrl->tag_set.queue_depth = ctrl->ctrl.opts->queue_size;
2866-
ctrl->tag_set.reserved_tags = 1; /* fabric connect */
2866+
ctrl->tag_set.reserved_tags = NVMF_RESERVED_TAGS;
28672867
ctrl->tag_set.numa_node = ctrl->ctrl.numa_node;
28682868
ctrl->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
28692869
ctrl->tag_set.cmd_size =
@@ -3485,7 +3485,7 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
34853485
memset(&ctrl->admin_tag_set, 0, sizeof(ctrl->admin_tag_set));
34863486
ctrl->admin_tag_set.ops = &nvme_fc_admin_mq_ops;
34873487
ctrl->admin_tag_set.queue_depth = NVME_AQ_MQ_TAG_DEPTH;
3488-
ctrl->admin_tag_set.reserved_tags = 2; /* fabric connect + Keep-Alive */
3488+
ctrl->admin_tag_set.reserved_tags = NVMF_RESERVED_TAGS;
34893489
ctrl->admin_tag_set.numa_node = ctrl->ctrl.numa_node;
34903490
ctrl->admin_tag_set.cmd_size =
34913491
struct_size((struct nvme_fcp_op_w_sgl *)NULL, priv,

drivers/nvme/host/rdma.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,11 @@ static int nvme_rdma_alloc_io_queues(struct nvme_rdma_ctrl *ctrl)
736736
return ret;
737737

738738
ctrl->ctrl.queue_count = nr_io_queues + 1;
739-
if (ctrl->ctrl.queue_count < 2)
740-
return 0;
739+
if (ctrl->ctrl.queue_count < 2) {
740+
dev_err(ctrl->ctrl.device,
741+
"unable to set any I/O queues\n");
742+
return -ENOMEM;
743+
}
741744

742745
dev_info(ctrl->ctrl.device,
743746
"creating %d I/O queues.\n", nr_io_queues);
@@ -798,7 +801,7 @@ static struct blk_mq_tag_set *nvme_rdma_alloc_tagset(struct nvme_ctrl *nctrl,
798801
memset(set, 0, sizeof(*set));
799802
set->ops = &nvme_rdma_admin_mq_ops;
800803
set->queue_depth = NVME_AQ_MQ_TAG_DEPTH;
801-
set->reserved_tags = 2; /* connect + keep-alive */
804+
set->reserved_tags = NVMF_RESERVED_TAGS;
802805
set->numa_node = nctrl->numa_node;
803806
set->cmd_size = sizeof(struct nvme_rdma_request) +
804807
NVME_RDMA_DATA_SGL_SIZE;
@@ -811,7 +814,7 @@ static struct blk_mq_tag_set *nvme_rdma_alloc_tagset(struct nvme_ctrl *nctrl,
811814
memset(set, 0, sizeof(*set));
812815
set->ops = &nvme_rdma_mq_ops;
813816
set->queue_depth = nctrl->sqsize + 1;
814-
set->reserved_tags = 1; /* fabric connect */
817+
set->reserved_tags = NVMF_RESERVED_TAGS;
815818
set->numa_node = nctrl->numa_node;
816819
set->flags = BLK_MQ_F_SHOULD_MERGE;
817820
set->cmd_size = sizeof(struct nvme_rdma_request) +

drivers/nvme/host/tcp.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ static inline void nvme_tcp_queue_request(struct nvme_tcp_request *req,
287287
* directly, otherwise queue io_work. Also, only do that if we
288288
* are on the same cpu, so we don't introduce contention.
289289
*/
290-
if (queue->io_cpu == __smp_processor_id() &&
290+
if (queue->io_cpu == raw_smp_processor_id() &&
291291
sync && empty && mutex_trylock(&queue->send_mutex)) {
292292
queue->more_requests = !last;
293293
nvme_tcp_send_all(queue);
@@ -568,6 +568,13 @@ static int nvme_tcp_setup_h2c_data_pdu(struct nvme_tcp_request *req,
568568
req->pdu_len = le32_to_cpu(pdu->r2t_length);
569569
req->pdu_sent = 0;
570570

571+
if (unlikely(!req->pdu_len)) {
572+
dev_err(queue->ctrl->ctrl.device,
573+
"req %d r2t len is %u, probably a bug...\n",
574+
rq->tag, req->pdu_len);
575+
return -EPROTO;
576+
}
577+
571578
if (unlikely(req->data_sent + req->pdu_len > req->data_len)) {
572579
dev_err(queue->ctrl->ctrl.device,
573580
"req %d r2t len %u exceeded data len %u (%zu sent)\n",
@@ -1575,7 +1582,7 @@ static struct blk_mq_tag_set *nvme_tcp_alloc_tagset(struct nvme_ctrl *nctrl,
15751582
memset(set, 0, sizeof(*set));
15761583
set->ops = &nvme_tcp_admin_mq_ops;
15771584
set->queue_depth = NVME_AQ_MQ_TAG_DEPTH;
1578-
set->reserved_tags = 2; /* connect + keep-alive */
1585+
set->reserved_tags = NVMF_RESERVED_TAGS;
15791586
set->numa_node = nctrl->numa_node;
15801587
set->flags = BLK_MQ_F_BLOCKING;
15811588
set->cmd_size = sizeof(struct nvme_tcp_request);
@@ -1587,7 +1594,7 @@ static struct blk_mq_tag_set *nvme_tcp_alloc_tagset(struct nvme_ctrl *nctrl,
15871594
memset(set, 0, sizeof(*set));
15881595
set->ops = &nvme_tcp_mq_ops;
15891596
set->queue_depth = nctrl->sqsize + 1;
1590-
set->reserved_tags = 1; /* fabric connect */
1597+
set->reserved_tags = NVMF_RESERVED_TAGS;
15911598
set->numa_node = nctrl->numa_node;
15921599
set->flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_BLOCKING;
15931600
set->cmd_size = sizeof(struct nvme_tcp_request);
@@ -1745,8 +1752,11 @@ static int nvme_tcp_alloc_io_queues(struct nvme_ctrl *ctrl)
17451752
return ret;
17461753

17471754
ctrl->queue_count = nr_io_queues + 1;
1748-
if (ctrl->queue_count < 2)
1749-
return 0;
1755+
if (ctrl->queue_count < 2) {
1756+
dev_err(ctrl->device,
1757+
"unable to set any I/O queues\n");
1758+
return -ENOMEM;
1759+
}
17501760

17511761
dev_info(ctrl->device,
17521762
"creating %d I/O queues.\n", nr_io_queues);

drivers/nvme/target/core.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,9 +1118,20 @@ static void nvmet_start_ctrl(struct nvmet_ctrl *ctrl)
11181118
{
11191119
lockdep_assert_held(&ctrl->lock);
11201120

1121-
if (nvmet_cc_iosqes(ctrl->cc) != NVME_NVM_IOSQES ||
1122-
nvmet_cc_iocqes(ctrl->cc) != NVME_NVM_IOCQES ||
1123-
nvmet_cc_mps(ctrl->cc) != 0 ||
1121+
/*
1122+
* Only I/O controllers should verify iosqes,iocqes.
1123+
* Strictly speaking, the spec says a discovery controller
1124+
* should verify iosqes,iocqes are zeroed, however that
1125+
* would break backwards compatibility, so don't enforce it.
1126+
*/
1127+
if (ctrl->subsys->type != NVME_NQN_DISC &&
1128+
(nvmet_cc_iosqes(ctrl->cc) != NVME_NVM_IOSQES ||
1129+
nvmet_cc_iocqes(ctrl->cc) != NVME_NVM_IOCQES)) {
1130+
ctrl->csts = NVME_CSTS_CFS;
1131+
return;
1132+
}
1133+
1134+
if (nvmet_cc_mps(ctrl->cc) != 0 ||
11241135
nvmet_cc_ams(ctrl->cc) != 0 ||
11251136
nvmet_cc_css(ctrl->cc) != 0) {
11261137
ctrl->csts = NVME_CSTS_CFS;

drivers/nvme/target/loop.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ static int nvme_loop_configure_admin_queue(struct nvme_loop_ctrl *ctrl)
349349
memset(&ctrl->admin_tag_set, 0, sizeof(ctrl->admin_tag_set));
350350
ctrl->admin_tag_set.ops = &nvme_loop_admin_mq_ops;
351351
ctrl->admin_tag_set.queue_depth = NVME_AQ_MQ_TAG_DEPTH;
352-
ctrl->admin_tag_set.reserved_tags = 2; /* connect + keep-alive */
352+
ctrl->admin_tag_set.reserved_tags = NVMF_RESERVED_TAGS;
353353
ctrl->admin_tag_set.numa_node = ctrl->ctrl.numa_node;
354354
ctrl->admin_tag_set.cmd_size = sizeof(struct nvme_loop_iod) +
355355
NVME_INLINE_SG_CNT * sizeof(struct scatterlist);
@@ -520,7 +520,7 @@ static int nvme_loop_create_io_queues(struct nvme_loop_ctrl *ctrl)
520520
memset(&ctrl->tag_set, 0, sizeof(ctrl->tag_set));
521521
ctrl->tag_set.ops = &nvme_loop_mq_ops;
522522
ctrl->tag_set.queue_depth = ctrl->ctrl.opts->queue_size;
523-
ctrl->tag_set.reserved_tags = 1; /* fabric connect */
523+
ctrl->tag_set.reserved_tags = NVMF_RESERVED_TAGS;
524524
ctrl->tag_set.numa_node = ctrl->ctrl.numa_node;
525525
ctrl->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
526526
ctrl->tag_set.cmd_size = sizeof(struct nvme_loop_iod) +

drivers/nvme/target/tcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,11 +1098,11 @@ static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue)
10981098
cmd->rbytes_done += ret;
10991099
}
11001100

1101+
nvmet_tcp_unmap_pdu_iovec(cmd);
11011102
if (queue->data_digest) {
11021103
nvmet_tcp_prep_recv_ddgst(cmd);
11031104
return 0;
11041105
}
1105-
nvmet_tcp_unmap_pdu_iovec(cmd);
11061106

11071107
if (!(cmd->flags & NVMET_TCP_F_INIT_FAILED) &&
11081108
cmd->rbytes_done == cmd->req.transfer_len) {

0 commit comments

Comments
 (0)