nvme_fcloop: fix abort race condition
authorJames Smart <jsmart2021@gmail.com>
Thu, 30 Nov 2017 00:47:30 +0000 (16:47 -0800)
committerChristoph Hellwig <hch@lst.de>
Mon, 8 Jan 2018 10:01:53 +0000 (11:01 +0100)
A test case revealed a race condition of an i/o completing on a thread
parallel to the delete_association generating the aborts for the
outstanding ios on the controller.  The i/o completion was freeing the
target fcloop context, thus the abort task referenced the just-freed
memory.

Correct by clearing the target/initiator cross pointers in the io
completion and abort tasks before calling the callbacks. On aborts
that detect already finished io's, ensure the complete context is
called.

Signed-off-by: James Smart <james.smart@broadcom.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/target/fcloop.c

index 7b75d9de55ab0d33939bf314a81ee01e26a6d1b1..3eb2a0733f46de5fb00c69e3e1744c6d5423b7d3 100644 (file)
@@ -370,6 +370,7 @@ fcloop_tgt_fcprqst_done_work(struct work_struct *work)
 
        spin_lock(&tfcp_req->reqlock);
        fcpreq = tfcp_req->fcpreq;
+       tfcp_req->fcpreq = NULL;
        spin_unlock(&tfcp_req->reqlock);
 
        if (tport->remoteport && fcpreq) {
@@ -611,11 +612,7 @@ fcloop_fcp_abort(struct nvme_fc_local_port *localport,
 
        if (!tfcp_req)
                /* abort has already been called */
-               return;
-
-       if (rport->targetport)
-               nvmet_fc_rcv_fcp_abort(rport->targetport,
-                                       &tfcp_req->tgt_fcp_req);
+               goto finish;
 
        /* break initiator/target relationship for io */
        spin_lock(&tfcp_req->reqlock);
@@ -623,6 +620,11 @@ fcloop_fcp_abort(struct nvme_fc_local_port *localport,
        tfcp_req->fcpreq = NULL;
        spin_unlock(&tfcp_req->reqlock);
 
+       if (rport->targetport)
+               nvmet_fc_rcv_fcp_abort(rport->targetport,
+                                       &tfcp_req->tgt_fcp_req);
+
+finish:
        /* post the aborted io completion */
        fcpreq->status = -ECANCELED;
        schedule_work(&inireq->iniwork);