Skip to contentSkip to conversation

BLK_EH_HANDLED

PATCH In review Christoph Hellwig 5 participants 39 messages May 23, 2018 – May 29, 2018

Subsystems (14)
lore
Share & tools
lore

Christoph Hellwig

author maintainer
#0 lore raw

Hi all,

this series removes the BLK_EH_HANDLED return value, and instead places responsibility of timed out commands entirely on the drivers. Except for some odd layering vilations in libiscsi this actually is surprisingly simple. The last two pathes contain a respin of Keith' series to refcount struct request in the eye of timeouts. Once the BLK_EH_HANDLED special case is gone this actually seems the EH fixing approach that seems the most sensible to me.

author maintainer
#1 lore raw

PATCH 1/14 libata: remove ata_scsi_timed_out

As far as I can tell this function can't even be called any more, given that ATA implements its own eh_strategy_handler with ata_scsi_error, which never calls ->eh_timed_out.

---
 drivers/ata/libata-eh.c | 51 -----------------------------------------
 include/linux/libata.h  |  2 --
 2 files changed, 53 deletions(-)
drivers/ata/libata-eh.c +0 -51
index c016829a38fd..e87785dec151 100644
@@ -500,57 +500,6 @@ void ata_eh_release(struct ata_port *ap)
 	mutex_unlock(&ap->host->eh_mutex);
 }
 
-/**
- *	ata_scsi_timed_out - SCSI layer time out callback
- *	@cmd: timed out SCSI command
- *
- *	Handles SCSI layer timeout.  We race with normal completion of
- *	the qc for @cmd.  If the qc is already gone, we lose and let
- *	the scsi command finish (EH_HANDLED).  Otherwise, the qc has
- *	timed out and EH should be invoked.  Prevent ata_qc_complete()
- *	from finishing it by setting EH_SCHEDULED and return
- *	EH_NOT_HANDLED.
- *
- *	TODO: kill this function once old EH is gone.
- *
- *	LOCKING:
- *	Called from timer context
- *
- *	RETURNS:
- *	EH_HANDLED or EH_NOT_HANDLED
- */
-enum blk_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
-{
-	struct Scsi_Host *host = cmd->device->host;
-	struct ata_port *ap = ata_shost_to_port(host);
-	unsigned long flags;
-	struct ata_queued_cmd *qc;
-	enum blk_eh_timer_return ret;
-
-	DPRINTK("ENTER\n");
-
-	if (ap->ops->error_handler) {
-		ret = BLK_EH_NOT_HANDLED;
-		goto out;
-	}
-
-	ret = BLK_EH_HANDLED;
-	spin_lock_irqsave(ap->lock, flags);
-	qc = ata_qc_from_tag(ap, ap->link.active_tag);
-	if (qc) {
-		WARN_ON(qc->scsicmd != cmd);
-		qc->flags |= ATA_QCFLAG_EH_SCHEDULED;
-		qc->err_mask |= AC_ERR_TIMEOUT;
-		ret = BLK_EH_NOT_HANDLED;
-	}
-	spin_unlock_irqrestore(ap->lock, flags);
-
- out:
-	DPRINTK("EXIT, ret=%d\n", ret);
-	return ret;
-}
-EXPORT_SYMBOL(ata_scsi_timed_out);
-
 static void ata_eh_unload(struct ata_port *ap)
 {
 	struct ata_link *link;
include/linux/libata.h +0 -2
index 1795fecdea17..1c113134c98f 100644
@@ -1133,7 +1133,6 @@ extern int ata_sas_port_start(struct ata_port *ap);
 extern void ata_sas_port_stop(struct ata_port *ap);
 extern int ata_sas_slave_configure(struct scsi_device *, struct ata_port *);
 extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap);
-extern enum blk_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd);
 extern int sata_scr_valid(struct ata_link *link);
 extern int sata_scr_read(struct ata_link *link, int reg, u32 *val);
 extern int sata_scr_write(struct ata_link *link, int reg, u32 val);
@@ -1359,7 +1358,6 @@ extern struct device_attribute *ata_common_sdev_attrs[];
 	.proc_name		= drv_name,			\
 	.slave_configure	= ata_scsi_slave_config,	\
 	.slave_destroy		= ata_scsi_slave_destroy,	\
-	.eh_timed_out		= ata_scsi_timed_out,		\
 	.bios_param		= ata_std_bios_param,		\
 	.unlock_native_capacity	= ata_scsi_unlock_native_capacity, \
 	.sdev_attrs		= ata_common_sdev_attrs
Signature · 1 line
2.17.0
Reviewed-by on v1 1/14
#2 lore raw

Re: [PATCH 01/14] libata: remove ata_scsi_timed_out

Quoted 10 lines · Christoph Hellwig

As far as I can tell this function can't even be called any more, given that ATA implements its own eh_strategy_handler with ata_scsi_error, which never calls ->eh_timed_out.

---
  drivers/ata/libata-eh.c | 51 -----------------------------------------
  include/linux/libata.h  |  2 --
  2 files changed, 53 deletions(-)

Cheers,

Hannes

author maintainer
#3 lore raw

PATCH 2/14 block: rename BLK_EH_NOT_HANDLED to BLK_EH_DONE

In reply to Christoph Hellwig

The BLK_EH_NOT_HANDLED implies nothing happen, but very often that is not what is happening - instead the driver already completed the command. Fix the symbolic name to reflect that a little better.

---
 Documentation/scsi/scsi_eh.txt            | 4 ++--
 block/blk-mq.c                            | 2 +-
 block/blk-timeout.c                       | 2 +-
 drivers/block/nbd.c                       | 2 +-
 drivers/message/fusion/mptsas.c           | 2 +-
 drivers/s390/block/dasd.c                 | 6 +++---
 drivers/scsi/gdth.c                       | 2 +-
 drivers/scsi/libiscsi.c                   | 2 +-
 drivers/scsi/megaraid/megaraid_sas_base.c | 2 +-
 drivers/scsi/mvumi.c                      | 2 +-
 drivers/scsi/qla4xxx/ql4_os.c             | 2 +-
 drivers/scsi/scsi_error.c                 | 4 ++--
 drivers/scsi/scsi_transport_fc.c          | 4 ++--
 drivers/scsi/scsi_transport_srp.c         | 4 ++--
 drivers/scsi/ufs/ufshcd.c                 | 6 +++---
 include/linux/blkdev.h                    | 2 +-
 include/scsi/scsi_host.h                  | 2 +-
 17 files changed, 25 insertions(+), 25 deletions(-)
Documentation/scsi/scsi_eh.txt +2 -2
index 11e447bdb3a5..3ae8419e72cf 100644
@@ -97,9 +97,9 @@ function
 	This indicates that more time is required to finish the
 	command.  Timer is restarted.  This action is counted as a
 	retry and only allowed scmd->allowed + 1(!) times.  Once the
-	limit is reached, action for BLK_EH_NOT_HANDLED is taken instead.
+	limit is reached, action for BLK_EH_DONE is taken instead.
 
-    - BLK_EH_NOT_HANDLED
+    - BLK_EH_DONE
         eh_timed_out() callback did not handle the command.
 	Step #2 is taken.
 
block/blk-mq.c +1 -1
index df928200b17e..546acc8cb201 100644
@@ -856,7 +856,7 @@ static void blk_mq_rq_timed_out(struct request *req, bool reserved)
 		blk_mq_rq_update_aborted_gstate(req, 0);
 		blk_add_timer(req);
 		break;
-	case BLK_EH_NOT_HANDLED:
+	case BLK_EH_DONE:
 		break;
 	default:
 		printk(KERN_ERR "block: bad eh return: %d\n", ret);
block/blk-timeout.c +1 -1
index 652d4d4d3e97..3c622335811f 100644
@@ -93,7 +93,7 @@ static void blk_rq_timed_out(struct request *req)
 		blk_add_timer(req);
 		blk_clear_rq_complete(req);
 		break;
-	case BLK_EH_NOT_HANDLED:
+	case BLK_EH_DONE:
 		/*
 		 * LLD handles this for now but in the future
 		 * we can send a request msg to abort the command
drivers/block/nbd.c +1 -1
index 1147e4680c80..09d9959287fe 100644
@@ -328,7 +328,7 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
 			}
 			blk_mq_requeue_request(req, true);
 			nbd_config_put(nbd);
-			return BLK_EH_NOT_HANDLED;
+			return BLK_EH_DONE;
 		}
 	} else {
 		dev_err_ratelimited(nbd_to_dev(nbd),
drivers/message/fusion/mptsas.c +1 -1
index 86503f60468f..19a5aa70ecda 100644
@@ -1929,7 +1929,7 @@ static enum blk_eh_timer_return mptsas_eh_timed_out(struct scsi_cmnd *sc)
 	MPT_SCSI_HOST *hd;
 	MPT_ADAPTER   *ioc;
 	VirtDevice    *vdevice;
-	enum blk_eh_timer_return rc = BLK_EH_NOT_HANDLED;
+	enum blk_eh_timer_return rc = BLK_EH_DONE;
 
 	hd = shost_priv(sc->device->host);
 	if (hd == NULL) {
drivers/s390/block/dasd.c +3 -3
index 04143c08bd6e..b0e89ca48a3c 100644
@@ -3053,7 +3053,7 @@ static blk_status_t do_dasd_request(struct blk_mq_hw_ctx *hctx,
  *
  * Return values:
  * BLK_EH_RESET_TIMER if the request should be left running
- * BLK_EH_NOT_HANDLED if the request is handled or terminated
+ * BLK_EH_DONE if the request is handled or terminated
  *		      by the driver.
  */
 enum blk_eh_timer_return dasd_times_out(struct request *req, bool reserved)
@@ -3065,7 +3065,7 @@ enum blk_eh_timer_return dasd_times_out(struct request *req, bool reserved)
 	int rc = 0;
 
 	if (!cqr)
-		return BLK_EH_NOT_HANDLED;
+		return BLK_EH_DONE;
 
 	spin_lock_irqsave(&cqr->dq->lock, flags);
 	device = cqr->startdev ? cqr->startdev : block->base;
@@ -3124,7 +3124,7 @@ enum blk_eh_timer_return dasd_times_out(struct request *req, bool reserved)
 	spin_unlock(&block->queue_lock);
 	spin_unlock_irqrestore(&cqr->dq->lock, flags);
 
-	return rc ? BLK_EH_RESET_TIMER : BLK_EH_NOT_HANDLED;
+	return rc ? BLK_EH_RESET_TIMER : BLK_EH_DONE;
 }
 
 static int dasd_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
drivers/scsi/gdth.c +1 -1
index c35f05c4c6bb..85604795d8ee 100644
@@ -3882,7 +3882,7 @@ static enum blk_eh_timer_return gdth_timed_out(struct scsi_cmnd *scp)
 	struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
 	u8 b, t;
 	unsigned long flags;
-	enum blk_eh_timer_return retval = BLK_EH_NOT_HANDLED;
+	enum blk_eh_timer_return retval = BLK_EH_DONE;
 
 	TRACE(("%s() cmd 0x%x\n", scp->cmnd[0], __func__));
 	b = scp->device->channel;
drivers/scsi/libiscsi.c +1 -1
index 15a2fef51e38..eee43ba83a60 100644
@@ -1963,7 +1963,7 @@ static int iscsi_has_ping_timed_out(struct iscsi_conn *conn)
 
 enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc)
 {
-	enum blk_eh_timer_return rc = BLK_EH_NOT_HANDLED;
+	enum blk_eh_timer_return rc = BLK_EH_DONE;
 	struct iscsi_task *task = NULL, *running_task;
 	struct iscsi_cls_session *cls_session;
 	struct iscsi_session *session;
drivers/scsi/megaraid/megaraid_sas_base.c +1 -1
index b89c6e6c0589..ce656c466ca9 100644
@@ -2772,7 +2772,7 @@ blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd)
 
 	if (time_after(jiffies, scmd->jiffies_at_alloc +
 				(scmd_timeout * 2) * HZ)) {
-		return BLK_EH_NOT_HANDLED;
+		return BLK_EH_DONE;
 	}
 
 	instance = (struct megasas_instance *)scmd->device->host->hostdata;
drivers/scsi/mvumi.c +1 -1
index fe97401ad192..afd27165cd93 100644
@@ -2155,7 +2155,7 @@ static enum blk_eh_timer_return mvumi_timed_out(struct scsi_cmnd *scmd)
 	mvumi_return_cmd(mhba, cmd);
 	spin_unlock_irqrestore(mhba->shost->host_lock, flags);
 
-	return BLK_EH_NOT_HANDLED;
+	return BLK_EH_DONE;
 }
 
 static int
drivers/scsi/qla4xxx/ql4_os.c +1 -1
index 94c14ce94da2..0e13349dce57 100644
@@ -1848,7 +1848,7 @@ static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
 	struct iscsi_cls_session *session;
 	struct iscsi_session *sess;
 	unsigned long flags;
-	enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
+	enum blk_eh_timer_return ret = BLK_EH_DONE;
 
 	session = starget_to_session(scsi_target(sc->device));
 	sess = session->dd_data;
drivers/scsi/scsi_error.c +2 -2
index b36e73090018..9c02ba2e7ef3 100644
@@ -282,7 +282,7 @@ void scsi_eh_scmd_add(struct scsi_cmnd *scmd)
 enum blk_eh_timer_return scsi_times_out(struct request *req)
 {
 	struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(req);
-	enum blk_eh_timer_return rtn = BLK_EH_NOT_HANDLED;
+	enum blk_eh_timer_return rtn = BLK_EH_DONE;
 	struct Scsi_Host *host = scmd->device->host;
 
 	trace_scsi_dispatch_cmd_timeout(scmd);
@@ -294,7 +294,7 @@ enum blk_eh_timer_return scsi_times_out(struct request *req)
 	if (host->hostt->eh_timed_out)
 		rtn = host->hostt->eh_timed_out(scmd);
 
-	if (rtn == BLK_EH_NOT_HANDLED) {
+	if (rtn == BLK_EH_DONE) {
 		if (scsi_abort_command(scmd) != SUCCESS) {
 			set_host_byte(scmd, DID_TIME_OUT);
 			scsi_eh_scmd_add(scmd);
drivers/scsi/scsi_transport_fc.c +2 -2
index be3be0f9cb2d..90075a0ddcfe 100644
@@ -2087,7 +2087,7 @@ fc_eh_timed_out(struct scsi_cmnd *scmd)
 	if (rport->port_state == FC_PORTSTATE_BLOCKED)
 		return BLK_EH_RESET_TIMER;
 
-	return BLK_EH_NOT_HANDLED;
+	return BLK_EH_DONE;
 }
 EXPORT_SYMBOL(fc_eh_timed_out);
 
@@ -3592,7 +3592,7 @@ fc_bsg_job_timeout(struct request *req)
 
 	/* the blk_end_sync_io() doesn't check the error */
 	if (!inflight)
-		return BLK_EH_NOT_HANDLED;
+		return BLK_EH_DONE;
 	else
 		return BLK_EH_HANDLED;
 }
drivers/scsi/scsi_transport_srp.c +2 -2
index 36f6190931bc..a9c1c991da35 100644
@@ -587,7 +587,7 @@ EXPORT_SYMBOL(srp_reconnect_rport);
  *
  * If a timeout occurs while an rport is in the blocked state, ask the SCSI
  * EH to continue waiting (BLK_EH_RESET_TIMER). Otherwise let the SCSI core
- * handle the timeout (BLK_EH_NOT_HANDLED).
+ * handle the timeout (BLK_EH_DONE).
  *
  * Note: This function is called from soft-IRQ context and with the request
  * queue lock held.
@@ -602,7 +602,7 @@ enum blk_eh_timer_return srp_timed_out(struct scsi_cmnd *scmd)
 	pr_debug("timeout for sdev %s\n", dev_name(&sdev->sdev_gendev));
 	return rport->fast_io_fail_tmo < 0 && rport->dev_loss_tmo < 0 &&
 		i->f->reset_timer_if_blocked && scsi_device_blocked(sdev) ?
-		BLK_EH_RESET_TIMER : BLK_EH_NOT_HANDLED;
+		BLK_EH_RESET_TIMER : BLK_EH_DONE;
 }
 EXPORT_SYMBOL(srp_timed_out);
 
drivers/scsi/ufs/ufshcd.c +3 -3
index 00e79057f870..d0a1674915a1 100644
@@ -6497,12 +6497,12 @@ static enum blk_eh_timer_return ufshcd_eh_timed_out(struct scsi_cmnd *scmd)
 	bool found = false;
 
 	if (!scmd || !scmd->device || !scmd->device->host)
-		return BLK_EH_NOT_HANDLED;
+		return BLK_EH_DONE;
 
 	host = scmd->device->host;
 	hba = shost_priv(host);
 	if (!hba)
-		return BLK_EH_NOT_HANDLED;
+		return BLK_EH_DONE;
 
 	spin_lock_irqsave(host->host_lock, flags);
 
@@ -6520,7 +6520,7 @@ static enum blk_eh_timer_return ufshcd_eh_timed_out(struct scsi_cmnd *scmd)
 	 * SCSI command was not actually dispatched to UFS driver, otherwise
 	 * let SCSI layer handle the error as usual.
 	 */
-	return found ? BLK_EH_NOT_HANDLED : BLK_EH_RESET_TIMER;
+	return found ? BLK_EH_DONE : BLK_EH_RESET_TIMER;
 }
 
 static const struct attribute_group *ufshcd_driver_groups[] = {
include/linux/blkdev.h +1 -1
index f3999719f828..ba0844c176f2 100644
@@ -337,7 +337,7 @@ typedef int (init_rq_fn)(struct request_queue *, struct request *, gfp_t);
 typedef void (exit_rq_fn)(struct request_queue *, struct request *);
 
 enum blk_eh_timer_return {
-	BLK_EH_NOT_HANDLED,
+	BLK_EH_DONE,
 	BLK_EH_HANDLED,
 	BLK_EH_RESET_TIMER,
 };
include/scsi/scsi_host.h +1 -1
index 12f454cb6f61..53b485fe9b67 100644
@@ -307,7 +307,7 @@ struct scsi_host_template {
 	 * EH_HANDLED:		I fixed the error, please complete the command
 	 * EH_RESET_TIMER:	I need more time, reset the timer and
 	 *			begin counting again
-	 * EH_NOT_HANDLED	Begin normal error recovery
+	 * EH_DONE:		Begin normal error recovery
 	 *
 	 * Status: OPTIONAL
 	 */
Signature · 1 line
2.17.0
Reviewed-by on v1 2/14
#4 lore raw

Re: [PATCH 02/14] block: rename BLK_EH_NOT_HANDLED to BLK_EH_DONE

Looks good,

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
Reviewed-by on v1 2/14
#5 lore raw

Re: [PATCH 02/14] block: rename BLK_EH_NOT_HANDLED to BLK_EH_DONE

In reply to Christoph Hellwig
Quoted 16 lines · Christoph Hellwig

The BLK_EH_NOT_HANDLED implies nothing happen, but very often that is not what is happening - instead the driver already completed the command. Fix the symbolic name to reflect that a little better.

---
  Documentation/scsi/scsi_eh.txt            | 4 ++--
  block/blk-mq.c                            | 2 +-
  block/blk-timeout.c                       | 2 +-
  drivers/block/nbd.c                       | 2 +-
  drivers/message/fusion/mptsas.c           | 2 +-
  drivers/s390/block/dasd.c                 | 6 +++---
  drivers/scsi/gdth.c                       | 2 +-
  drivers/scsi/libiscsi.c                   | 2 +-
  drivers/scsi/megaraid/megaraid_sas_base.c | 2 +-
  drivers/scsi/mvumi.c                      | 2 +-
Quoted 9 lines
  drivers/scsi/qla4xxx/ql4_os.c             | 2 +-
  drivers/scsi/scsi_error.c                 | 4 ++--
  drivers/scsi/scsi_transport_fc.c          | 4 ++--
  drivers/scsi/scsi_transport_srp.c         | 4 ++--
  drivers/scsi/ufs/ufshcd.c                 | 6 +++---
  include/linux/blkdev.h                    | 2 +-
  include/scsi/scsi_host.h                  | 2 +-
  17 files changed, 25 insertions(+), 25 deletions(-)

Cheers,

Hannes

author maintainer
#6 lore raw

PATCH 3/14 nvme: return BLK_EH_DONE from ->timeout

In reply to Christoph Hellwig

NVMe always completes the request before returning from ->timeout, either by polling for it, or by disabling the controller. Return BLK_EH_DONE so that the block layer doesn't even try to complete it again.

---
 drivers/nvme/host/pci.c    | 14 +++++---------
 drivers/nvme/host/rdma.c   |  2 +-
 drivers/nvme/target/loop.c |  2 +-
 3 files changed, 7 insertions(+), 11 deletions(-)
drivers/nvme/host/pci.c +5 -9
index 917e1714f7d9..31525324b79f 100644
@@ -1205,7 +1205,7 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
 		nvme_warn_reset(dev, csts);
 		nvme_dev_disable(dev, false);
 		nvme_reset_ctrl(&dev->ctrl);
-		return BLK_EH_HANDLED;
+		return BLK_EH_DONE;
 	}
 
 	/*
@@ -1215,14 +1215,14 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
 		dev_warn(dev->ctrl.device,
 			 "I/O %d QID %d timeout, completion polled\n",
 			 req->tag, nvmeq->qid);
-		return BLK_EH_HANDLED;
+		return BLK_EH_DONE;
 	}
 
 	/*
 	 * Shutdown immediately if controller times out while starting. The
 	 * reset work will see the pci device disabled when it gets the forced
 	 * cancellation error. All outstanding requests are completed on
-	 * shutdown, so we return BLK_EH_HANDLED.
+	 * shutdown, so we return BLK_EH_DONE.
 	 */
 	switch (dev->ctrl.state) {
 	case NVME_CTRL_CONNECTING:
@@ -1232,7 +1232,7 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
 			 req->tag, nvmeq->qid);
 		nvme_dev_disable(dev, false);
 		nvme_req(req)->flags |= NVME_REQ_CANCELLED;
-		return BLK_EH_HANDLED;
+		return BLK_EH_DONE;
 	default:
 		break;
 	}
@@ -1249,12 +1249,8 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
 		nvme_dev_disable(dev, false);
 		nvme_reset_ctrl(&dev->ctrl);
 
-		/*
-		 * Mark the request as handled, since the inline shutdown
-		 * forces all outstanding requests to complete.
-		 */
 		nvme_req(req)->flags |= NVME_REQ_CANCELLED;
-		return BLK_EH_HANDLED;
+		return BLK_EH_DONE;
 	}
 
 	if (atomic_dec_return(&dev->ctrl.abort_limit) < 0) {
drivers/nvme/host/rdma.c +1 -1
index 1eb4438a8763..ac7462cd7f0f 100644
@@ -1598,7 +1598,7 @@ nvme_rdma_timeout(struct request *rq, bool reserved)
 	/* fail with DNR on cmd timeout */
 	nvme_req(rq)->status = NVME_SC_ABORT_REQ | NVME_SC_DNR;
 
-	return BLK_EH_HANDLED;
+	return BLK_EH_DONE;
 }
 
 static blk_status_t nvme_rdma_queue_rq(struct blk_mq_hw_ctx *hctx,
drivers/nvme/target/loop.c +1 -1
index 27a8561c0cb9..22e3627bf16b 100644
@@ -146,7 +146,7 @@ nvme_loop_timeout(struct request *rq, bool reserved)
 	/* fail with DNR on admin cmd timeout */
 	nvme_req(rq)->status = NVME_SC_ABORT_REQ | NVME_SC_DNR;
 
-	return BLK_EH_HANDLED;
+	return BLK_EH_DONE;
 }
 
 static blk_status_t nvme_loop_queue_rq(struct blk_mq_hw_ctx *hctx,
Signature · 1 line
2.17.0
Reviewed-by on v1 3/14
#7 lore raw

Re: [PATCH 03/14] nvme: return BLK_EH_DONE from ->timeout

Looks good,

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
Reviewed-by on v1 3/14
#8 lore raw

Re: [PATCH 03/14] nvme: return BLK_EH_DONE from ->timeout

In reply to Christoph Hellwig
Quoted 11 lines · Christoph Hellwig

NVMe always completes the request before returning from ->timeout, either by polling for it, or by disabling the controller. Return BLK_EH_DONE so that the block layer doesn't even try to complete it again.

---
  drivers/nvme/host/pci.c    | 14 +++++---------
  drivers/nvme/host/rdma.c , |  2 +-
  drivers/nvme/target/loop.c |  2 +-
  3 files changed, 7 insertions(+), 11 deletions(-)

Is there a way of _testing_ this patch?
It looks pretty dodgy, just replacing BLK_EH_HANDLED with BLK_EH_NOT_HANDLED. And, as nothing else has changed, would imply that we can do it on older/stable versions, too. Which means that the original code was buggy to start with.
Hence a test here would be really beneficial.

But then, assuming you did some tests here:

Cheers,

Hannes

author maintainer
#9 lore raw

Re: [PATCH 03/14] nvme: return BLK_EH_DONE from ->timeout

Quoted 1 line · Hannes Reinecke

Is there a way of _testing_ this patch?

Use the error injection framework Johannes wrote? Use blktests (but make sure you have a fixed version of test 011).

Quoted 6 lines

It looks pretty dodgy, just replacing BLK_EH_HANDLED with BLK_EH_NOT_HANDLED.
And, as nothing else has changed, would imply that we can do it on older/stable versions, too.
Which means that the original code was buggy to start with. Hence a test here would be really beneficial.

NVMe always completed the requests itself, so not too much changed.

#10 lore raw

Re: [PATCH 03/14] nvme: return BLK_EH_DONE from ->timeout

In reply to Christoph Hellwig
Quoted 93 lines · Christoph Hellwig

NVMe always completes the request before returning from ->timeout, either by polling for it, or by disabling the controller. Return BLK_EH_DONE so that the block layer doesn't even try to complete it again.

---
 drivers/nvme/host/pci.c    | 14 +++++---------
 drivers/nvme/host/rdma.c   |  2 +-
 drivers/nvme/target/loop.c |  2 +-
 3 files changed, 7 insertions(+), 11 deletions(-)
drivers/nvme/host/pci.c +5 -9
index 917e1714f7d9..31525324b79f 100644
@@ -1205,7 +1205,7 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
 		nvme_warn_reset(dev, csts);
 		nvme_dev_disable(dev, false);
 		nvme_reset_ctrl(&dev->ctrl);
-		return BLK_EH_HANDLED;
+		return BLK_EH_DONE;
 	}
 
 	/*
@@ -1215,14 +1215,14 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
 		dev_warn(dev->ctrl.device,
 			 "I/O %d QID %d timeout, completion polled\n",
 			 req->tag, nvmeq->qid);
-		return BLK_EH_HANDLED;
+		return BLK_EH_DONE;
 	}
 
 	/*
 	 * Shutdown immediately if controller times out while starting. The
 	 * reset work will see the pci device disabled when it gets the forced
 	 * cancellation error. All outstanding requests are completed on
-	 * shutdown, so we return BLK_EH_HANDLED.
+	 * shutdown, so we return BLK_EH_DONE.
 	 */
 	switch (dev->ctrl.state) {
 	case NVME_CTRL_CONNECTING:
@@ -1232,7 +1232,7 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
 			 req->tag, nvmeq->qid);
 		nvme_dev_disable(dev, false);
 		nvme_req(req)->flags |= NVME_REQ_CANCELLED;
-		return BLK_EH_HANDLED;
+		return BLK_EH_DONE;
 	default:
 		break;
 	}
@@ -1249,12 +1249,8 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
 		nvme_dev_disable(dev, false);
 		nvme_reset_ctrl(&dev->ctrl);
 
-		/*
-		 * Mark the request as handled, since the inline shutdown
-		 * forces all outstanding requests to complete.
-		 */
 		nvme_req(req)->flags |= NVME_REQ_CANCELLED;
-		return BLK_EH_HANDLED;
+		return BLK_EH_DONE;
 	}
 
 	if (atomic_dec_return(&dev->ctrl.abort_limit) < 0) {
drivers/nvme/host/rdma.c +1 -1
index 1eb4438a8763..ac7462cd7f0f 100644
@@ -1598,7 +1598,7 @@ nvme_rdma_timeout(struct request *rq, bool reserved)
 	/* fail with DNR on cmd timeout */
 	nvme_req(rq)->status = NVME_SC_ABORT_REQ | NVME_SC_DNR;
 
-	return BLK_EH_HANDLED;
+	return BLK_EH_DONE;
 }
 
 static blk_status_t nvme_rdma_queue_rq(struct blk_mq_hw_ctx *hctx,
drivers/nvme/target/loop.c +1 -1
index 27a8561c0cb9..22e3627bf16b 100644
@@ -146,7 +146,7 @@ nvme_loop_timeout(struct request *rq, bool reserved)
 	/* fail with DNR on admin cmd timeout */
 	nvme_req(rq)->status = NVME_SC_ABORT_REQ | NVME_SC_DNR;
 
-	return BLK_EH_HANDLED;
+	return BLK_EH_DONE;
 }
 
 static blk_status_t nvme_loop_queue_rq(struct blk_mq_hw_ctx *hctx,
Signature · 1 line
2.17.0

This change should have been done after '[PATCH 13/14] blk-mq: Remove generation seqeunce', otherwise the timed-out request won't be completed by nvme_cancel_request() at all because we always marked this request as 'COMPLETE' before calling .timeout().

Thanks,
Ming

author maintainer
#11 lore raw

Re: [PATCH 03/14] nvme: return BLK_EH_DONE from ->timeout

Quoted 4 lines · Ming Lei

This change should have been done after '[PATCH 13/14] blk-mq: Remove generation seqeunce', otherwise the timed-out request won't be completed by nvme_cancel_request() at all because we always marked this request as 'COMPLETE' before calling .timeout().

Yes. Or we should start out with reverting the whole series introducing the gstate. I think it has shown to create much more problems than it solved, and starting from a clean state without it will allow us to iterate much saner.

#12 lore raw

Re: [PATCH 03/14] nvme: return BLK_EH_DONE from ->timeout

Quoted 10 lines · Christoph Hellwig
Quoted 4 lines · Ming Lei

This change should have been done after '[PATCH 13/14] blk-mq: Remove generation seqeunce', otherwise the timed-out request won't be completed by nvme_cancel_request() at all because we always marked this request as 'COMPLETE' before calling .timeout().

Yes. Or we should start out with reverting the whole series introducing the gstate. I think it has shown to create much more problems than it solved, and starting from a clean state without it will allow us to iterate much saner.

It may not help for this case by reverting the series introducing the gstate.

This behaviour has been used from the beginning, such as, the code becomes the following after the revert:

                if (!blk_mark_rq_complete(rq))
                        blk_mq_rq_timed_out(rq, reserved);

Given the patch 13("blk-mq: Remove generation seqeunce") is the 1st one to change the behaviour, we should put this patch and other related ones after patch 13 for avoiding to break 'git bisect'.

Thanks,
Ming

author maintainer
#13 lore raw

PATCH 4/14 nbd: complete requests from ->timeout

In reply to Christoph Hellwig

By completing the request entirely in the driver we can remove the BLK_EH_HANDLED return value and thus the split responsibility between the driver and the block layer that has been causing trouble.

---
 drivers/block/nbd.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/block/nbd.c +4 -3
index 09d9959287fe..30a851b8a99c 100644
@@ -300,7 +300,7 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
 
 	if (!refcount_inc_not_zero(&nbd->config_refs)) {
 		cmd->status = BLK_STS_TIMEOUT;
-		return BLK_EH_HANDLED;
+		goto done;
 	}
 	config = nbd->config;
 
@@ -338,8 +338,9 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
 	cmd->status = BLK_STS_IOERR;
 	sock_shutdown(nbd);
 	nbd_config_put(nbd);
-
-	return BLK_EH_HANDLED;
+done:
+	blk_mq_complete_request(req);
+	return BLK_EH_DONE;
 }
 
 /*
Signature · 1 line
2.17.0
Reviewed-by on v1 4/14
#14 lore raw

Re: [PATCH 04/14] nbd: complete requests from ->timeout

Quoted 25 lines · Christoph Hellwig

By completing the request entirely in the driver we can remove the BLK_EH_HANDLED return value and thus the split responsibility between the driver and the block layer that has been causing trouble.

---
  drivers/block/nbd.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
drivers/block/nbd.c +1 -1
index 09d9959287fe..30a851b8a99c 100644
@@ -300,7 +300,7 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
 
  	if (!refcount_inc_not_zero(&nbd->config_refs)) {
  		cmd->status = BLK_STS_TIMEOUT;
-		return BLK_EH_HANDLED;
+		goto done;
  	}
  	config = nbd->config;
 
@@ -338,8 +338,9 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
  	cmd->status = BLK_STS_IOERR;

drivers/block/nbd.c static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req, · line 346

Quoted 10 lines
drivers/block/nbd.c +3 -2
  	sock_shutdown(nbd);
  	nbd_config_put(nbd);
-
-	return BLK_EH_HANDLED;
+done:
+	blk_mq_complete_request(req);
+	return BLK_EH_DONE;
  }
 
  /*

Again, some testcase would be nice ...

Cheers,

Hannes

author maintainer
#15 lore raw

Re: [PATCH 04/14] nbd: complete requests from ->timeout

Quoted 1 line · Hannes Reinecke

Again, some testcase would be nice ...

For this one I don't have an actual test case. I'll have to defer to the nbd maintainers for that.

author maintainer
#16 lore raw

PATCH 5/14 mtip32xx: complete requests from ->timeout

In reply to Christoph Hellwig

By completing the request entirely in the driver we can remove the BLK_EH_HANDLED return value and thus the split responsibility between the driver and the block layer that has been causing trouble.

---
 drivers/block/mtip32xx/mtip32xx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/mtip32xx/mtip32xx.c +2 -1
index 6df5b0b1517a..beace13effe4 100644
@@ -3720,7 +3720,8 @@ static enum blk_eh_timer_return mtip_cmd_timeout(struct request *req,
 		struct mtip_cmd *cmd = blk_mq_rq_to_pdu(req);
 
 		cmd->status = BLK_STS_TIMEOUT;
-		return BLK_EH_HANDLED;
+		blk_mq_complete_request(req);
+		return BLK_EH_DONE;
 	}
 
 	if (test_bit(req->tag, dd->port->cmds_to_issue))
Signature · 1 line
2.17.0
Reviewed-by on v1 5/14
#17 lore raw

Re: [PATCH 05/14] mtip32xx: complete requests from ->timeout

Looks good,

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
Reviewed-by on v1 5/14
#18 lore raw

Re: [PATCH 05/14] mtip32xx: complete requests from ->timeout

In reply to Christoph Hellwig
Quoted 15 lines · Christoph Hellwig

By completing the request entirely in the driver we can remove the BLK_EH_HANDLED return value and thus the split responsibility between the driver and the block layer that has been causing trouble.

---
  drivers/block/mtip32xx/mtip32xx.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/mtip32xx/mtip32xx.c +0 -0
index 6df5b0b1517a..beace13effe4 100644

drivers/block/mtip32xx/mtip32xx.c static enum blk_eh_timer_return mtip_cmd_timeout(struct request *req, · line 3727

Quoted 9 lines
drivers/block/mtip32xx/mtip32xx.c +2 -1
@@ -3720,7 +3720,8 @@ static enum blk_eh_timer_return mtip_cmd_timeout(struct request *req,
  		struct mtip_cmd *cmd = blk_mq_rq_to_pdu(req);
 
  		cmd->status = BLK_STS_TIMEOUT;
-		return BLK_EH_HANDLED;
+		blk_mq_complete_request(req);
+		return BLK_EH_DONE;
  	}
 
  	if (test_bit(req->tag, dd->port->cmds_to_issue))

Cheers,

Hannes

author maintainer
#19 lore raw

PATCH 6/14 null_blk: complete requests from ->timeout

In reply to Christoph Hellwig

By completing the request entirely in the driver we can remove the BLK_EH_HANDLED return value and thus the split responsibility between the driver and the block layer that has been causing trouble.

---
 drivers/block/null_blk.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/block/null_blk.c +4 -2
index a76553293a31..f86e7af1dc8e 100644
@@ -1365,7 +1365,8 @@ static blk_qc_t null_queue_bio(struct request_queue *q, struct bio *bio)
 static enum blk_eh_timer_return null_rq_timed_out_fn(struct request *rq)
 {
 	pr_info("null: rq %p timed out\n", rq);
-	return BLK_EH_HANDLED;
+	blk_mq_complete_request(rq);
+	return BLK_EH_DONE;
 }
 
 static int null_rq_prep_fn(struct request_queue *q, struct request *req)
@@ -1427,7 +1428,8 @@ static void null_request_fn(struct request_queue *q)
 static enum blk_eh_timer_return null_timeout_rq(struct request *rq, bool res)
 {
 	pr_info("null: rq %p timed out\n", rq);
-	return BLK_EH_HANDLED;
+	blk_mq_complete_request(rq);
+	return BLK_EH_DONE;
 }
 
 static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx,
Signature · 1 line
2.17.0
Reviewed-by on v1 6/14
#20 lore raw

Re: [PATCH 06/14] null_blk: complete requests from ->timeout

Looks good,

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
Reviewed-by on v1 6/14
#21 lore raw

Re: [PATCH 06/14] null_blk: complete requests from ->timeout

In reply to Christoph Hellwig
Quoted 9 lines · Christoph Hellwig

By completing the request entirely in the driver we can remove the BLK_EH_HANDLED return value and thus the split responsibility between the driver and the block layer that has been causing trouble.

---
  drivers/block/null_blk.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)

Cheers,

Hannes

author maintainer
#22 lore raw

PATCH 7/14 scsi_transport_fc: complete requests from ->timeout

In reply to Christoph Hellwig

By completing the request entirely in the driver we can remove the BLK_EH_HANDLED return value and thus the split responsibility between the driver and the block layer that has been causing trouble.

---
 drivers/scsi/scsi_transport_fc.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/scsi/scsi_transport_fc.c +3 -4
index 90075a0ddcfe..7a9a65588a1b 100644
@@ -3591,10 +3591,9 @@ fc_bsg_job_timeout(struct request *req)
 	}
 
 	/* the blk_end_sync_io() doesn't check the error */
-	if (!inflight)
-		return BLK_EH_DONE;
-	else
-		return BLK_EH_HANDLED;
+	if (inflight)
+		blk_mq_complete_request(req);
+	return BLK_EH_DONE;
 }
 
 /**
Signature · 1 line
2.17.0
Reviewed-by on v1 7/14
#23 lore raw

Re: [PATCH 07/14] scsi_transport_fc: complete requests from ->timeout

Looks good,

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
Reviewed-by on v1 7/14
#24 lore raw

Re: [PATCH 07/14] scsi_transport_fc: complete requests from ->timeout

In reply to Christoph Hellwig
Quoted 18 lines · Christoph Hellwig

By completing the request entirely in the driver we can remove the BLK_EH_HANDLED return value and thus the split responsibility between the driver and the block layer that has been causing trouble.

---
  drivers/scsi/scsi_transport_fc.c | 7 +++----
  1 file changed, 3 insertions(+), 4 deletions(-)
drivers/scsi/scsi_transport_fc.c +0 -0
index 90075a0ddcfe..7a9a65588a1b 100644
@@ -3591,10 +3591,9 @@ fc_bsg_job_timeout(struct request *req)
  	}
 
  	/* the blk_end_sync_io() doesn't check the error */

drivers/scsi/scsi_transport_fc.c fc_bsg_job_timeout(struct request *req) · line 3599

Quoted 10 lines
drivers/scsi/scsi_transport_fc.c +3 -4
-	if (!inflight)
-		return BLK_EH_DONE;
-	else
-		return BLK_EH_HANDLED;
+	if (inflight)
+		blk_mq_complete_request(req);
+	return BLK_EH_DONE;
  }
 
  /**

Cheers,

Hannes

author maintainer
#25 lore raw

PATCH 8/14 mmc: complete requests from ->timeout

In reply to Christoph Hellwig

By completing the request entirely in the driver we can remove the BLK_EH_HANDLED return value and thus the split responsibility between the driver and the block layer that has been causing trouble.

[While this keeps existing behavior it seems to mismatch the comment,
maintainers please chime in!]

---
 drivers/mmc/core/queue.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/mmc/core/queue.c +3 -2
index 56e9a803db21..648eb6743ed5 100644
@@ -111,8 +111,9 @@ static enum blk_eh_timer_return mmc_cqe_timed_out(struct request *req)
 				__mmc_cqe_recovery_notifier(mq);
 			return BLK_EH_RESET_TIMER;
 		}
-		/* No timeout */
-		return BLK_EH_HANDLED;
+		/* No timeout (XXX: huh? comment doesn't make much sense) */
+		blk_mq_complete_request(req);
+		return BLK_EH_DONE;
 	default:
 		/* Timeout is handled by mmc core */
 		return BLK_EH_RESET_TIMER;
Signature · 1 line
2.17.0
Reviewed-by on v1 8/14
#26 lore raw

Re: [PATCH 08/14] mmc: complete requests from ->timeout

Quoted 19 lines · Christoph Hellwig

By completing the request entirely in the driver we can remove the BLK_EH_HANDLED return value and thus the split responsibility between the driver and the block layer that has been causing trouble.

[While this keeps existing behavior it seems to mismatch the comment,
maintainers please chime in!]

---
  drivers/mmc/core/queue.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/mmc/core/queue.c +0 -0
index 56e9a803db21..648eb6743ed5 100644
@@ -111,8 +111,9 @@ static enum blk_eh_timer_return mmc_cqe_timed_out(struct request *req)
  				__mmc_cqe_recovery_notifier(mq);

drivers/mmc/core/queue.c static enum blk_eh_timer_return mmc_cqe_timed_out(struct request *req) · line 119

Quoted 10 lines
drivers/mmc/core/queue.c +3 -2
  			return BLK_EH_RESET_TIMER;
  		}
-		/* No timeout */
-		return BLK_EH_HANDLED;
+		/* No timeout (XXX: huh? comment doesn't make much sense) */
+		blk_mq_complete_request(req);
+		return BLK_EH_DONE;
  	default:
  		/* Timeout is handled by mmc core */
  		return BLK_EH_RESET_TIMER;

Cheers,

Hannes

author maintainer
#27 lore raw

PATCH 9/14 libiscsi: don't try to bypass SCSI EH

In reply to Christoph Hellwig

libiscsi is the only SCSI code that return BLK_EH_HANDLED, thus trying to bypass the normal SCSI EH code. We are going to remove this return value at the block layer, and at least from a quick look it doesn't look too harmful to try to send an abort for these cases, especially as the first one should not actually be possible. If this doesn't work out iscsi will probably need its own eh_strategy_handler instead to just do the right thing.

---
 drivers/scsi/libiscsi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/libiscsi.c +2 -2
index eee43ba83a60..71bdc0b52cf9 100644
@@ -1982,7 +1982,7 @@ enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc)
 		 * Raced with completion. Blk layer has taken ownership
 		 * so let timeout code complete it now.
 		 */
-		rc = BLK_EH_HANDLED;
+		rc = BLK_EH_DONE;
 		goto done;
 	}
 
@@ -1997,7 +1997,7 @@ enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc)
 		if (unlikely(system_state != SYSTEM_RUNNING)) {
 			sc->result = DID_NO_CONNECT << 16;
 			ISCSI_DBG_EH(session, "sc on shutdown, handled\n");
-			rc = BLK_EH_HANDLED;
+			rc = BLK_EH_DONE;
 			goto done;
 		}
 		/*
Signature · 1 line
2.17.0
Reviewed-by on v1 9/14
#28 lore raw

Re: [PATCH 09/14] libiscsi: don't try to bypass SCSI EH

Quoted 28 lines · Christoph Hellwig

libiscsi is the only SCSI code that return BLK_EH_HANDLED, thus trying to bypass the normal SCSI EH code. We are going to remove this return value at the block layer, and at least from a quick look it doesn't look too harmful to try to send an abort for these cases, especially as the first one should not actually be possible. If this doesn't work out iscsi will probably need its own eh_strategy_handler instead to just do the right thing.

---
  drivers/scsi/libiscsi.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/libiscsi.c +1 -1
index eee43ba83a60..71bdc0b52cf9 100644
@@ -1982,7 +1982,7 @@ enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc)
  		 * Raced with completion. Blk layer has taken ownership
  		 * so let timeout code complete it now.
  		 */
-		rc = BLK_EH_HANDLED;
+		rc = BLK_EH_DONE;
  		goto done;
  	}
 

drivers/scsi/libiscsi.c enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc) · line 2003

Quoted 8 lines
drivers/scsi/libiscsi.c +1 -1
@@ -1997,7 +1997,7 @@ enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc)
  		if (unlikely(system_state != SYSTEM_RUNNING)) {
  			sc->result = DID_NO_CONNECT << 16;
  			ISCSI_DBG_EH(session, "sc on shutdown, handled\n");
-			rc = BLK_EH_HANDLED;
+			rc = BLK_EH_DONE;
  			goto done;
  		}
  		/*

That should be okay, as these two returns are the pathological case where the command has already completed before the timeout handler got invoked. IE the very same issue which triggered this patchset in the first place.

Cheers,

Hannes

author maintainer
#29 lore raw

PATCH 10/14 block: remove BLK_EH_HANDLED

In reply to Christoph Hellwig
---
 Documentation/scsi/scsi_eh.txt | 11 -----------
 block/blk-mq.c                 |  3 ---
 block/blk-timeout.c            |  3 ---
 include/linux/blkdev.h         |  1 -
 4 files changed, 18 deletions(-)
Documentation/scsi/scsi_eh.txt +0 -11
index 3ae8419e72cf..1b7436932a2b 100644
@@ -82,17 +82,6 @@ function
  1. invokes optional hostt->eh_timed_out() callback.  Return value can
     be one of
 
-    - BLK_EH_HANDLED
-	This indicates that eh_timed_out() dealt with the timeout.
-	The command is passed back to the block layer and completed
-	via __blk_complete_requests().
-
-	*NOTE* After returning BLK_EH_HANDLED the SCSI layer is
-	assumed to be finished with the command, and no other
-	functions from the SCSI layer will be called. So this
-	should typically only be returned if the eh_timed_out()
-	handler raced with normal completion.
-
     - BLK_EH_RESET_TIMER
 	This indicates that more time is required to finish the
 	command.  Timer is restarted.  This action is counted as a
block/blk-mq.c +0 -3
index 546acc8cb201..22ab2a148a9b 100644
@@ -844,9 +844,6 @@ static void blk_mq_rq_timed_out(struct request *req, bool reserved)
 		ret = ops->timeout(req, reserved);
 
 	switch (ret) {
-	case BLK_EH_HANDLED:
-		__blk_mq_complete_request(req);
-		break;
 	case BLK_EH_RESET_TIMER:
 		/*
 		 * As nothing prevents from completion happening while
block/blk-timeout.c +0 -3
index 3c622335811f..aae8f233341b 100644
@@ -86,9 +86,6 @@ static void blk_rq_timed_out(struct request *req)
 	if (q->rq_timed_out_fn)
 		ret = q->rq_timed_out_fn(req);
 	switch (ret) {
-	case BLK_EH_HANDLED:
-		__blk_complete_request(req);
-		break;
 	case BLK_EH_RESET_TIMER:
 		blk_add_timer(req);
 		blk_clear_rq_complete(req);
include/linux/blkdev.h +0 -1
index ba0844c176f2..3d9d4da4dedd 100644
@@ -338,7 +338,6 @@ typedef void (exit_rq_fn)(struct request_queue *, struct request *);
 
 enum blk_eh_timer_return {
 	BLK_EH_DONE,
-	BLK_EH_HANDLED,
 	BLK_EH_RESET_TIMER,
 };
 
Signature · 1 line
2.17.0
author maintainer
#31 lore raw

PATCH 11/14 block: document the blk_eh_timer_return values

In reply to Christoph Hellwig
---
 include/linux/blkdev.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/blkdev.h +2 -2
index 3d9d4da4dedd..3815d9dcfbe0 100644
@@ -337,8 +337,8 @@ typedef int (init_rq_fn)(struct request_queue *, struct request *, gfp_t);
 typedef void (exit_rq_fn)(struct request_queue *, struct request *);
 
 enum blk_eh_timer_return {
-	BLK_EH_DONE,
-	BLK_EH_RESET_TIMER,
+	BLK_EH_DONE,		/* drivers has completed the command */
+	BLK_EH_RESET_TIMER,	/* reset timer and try again */
 };
 
 typedef enum blk_eh_timer_return (rq_timed_out_fn)(struct request *);
Signature · 1 line
2.17.0
Reviewed-by on v1 11/14
#32 lore raw

Re: [PATCH 11/14] block: document the blk_eh_timer_return values

Quoted 11 lines · Christoph Hellwig
---
  include/linux/blkdev.h | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/blkdev.h +0 -0
index 3d9d4da4dedd..3815d9dcfbe0 100644

include/linux/blkdev.h typedef int (init_rq_fn)(struct request_queue *, struct request *, gfp_t); · line 344

Quoted 10 lines
include/linux/blkdev.h +2 -2
@@ -337,8 +337,8 @@ typedef int (init_rq_fn)(struct request_queue *, struct request *, gfp_t);
  typedef void (exit_rq_fn)(struct request_queue *, struct request *);
 
  enum blk_eh_timer_return {
-	BLK_EH_DONE,
-	BLK_EH_RESET_TIMER,
+	BLK_EH_DONE,		/* drivers has completed the command */
+	BLK_EH_RESET_TIMER,	/* reset timer and try again */
  };
 
  typedef enum blk_eh_timer_return (rq_timed_out_fn)(struct request *);

Cheers,

Hannes

author maintainer
#33 lore raw

PATCH 12/14 blk-mq: Fix timeout and state order

In reply to Christoph Hellwig

From: Keith Busch <[email protected]>

The block layer had been setting the state to in-flight prior to updating the timer. This is the wrong order since the timeout handler could observe the in-flight state with the older timeout, believing the request had expired when in fact it is just getting started.

---
 block/blk-mq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-mq.c +1 -1
index 22ab2a148a9b..614cb03732ed 100644
@@ -697,8 +697,8 @@ void blk_mq_start_request(struct request *rq)
 	preempt_disable();
 	write_seqcount_begin(&rq->gstate_seq);
 
-	blk_mq_rq_update_state(rq, MQ_RQ_IN_FLIGHT);
 	blk_add_timer(rq);
+	blk_mq_rq_update_state(rq, MQ_RQ_IN_FLIGHT);
 
 	write_seqcount_end(&rq->gstate_seq);
 	preempt_enable();
Signature · 1 line
2.17.0
Reviewed-by on v1 12/14
#34 lore raw

Re: [PATCH 12/14] blk-mq: Fix timeout and state order

Quoted 18 lines · Christoph Hellwig

From: Keith Busch <[email protected]>

The block layer had been setting the state to in-flight prior to updating the timer. This is the wrong order since the timeout handler could observe the in-flight state with the older timeout, believing the request had expired when in fact it is just getting started.

---
  block/blk-mq.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-mq.c +0 -0
index 22ab2a148a9b..614cb03732ed 100644

block/blk-mq.c void blk_mq_start_request(struct request *rq) · line 704

Quoted 9 lines
block/blk-mq.c +1 -1
@@ -697,8 +697,8 @@ void blk_mq_start_request(struct request *rq)
  	preempt_disable();
  	write_seqcount_begin(&rq->gstate_seq);
 
-	blk_mq_rq_update_state(rq, MQ_RQ_IN_FLIGHT);
  	blk_add_timer(rq);
+	blk_mq_rq_update_state(rq, MQ_RQ_IN_FLIGHT);
 
  	write_seqcount_end(&rq->gstate_seq);
  	preempt_enable();

Cheers,

Hannes

author maintainer
#35 lore raw

PATCH 13/14 blk-mq: Remove generation seqeunce

In reply to Christoph Hellwig

From: Keith Busch <[email protected]>

This patch simplifies the timeout handling by relying on the request reference counting to ensure the iterator is operating on an inflight and truly timed out request. Since the reference counting prevents the tag from being reallocated, the block layer no longer needs to prevent drivers from completing their requests while the timeout handler is operating on it: a driver completing a request is allowed to proceed to the next state without additional syncronization with the block layer.

This also removes any need for generation sequence numbers since the request lifetime is prevented from being reallocated as a new sequence while timeout handling is operating on it.

To enables this a refcount is added to struct request so that request users can be sure they're operating on the same request without it changing while they're processing it. The request's tag won't be released for reuse until both the timeout handler and the completion are done with it.

[hch: slight cleanups]

---
 block/blk-core.c       |   6 -
 block/blk-mq-debugfs.c |   1 -
 block/blk-mq.c         | 318 +++++++++++------------------------------
 block/blk-mq.h         |  42 +-----
 block/blk-timeout.c    |   1 -
 include/linux/blkdev.h |  35 ++---
 6 files changed, 98 insertions(+), 305 deletions(-)
block/blk-core.c +0 -6
index 43370faee935..cee03cad99f2 100644
@@ -198,12 +198,6 @@ void blk_rq_init(struct request_queue *q, struct request *rq)
 	rq->internal_tag = -1;
 	rq->start_time_ns = ktime_get_ns();
 	rq->part = NULL;
-	seqcount_init(&rq->gstate_seq);
-	u64_stats_init(&rq->aborted_gstate_sync);
-	/*
-	 * See comment of blk_mq_init_request
-	 */
-	WRITE_ONCE(rq->gstate, MQ_RQ_GEN_INC);
 }
 EXPORT_SYMBOL(blk_rq_init);
 
block/blk-mq-debugfs.c +0 -1
index 3080e18cb859..ffa622366922 100644
@@ -344,7 +344,6 @@ static const char *const rqf_name[] = {
 	RQF_NAME(STATS),
 	RQF_NAME(SPECIAL_PAYLOAD),
 	RQF_NAME(ZONE_WRITE_LOCKED),
-	RQF_NAME(MQ_TIMEOUT_EXPIRED),
 	RQF_NAME(MQ_POLL_SLEPT),
 };
 #undef RQF_NAME
block/blk-mq.c +84 -234

480 lines not on this page · raw message

block/blk-mq.h +2 -40

55 lines not on this page · raw message

block/blk-timeout.c +0 -1
index aae8f233341b..4b8a48d48ba1 100644
@@ -211,7 +211,6 @@ void blk_add_timer(struct request *req)
 		req->timeout = q->rq_timeout;
 
 	blk_rq_set_deadline(req, jiffies + req->timeout);
-	req->rq_flags &= ~RQF_MQ_TIMEOUT_EXPIRED;
 
 	/*
 	 * Only the non-mq case needs to add the request to a protected list.
include/linux/blkdev.h +12 -23
index 3815d9dcfbe0..9f06b29adaa4 100644
@@ -125,15 +125,22 @@ typedef __u32 __bitwise req_flags_t;
 #define RQF_SPECIAL_PAYLOAD	((__force req_flags_t)(1 << 18))
 /* The per-zone write lock is held for this request */
 #define RQF_ZONE_WRITE_LOCKED	((__force req_flags_t)(1 << 19))
-/* timeout is expired */
-#define RQF_MQ_TIMEOUT_EXPIRED	((__force req_flags_t)(1 << 20))
 /* already slept for hybrid poll */
-#define RQF_MQ_POLL_SLEPT	((__force req_flags_t)(1 << 21))
+#define RQF_MQ_POLL_SLEPT	((__force req_flags_t)(1 << 20))
 
 /* flags that prevent us from merging requests: */
 #define RQF_NOMERGE_FLAGS \
 	(RQF_STARTED | RQF_SOFTBARRIER | RQF_FLUSH_SEQ | RQF_SPECIAL_PAYLOAD)
 
+/*
+ * Request state for blk-mq.
+ */
+enum mq_rq_state {
+	MQ_RQ_IDLE		= 0,
+	MQ_RQ_IN_FLIGHT		= 1,
+	MQ_RQ_COMPLETE		= 2,
+};
+
 /*
  * Try to put the fields that are referenced together in the same cacheline.
  *
@@ -236,26 +243,8 @@ struct request {
 
 	unsigned int extra_len;	/* length of alignment and padding */
 
-	/*
-	 * On blk-mq, the lower bits of ->gstate (generation number and
-	 * state) carry the MQ_RQ_* state value and the upper bits the
-	 * generation number which is monotonically incremented and used to
-	 * distinguish the reuse instances.
-	 *
-	 * ->gstate_seq allows updates to ->gstate and other fields
-	 * (currently ->deadline) during request start to be read
-	 * atomically from the timeout path, so that it can operate on a
-	 * coherent set of information.
-	 */
-	seqcount_t gstate_seq;
-	u64 gstate;
-
-	/*
-	 * ->aborted_gstate is used by the timeout to claim a specific
-	 * recycle instance of this request.  See blk_mq_timeout_work().
-	 */
-	struct u64_stats_sync aborted_gstate_sync;
-	u64 aborted_gstate;
+	enum mq_rq_state state;
+	refcount_t ref;
 
 	/* access through blk_rq_set_deadline, blk_rq_deadline */
 	unsigned long __deadline;
Signature · 1 line
2.17.0
#36 lore raw

Re: [PATCH 13/14] blk-mq: Remove generation seqeunce

Quoted 9 lines · Christoph Hellwig
block/blk-mq.c +0 -9
-static void hctx_unlock(struct blk_mq_hw_ctx *hctx, int srcu_idx)
-	__releases(hctx->srcu)
-{
-	if (!(hctx->flags & BLK_MQ_F_BLOCKING))
-		rcu_read_unlock();
-	else
-		srcu_read_unlock(hctx->srcu, srcu_idx);
-}
-

block/blk-mq.c static void __blk_mq_complete_request(struct request *rq) · line 594

Quoted 10 lines
block/blk-mq.c +0 -10
-static void hctx_lock(struct blk_mq_hw_ctx *hctx, int *srcu_idx)
-	__acquires(hctx->srcu)
-{
-	if (!(hctx->flags & BLK_MQ_F_BLOCKING)) {
-		/* shut up gcc false positive */
-		*srcu_idx = 0;
-		rcu_read_lock();
-	} else
-		*srcu_idx = srcu_read_lock(hctx->srcu);
-}

I may have too ambitious on removing hctx_lock. That's actually nothing to do with the completion issues, but it is necessary for quiesce to work reliably. Otherwise, I still think there is some promise to the reset of the approach.

author maintainer
#37 lore raw

PATCH 14/14 blk-mq: simplify blk_mq_rq_timed_out

In reply to Christoph Hellwig
---
 block/blk-mq.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)
block/blk-mq.c +8 -14
index 8c7b1803b7e9..592bab689f8e 100644
@@ -747,22 +747,16 @@ EXPORT_SYMBOL(blk_mq_tag_to_rq);
 
 static void blk_mq_rq_timed_out(struct request *req, bool reserved)
 {
-	const struct blk_mq_ops *ops = req->q->mq_ops;
-	enum blk_eh_timer_return ret = BLK_EH_RESET_TIMER;
+	if (req->q->mq_ops->timeout) {
+		enum blk_eh_timer_return ret;
 
-	if (ops->timeout)
-		ret = ops->timeout(req, reserved);
-
-	switch (ret) {
-	case BLK_EH_RESET_TIMER:
-		blk_add_timer(req);
-		break;
-	case BLK_EH_DONE:
-		break;
-	default:
-		printk(KERN_ERR "block: bad eh return: %d\n", ret);
-		break;
+		ret = req->q->mq_ops->timeout(req, reserved);
+		if (ret == BLK_EH_DONE)
+			return;
+		WARN_ON_ONCE(ret != BLK_EH_RESET_TIMER);
 	}
+
+	blk_add_timer(req);
 }
 
 static bool blk_mq_req_expired(struct request *rq, unsigned long *next)
Signature · 1 line
2.17.0
#38 lore raw
In reply to Christoph Hellwig
Quoted 10 lines · Christoph Hellwig

Hi all,

this series removes the BLK_EH_HANDLED return value, and instead places responsibility of timed out commands entirely on the drivers. Except for some odd layering vilations in libiscsi this actually is surprisingly simple. The last two pathes contain a respin of Keith' series to refcount struct request in the eye of timeouts. Once the BLK_EH_HANDLED special case is gone this actually seems the EH fixing approach that seems the most sensible to me.

YES!

Cheers,

Hannes