scsi: ufs: core: Let the sq_lock protect sq_tail_slot access
authorCan Guo <quic_cang@quicinc.com>
Mon, 18 Dec 2023 15:32:17 +0000 (07:32 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 1 Jan 2024 12:42:37 +0000 (12:42 +0000)
commit1f7213358d846079b88c22ab8b7eb1f5652037c2
treea08147a8d650b32ba656f95d21909587c2ea88d2
parenta8409bcc324347bcb6abff033fffc3ab8be1c819
scsi: ufs: core: Let the sq_lock protect sq_tail_slot access

[ Upstream commit 04c116e2bdfc3969f9819d2cebfdf678353c354c ]

When accessing sq_tail_slot without protection from sq_lock, a race
condition can cause multiple SQEs to be copied to duplicate SQE slots. This
can lead to multiple stability issues. Fix this 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()")
Signed-off-by: Can Guo <quic_cang@quicinc.com>
Link: https://lore.kernel.org/r/1702913550-20631-1-git-send-email-quic_cang@quicinc.com
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/ufs/core/ufshcd.c