Skip to content

Commit bbc1528

Browse files
committed
Merge branch 'nvme-4.20' of git://git.infradead.org/nvme into for-4.20/block
Pull NVMe updates from Christoph: "The second batch of updates for Linux 4.20: - lot of fixes for issues found by static type checkers from Bart - two small fixes from Keith - fabrics cleanups in preparation of the TCP transport from Sagi - more cleanups from Chaitanya" * 'nvme-4.20' of git://git.infradead.org/nvme: nvme-fabrics: move controller options matching to fabrics nvme-rdma: always have a valid trsvcid nvme-pci: remove duplicate check nvme-pci: fix hot removal during error handling nvmet-fcloop: suppress a compiler warning nvme-core: make implicit seed truncation explicit nvmet-fc: fix kernel-doc headers nvme-fc: rework the request initialization code nvme-fc: introduce struct nvme_fcp_op_w_sgl nvme-fc: fix kernel-doc headers nvmet: avoid integer overflow in the discard code nvmet-rdma: declare local symbols static nvmet: use strlcpy() instead of strcpy() nvme-pci: fix nvme_suspend_queue() kernel-doc header nvme-core: rework a NQN copying operation nvme-core: declare local symbols static nvmet-rdma: check for timeout in nvme_rdma_wait_for_cm() nvmet: use strcmp() instead of strncmp() for subsystem lookup nvmet: remove unreachable code nvme: update node paths after adding new path
2 parents ee75fa2 + b7c7be6 commit bbc1528

File tree

14 files changed

+107
-95
lines changed

14 files changed

+107
-95
lines changed

drivers/nvme/host/core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
11321132

11331133
return nvme_submit_user_cmd(ns->queue, &c,
11341134
(void __user *)(uintptr_t)io.addr, length,
1135-
metadata, meta_len, io.slba, NULL, 0);
1135+
metadata, meta_len, lower_32_bits(io.slba), NULL, 0);
11361136
}
11371137

11381138
static u32 nvme_known_admin_effects(u8 opcode)
@@ -2076,7 +2076,7 @@ static void nvme_init_subnqn(struct nvme_subsystem *subsys, struct nvme_ctrl *ct
20762076

20772077
nqnlen = strnlen(id->subnqn, NVMF_NQN_SIZE);
20782078
if (nqnlen > 0 && nqnlen < NVMF_NQN_SIZE) {
2079-
strncpy(subsys->subnqn, id->subnqn, NVMF_NQN_SIZE);
2079+
strlcpy(subsys->subnqn, id->subnqn, NVMF_NQN_SIZE);
20802080
return;
20812081
}
20822082

@@ -2729,7 +2729,7 @@ static umode_t nvme_ns_id_attrs_are_visible(struct kobject *kobj,
27292729
return a->mode;
27302730
}
27312731

2732-
const struct attribute_group nvme_ns_id_attr_group = {
2732+
static const struct attribute_group nvme_ns_id_attr_group = {
27332733
.attrs = nvme_ns_id_attrs,
27342734
.is_visible = nvme_ns_id_attrs_are_visible,
27352735
};

drivers/nvme/host/fabrics.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,36 @@ static int nvmf_check_required_opts(struct nvmf_ctrl_options *opts,
868868
return 0;
869869
}
870870

871+
bool nvmf_ip_options_match(struct nvme_ctrl *ctrl,
872+
struct nvmf_ctrl_options *opts)
873+
{
874+
if (!nvmf_ctlr_matches_baseopts(ctrl, opts) ||
875+
strcmp(opts->traddr, ctrl->opts->traddr) ||
876+
strcmp(opts->trsvcid, ctrl->opts->trsvcid))
877+
return false;
878+
879+
/*
880+
* Checking the local address is rough. In most cases, none is specified
881+
* and the host port is selected by the stack.
882+
*
883+
* Assume no match if:
884+
* - local address is specified and address is not the same
885+
* - local address is not specified but remote is, or vice versa
886+
* (admin using specific host_traddr when it matters).
887+
*/
888+
if ((opts->mask & NVMF_OPT_HOST_TRADDR) &&
889+
(ctrl->opts->mask & NVMF_OPT_HOST_TRADDR)) {
890+
if (strcmp(opts->host_traddr, ctrl->opts->host_traddr))
891+
return false;
892+
} else if ((opts->mask & NVMF_OPT_HOST_TRADDR) ||
893+
(ctrl->opts->mask & NVMF_OPT_HOST_TRADDR)) {
894+
return false;
895+
}
896+
897+
return true;
898+
}
899+
EXPORT_SYMBOL_GPL(nvmf_ip_options_match);
900+
871901
static int nvmf_check_allowed_opts(struct nvmf_ctrl_options *opts,
872902
unsigned int allowed_opts)
873903
{

drivers/nvme/host/fabrics.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ blk_status_t nvmf_fail_nonready_command(struct nvme_ctrl *ctrl,
166166
struct request *rq);
167167
bool __nvmf_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
168168
bool queue_live);
169+
bool nvmf_ip_options_match(struct nvme_ctrl *ctrl,
170+
struct nvmf_ctrl_options *opts);
169171

170172
static inline bool nvmf_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
171173
bool queue_live)

drivers/nvme/host/fc.c

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <uapi/scsi/fc/fc_fs.h>
2121
#include <uapi/scsi/fc/fc_els.h>
2222
#include <linux/delay.h>
23+
#include <linux/overflow.h>
2324

2425
#include "nvme.h"
2526
#include "fabrics.h"
@@ -104,6 +105,12 @@ struct nvme_fc_fcp_op {
104105
struct nvme_fc_ersp_iu rsp_iu;
105106
};
106107

108+
struct nvme_fcp_op_w_sgl {
109+
struct nvme_fc_fcp_op op;
110+
struct scatterlist sgl[SG_CHUNK_SIZE];
111+
uint8_t priv[0];
112+
};
113+
107114
struct nvme_fc_lport {
108115
struct nvme_fc_local_port localport;
109116

@@ -317,7 +324,7 @@ nvme_fc_attach_to_unreg_lport(struct nvme_fc_port_info *pinfo,
317324
* @template: LLDD entrypoints and operational parameters for the port
318325
* @dev: physical hardware device node port corresponds to. Will be
319326
* used for DMA mappings
320-
* @lport_p: pointer to a local port pointer. Upon success, the routine
327+
* @portptr: pointer to a local port pointer. Upon success, the routine
321328
* will allocate a nvme_fc_local_port structure and place its
322329
* address in the local port pointer. Upon failure, local port
323330
* pointer will be set to 0.
@@ -425,8 +432,7 @@ EXPORT_SYMBOL_GPL(nvme_fc_register_localport);
425432
* nvme_fc_unregister_localport - transport entry point called by an
426433
* LLDD to deregister/remove a previously
427434
* registered a NVME host FC port.
428-
* @localport: pointer to the (registered) local port that is to be
429-
* deregistered.
435+
* @portptr: pointer to the (registered) local port that is to be deregistered.
430436
*
431437
* Returns:
432438
* a completion status. Must be 0 upon success; a negative errno
@@ -632,7 +638,7 @@ __nvme_fc_set_dev_loss_tmo(struct nvme_fc_rport *rport,
632638
* @localport: pointer to the (registered) local port that the remote
633639
* subsystem port is connected to.
634640
* @pinfo: pointer to information about the port to be registered
635-
* @rport_p: pointer to a remote port pointer. Upon success, the routine
641+
* @portptr: pointer to a remote port pointer. Upon success, the routine
636642
* will allocate a nvme_fc_remote_port structure and place its
637643
* address in the remote port pointer. Upon failure, remote port
638644
* pointer will be set to 0.
@@ -809,8 +815,8 @@ nvme_fc_ctrl_connectivity_loss(struct nvme_fc_ctrl *ctrl)
809815
* nvme_fc_unregister_remoteport - transport entry point called by an
810816
* LLDD to deregister/remove a previously
811817
* registered a NVME subsystem FC port.
812-
* @remoteport: pointer to the (registered) remote port that is to be
813-
* deregistered.
818+
* @portptr: pointer to the (registered) remote port that is to be
819+
* deregistered.
814820
*
815821
* Returns:
816822
* a completion status. Must be 0 upon success; a negative errno
@@ -1687,6 +1693,8 @@ __nvme_fc_init_request(struct nvme_fc_ctrl *ctrl,
16871693
struct nvme_fc_queue *queue, struct nvme_fc_fcp_op *op,
16881694
struct request *rq, u32 rqno)
16891695
{
1696+
struct nvme_fcp_op_w_sgl *op_w_sgl =
1697+
container_of(op, typeof(*op_w_sgl), op);
16901698
struct nvme_fc_cmd_iu *cmdiu = &op->cmd_iu;
16911699
int ret = 0;
16921700

@@ -1696,7 +1704,6 @@ __nvme_fc_init_request(struct nvme_fc_ctrl *ctrl,
16961704
op->fcp_req.rspaddr = &op->rsp_iu;
16971705
op->fcp_req.rsplen = sizeof(op->rsp_iu);
16981706
op->fcp_req.done = nvme_fc_fcpio_done;
1699-
op->fcp_req.first_sgl = (struct scatterlist *)&op[1];
17001707
op->fcp_req.private = &op->fcp_req.first_sgl[SG_CHUNK_SIZE];
17011708
op->ctrl = ctrl;
17021709
op->queue = queue;
@@ -1735,12 +1742,17 @@ nvme_fc_init_request(struct blk_mq_tag_set *set, struct request *rq,
17351742
unsigned int hctx_idx, unsigned int numa_node)
17361743
{
17371744
struct nvme_fc_ctrl *ctrl = set->driver_data;
1738-
struct nvme_fc_fcp_op *op = blk_mq_rq_to_pdu(rq);
1745+
struct nvme_fcp_op_w_sgl *op = blk_mq_rq_to_pdu(rq);
17391746
int queue_idx = (set == &ctrl->tag_set) ? hctx_idx + 1 : 0;
17401747
struct nvme_fc_queue *queue = &ctrl->queues[queue_idx];
1748+
int res;
17411749

17421750
nvme_req(rq)->ctrl = &ctrl->ctrl;
1743-
return __nvme_fc_init_request(ctrl, queue, op, rq, queue->rqcnt++);
1751+
res = __nvme_fc_init_request(ctrl, queue, &op->op, rq, queue->rqcnt++);
1752+
if (res)
1753+
return res;
1754+
op->op.fcp_req.first_sgl = &op->sgl[0];
1755+
return res;
17441756
}
17451757

17461758
static int
@@ -1770,7 +1782,6 @@ nvme_fc_init_aen_ops(struct nvme_fc_ctrl *ctrl)
17701782
}
17711783

17721784
aen_op->flags = FCOP_FLAGS_AEN;
1773-
aen_op->fcp_req.first_sgl = NULL; /* no sg list */
17741785
aen_op->fcp_req.private = private;
17751786

17761787
memset(sqe, 0, sizeof(*sqe));
@@ -2424,10 +2435,9 @@ nvme_fc_create_io_queues(struct nvme_fc_ctrl *ctrl)
24242435
ctrl->tag_set.reserved_tags = 1; /* fabric connect */
24252436
ctrl->tag_set.numa_node = NUMA_NO_NODE;
24262437
ctrl->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
2427-
ctrl->tag_set.cmd_size = sizeof(struct nvme_fc_fcp_op) +
2428-
(SG_CHUNK_SIZE *
2429-
sizeof(struct scatterlist)) +
2430-
ctrl->lport->ops->fcprqst_priv_sz;
2438+
ctrl->tag_set.cmd_size =
2439+
struct_size((struct nvme_fcp_op_w_sgl *)NULL, priv,
2440+
ctrl->lport->ops->fcprqst_priv_sz);
24312441
ctrl->tag_set.driver_data = ctrl;
24322442
ctrl->tag_set.nr_hw_queues = ctrl->ctrl.queue_count - 1;
24332443
ctrl->tag_set.timeout = NVME_IO_TIMEOUT;
@@ -3029,10 +3039,9 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
30293039
ctrl->admin_tag_set.queue_depth = NVME_AQ_MQ_TAG_DEPTH;
30303040
ctrl->admin_tag_set.reserved_tags = 2; /* fabric connect + Keep-Alive */
30313041
ctrl->admin_tag_set.numa_node = NUMA_NO_NODE;
3032-
ctrl->admin_tag_set.cmd_size = sizeof(struct nvme_fc_fcp_op) +
3033-
(SG_CHUNK_SIZE *
3034-
sizeof(struct scatterlist)) +
3035-
ctrl->lport->ops->fcprqst_priv_sz;
3042+
ctrl->admin_tag_set.cmd_size =
3043+
struct_size((struct nvme_fcp_op_w_sgl *)NULL, priv,
3044+
ctrl->lport->ops->fcprqst_priv_sz);
30363045
ctrl->admin_tag_set.driver_data = ctrl;
30373046
ctrl->admin_tag_set.nr_hw_queues = 1;
30383047
ctrl->admin_tag_set.timeout = ADMIN_TIMEOUT;

drivers/nvme/host/multipath.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,15 @@ static void nvme_mpath_set_live(struct nvme_ns *ns)
321321
device_add_disk(&head->subsys->dev, head->disk,
322322
nvme_ns_id_attr_groups);
323323

324+
if (nvme_path_is_optimized(ns)) {
325+
int node, srcu_idx;
326+
327+
srcu_idx = srcu_read_lock(&head->srcu);
328+
for_each_node(node)
329+
__nvme_find_path(head, node);
330+
srcu_read_unlock(&head->srcu, srcu_idx);
331+
}
332+
324333
kblockd_schedule_work(&ns->head->requeue_work);
325334
}
326335

drivers/nvme/host/pci.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -772,10 +772,10 @@ static blk_status_t nvme_map_data(struct nvme_dev *dev, struct request *req,
772772

773773
if (!dma_map_sg(dev->dev, &iod->meta_sg, 1, dma_dir))
774774
goto out_unmap;
775-
}
776775

777-
if (blk_integrity_rq(req))
778776
cmnd->rw.metadata = cpu_to_le64(sg_dma_address(&iod->meta_sg));
777+
}
778+
779779
return BLK_STS_OK;
780780

781781
out_unmap:
@@ -1249,7 +1249,7 @@ static void nvme_free_queues(struct nvme_dev *dev, int lowest)
12491249

12501250
/**
12511251
* nvme_suspend_queue - put queue into suspended state
1252-
* @nvmeq - queue to suspend
1252+
* @nvmeq: queue to suspend
12531253
*/
12541254
static int nvme_suspend_queue(struct nvme_queue *nvmeq)
12551255
{
@@ -2564,13 +2564,12 @@ static void nvme_remove(struct pci_dev *pdev)
25642564
struct nvme_dev *dev = pci_get_drvdata(pdev);
25652565

25662566
nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_DELETING);
2567-
2568-
cancel_work_sync(&dev->ctrl.reset_work);
25692567
pci_set_drvdata(pdev, NULL);
25702568

25712569
if (!pci_device_is_present(pdev)) {
25722570
nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_DEAD);
25732571
nvme_dev_disable(dev, true);
2572+
nvme_dev_remove_admin(dev);
25742573
}
25752574

25762575
flush_work(&dev->ctrl.reset_work);

drivers/nvme/host/rdma.c

Lines changed: 21 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,15 @@ static void nvme_rdma_qp_event(struct ib_event *event, void *context)
233233

234234
static int nvme_rdma_wait_for_cm(struct nvme_rdma_queue *queue)
235235
{
236-
wait_for_completion_interruptible_timeout(&queue->cm_done,
236+
int ret;
237+
238+
ret = wait_for_completion_interruptible_timeout(&queue->cm_done,
237239
msecs_to_jiffies(NVME_RDMA_CONNECT_TIMEOUT_MS) + 1);
240+
if (ret < 0)
241+
return ret;
242+
if (ret == 0)
243+
return -ETIMEDOUT;
244+
WARN_ON_ONCE(queue->cm_error > 0);
238245
return queue->cm_error;
239246
}
240247

@@ -1849,54 +1856,6 @@ static const struct nvme_ctrl_ops nvme_rdma_ctrl_ops = {
18491856
.stop_ctrl = nvme_rdma_stop_ctrl,
18501857
};
18511858

1852-
static inline bool
1853-
__nvme_rdma_options_match(struct nvme_rdma_ctrl *ctrl,
1854-
struct nvmf_ctrl_options *opts)
1855-
{
1856-
char *stdport = __stringify(NVME_RDMA_IP_PORT);
1857-
1858-
1859-
if (!nvmf_ctlr_matches_baseopts(&ctrl->ctrl, opts) ||
1860-
strcmp(opts->traddr, ctrl->ctrl.opts->traddr))
1861-
return false;
1862-
1863-
if (opts->mask & NVMF_OPT_TRSVCID &&
1864-
ctrl->ctrl.opts->mask & NVMF_OPT_TRSVCID) {
1865-
if (strcmp(opts->trsvcid, ctrl->ctrl.opts->trsvcid))
1866-
return false;
1867-
} else if (opts->mask & NVMF_OPT_TRSVCID) {
1868-
if (strcmp(opts->trsvcid, stdport))
1869-
return false;
1870-
} else if (ctrl->ctrl.opts->mask & NVMF_OPT_TRSVCID) {
1871-
if (strcmp(stdport, ctrl->ctrl.opts->trsvcid))
1872-
return false;
1873-
}
1874-
/* else, it's a match as both have stdport. Fall to next checks */
1875-
1876-
/*
1877-
* checking the local address is rough. In most cases, one
1878-
* is not specified and the host port is selected by the stack.
1879-
*
1880-
* Assume no match if:
1881-
* local address is specified and address is not the same
1882-
* local address is not specified but remote is, or vice versa
1883-
* (admin using specific host_traddr when it matters).
1884-
*/
1885-
if (opts->mask & NVMF_OPT_HOST_TRADDR &&
1886-
ctrl->ctrl.opts->mask & NVMF_OPT_HOST_TRADDR) {
1887-
if (strcmp(opts->host_traddr, ctrl->ctrl.opts->host_traddr))
1888-
return false;
1889-
} else if (opts->mask & NVMF_OPT_HOST_TRADDR ||
1890-
ctrl->ctrl.opts->mask & NVMF_OPT_HOST_TRADDR)
1891-
return false;
1892-
/*
1893-
* if neither controller had an host port specified, assume it's
1894-
* a match as everything else matched.
1895-
*/
1896-
1897-
return true;
1898-
}
1899-
19001859
/*
19011860
* Fails a connection request if it matches an existing controller
19021861
* (association) with the same tuple:
@@ -1917,7 +1876,7 @@ nvme_rdma_existing_controller(struct nvmf_ctrl_options *opts)
19171876

19181877
mutex_lock(&nvme_rdma_ctrl_mutex);
19191878
list_for_each_entry(ctrl, &nvme_rdma_ctrl_list, list) {
1920-
found = __nvme_rdma_options_match(ctrl, opts);
1879+
found = nvmf_ip_options_match(&ctrl->ctrl, opts);
19211880
if (found)
19221881
break;
19231882
}
@@ -1932,23 +1891,28 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev,
19321891
struct nvme_rdma_ctrl *ctrl;
19331892
int ret;
19341893
bool changed;
1935-
char *port;
19361894

19371895
ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
19381896
if (!ctrl)
19391897
return ERR_PTR(-ENOMEM);
19401898
ctrl->ctrl.opts = opts;
19411899
INIT_LIST_HEAD(&ctrl->list);
19421900

1943-
if (opts->mask & NVMF_OPT_TRSVCID)
1944-
port = opts->trsvcid;
1945-
else
1946-
port = __stringify(NVME_RDMA_IP_PORT);
1901+
if (!(opts->mask & NVMF_OPT_TRSVCID)) {
1902+
opts->trsvcid =
1903+
kstrdup(__stringify(NVME_RDMA_IP_PORT), GFP_KERNEL);
1904+
if (!opts->trsvcid) {
1905+
ret = -ENOMEM;
1906+
goto out_free_ctrl;
1907+
}
1908+
opts->mask |= NVMF_OPT_TRSVCID;
1909+
}
19471910

19481911
ret = inet_pton_with_scope(&init_net, AF_UNSPEC,
1949-
opts->traddr, port, &ctrl->addr);
1912+
opts->traddr, opts->trsvcid, &ctrl->addr);
19501913
if (ret) {
1951-
pr_err("malformed address passed: %s:%s\n", opts->traddr, port);
1914+
pr_err("malformed address passed: %s:%s\n",
1915+
opts->traddr, opts->trsvcid);
19521916
goto out_free_ctrl;
19531917
}
19541918

drivers/nvme/target/admin-cmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
353353
if (req->port->inline_data_size)
354354
id->sgls |= cpu_to_le32(1 << 20);
355355

356-
strcpy(id->subnqn, ctrl->subsys->subsysnqn);
356+
strlcpy(id->subnqn, ctrl->subsys->subsysnqn, sizeof(id->subnqn));
357357

358358
/* Max command capsule size is sqe + single page of in-capsule data */
359359
id->ioccsz = cpu_to_le32((sizeof(struct nvme_command) +

drivers/nvme/target/core.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,8 +1105,7 @@ static struct nvmet_subsys *nvmet_find_get_subsys(struct nvmet_port *port,
11051105
if (!port)
11061106
return NULL;
11071107

1108-
if (!strncmp(NVME_DISC_SUBSYS_NAME, subsysnqn,
1109-
NVMF_NQN_SIZE)) {
1108+
if (!strcmp(NVME_DISC_SUBSYS_NAME, subsysnqn)) {
11101109
if (!kref_get_unless_zero(&nvmet_disc_subsys->ref))
11111110
return NULL;
11121111
return nvmet_disc_subsys;

0 commit comments

Comments
 (0)