scsi: ufs: core: Let the sq_lock protect sq_tail_slot access
Subsystems (3)
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.
drivers/ufs/core/ufshcd.c +2 -1
@@ -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
Quoted 15 lines · Can Guo
If access
sq_tail_slotwithout the protection from thesq_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, inufshcd_send_command(), back under protection from thesq_lock.Fixes 3c85f087faec ("scsi: ufs: mcq: Use pointer arithmetic in ufshcd_send_command()")Signed-off-by Can Guo <[email protected]>drivers/ufs/core/ufshcd.c +0
-0@@ -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
-1int 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);
Quoted 7 lines · Can Guo
If access
sq_tail_slotwithout the protection from thesq_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, inufshcd_send_command(), back under protection from thesq_lock.Fixes 3c85f087faec ("scsi: ufs: mcq: Use pointer arithmetic in ufshcd_send_command()")
Quoted 1 line
Signed-off-by Can Guo <[email protected]>
- Mani
Quoted 20 lines
drivers/ufs/core/ufshcd.c +2
-1@@ -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
மணிவண்ணன் சதாசிவம்
Bart Van Assche
reviewerQuoted 10 lines · Manivannan Sadhasivam
Quoted 7 lines · Can Guo
If access
sq_tail_slotwithout the protection from thesq_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, inufshcd_send_command(), back under protection from thesq_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.
Quoted 8 lines · Bart Van Assche
Quoted 7 lines · Manivannan Sadhasivam
Quoted 6 lines · Can Guo
If access
sq_tail_slotwithout the protection from thesq_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, inufshcd_send_command(), back under protection from thesq_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
மணிவண்ணன் சதாசிவம்
Quoted 15 lines · Can Guo
If access
sq_tail_slotwithout the protection from thesq_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, inufshcd_send_command(), back under protection from thesq_lock.Fixes 3c85f087faec ("scsi: ufs: mcq: Use pointer arithmetic in ufshcd_send_command()")Signed-off-by Can Guo <[email protected]>drivers/ufs/core/ufshcd.c +0
-0@@ -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
-1int 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]>