Some fabrics fixes
Subsystems (3)
Sagi Grimberg
maintainerv2 cover Some fabrics fixes
A set of fixes to the nvme-rdma host driver. First two patches relate to bug reports from Steve Wise on dervice removal handling (and go together with Steve's iwcm patch set).
Next two patches remove redundant calls to nvme_remove_namespaces which is called from nvme_uninit_ctrl.
The last patch fixes the host behavior that it never shutdown the controller (wrong check on the controller state). Christoph, we can either go with this and change the behavior incrementally (currently we never shutdown the controller) or I can just remove the patch altogether.
Changes from v1:
- rearranged nvme ctrl remove to avoid code duplication
- added some change log info to rdma and loop uninit and shutdown reordering.
- collected some review tags
Sagi Grimberg (5):
nvme-rdma: Fix device removal handling
nvme-rdma: Remove duplicate call to nvme_remove_namespaces
nvme-rdma: Free the I/O tags when we delete the controller
nvme-loop: Remove duplicate call to nvme_remove_namespaces
nvme-rdma: Make sure to shutdown the controller if we can
drivers/nvme/host/rdma.c | 72 +++++++++++++++++++++++++--------------------- drivers/nvme/target/loop.c | 4 +-- 2 files changed, 40 insertions(+), 36 deletions(-)
Signature · 1 line
1.9.1
Sagi Grimberg
maintainerPATCH v2 1/5 nvme-rdma: Fix device removal handling
Device removal sequence may have crashed because the controller (and admin queue space) was freed before we destroyed the admin queue resources. Thus we want to destroy the admin queue and only then queue controller deletion and wait for it to complete.
More specifically we:
1. own the controller deletion (make sure we are not competing with another deletion).
2. get rid of inflight reconnects if exists (which also destroy and create queues).
3. destroy the queue.
4. safely queue controller deletion (and wait for it to complete).
--- drivers/nvme/host/rdma.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-)
drivers/nvme/host/rdma.c +21 -20
@@ -169,7 +169,6 @@ MODULE_PARM_DESC(register_always,static int nvme_rdma_cm_handler (struct rdma_cm_id *cm_id,struct rdma_cm_event *event);static void nvme_rdma_recv_done (struct ib_cq *cq,struct ib_wc *wc); -static int __nvme_rdma_del_ctrl (struct nvme_rdma_ctrl *ctrl);/* XXX: really should move to a generic header sooner or later.. */ static inline void put_unaligned_le24 (u32 val,u8 *p)
@@ -1318,37 +1317,39 @@ out_destroy_queue_ib:* that caught the event. Since we hold the callout until the controller * deletion is completed, we'll deadlock if the controller deletion will * call rdma_destroy_id on this queue's cm_id. Thus, we claim ownership -* of destroying this queue before-hand, destroy the queue resources -* after the controller deletion completed with the exception of destroying -* the cm_id implicitely by returning a non-zero rc to the callout. +* of destroying this queue before-hand, destroy the queue resources, +* then queue the controller deletion which won't destroy this queue and +* we destroy the cm_id implicitely by returning a non-zero rc to the callout. */ static int nvme_rdma_device_unplug (struct nvme_rdma_queue *queue) {struct nvme_rdma_ctrl *ctrl = queue->ctrl; -int ret, ctrl_deleted =0 ; +int ret; -/* First disable the queue so ctrl delete won't free it */ -if (!test_and_clear_bit (NVME_RDMA_Q_CONNECTED , &queue->flags)) - goto out; +/* Own the controller deletion */ +if (!nvme_change_ctrl_state (&ctrl->ctrl,NVME_CTRL_DELETING )) +return 0 ; -/* delete the controller */ - ret =__nvme_rdma_del_ctrl (ctrl); -if (!ret) { -dev_warn (ctrl->ctrl.device, -"Got rdma device removal event, deleting ctrl\n" ); -flush_work (&ctrl->delete_work); +dev_warn (ctrl->ctrl.device, +"Got rdma device removal event, deleting ctrl\n" ); -/* Return non-zero so the cm_id will destroy implicitly */ - ctrl_deleted =1 ; +/* Get rid of reconnect work if its running */ +cancel_delayed_work_sync (&ctrl->reconnect_work); +/* Disable the queue so ctrl delete won't free it */ +if (test_and_clear_bit (NVME_RDMA_Q_CONNECTED , &queue->flags)) {/* Free this queue ourselves */ -rdma_disconnect (queue->cm_id); -ib_drain_qp (queue->qp); +nvme_rdma_stop_queue (queue);nvme_rdma_destroy_queue_ib (queue); + +/* Return non-zero so the cm_id will destroy implicitly */ + ret =1 ; } -out: -return ctrl_deleted; +/* Queue controller deletion */ +queue_work (nvme_rdma_wq, &ctrl->delete_work); +flush_work (&ctrl->delete_work); +return ret; } static int nvme_rdma_cm_handler(struct rdma_cm_id *cm_id,
Signature · 1 line
1.9.1
Sagi Grimberg
maintainerPATCH v2 2/5 nvme-rdma: Remove duplicate call to nvme_remove_namespaces
In reply to Sagi Grimbergnvme_uninit_ctrl already does that for us. Note that we reordered nvme_rdma_shutdown_ctrl and nvme_uninit_ctrl, this is perfectly fine because we actually want ctrl uninit (aen, scan cancellation and namespaces removal) to happen before we shutdown the rdma resources.
Also, centralize the deletion work and the dead controller removal work code duplication into __nvme_rdma_shutdown_ctrl that accepts a shutdown boolean.
--- drivers/nvme/host/rdma.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
drivers/nvme/host/rdma.c +10 -7
@@ -1658,15 +1658,20 @@ static void nvme_rdma_shutdown_ctrl(struct nvme_rdma_ctrl *ctrl)nvme_rdma_destroy_admin_queue (ctrl); } +static void __nvme_rdma_remove_ctrl (struct nvme_rdma_ctrl *ctrl,bool shutdown) +{ +nvme_uninit_ctrl (&ctrl->ctrl); +if (shutdown) +nvme_rdma_shutdown_ctrl (ctrl); +nvme_put_ctrl (&ctrl->ctrl); +} +static void nvme_rdma_del_ctrl_work (struct work_struct *work) {struct nvme_rdma_ctrl *ctrl =container_of (work, struct nvme_rdma_ctrl, delete_work); -nvme_remove_namespaces (&ctrl->ctrl); -nvme_rdma_shutdown_ctrl (ctrl); -nvme_uninit_ctrl (&ctrl->ctrl); -nvme_put_ctrl (&ctrl->ctrl); +__nvme_rdma_remove_ctrl (ctrl, true); }static int __nvme_rdma_del_ctrl (struct nvme_rdma_ctrl *ctrl)
@@ -1699,9 +1704,7 @@ static void nvme_rdma_remove_ctrl_work(struct work_struct *work)struct nvme_rdma_ctrl *ctrl =container_of (work, struct nvme_rdma_ctrl, delete_work); -nvme_remove_namespaces (&ctrl->ctrl); -nvme_uninit_ctrl (&ctrl->ctrl); -nvme_put_ctrl (&ctrl->ctrl); +__nvme_rdma_remove_ctrl (ctrl, false); }static void nvme_rdma_reset_ctrl_work (struct work_struct *work)
Signature · 1 line
1.9.1
Christoph Hellwig
maintainerPATCH v2 2/5 nvme-rdma: Remove duplicate call to nvme_remove_namespaces
Quoted 9 lines · Sagi Grimberg
nvme_uninit_ctrlalready does that for us. Note that we reorderednvme_rdma_shutdown_ctrlandnvme_uninit_ctrl, this is perfectly fine because we actually want ctrl uninit (aen, scan cancellation and namespaces removal) to happen before we shutdown the rdma resources.Also, centralize the deletion work and the dead controller removal work code duplication into
__nvme_rdma_shutdown_ctrlthat accepts a shutdown boolean.
Looks fine:
Sagi Grimberg
maintainerPATCH v2 3/5 nvme-rdma: Free the I/O tags when we delete the controller
In reply to Sagi GrimbergIf we wait until we free the controller (free_ctrl) we might lose our rdma device without any notification while we still have open resources (tags mrs and dma mappings).
Instead, destroy the tags with their rdma resources once we delete the device and not when freeing it.
Note that we don't do that in nvme_rdma_shutdown_ctrl because controller reset uses it as well and we want to give active I/O a chance to complete successfully.
--- drivers/nvme/host/rdma.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/nvme/host/rdma.c +7 -5
@@ -686,11 +686,6 @@ static void nvme_rdma_free_ctrl(struct nvme_ctrl *nctrl)list_del (&ctrl->list);mutex_unlock (&nvme_rdma_ctrl_mutex); -if (ctrl->ctrl.tagset) { -blk_cleanup_queue (ctrl->ctrl.connect_q); -blk_mq_free_tag_set (&ctrl->tag_set); -nvme_rdma_dev_put (ctrl->device); - }kfree (ctrl->queues);nvmf_free_options (nctrl->opts); free_ctrl:
@@ -1663,6 +1658,13 @@ static void __nvme_rdma_remove_ctrl(struct nvme_rdma_ctrl *ctrl, bool shutdown)nvme_uninit_ctrl (&ctrl->ctrl);if (shutdown)nvme_rdma_shutdown_ctrl (ctrl); + +if (ctrl->ctrl.tagset) { +blk_cleanup_queue (ctrl->ctrl.connect_q); +blk_mq_free_tag_set (&ctrl->tag_set); +nvme_rdma_dev_put (ctrl->device); + } +nvme_put_ctrl (&ctrl->ctrl); }
Signature · 1 line
1.9.1
Christoph Hellwig
maintainerPATCH v2 3/5 nvme-rdma: Free the I/O tags when we delete the controller
Quoted 4 lines · Sagi Grimberg
If we wait until we free the controller (
free_ctrl) we might lose our rdma device without any notification while we still have open resources (tags mrs and dma mappings).
Quoted 8 lines
Instead, destroy the tags with their rdma resources once we delete the device and not when freeing it.
Note that we don't do that in
nvme_rdma_shutdown_ctrlbecause controller reset uses it as well and we want to give active I/O a chance to complete successfully.Signed-off-by Sagi Grimberg <sagi at grimberg.me>
Looks fine:
Sagi Grimberg
maintainerPATCH v2 4/5 nvme-loop: Remove duplicate call to nvme_remove_namespaces
In reply to Sagi Grimbergnvme_uninit_ctrl already does that for us. Note that we reordered nvme_loop_shutdown_ctrl with nvme_uninit_ctrl but its safe because we want controller uninit to happen before we shutdown the transport resources.
--- drivers/nvme/target/loop.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/nvme/target/loop.c +1 -3
@@ -414,9 +414,8 @@ static void nvme_loop_del_ctrl_work(struct work_struct *work)struct nvme_loop_ctrl *ctrl =container_of (work, struct nvme_loop_ctrl, delete_work); -nvme_remove_namespaces (&ctrl->ctrl); -nvme_loop_shutdown_ctrl (ctrl);nvme_uninit_ctrl (&ctrl->ctrl); +nvme_loop_shutdown_ctrl (ctrl);nvme_put_ctrl (&ctrl->ctrl); }
@@ -501,7 +500,6 @@ out_free_queues:nvme_loop_destroy_admin_queue (ctrl); out_disable:dev_warn (ctrl->ctrl.device,"Removing after reset failure\n" ); -nvme_remove_namespaces (&ctrl->ctrl);nvme_uninit_ctrl (&ctrl->ctrl);nvme_put_ctrl (&ctrl->ctrl); }
Signature · 1 line
1.9.1
Christoph Hellwig
maintainerPATCH v2 4/5 nvme-loop: Remove duplicate call to nvme_remove_namespaces
Quoted 6 lines · Sagi Grimberg
nvme_uninit_ctrlalready does that for us. Note that we reorderednvme_loop_shutdown_ctrlwithnvme_uninit_ctrlbut its safe because we want controller uninit to happen before we shutdown the transport resources.Signed-off-by Sagi Grimberg <sagi at grimberg.me>
Looks fine,
Sagi Grimberg
maintainerPATCH v2 5/5 nvme-rdma: Make sure to shutdown the controller if we can
In reply to Sagi GrimbergRelying on ctrl state in nvme_rdma_shutdown_ctrl is wrong because it will never be NVME_CTRL_LIVE (delete_ctrl or reset_ctrl invoked it).
Instead, check that the admin queue is connected. Note that it is safe because we can never see a copmeting thread trying to destroy the admin queue (reset or delete controller).
--- drivers/nvme/host/rdma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/rdma.c +1 -1
@@ -1644,7 +1644,7 @@ static void nvme_rdma_shutdown_ctrl(struct nvme_rdma_ctrl *ctrl)nvme_rdma_free_io_queues (ctrl); } -if (ctrl->ctrl.state ==NVME_CTRL_LIVE ) +if (test_bit (NVME_RDMA_Q_CONNECTED , &ctrl->queues[0 ].flags))nvme_shutdown_ctrl (&ctrl->ctrl);blk_mq_stop_hw_queues (ctrl->ctrl.admin_q);
Signature · 1 line
1.9.1
Christoph Hellwig
maintainerPATCH v2 5/5 nvme-rdma: Make sure to shutdown the controller if we can
Quoted 8 lines · Sagi Grimberg
Relying on ctrl state in
nvme_rdma_shutdown_ctrlis wrong because it will never beNVME_CTRL_LIVE(delete_ctrlorreset_ctrlinvoked it).Instead, check that the admin queue is connected. Note that it is safe because we can never see a copmeting thread trying to destroy the admin queue (reset or delete controller).
Signed-off-by Sagi Grimberg <sagi at grimberg.me>
Looks fine,