mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH v2 2/2] scsi: ufs: core: Decouple CQ sweep from request iterator in MCQ
@ 2026-09-30  7:30 Peter Wang (王信友)
  0 siblings, 0 replies; 16+ messages in thread
From: Peter Wang (王信友) @ 2026-09-30  7:30 UTC (permalink / raw)
  To: Bart Van Assche, Stanley Jhu
  Cc: linux-scsi, Martin K. Petersen, James E.J. Bottomley,
	Alim Akhtar, Avri Altman, Bean Huo, Bao D. Nguyen, Can Guo,
	Manivannan Sadhasivam, linux-kernel

On Fri, 2026-09-25 at 10:26 -0700, Bart Van Assche wrote:
> A correction: the INIT_LIST_HEAD(&cmd->eh_entry) statement is not
> reached while SCSI host recovery is in progress because
> SCMD_STATE_COMPLETE is set for all pending commands before the SCSI
> host recovery starts. scsi_done() skips SCSI commands for which that
> bit is set due to the following code:
> 
>         if (unlikely(test_and_set_bit(SCMD_STATE_COMPLETE, &cmd-
> >state)))
>                 return;
> 
> Hence, the scmd->result value is ignored if scsi_done() is called
> while SCSI host recovery is in progress.
> 
> Bart.

Thanks to Bart and Stanley for the detailed explanation.
It is clear to me now.

Thanks
Peter


^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: [PATCH v2 2/2] scsi: ufs: core: Decouple CQ sweep from request iterator in MCQ
@ 2026-09-22  6:13 Peter Wang (王信友)
  0 siblings, 0 replies; 16+ messages in thread
From: Peter Wang (王信友) @ 2026-09-22  6:13 UTC (permalink / raw)
  To: Stanley Jhu, Bart Van Assche
  Cc: linux-scsi, Martin K. Petersen, James E.J. Bottomley,
	Alim Akhtar, Avri Altman, Bean Huo, Bao D. Nguyen, Can Guo,
	Manivannan Sadhasivam, linux-kernel

[-- Attachment #1: winmail.dat --]
[-- Type: application/ms-tnef, Size: 12707 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread
* [PATCH] scsi: ufs: core: Avoid unsafe MMIO reads in ufshcd_mcq_compl_all_cqes_lock()
@ 2026-09-01 12:23 Stanley Jhu
  2026-09-18 14:38 ` [PATCH v2 0/2] scsi: ufs: core: Fix unsafe MMIO reads and redundant CQ sweeps in MCQ reset Stanley Jhu
  0 siblings, 1 reply; 16+ messages in thread
From: Stanley Jhu @ 2026-09-01 12:23 UTC (permalink / raw)
  To: Martin K . Petersen, James E . J . Bottomley
  Cc: Alim Akhtar, Avri Altman, Bart Van Assche, Peter Wang, quic_cang,
	quic_nguyenb, linux-scsi, linux-kernel, stable

Reading host controller registers (such as CQTP) is unsafe when the
host controller is disabled (HCE = 0), as accessing registers in an
unclocked or reset state can cause bus stalls and system hangs.

In ufshcd_mcq_compl_all_cqes_lock(), all completion queue entries have
already been inspected, processed, and cleared in memory, so the
software queue is logically empty.

Avoid the unsafe MMIO read of CQTP by synchronizing hwq->cq_tail_slot
directly to hwq->cq_head_slot in software. Upon subsequent controller
re-initialization, ufshcd_mcq_make_queues_operational() will
reconfigure and re-zero all queue pointers.

Fixes: ab248643d3d6 ("scsi: ufs: core: Add error handling for MCQ mode")
Cc: stable@vger.kernel.org
Signed-off-by: Stanley Jhu <stanleyjhu@google.com>
---
 drivers/ufs/core/ufs-mcq.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/ufs/core/ufs-mcq.c b/drivers/ufs/core/ufs-mcq.c
index 8106d55f4041..0e1f99c8d77c 100644
--- a/drivers/ufs/core/ufs-mcq.c
+++ b/drivers/ufs/core/ufs-mcq.c
@@ -349,8 +349,12 @@ void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba,
                entries--;
        }

-       ufshcd_mcq_update_cq_tail_slot(hwq);
-       hwq->cq_head_slot = hwq->cq_tail_slot;
+       /*
+        * All completion entries have been processed and cleared.
+        * Synchronize tail to head in software to mark the queue empty,
+        * avoiding unsafe MMIO reads while the controller is disabled.
+        */
+       hwq->cq_tail_slot = hwq->cq_head_slot;
        spin_unlock_irqrestore(&hwq->cq_lock, flags);
 }

--
2.43.0

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2026-09-30  7:31 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-30  7:30 [PATCH v2 2/2] scsi: ufs: core: Decouple CQ sweep from request iterator in MCQ Peter Wang (王信友)
  -- strict thread matches above, loose matches on Subject: below --
2026-09-22  6:13 Peter Wang (王信友)
2026-09-01 12:23 [PATCH] scsi: ufs: core: Avoid unsafe MMIO reads in ufshcd_mcq_compl_all_cqes_lock() Stanley Jhu
2026-09-18 14:38 ` [PATCH v2 0/2] scsi: ufs: core: Fix unsafe MMIO reads and redundant CQ sweeps in MCQ reset Stanley Jhu
2026-09-18 14:38   ` [PATCH v2 2/2] scsi: ufs: core: Decouple CQ sweep from request iterator in MCQ Stanley Jhu
2026-09-18 16:06     ` Bart Van Assche
2026-09-20 13:49       ` Stanley Jhu
2026-09-21 17:13         ` Bart Van Assche
2026-09-22  7:37           ` Peter Wang
2026-09-22 16:30             ` Bart Van Assche
2026-09-23  6:09               ` Peter Wang
2026-09-23 11:18                 ` Stanley Jhu
2026-09-23 17:02                   ` Bart Van Assche
2026-09-25 17:26                     ` Bart Van Assche
2026-09-30  7:31                       ` Peter Wang
2026-09-23 16:50                 ` Bart Van Assche
2026-09-22  7:36         ` Peter Wang
2026-09-25 17:44     ` Bart Van Assche

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®