diff mbox series

scsi: hisi_sas: Fix memory ordering in hisi_sas_task_deliver()

Message ID 1652774661-12935-1-git-send-email-john.garry@huawei.com
State New
Headers show
Series scsi: hisi_sas: Fix memory ordering in hisi_sas_task_deliver() | expand

Commit Message

John Garry May 17, 2022, 8:04 a.m. UTC
The memories for the slot should be observed to be written prior to
observing the slot as ready.

Prior to commit 26fc0ea74fcb ("scsi: libsas: Drop SAS_TASK_AT_INITIATOR"),
we had a spin_lock() + spin_unlock() immediately before marking the slot
as ready. The spin_unlock() - with release semantics - caused the slot
memory to be observed to be written.

Now that the spin_lock() + spin_unlock() is gone, use a smp_wmb().

Fixes: 26fc0ea74fcb ("scsi: libsas: Drop SAS_TASK_AT_INITIATOR")
Reported-by: Yihang Li <liyihang6@hisilicon.com>
Tested-by: Yihang Li <liyihang6@hisilicon.com>
Signed-off-by: John Garry <john.garry@huawei.com>
---
Hi Martin, Please consider for v5.18, thanks!

Comments

Martin K. Petersen May 20, 2022, 1:09 a.m. UTC | #1
On Tue, 17 May 2022 16:04:21 +0800, John Garry wrote:

> The memories for the slot should be observed to be written prior to
> observing the slot as ready.
> 
> Prior to commit 26fc0ea74fcb ("scsi: libsas: Drop SAS_TASK_AT_INITIATOR"),
> we had a spin_lock() + spin_unlock() immediately before marking the slot
> as ready. The spin_unlock() - with release semantics - caused the slot
> memory to be observed to be written.
> 
> [...]

Applied to 5.19/scsi-queue, thanks!

[1/1] scsi: hisi_sas: Fix memory ordering in hisi_sas_task_deliver()
      https://git.kernel.org/mkp/scsi/c/6c6ac8b7773f
diff mbox series

Patch

diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c
index 4bda2f6cb352..f56dd01230ce 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_main.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_main.c
@@ -446,6 +446,8 @@  void hisi_sas_task_deliver(struct hisi_hba *hisi_hba,
 		return;
 	}
 
+	/* Make slot memories observable before marking as ready */
+	smp_wmb();
 	WRITE_ONCE(slot->ready, 1);
 
 	spin_lock(&dq->lock);