Skip to content

Commit f4cfdda

Browse files
akhilpo-qcomgregkh
authored andcommitted
drm/msm/a6xx: Use barriers while updating HFI Q headers
[ Upstream commit dc78b35 ] To avoid harmful compiler optimizations and IO reordering in the HW, use barriers and READ/WRITE_ONCE helpers as necessary while accessing the HFI queue index variables. Fixes: 4b565ca ("drm/msm: Add A6XX device support") Signed-off-by: Akhil P Oommen <akhilpo@oss.qualcomm.com> Patchwork: https://patchwork.freedesktop.org/patch/714653/ Message-ID: <20260327-a8xx-gpu-batch2-v2-1-2b53c38d2101@oss.qualcomm.com> Signed-off-by: Rob Clark <robin.clark@oss.qualcomm.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6ce39e2 commit f4cfdda

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

drivers/gpu/drm/msm/adreno/a6xx_hfi.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static int a6xx_hfi_queue_read(struct a6xx_gmu *gmu,
3434
struct a6xx_hfi_queue_header *header = queue->header;
3535
u32 i, hdr, index = header->read_index;
3636

37-
if (header->read_index == header->write_index) {
37+
if (header->read_index == READ_ONCE(header->write_index)) {
3838
header->rx_request = 1;
3939
return 0;
4040
}
@@ -62,7 +62,10 @@ static int a6xx_hfi_queue_read(struct a6xx_gmu *gmu,
6262
if (!gmu->legacy)
6363
index = ALIGN(index, 4) % header->size;
6464

65-
header->read_index = index;
65+
/* Ensure all memory operations are complete before updating the read index */
66+
dma_mb();
67+
68+
WRITE_ONCE(header->read_index, index);
6669
return HFI_HEADER_SIZE(hdr);
6770
}
6871

@@ -74,7 +77,7 @@ static int a6xx_hfi_queue_write(struct a6xx_gmu *gmu,
7477

7578
spin_lock(&queue->lock);
7679

77-
space = CIRC_SPACE(header->write_index, header->read_index,
80+
space = CIRC_SPACE(header->write_index, READ_ONCE(header->read_index),
7881
header->size);
7982
if (space < dwords) {
8083
header->dropped++;
@@ -95,7 +98,10 @@ static int a6xx_hfi_queue_write(struct a6xx_gmu *gmu,
9598
queue->data[index] = 0xfafafafa;
9699
}
97100

98-
header->write_index = index;
101+
/* Ensure all memory operations are complete before updating the write index */
102+
dma_mb();
103+
104+
WRITE_ONCE(header->write_index, index);
99105
spin_unlock(&queue->lock);
100106

101107
gmu_write(gmu, REG_A6XX_GMU_HOST2GMU_INTR_SET, 0x01);

0 commit comments

Comments
 (0)