Skip to contentSkip to conversation

drm/amdgpu/gfx6: flush the scratch register write in the ring and IB tests

PATCH In review Jesse Zhang 2 participants 8 messages Oct 26

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index a5553d181d97..c49634aa1bfc 100644
@@ -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
#1 lore raw

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
index 50e25109d0eb..72c84b61fda1 100644
@@ -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
#2 lore raw

PATCH v2 3/7 drm/amdgpu/gfx8: flush the scratch register write in the ring test

In reply to Jesse Zhang

The 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
index 7e2f9c13dec3..4666aa5b38c7 100644
@@ -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
#3 lore raw

PATCH v2 4/7 drm/amdgpu/gfx9: flush the scratch register write in the ring test

In reply to Jesse Zhang

The 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
index 75d1bbdb421f..2e2673a6dbbf 100644
@@ -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
#4 lore raw

PATCH v2 5/7 drm/amdgpu/gfx10: flush the scratch register write in the ring test

In reply to Jesse Zhang

The 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
index b6f61f4a08e5..90a23aac7487 100644
@@ -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
#5 lore raw

PATCH v2 6/7 drm/amdgpu/gfx11: flush the scratch register write in the ring test

In reply to Jesse Zhang

The 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
index 315dfd806d56..b7f9fa3cbd2d 100644
@@ -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
Reviewed-by on v2 6/7
#6 lore raw

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 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.

Quoted 4 lines

Read the scratch register back before submitting the packet.

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
index 315dfd806d56..b7f9fa3cbd2d 100644
@@ -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",
#7 lore raw

PATCH v2 7/7 drm/amdgpu/gfx12: flush the scratch register write in the ring test

In reply to Jesse Zhang

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 | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2 -0
index d334fb805020..23c771dcd535 100644
@@ -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