2021-09-29 07:02:49

by Po-Wen Kao

[permalink] [raw]
Subject: [PATCH 0/2] 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(-)

--
2.18.0


2021-09-29 07:03:55

by Po-Wen Kao

[permalink] [raw]
Subject: [PATCH 2/2] scsi: ufs: fix TM request timeout

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().

Signed-off-by: Po-Wen Kao <[email protected]>
---
drivers/scsi/ufs/ufshcd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 3841ab49f556..7a1ea42302b8 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -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;
--
2.18.0

2021-09-29 07:07:24

by Po-Wen Kao

[permalink] [raw]
Subject: [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.

Signed-off-by: Po-Wen Kao <[email protected]>
---
block/blk-mq-tag.c | 36 ++++++++++++++++++++++++++++++------
include/linux/blk-mq.h | 4 ++++
2 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c
index 86f87346232a..7723689e7714 100644
--- a/block/blk-mq-tag.c
+++ b/block/blk-mq-tag.c
@@ -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)
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 13ba1861e688..29c851192093 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -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);
--
2.18.0

2021-09-29 07:14:09

by Christoph Hellwig

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

On Wed, Sep 29, 2021 at 03:00:46PM +0800, Po-Wen Kao wrote:
> 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.

2021-09-29 10:40:18

by Avri Altman

[permalink] [raw]
Subject: RE: [PATCH 0/2] 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.
Is this the same issue that was addressed here - https://www.spinics.net/lists/linux-scsi/msg164520.html ?

Thanks,
Avri

>
> 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

2021-09-30 12:12:04

by Po-Wen Kao

[permalink] [raw]
Subject: Re: [PATCH 0/2] Fix UFS task management command timeout

Hi Avri,

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

Best,
Po-Wen Kao

On Wed, 2021-09-29 at 07:39 +0000, Avri Altman wrote:
> > 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.
>
> 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
>
> >
> > 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
>
>