Skip to contentSkip to conversation

Fix UFS task management command timeout

PATCH In review Po-Wen Kao 3 participants 6 messages Sep 29, 2021 – Sep 30, 2021

Subsystems (2)
lore
Share & tools
lore

Po-Wen Kao

author
#0 lore raw

cover Fix UFS task management command timeout

On UTP_TASK_REQ_COMPL interrupt, ufshcd_tmc_handler() iterates through busy requests in tags->rqs and complete request if corresponding doorbell flag is reset.
However, ufshcd_issue_tm_cmd() allocates requests from tags->static_rqs and trigger doorbell directly without dispatching request through block layer, thus requests can never be found in tags->rqs and completed properly. Any TM command issued by ufshcd_issue_tm_cmd() inevitably timeout and further leads to recovery flow failure when LU Reset or Abort Task is issued.

In this patch, blk_mq_tagset_busy_iter() call in ufshcd_tmc_handler() is replaced with new interface, blk_mq_drv_tagset_busy_iter(), to allow completion of request allocted by driver. The new interface is introduced for driver to iterate through requests in static_rqs.

Po-Wen Kao (2):
blk-mq: new busy request iterator for driver
scsi: ufs: fix TM request timeout

 block/blk-mq-tag.c        | 36 ++++++++++++++++++++++++++++++------
 drivers/scsi/ufs/ufshcd.c |  2 +-
 include/linux/blk-mq.h    |  4 ++++
 3 files changed, 35 insertions(+), 7 deletions(-)
Signature · 1 line
2.18.0
author
#1 lore raw

PATCH 1/2 blk-mq: new busy request iterator for driver

Driver occasionally execute allocated request directly without dispatching to block layer, thus request never appears in tags->rqs. To allow driver to iterate through requests in static_rqs, a new interface blk_mq_drv_tagset_busy_iter() is introduced.

---
 block/blk-mq-tag.c     | 36 ++++++++++++++++++++++++++++++------
 include/linux/blk-mq.h |  4 ++++
 2 files changed, 34 insertions(+), 6 deletions(-)
block/blk-mq-tag.c +30 -6
index 86f87346232a..7723689e7714 100644
@@ -365,6 +365,31 @@ void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
 
 /**
  * blk_mq_tagset_busy_iter - iterate over all started requests in a tag set
+ * Refer to __blk_mq_tagset_iter() for parameter details.
+ */
+void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
+		busy_tag_iter_fn *fn, void *priv)
+{
+	__blk_mq_tagset_iter(tagset, fn, priv,
+			BT_TAG_ITER_STARTED);
+}
+EXPORT_SYMBOL(blk_mq_tagset_busy_iter);
+
+/**
+ * blk_mq_drv_tagset_busy_iter - iterate over all started static requests
+ * in a tag set.
+ * Refer to __blk_mq_tagset_iter() for parameter details.
+ */
+void blk_mq_drv_tagset_busy_iter(struct blk_mq_tag_set *tagset,
+		busy_tag_iter_fn *fn, void *priv)
+{
+	__blk_mq_tagset_iter(tagset, fn, priv,
+			BT_TAG_ITER_STARTED | BT_TAG_ITER_STATIC_RQS);
+}
+EXPORT_SYMBOL(blk_mq_drv_tagset_busy_iter);
+
+/**
+ * blk_mq_tm_tagset_busy_iter - iterate over all requests in a tagset.
  * @tagset:	Tag set to iterate over.
  * @fn:		Pointer to the function that will be called for each started
  *		request. @fn will be called as follows: @fn(rq, @priv,
@@ -375,19 +400,18 @@ void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
  *
  * We grab one request reference before calling @fn and release it after
  * @fn returns.
+ * @flags: BT_TAG_ITER_*
  */
-void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
-		busy_tag_iter_fn *fn, void *priv)
+void __blk_mq_tagset_iter(struct blk_mq_tag_set *tagset,
+		busy_tag_iter_fn *fn, void *priv, unsigned int flags)
 {
 	int i;
-
 	for (i = 0; i < tagset->nr_hw_queues; i++) {
 		if (tagset->tags && tagset->tags[i])
-			__blk_mq_all_tag_iter(tagset->tags[i], fn, priv,
-					      BT_TAG_ITER_STARTED);
+			__blk_mq_all_tag_iter(tagset->tags[i], fn, priv, flags);
 	}
 }
-EXPORT_SYMBOL(blk_mq_tagset_busy_iter);
+
 
 static bool blk_mq_tagset_count_completed_rqs(struct request *rq,
 		void *data, bool reserved)
include/linux/blk-mq.h +4 -0
index 13ba1861e688..29c851192093 100644
@@ -545,6 +545,10 @@ void blk_mq_run_hw_queues(struct request_queue *q, bool async);
 void blk_mq_delay_run_hw_queues(struct request_queue *q, unsigned long msecs);
 void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
 		busy_tag_iter_fn *fn, void *priv);
+void blk_mq_drv_tagset_busy_iter(struct blk_mq_tag_set *tagset,
+		busy_tag_iter_fn *fn, void *priv);
+void __blk_mq_tagset_iter(struct blk_mq_tag_set *tagset,
+		busy_tag_iter_fn *fn, void *priv, unsigned int flags);
 void blk_mq_tagset_wait_completed_request(struct blk_mq_tag_set *tagset);
 void blk_mq_freeze_queue(struct request_queue *q);
 void blk_mq_unfreeze_queue(struct request_queue *q);
Signature · 1 line
2.18.0
#2 lore raw

Re: [PATCH 1/2] blk-mq: new busy request iterator for driver

Quoted 4 lines · Po-Wen Kao

Driver occasionally execute allocated request directly without dispatching to block layer, thus request never appears in tags->rqs. To allow driver to iterate through requests in static_rqs, a new interface blk_mq_drv_tagset_busy_iter() is introduced.

Don't do that. All requests must be dispatched to blk-mq. Let's not even get started on these hacks that will make our life painful forever.

author
#3 lore raw

PATCH 2/2 scsi: ufs: fix TM request timeout

In reply to Po-Wen Kao

TM command issued by ufshcd_issue_tm_cmd() inevitably timeout since interrupt handler iterates wrong request list for completion.

The issue is fixed by iterating static_rqs instead of rqs to find requests with new interface blk_mq_drv_tagset_busy_iter().

---
 drivers/scsi/ufs/ufshcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/ufs/ufshcd.c +1 -1
index 3841ab49f556..7a1ea42302b8 100644
@@ -6428,7 +6428,7 @@ static irqreturn_t ufshcd_tmc_handler(struct ufs_hba *hba)
 
 	spin_lock_irqsave(hba->host->host_lock, flags);
 	ci.pending = ufshcd_readl(hba, REG_UTP_TASK_REQ_DOOR_BELL);
-	blk_mq_tagset_busy_iter(q->tag_set, ufshcd_compl_tm, &ci);
+	blk_mq_drv_tagset_busy_iter(q->tag_set, ufshcd_compl_tm, &ci);
 	spin_unlock_irqrestore(hba->host->host_lock, flags);
 
 	return ci.ncpl ? IRQ_HANDLED : IRQ_NONE;
Signature · 1 line
2.18.0
#4 lore raw
In reply to Po-Wen Kao
Quoted 10 lines

On UTP_TASK_REQ_COMPL interrupt, ufshcd_tmc_handler() iterates through busy requests in tags->rqs and complete request if corresponding doorbell flag is reset.
However, ufshcd_issue_tm_cmd() allocates requests from tags->static_rqs and trigger doorbell directly without dispatching request through block layer, thus requests can never be found in tags->rqs and completed properly. Any TM command issued by ufshcd_issue_tm_cmd() inevitably timeout and further leads to recovery flow failure when LU Reset or Abort Task is issued.

Quoted 4 lines

In this patch, blk_mq_tagset_busy_iter() call in ufshcd_tmc_handler() is replaced with new interface, blk_mq_drv_tagset_busy_iter(), to allow completion of request allocted by driver. The new interface is introduced for driver to iterate through requests in static_rqs.

Is this the same issue that was addressed here - https://www.spinics.net/lists/linux-scsi/msg164520.html ?

Thanks,
Avri

Quoted 12 lines

Po-Wen Kao (2):
blk-mq: new busy request iterator for driver
scsi: ufs: fix TM request timeout

 block/blk-mq-tag.c        | 36 ++++++++++++++++++++++++++++++------
 drivers/scsi/ufs/ufshcd.c |  2 +-
 include/linux/blk-mq.h    |  4 ++++
 3 files changed, 35 insertions(+), 7 deletions(-)

--
2.18.0

author
#5 lore raw

Hi Avri,

Thanks for reminding. It's exactly the same issue.

Best,
Po-Wen Kao

Quoted 42 lines · Avri Altman
Quoted 13 lines

On UTP_TASK_REQ_COMPL interrupt, ufshcd_tmc_handler() iterates through
busy requests in tags->rqs and complete request if corresponding doorbell flag is reset.
However, ufshcd_issue_tm_cmd() allocates requests from tags-

Quoted 1 line

static_rqs

and trigger doorbell directly without dispatching request through block
layer, thus requests can never be found in tags->rqs and completed properly. Any TM command issued by ufshcd_issue_tm_cmd() inevitably timeout and further leads to recovery flow failure when LU Reset or Abort Task is issued.

Quoted 6 lines

In this patch, blk_mq_tagset_busy_iter() call in ufshcd_tmc_handler()
is replaced with new interface, blk_mq_drv_tagset_busy_iter(), to allow completion of request allocted by driver. The new interface is
introduced for driver to iterate through requests in static_rqs.

Is this the same issue that was addressed here -
https://urldefense.com/v3/__https://www.spinics.net/lists/linux-scsi/msg164520.html__;!!CTRNKA9wMg0ARbw!yDkg-AVkMBFsnDBV42HMDgnE51HaEBarK2Tw8z8Di4aC1_7BrRkjIO13nz5rFUk-FA$
A$ ?

Thanks,
Avri

Quoted 13 lines

Po-Wen Kao (2):
blk-mq: new busy request iterator for driver
scsi: ufs: fix TM request timeout

 block/blk-mq-tag.c        | 36 ++++++++++++++++++++++++++++++-----
-
 drivers/scsi/ufs/ufshcd.c |  2 +-
 include/linux/blk-mq.h    |  4 ++++
 3 files changed, 35 insertions(+), 7 deletions(-)

--
2.18.0