Skip to content

Commit 1c09b66

Browse files
Xiaofei Tanmartinkpetersen
authored andcommitted
scsi: hisi_sas: add memory barrier in task delivery function
In task start delivery function, we need to add a memory barrier to prevent re-ordering of reading memory by hardware. Because the slot data is set in task prepare function and it could be running in another CPU. This patch adds an memory barrier after s->ready is read in the task start delivery function, and uses WRITE_ONCE() in the places where s->ready is set to ensure that the compiler does not re-order. Signed-off-by: Xiaofei Tan <tanxiaofei@huawei.com> Signed-off-by: John Garry <john.garry@huawei.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 6cca51e commit 1c09b66

4 files changed

Lines changed: 32 additions & 17 deletions

File tree

‎drivers/scsi/hisi_sas/hisi_sas_main.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ static int hisi_sas_task_prep(struct sas_task *task,
446446
spin_unlock_irqrestore(&task->task_state_lock, flags);
447447

448448
++(*pass);
449-
slot->ready = 1;
449+
WRITE_ONCE(slot->ready, 1);
450450

451451
return 0;
452452

@@ -1749,7 +1749,7 @@ hisi_sas_internal_abort_task_exec(struct hisi_hba *hisi_hba, int device_id,
17491749
task->task_state_flags |= SAS_TASK_AT_INITIATOR;
17501750
spin_unlock_irqrestore(&task->task_state_lock, flags);
17511751

1752-
slot->ready = 1;
1752+
WRITE_ONCE(slot->ready, 1);
17531753
/* send abort command to the chip */
17541754
spin_lock_irqsave(&dq->lock, flags);
17551755
list_add_tail(&slot->entry, &sas_dev->list);

‎drivers/scsi/hisi_sas/hisi_sas_v1_hw.c‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -903,23 +903,28 @@ get_free_slot_v1_hw(struct hisi_hba *hisi_hba, struct hisi_sas_dq *dq)
903903
static void start_delivery_v1_hw(struct hisi_sas_dq *dq)
904904
{
905905
struct hisi_hba *hisi_hba = dq->hisi_hba;
906-
struct hisi_sas_slot *s, *s1;
906+
struct hisi_sas_slot *s, *s1, *s2 = NULL;
907907
struct list_head *dq_list;
908908
int dlvry_queue = dq->id;
909-
int wp, count = 0;
909+
int wp;
910910

911911
dq_list = &dq->list;
912912
list_for_each_entry_safe(s, s1, &dq->list, delivery) {
913913
if (!s->ready)
914914
break;
915-
count++;
916-
wp = (s->dlvry_queue_slot + 1) % HISI_SAS_QUEUE_SLOTS;
915+
s2 = s;
917916
list_del(&s->delivery);
918917
}
919918

920-
if (!count)
919+
if (!s2)
921920
return;
922921

922+
/*
923+
* Ensure that memories for slots built on other CPUs is observed.
924+
*/
925+
smp_rmb();
926+
wp = (s2->dlvry_queue_slot + 1) % HISI_SAS_QUEUE_SLOTS;
927+
923928
hisi_sas_write32(hisi_hba, DLVRY_Q_0_WR_PTR + (dlvry_queue * 0x14), wp);
924929
}
925930

‎drivers/scsi/hisi_sas/hisi_sas_v2_hw.c‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,23 +1665,28 @@ get_free_slot_v2_hw(struct hisi_hba *hisi_hba, struct hisi_sas_dq *dq)
16651665
static void start_delivery_v2_hw(struct hisi_sas_dq *dq)
16661666
{
16671667
struct hisi_hba *hisi_hba = dq->hisi_hba;
1668-
struct hisi_sas_slot *s, *s1;
1668+
struct hisi_sas_slot *s, *s1, *s2 = NULL;
16691669
struct list_head *dq_list;
16701670
int dlvry_queue = dq->id;
1671-
int wp, count = 0;
1671+
int wp;
16721672

16731673
dq_list = &dq->list;
16741674
list_for_each_entry_safe(s, s1, &dq->list, delivery) {
16751675
if (!s->ready)
16761676
break;
1677-
count++;
1678-
wp = (s->dlvry_queue_slot + 1) % HISI_SAS_QUEUE_SLOTS;
1677+
s2 = s;
16791678
list_del(&s->delivery);
16801679
}
16811680

1682-
if (!count)
1681+
if (!s2)
16831682
return;
16841683

1684+
/*
1685+
* Ensure that memories for slots built on other CPUs is observed.
1686+
*/
1687+
smp_rmb();
1688+
wp = (s2->dlvry_queue_slot + 1) % HISI_SAS_QUEUE_SLOTS;
1689+
16851690
hisi_sas_write32(hisi_hba, DLVRY_Q_0_WR_PTR + (dlvry_queue * 0x14), wp);
16861691
}
16871692

‎drivers/scsi/hisi_sas/hisi_sas_v3_hw.c‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -882,23 +882,28 @@ get_free_slot_v3_hw(struct hisi_hba *hisi_hba, struct hisi_sas_dq *dq)
882882
static void start_delivery_v3_hw(struct hisi_sas_dq *dq)
883883
{
884884
struct hisi_hba *hisi_hba = dq->hisi_hba;
885-
struct hisi_sas_slot *s, *s1;
885+
struct hisi_sas_slot *s, *s1, *s2 = NULL;
886886
struct list_head *dq_list;
887887
int dlvry_queue = dq->id;
888-
int wp, count = 0;
888+
int wp;
889889

890890
dq_list = &dq->list;
891891
list_for_each_entry_safe(s, s1, &dq->list, delivery) {
892892
if (!s->ready)
893893
break;
894-
count++;
895-
wp = (s->dlvry_queue_slot + 1) % HISI_SAS_QUEUE_SLOTS;
894+
s2 = s;
896895
list_del(&s->delivery);
897896
}
898897

899-
if (!count)
898+
if (!s2)
900899
return;
901900

901+
/*
902+
* Ensure that memories for slots built on other CPUs is observed.
903+
*/
904+
smp_rmb();
905+
wp = (s2->dlvry_queue_slot + 1) % HISI_SAS_QUEUE_SLOTS;
906+
902907
hisi_sas_write32(hisi_hba, DLVRY_Q_0_WR_PTR + (dlvry_queue * 0x14), wp);
903908
}
904909

0 commit comments

Comments
 (0)