Skip to content

Commit 7df0b26

Browse files
javed-hmartinkpetersen
authored andcommitted
scsi: qedf: Add synchronization between I/O completions and abort
Avoid race condition between I/O completion and abort processing by protecting the cmd_type with the rport lock. Signed-off-by: Javed Hasan <[email protected]> Signed-off-by: Saurav Kashyap <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 5c584fe commit 7df0b26

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

drivers/scsi/qedf/qedf_io.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,24 +1904,28 @@ int qedf_initiate_abts(struct qedf_ioreq *io_req, bool return_scsi_cmd_on_abts)
19041904
goto drop_rdata_kref;
19051905
}
19061906

1907+
spin_lock_irqsave(&fcport->rport_lock, flags);
19071908
if (!test_bit(QEDF_CMD_OUTSTANDING, &io_req->flags) ||
19081909
test_bit(QEDF_CMD_IN_CLEANUP, &io_req->flags) ||
19091910
test_bit(QEDF_CMD_IN_ABORT, &io_req->flags)) {
19101911
QEDF_ERR(&qedf->dbg_ctx,
19111912
"io_req xid=0x%x sc_cmd=%p already in cleanup or abort processing or already completed.\n",
19121913
io_req->xid, io_req->sc_cmd);
19131914
rc = 1;
1915+
spin_unlock_irqrestore(&fcport->rport_lock, flags);
19141916
goto drop_rdata_kref;
19151917
}
19161918

1919+
/* Set the command type to abort */
1920+
io_req->cmd_type = QEDF_ABTS;
1921+
spin_unlock_irqrestore(&fcport->rport_lock, flags);
1922+
19171923
kref_get(&io_req->refcount);
19181924

19191925
xid = io_req->xid;
19201926
qedf->control_requests++;
19211927
qedf->packet_aborts++;
19221928

1923-
/* Set the command type to abort */
1924-
io_req->cmd_type = QEDF_ABTS;
19251929
io_req->return_scsi_cmd_on_abts = return_scsi_cmd_on_abts;
19261930

19271931
set_bit(QEDF_CMD_IN_ABORT, &io_req->flags);
@@ -2210,7 +2214,9 @@ int qedf_initiate_cleanup(struct qedf_ioreq *io_req,
22102214
refcount, fcport, fcport->rdata->ids.port_id);
22112215

22122216
/* Cleanup cmds re-use the same TID as the original I/O */
2217+
spin_lock_irqsave(&fcport->rport_lock, flags);
22132218
io_req->cmd_type = QEDF_CLEANUP;
2219+
spin_unlock_irqrestore(&fcport->rport_lock, flags);
22142220
io_req->return_scsi_cmd_on_abts = return_scsi_cmd_on_abts;
22152221

22162222
init_completion(&io_req->cleanup_done);

drivers/scsi/qedf/qedf_main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2805,6 +2805,8 @@ void qedf_process_cqe(struct qedf_ctx *qedf, struct fcoe_cqe *cqe)
28052805
struct qedf_ioreq *io_req;
28062806
struct qedf_rport *fcport;
28072807
u32 comp_type;
2808+
u8 io_comp_type;
2809+
unsigned long flags;
28082810

28092811
comp_type = (cqe->cqe_data >> FCOE_CQE_CQE_TYPE_SHIFT) &
28102812
FCOE_CQE_CQE_TYPE_MASK;
@@ -2838,11 +2840,14 @@ void qedf_process_cqe(struct qedf_ctx *qedf, struct fcoe_cqe *cqe)
28382840
return;
28392841
}
28402842

2843+
spin_lock_irqsave(&fcport->rport_lock, flags);
2844+
io_comp_type = io_req->cmd_type;
2845+
spin_unlock_irqrestore(&fcport->rport_lock, flags);
28412846

28422847
switch (comp_type) {
28432848
case FCOE_GOOD_COMPLETION_CQE_TYPE:
28442849
atomic_inc(&fcport->free_sqes);
2845-
switch (io_req->cmd_type) {
2850+
switch (io_comp_type) {
28462851
case QEDF_SCSI_CMD:
28472852
qedf_scsi_completion(qedf, cqe, io_req);
28482853
break;

0 commit comments

Comments
 (0)