nvme: fix nvme_remove going to uninterruptible sleep for ever
PATCH v2 1/1 nvme: fix nvme_remove going to uninterruptible sleep for ever
Once controller is in DEAD or DELETING state a call to delete_destroy from nvme_uninit_ctrl results in setting the latency tolerance via nvme_set_latency_tolerance callback even though queues have already been killed. This in turn leads the PID to go into uninterruptible sleep and prevents removal of nvme controller from completion. The stack trace is:
[<ffffffff813c9716>] blk_execute_rq+0x56/0x80 [<ffffffff815cb6e9>] __nvme_submit_sync_cmd+0x89/0xf0 [<ffffffff815ce7be>] nvme_set_features+0x5e/0x90 [<ffffffff815ce9f6>] nvme_configure_apst+0x166/0x200 [<ffffffff815cef45>] nvme_set_latency_tolerance+0x35/0x50 [<ffffffff8157bd11>] apply_constraint+0xb1/0xc0 [<ffffffff8157cbb4>] dev_pm_qos_constraints_destroy+0xf4/0x1f0 [<ffffffff8157b44a>] dpm_sysfs_remove+0x2a/0x60 [<ffffffff8156d951>] device_del+0x101/0x320 [<ffffffff8156db8a>] device_unregister+0x1a/0x60 [<ffffffff8156dc4c>] device_destroy+0x3c/0x50 [<ffffffff815cd295>] nvme_uninit_ctrl+0x45/0xa0 [<ffffffff815d4858>] nvme_remove+0x78/0x110 [<ffffffff81452b69>] pci_device_remove+0x39/0xb0 [<ffffffff81572935>] device_release_driver_internal+0x155/0x210 [<ffffffff81572a02>] device_release_driver+0x12/0x20 [<ffffffff815d36fb>] nvme_remove_dead_ctrl_work+0x6b/0x70 [<ffffffff810bf3bc>] process_one_work+0x18c/0x3a0 [<ffffffff810bf61e>] worker_thread+0x4e/0x3b0 [<ffffffff810c5ac9>] kthread+0x109/0x140 [<ffffffff8185800c>] ret_from_fork+0x2c/0x40
[<ffffffffffffffff>] 0xffffffffffffffff
and PID is in 'D' state. Attached patch returns from nvme_configure_apst to avoids configuration and syncing commands when controller is either in DELETING state or DEAD state which can only happen once we are in nvme_remove. This allows removal to complete and release remaining resources after nvme_uninit_ctrl.
V2: Move the check to nvme_configure_apst instead of callback (suggested by Christoph)
--- drivers/nvme/host/core.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/nvme/host/core.c +7 -0
@@ -1357,6 +1357,13 @@ static void nvme_configure_apst(struct nvme_ctrl *ctrl)int ret;/* +* Avoid configuration and syncing commands if controller is already +* being removed and queues have been killed. +*/ +if (ctrl->state ==NVME_CTRL_DELETING || ctrl->state ==NVME_CTRL_DEAD ) +return ; + +/* * If APST isn't supported or if we haven't been initialized yet, * then don't do anything. */
Signature · 1 line
2.9.3
Looks good,
Sagi Grimberg
maintainerdrivers/nvme/host/core.c static void nvme_configure_apst(struct nvme_ctrl *ctrl) · line 1365
Quoted 8 lines
drivers/nvme/host/core.c +6
-0/* +* Avoid configuration and syncing commands if controller is already +* being removed and queues have been killed. +*/ +if (ctrl->state ==NVME_CTRL_DELETING || ctrl->state ==NVME_CTRL_DEAD ) +return ; +
Hey Rakesh, Christoph,
Given that the issue is for sync command submission during controller removal, I'm wandering if we should perhaps move this check to __nvme_submit_sync_cmd?
AFAICT user-space can just as easily trigger set_features in the same condition which will trigger the hang couldn't it?
Quoted 11 lines · Sagi Grimberg
drivers/nvme/host/core.c static void nvme_configure_apst(struct nvme_ctrl *ctrl) · line 1365
Quoted 8 lines
drivers/nvme/host/core.c +6
-0/* +* Avoid configuration and syncing commands if controller is already +* being removed and queues have been killed. +*/ +if (ctrl->state ==NVME_CTRL_DELETING || ctrl->state ==NVME_CTRL_DEAD ) +return ; +Hey Rakesh, Christoph,
Quoted 6 lines
Given that the issue is for sync command submission during controller removal, I'm wandering if we should perhaps move this check to
__nvme_submit_sync_cmd?AFAICT user-space can just as easily trigger
set_featuresin the same condition which will trigger the hang couldn't it?
Seems possible. But it seems worth keeping this check as it avoids the instructions between start of nvme_configure_apst and __nvme_submit_sync_cmd. This check seems to solve more severe hang as PID which started off from nvme_remove eventually hangs itself on blk_execute_rq..
We can fix user-space triggered set_features higger up e.g. in nvme_ioctl by putting same check. Introduction of a separate state NVME_CTRL_SCHED_RESET (being discussed in another thread) has additional advantage of making sure that only one thread is going through resetting and eventually through removal (if required) and solves lot of problems.
It makes sense to push this separately because of above reasons and we can fix user space trigger of deadlock once discussion on another thread has moved forward on introducing of new state.
Christoph Hellwig
maintainerQuoted 6 lines · Rakesh Pandit
We can fix user-space triggered
set_featureshigger up e.g. innvme_ioctlby putting same check. Introduction of a separate stateNVME_CTRL_SCHED_RESET(being discussed in another thread) has additional advantage of making sure that only one thread is going through resetting and eventually through removal (if required) and solves lot of problems.
I think we need the NVME_CTRL_SCHED_RESET state. In fact I'm pretty sure some time in the past I already had it in a local tree as a generalization of rdma and loop already use NVME_CTRL_RESETTING (they set it before queueing the reset work).
But I don't fully understand how the NVME_CTRL_SCHED_RESET fix is related to this patch?
Quoted 8 lines · Christoph Hellwig
Quoted 6 lines · Rakesh Pandit
We can fix user-space triggered
set_featureshigger up e.g. innvme_ioctlby putting same check. Introduction of a separate stateNVME_CTRL_SCHED_RESET(being discussed in another thread) has additional advantage of making sure that only one thread is going through resetting and eventually through removal (if required) and solves lot of problems.
Quoted 7 lines
I think we need the
NVME_CTRL_SCHED_RESETstate. In fact I'm pretty sure some time in the past I already had it in a local tree as a generalization of rdma and loop already useNVME_CTRL_RESETTING(they set it before queueing the reset work).But I don't fully understand how the
NVME_CTRL_SCHED_RESETfix is related to this patch?
They aren't related. Sorry for confusion. I intended to answer another thread but instead wrote it here.
Christoph Hellwig
maintainerQuoted 10 lines · Rakesh Pandit
Quoted 7 lines
I think we need the
NVME_CTRL_SCHED_RESETstate. In fact I'm pretty sure some time in the past I already had it in a local tree as a generalization of rdma and loop already useNVME_CTRL_RESETTING(they set it before queueing the reset work).But I don't fully understand how the
NVME_CTRL_SCHED_RESETfix is related to this patch?They aren't related. Sorry for confusion. I intended to answer another thread but instead wrote it here.
Ok, thanks. But I think the Point from Sagi that we should move the state check all the way down to submit_sync_command still makes sense to me.
Quoted 14 lines · Rakesh Pandit
Quoted 13 lines · Christoph Hellwig
Quoted 6 lines · Rakesh Pandit
We can fix user-space triggered
set_featureshigger up e.g. innvme_ioctlby putting same check. Introduction of a separate stateNVME_CTRL_SCHED_RESET(being discussed in another thread) has additional advantage of making sure that only one thread is going through resetting and eventually through removal (if required) and solves lot of problems.I think we need the
NVME_CTRL_SCHED_RESETstate. In fact I'm pretty sure some time in the past I already had it in a local tree as a generalization of rdma and loop already useNVME_CTRL_RESETTING(they set it before queueing the reset work).
Quoted 6 lines
Quoted 2 lines
But I don't fully understand how the
NVME_CTRL_SCHED_RESETfix is related to this patch?They aren't related. Sorry for confusion. I intended to answer another thread but instead wrote it here.
Also Sagi pointed out that user space set_features ioctl if fired up in a window after nvme_removal it can also result in this issue seems to be correct. I would prefer to keep this as it is and introduce similar check higher up in nvme_ioctrl instead so that we don't send sync commands if queues are killed already.
Would you prefer a patch ? Thanks,
Christoph Hellwig
maintainerQuoted 7 lines · Rakesh Pandit
Also Sagi pointed out that user space
set_featuresioctl if fired up in a window afternvme_removalit can also result in this issue seems to be correct. I would prefer to keep this as it is and introduce similar check higher up innvme_ioctrlinstead so that we don't send sync commands if queues are killed already.Would you prefer a patch ? Thanks,
If we want to kill everyone we probably should do it in ->queue_rq. Or is the block layer blocking you somewhere else?
Quoted 10 lines · Christoph Hellwig
Quoted 7 lines · Rakesh Pandit
Also Sagi pointed out that user space
set_featuresioctl if fired up in a window afternvme_removalit can also result in this issue seems to be correct. I would prefer to keep this as it is and introduce similar check higher up innvme_ioctrlinstead so that we don't send sync commands if queues are killed already.Would you prefer a patch ? Thanks,
If we want to kill everyone we probably should do it in ->queue_rq.
Looks ->queue_rq has done it already via checking nvmeq->cq_vector
Quoted 1 line
Or is the block layer blocking you somewhere else?
blk-mq doesn't handle dying in the I/O path.
Maybe it is similar with 806f026f9b901eaf1a(nvme: use blk_mq_start_hw_queues() in nvme_kill_queues()), seems we need to do it for admin_q too.
Can the following change fix the issue?
drivers/nvme/host/core.c +1 -0
@@ -2438,6 +2438,7 @@ void nvme_kill_queues(struct nvme_ctrl *ctrl)struct nvme_ns *ns;mutex_lock (&ctrl->namespaces_mutex); +blk_mq_start_hw_queues (ctrl->admin_q);list_for_each_entry (ns, &ctrl->namespaces, list) {/* * Revalidating a dead namespace sets capacity to 0. This will
Thanks,
Ming
Quoted 30 lines · Ming Lei
Quoted 10 lines · Christoph Hellwig
Quoted 7 lines · Rakesh Pandit
Also Sagi pointed out that user space
set_featuresioctl if fired up in a window afternvme_removalit can also result in this issue seems to be correct. I would prefer to keep this as it is and introduce similar check higher up innvme_ioctrlinstead so that we don't send sync commands if queues are killed already.Would you prefer a patch ? Thanks,
If we want to kill everyone we probably should do it in ->queue_rq.
Looks ->queue_rq has done it already via checking
nvmeq->cq_vectorQuoted 1 line
Or is the block layer blocking you somewhere else?
blk-mq doesn't handle dying in the I/O path.
Maybe it is similar with 806f026f9b901eaf1a(nvme: use
blk_mq_start_hw_queues()innvme_kill_queues()), seems we need to do it foradmin_qtoo.Can the following change fix the issue?
drivers/nvme/host/core.c +0
-0
drivers/nvme/host/core.c void nvme_kill_queues(struct nvme_ctrl *ctrl) · line 2444
Quoted 7 lines
drivers/nvme/host/core.c +1
-0@@ -2438,6 +2438,7 @@ void nvme_kill_queues(struct nvme_ctrl *ctrl)struct nvme_ns *ns;mutex_lock (&ctrl->namespaces_mutex); +blk_mq_start_hw_queues (ctrl->admin_q);list_for_each_entry (ns, &ctrl->namespaces, list) {/* * Revalidating a dead namespace sets capacity to 0. This will
Yes change fixes the issue.
Quoted 31 lines · Rakesh Pandit
Quoted 30 lines · Ming Lei
Quoted 10 lines · Christoph Hellwig
Quoted 7 lines · Rakesh Pandit
Also Sagi pointed out that user space
set_featuresioctl if fired up in a window afternvme_removalit can also result in this issue seems to be correct. I would prefer to keep this as it is and introduce similar check higher up innvme_ioctrlinstead so that we don't send sync commands if queues are killed already.Would you prefer a patch ? Thanks,
If we want to kill everyone we probably should do it in ->queue_rq.
Looks ->queue_rq has done it already via checking
nvmeq->cq_vectorQuoted 1 line
Or is the block layer blocking you somewhere else?
blk-mq doesn't handle dying in the I/O path.
Maybe it is similar with 806f026f9b901eaf1a(nvme: use
blk_mq_start_hw_queues()innvme_kill_queues()), seems we need to do it foradmin_qtoo.Can the following change fix the issue?
drivers/nvme/host/core.c +0
-0@@ -2438,6 +2438,7 @@ void nvme_kill_queues(struct nvme_ctrl *ctrl)struct nvme_ns *ns;
Quoted 9 lines
drivers/nvme/host/core.c void nvme_kill_queues(struct nvme_ctrl *ctrl) · line 2444
Quoted 7 lines
drivers/nvme/host/core.c +1
-0mutex_lock (&ctrl->namespaces_mutex); +blk_mq_start_hw_queues (ctrl->admin_q);list_for_each_entry (ns, &ctrl->namespaces, list) {/* * Revalidating a dead namespace sets capacity to 0. This will Yes change fixes the issue.
Rakesh, thanks for your test, and I will prepare a formal one for merging.
thanks,
Ming
Sagi Grimberg
maintainerQuoted 5 lines
I think we need the
NVME_CTRL_SCHED_RESETstate. In fact I'm pretty sure some time in the past I already had it in a local tree as a generalization of rdma and loop already useNVME_CTRL_RESETTING(they set it before queueing the reset work).
I don't remember having it, but I might be wrong...
Can you explain again why you think we need it? Sorry for being difficult, but I'm not exactly sure why it makes things better or simpler.
Christoph Hellwig
maintainerQuoted 11 lines · Sagi Grimberg
Quoted 5 lines
I think we need the
NVME_CTRL_SCHED_RESETstate. In fact I'm pretty sure some time in the past I already had it in a local tree as a generalization of rdma and loop already useNVME_CTRL_RESETTING(they set it before queueing the reset work).I don't remember having it, but I might be wrong...
Can you explain again why you think we need it? Sorry for being difficult, but I'm not exactly sure why it makes things better or simpler.
Motly that we can treat a controller as under reset before scheduling the reset work, both to prevent multiple schedules, and to make checks like the one in nvme_should_reset robus.
But I think something along the lines of the earlier patch from Rakesh that just sets the RESETTING state earlier + the cancel_work_sync suggested by you should also work for that purpose. So maybe that's the way to go after all.
Quoted 13 lines · Christoph Hellwig
Quoted 11 lines · Sagi Grimberg
Quoted 5 lines
I think we need the
NVME_CTRL_SCHED_RESETstate. In fact I'm pretty sure some time in the past I already had it in a local tree as a generalization of rdma and loop already useNVME_CTRL_RESETTING(they set it before queueing the reset work).I don't remember having it, but I might be wrong...
Can you explain again why you think we need it? Sorry for being difficult, but I'm not exactly sure why it makes things better or simpler.
Quoted 8 lines
Motly that we can treat a controller as under reset before scheduling the reset work, both to prevent multiple schedules, and to make checks like the one in
nvme_should_resetrobus.But I think something along the lines of the earlier patch from Rakesh that just sets the RESETTING state earlier + the
cancel_work_syncsuggested by you should also work for that purpose. So maybe that's the way to go after all.
I would post a new patch which includes my RESETTING state earlier patch + the cancel_work_sync which Sagi suggested after testing.
Sagi: Because my RESETTING patch earlier is subset of your untested patch with cancel_work_sync, it would be logical to take a signed off from you as well. May you review/ack/nack the patch? Feel free to let me know if you want me to change it further or instead you want to post as author.
I am okay with either as long as we fix the issue.
Sagi Grimberg
maintainerRakesh,
Quoted 8 lines
I would post a new patch which includes my RESETTING state earlier patch + the
cancel_work_syncwhich Sagi suggested after testing.Sagi: Because my RESETTING patch earlier is subset of your untested patch with
cancel_work_sync, it would be logical to take a signed off from you as well. May you review/ack/nack the patch? Feel free to let me know if you want me to change it further or instead you want to post as author.
Its all yours :)
send a patch and we'll review it, thanks.