Skip to contentSkip to conversation

scsi: ufs: core: Fix ufshcd_inc_sq_tail function bug

PATCH Applied Zhang Hui 4 participants 5 messages Jun 1, 2023 – Jun 15, 2023

Subsystems (2)
lore
Share & tools
lore

Zhang Hui

author
#0 lore raw

PATCH v2 1/1 scsi: ufs: core: Fix ufshcd_inc_sq_tail function bug

From: zhanghui <[email protected]>

When qdepth is not power of 2, not every bit of the mask is 1, so sq_tail_slot some bits will be cleared unexpected.

---
 drivers/ufs/core/ufshcd-priv.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/ufs/core/ufshcd-priv.h +3 -2
index d53b93c21a0c..319fba31c1f5 100644
@@ -366,10 +366,11 @@ static inline bool ufs_is_valid_unit_desc_lun(struct ufs_dev_info *dev_info, u8
 static inline void ufshcd_inc_sq_tail(struct ufs_hw_queue *q)
 	__must_hold(&q->sq_lock)
 {
-	u32 mask = q->max_entries - 1;
 	u32 val;
 
-	q->sq_tail_slot = (q->sq_tail_slot + 1) & mask;
+	q->sq_tail_slot++;
+	if (q->sq_tail_slot == q->max_entries)
+		q->sq_tail_slot = 0;
 	val = q->sq_tail_slot * sizeof(struct utp_transfer_req_desc);
 	writel(val, q->mcq_sq_tail);
 }
Signature · 1 line
2.39.0
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 18 lines · Zhang Hui

From: zhanghui <[email protected]>

When qdepth is not power of 2, not every bit of the mask is 1, so sq_tail_slot some bits will be cleared unexpected.

---
  drivers/ufs/core/ufshcd-priv.h | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/ufs/core/ufshcd-priv.h +0 -0
index d53b93c21a0c..319fba31c1f5 100644
@@ -366,10 +366,11 @@ static inline bool ufs_is_valid_unit_desc_lun(struct ufs_dev_info *dev_info, u8
  static inline void ufshcd_inc_sq_tail(struct ufs_hw_queue *q)
  	__must_hold(&q->sq_lock)
  {

drivers/ufs/core/ufshcd-priv.h static inline bool ufs_is_valid_unit_desc_lun(struct ufs_dev_info *dev_info, u8 · line 376

Quoted 10 lines
drivers/ufs/core/ufshcd-priv.h +3 -2
-	u32 mask = q->max_entries - 1;
  	u32 val;
 
-	q->sq_tail_slot = (q->sq_tail_slot + 1) & mask;
+	q->sq_tail_slot++;
+	if (q->sq_tail_slot == q->max_entries)
+		q->sq_tail_slot = 0;
  	val = q->sq_tail_slot * sizeof(struct utp_transfer_req_desc);
  	writel(val, q->mcq_sq_tail);
  }
#3 lore raw
In reply to Zhang Hui

Zhang,

Quoted 2 lines

When qdepth is not power of 2, not every bit of the mask is 1, so sq_tail_slot some bits will be cleared unexpected.

Applied to 6.5/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering