Skip to content

Commit f00c159

Browse files
shroffnipelwell
authored andcommitted
nvme: cancel pending I/O if nvme controller is in terminal state
[ Upstream commit 25bb353 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 743daff commit f00c159

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

drivers/nvme/host/core.c

-21
Original file line numberDiff line numberDiff line change
@@ -587,27 +587,6 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
587587
}
588588
EXPORT_SYMBOL_GPL(nvme_change_ctrl_state);
589589

590-
/*
591-
* Returns true for sink states that can't ever transition back to live.
592-
*/
593-
static bool nvme_state_terminal(struct nvme_ctrl *ctrl)
594-
{
595-
switch (nvme_ctrl_state(ctrl)) {
596-
case NVME_CTRL_NEW:
597-
case NVME_CTRL_LIVE:
598-
case NVME_CTRL_RESETTING:
599-
case NVME_CTRL_CONNECTING:
600-
return false;
601-
case NVME_CTRL_DELETING:
602-
case NVME_CTRL_DELETING_NOIO:
603-
case NVME_CTRL_DEAD:
604-
return true;
605-
default:
606-
WARN_ONCE(1, "Unhandled ctrl state:%d", ctrl->state);
607-
return true;
608-
}
609-
}
610-
611590
/*
612591
* Waits for the controller state to be resetting, or returns false if it is
613592
* not possible to ever transition to that state.

drivers/nvme/host/nvme.h

+21
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,27 @@ static inline bool nvme_is_aen_req(u16 qid, __u16 command_id)
740740
nvme_tag_from_cid(command_id) >= NVME_AQ_BLK_MQ_DEPTH;
741741
}
742742

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

drivers/nvme/host/pci.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,9 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req)
12861286
struct nvme_command cmd = { };
12871287
u32 csts = readl(dev->bar + NVME_REG_CSTS);
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
*/
@@ -1388,8 +1391,11 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req)
13881391
return BLK_EH_RESET_TIMER;
13891392

13901393
disable:
1391-
if (!nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_RESETTING))
1394+
if (!nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_RESETTING)) {
1395+
if (nvme_state_terminal(&dev->ctrl))
1396+
nvme_dev_disable(dev, true);
13921397
return BLK_EH_DONE;
1398+
}
13931399

13941400
nvme_dev_disable(dev, false);
13951401
if (nvme_try_sched_reset(&dev->ctrl))

0 commit comments

Comments
 (0)