Skip to content

Commit e369edb

Browse files
committed
Merge tag 'nvme-5.13-2021-06-03' of git://git.infradead.org/nvme into block-5.13
Pull NVMe fixes from Christoph: "nvme fixes for Linux 5.13: - fix corruption in RDMA in-capsule SGLs (Sagi Grimberg) - nvme-loop reset fixes (Hannes Reinecke) - nvmet fix for freeing unallocated p2pmem (Max Gurtovoy)" * tag 'nvme-5.13-2021-06-03' of git://git.infradead.org/nvme: nvmet: fix freeing unallocated p2pmem nvme-loop: do not warn for deleted controllers during reset nvme-loop: check for NVME_LOOP_Q_LIVE in nvme_loop_destroy_admin_queue() nvme-loop: clear NVME_LOOP_Q_LIVE when nvme_loop_configure_admin_queue() fails nvme-loop: reset queue count to 1 in nvme_loop_destroy_io_queues() nvme-rdma: fix in-casule data send for chained sgls
2 parents a4b58f1 + bcd9a07 commit e369edb

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

drivers/nvme/host/rdma.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,16 +1320,17 @@ static int nvme_rdma_map_sg_inline(struct nvme_rdma_queue *queue,
13201320
int count)
13211321
{
13221322
struct nvme_sgl_desc *sg = &c->common.dptr.sgl;
1323-
struct scatterlist *sgl = req->data_sgl.sg_table.sgl;
13241323
struct ib_sge *sge = &req->sge[1];
1324+
struct scatterlist *sgl;
13251325
u32 len = 0;
13261326
int i;
13271327

1328-
for (i = 0; i < count; i++, sgl++, sge++) {
1328+
for_each_sg(req->data_sgl.sg_table.sgl, sgl, count, i) {
13291329
sge->addr = sg_dma_address(sgl);
13301330
sge->length = sg_dma_len(sgl);
13311331
sge->lkey = queue->device->pd->local_dma_lkey;
13321332
len += sge->length;
1333+
sge++;
13331334
}
13341335

13351336
sg->addr = cpu_to_le64(queue->ctrl->ctrl.icdoff);

drivers/nvme/target/core.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,45 +1005,43 @@ static unsigned int nvmet_data_transfer_len(struct nvmet_req *req)
10051005
return req->transfer_len - req->metadata_len;
10061006
}
10071007

1008-
static int nvmet_req_alloc_p2pmem_sgls(struct nvmet_req *req)
1008+
static int nvmet_req_alloc_p2pmem_sgls(struct pci_dev *p2p_dev,
1009+
struct nvmet_req *req)
10091010
{
1010-
req->sg = pci_p2pmem_alloc_sgl(req->p2p_dev, &req->sg_cnt,
1011+
req->sg = pci_p2pmem_alloc_sgl(p2p_dev, &req->sg_cnt,
10111012
nvmet_data_transfer_len(req));
10121013
if (!req->sg)
10131014
goto out_err;
10141015

10151016
if (req->metadata_len) {
1016-
req->metadata_sg = pci_p2pmem_alloc_sgl(req->p2p_dev,
1017+
req->metadata_sg = pci_p2pmem_alloc_sgl(p2p_dev,
10171018
&req->metadata_sg_cnt, req->metadata_len);
10181019
if (!req->metadata_sg)
10191020
goto out_free_sg;
10201021
}
1022+
1023+
req->p2p_dev = p2p_dev;
1024+
10211025
return 0;
10221026
out_free_sg:
10231027
pci_p2pmem_free_sgl(req->p2p_dev, req->sg);
10241028
out_err:
10251029
return -ENOMEM;
10261030
}
10271031

1028-
static bool nvmet_req_find_p2p_dev(struct nvmet_req *req)
1032+
static struct pci_dev *nvmet_req_find_p2p_dev(struct nvmet_req *req)
10291033
{
1030-
if (!IS_ENABLED(CONFIG_PCI_P2PDMA))
1031-
return false;
1032-
1033-
if (req->sq->ctrl && req->sq->qid && req->ns) {
1034-
req->p2p_dev = radix_tree_lookup(&req->sq->ctrl->p2p_ns_map,
1035-
req->ns->nsid);
1036-
if (req->p2p_dev)
1037-
return true;
1038-
}
1039-
1040-
req->p2p_dev = NULL;
1041-
return false;
1034+
if (!IS_ENABLED(CONFIG_PCI_P2PDMA) ||
1035+
!req->sq->ctrl || !req->sq->qid || !req->ns)
1036+
return NULL;
1037+
return radix_tree_lookup(&req->sq->ctrl->p2p_ns_map, req->ns->nsid);
10421038
}
10431039

10441040
int nvmet_req_alloc_sgls(struct nvmet_req *req)
10451041
{
1046-
if (nvmet_req_find_p2p_dev(req) && !nvmet_req_alloc_p2pmem_sgls(req))
1042+
struct pci_dev *p2p_dev = nvmet_req_find_p2p_dev(req);
1043+
1044+
if (p2p_dev && !nvmet_req_alloc_p2pmem_sgls(p2p_dev, req))
10471045
return 0;
10481046

10491047
req->sg = sgl_alloc(nvmet_data_transfer_len(req), GFP_KERNEL,
@@ -1072,6 +1070,7 @@ void nvmet_req_free_sgls(struct nvmet_req *req)
10721070
pci_p2pmem_free_sgl(req->p2p_dev, req->sg);
10731071
if (req->metadata_sg)
10741072
pci_p2pmem_free_sgl(req->p2p_dev, req->metadata_sg);
1073+
req->p2p_dev = NULL;
10751074
} else {
10761075
sgl_free(req->sg);
10771076
if (req->metadata_sg)

drivers/nvme/target/loop.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ static const struct blk_mq_ops nvme_loop_admin_mq_ops = {
263263

264264
static void nvme_loop_destroy_admin_queue(struct nvme_loop_ctrl *ctrl)
265265
{
266-
clear_bit(NVME_LOOP_Q_LIVE, &ctrl->queues[0].flags);
266+
if (!test_and_clear_bit(NVME_LOOP_Q_LIVE, &ctrl->queues[0].flags))
267+
return;
267268
nvmet_sq_destroy(&ctrl->queues[0].nvme_sq);
268269
blk_cleanup_queue(ctrl->ctrl.admin_q);
269270
blk_cleanup_queue(ctrl->ctrl.fabrics_q);
@@ -299,6 +300,7 @@ static void nvme_loop_destroy_io_queues(struct nvme_loop_ctrl *ctrl)
299300
clear_bit(NVME_LOOP_Q_LIVE, &ctrl->queues[i].flags);
300301
nvmet_sq_destroy(&ctrl->queues[i].nvme_sq);
301302
}
303+
ctrl->ctrl.queue_count = 1;
302304
}
303305

304306
static int nvme_loop_init_io_queues(struct nvme_loop_ctrl *ctrl)
@@ -405,6 +407,7 @@ static int nvme_loop_configure_admin_queue(struct nvme_loop_ctrl *ctrl)
405407
return 0;
406408

407409
out_cleanup_queue:
410+
clear_bit(NVME_LOOP_Q_LIVE, &ctrl->queues[0].flags);
408411
blk_cleanup_queue(ctrl->ctrl.admin_q);
409412
out_cleanup_fabrics_q:
410413
blk_cleanup_queue(ctrl->ctrl.fabrics_q);
@@ -462,8 +465,10 @@ static void nvme_loop_reset_ctrl_work(struct work_struct *work)
462465
nvme_loop_shutdown_ctrl(ctrl);
463466

464467
if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) {
465-
/* state change failure should never happen */
466-
WARN_ON_ONCE(1);
468+
if (ctrl->ctrl.state != NVME_CTRL_DELETING &&
469+
ctrl->ctrl.state != NVME_CTRL_DELETING_NOIO)
470+
/* state change failure for non-deleted ctrl? */
471+
WARN_ON_ONCE(1);
467472
return;
468473
}
469474

0 commit comments

Comments
 (0)