Skip to contentSkip to conversation

nvme: add nvme_delete_dead_ctrl for avoiding io deadlock

PATCH In review Ming Lei 3 participants 7 messages May 30, 2023 – Jun 6, 2023

Subsystems (2)
lore
Share & tools
lore

Ming Lei

author
#0 lore raw

cover nvme: add nvme_delete_dead_ctrl for avoiding io deadlock

Hello,

The 1st patch adds nvme_delete_dead_ctrl().

The 2nd patch calls it after reconnection fails in tcp/rdma driver, and fixes one io dead lock.

Ming Lei (2):
nvme: add API of nvme_delete_dead_ctrl
nvme: rdma/tcp: call nvme_delete_dead_ctrl for handling reconnect
failure

 drivers/nvme/host/core.c | 24 +++++++++++++++++++++++-
 drivers/nvme/host/nvme.h |  1 +
 drivers/nvme/host/rdma.c |  2 +-
 drivers/nvme/host/tcp.c  |  2 +-
 4 files changed, 26 insertions(+), 3 deletions(-)
Signature · 1 line
2.40.1
author
#1 lore raw

PATCH 1/2 nvme: add API of nvme_delete_dead_ctrl

When driver confirms that the controller is dead, this controller should be deleted with marking as DEAD. Otherwise, upper layer may wait forever in __bio_queue_enter() since the disk won't be marked as DEAD. Especially, in del_gendisk(), disk won't be marked as DEAD unless bdev sync & invalidate returns. If any writeback IO waits in __bio_queue_enter(), IO deadlock is caused.

Add nvme_delete_dead_ctrl() for avoiding such kind of io deadlock.

---
 drivers/nvme/host/core.c | 24 +++++++++++++++++++++++-
 drivers/nvme/host/nvme.h |  1 +
 2 files changed, 24 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +23 -1
index ccb6eb1282f8..413213cfa417 100644
@@ -227,16 +227,38 @@ static void nvme_delete_ctrl_work(struct work_struct *work)
 	nvme_do_delete_ctrl(ctrl);
 }
 
-int nvme_delete_ctrl(struct nvme_ctrl *ctrl)
+static int __nvme_delete_ctrl(struct nvme_ctrl *ctrl,
+			      enum nvme_ctrl_state state)
 {
+	if (state != NVME_CTRL_DELETING && state != NVME_CTRL_DEAD)
+		return -EINVAL;
+
 	if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING))
 		return -EBUSY;
+	if (state == NVME_CTRL_DEAD) {
+		if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DEAD))
+			return -EBUSY;
+	}
 	if (!queue_work(nvme_delete_wq, &ctrl->delete_work))
 		return -EBUSY;
 	return 0;
 }
+
+int nvme_delete_ctrl(struct nvme_ctrl *ctrl)
+{
+	return __nvme_delete_ctrl(ctrl, NVME_CTRL_DELETING);
+}
 EXPORT_SYMBOL_GPL(nvme_delete_ctrl);
 
+/*
+ * Called when driver confirmed that the controller is really dead
+ */
+int nvme_delete_dead_ctrl(struct nvme_ctrl *ctrl)
+{
+	return __nvme_delete_ctrl(ctrl, NVME_CTRL_DEAD);
+}
+EXPORT_SYMBOL_GPL(nvme_delete_dead_ctrl);
+
 static void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl)
 {
 	/*
drivers/nvme/host/nvme.h +1 -0
index bf46f122e9e1..8f62246a85be 100644
@@ -828,6 +828,7 @@ void nvme_stop_keep_alive(struct nvme_ctrl *ctrl);
 int nvme_reset_ctrl(struct nvme_ctrl *ctrl);
 int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl);
 int nvme_delete_ctrl(struct nvme_ctrl *ctrl);
+int nvme_delete_dead_ctrl(struct nvme_ctrl *ctrl);
 void nvme_queue_scan(struct nvme_ctrl *ctrl);
 int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi,
 		void *log, size_t size, u64 offset);
Signature · 1 line
2.40.1
maintainer
#2 lore raw

Re: [PATCH 1/2] nvme: add API of nvme_delete_dead_ctrl

Quoted 31 lines

When driver confirms that the controller is dead, this controller should be deleted with marking as DEAD. Otherwise, upper layer may wait forever in __bio_queue_enter() since the disk won't be marked as DEAD. Especially, in del_gendisk(), disk won't be marked as DEAD unless bdev sync & invalidate returns. If any writeback IO waits in __bio_queue_enter(), IO deadlock is caused.

Add nvme_delete_dead_ctrl() for avoiding such kind of io deadlock.

---
  drivers/nvme/host/core.c | 24 +++++++++++++++++++++++-
  drivers/nvme/host/nvme.h |  1 +
  2 files changed, 24 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +5 -1
index ccb6eb1282f8..413213cfa417 100644
@@ -227,16 +227,38 @@ static void nvme_delete_ctrl_work(struct work_struct *work)
  	nvme_do_delete_ctrl(ctrl);
  }
 
-int nvme_delete_ctrl(struct nvme_ctrl *ctrl)
+static int __nvme_delete_ctrl(struct nvme_ctrl *ctrl,
+			      enum nvme_ctrl_state state)
  {
+	if (state != NVME_CTRL_DELETING && state != NVME_CTRL_DEAD)
+		return -EINVAL;
+

drivers/nvme/host/core.c static void nvme_delete_ctrl_work(struct work_struct *work) · line 245

Quoted 10 lines
drivers/nvme/host/core.c +4 -0
  	if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING))
  		return -EBUSY;
+	if (state == NVME_CTRL_DEAD) {
+		if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DEAD))
+			return -EBUSY;
+	}
  	if (!queue_work(nvme_delete_wq, &ctrl->delete_work))
  		return -EBUSY;
  	return 0;
  }

the user can trigger a delete in exactly the same condition as the transport (say a nanosecond before the transport exhaust the max_reconnects).

I think that we'd want something like
--

drivers/nvme/host/core.c +5 -0
index 841f155fe0b3..6c718ad46e06 100644
@@ -231,6 +231,11 @@ int nvme_delete_ctrl(struct nvme_ctrl *ctrl)
 {
        if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING))
                return -EBUSY;
+
+       if (ctrl->ops->transport_disconnected &&
+           ctrl->ops->transport_disconnected(ctrl))
+               nvme_change_ctrl_state(ctrl, NVME_CTRL_DEAD);
+
        if (!queue_work(nvme_delete_wq, &ctrl->delete_work))
                return -EBUSY;
        return 0;
drivers/nvme/host/pci.c +8 -0
index 054bf2f8b1a1..657d3f79953d 100644
@@ -2828,6 +2828,13 @@ static bool nvme_pci_supports_pci_p2pdma(struct nvme_ctrl *ctrl)
        return dma_pci_p2pdma_supported(dev->dev);
 }
 
+static bool nvme_pci_disconnected(struct nvme_ctrl *nctrl)
+{
+       struct nvme_dev *dev = to_nvme_dev(ctrl);
+
+       return !pci_device_is_present(to_pci_dev(dev->dev));
+}
+
 static const struct nvme_ctrl_ops nvme_pci_ctrl_ops = {
        .name                   = "pcie",
        .module                 = THIS_MODULE,
@@ -2841,6 +2848,7 @@ static const struct nvme_ctrl_ops nvme_pci_ctrl_ops = {
        .get_address            = nvme_pci_get_address,
        .print_device_info      = nvme_pci_print_device_info,
        .supports_pci_p2pdma    = nvme_pci_supports_pci_p2pdma,
+       .transport_disconnected = nvme_pci_disconnected,
 };
 
 static int nvme_dev_map(struct nvme_dev *dev)
drivers/nvme/host/rdma.c +13 -0
index 0eb79696fb73..2a03df693b0e 100644
@@ -2235,6 +2235,18 @@ static void nvme_rdma_reset_ctrl_work(struct work_struct *work)
        nvme_rdma_reconnect_or_remove(ctrl);
 }
 
+static bool nvme_rdma_disconnected(struct nvme_ctrl *nctrl)
+{
+       struct nvme_rdma_ctrl *ctrl = to_rdma_ctrl(nctrl);
+       int i;
+
+       for (i = 0; i < ctrl->queue_count; i++) {
+               if (test_bit(NVME_RDMA_Q_LIVE, &ctrl->queues[i].flags))
+                       return false;
+       }
+       return true;
+}
+
 static const struct nvme_ctrl_ops nvme_rdma_ctrl_ops = {
        .name                   = "rdma",
        .module                 = THIS_MODULE,
@@ -2247,6 +2259,7 @@ static const struct nvme_ctrl_ops nvme_rdma_ctrl_ops = {
        .delete_ctrl            = nvme_rdma_delete_ctrl,
        .get_address            = nvmf_get_address,
        .stop_ctrl              = nvme_rdma_stop_ctrl,
+       .transport_disconnected = nvme_rdma_disconnected,
 };
 
 /*
drivers/nvme/host/tcp.c +13 -0
index fe01ba75570d..043ce9878560 100644
@@ -2536,6 +2536,18 @@ static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size)
        return len;
 }
 
+static bool nvme_tcp_disconnected(struct nvme_ctrl *nctrl)
+{
+       struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl);
+       int i;
+
+       for (i = 0; i < ctrl->queue_count; i++) {
+               if (test_bit(NVME_TCP_Q_LIVE, &ctrl->queues[i].flags))
+                       return false;
+       }
+       return true;
+}
+
 static const struct blk_mq_ops nvme_tcp_mq_ops = {
        .queue_rq       = nvme_tcp_queue_rq,
        .commit_rqs     = nvme_tcp_commit_rqs,
@@ -2569,6 +2581,7 @@ static const struct nvme_ctrl_ops nvme_tcp_ctrl_ops = {
        .delete_ctrl            = nvme_tcp_delete_ctrl,
        .get_address            = nvme_tcp_get_address,
        .stop_ctrl              = nvme_tcp_stop_ctrl,
+       .transport_disconnected = nvme_tcp_disconnected,
 };
 
 static bool

--

author
#3 lore raw

Re: [PATCH 1/2] nvme: add API of nvme_delete_dead_ctrl

Quoted 36 lines · Sagi Grimberg
Quoted 36 lines

When driver confirms that the controller is dead, this controller should be deleted with marking as DEAD. Otherwise, upper layer may wait forever in __bio_queue_enter() since the disk won't be marked as DEAD. Especially, in del_gendisk(), disk won't be marked as DEAD unless bdev sync & invalidate returns. If any writeback IO waits in __bio_queue_enter(), IO deadlock is caused.

Add nvme_delete_dead_ctrl() for avoiding such kind of io deadlock.

---
  drivers/nvme/host/core.c | 24 +++++++++++++++++++++++-
  drivers/nvme/host/nvme.h |  1 +
  2 files changed, 24 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +9 -1
index ccb6eb1282f8..413213cfa417 100644
@@ -227,16 +227,38 @@ static void nvme_delete_ctrl_work(struct work_struct *work)
  	nvme_do_delete_ctrl(ctrl);
  }
-int nvme_delete_ctrl(struct nvme_ctrl *ctrl)
+static int __nvme_delete_ctrl(struct nvme_ctrl *ctrl,
+			      enum nvme_ctrl_state state)
  {
+	if (state != NVME_CTRL_DELETING && state != NVME_CTRL_DEAD)
+		return -EINVAL;
+
  	if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING))
  		return -EBUSY;
+	if (state == NVME_CTRL_DEAD) {
+		if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DEAD))
+			return -EBUSY;
+	}
Quoted 8 lines

drivers/nvme/host/core.c static void nvme_delete_ctrl_work(struct work_struct *work) · line 244

Quoted 4 lines
drivers/nvme/host/core.c +0 -0
  	if (!queue_work(nvme_delete_wq, &ctrl->delete_work))
  		return -EBUSY;
  	return 0;
  }

the user can trigger a delete in exactly the same condition as the transport (say a nanosecond before the transport exhaust the max_reconnects).

Yeah, the problem can be triggered when removing any NS which request queue is frozen.

It it too fragile to call freeze_queue and unfreeze_queue in different contexts since both two should have been done in strict pair, and meantime I don't think freezing queues in nvme_rdma_teardown_io_queues() is needed cause quiescing is supposed to be enough for driver to recover controller.

And I guess the following approach(rdma only) should address the issue cleanly:

drivers/nvme/host/rdma.c +2 -1
index 0eb79696fb73..59352671aeb7 100644
@@ -919,6 +919,7 @@ static int nvme_rdma_configure_io_queues(struct nvme_rdma_ctrl *ctrl, bool new)
 
        if (!new) {
                nvme_unquiesce_io_queues(&ctrl->ctrl);
+               nvme_start_freeze(&ctrl->ctrl);
                if (!nvme_wait_freeze_timeout(&ctrl->ctrl, NVME_IO_TIMEOUT)) {
                        /*
                         * If we timed out waiting for freeze we are likely to
@@ -926,6 +927,7 @@ static int nvme_rdma_configure_io_queues(struct nvme_rdma_ctrl *ctrl, bool new)
                         * to be safe.
                         */
                        ret = -ENODEV;
+                       nvme_unfreeze(&ctrl->ctrl);
                        goto out_wait_freeze_timed_out;
                }
                blk_mq_update_nr_hw_queues(ctrl->ctrl.tagset,
@@ -975,7 +977,6 @@ static void nvme_rdma_teardown_io_queues(struct nvme_rdma_ctrl *ctrl,
                bool remove)
 {
        if (ctrl->ctrl.queue_count > 1) {
-               nvme_start_freeze(&ctrl->ctrl);
                nvme_quiesce_io_queues(&ctrl->ctrl);
                nvme_sync_io_queues(&ctrl->ctrl);
                nvme_rdma_stop_io_queues(ctrl);
Quoted 105 lines

I think that we'd want something like
--

drivers/nvme/host/core.c +5 -0
index 841f155fe0b3..6c718ad46e06 100644
@@ -231,6 +231,11 @@ int nvme_delete_ctrl(struct nvme_ctrl *ctrl)
 {
        if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING))
                return -EBUSY;
+
+       if (ctrl->ops->transport_disconnected &&
+           ctrl->ops->transport_disconnected(ctrl))
+               nvme_change_ctrl_state(ctrl, NVME_CTRL_DEAD);
+
        if (!queue_work(nvme_delete_wq, &ctrl->delete_work))
                return -EBUSY;
        return 0;
drivers/nvme/host/pci.c +7 -0
index 054bf2f8b1a1..657d3f79953d 100644
@@ -2828,6 +2828,13 @@ static bool nvme_pci_supports_pci_p2pdma(struct
 nvme_ctrl *ctrl)
        return dma_pci_p2pdma_supported(dev->dev);
 }
 
+static bool nvme_pci_disconnected(struct nvme_ctrl *nctrl)
+{
+       struct nvme_dev *dev = to_nvme_dev(ctrl);
+
+       return !pci_device_is_present(to_pci_dev(dev->dev));
+}
+
 static const struct nvme_ctrl_ops nvme_pci_ctrl_ops = {
        .name                   = "pcie",

.module = THIS_MODULE,

drivers/nvme/host/pci.c +1 -0
@@ -2841,6 +2848,7 @@ static const struct nvme_ctrl_ops nvme_pci_ctrl_ops =
 {
        .get_address            = nvme_pci_get_address,
        .print_device_info      = nvme_pci_print_device_info,
        .supports_pci_p2pdma    = nvme_pci_supports_pci_p2pdma,
+       .transport_disconnected = nvme_pci_disconnected,
 };
 

static int nvme_dev_map(struct nvme_dev *dev)

drivers/nvme/host/rdma.c +12 -0
index 0eb79696fb73..2a03df693b0e 100644
@@ -2235,6 +2235,18 @@ static void nvme_rdma_reset_ctrl_work(struct
 work_struct *work)
        nvme_rdma_reconnect_or_remove(ctrl);
 }
 
+static bool nvme_rdma_disconnected(struct nvme_ctrl *nctrl)
+{
+       struct nvme_rdma_ctrl *ctrl = to_rdma_ctrl(nctrl);
+       int i;
+
+       for (i = 0; i < ctrl->queue_count; i++) {
+               if (test_bit(NVME_RDMA_Q_LIVE, &ctrl->queues[i].flags))
+                       return false;
+       }
+       return true;
+}
+
 static const struct nvme_ctrl_ops nvme_rdma_ctrl_ops = {
        .name                   = "rdma",

.module = THIS_MODULE,

drivers/nvme/host/rdma.c +1 -0
@@ -2247,6 +2259,7 @@ static const struct nvme_ctrl_ops nvme_rdma_ctrl_ops =
 {
        .delete_ctrl            = nvme_rdma_delete_ctrl,
        .get_address            = nvmf_get_address,
        .stop_ctrl              = nvme_rdma_stop_ctrl,
+       .transport_disconnected = nvme_rdma_disconnected,
 };
 

/*

drivers/nvme/host/tcp.c +12 -0
index fe01ba75570d..043ce9878560 100644
@@ -2536,6 +2536,18 @@ static int nvme_tcp_get_address(struct nvme_ctrl
 *ctrl, char *buf, int size)
        return len;
 }
 
+static bool nvme_tcp_disconnected(struct nvme_ctrl *nctrl)
+{
+       struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl);
+       int i;
+
+       for (i = 0; i < ctrl->queue_count; i++) {
+               if (test_bit(NVME_TCP_Q_LIVE, &ctrl->queues[i].flags))
+                       return false;
+       }
+       return true;
+}
+
 static const struct blk_mq_ops nvme_tcp_mq_ops = {
        .queue_rq       = nvme_tcp_queue_rq,

.commit_rqs = nvme_tcp_commit_rqs,

drivers/nvme/host/tcp.c static const struct nvme_ctrl_ops nvme_tcp_ctrl_ops = · line 2585

Quoted 5 lines
drivers/nvme/host/tcp.c +1 -0
@@ -2569,6 +2581,7 @@ static const struct nvme_ctrl_ops nvme_tcp_ctrl_ops =
 {
        .delete_ctrl            = nvme_tcp_delete_ctrl,
        .get_address            = nvme_tcp_get_address,
        .stop_ctrl              = nvme_tcp_stop_ctrl,
+       .transport_disconnected = nvme_tcp_disconnected,

This way is too violent. The current queue/device status does not mean the controller/queue is really dead cause recovering is in in-progress, and we should call blk_mark_disk_dead() in case that controller is confirmed as DEAD.

Thanks,
Ming

maintainer
#4 lore raw

Re: [PATCH 1/2] nvme: add API of nvme_delete_dead_ctrl

Quoted 78 lines · Ming Lei
Quoted 36 lines · Sagi Grimberg
Quoted 36 lines

When driver confirms that the controller is dead, this controller should be deleted with marking as DEAD. Otherwise, upper layer may wait forever in __bio_queue_enter() since the disk won't be marked as DEAD. Especially, in del_gendisk(), disk won't be marked as DEAD unless bdev sync & invalidate returns. If any writeback IO waits in __bio_queue_enter(), IO deadlock is caused.

Add nvme_delete_dead_ctrl() for avoiding such kind of io deadlock.

---
   drivers/nvme/host/core.c | 24 +++++++++++++++++++++++-
   drivers/nvme/host/nvme.h |  1 +
   2 files changed, 24 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +9 -1
index ccb6eb1282f8..413213cfa417 100644
@@ -227,16 +227,38 @@ static void nvme_delete_ctrl_work(struct work_struct *work)
   	nvme_do_delete_ctrl(ctrl);
   }
-int nvme_delete_ctrl(struct nvme_ctrl *ctrl)
+static int __nvme_delete_ctrl(struct nvme_ctrl *ctrl,
+			      enum nvme_ctrl_state state)
   {
+	if (state != NVME_CTRL_DELETING && state != NVME_CTRL_DEAD)
+		return -EINVAL;
+
   	if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING))
   		return -EBUSY;
+	if (state == NVME_CTRL_DEAD) {
+		if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DEAD))
+			return -EBUSY;
+	}
Quoted 8 lines

drivers/nvme/host/core.c static void nvme_delete_ctrl_work(struct work_struct *work) · line 244

Quoted 4 lines
drivers/nvme/host/core.c +0 -0
   	if (!queue_work(nvme_delete_wq, &ctrl->delete_work))
   		return -EBUSY;
   	return 0;
   }

the user can trigger a delete in exactly the same condition as the transport (say a nanosecond before the transport exhaust the max_reconnects).

Yeah, the problem can be triggered when removing any NS which request queue is frozen.

It it too fragile to call freeze_queue and unfreeze_queue in different contexts since both two should have been done in strict pair, and meantime I don't think freezing queues in nvme_rdma_teardown_io_queues() is needed cause quiescing is supposed to be enough for driver to recover controller.

And I guess the following approach(rdma only) should address the issue cleanly:

drivers/nvme/host/rdma.c +2 -0
index 0eb79696fb73..59352671aeb7 100644
@@ -919,6 +919,7 @@ static int nvme_rdma_configure_io_queues(struct nvme_rdma_ctrl *ctrl, bool new)
 
         if (!new) {
                 nvme_unquiesce_io_queues(&ctrl->ctrl);
+               nvme_start_freeze(&ctrl->ctrl);
                 if (!nvme_wait_freeze_timeout(&ctrl->ctrl, NVME_IO_TIMEOUT)) {
                         /*
                          * If we timed out waiting for freeze we are likely to
@@ -926,6 +927,7 @@ static int nvme_rdma_configure_io_queues(struct nvme_rdma_ctrl *ctrl, bool new)
                          * to be safe.
                          */
                         ret = -ENODEV;
+                       nvme_unfreeze(&ctrl->ctrl);
                         goto out_wait_freeze_timed_out;
                 }
                 blk_mq_update_nr_hw_queues(ctrl->ctrl.tagset,

drivers/nvme/host/rdma.c static void nvme_rdma_teardown_io_queues(struct nvme_rdma_ctrl *ctrl, · line 982

Quoted 7 lines
drivers/nvme/host/rdma.c +0 -1
@@ -975,7 +977,6 @@ static void nvme_rdma_teardown_io_queues(struct nvme_rdma_ctrl *ctrl,
                 bool remove)
  {
         if (ctrl->ctrl.queue_count > 1) {
-               nvme_start_freeze(&ctrl->ctrl);
                 nvme_quiesce_io_queues(&ctrl->ctrl);
                 nvme_sync_io_queues(&ctrl->ctrl);
                 nvme_rdma_stop_io_queues(ctrl);

I agree this should work.

Quoted 108 lines
Quoted 108 lines

I think that we'd want something like
--

drivers/nvme/host/core.c +5 -0
index 841f155fe0b3..6c718ad46e06 100644
@@ -231,6 +231,11 @@ int nvme_delete_ctrl(struct nvme_ctrl *ctrl)
  {
         if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING))
                 return -EBUSY;
+
+       if (ctrl->ops->transport_disconnected &&
+           ctrl->ops->transport_disconnected(ctrl))
+               nvme_change_ctrl_state(ctrl, NVME_CTRL_DEAD);
+
         if (!queue_work(nvme_delete_wq, &ctrl->delete_work))
                 return -EBUSY;
         return 0;
drivers/nvme/host/pci.c +7 -0
index 054bf2f8b1a1..657d3f79953d 100644
@@ -2828,6 +2828,13 @@ static bool nvme_pci_supports_pci_p2pdma(struct
 nvme_ctrl *ctrl)
         return dma_pci_p2pdma_supported(dev->dev);
  }
 
+static bool nvme_pci_disconnected(struct nvme_ctrl *nctrl)
+{
+       struct nvme_dev *dev = to_nvme_dev(ctrl);
+
+       return !pci_device_is_present(to_pci_dev(dev->dev));
+}
+
  static const struct nvme_ctrl_ops nvme_pci_ctrl_ops = {
         .name                   = "pcie",

.module = THIS_MODULE,

drivers/nvme/host/pci.c +1 -0
@@ -2841,6 +2848,7 @@ static const struct nvme_ctrl_ops nvme_pci_ctrl_ops =
 {
         .get_address            = nvme_pci_get_address,
         .print_device_info      = nvme_pci_print_device_info,
         .supports_pci_p2pdma    = nvme_pci_supports_pci_p2pdma,
+       .transport_disconnected = nvme_pci_disconnected,
  };
 

static int nvme_dev_map(struct nvme_dev *dev)

drivers/nvme/host/rdma.c +12 -0
index 0eb79696fb73..2a03df693b0e 100644
@@ -2235,6 +2235,18 @@ static void nvme_rdma_reset_ctrl_work(struct
 work_struct *work)
         nvme_rdma_reconnect_or_remove(ctrl);
  }
 
+static bool nvme_rdma_disconnected(struct nvme_ctrl *nctrl)
+{
+       struct nvme_rdma_ctrl *ctrl = to_rdma_ctrl(nctrl);
+       int i;
+
+       for (i = 0; i < ctrl->queue_count; i++) {
+               if (test_bit(NVME_RDMA_Q_LIVE, &ctrl->queues[i].flags))
+                       return false;
+       }
+       return true;
+}
+
  static const struct nvme_ctrl_ops nvme_rdma_ctrl_ops = {
         .name                   = "rdma",

.module = THIS_MODULE,

drivers/nvme/host/rdma.c +1 -0
@@ -2247,6 +2259,7 @@ static const struct nvme_ctrl_ops nvme_rdma_ctrl_ops =
 {
         .delete_ctrl            = nvme_rdma_delete_ctrl,
         .get_address            = nvmf_get_address,
         .stop_ctrl              = nvme_rdma_stop_ctrl,
+       .transport_disconnected = nvme_rdma_disconnected,
  };
 

/*

drivers/nvme/host/tcp.c +12 -0
index fe01ba75570d..043ce9878560 100644
@@ -2536,6 +2536,18 @@ static int nvme_tcp_get_address(struct nvme_ctrl
 *ctrl, char *buf, int size)
         return len;
  }
 
+static bool nvme_tcp_disconnected(struct nvme_ctrl *nctrl)
+{
+       struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl);
+       int i;
+
+       for (i = 0; i < ctrl->queue_count; i++) {
+               if (test_bit(NVME_TCP_Q_LIVE, &ctrl->queues[i].flags))
+                       return false;
+       }
+       return true;
+}
+
  static const struct blk_mq_ops nvme_tcp_mq_ops = {
         .queue_rq       = nvme_tcp_queue_rq,

.commit_rqs = nvme_tcp_commit_rqs,

drivers/nvme/host/tcp.c +0 -0
@@ -2569,6 +2581,7 @@ static const struct nvme_ctrl_ops nvme_tcp_ctrl_ops =
 {
         .delete_ctrl            = nvme_tcp_delete_ctrl,
Quoted 8 lines

drivers/nvme/host/tcp.c static const struct nvme_ctrl_ops nvme_tcp_ctrl_ops = · line 2585

Quoted 3 lines
drivers/nvme/host/tcp.c +1 -0
         .get_address            = nvme_tcp_get_address,
         .stop_ctrl              = nvme_tcp_stop_ctrl,
+       .transport_disconnected = nvme_tcp_disconnected,

This way is too violent. The current queue/device status does not mean the controller/queue is really dead cause recovering is in in-progress, and we should call blk_mark_disk_dead() in case that controller is confirmed as DEAD.

Well, the controller is going away, and the queues are not LIVE, so I think the logic makes sense. However I do agree that your other suggestion is cleaner.

author
#5 lore raw

PATCH 2/2 nvme: rdma/tcp: call nvme_delete_dead_ctrl for handling reconnect failure

In reply to Ming Lei

Reconnect failure has been reached after trying enough times, and controller is actually incapable of handling IO, so it should be marked as dead, so call nvme_delete_dead_ctrl() to handle the failure for avoiding the following IO deadlock:

1) writeback IO waits in __bio_queue_enter() because queue is frozen during error recovery

2) reconnect failure handler removes controller, and del_gendisk() waits for above writeback IO in fsync/invalidate bdev

Fix the issue by calling nvme_delete_dead_ctrl() which call nvme_mark_namespaces_dead() before deleting disk, so the above writeback IO will be failed, and IO deadlock is avoided.

---
 drivers/nvme/host/rdma.c | 2 +-
 drivers/nvme/host/tcp.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/host/rdma.c +1 -1
index 0eb79696fb73..cdf5855c3009 100644
@@ -1028,7 +1028,7 @@ static void nvme_rdma_reconnect_or_remove(struct nvme_rdma_ctrl *ctrl)
 		queue_delayed_work(nvme_wq, &ctrl->reconnect_work,
 				ctrl->ctrl.opts->reconnect_delay * HZ);
 	} else {
-		nvme_delete_ctrl(&ctrl->ctrl);
+		nvme_delete_dead_ctrl(&ctrl->ctrl);
 	}
 }
 
drivers/nvme/host/tcp.c +1 -1
index bf0230442d57..2c119bff7010 100644
@@ -2047,7 +2047,7 @@ static void nvme_tcp_reconnect_or_remove(struct nvme_ctrl *ctrl)
 				ctrl->opts->reconnect_delay * HZ);
 	} else {
 		dev_info(ctrl->device, "Removing controller...\n");
-		nvme_delete_ctrl(ctrl);
+		nvme_delete_dead_ctrl(ctrl);
 	}
 }
 
Signature · 1 line
2.40.1
Tested-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] nvme: rdma/tcp: call nvme_delete_dead_ctrl for handling reconnect failure

Thanks Ming, feel free to add:

Quoted 52 lines · Ming Lei

Reconnect failure has been reached after trying enough times, and controller is actually incapable of handling IO, so it should be marked as dead, so call nvme_delete_dead_ctrl() to handle the failure for avoiding the following IO deadlock:

1) writeback IO waits in __bio_queue_enter() because queue is frozen during error recovery

2) reconnect failure handler removes controller, and del_gendisk() waits for above writeback IO in fsync/invalidate bdev

Fix the issue by calling nvme_delete_dead_ctrl() which call nvme_mark_namespaces_dead() before deleting disk, so the above writeback IO will be failed, and IO deadlock is avoided.

---
 drivers/nvme/host/rdma.c | 2 +-
 drivers/nvme/host/tcp.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/host/rdma.c +1 -1
index 0eb79696fb73..cdf5855c3009 100644
@@ -1028,7 +1028,7 @@ static void nvme_rdma_reconnect_or_remove(struct nvme_rdma_ctrl *ctrl)
                queue_delayed_work(nvme_wq, &ctrl->reconnect_work,
                                ctrl->ctrl.opts->reconnect_delay * HZ);
        } else {
-               nvme_delete_ctrl(&ctrl->ctrl);
+               nvme_delete_dead_ctrl(&ctrl->ctrl);
        }
 }
 
drivers/nvme/host/tcp.c +1 -2
index bf0230442d57..2c119bff7010 100644
@@ -2047,7 +2047,7 @@ static void nvme_tcp_reconnect_or_remove(struct nvme_ctrl *ctrl)
                                ctrl->opts->reconnect_delay * HZ);
        } else {
                dev_info(ctrl->device, "Removing controller...\n");
-               nvme_delete_ctrl(ctrl);
+               nvme_delete_dead_ctrl(ctrl);
        }
 }
 
--

2.40.1

Signature · 2 lines
Best Regards,
  Yi Zhang