drm/amdgpu/gfx12: flush the scratch register write in the ring test
Subsystems (2)
PATCH 1/1 drm/amdgpu/gfx12: flush the scratch register write in the ring test
The ring test writes 0xCAFEDEAD to SCRATCH_REG0 through MMIO, rings the doorbell for the CP to write 0xDEADBEEF with SET_UCONFIG_REG, and polls for the new value.
Nothing orders the posted MMIO write against the CP's write: the doorbell reaches the CP on another path. With coarse grain clock gating, a GC register access from the host takes about 2 us, and an awake CP can execute the packet before the 0xCAFEDEAD write lands. The test then reads 0xCAFEDEAD forever and fails, although the ring consumed the packet (rptr == wptr).
On Navi48, 39 of 10000 back-to-back compute ring tests failed this way. None failed when a GC register was read back after the write, or with CGCG disabled.
Ring tests run on every queue, pipe and IP reset, and a false failure there escalates the recovery to a full GPU reset.
Read the scratch register back before ringing the doorbell, as commit 3f69d5860f5b ("drm/amdgpu: Add a read to GFX v9.4.3 ring test") does for a similar race on gfx 9.4.3 with multiple XCCs.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +5 -0
@@ -458,6 +458,11 @@ static int gfx_v12_0_ring_test_ring(struct amdgpu_ring *ring)int r;WREG32 (scratch,0xCAFEDEAD ); +/* +* Read the value back so the posted write reaches the register before +* the CP writes the test value; otherwise it can overwrite the result. +*/ +RREG32 (scratch); r =amdgpu_ring_alloc (ring,5 );if (r) { drm_err(adev_to_drm(adev),
Signature · 1 line
2.50.1
Quoted 15 lines · Jesse Zhang
The ring test writes
0xCAFEDEADtoSCRATCH_REG0through MMIO, rings the doorbell for the CP to write0xDEADBEEFwithSET_UCONFIG_REG, and polls for the new value.Nothing orders the posted MMIO write against the CP's write: the doorbell reaches the CP on another path. With coarse grain clock gating, a GC register access from the host takes about 2 us, and an awake CP can execute the packet before the
0xCAFEDEADwrite lands. The test then reads0xCAFEDEADforever and fails, although the ring consumed the packet (rptr == wptr).On Navi48, 39 of 10000 back-to-back compute ring tests failed this way. None failed when a GC register was read back after the write, or with CGCG disabled.
Quoted 8 lines
Ring tests run on every queue, pipe and IP reset, and a false failure there escalates the recovery to a full GPU reset.
Read the scratch register back before ringing the doorbell, as commit
3f69d5860f5b("drm/amdgpu: Add a read to GFX v9.4.3 ring test") does for a similar race on gfx 9.4.3 with multiple XCCs.Signed-off-by Jesse Zhang <[email protected]>
Thanks,
Lijo
Quoted 20 lines
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +5
-0@@ -458,6 +458,11 @@ static int gfx_v12_0_ring_test_ring(struct amdgpu_ring *ring)int r;WREG32 (scratch,0xCAFEDEAD ); +/* +* Read the value back so the posted write reaches the register before +* the CP writes the test value; otherwise it can overwrite the result. +*/ +RREG32 (scratch); r =amdgpu_ring_alloc (ring,5 );if (r) { drm_err(adev_to_drm(adev),
Deucher, Alexander
maintainerAMD General
Quoted 25 lines
-----Original Message-----
From: Jesse Zhang <[email protected]>
Sent: Friday, October 23, 2026 2:30 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Mario Sopena-Novales <[email protected]>; Caike, Igor <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH] drm/amdgpu/gfx12: flush the scratch register write in the ring testThe ring test writes
0xCAFEDEADtoSCRATCH_REG0through MMIO, rings the doorbell for the CP to write0xDEADBEEFwithSET_UCONFIG_REG, and polls for the new value.Nothing orders the posted MMIO write against the CP's write: the doorbell reaches the CP on another path. With coarse grain clock gating, a GC register access from the host takes about 2 us, and an awake CP can execute the packet before the
0xCAFEDEADwrite lands. The test then reads0xCAFEDEADforever and fails, although the ring consumed the packet (rptr == wptr).On Navi48, 39 of 10000 back-to-back compute ring tests failed this way. None failed when a GC register was read back after the write, or with CGCG disabled.
Quoted 6 lines
Ring tests run on every queue, pipe and IP reset, and a false failure there escalates the recovery to a full GPU reset.
Read the scratch register back before ringing the doorbell, as commit
3f69d5860f5b("drm/amdgpu: Add a read to GFX v9.4.3 ring test") does for a similar race on gfx 9.4.3 with multiple XCCs.
Seems like we should do this for all gfx versions. Can you check the others and fix them up as well?
Alex
Quoted 26 lines
Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +5
-0@@ -458,6 +458,11 @@ static int gfx_v12_0_ring_test_ring(struct amdgpu_ring *ring)int r;WREG32 (scratch,0xCAFEDEAD ); +/* +* Read the value back so the posted write reaches the register before +* the CP writes the test value; otherwise it can overwrite the result. +*/ +RREG32 (scratch); r =amdgpu_ring_alloc (ring,5 );if (r) {drm_err(adev_to_drm(adev),--
2.50.1
Christian König
maintainerQuoted 27 lines · Alexander
AMD General
Quoted 25 lines
-----Original Message-----
From: Jesse Zhang <[email protected]>
Sent: Friday, October 23, 2026 2:30 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Mario Sopena-Novales <[email protected]>; Caike, Igor <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH] drm/amdgpu/gfx12: flush the scratch register write in the ring testThe ring test writes
0xCAFEDEADtoSCRATCH_REG0through MMIO, rings the doorbell for the CP to write0xDEADBEEFwithSET_UCONFIG_REG, and polls for the new value.Nothing orders the posted MMIO write against the CP's write: the doorbell reaches the CP on another path. With coarse grain clock gating, a GC register access from the host takes about 2 us, and an awake CP can execute the packet before the
0xCAFEDEADwrite lands. The test then reads0xCAFEDEADforever and fails, although the ring consumed the packet (rptr == wptr).On Navi48, 39 of 10000 back-to-back compute ring tests failed this way. None failed when a GC register was read back after the write, or with CGCG disabled.
Quoted 8 lines
Quoted 6 lines
Ring tests run on every queue, pipe and IP reset, and a false failure there escalates the recovery to a full GPU reset.
Read the scratch register back before ringing the doorbell, as commit
3f69d5860f5b("drm/amdgpu: Add a read to GFX v9.4.3 ring test") does for a similar race on gfx 9.4.3 with multiple XCCs.Seems like we should do this for all gfx versions. Can you check the others and fix them up as well?
IIRC we removed exactly that ages ago because we have the dependency that WREG32 writes are ordered with doorbell writes on many other places as well.
If that isn't the case we have a much larger problem here at hand and potentially need to fix the doorbell write functions instead.
Regards,
Christian.
Quoted 30 lines
Alex
Quoted 26 lines
Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +5
-0@@ -458,6 +458,11 @@ static int gfx_v12_0_ring_test_ring(struct amdgpu_ring *ring)int r;WREG32 (scratch,0xCAFEDEAD ); +/* +* Read the value back so the posted write reaches the register before +* the CP writes the test value; otherwise it can overwrite the result. +*/ +RREG32 (scratch); r =amdgpu_ring_alloc (ring,5 );if (r) {drm_err(adev_to_drm(adev),--
2.50.1