nvme: pci: fix & improve timeout handling
Subsystems (3)
v6 cover nvme: pci: fix & improve timeout handling
Hi,
The 1st patch introduces blk_quiesce_timeout() and blk_unquiesce_timeout() for NVMe, meantime fixes blk_sync_queue().
The 2nd and 3rd patches fix race between nvme_dev_disable() and controller reset, and avoids double irq freeing and IO hang after queues are killed.
The 4th patch covers timeout for admin commands for recovering controller for avoiding possible deadlock.
The 5rd and 6th patches avoid to wait_freeze on queues which aren't frozen.
The last 5 patches fixes several races wrt. NVMe timeout handler. Meantime the NVMe PCI timeout mecanism become much more rebost than before.
With this patchset, block/011 can be passed.
Also run block 019, it still passed.
Please reivew, ack and test!
gitweb:
https://github.com/ming1/linux/commits/v4.17-rc-nvme-timeout.V6
V6:
- fix EH seq number so that correct EH name can be shown in log
- avoid NULL pointer dereference of admin queue
- avoid request leak in nvme_set_host_mem_timeout
- cover races between nvme_dev_disable() and reset wrt. cq_vector
- think EH as done when its state is updated as ADMIN_ONLY
V5:
- avoid to remove controller in case of reset failure in inner EHs
- make sure that nvme_unfreeze and nvme_start_freeze are paired
V4:
- fixe nvme_init_set_host_mem_cmd()
- use nested EH model, and run both nvme_dev_disable() and resetting in one same context
V3:
- fix one new race related freezing in patch 4, nvme_reset_work() may hang forever without this patch
- rewrite the last 3 patches, and avoid to break nvme_reset_ctrl*()
V2:
- fix draining timeout work, so no need to change return value from .timeout()
- fix race between nvme_start_freeze() and nvme_unfreeze()
- cover timeout for admin commands running in EH
Ming Lei (10):
block: introduce blk_quiesce_timeout() and blk_unquiesce_timeout()
nvme: pci: cover timeout for admin commands running in EH
nvme: pci: unquiesce admin queue after controller is shutdown
nvme: pci: only wait freezing if queue is frozen
nvme: pci: freeze queue in nvme_dev_disable() in case of error
recovery
nvme: pci: prepare for supporting error recovery from resetting
context
nvme: pci: move error handling out of nvme_reset_dev()
nvme: pci: don't unfreeze queue until controller state updating
succeeds
nvme: core: introduce nvme_force_change_ctrl_state()
nvme: pci: support nested EH
jianchao.wang (1):
nvme: pci: set nvmeq->cq_vector after alloc cq/sq
block/blk-core.c | 21 ++- block/blk-mq.c | 9 + block/blk-timeout.c | 5 +- drivers/nvme/host/core.c | 57 ++++++ drivers/nvme/host/nvme.h | 7 + drivers/nvme/host/pci.c | 450 ++++++++++++++++++++++++++++++++++++++++------- include/linux/blkdev.h | 13 ++ 7 files changed, 499 insertions(+), 63 deletions(-)
Signature · 1 line
2.9.5
PATCH v6 1/11 block: introduce blk_quiesce_timeout() and blk_unquiesce_timeout()
Turns out the current way can't drain timout completely because mod_timer() can be triggered in the work func, which can be just run inside the synced timeout work:
del_timer_sync(&q->timeout);
cancel_work_sync(&q->timeout_work);This patch introduces one flag of 'timeout_off' for fixing this issue, turns out this simple way does work.
Also blk_quiesce_timeout() and blk_unquiesce_timeout() are introduced for draining timeout, which is needed by NVMe.
--- block/blk-core.c | 21 +++++++++++++++++++-- block/blk-mq.c | 9 +++++++++ block/blk-timeout.c | 5 ++++- include/linux/blkdev.h | 13 +++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-)
block/blk-core.c +19 -2
@@ -392,6 +392,22 @@ void blk_stop_queue(struct request_queue *q) }EXPORT_SYMBOL (blk_stop_queue); +void blk_unquiesce_timeout (struct request_queue *q) +{ +blk_mark_timeout_quiesce (q, false); +mod_timer (&q->timeout, jiffies + q->rq_timeout); +} +EXPORT_SYMBOL (blk_unquiesce_timeout); + +void blk_quiesce_timeout (struct request_queue *q) +{ +blk_mark_timeout_quiesce (q, true); + +del_timer_sync (&q->timeout); +cancel_work_sync (&q->timeout_work); +} +EXPORT_SYMBOL (blk_quiesce_timeout); +/** * blk_sync_queue - cancel any pending callbacks on a queue * @q: the queue
@@ -412,8 +428,7 @@ EXPORT_SYMBOL(blk_stop_queue);*/ void blk_sync_queue (struct request_queue *q) { -del_timer_sync (&q->timeout); -cancel_work_sync (&q->timeout_work); +blk_quiesce_timeout (q);if (q->mq_ops) {struct blk_mq_hw_ctx *hctx;
@@ -425,6 +440,8 @@ void blk_sync_queue(struct request_queue *q) }else {cancel_delayed_work_sync (&q->delay_work); } + +blk_mark_timeout_quiesce (q, false); }EXPORT_SYMBOL (blk_sync_queue);
block/blk-mq.c +9 -0
@@ -917,6 +917,15 @@ static void blk_mq_timeout_work(struct work_struct *work) };struct blk_mq_hw_ctx *hctx;int i; +bool timeout_off; +unsigned long flags; + +spin_lock_irqsave (q->queue_lock, flags); + timeout_off = q->timeout_off; +spin_unlock_irqrestore (q->queue_lock, flags); + +if (timeout_off) +return ;/* A deadlock might occur if a request is stuck requiring a * timeout at the same time a queue freeze is waiting
block/blk-timeout.c +4 -1
@@ -136,12 +136,15 @@ void blk_timeout_work(struct work_struct *work)spin_lock_irqsave (q->queue_lock, flags); +if (q->timeout_off) + goto exit; +list_for_each_entry_safe (rq, tmp, &q->timeout_list, timeout_list)blk_rq_check_expired (rq, &next, &next_set);if (next_set)mod_timer (&q->timeout,round_jiffies_up (next)); - +exit:spin_unlock_irqrestore (q->queue_lock, flags); }
include/linux/blkdev.h +13 -0
@@ -584,6 +584,7 @@ struct request_queue {struct timer_list timeout;struct work_struct timeout_work;struct list_head timeout_list; +bool timeout_off;struct list_head icq_list;#ifdef CONFIG_BLK_CGROUP
@@ -1017,6 +1018,18 @@ extern void blk_execute_rq(struct request_queue *, struct gendisk *,extern void blk_execute_rq_nowait (struct request_queue *,struct gendisk *,struct request *,int ,rq_end_io_fn *); +static inline void blk_mark_timeout_quiesce (struct request_queue *q,bool quiesce) +{ +unsigned long flags; + +spin_lock_irqsave (q->queue_lock, flags); + q->timeout_off = quiesce; +spin_unlock_irqrestore (q->queue_lock, flags); +} + +extern void blk_quiesce_timeout (struct request_queue *q); +extern void blk_unquiesce_timeout (struct request_queue *q); +int blk_status_to_errno (blk_status_t status);blk_status_t errno_to_blk_status (int errno);
Signature · 1 line
2.9.5
PATCH v6 2/11 nvme: pci: cover timeout for admin commands running in EH
In reply to Ming LeiWhen admin commands are used in EH for recovering controller, we have to cover their timeout and can't depend on block's timeout since deadlock may be caused when these commands are timed-out by block layer again.
--- drivers/nvme/host/pci.c | 81 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 11 deletions(-)
drivers/nvme/host/pci.c +70 -11
@@ -1742,21 +1742,28 @@ static inline void nvme_release_cmb(struct nvme_dev *dev) } } -static int nvme_set_host_mem (struct nvme_dev *dev,u32 bits) +static void nvme_init_set_host_mem_cmd (struct nvme_dev *dev, +struct nvme_command *c,u32 bits) {u64 dma_addr = dev->host_mem_descs_dma; + +memset (c,0 ,sizeof (*c)); + c->features.opcode = nvme_admin_set_features; + c->features.fid =cpu_to_le32 (NVME_FEAT_HOST_MEM_BUF ); + c->features.dword11 =cpu_to_le32 (bits); + c->features.dword12 =cpu_to_le32 (dev->host_mem_size >> +ilog2 (dev->ctrl.page_size)); + c->features.dword13 =cpu_to_le32 (lower_32_bits (dma_addr)); + c->features.dword14 =cpu_to_le32 (upper_32_bits (dma_addr)); + c->features.dword15 =cpu_to_le32 (dev->nr_host_mem_descs); +} + +static int nvme_set_host_mem (struct nvme_dev *dev,u32 bits) +{struct nvme_command c;int ret; -memset (&c,0 ,sizeof (c)); - c.features.opcode = nvme_admin_set_features; - c.features.fid =cpu_to_le32 (NVME_FEAT_HOST_MEM_BUF ); - c.features.dword11 =cpu_to_le32 (bits); - c.features.dword12 =cpu_to_le32 (dev->host_mem_size >> -ilog2 (dev->ctrl.page_size)); - c.features.dword13 =cpu_to_le32 (lower_32_bits (dma_addr)); - c.features.dword14 =cpu_to_le32 (upper_32_bits (dma_addr)); - c.features.dword15 =cpu_to_le32 (dev->nr_host_mem_descs); +nvme_init_set_host_mem_cmd (dev, &c, bits); ret =nvme_submit_sync_cmd (dev->ctrl.admin_q, &c,NULL ,0 );if (ret) {
@@ -1767,6 +1774,58 @@ static int nvme_set_host_mem(struct nvme_dev *dev, u32 bits)return ret; } +static void nvme_set_host_mem_end_io (struct request *rq,blk_status_t sts) +{ +struct completion *waiting = rq->end_io_data; + + rq->end_io_data =NULL ; +blk_mq_free_request (rq); + +/* +* complete last, if this is a stack request the process (and thus +* the rq pointer) could be invalid right after this complete() +*/ +complete (waiting); +} + +/* +* This function can only be used inside nvme_dev_disable() when timeout +* may not work, then this function has to cover the timeout by itself. +* +* When wait_for_completion_io_timeout() returns 0 and timeout happens, +* this request will be completed after controller is shutdown. +*/ +static int nvme_set_host_mem_timeout (struct nvme_dev *dev,u32 bits) +{ +DECLARE_COMPLETION_ONSTACK (wait); +struct nvme_command c; +struct request_queue *q = dev->ctrl.admin_q; +struct request *req; +int ret; + +nvme_init_set_host_mem_cmd (dev, &c, bits); + + req =nvme_alloc_request (q, &c,0 ,NVME_QID_ANY ); +if (IS_ERR (req)) +return PTR_ERR (req); + + req->timeout =ADMIN_TIMEOUT ; + req->end_io_data = &wait; + +blk_execute_rq_nowait (q,NULL , req, false, + nvme_set_host_mem_end_io); + ret =wait_for_completion_io_timeout (&wait,ADMIN_TIMEOUT ); +if (ret >0 ) { +if (nvme_req (req)->flags &NVME_REQ_CANCELLED ) + ret = -EINTR ; +else + ret =nvme_req (req)->status; + }else + ret = -EINTR ; + +return ret; +} +static void nvme_free_host_mem (struct nvme_dev *dev) {int i;
@@ -2225,7 +2284,7 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown)* but I'd rather be safe than sorry.. */ if (dev->host_mem_descs) -nvme_set_host_mem (dev,0 ); +nvme_set_host_mem_timeout (dev,0 );nvme_disable_io_queues (dev);nvme_disable_admin_queue (dev, shutdown); }
Signature · 1 line
2.9.5
Re: [PATCH V6 02/11] nvme: pci: cover timeout for admin commands running in EH
Quoted 41 lines · Ming Lei
drivers/nvme/host/pci.c +41
-0+static void nvme_set_host_mem_end_io (struct request *rq,blk_status_t sts) +{ +struct completion *waiting = rq->end_io_data; + + rq->end_io_data =NULL ; +blk_mq_free_request (rq); + +/* +* complete last, if this is a stack request the process (and thus +* the rq pointer) could be invalid right after this complete() +*/ +complete (waiting); +} + +/* +* This function can only be used inside nvme_dev_disable() when timeout +* may not work, then this function has to cover the timeout by itself. +* +* When wait_for_completion_io_timeout() returns 0 and timeout happens, +* this request will be completed after controller is shutdown. +*/ +static int nvme_set_host_mem_timeout (struct nvme_dev *dev,u32 bits) +{ +DECLARE_COMPLETION_ONSTACK (wait); +struct nvme_command c; +struct request_queue *q = dev->ctrl.admin_q; +struct request *req; +int ret; + +nvme_init_set_host_mem_cmd (dev, &c, bits); + + req =nvme_alloc_request (q, &c,0 ,NVME_QID_ANY ); +if (IS_ERR (req)) +return PTR_ERR (req); + + req->timeout =ADMIN_TIMEOUT ; + req->end_io_data = &wait; + +blk_execute_rq_nowait (q,NULL , req, false, + nvme_set_host_mem_end_io); + ret =wait_for_completion_io_timeout (&wait,ADMIN_TIMEOUT );
drivers/nvme/host/pci.c static int nvme_set_host_mem(struct nvme_dev *dev, u32 bits) · line 1827
Quoted 10 lines
drivers/nvme/host/pci.c +10
-0+if (ret >0 ) { +if (nvme_req (req)->flags &NVME_REQ_CANCELLED ) + ret = -EINTR ; +else + ret =nvme_req (req)->status; + }else + ret = -EINTR ; + +return ret; +}
This function doesn't need to return anything at all. The caller doesn't care about the success in order to decide what to do next.
Now let's say it does time out. The command will be be completed later through nvme_cancel_request, but your completion callback will reference a now invalid stack variable.
Quoted 12 lines
static void
nvme_free_host_mem(struct nvme_dev *dev){drivers/nvme/host/pci.c +1
-1int i;@@ -2225,7 +2284,7 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown)* but I'd rather be safe than sorry.. */ if (dev->host_mem_descs) -nvme_set_host_mem (dev,0 ); +nvme_set_host_mem_timeout (dev,0 );nvme_disable_io_queues (dev);nvme_disable_admin_queue (dev, shutdown); }
PATCH v6 3/11 nvme: pci: unquiesce admin queue after controller is shutdown
In reply to Ming LeiGiven timeout event can come during reset, nvme_dev_disable() shouldn't keep admin queue as quiesced after controller is shutdown. Otherwise it may block admin IO in reset, and cause reset hang forever.
This patch fixes this issue by unquiescing admin queue at the end of nvme_dev_disable().
--- drivers/nvme/host/pci.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/nvme/host/pci.c +12 -2
@@ -1557,8 +1557,7 @@ static int nvme_alloc_admin_tags(struct nvme_dev *dev) dev->ctrl.admin_q =NULL ;return -ENODEV ; } - }else -blk_mq_unquiesce_queue (dev->ctrl.admin_q); + }return 0 ; }
@@ -2303,6 +2302,17 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown)*/ if (shutdown)nvme_start_queues (&dev->ctrl); + +/* +* Avoid to stuck reset because timeout may happen during reset and +* reset may hang forever if admin queue is kept as quiesced. +* +* Druing reset, if admin queue isn't ready, the command will be +* failed immediately, that means we don't need to quiesce admin +* queue. +*/ +if (dev->ctrl.admin_q) +blk_mq_unquiesce_queue (dev->ctrl.admin_q);mutex_unlock (&dev->shutdown_lock); }
Signature · 1 line
2.9.5
PATCH v6 4/11 nvme: pci: set nvmeq->cq_vector after alloc cq/sq
In reply to Ming LeiFrom: "jianchao.wang" <[email protected]>
Currently nvmeq->cq_vector is set before alloc cq/sq. If the alloc cq/sq command timeout, nvme_suspend_queue will invoke free_irq for the nvmeq because the cq_vector is valid, this will cause warning 'Trying to free already-free IRQ xxx'. set nvmeq->cq_vector after alloc cq/sq successes to fix this.
--- drivers/nvme/host/pci.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
drivers/nvme/host/pci.c +16 -9
@@ -1070,7 +1070,7 @@ static int adapter_delete_queue(struct nvme_dev *dev, u8 opcode, u16 id) }static int adapter_alloc_cq (struct nvme_dev *dev,u16 qid, -struct nvme_queue *nvmeq) +struct nvme_queue *nvmeq,int cq_vector) {struct nvme_command c;int flags =NVME_QUEUE_PHYS_CONTIG |NVME_CQ_IRQ_ENABLED ;
@@ -1085,7 +1085,7 @@ static int adapter_alloc_cq(struct nvme_dev *dev, u16 qid, c.create_cq.cqid =cpu_to_le16 (qid); c.create_cq.qsize =cpu_to_le16 (nvmeq->q_depth -1 ); c.create_cq.cq_flags =cpu_to_le16 (flags); - c.create_cq.irq_vector =cpu_to_le16 (nvmeq->cq_vector); + c.create_cq.irq_vector =cpu_to_le16 (cq_vector);return nvme_submit_sync_cmd (dev->ctrl.admin_q, &c,NULL ,0 ); }
@@ -1459,6 +1459,7 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid) {struct nvme_dev *dev = nvmeq->dev;int result; +int cq_vector;if (dev->cmb && use_cmb_sqes && (dev->cmbsz &NVME_CMBSZ_SQS )) { unsigned offset = (qid - 1) * roundup(SQ_SIZE(nvmeq->q_depth),
@@ -1471,15 +1472,21 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid)* A queue's vector matches the queue identifier unless the controller * has only one vector available. */ - nvmeq->cq_vector = dev->num_vecs ==1 ?0 : qid; - result =adapter_alloc_cq (dev, qid, nvmeq); + cq_vector = dev->num_vecs ==1 ?0 : qid; + result =adapter_alloc_cq (dev, qid, nvmeq, cq_vector);if (result <0 ) - goto release_vector; + goto out; result =adapter_alloc_sq (dev, qid, nvmeq);if (result <0 ) goto release_cq; +/* +* set cq_vector after alloc cq/sq, otherwise, if alloc cq/sq command +* timeout, nvme_suspend_queue will invoke free_irq for it and cause warning +* 'Trying to free already-free IRQ xxx' +*/ + nvmeq->cq_vector = cq_vector;nvme_init_queue (nvmeq, qid); result =queue_request_irq (nvmeq);if (result <0 )
@@ -1487,13 +1494,13 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid)return result; - release_sq: +release_sq: + nvmeq->cq_vector =-1 ; dev->online_queues--;adapter_delete_sq (dev, qid); - release_cq: +release_cq:adapter_delete_cq (dev, qid); - release_vector: - nvmeq->cq_vector =-1 ; +out:return result; }
Signature · 1 line
2.9.5
PATCH v6 5/11 nvme: pci: only wait freezing if queue is frozen
In reply to Ming LeiIn nvme_dev_disable() called during shutting down controler, nvme_wait_freeze_timeout() may be done on the controller not frozen yet, so add the check for avoiding the case.
--- drivers/nvme/host/pci.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/nvme/host/pci.c +5 -2
@@ -2259,14 +2259,17 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown)int i;bool dead = true;struct pci_dev *pdev =to_pci_dev (dev->dev); +bool frozen = false;mutex_lock (&dev->shutdown_lock);if (pci_is_enabled (pdev)) {u32 csts =readl (dev->bar +NVME_REG_CSTS );if (dev->ctrl.state ==NVME_CTRL_LIVE || - dev->ctrl.state ==NVME_CTRL_RESETTING ) + dev->ctrl.state ==NVME_CTRL_RESETTING ) {nvme_start_freeze (&dev->ctrl); + frozen = true; + } dead = !!((csts &NVME_CSTS_CFS ) || !(csts &NVME_CSTS_RDY ) || pdev->error_state != pci_channel_io_normal); }
@@ -2276,7 +2279,7 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown)* doing a safe shutdown. */ if (!dead) { -if (shutdown) +if (shutdown && frozen)nvme_wait_freeze_timeout (&dev->ctrl,NVME_IO_TIMEOUT ); }
Signature · 1 line
2.9.5
PATCH v6 6/11 nvme: pci: freeze queue in nvme_dev_disable() in case of error recovery
In reply to Ming LeiWhen nvme_dev_disable() is used for error recovery, we should always freeze queues before shutdown controller:
- reset handler supposes queues are frozen, and will wait_freeze & unfreeze them explicitly, if queues aren't frozen during nvme_dev_disable(), reset handler may wait forever even though there isn't any requests allocated.
- this way may avoid to cancel lots of requests during error recovery
This patch introduces the parameter of 'freeze_queue' for fixing this issue.
--- drivers/nvme/host/pci.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-)
drivers/nvme/host/pci.c +32 -15
@@ -69,7 +69,8 @@ struct nvme_dev;struct nvme_queue ;static void nvme_process_cq (struct nvme_queue *nvmeq); -static void nvme_dev_disable (struct nvme_dev *dev,bool shutdown); +static void nvme_dev_disable (struct nvme_dev *dev,bool shutdown,bool + freeze_queue);/* * Represents an NVM Express device. Each nvme_dev is a PCI function.
@@ -1206,7 +1207,7 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)*/ if (nvme_should_reset (dev, csts)) {nvme_warn_reset (dev, csts); -nvme_dev_disable (dev, false); +nvme_dev_disable (dev, false, true);nvme_reset_ctrl (&dev->ctrl);return BLK_EH_HANDLED ; }
@@ -1233,7 +1234,7 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)dev_warn (dev->ctrl.device,"I/O %d QID %d timeout, disable controller\n" , req->tag, nvmeq->qid); -nvme_dev_disable (dev, false); +nvme_dev_disable (dev, false, false);nvme_req (req)->flags |=NVME_REQ_CANCELLED ;return BLK_EH_HANDLED ;default :
@@ -1249,7 +1250,7 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)dev_warn (dev->ctrl.device,"I/O %d QID %d timeout, reset controller\n" , req->tag, nvmeq->qid); -nvme_dev_disable (dev, false); +nvme_dev_disable (dev, false, true);nvme_reset_ctrl (&dev->ctrl);/*
@@ -2254,19 +2255,35 @@ static void nvme_pci_disable(struct nvme_dev *dev) } } -static void nvme_dev_disable (struct nvme_dev *dev,bool shutdown) +/* +* Resetting often follows nvme_dev_disable(), so queues need to be frozen +* before resetting. +*/ +static void nvme_dev_disable (struct nvme_dev *dev,bool shutdown,bool + freeze_queue) {int i;bool dead = true;struct pci_dev *pdev =to_pci_dev (dev->dev);bool frozen = false; +/* +* 'freeze_queue' is only valid for non-shutdown, and we do +* inline freeze & wait_freeze_timeout for shutdown just for +* completing as many as possible requests before shutdown +*/ +if (shutdown) + freeze_queue = false; + +if (freeze_queue) +nvme_start_freeze (&dev->ctrl); +mutex_lock (&dev->shutdown_lock);if (pci_is_enabled (pdev)) {u32 csts =readl (dev->bar +NVME_REG_CSTS ); -if (dev->ctrl.state ==NVME_CTRL_LIVE || - dev->ctrl.state ==NVME_CTRL_RESETTING ) { +if (shutdown && (dev->ctrl.state ==NVME_CTRL_LIVE || + dev->ctrl.state ==NVME_CTRL_RESETTING )) {nvme_start_freeze (&dev->ctrl); frozen = true; }
@@ -2369,7 +2386,7 @@ static void nvme_remove_dead_ctrl(struct nvme_dev *dev, int status)dev_warn (dev->ctrl.device,"Removing after probe failure status: %d\n" , status);nvme_get_ctrl (&dev->ctrl); -nvme_dev_disable (dev, false); +nvme_dev_disable (dev, false, false);if (!queue_work (nvme_wq, &dev->remove_work))nvme_put_ctrl (&dev->ctrl); }
@@ -2390,7 +2407,7 @@ static void nvme_reset_work(struct work_struct *work)* moving on. */ if (dev->ctrl.ctrl_config &NVME_CC_ENABLE ) -nvme_dev_disable (dev, false); +nvme_dev_disable (dev, false, false);/* * Introduce CONNECTING state from nvme-fc/rdma transports to mark the
@@ -2639,7 +2656,7 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)static void nvme_reset_prepare (struct pci_dev *pdev) {struct nvme_dev *dev =pci_get_drvdata (pdev); -nvme_dev_disable (dev, false); +nvme_dev_disable (dev, false, true); }static void nvme_reset_done (struct pci_dev *pdev)
@@ -2651,7 +2668,7 @@ static void nvme_reset_done(struct pci_dev *pdev)static void nvme_shutdown (struct pci_dev *pdev) {struct nvme_dev *dev =pci_get_drvdata (pdev); -nvme_dev_disable (dev, true); +nvme_dev_disable (dev, true, false); }/*
@@ -2670,13 +2687,13 @@ static void nvme_remove(struct pci_dev *pdev)if (!pci_device_is_present (pdev)) {nvme_change_ctrl_state (&dev->ctrl,NVME_CTRL_DEAD ); -nvme_dev_disable (dev, false); +nvme_dev_disable (dev, false, false); }flush_work (&dev->ctrl.reset_work);nvme_stop_ctrl (&dev->ctrl);nvme_remove_namespaces (&dev->ctrl); -nvme_dev_disable (dev, true); +nvme_dev_disable (dev, true, false);nvme_free_host_mem (dev);nvme_dev_remove_admin (dev);nvme_free_queues (dev,0 );
@@ -2710,7 +2727,7 @@ static int nvme_suspend(struct device *dev)struct pci_dev *pdev =to_pci_dev (dev);struct nvme_dev *ndev =pci_get_drvdata (pdev); -nvme_dev_disable (ndev, true); +nvme_dev_disable (ndev, true, false);return 0 ; }
@@ -2742,7 +2759,7 @@ static pci_ers_result_t nvme_error_detected(struct pci_dev *pdev,case pci_channel_io_frozen:dev_warn (dev->ctrl.device,"frozen state error detected, reset controller\n" ); -nvme_dev_disable (dev, false); +nvme_dev_disable (dev, false, true);return PCI_ERS_RESULT_NEED_RESET ;case pci_channel_io_perm_failure: dev_warn(dev->ctrl.device,
Signature · 1 line
2.9.5
PATCH v6 7/11 nvme: pci: prepare for supporting error recovery from resetting context
In reply to Ming LeiEither the admin or normal IO in reset context may be timed out because controller error happens. When this timeout happens, we may have to start controller recovery again.
This patch introduces 'reset_lock' and holds this lock when running reset, so that we may support nested reset in the following patches.
--- drivers/nvme/host/core.c | 2 ++ drivers/nvme/host/nvme.h | 3 +++ drivers/nvme/host/pci.c | 20 +++++++++++++++++--- 3 files changed, 22 insertions(+), 3 deletions(-)
drivers/nvme/host/core.c +2 -0
@@ -3430,6 +3430,8 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,INIT_WORK (&ctrl->fw_act_work, nvme_fw_act_work);INIT_WORK (&ctrl->delete_work, nvme_delete_ctrl_work); +mutex_init (&ctrl->reset_lock); + ret =ida_simple_get (&nvme_instance_ida,0 ,0 ,GFP_KERNEL );if (ret <0 ) goto out;
drivers/nvme/host/nvme.h +3 -0
@@ -151,6 +151,9 @@ struct nvme_ctrl {struct device ctrl_device;struct device *device;/* char device */ struct cdev cdev; + +/* sync reset activities */ +struct mutex reset_lock;struct work_struct reset_work;struct work_struct delete_work;
drivers/nvme/host/pci.c +17 -3
@@ -2391,14 +2391,14 @@ static void nvme_remove_dead_ctrl(struct nvme_dev *dev, int status)nvme_put_ctrl (&dev->ctrl); } -static void nvme_reset_work (struct work_struct *work) +static void nvme_reset_dev (struct nvme_dev *dev) { -struct nvme_dev *dev = - container_of(work, struct nvme_dev, ctrl.reset_work);bool was_suspend = !!(dev->ctrl.ctrl_config &NVME_CC_SHN_NORMAL );int result = -ENODEV ;enum nvme_ctrl_state new_state =NVME_CTRL_LIVE ; +lockdep_assert_held (&dev->ctrl.reset_lock); +if (WARN_ON (dev->ctrl.state !=NVME_CTRL_RESETTING )) goto out;
@@ -2474,7 +2474,11 @@ static void nvme_reset_work(struct work_struct *work) new_state =NVME_CTRL_ADMIN_ONLY ; }else {nvme_start_queues (&dev->ctrl); +mutex_unlock (&dev->ctrl.reset_lock); +nvme_wait_freeze (&dev->ctrl); + +mutex_lock (&dev->ctrl.reset_lock);/* hit this only when allocate tagset fails */ if (nvme_dev_add (dev)) new_state =NVME_CTRL_ADMIN_ONLY ;
@@ -2498,6 +2502,16 @@ static void nvme_reset_work(struct work_struct *work)nvme_remove_dead_ctrl (dev, result); } +static void nvme_reset_work (struct work_struct *work) +{ +struct nvme_dev *dev = + container_of(work, struct nvme_dev, ctrl.reset_work); + +mutex_lock (&dev->ctrl.reset_lock); +nvme_reset_dev (dev); +mutex_unlock (&dev->ctrl.reset_lock); +} +static void nvme_remove_dead_ctrl_work (struct work_struct *work) { struct nvme_dev *dev = container_of(work, struct nvme_dev, remove_work);
Signature · 1 line
2.9.5
PATCH v6 8/11 nvme: pci: move error handling out of nvme_reset_dev()
In reply to Ming LeiOnce nested EH is introduced, we may not need to handle error in the inner EH, so move error handling out of nvme_reset_dev().
Meantime return the reset result to caller.
--- drivers/nvme/host/pci.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/nvme/host/pci.c +8 -4
@@ -2391,7 +2391,7 @@ static void nvme_remove_dead_ctrl(struct nvme_dev *dev, int status)nvme_put_ctrl (&dev->ctrl); } -static void nvme_reset_dev (struct nvme_dev *dev) +static int nvme_reset_dev (struct nvme_dev *dev) {bool was_suspend = !!(dev->ctrl.ctrl_config &NVME_CC_SHN_NORMAL );int result = -ENODEV ;
@@ -2485,6 +2485,7 @@ static void nvme_reset_dev(struct nvme_dev *dev)nvme_unfreeze (&dev->ctrl); } + result = -ENODEV ;/* * If only admin queue live, keep it to do further investigation or * recovery.
@@ -2496,19 +2497,22 @@ static void nvme_reset_dev(struct nvme_dev *dev) }nvme_start_ctrl (&dev->ctrl); -return ; +return 0 ; out: -nvme_remove_dead_ctrl (dev, result); +return result; }static void nvme_reset_work (struct work_struct *work) {struct nvme_dev *dev = container_of(work, struct nvme_dev, ctrl.reset_work); +int result;mutex_lock (&dev->ctrl.reset_lock); -nvme_reset_dev (dev); + result =nvme_reset_dev (dev); +if (result) +nvme_remove_dead_ctrl (dev, result);mutex_unlock (&dev->ctrl.reset_lock); }
Signature · 1 line
2.9.5
PATCH v6 9/11 nvme: pci: don't unfreeze queue until controller state updating succeeds
In reply to Ming LeiIf it fails to update controller state into LIVE or ADMIN_ONLY, the controller will be removed, so not necessary to unfreeze queue any more.
This way will make the following patch easier to not leak the freeze couner.
--- drivers/nvme/host/pci.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/nvme/host/pci.c +5 -1
@@ -2396,6 +2396,7 @@ static int nvme_reset_dev(struct nvme_dev *dev)bool was_suspend = !!(dev->ctrl.ctrl_config &NVME_CC_SHN_NORMAL );int result = -ENODEV ;enum nvme_ctrl_state new_state =NVME_CTRL_LIVE ; +bool unfreeze_queue = false;lockdep_assert_held (&dev->ctrl.reset_lock);
@@ -2482,7 +2483,7 @@ static int nvme_reset_dev(struct nvme_dev *dev)/* hit this only when allocate tagset fails */ if (nvme_dev_add (dev)) new_state =NVME_CTRL_ADMIN_ONLY ; -nvme_unfreeze (&dev->ctrl); + unfreeze_queue = true; } result = -ENODEV ;
@@ -2497,6 +2498,9 @@ static int nvme_reset_dev(struct nvme_dev *dev) }nvme_start_ctrl (&dev->ctrl); + +if (unfreeze_queue) +nvme_unfreeze (&dev->ctrl);return 0 ; out:
Signature · 1 line
2.9.5
PATCH v6 10/11 nvme: core: introduce nvme_force_change_ctrl_state()
In reply to Ming LeiWhen controller is being reset, timeout still may be triggered, for handling this situation, the contoller state has to be changed to NVME_CTRL_RESETTING first.
So introduce nvme_force_change_ctrl_state() for this purpose.
--- drivers/nvme/host/core.c | 33 +++++++++++++++++++++++++++++++++ drivers/nvme/host/nvme.h | 2 ++ 2 files changed, 35 insertions(+)
drivers/nvme/host/core.c +33 -0
@@ -256,6 +256,39 @@ void nvme_cancel_request(struct request *req, void *data, bool reserved) }EXPORT_SYMBOL_GPL (nvme_cancel_request); +/* should only be used by EH for handling error during reset */ +void nvme_force_change_ctrl_state (struct nvme_ctrl *ctrl, +enum nvme_ctrl_state new_state) +{ +enum nvme_ctrl_state old_state; +unsigned long flags; +bool warn = true; + +spin_lock_irqsave (&ctrl->lock, flags); + old_state = ctrl->state; +switch (new_state) { +case NVME_CTRL_RESETTING : +switch (old_state) { +case NVME_CTRL_LIVE : +case NVME_CTRL_ADMIN_ONLY : +case NVME_CTRL_RESETTING : +case NVME_CTRL_CONNECTING : + warn = false; +break ; +default : +break ; + } +default : +break ; + } +if (warn) +WARN (1 ,"Make sure you want to change to %d from %d\n" , + new_state, old_state); + ctrl->state = new_state; +spin_unlock_irqrestore (&ctrl->lock, flags); +} +EXPORT_SYMBOL_GPL (nvme_force_change_ctrl_state); +bool nvme_change_ctrl_state (struct nvme_ctrl *ctrl,enum nvme_ctrl_state new_state) {
drivers/nvme/host/nvme.h +2 -0
@@ -390,6 +390,8 @@ void nvme_complete_rq(struct request *req);void nvme_cancel_request (struct request *req,void *data,bool reserved);bool nvme_change_ctrl_state (struct nvme_ctrl *ctrl,enum nvme_ctrl_state new_state); +void nvme_force_change_ctrl_state (struct nvme_ctrl *ctrl, +enum nvme_ctrl_state new_state);int nvme_disable_ctrl (struct nvme_ctrl *ctrl,u64 cap);int nvme_enable_ctrl (struct nvme_ctrl *ctrl,u64 cap);int nvme_shutdown_ctrl (struct nvme_ctrl *ctrl);
Signature · 1 line
2.9.5
PATCH v6 11/11 nvme: pci: support nested EH
In reply to Ming LeiWhen one req is timed out, now nvme_timeout() handles it by the following way:
nvme_dev_disable(dev, false); nvme_reset_ctrl(&dev->ctrl); return BLK_EH_HANDLED.
There are several issues about the above approach:
1) IO may fail during resetting
Admin IO timeout may be triggered in nvme_reset_dev() when error happens. Normal IO timeout may be triggered too during nvme_wait_freeze() in reset path. When the two kinds of timeout happen, the current reset mechanism can't work any more.
2) race between nvme_start_freeze and nvme_wait_freeze() & nvme_unfreeze()
- nvme_dev_disable() and resetting controller are required for recovering controller, but the two are run from different contexts. nvme_start_freeze() is call from nvme_dev_disable() which is run timeout work context, and nvme_unfreeze() is run from reset work context. Unfortunatley timeout may be triggered during resetting controller, so nvme_start_freeze() may be run several times.
- Also two reset work may run one by one, this may cause hang in nvme_wait_freeze() forever too.
3) all namespace's EH require to shutdown & reset the controller
block's timeout handler is per-request-queue, that means each namespace's error handling may shutdown & reset the whole controller, then the shutdown from one namespace may quiese queues when resetting from another namespace is in-progress.
This patch fixes the above issues by using nested EH:
1) run controller shutdown(nvme_dev_disable()) and resetting(nvme_reset_dev) from one same EH context, so the above race 2) can be fixed easily.
2) always start a new context for handling EH, and cancel all in-flight requests(include the timed-out ones) in nvme_dev_disable() by quiescing timeout event before shutdown controller.
3) limit the max number of nested EH, when the limit is reached, removes the controller and fails all in-flight request.
With this approach, blktest block/011 can be passed.
--- drivers/nvme/host/core.c | 22 +++++ drivers/nvme/host/nvme.h | 2 + drivers/nvme/host/pci.c | 252 +++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 256 insertions(+), 20 deletions(-)
drivers/nvme/host/core.c +22 -0
@@ -3587,6 +3587,28 @@ void nvme_start_freeze(struct nvme_ctrl *ctrl) }EXPORT_SYMBOL_GPL (nvme_start_freeze); +void nvme_unquiesce_timeout (struct nvme_ctrl *ctrl) +{ +struct nvme_ns *ns; + +down_read (&ctrl->namespaces_rwsem); +list_for_each_entry (ns, &ctrl->namespaces, list) +blk_unquiesce_timeout (ns->queue); +up_read (&ctrl->namespaces_rwsem); +} +EXPORT_SYMBOL_GPL (nvme_unquiesce_timeout); + +void nvme_quiesce_timeout (struct nvme_ctrl *ctrl) +{ +struct nvme_ns *ns; + +down_read (&ctrl->namespaces_rwsem); +list_for_each_entry (ns, &ctrl->namespaces, list) +blk_quiesce_timeout (ns->queue); +up_read (&ctrl->namespaces_rwsem); +} +EXPORT_SYMBOL_GPL (nvme_quiesce_timeout); +void nvme_stop_queues (struct nvme_ctrl *ctrl) {struct nvme_ns *ns;
drivers/nvme/host/nvme.h +2 -0
@@ -412,6 +412,8 @@ int nvme_sec_submit(void *data, u16 spsp, u8 secp, void *buffer, size_t len,void nvme_complete_async_event (struct nvme_ctrl *ctrl,__le16 status,union nvme_result *res); +void nvme_unquiesce_timeout (struct nvme_ctrl *ctrl); +void nvme_quiesce_timeout (struct nvme_ctrl *ctrl);void nvme_stop_queues (struct nvme_ctrl *ctrl);void nvme_start_queues (struct nvme_ctrl *ctrl);void nvme_kill_queues (struct nvme_ctrl *ctrl);
drivers/nvme/host/pci.c +232 -20
342 lines not on this page · raw message
Signature · 1 line
2.9.5
Re: [PATCH V6 11/11] nvme: pci: support nested EH
Hi Ming,
I'm sorry, but I am frankly not on board with introducing yet another work-queue into this driver for handling this situation. The fact you missed syncing with this queue in the surprise remove case, introducing various use-after-free conditions, just demonstrates exactly how over-complicated this approach is. That, and the forced controller state transtions is yet another way surprise removal will break as its depending on the state machine to prevent certain transitions.
The driver is already in a work queue context when it becomes aware of corrective action being necessary. Seriously, simply syncing these in the reset convers nearly all conditions you're concered with, most of which will be obviated if Bart's blk-mq timeout rework is added. The only case that isn't covered is if IO stops when renumbering the hardware contexts (unlikely as that is), and that's easily fixable just moving that into the scan_work.
As far as blktests block/011 is concerned, I think this needs to be rethought considering what it's actually showing us. The fact the pci driver provides such an easy way to not only muck with PCI config register *and* internal kernel structures out from under a driver that's bound to it is insane. If PCI really wants to provide this sysfs entry, it really ought to notify bound drivers that this is occuring, similar to the 'reset' sysfs.
Anyway, there is merit to some of your earlier patches. In particular, specifically patches 2, 4, and 5. On the timing out the host memory releasing (patch 2), I would just rather see this as a generic API, though:
http://lists.infradead.org/pipermail/linux-nvme/2018-January/015313.html
http://lists.infradead.org/pipermail/linux-nvme/2018-January/015314.html
Re: [PATCH V6 11/11] nvme: pci: support nested EH
Hi Keith,
Quoted 6 lines · Keith Busch
Hi Ming,
I'm sorry, but I am frankly not on board with introducing yet another work-queue into this driver for handling this situation. The fact you missed syncing with this queue in the surprise remove case, introducing various use-after-free conditions, just demonstrates exactly
blk_cleanup_queue() will drain all requests, and all the timeout activities will be quiesced, so could you explain what the use-after-free conditions are? Also we can wait on 'eh_wq' simply until dev->nested_eh becomes zero before removing 'nvme_dev'.
Quoted 1 line
how over-complicated this approach is. That, and the forced controller
Now we run controller shutdown and resetting in different contests, which has caused big trouble, kinds of IO hang:
https://marc.info/?l=linux-block&m=152644353006033&w=2
This patch moves the two into one same context, it is really a simplification for avoiding IO hang which is caused by race between starting freeze and nvme_wait_freeze(), which two are run from different contexts now.
The sync between all EH contexts looks a bit complicated, but eh_wq is introduced to sync until the recovery is done for all EHs.
So the new EH model isn't complicated.
I hope all these issues can be fixed, but open to any soluiton, unfortunately not see any workable way yet, except for this patchset.
Quoted 2 lines
state transtions is yet another way surprise removal will break as its depending on the state machine to prevent certain transitions.
We can limit the transtions in nvme_force_change_ctrl_state() too, that can be documented well.
Quoted 3 lines
The driver is already in a work queue context when it becomes aware of corrective action being necessary. Seriously, simply syncing these in the
Yeah, it is in reset work func, which is part of recovery, but either admin or normal IO can be timed-out in this context too, that is why I introduces new work to cover this case.
I think we have to handle the issue of IO time-out during reset.
In block/011 test, it can be observed easily that the 3rd EH is started to recover the whole failure, and finally it succeeds.
Quoted 1 line
reset convers nearly all conditions you're concered with, most of which
I believe I have explained it to you, that isn't enough:
https://marc.info/?l=linux-block&m=152599770314638&w=2
https://marc.info/?l=linux-block&m=152598984210852&w=2
https://marc.info/?l=linux-block&m=152598664409170&w=2
Quoted 4 lines
will be obviated if Bart's blk-mq timeout rework is added. The only case that isn't covered is if IO stops when renumbering the hardware contexts (unlikely as that is), and that's easily fixable just moving that into the
scan_work.
How can Bart's patch cover multiple NS's case? Timeout from multiple NS still can come at the same time.
Quoted 8 lines
As far as blktests block/011 is concerned, I think this needs to be rethought considering what it's actually showing us. The fact the pci driver provides such an easy way to not only muck with PCI config register *and* internal kernel structures out from under a driver that's bound to it is insane. If PCI really wants to provide this sysfs entry, it really ought to notify bound drivers that this is occuring, similar to the 'reset' sysfs.
All simulation in block/011 may happen in reality.
When one IO is timed out, IO dispatched during resetting can be timed-out too.
Unfortunately current NVMe driver can't handle that and the reset work will hang forever. I don't believe it is a good way as EH.
Quoted 8 lines
Anyway, there is merit to some of your earlier patches. In particular, specifically patches 2, 4, and 5. On the timing out the host memory releasing (patch 2), I would just rather see this as a generic API, though:
http://lists.infradead.org/pipermail/linux-nvme/2018-January/015313.html
http://lists.infradead.org/pipermail/linux-nvme/2018-January/015314.html
The generic API may not be necessary, since it is only needed when it is called in nvme_dev_disable(), but it is still better to have this API.
Except above, you ignore one big source of IO hang, that is the race between starting freeze & blk_mq_freeze_queue_wait().
- nvme_dev_disable() and resetting controller are required for recovering controller, but the two are run from different contexts. nvme_start_freeze() is call from nvme_dev_disable() which is run timeout work context, and nvme_unfreeze() is run from reset work context. Unfortunatley timeout may be triggered during resetting controller, so nvme_start_freeze() may be run several times.
- Also two reset work may run one by one, this may cause hang in nvme_wait_freeze() forever too.
In short, I'd see all these issues described in the following commit log can be fixed:
https://marc.info/?l=linux-block&m=152644353006033&w=2
If you think there are better ways, let's talk in code. Again, I am open to any solution.
Thanks,
Ming
Re: [PATCH V6 11/11] nvme: pci: support nested EH
Hi Ming,
I'm developing the answers in code the issues you raised. It will just take a moment to complete flushing those out. In the meantime just want to point out why I think block/011 isn't a real test.
Quoted 1 line · Ming Lei
All simulation in block/011 may happen in reality.
If this test actually simulates reality, then the following one line patch (plus explanation for why) would be a real "fix" as this is very successful in passing block/011. :)
---
drivers/nvme/host/pci.c +6 -1
@@ -2118,6 +2118,12 @@ static int nvme_pci_enable(struct nvme_dev *dev)if (pci_enable_device_mem (pdev))return result; +/* +* blktests block/011 disables the device without the driver knowing. +* We'll just enable the device twice to get the enable_cnt > 1 +* so that the test's disabling does absolutely nothing. +*/ +pci_enable_device_mem (pdev);pci_set_master (pdev); --
Christoph Hellwig
maintainerRe: [PATCH V6 11/11] nvme: pci: support nested EH
Quoted 13 lines · Keith Busch
Quoted 1 line · Ming Lei
All simulation in block/011 may happen in reality.
If this test actually simulates reality, then the following one line patch (plus explanation for why) would be a real "fix" as this is very successful in passing block/011. :)
---
drivers/nvme/host/pci.c +0
-0
drivers/nvme/host/pci.c static int nvme_pci_enable(struct nvme_dev *dev) · line 2126
Quoted 9 lines
drivers/nvme/host/pci.c +6
-0@@ -2118,6 +2118,12 @@ static int nvme_pci_enable(struct nvme_dev *dev)if (pci_enable_device_mem (pdev))return result; +/* +* blktests block/011 disables the device without the driver knowing. +* We'll just enable the device twice to get the enable_cnt > 1 +* so that the test's disabling does absolutely nothing. +*/ +pci_enable_device_mem (pdev);
Heh. But yes, this test and the PCI "enable" interface in sysfs look horribly wrong. pci_disable_device/pci_enable_device aren't something we can just do underneath the driver. Even if injecting the lowlevel config space manipulations done by it might be useful and a good test the Linux state ones are just killing the driver.
The enable attribute appears to have been added by Arjan for the Xorg driver. I think if we have a driver bound to the device we should not allow it.
Re: [PATCH V6 11/11] nvme: pci: support nested EH
Quoted 15 lines · Christoph Hellwig
Quoted 14 lines · Keith Busch
Quoted 1 line · Ming Lei
All simulation in block/011 may happen in reality.
If this test actually simulates reality, then the following one line patch (plus explanation for why) would be a real "fix" as this is very successful in passing block/011. :)
---
drivers/nvme/host/pci.c +0
-0@@ -2118,6 +2118,12 @@ static int nvme_pci_enable(struct nvme_dev *dev)
Quoted 14 lines
drivers/nvme/host/pci.c static int nvme_pci_enable(struct nvme_dev *dev) · line 2126
Quoted 8 lines
drivers/nvme/host/pci.c +6
-0if (pci_enable_device_mem (pdev))return result; +/* +* blktests block/011 disables the device without the driver knowing. +* We'll just enable the device twice to get the enable_cnt > 1 +* so that the test's disabling does absolutely nothing. +*/ +pci_enable_device_mem (pdev);Heh. But yes, this test and the PCI "enable" interface in sysfs look horribly wrong. pci_disable_device/pci_enable_device aren't something we can just do underneath the driver. Even if injecting the lowlevel config space manipulations done by it might be useful and a good test the Linux state ones are just killing the driver.
Yes, I'm totally fine with injecting errors into the config space, but for goodness sakes, don't fuck with the internal kernel structures out from under drivers using them.
My suggestion is to use 'setpci' to disable the device if you want to inject this scenario. That way you get the desired broken device scenario you want to test, but struct pci_dev hasn't been altered.
Quoted 3 lines
The enable attribute appears to have been added by Arjan for the Xorg driver. I think if we have a driver bound to the device we should not allow it.
Agreed. Alternatively possibly call the driver's reset_preparei/done callbacks.
Re: [PATCH V6 11/11] nvme: pci: support nested EH
Quoted 14 lines · Keith Busch
Quoted 5 lines
Heh. But yes, this test and the PCI "enable" interface in sysfs look horribly wrong. pci_disable_device/pci_enable_device aren't something we can just do underneath the driver. Even if injecting the lowlevel config space manipulations done by it might be useful and a good test the Linux state ones are just killing the driver.
Yes, I'm totally fine with injecting errors into the config space, but for goodness sakes, don't fuck with the internal kernel structures out from under drivers using them.
My suggestion is to use 'setpci' to disable the device if you want to inject this scenario. That way you get the desired broken device scenario you want to test, but struct
pci_devhasn't been altered.
Quoted 6 lines
Quoted 3 lines
The enable attribute appears to have been added by Arjan for the Xorg driver. I think if we have a driver bound to the device we should not allow it.
Agreed. Alternatively possibly call the driver's reset_preparei/done callbacks.
Exactly, but as long as we can issue the reset via sysfs the test-case is still valid.
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: Felix Imend�rffer, Jane Smithard, Graham Norton HRB 21284 (AG N�rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH V6 11/11] nvme: pci: support nested EH
Quoted 5 lines · Johannes Thumshirn
Quoted 2 lines
Agreed. Alternatively possibly call the driver's reset_preparei/done callbacks.
Exactly, but as long as we can issue the reset via sysfs the test-case is still valid.
I disagree the test case is valid. The test writes '0' to the pci-sysfs 'enable', but the driver also disables the pci device as part of resetting, which is a perfectly reasonable thing for a driver to do.
If the timing of the test's loop happens to write '0' right after the driver disabled the device that it owns, a 'write error' on that sysfs write occurs, and blktests then incorrectly claims the test failed.
Re: [PATCH V6 11/11] nvme: pci: support nested EH
Quoted 7 lines · Keith Busch
Quoted 5 lines · Johannes Thumshirn
Quoted 2 lines
Agreed. Alternatively possibly call the driver's reset_preparei/done callbacks.
Exactly, but as long as we can issue the reset via sysfs the test-case is still valid.
Quoted 7 lines
I disagree the test case is valid. The test writes '0' to the pci-sysfs 'enable', but the driver also disables the pci device as part of resetting, which is a perfectly reasonable thing for a driver to do.
If the timing of the test's loop happens to write '0' right after the driver disabled the device that it owns, a 'write error' on that sysfs write occurs, and blktests then incorrectly claims the test failed.
Hmm, ok that's a valid point. But seeing you have sent a patch for blktests anyways I think it's gone now.
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: Felix Imend�rffer, Jane Smithard, Graham Norton HRB 21284 (AG N�rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH V6 11/11] nvme: pci: support nested EH
In reply to Keith BuschQuoted 19 lines · Keith Busch
Hi Ming,
I'm developing the answers in code the issues you raised. It will just take a moment to complete flushing those out. In the meantime just want to point out why I think block/011 isn't a real test.
Quoted 1 line · Ming Lei
All simulation in block/011 may happen in reality.
If this test actually simulates reality, then the following one line patch (plus explanation for why) would be a real "fix" as this is very successful in passing block/011. :)
---
drivers/nvme/host/pci.c +0
-0
drivers/nvme/host/pci.c static int nvme_pci_enable(struct nvme_dev *dev) · line 2126
Quoted 9 lines
drivers/nvme/host/pci.c +6
-0@@ -2118,6 +2118,12 @@ static int nvme_pci_enable(struct nvme_dev *dev)if (pci_enable_device_mem (pdev))return result; +/* +* blktests block/011 disables the device without the driver knowing. +* We'll just enable the device twice to get the enable_cnt > 1 +* so that the test's disabling does absolutely nothing. +*/ +pci_enable_device_mem (pdev);
What I think block/011 is helpful is that it can trigger IO timeout during reset, which can be triggered in reality too.
That is one big problem of NVMe driver, IMO.
And this patch does fix this issue, together other timeout related races.
Thanks,
Ming
Re: [PATCH V6 11/11] nvme: pci: support nested EH
Quoted 33 lines · Ming Lei
Quoted 19 lines · Keith Busch
Hi Ming,
I'm developing the answers in code the issues you raised. It will just take a moment to complete flushing those out. In the meantime just want to point out why I think block/011 isn't a real test.
Quoted 1 line · Ming Lei
All simulation in block/011 may happen in reality.
If this test actually simulates reality, then the following one line patch (plus explanation for why) would be a real "fix" as this is very successful in passing block/011. :)
---
drivers/nvme/host/pci.c +0
-0drivers/nvme/host/pci.c static int nvme_pci_enable(struct nvme_dev *dev) · line 2126
Quoted 9 lines
drivers/nvme/host/pci.c +6
-0@@ -2118,6 +2118,12 @@ static int nvme_pci_enable(struct nvme_dev *dev)if (pci_enable_device_mem (pdev))return result; +/* +* blktests block/011 disables the device without the driver knowing. +* We'll just enable the device twice to get the enable_cnt > 1 +* so that the test's disabling does absolutely nothing. +*/ +pci_enable_device_mem (pdev);What I think block/011 is helpful is that it can trigger IO timeout during reset, which can be triggered in reality too.
Quoted 4 lines
That is one big problem of NVMe driver, IMO.
And this patch does fix this issue, together other timeout related races.
BTW, the above patch may not be enough to 'fix' this NVMe issue, I guess you may have to figure out another one to remove fault-injection, or at least disable io-timeout-fail on NVMe.
Thanks,
Ming
Re: [PATCH V6 11/11] nvme: pci: support nested EH
In reply to Ming LeiQuoted 2 lines · Ming Lei
What I think block/011 is helpful is that it can trigger IO timeout during reset, which can be triggered in reality too.
As I mentioned earlier, there is nothing wrong with the spirit of the test. What's wrong with it is the misguided implemention.
Do you underestand why it ever passes? The success happens when the enabling part of the loop happens to coincide with the driver's enabling, creating the pci_dev->enable_cnt > 1, making subsequent disable parts of the loop do absolutely nothing; the exact same as the one-liner (non-serious) patch I sent to defeat the test.
A better way to induce the timeout is:
# setpci -s <B:D.f> 4.w=0:6
This will halt the device without messing with the kernel structures, just like how a real device failure would occur.
Jens Axboe
maintainerRe: [PATCH V6 11/11] nvme: pci: support nested EH
Quoted 13 lines · Keith Busch
Quoted 2 lines · Ming Lei
What I think block/011 is helpful is that it can trigger IO timeout during reset, which can be triggered in reality too.
As I mentioned earlier, there is nothing wrong with the spirit of the test. What's wrong with it is the misguided implemention.
Do you underestand why it ever passes? The success happens when the enabling part of the loop happens to coincide with the driver's enabling, creating the
pci_dev->enable_cnt> 1, making subsequent disable parts of the loop do absolutely nothing; the exact same as the one-liner (non-serious) patch I sent to defeat the test.
Quoted 6 lines
A better way to induce the timeout is:
# setpci -s <B:D.f> 4.w=0:6This will halt the device without messing with the kernel structures, just like how a real device failure would occur.
Let's just improve/fix the test case. Sounds like the 'enable' sysfs attribute should never have been exported, and hence the test should never have used it. blktests is not the source of truth, necessarily, and it would be silly to work around cases in the kernel if it's a clear case of "doctor it hurts when I shoot myself in the foot".
Signature · 1 line
Jens Axboe
Re: [PATCH V6 11/11] nvme: pci: support nested EH
In reply to Keith BuschQuoted 13 lines · Keith Busch
Quoted 2 lines · Ming Lei
What I think block/011 is helpful is that it can trigger IO timeout during reset, which can be triggered in reality too.
As I mentioned earlier, there is nothing wrong with the spirit of the test. What's wrong with it is the misguided implemention.
Do you underestand why it ever passes? The success happens when the enabling part of the loop happens to coincide with the driver's enabling, creating the
pci_dev->enable_cnt> 1, making subsequent disable parts of the loop do absolutely nothing; the exact same as the one-liner (non-serious) patch I sent to defeat the test.
Quoted 6 lines
A better way to induce the timeout is:
# setpci -s <B:D.f> 4.w=0:6This will halt the device without messing with the kernel structures, just like how a real device failure would occur.
Frankly speaking, I don't care how the test-case is implemented at all.
The big problem is that NVMe driver can't handle IO time-out during reset context, and finally either the controller becomes DEAD or reset context hangs forever, and everything can't move on.
The issue can be reproduced easier via io-timeout-fail fault injection.
So could we please face to the real issue instead of working around test case?
Thanks,
Ming
Re: [PATCH V6 11/11] nvme: pci: support nested EH
Quoted 2 lines · Ming Lei
So could we please face to the real issue instead of working around test case?
Yes, that's why I want you to stop referencing the broken test.
Re: [PATCH V6 11/11] nvme: pci: support nested EH
Quoted 5 lines · Keith Busch
Quoted 2 lines · Ming Lei
So could we please face to the real issue instead of working around test case?
Yes, that's why I want you to stop referencing the broken test.
Unfortunately I don't care if it is broken or not, and I think the test case is great because it can expose the real problem. That is its value!
The reason why I referenced this test is that everyone can reproduce this real issue easily, that is it.
Thanks,
Ming