Skip to content

Commit 25bb353

Browse files
shroffnikeithbusch
authored andcommitted
nvme: cancel pending I/O if nvme controller is in terminal state
While I/O is running, if the pci bus error occurs then in-flight I/O can not complete. Worst, if at this time, user (logically) hot-unplug the nvme disk then the nvme_remove() code path can't forward progress until in-flight I/O is cancelled. So these sequence of events may potentially hang hot-unplug code path indefinitely. This patch helps cancel the pending/in-flight I/O from the nvme request timeout handler in case the nvme controller is in the terminal (DEAD/DELETING/DELETING_NOIO) state and that helps nvme_remove() code path forward progress and finish successfully. Link: https://lore.kernel.org/all/199be893-5dfa-41e5-b6f2-40ac90ebccc4@linux.ibm.com/ Signed-off-by: Nilay Shroff <nilay@linux.ibm.com> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent 445f911 commit 25bb353

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

drivers/nvme/host/core.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -628,27 +628,6 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
628628
}
629629
EXPORT_SYMBOL_GPL(nvme_change_ctrl_state);
630630

631-
/*
632-
* Returns true for sink states that can't ever transition back to live.
633-
*/
634-
static bool nvme_state_terminal(struct nvme_ctrl *ctrl)
635-
{
636-
switch (nvme_ctrl_state(ctrl)) {
637-
case NVME_CTRL_NEW:
638-
case NVME_CTRL_LIVE:
639-
case NVME_CTRL_RESETTING:
640-
case NVME_CTRL_CONNECTING:
641-
return false;
642-
case NVME_CTRL_DELETING:
643-
case NVME_CTRL_DELETING_NOIO:
644-
case NVME_CTRL_DEAD:
645-
return true;
646-
default:
647-
WARN_ONCE(1, "Unhandled ctrl state:%d", ctrl->state);
648-
return true;
649-
}
650-
}
651-
652631
/*
653632
* Waits for the controller state to be resetting, or returns false if it is
654633
* not possible to ever transition to that state.

drivers/nvme/host/nvme.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,27 @@ static inline bool nvme_is_aen_req(u16 qid, __u16 command_id)
741741
nvme_tag_from_cid(command_id) >= NVME_AQ_BLK_MQ_DEPTH;
742742
}
743743

744+
/*
745+
* Returns true for sink states that can't ever transition back to live.
746+
*/
747+
static inline bool nvme_state_terminal(struct nvme_ctrl *ctrl)
748+
{
749+
switch (nvme_ctrl_state(ctrl)) {
750+
case NVME_CTRL_NEW:
751+
case NVME_CTRL_LIVE:
752+
case NVME_CTRL_RESETTING:
753+
case NVME_CTRL_CONNECTING:
754+
return false;
755+
case NVME_CTRL_DELETING:
756+
case NVME_CTRL_DELETING_NOIO:
757+
case NVME_CTRL_DEAD:
758+
return true;
759+
default:
760+
WARN_ONCE(1, "Unhandled ctrl state:%d", ctrl->state);
761+
return true;
762+
}
763+
}
764+
744765
void nvme_complete_rq(struct request *req);
745766
void nvme_complete_batch_req(struct request *req);
746767

drivers/nvme/host/pci.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,9 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req)
12861286
u32 csts = readl(dev->bar + NVME_REG_CSTS);
12871287
u8 opcode;
12881288

1289+
if (nvme_state_terminal(&dev->ctrl))
1290+
goto disable;
1291+
12891292
/* If PCI error recovery process is happening, we cannot reset or
12901293
* the recovery mechanism will surely fail.
12911294
*/
@@ -1390,8 +1393,11 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req)
13901393
return BLK_EH_RESET_TIMER;
13911394

13921395
disable:
1393-
if (!nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_RESETTING))
1396+
if (!nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_RESETTING)) {
1397+
if (nvme_state_terminal(&dev->ctrl))
1398+
nvme_dev_disable(dev, true);
13941399
return BLK_EH_DONE;
1400+
}
13951401

13961402
nvme_dev_disable(dev, false);
13971403
if (nvme_try_sched_reset(&dev->ctrl))

0 commit comments

Comments
 (0)