From: Christian Gmeiner <[email protected]>

The FE prefetch engine can run ahead of an MMUv2 flush and use stale
translations. This shows up as a spurious MMU fault. Stall the prefetch
with the flush, like gckHARDWARE_FlushMMU(..) in galcore.

Fixes: 2e145a224866 ("drm/etnaviv: add flushing logic for MMUv2")
Signed-off-by: Christian Gmeiner <[email protected]>
---
Daniel Drake posted a fix for the same problem on a VIP9000 NPU [1]. I
found the same root cause earlier this year on a GC7000L with softpin,
where parallel dEQP runs end in MMU faults on pages that are mapped.

Daniel's patch sets the stall prefetch bits on every semaphore and stall
token. galcore sets them only in its MMU sequences:
gckHARDWARE_FlushMMU(..), gckHARDWARE_FlushAsyncMMU(..) and
gckHARDWARE_SwitchSecurityMode(..). This patch follows galcore and sets
them only for the MMUv2 flush in etnaviv_buffer_queue(..). An MMU
context switch goes through the same flush.

[1] 
https://lore.kernel.org/all/[email protected]/
---
 drivers/gpu/drm/etnaviv/etnaviv_buffer.c | 10 ++++++----
 drivers/gpu/drm/etnaviv/etnaviv_buffer.h | 31 ++++++++++++++++++++++++++-----
 2 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/etnaviv/etnaviv_buffer.c 
b/drivers/gpu/drm/etnaviv/etnaviv_buffer.c
index 99c91a9eecf1..162c98e903e4 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_buffer.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_buffer.c
@@ -292,6 +292,8 @@ void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 
exec_state,
        bool need_flush = switch_mmu_context || gpu->flush_seq != new_flush_seq;
        bool has_blt = !!(gpu->identity.minor_features5 &
                          chipMinorFeatures5_BLT_ENGINE);
+       bool stall_fe_prefetch = !!(gpu->identity.minor_features5 &
+                                   
chipMinorFeatures5_FE_ALLOW_STALL_PREFETCH_ENG);
 
        lockdep_assert_held(&gpu->lock);
 
@@ -370,10 +372,10 @@ void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 
exec_state,
 
                                CMD_LOAD_STATE(buffer, VIVS_MMUv2_CONFIGURATION,
                                               flush);
-                               CMD_SEM(buffer, SYNC_RECIPIENT_FE,
-                                       SYNC_RECIPIENT_PE);
-                               CMD_STALL(buffer, SYNC_RECIPIENT_FE,
-                                       SYNC_RECIPIENT_PE);
+                               __CMD_SEM(buffer, SYNC_RECIPIENT_FE,
+                                         SYNC_RECIPIENT_PE, stall_fe_prefetch);
+                               __CMD_STALL(buffer, SYNC_RECIPIENT_FE,
+                                           SYNC_RECIPIENT_PE, 
stall_fe_prefetch);
                        }
 
                        gpu->flush_seq = new_flush_seq;
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_buffer.h 
b/drivers/gpu/drm/etnaviv/etnaviv_buffer.h
index 4331ca8aac47..9b5e2c4ae2af 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_buffer.h
+++ b/drivers/gpu/drm/etnaviv/etnaviv_buffer.h
@@ -81,19 +81,40 @@ static inline void CMD_LINK(struct etnaviv_cmdbuf *buffer, 
u16 prefetch,
        OUT(buffer, address);
 }
 
-static inline void CMD_STALL(struct etnaviv_cmdbuf *buffer, u32 from, u32 to)
+static inline void __CMD_STALL(struct etnaviv_cmdbuf *buffer, u32 from, u32 to,
+                              bool stall_prefetch)
 {
+       u32 token = VIV_FE_STALL_TOKEN_FROM(from) | VIV_FE_STALL_TOKEN_TO(to);
+
+       if (stall_prefetch)
+               token |= VIV_FE_STALL_TOKEN_UNK28__MASK;
+
        buffer->user_size = ALIGN(buffer->user_size, 8);
 
        OUT(buffer, VIV_FE_STALL_HEADER_OP_STALL);
-       OUT(buffer, VIV_FE_STALL_TOKEN_FROM(from) | VIV_FE_STALL_TOKEN_TO(to));
+       OUT(buffer, token);
+}
+
+static inline void CMD_STALL(struct etnaviv_cmdbuf *buffer, u32 from, u32 to)
+{
+       __CMD_STALL(buffer, from, to, false);
+}
+
+static inline void __CMD_SEM(struct etnaviv_cmdbuf *buffer, u32 from, u32 to,
+                            bool stall_prefetch)
+{
+       u32 token = VIVS_GL_SEMAPHORE_TOKEN_FROM(from) |
+                   VIVS_GL_SEMAPHORE_TOKEN_TO(to);
+
+       if (stall_prefetch)
+               token |= VIVS_GL_SEMAPHORE_TOKEN_UNK28__MASK;
+
+       CMD_LOAD_STATE(buffer, VIVS_GL_SEMAPHORE_TOKEN, token);
 }
 
 static inline void CMD_SEM(struct etnaviv_cmdbuf *buffer, u32 from, u32 to)
 {
-       CMD_LOAD_STATE(buffer, VIVS_GL_SEMAPHORE_TOKEN,
-                      VIVS_GL_SEMAPHORE_TOKEN_FROM(from) |
-                              VIVS_GL_SEMAPHORE_TOKEN_TO(to));
+       __CMD_SEM(buffer, from, to, false);
 }
 
 #endif /* __ETNAVIV_BUFFER_H__ */

---
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
change-id: 20261201-etnaviv-stall-fe-prefetch-40cd052426ea

Best regards,
-- 
Christian Gmeiner <[email protected]>

Reply via email to