Skip to contentSkip to conversation

scsi: ufs: core: Let the sq_lock protect sq_tail_slot access

PATCH In review Can Guo 4 participants 6 messages Dec 18, 2023 – Jan 2, 2024

Subsystems (3)
lore
Share & tools
lore

Can Guo

author
#0 lore raw

PATCH 1/1 scsi: ufs: core: Let the sq_lock protect sq_tail_slot access

If access sq_tail_slot without the protection from the sq_lock, race condition can have multiple SQEs copied to duplicate SQE slot(s), which can lead to multiple incredible stability issues. Fix it by moving the *dest initialization, in ufshcd_send_command(), back under protection from the sq_lock.

Fixes 3c85f087faec ("scsi: ufs: mcq: Use pointer arithmetic in ufshcd_send_command()")
drivers/ufs/core/ufshcd.c +2 -1
index ae9936f..2994aac 100644
@@ -2274,9 +2274,10 @@ void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag,
 	if (is_mcq_enabled(hba)) {
 		int utrd_size = sizeof(struct utp_transfer_req_desc);
 		struct utp_transfer_req_desc *src = lrbp->utr_descriptor_ptr;
-		struct utp_transfer_req_desc *dest = hwq->sqe_base_addr + hwq->sq_tail_slot;
+		struct utp_transfer_req_desc *dest;
 
 		spin_lock(&hwq->sq_lock);
+		dest = hwq->sqe_base_addr + hwq->sq_tail_slot;
 		memcpy(dest, src, utrd_size);
 		ufshcd_inc_sq_tail(hwq);
 		spin_unlock(&hwq->sq_lock);
Signature · 1 line
2.7.4
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Can Guo

If access sq_tail_slot without the protection from the sq_lock, race condition can have multiple SQEs copied to duplicate SQE slot(s), which can lead to multiple incredible stability issues. Fix it by moving the *dest initialization, in ufshcd_send_command(), back under protection from the sq_lock.

Fixes 3c85f087faec ("scsi: ufs: mcq: Use pointer arithmetic in ufshcd_send_command()")
drivers/ufs/core/ufshcd.c +0 -0
index ae9936f..2994aac 100644
@@ -2274,9 +2274,10 @@ void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag,
  	if (is_mcq_enabled(hba)) {

drivers/ufs/core/ufshcd.c void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag, · line 2283

Quoted 10 lines
drivers/ufs/core/ufshcd.c +2 -1
  		int utrd_size = sizeof(struct utp_transfer_req_desc);
  		struct utp_transfer_req_desc *src = lrbp->utr_descriptor_ptr;
-		struct utp_transfer_req_desc *dest = hwq->sqe_base_addr + hwq->sq_tail_slot;
+		struct utp_transfer_req_desc *dest;
 
  		spin_lock(&hwq->sq_lock);
+		dest = hwq->sqe_base_addr + hwq->sq_tail_slot;
  		memcpy(dest, src, utrd_size);
  		ufshcd_inc_sq_tail(hwq);
  		spin_unlock(&hwq->sq_lock);
Reviewed-by on v1 1/1
#2 lore raw
In reply to Can Guo
Quoted 7 lines · Can Guo

If access sq_tail_slot without the protection from the sq_lock, race condition can have multiple SQEs copied to duplicate SQE slot(s), which can lead to multiple incredible stability issues. Fix it by moving the *dest initialization, in ufshcd_send_command(), back under protection from the sq_lock.

Fixes 3c85f087faec ("scsi: ufs: mcq: Use pointer arithmetic in ufshcd_send_command()")
Quoted 1 line

- Mani

Quoted 20 lines
drivers/ufs/core/ufshcd.c +2 -1
index ae9936f..2994aac 100644
@@ -2274,9 +2274,10 @@ void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag,
 	if (is_mcq_enabled(hba)) {
 		int utrd_size = sizeof(struct utp_transfer_req_desc);
 		struct utp_transfer_req_desc *src = lrbp->utr_descriptor_ptr;
-		struct utp_transfer_req_desc *dest = hwq->sqe_base_addr + hwq->sq_tail_slot;
+		struct utp_transfer_req_desc *dest;
 
 		spin_lock(&hwq->sq_lock);
+		dest = hwq->sqe_base_addr + hwq->sq_tail_slot;
 		memcpy(dest, src, utrd_size);
 		ufshcd_inc_sq_tail(hwq);
 		spin_unlock(&hwq->sq_lock);
Signature · 1 line
2.7.4
Signature · 1 line
மணிவண்ணன் சதாசிவம்
#3 lore raw
Quoted 10 lines · Manivannan Sadhasivam
Quoted 7 lines · Can Guo

If access sq_tail_slot without the protection from the sq_lock, race condition can have multiple SQEs copied to duplicate SQE slot(s), which can lead to multiple incredible stability issues. Fix it by moving the *dest initialization, in ufshcd_send_command(), back under protection from the sq_lock.

Fixes 3c85f087faec ("scsi: ufs: mcq: Use pointer arithmetic in ufshcd_send_command()")

Hmm ... is the "Cc: stable" tag really required if a "Fixes:" tag is present?

Bart.

#4 lore raw
Quoted 8 lines · Bart Van Assche
Quoted 7 lines · Manivannan Sadhasivam
Quoted 6 lines · Can Guo

If access sq_tail_slot without the protection from the sq_lock, race condition can have multiple SQEs copied to duplicate SQE slot(s), which can lead to multiple incredible stability issues. Fix it by moving the *dest initialization, in ufshcd_send_command(), back under protection from the sq_lock.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Fixes 3c85f087faec ("scsi: ufs: mcq: Use pointer arithmetic in ufshcd_send_command()")

Hmm ... is the "Cc: stable" tag really required if a "Fixes:" tag is present?

Yes it is required as I pointed out in the other thread.

- Mani

Quoted 2 lines

Bart.

Signature · 1 line
மணிவண்ணன் சதாசிவம்
#5 lore raw
In reply to Can Guo
Quoted 15 lines · Can Guo

If access sq_tail_slot without the protection from the sq_lock, race condition can have multiple SQEs copied to duplicate SQE slot(s), which can lead to multiple incredible stability issues. Fix it by moving the *dest initialization, in ufshcd_send_command(), back under protection from the sq_lock.

Fixes 3c85f087faec ("scsi: ufs: mcq: Use pointer arithmetic in ufshcd_send_command()")
drivers/ufs/core/ufshcd.c +0 -0
index ae9936f..2994aac 100644
@@ -2274,9 +2274,10 @@ void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag,
  	if (is_mcq_enabled(hba)) {

drivers/ufs/core/ufshcd.c void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag, · line 2283

Quoted 10 lines
drivers/ufs/core/ufshcd.c +2 -1
  		int utrd_size = sizeof(struct utp_transfer_req_desc);
  		struct utp_transfer_req_desc *src = lrbp->utr_descriptor_ptr;
-		struct utp_transfer_req_desc *dest = hwq->sqe_base_addr + hwq->sq_tail_slot;
+		struct utp_transfer_req_desc *dest;
 
  		spin_lock(&hwq->sq_lock);
+		dest = hwq->sqe_base_addr + hwq->sq_tail_slot;
  		memcpy(dest, src, utrd_size);
  		ufshcd_inc_sq_tail(hwq);
  		spin_unlock(&hwq->sq_lock);

Reviewed and Tested-by: Bao D. Nguyen <[email protected]>