Skip to contentSkip to conversation

Fix SDMA after module reload

PATCH In review Alex Deucher 3 participants 8 messages Jun 1, 2016 – Jun 8, 2016

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

cover Fix SDMA after module reload

This patch set fixes SDMA after module reload.

Monk Liu (4):
drm/amdgpu: clear RB at ring init
drm/amdgpu: clear SA bo when created
drm/amdgpu: init more register for sdma
drm/amdgpu: modify sdma start sequence

 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c |  3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c   |  1 +
 drivers/gpu/drm/amd/amdgpu/cik_sdma.c    | 11 +++++++++--
 drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c   | 10 ++++++++--
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c   | 17 +++++++++++++----
 5 files changed, 34 insertions(+), 8 deletions(-)
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 1/4 drm/amdgpu: clear RB at ring init

From: Monk Liu <[email protected]>

This help fix reloading driver hang issue of SDMA ring.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +3 -0
index 3b02272..a4b3f44 100644
@@ -310,6 +310,9 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 		}
 		r = amdgpu_bo_kmap(ring->ring_obj,
 				       (void **)&ring->ring);
+
+		memset((void *)ring->ring, 0, ring->ring_size);
+
 		amdgpu_bo_unreserve(ring->ring_obj);
 		if (r) {
 			dev_err(adev->dev, "(%d) ring map failed\n", r);
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

Re: [PATCH 1/4] drm/amdgpu: clear RB at ring init

Quoted 19 lines · Alex Deucher

From: Monk Liu <[email protected]>

This help fix reloading driver hang issue of SDMA ring.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0 -0
index 3b02272..a4b3f44 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, · line 318

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +3 -0
@@ -310,6 +310,9 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 		}
 		r = amdgpu_bo_kmap(ring->ring_obj,
 				       (void **)&ring->ring);
+
+		memset((void *)ring->ring, 0, ring->ring_size);
+
 		amdgpu_bo_unreserve(ring->ring_obj);
 		if (r) {
 			dev_err(adev->dev, "(%d) ring map failed\n", r);

We should only call memset if amdgpu_bo_kmap succeeded. Same issue in patch 2.

There's something else about these two patches I'm a bit worried about:

The GPU should only read data from ring buffers and IBs that we previously explicitly wrote there. I'm afraid these patches might just paper over bugs elsewhere, which might still bite us under different circumstances.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

RE: [PATCH 1/4] drm/amdgpu: clear RB at ring init

Quoted 1 line

We should only call memset if amdgpu_bo_kmap succeeded. Same issue in patch 2.

[ml] agreed

Quoted 3 lines

There's something else about these two patches I'm a bit worried about:

The GPU should only read data from ring buffers and IBs that we previously explicitly wrote there. I'm afraid these patches might just paper over bugs elsewhere, which might still bite us under different circumstances.

[ml] so do you mean we should use NOP to fulfill the ring buffer instead of 0 ?

-----Original Message-----
From: Michel Dänzer [mailto:[email protected]]
Sent: Tuesday, June 07, 2016 3:34 PM
To: Alex Deucher <[email protected]>
Cc: [email protected]; Liu, Monk <[email protected]>
Subject: Re: [PATCH 1/4] drm/amdgpu: clear RB at ring init

Quoted 19 lines · Alex Deucher

From: Monk Liu <[email protected]>

This help fix reloading driver hang issue of SDMA ring.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0 -0
index 3b02272..a4b3f44 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, · line 318

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +3 -0
@@ -310,6 +310,9 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 		}
 		r = amdgpu_bo_kmap(ring->ring_obj,
 				       (void **)&ring->ring);
+
+		memset((void *)ring->ring, 0, ring->ring_size);
+
 		amdgpu_bo_unreserve(ring->ring_obj);
 		if (r) {
 			dev_err(adev->dev, "(%d) ring map failed\n", r);

We should only call memset if amdgpu_bo_kmap succeeded. Same issue in patch 2.

There's something else about these two patches I'm a bit worried about:

The GPU should only read data from ring buffers and IBs that we previously explicitly wrote there. I'm afraid these patches might just paper over bugs elsewhere, which might still bite us under different circumstances.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

Re: [PATCH 1/4] drm/amdgpu: clear RB at ring init

Quoted 8 lines · Monk
Quoted 6 lines

There's something else about these two patches I'm a bit worried about:

The GPU should only read data from ring buffers and IBs that we previously explicitly wrote there. I'm afraid these patches might just paper over bugs elsewhere, which might still bite us under different circumstances.

so do you mean we should use NOP to fulfill the ring buffer instead of 0 ?

I mean we should find out why the GPU seems to read something else than the packets we write to the ring buffer / IBs.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw

PATCH 2/4 drm/amdgpu: clear SA bo when created

In reply to Alex Deucher

From: Monk Liu <[email protected]>

This help fix reloading driver hang issue of SDMA ring

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c +1 -0
index 8bf84ef..48618ee 100644
@@ -115,6 +115,7 @@ int amdgpu_sa_bo_manager_start(struct amdgpu_device *adev,
 		return r;
 	}
 	r = amdgpu_bo_kmap(sa_manager->bo, &sa_manager->cpu_ptr);
+	memset(sa_manager->cpu_ptr, 0, sa_manager->size);
 	amdgpu_bo_unreserve(sa_manager->bo);
 	return r;
 }
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw

PATCH 3/4 drm/amdgpu: init more register for sdma

In reply to Alex Deucher

From: Monk Liu <[email protected]>

This help fix reloading driver hang issue of SDMA ring

---
 drivers/gpu/drm/amd/amdgpu/cik_sdma.c  | 2 ++
 drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 2 ++
 3 files changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/cik_sdma.c +2 -0
index 518dca4..76f73ab 100644
@@ -419,6 +419,8 @@ static int cik_sdma_gfx_resume(struct amdgpu_device *adev)
 		/* Initialize the ring buffer's read and write pointers */
 		WREG32(mmSDMA0_GFX_RB_RPTR + sdma_offsets[i], 0);
 		WREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[i], 0);
+		WREG32(mmSDMA0_GFX_IB_RPTR + sdma_offsets[i], 0);
+		WREG32(mmSDMA0_GFX_IB_OFFSET + sdma_offsets[i], 0);
 
 		/* set the wb address whether it's enabled or not */
 		WREG32(mmSDMA0_GFX_RB_RPTR_ADDR_HI + sdma_offsets[i],
drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +2 -0
index f4c3130..e11a374 100644
@@ -461,6 +461,8 @@ static int sdma_v2_4_gfx_resume(struct amdgpu_device *adev)
 		/* Initialize the ring buffer's read and write pointers */
 		WREG32(mmSDMA0_GFX_RB_RPTR + sdma_offsets[i], 0);
 		WREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[i], 0);
+		WREG32(mmSDMA0_GFX_IB_RPTR + sdma_offsets[i], 0);
+		WREG32(mmSDMA0_GFX_IB_OFFSET + sdma_offsets[i], 0);
 
 		/* set the wb address whether it's enabled or not */
 		WREG32(mmSDMA0_GFX_RB_RPTR_ADDR_HI + sdma_offsets[i],
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +2 -0
index 31d99b00..585d8fe 100644
@@ -672,6 +672,8 @@ static int sdma_v3_0_gfx_resume(struct amdgpu_device *adev)
 		/* Initialize the ring buffer's read and write pointers */
 		WREG32(mmSDMA0_GFX_RB_RPTR + sdma_offsets[i], 0);
 		WREG32(mmSDMA0_GFX_RB_WPTR + sdma_offsets[i], 0);
+		WREG32(mmSDMA0_GFX_IB_RPTR + sdma_offsets[i], 0);
+		WREG32(mmSDMA0_GFX_IB_OFFSET + sdma_offsets[i], 0);
 
 		/* set the wb address whether it's enabled or not */
 		WREG32(mmSDMA0_GFX_RB_RPTR_ADDR_HI + sdma_offsets[i],
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#7 lore raw

PATCH 4/4 drm/amdgpu: modify sdma start sequence

In reply to Alex Deucher

From: Monk Liu <[email protected]>

should fist halt engine, and then doing the register programing, and later unhalt engine, and finally run ring_test.

this help fix reloading driver hang issue of SDMA ring

original sequence is wrong for it programing engine after unhalt, which will lead to fault behavior when doing driver reloading after unloaded.

---
 drivers/gpu/drm/amd/amdgpu/cik_sdma.c  |  9 +++++++--
 drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c |  8 ++++++--
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 15 +++++++++++----
 3 files changed, 24 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/cik_sdma.c +7 -2
index 76f73ab..0079916 100644
@@ -448,7 +448,12 @@ static int cik_sdma_gfx_resume(struct amdgpu_device *adev)
 		WREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i], ib_cntl);
 
 		ring->ready = true;
+	}
+
+	cik_sdma_enable(adev, true);
 
+	for (i = 0; i < adev->sdma.num_instances; i++) {
+		ring = &adev->sdma.instance[i].ring;
 		r = amdgpu_ring_test_ring(ring);
 		if (r) {
 			ring->ready = false;
@@ -531,8 +536,8 @@ static int cik_sdma_start(struct amdgpu_device *adev)
 	if (r)
 		return r;
 
-	/* unhalt the MEs */
-	cik_sdma_enable(adev, true);
+	/* halt the engine before programing */
+	cik_sdma_enable(adev, false);
 
 	/* start the gfx rings and rlc compute queues */
 	r = cik_sdma_gfx_resume(adev);
drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +6 -2
index e11a374..f6014b0 100644
@@ -491,7 +491,11 @@ static int sdma_v2_4_gfx_resume(struct amdgpu_device *adev)
 		WREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i], ib_cntl);
 
 		ring->ready = true;
+	}
 
+	sdma_v2_4_enable(adev, true);
+	for (i = 0; i < adev->sdma.num_instances; i++) {
+		ring = &adev->sdma.instance[i].ring;
 		r = amdgpu_ring_test_ring(ring);
 		if (r) {
 			ring->ready = false;
@@ -582,8 +586,8 @@ static int sdma_v2_4_start(struct amdgpu_device *adev)
 			return -EINVAL;
 	}
 
-	/* unhalt the MEs */
-	sdma_v2_4_enable(adev, true);
+	/* halt the engine before programing */
+	sdma_v2_4_enable(adev, false);
 
 	/* start the gfx rings and rlc compute queues */
 	r = sdma_v2_4_gfx_resume(adev);
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +11 -4
index 585d8fe..33605d4 100644
@@ -713,7 +713,15 @@ static int sdma_v3_0_gfx_resume(struct amdgpu_device *adev)
 		WREG32(mmSDMA0_GFX_IB_CNTL + sdma_offsets[i], ib_cntl);
 
 		ring->ready = true;
+	}
 
+	/* unhalt the MEs */
+	sdma_v3_0_enable(adev, true);
+	/* enable sdma ring preemption */
+	sdma_v3_0_ctx_switch_enable(adev, true);
+
+	for (i = 0; i < adev->sdma.num_instances; i++) {
+		ring = &adev->sdma.instance[i].ring;
 		r = amdgpu_ring_test_ring(ring);
 		if (r) {
 			ring->ready = false;
@@ -806,10 +814,9 @@ static int sdma_v3_0_start(struct amdgpu_device *adev)
 		}
 	}
 
-	/* unhalt the MEs */
-	sdma_v3_0_enable(adev, true);
-	/* enable sdma ring preemption */
-	sdma_v3_0_ctx_switch_enable(adev, true);
+	/* disble sdma engine before programing it */
+	sdma_v3_0_ctx_switch_enable(adev, false);
+	sdma_v3_0_enable(adev, false);
 
 	/* start the gfx rings and rlc compute queues */
 	r = sdma_v3_0_gfx_resume(adev);
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel