Skip to content

Commit ee6fdc5

Browse files
mliang-purekeithbusch
authored andcommitted
nvme-fc: fix race between error recovery and creating association
There is a small race window between nvme-fc association creation and error recovery. Fix this race condition by protecting accessing to controller state and ASSOC_FAILED flag under nvme-fc controller lock. Signed-off-by: Michael Liang <mliang@purestorage.com> Reviewed-by: Caleb Sander <csander@purestorage.com> Reviewed-by: James Smart <jsmart2021@gmail.com> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent 60e445b commit ee6fdc5

File tree

1 file changed

+16
-5
lines changed
  • drivers/nvme/host

1 file changed

+16
-5
lines changed

drivers/nvme/host/fc.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,17 +2548,24 @@ nvme_fc_error_recovery(struct nvme_fc_ctrl *ctrl, char *errmsg)
25482548
* the controller. Abort any ios on the association and let the
25492549
* create_association error path resolve things.
25502550
*/
2551-
if (ctrl->ctrl.state == NVME_CTRL_CONNECTING) {
2552-
__nvme_fc_abort_outstanding_ios(ctrl, true);
2551+
enum nvme_ctrl_state state;
2552+
unsigned long flags;
2553+
2554+
spin_lock_irqsave(&ctrl->lock, flags);
2555+
state = ctrl->ctrl.state;
2556+
if (state == NVME_CTRL_CONNECTING) {
25532557
set_bit(ASSOC_FAILED, &ctrl->flags);
2558+
spin_unlock_irqrestore(&ctrl->lock, flags);
2559+
__nvme_fc_abort_outstanding_ios(ctrl, true);
25542560
dev_warn(ctrl->ctrl.device,
25552561
"NVME-FC{%d}: transport error during (re)connect\n",
25562562
ctrl->cnum);
25572563
return;
25582564
}
2565+
spin_unlock_irqrestore(&ctrl->lock, flags);
25592566

25602567
/* Otherwise, only proceed if in LIVE state - e.g. on first error */
2561-
if (ctrl->ctrl.state != NVME_CTRL_LIVE)
2568+
if (state != NVME_CTRL_LIVE)
25622569
return;
25632570

25642571
dev_warn(ctrl->ctrl.device,
@@ -3172,12 +3179,16 @@ nvme_fc_create_association(struct nvme_fc_ctrl *ctrl)
31723179
else
31733180
ret = nvme_fc_recreate_io_queues(ctrl);
31743181
}
3182+
3183+
spin_lock_irqsave(&ctrl->lock, flags);
31753184
if (!ret && test_bit(ASSOC_FAILED, &ctrl->flags))
31763185
ret = -EIO;
3177-
if (ret)
3186+
if (ret) {
3187+
spin_unlock_irqrestore(&ctrl->lock, flags);
31783188
goto out_term_aen_ops;
3179-
3189+
}
31803190
changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE);
3191+
spin_unlock_irqrestore(&ctrl->lock, flags);
31813192

31823193
ctrl->ctrl.nr_reconnects = 0;
31833194

0 commit comments

Comments
 (0)