Patch "scsi: fnic: Finish scsi_cmnd before dropping the spinlock" has been added to the 5.16-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    scsi: fnic: Finish scsi_cmnd before dropping the spinlock

to the 5.16-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     scsi-fnic-finish-scsi_cmnd-before-dropping-the-spinl.patch
and it can be found in the queue-5.16 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 41ed00e2e0ef21f64a79469709fe29f55a64f56d
Author: David Jeffery <djeffery@xxxxxxxxxx>
Date:   Fri Mar 11 13:43:59 2022 -0500

    scsi: fnic: Finish scsi_cmnd before dropping the spinlock
    
    [ Upstream commit 733ab7e1b5d1041204c4ca7373f6e6f9d08e3283 ]
    
    When aborting a SCSI command through fnic, there is a race with the fnic
    interrupt handler which can result in the SCSI command and its request
    being completed twice. If the interrupt handler claims the command by
    setting CMD_SP to NULL first, the abort handler assumes the interrupt
    handler has completed the command and returns SUCCESS, causing the request
    for the scsi_cmnd to be re-queued.
    
    But the interrupt handler may not have finished the command yet. After it
    drops the spinlock protecting CMD_SP, it does memory cleanup before finally
    calling scsi_done() to complete the scsi_cmnd. If the call to scsi_done
    occurs after the abort handler finishes and re-queues the request, the
    completion of the scsi_cmnd will advance and try to double complete a
    request already queued for retry.
    
    This patch fixes the issue by moving scsi_done() and any other use of
    scsi_cmnd to before the spinlock is released by the interrupt handler.
    
    Link: https://lore.kernel.org/r/20220311184359.2345319-1-djeffery@xxxxxxxxxx
    Reviewed-by: Laurence Oberman <loberman@xxxxxxxxxx>
    Reviewed-by: Ming Lei <ming.lei@xxxxxxxxxx>
    Signed-off-by: David Jeffery <djeffery@xxxxxxxxxx>
    Signed-off-by: Martin K. Petersen <martin.petersen@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/scsi/fnic/fnic_scsi.c b/drivers/scsi/fnic/fnic_scsi.c
index 88c549f257db..40a52feb315d 100644
--- a/drivers/scsi/fnic/fnic_scsi.c
+++ b/drivers/scsi/fnic/fnic_scsi.c
@@ -986,8 +986,6 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic,
 	CMD_SP(sc) = NULL;
 	CMD_FLAGS(sc) |= FNIC_IO_DONE;
 
-	spin_unlock_irqrestore(io_lock, flags);
-
 	if (hdr_status != FCPIO_SUCCESS) {
 		atomic64_inc(&fnic_stats->io_stats.io_failures);
 		shost_printk(KERN_ERR, fnic->lport->host, "hdr status = %s\n",
@@ -996,8 +994,6 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic,
 
 	fnic_release_ioreq_buf(fnic, io_req, sc);
 
-	mempool_free(io_req, fnic->io_req_pool);
-
 	cmd_trace = ((u64)hdr_status << 56) |
 		  (u64)icmnd_cmpl->scsi_status << 48 |
 		  (u64)icmnd_cmpl->flags << 40 | (u64)sc->cmnd[0] << 32 |
@@ -1021,6 +1017,12 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic,
 	} else
 		fnic->lport->host_stats.fcp_control_requests++;
 
+	/* Call SCSI completion function to complete the IO */
+	scsi_done(sc);
+	spin_unlock_irqrestore(io_lock, flags);
+
+	mempool_free(io_req, fnic->io_req_pool);
+
 	atomic64_dec(&fnic_stats->io_stats.active_ios);
 	if (atomic64_read(&fnic->io_cmpl_skip))
 		atomic64_dec(&fnic->io_cmpl_skip);
@@ -1049,9 +1051,6 @@ static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic,
 		if(io_duration_time > atomic64_read(&fnic_stats->io_stats.current_max_io_time))
 			atomic64_set(&fnic_stats->io_stats.current_max_io_time, io_duration_time);
 	}
-
-	/* Call SCSI completion function to complete the IO */
-	scsi_done(sc);
 }
 
 /* fnic_fcpio_itmf_cmpl_handler



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux