Commit
469fa055664bfd8717b087a80d59c03055789c17
scsi: ufs: core: Decouple CQ sweep from request iterator in MCQ
In MCQ mode, ufshcd_mcq_compl_pending_transfer() uses
blk_mq_tagset_busy_iter() to iterate over busy requests during error
recovery and host reset. However, both iterator callbacks perform
whole-queue operations redundantly for each visited request:
- force_compl == true: ufshcd_mcq_force_compl_one() calls
ufshcd_mcq_compl_all_cqes_lock() on every busy request, sweeping the
entire completion ring (hwq->max_entries slots) once per active request
under spin_lock_irqsave even though the first sweep already cleared all
completion entries.
- force_compl == false: ufshcd_mcq_compl_one() acquires cq_lock and polls
CQTPy over MMIO via ufshcd_mcq_poll_cqe_lock() for every busy request
without doing any per-request work.
Sweep or poll each hardware queue (hba->uhq[i]) once at the start of
ufshcd_mcq_compl_pending_transfer(). When force_compl is true, run
blk_mq_tagset_busy_iter() afterward to complete residual in-flight
requests with DID_REQUEUE, and remove the now-unused
ufshcd_mcq_compl_one() callback.
Fixes: ab248643d3d6 ("scsi: ufs: core: Add error handling for MCQ mode")
Cc: stable@vger.kernel.org
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Stanley Jhu <stanleyjhu@google.com>
Reviewed-by: Peter Wang <peter.wang@mediatek.com>
Link: https://patch.msgid.link/20260928035816.1294326-3-stanleyjhu@google.com
Signed-off-by: Martin K. Petersen (Oracle) <mkp@kernel.org>
Stanley Jhu <stanleyjhu@google.com> · 2026-09-28 03:58 UTC · committed by Martin K. Petersen (Oracle)
1 file changed,
+12
−19
modified drivers/ufs/core/ufshcd.c
| @@ -6044,8 +6044,6 @@ static bool ufshcd_mcq_force_compl_one(struct request *rq, void *priv) | |||
| 6044 | 6044 | if (blk_mq_is_reserved_rq(rq) || !hwq) | |
| 6045 | 6045 | return true; | |
| 6046 | 6046 | ||
| 6047 | - | ufshcd_mcq_compl_all_cqes_lock(hba, hwq); | |
| 6048 | - | ||
| 6049 | 6047 | /* | |
| 6050 | 6048 | * For those cmds of which the cqes are not present in the cq, complete | |
| 6051 | 6049 | * them explicitly. | |
| @@ -6061,19 +6059,6 @@ static bool ufshcd_mcq_force_compl_one(struct request *rq, void *priv) | |||
| 6061 | 6059 | return true; | |
| 6062 | 6060 | } | |
| 6063 | 6061 | ||
| 6064 | - | static bool ufshcd_mcq_compl_one(struct request *rq, void *priv) | |
| 6065 | - | { | |
| 6066 | - | struct scsi_device *sdev = rq->q->queuedata; | |
| 6067 | - | struct Scsi_Host *shost = sdev->host; | |
| 6068 | - | struct ufs_hba *hba = shost_priv(shost); | |
| 6069 | - | struct ufs_hw_queue *hwq = ufshcd_mcq_req_to_hwq(hba, rq); | |
| 6070 | - | ||
| 6071 | - | if (!blk_mq_is_reserved_rq(rq) && hwq) | |
| 6072 | - | ufshcd_mcq_poll_cqe_lock(hba, hwq); | |
| 6073 | - | ||
| 6074 | - | return true; | |
| 6075 | - | } | |
| 6076 | - | ||
| 6077 | 6062 | /** | |
| 6078 | 6063 | * ufshcd_mcq_compl_pending_transfer - MCQ mode function. It is | |
| 6079 | 6064 | * invoked from the error handler context or ufshcd_host_reset_and_restore() | |
| @@ -6088,10 +6073,18 @@ static bool ufshcd_mcq_compl_one(struct request *rq, void *priv) | |||
| 6088 | 6073 | static void ufshcd_mcq_compl_pending_transfer(struct ufs_hba *hba, | |
| 6089 | 6074 | bool force_compl) | |
| 6090 | 6075 | { | |
| 6091 | - | blk_mq_tagset_busy_iter(&hba->host->tag_set, | |
| 6092 | - | force_compl ? ufshcd_mcq_force_compl_one : | |
| 6093 | - | ufshcd_mcq_compl_one, | |
| 6094 | - | NULL); | |
| 6076 | + | int i; | |
| 6077 | + | ||
| 6078 | + | for (i = 0; i < hba->nr_hw_queues; i++) { | |
| 6079 | + | if (force_compl) | |
| 6080 | + | ufshcd_mcq_compl_all_cqes_lock(hba, &hba->uhq[i]); | |
| 6081 | + | else | |
| 6082 | + | ufshcd_mcq_poll_cqe_lock(hba, &hba->uhq[i]); | |
| 6083 | + | } | |
| 6084 | + | ||
| 6085 | + | if (force_compl) | |
| 6086 | + | blk_mq_tagset_busy_iter(&hba->host->tag_set, | |
| 6087 | + | ufshcd_mcq_force_compl_one, NULL); | |
| 6095 | 6088 | } | |
| 6096 | 6089 | ||
| 6097 | 6090 | /** | |