Stress-testing Allwinner T527 VIP9000 NPU with jobs from multiple
processes, I observed occasional failures where a "MMU fault (slave not
present)" error would occur and cause a GPU hang and cancelled job.
This happens when pending jobs from multiple processes have been written
into the hardware command ring, and the hardware is able to iterate
through them at speed, switching into different MMU contexts.
I observed that the vendor kernel driver (galcore) sets some Stall FE
Prefetch bits on the semaphore and stall tokens on some devices, and
setting those bits completely eliminates the failure observed. My theory
is that the NPU concurrently prefetches some data ready for execution of
the next job, but in this case it was prefetching them from the MMU
context currently being executed, rather than from the context of the
next job. Setting these bits delays that prefetch accordingly.
Set the appropriate bits in CMD_SEM() and CMD_STALL() when the hardware
flags suggest. This matches the vendor behaviour and completely
eliminates the failures observed in the original test.
Fixes: 17e4660ae3d7 ("drm/etnaviv: implement per-process address spaces on
MMUv2")
Signed-off-by: Daniel Drake <[email protected]>
---
drivers/gpu/drm/etnaviv/etnaviv_buffer.c | 53 +++++++++++++++++-----------
drivers/gpu/drm/etnaviv/etnaviv_buffer.h | 12 ++++---
drivers/gpu/drm/etnaviv/etnaviv_flop_reset.c | 4 +--
3 files changed, 43 insertions(+), 26 deletions(-)
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_buffer.c
b/drivers/gpu/drm/etnaviv/etnaviv_buffer.c
index 99c91a9eecf1..87946dbe62ef 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_buffer.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_buffer.c
@@ -21,10 +21,20 @@
#include "etnaviv_flop_reset.h"
+static u32 etnaviv_stall_prefetch(struct etnaviv_gpu *gpu)
+{
+ if (gpu->identity.minor_features5 &
+ chipMinorFeatures5_FE_ALLOW_STALL_PREFETCH_ENG)
+ return 0x3;
+
+ return 0;
+}
+
static void etnaviv_cmd_select_pipe(struct etnaviv_gpu *gpu,
struct etnaviv_cmdbuf *buffer, u8 pipe)
{
u32 flush = 0;
+ u32 stall_prefetch = etnaviv_stall_prefetch(gpu);
lockdep_assert_held(&gpu->lock);
@@ -40,8 +50,8 @@ static void etnaviv_cmd_select_pipe(struct etnaviv_gpu *gpu,
flush = VIVS_GL_FLUSH_CACHE_DEPTH | VIVS_GL_FLUSH_CACHE_COLOR;
CMD_LOAD_STATE(buffer, VIVS_GL_FLUSH_CACHE, 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_prefetch);
+ CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE, stall_prefetch);
CMD_LOAD_STATE(buffer, VIVS_GL_PIPE_SELECT,
VIVS_GL_PIPE_SELECT_PIPE(pipe));
@@ -118,6 +128,7 @@ u16 etnaviv_buffer_init(struct etnaviv_gpu *gpu)
u16 etnaviv_buffer_config_mmuv2(struct etnaviv_gpu *gpu, u32 mtlb_addr, u32
safe_addr)
{
struct etnaviv_cmdbuf *buffer = &gpu->buffer;
+ u32 stall_prefetch = etnaviv_stall_prefetch(gpu);
lockdep_assert_held(&gpu->lock);
@@ -129,8 +140,8 @@ u16 etnaviv_buffer_config_mmuv2(struct etnaviv_gpu *gpu,
u32 mtlb_addr, u32 safe
CMD_LOAD_STATE(buffer, VIVS_MMUv2_CONFIGURATION,
mtlb_addr | VIVS_MMUv2_CONFIGURATION_MODE_MODE4_K);
CMD_LOAD_STATE(buffer, VIVS_MMUv2_SAFE_ADDRESS, safe_addr);
- 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_prefetch);
+ CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE,
stall_prefetch);
}
if (gpu->identity.features & chipFeatures_PIPE_2D) {
@@ -139,8 +150,8 @@ u16 etnaviv_buffer_config_mmuv2(struct etnaviv_gpu *gpu,
u32 mtlb_addr, u32 safe
CMD_LOAD_STATE(buffer, VIVS_MMUv2_CONFIGURATION,
mtlb_addr | VIVS_MMUv2_CONFIGURATION_MODE_MODE4_K);
CMD_LOAD_STATE(buffer, VIVS_MMUv2_SAFE_ADDRESS, safe_addr);
- 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_prefetch);
+ CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE,
stall_prefetch);
}
CMD_END(buffer);
@@ -186,6 +197,7 @@ void etnaviv_buffer_end(struct etnaviv_gpu *gpu)
u32 link_target, flush = 0;
bool has_blt = !!(gpu->identity.minor_features5 &
chipMinorFeatures5_BLT_ENGINE);
+ u32 stall_prefetch = etnaviv_stall_prefetch(gpu);
lockdep_assert_held(&gpu->lock);
@@ -206,23 +218,23 @@ void etnaviv_buffer_end(struct etnaviv_gpu *gpu)
link_target = etnaviv_buffer_reserve(gpu, buffer, dwords);
- 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_prefetch);
+ CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE,
stall_prefetch);
if (has_blt) {
CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x1);
- CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT);
- CMD_STALL(buffer, SYNC_RECIPIENT_FE,
SYNC_RECIPIENT_BLT);
+ CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT,
stall_prefetch);
+ CMD_STALL(buffer, SYNC_RECIPIENT_FE,
SYNC_RECIPIENT_BLT, stall_prefetch);
CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x0);
}
CMD_LOAD_STATE(buffer, VIVS_GL_FLUSH_CACHE, flush);
if (gpu->exec_state == ETNA_PIPE_3D)
etnaviv_cmd_flush_ts(buffer, has_blt);
- 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_prefetch);
+ CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE,
stall_prefetch);
if (has_blt) {
CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x1);
- CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT);
- CMD_STALL(buffer, SYNC_RECIPIENT_FE,
SYNC_RECIPIENT_BLT);
+ CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT,
stall_prefetch);
+ CMD_STALL(buffer, SYNC_RECIPIENT_FE,
SYNC_RECIPIENT_BLT, stall_prefetch);
CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x0);
}
CMD_END(buffer);
@@ -292,6 +304,7 @@ 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);
+ u32 stall_prefetch = etnaviv_stall_prefetch(gpu);
lockdep_assert_held(&gpu->lock);
@@ -371,9 +384,9 @@ 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);
+ SYNC_RECIPIENT_PE, stall_prefetch);
CMD_STALL(buffer, SYNC_RECIPIENT_FE,
- SYNC_RECIPIENT_PE);
+ SYNC_RECIPIENT_PE, stall_prefetch);
}
gpu->flush_seq = new_flush_seq;
@@ -427,13 +440,13 @@ void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32
exec_state,
VIVS_GL_FLUSH_CACHE_SHADER_L1);
etnaviv_cmd_flush_ts(buffer, has_blt);
}
- 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_prefetch);
+ CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE, stall_prefetch);
if (has_blt) {
CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x1);
- CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT);
- CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT);
+ CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT,
stall_prefetch);
+ CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT,
stall_prefetch);
CMD_LOAD_STATE(buffer, VIVS_BLT_ENABLE, 0x0);
}
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_buffer.h
b/drivers/gpu/drm/etnaviv/etnaviv_buffer.h
index 4331ca8aac47..48039805f4c5 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_buffer.h
+++ b/drivers/gpu/drm/etnaviv/etnaviv_buffer.h
@@ -81,19 +81,23 @@ 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,
+ u32 stall_prefetch)
{
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, VIV_FE_STALL_TOKEN_FROM(from) | VIV_FE_STALL_TOKEN_TO(to) |
+ VIV_FE_STALL_TOKEN_UNK28(stall_prefetch));
}
-static inline void CMD_SEM(struct etnaviv_cmdbuf *buffer, u32 from, u32 to)
+static inline void CMD_SEM(struct etnaviv_cmdbuf *buffer, u32 from, u32 to,
+ u32 stall_prefetch)
{
CMD_LOAD_STATE(buffer, VIVS_GL_SEMAPHORE_TOKEN,
VIVS_GL_SEMAPHORE_TOKEN_FROM(from) |
- VIVS_GL_SEMAPHORE_TOKEN_TO(to));
+ VIVS_GL_SEMAPHORE_TOKEN_TO(to) |
+ VIVS_GL_SEMAPHORE_TOKEN_UNK28(stall_prefetch));
}
#endif /* __ETNAVIV_BUFFER_H__ */
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_flop_reset.c
b/drivers/gpu/drm/etnaviv/etnaviv_flop_reset.c
index eb4b253ff835..ab9ee66efad2 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_flop_reset.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_flop_reset.c
@@ -32,8 +32,8 @@ static void etnaviv_emit_flop_reset_state_ppu(struct
etnaviv_cmdbuf *cmdbuf,
u32 shader_register_count)
{
CMD_LOAD_STATE(cmdbuf, VIVS_GL_API_MODE, VIVS_GL_API_MODE_OPENCL);
- CMD_SEM(cmdbuf, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
- CMD_STALL(cmdbuf, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
+ CMD_SEM(cmdbuf, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE, 0);
+ CMD_STALL(cmdbuf, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE, 0);
CMD_LOAD_STATES_START(cmdbuf, VIVS_SH_HALTI5_UNIFORMS(0), 4);
---
base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d
change-id: 20261201-etnaviv-stall-prefetch-7f5cf1f68ec1
Best regards,
--
Daniel Drake <[email protected]>