Skip to content

Commit db5a540

Browse files
igawkeithbusch
authored andcommitted
nvmet-fc: move lsop put work to nvmet_fc_ls_req_op
It’s possible for more than one async command to be in flight from __nvmet_fc_send_ls_req. For each command, a tgtport reference is taken. In the current code, only one put work item is queued at a time, which results in a leaked reference. To fix this, move the work item to the nvmet_fc_ls_req_op struct, which already tracks all resources related to the command. Fixes: 710c69d ("nvmet-fc: avoid deadlock on delete association path") Reviewed-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Daniel Wagner <wagi@kernel.org> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent 6ff1bd7 commit db5a540

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

  • drivers/nvme/target

drivers/nvme/target/fc.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ struct nvmet_fc_ls_req_op { /* for an LS RQST XMT */
5454
int ls_error;
5555
struct list_head lsreq_list; /* tgtport->ls_req_list */
5656
bool req_queued;
57+
58+
struct work_struct put_work;
5759
};
5860

5961

@@ -111,8 +113,6 @@ struct nvmet_fc_tgtport {
111113
struct nvmet_fc_port_entry *pe;
112114
struct kref ref;
113115
u32 max_sg_cnt;
114-
115-
struct work_struct put_work;
116116
};
117117

118118
struct nvmet_fc_port_entry {
@@ -235,12 +235,13 @@ static int nvmet_fc_tgt_a_get(struct nvmet_fc_tgt_assoc *assoc);
235235
static void nvmet_fc_tgt_q_put(struct nvmet_fc_tgt_queue *queue);
236236
static int nvmet_fc_tgt_q_get(struct nvmet_fc_tgt_queue *queue);
237237
static void nvmet_fc_tgtport_put(struct nvmet_fc_tgtport *tgtport);
238-
static void nvmet_fc_put_tgtport_work(struct work_struct *work)
238+
static void nvmet_fc_put_lsop_work(struct work_struct *work)
239239
{
240-
struct nvmet_fc_tgtport *tgtport =
241-
container_of(work, struct nvmet_fc_tgtport, put_work);
240+
struct nvmet_fc_ls_req_op *lsop =
241+
container_of(work, struct nvmet_fc_ls_req_op, put_work);
242242

243-
nvmet_fc_tgtport_put(tgtport);
243+
nvmet_fc_tgtport_put(lsop->tgtport);
244+
kfree(lsop);
244245
}
245246
static int nvmet_fc_tgtport_get(struct nvmet_fc_tgtport *tgtport);
246247
static void nvmet_fc_handle_fcp_rqst(struct nvmet_fc_tgtport *tgtport,
@@ -367,7 +368,7 @@ __nvmet_fc_finish_ls_req(struct nvmet_fc_ls_req_op *lsop)
367368
DMA_BIDIRECTIONAL);
368369

369370
out_putwork:
370-
queue_work(nvmet_wq, &tgtport->put_work);
371+
queue_work(nvmet_wq, &lsop->put_work);
371372
}
372373

373374
static int
@@ -388,6 +389,7 @@ __nvmet_fc_send_ls_req(struct nvmet_fc_tgtport *tgtport,
388389
lsreq->done = done;
389390
lsop->req_queued = false;
390391
INIT_LIST_HEAD(&lsop->lsreq_list);
392+
INIT_WORK(&lsop->put_work, nvmet_fc_put_lsop_work);
391393

392394
lsreq->rqstdma = fc_dma_map_single(tgtport->dev, lsreq->rqstaddr,
393395
lsreq->rqstlen + lsreq->rsplen,
@@ -447,8 +449,6 @@ nvmet_fc_disconnect_assoc_done(struct nvmefc_ls_req *lsreq, int status)
447449
__nvmet_fc_finish_ls_req(lsop);
448450

449451
/* fc-nvme target doesn't care about success or failure of cmd */
450-
451-
kfree(lsop);
452452
}
453453

454454
/*
@@ -1410,7 +1410,6 @@ nvmet_fc_register_targetport(struct nvmet_fc_port_info *pinfo,
14101410
kref_init(&newrec->ref);
14111411
ida_init(&newrec->assoc_cnt);
14121412
newrec->max_sg_cnt = template->max_sgl_segments;
1413-
INIT_WORK(&newrec->put_work, nvmet_fc_put_tgtport_work);
14141413

14151414
ret = nvmet_fc_alloc_ls_iodlist(newrec);
14161415
if (ret) {

0 commit comments

Comments
 (0)