drm/amdgpu/gfx6: flush the scratch register write in the ring and IB tests
Subsystems (2)
PATCH v2 1/7 drm/amdgpu/gfx6: flush the scratch register write in the ring and IB tests
The ring and IB tests write 0xCAFEDEAD to SCRATCH_REG0 through MMIO, then have the CP write 0xDEADBEEF to it and check for the new value.
Nothing orders the posted MMIO write against the CP's write, so it can land after it. The test then reads 0xCAFEDEAD and fails, although the CP executed the packet.
Read the scratch register back before submitting the packet.
--- drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c +4 -0
@@ -1875,6 +1875,8 @@ static int gfx_v6_0_ring_test_ring(struct amdgpu_ring *ring)int r;WREG32 (mmSCRATCH_REG0,0xCAFEDEAD ); +/* Flush the posted write before the CP writes the test value. */ +RREG32 (mmSCRATCH_REG0); r =amdgpu_ring_alloc (ring,3 );if (r)
@@ -1979,6 +1981,8 @@ static int gfx_v6_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)long r;WREG32 (mmSCRATCH_REG0,0xCAFEDEAD ); +/* Flush the posted write before the CP writes the test value. */ +RREG32 (mmSCRATCH_REG0); r = amdgpu_job_alloc_with_ib(adev, NULL, NULL, 256, AMDGPU_IB_POOL_DIRECT, AMDGPU_KERNEL_JOB_ID_GFX_RING_TEST,
Signature · 1 line
2.50.1
PATCH v2 2/7 drm/amdgpu/gfx7: flush the scratch register write in the ring and IB tests
The ring and IB tests write 0xCAFEDEAD to SCRATCH_REG0 through MMIO, then have the CP write 0xDEADBEEF to it and check for the new value.
Nothing orders the posted MMIO write against the CP's write, so it can land after it. The test then reads 0xCAFEDEAD and fails, although the CP executed the packet.
Read the scratch register back before submitting the packet.
--- drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +4 -0
@@ -2039,6 +2039,8 @@ static int gfx_v7_0_ring_test_ring(struct amdgpu_ring *ring)int r;WREG32 (mmSCRATCH_REG0,0xCAFEDEAD ); +/* Flush the posted write before the CP writes the test value. */ +RREG32 (mmSCRATCH_REG0); r =amdgpu_ring_alloc (ring,3 );if (r)return r;
@@ -2299,6 +2301,8 @@ static int gfx_v7_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)long r;WREG32 (mmSCRATCH_REG0,0xCAFEDEAD ); +/* Flush the posted write before the CP writes the test value. */ +RREG32 (mmSCRATCH_REG0); r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL, 256, AMDGPU_IB_POOL_DIRECT,
Signature · 1 line
2.50.1
PATCH v2 3/7 drm/amdgpu/gfx8: flush the scratch register write in the ring test
In reply to Jesse ZhangThe ring test writes 0xCAFEDEAD to SCRATCH_REG0 through MMIO, then has the CP write 0xDEADBEEF to it and polls for the new value.
Nothing orders the posted MMIO write against the CP's write, so it can land after it. The test then reads 0xCAFEDEAD forever and fails, although the CP executed the packet. A false ring test failure in a queue or pipe reset escalates the recovery to a full GPU reset.
Read the scratch register back before submitting the packet.
--- drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +2 -0
@@ -843,6 +843,8 @@ static int gfx_v8_0_ring_test_ring(struct amdgpu_ring *ring)int r;WREG32 (mmSCRATCH_REG0,0xCAFEDEAD ); +/* Flush the posted write before the CP writes the test value. */ +RREG32 (mmSCRATCH_REG0); r =amdgpu_ring_alloc (ring,3 );if (r)return r;
Signature · 1 line
2.50.1
PATCH v2 4/7 drm/amdgpu/gfx9: flush the scratch register write in the ring test
In reply to Jesse ZhangThe ring test writes 0xCAFEDEAD to SCRATCH_REG0 through MMIO, then has the CP write 0xDEADBEEF to it and polls for the new value.
Nothing orders the posted MMIO write against the CP's write, so it can land after it. The test then reads 0xCAFEDEAD forever and fails, although the CP executed the packet. A false ring test failure in a queue or pipe reset escalates the recovery to a full GPU reset.
Read the scratch register back before submitting the packet.
--- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -0
@@ -1200,6 +1200,8 @@ static int gfx_v9_0_ring_test_ring(struct amdgpu_ring *ring)int r;WREG32 (scratch,0xCAFEDEAD ); +/* Flush the posted write before the CP writes the test value. */ +RREG32 (scratch); r =amdgpu_ring_alloc (ring,3 );if (r)return r;
Signature · 1 line
2.50.1
PATCH v2 5/7 drm/amdgpu/gfx10: flush the scratch register write in the ring test
In reply to Jesse ZhangThe ring test writes 0xCAFEDEAD to SCRATCH_REG0 through MMIO, then has the CP write 0xDEADBEEF to it and polls for the new value.
Nothing orders the posted MMIO write against the CP's write, so it can land after it. The test then reads 0xCAFEDEAD forever and fails, although the CP executed the packet. A false ring test failure in a queue or pipe reset escalates the recovery to a full GPU reset.
Read the scratch register back before submitting the packet.
--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +2 -0
@@ -4039,6 +4039,8 @@ static int gfx_v10_0_ring_test_ring(struct amdgpu_ring *ring)int r;WREG32 (scratch,0xCAFEDEAD ); +/* Flush the posted write before the CP writes the test value. */ +RREG32 (scratch); r =amdgpu_ring_alloc (ring,3 );if (r) { drm_err(adev_to_drm(adev), "cp failed to lock ring %d (%d).\n",
Signature · 1 line
2.50.1
PATCH v2 6/7 drm/amdgpu/gfx11: flush the scratch register write in the ring test
In reply to Jesse ZhangThe ring test writes 0xCAFEDEAD to SCRATCH_REG0 through MMIO, then has the CP write 0xDEADBEEF to it and polls for the new value.
Nothing orders the posted MMIO write against the CP's write, so it can land after it. The test then reads 0xCAFEDEAD forever and fails, although the CP executed the packet. A false ring test failure in a queue or pipe reset escalates the recovery to a full GPU reset.
Read the scratch register back before submitting the packet.
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2 -0
@@ -587,6 +587,8 @@ static int gfx_v11_0_ring_test_ring(struct amdgpu_ring *ring)int r;WREG32 (scratch,0xCAFEDEAD ); +/* Flush the posted write before the CP writes the test value. */ +RREG32 (scratch); r =amdgpu_ring_alloc (ring,5 );if (r) { drm_err(adev_to_drm(adev), "cp failed to lock ring %d (%d).\n",
Signature · 1 line
2.50.1
Re: [PATCH v2 6/7] drm/amdgpu/gfx11: flush the scratch register write in the ring test
Quoted 8 lines · Jesse Zhang
The ring test writes
0xCAFEDEADtoSCRATCH_REG0through MMIO, then has the CP write0xDEADBEEFto it and polls for the new value.Nothing orders the posted MMIO write against the CP's write, so it can land after it. The test then reads
0xCAFEDEADforever and fails, although the CP executed the packet. A false ring test failure in a queue or pipe reset escalates the recovery to a full GPU reset.
Quoted 4 lines
Read the scratch register back before submitting the packet.
Suggested-by Alex Deucher <[email protected]>Signed-off-by Jesse Zhang <[email protected]>
Patches 1-6 are
Thanks,
Lijo
Quoted 17 lines
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0@@ -587,6 +587,8 @@ static int gfx_v11_0_ring_test_ring(struct amdgpu_ring *ring)int r;WREG32 (scratch,0xCAFEDEAD ); +/* Flush the posted write before the CP writes the test value. */ +RREG32 (scratch); r =amdgpu_ring_alloc (ring,5 );if (r) { drm_err(adev_to_drm(adev), "cp failed to lock ring %d (%d).\n",
PATCH v2 7/7 drm/amdgpu/gfx12: flush the scratch register write in the ring test
In reply to Jesse ZhangThe 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 | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2 -0
@@ -458,6 +458,8 @@ static int gfx_v12_0_ring_test_ring(struct amdgpu_ring *ring)int r;WREG32 (scratch,0xCAFEDEAD ); +/* Flush the posted write before the CP writes the test value. */ +RREG32 (scratch); r =amdgpu_ring_alloc (ring,5 );if (r) { drm_err(adev_to_drm(adev),
Signature · 1 line
2.50.1