Skip to contentSkip to conversation

Reset improvements

PATCH Superseded Alex Deucher 4 participants 45 messages Jul 1, 2025 – Jul 7, 2025

Subsystems (3)

v13 of 15 Superseded Latest is v15 →

lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

v13 cover Reset improvements

This set improves per queue reset support for a number of IPs. When we reset the queue, the queue is lost so we need to re-emit the unprocessed state from subsequent submissions. This is handled in gfx/compute queues via switch buffer and pipeline sync packets. However, you can still end up with parallel execution across queues. For correctness in that cause, enforce isolation needs to be enabled. That can impact certain use cases however and in most cases, the guilty job is correctly identified even without enforce isolation.

Tested on GC 10 and 11 chips with a game running and then running hang tests. The game pauses when the hang happens, then continues after the queue reset.

The same approach is extended to SDMA and VCN. They don't need enforce isolation because those engines are single threaded so they always operate serially.

Rework re-emit to signal the seq number of the bad job and verify that to verify that the reset worked, then re-emit the rest of the non-guilty state. This way we are not waiting on the rest of the state to complete, and if the subsequent state also contains a bad job, we'll end up in queue reset again rather than adapter reset.

Patches apply to the amd-staging-drm-next or drm-next branches in my git tree.

Git tree:
https://gitlab.freedesktop.org/agd5f/linux/-/commits/kq_resets?ref_type=heads

The IGT deadlock tests need the following fixes to properly handle -ETIME fences:
https://patchwork.freedesktop.org/series/150724/

v4: Drop explicit padding patches
Drop new timeout macro
Rework re-emit sequence
v5: Add a helper for reemit
Convert VCN, JPEG, SDMA to use new helpers
v6: Update SDMA 4.4.2 to use new helpers
Move ptr tracking to amdgpu_fence
Skip all jobs from the bad context on the ring
v7: Rework the backup logic
Move and clean up the guilty logic for engine resets Integrate suggestions from Christian
Add JPEG 4.0.5 support
v8: Add non-guilty ring backup handling
Clean up new function signatures
Reorder some bug fixes to the start of the series
v9: Clean up fence_emit
SDMA 5.x fixes
Add new reset helpers
sched wqueue stop/start cleanup
Add support for VCNs without unified queues
v10: Drop enforce isolation default change
Add more documentation
Clean up ring backup logic
v11: SDMA6/7 fixes
v12: Ring backup and reemit fixes
SDMA cleanups
SDMA5.x reemit support
GFX10 KGQ reset fix
v13: drop SDMA cleaups, they caused regressions in some IGT tests

Alex Deucher (28):
drm/amdgpu/sdma: consolidate engine reset handling drm/amdgpu/sdma: allow caller to handle kernel rings in engine reset drm/amdgpu: track ring state associated with a fence drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset drm/amdgpu/gfx9.4.3: re-emit unprocessed state on kcq reset drm/amdgpu/gfx10: re-emit unprocessed state on ring reset drm/amdgpu/gfx11: re-emit unprocessed state on ring reset drm/amdgpu/gfx12: re-emit unprocessed state on ring reset drm/amdgpu/sdma5: re-emit unprocessed state on ring reset drm/amdgpu/sdma5.2: re-emit unprocessed state on ring reset drm/amdgpu/sdma6: re-emit unprocessed state on ring reset drm/amdgpu/sdma7: re-emit unprocessed state on ring reset drm/amdgpu/jpeg2: re-emit unprocessed state on ring reset drm/amdgpu/jpeg2.5: re-emit unprocessed state on ring reset drm/amdgpu/jpeg3: re-emit unprocessed state on ring reset drm/amdgpu/jpeg4: re-emit unprocessed state on ring reset drm/amdgpu/jpeg4.0.3: re-emit unprocessed state on ring reset drm/amdgpu/jpeg4.0.5: add queue reset
drm/amdgpu/jpeg5: add queue reset
drm/amdgpu/jpeg5.0.1: re-emit unprocessed state on ring reset drm/amdgpu/vcn4: re-emit unprocessed state on ring reset drm/amdgpu/vcn4.0.3: re-emit unprocessed state on ring reset drm/amdgpu/vcn4.0.5: re-emit unprocessed state on ring reset drm/amdgpu/vcn5: re-emit unprocessed state on ring reset drm/amdgpu/vcn: add a helper framework for engine resets drm/amdgpu/vcn2: implement ring reset
drm/amdgpu/vcn2.5: implement ring reset
drm/amdgpu/vcn3: implement ring reset

 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c     | 90 +++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c        | 15 +++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c       |  4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c      | 67 ++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h      | 18 ++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c      | 43 +++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h      |  3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c       | 76 ++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h       |  6 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        |  4 +
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c        | 41 ++-------
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c        | 35 +-------
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c        | 35 +-------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         | 12 +--
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c       | 12 +--
 drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c        | 11 +--
 drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c        | 11 +--
 drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c        | 11 +--
 drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c        | 11 +--
 drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c      | 11 +--
 drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c      | 11 +++
 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c      | 14 +++
 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c      | 11 +--
 drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c      | 19 +---
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c        | 23 +++--
 drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c        | 23 +++--
 drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c        | 18 ++--
 drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c        | 18 ++--
 drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c         | 12 +++
 drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c         | 11 +++
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c         | 13 +++
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c         | 11 +--
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c       | 10 +--
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c       | 11 +--
 drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c       | 11 +--
 .../drm/amd/amdkfd/kfd_device_queue_manager.c |  2 +-
 36 files changed, 454 insertions(+), 280 deletions(-)
Signature · 1 line
2.50.0
author maintainer
#1 lore raw

PATCH v13 1/28 drm/amdgpu/sdma: consolidate engine reset handling

Move the force completion handling into the common engine reset function. No need to duplicate it for every IP version.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c |  5 ++++-
 drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 17 +----------------
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c   |  6 ++----
 drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c   |  6 ++----
 4 files changed, 9 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +4 -1
index 89a849640ab91..91e8f45fe886e 100644
@@ -573,9 +573,12 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)
 	 * to be submitted to the queues after the reset is complete.
 	 */
 	if (!ret) {
+		amdgpu_fence_driver_force_completion(gfx_ring);
 		drm_sched_wqueue_start(&gfx_ring->sched);
-		if (adev->sdma.has_page_queue)
+		if (adev->sdma.has_page_queue) {
+			amdgpu_fence_driver_force_completion(page_ring);
 			drm_sched_wqueue_start(&page_ring->sched);
+		}
 	}
 	mutex_unlock(&sdma_instance->engine_reset_mutex);
 
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1 -16
index d3072bca43e3f..572d105420ec3 100644
@@ -1714,7 +1714,7 @@ static int sdma_v4_4_2_stop_queue(struct amdgpu_ring *ring)
 static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring)
 {
 	struct amdgpu_device *adev = ring->adev;
-	u32 inst_mask, tmp_mask;
+	u32 inst_mask;
 	int i, r;
 
 	inst_mask = 1 << ring->me;
@@ -1733,21 +1733,6 @@ static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring)
 	}
 
 	r = sdma_v4_4_2_inst_start(adev, inst_mask, true);
-	if (r)
-		return r;
-
-	tmp_mask = inst_mask;
-	for_each_inst(i, tmp_mask) {
-		ring = &adev->sdma.instance[i].ring;
-
-		amdgpu_fence_driver_force_completion(ring);
-
-		if (adev->sdma.has_page_queue) {
-			struct amdgpu_ring *page = &adev->sdma.instance[i].page;
-
-			amdgpu_fence_driver_force_completion(page);
-		}
-	}
 
 	return r;
 }
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2 -4
index 4d72b085b3dd7..ed1706da7deec 100644
@@ -1618,10 +1618,8 @@ static int sdma_v5_0_restore_queue(struct amdgpu_ring *ring)
 
 	r = sdma_v5_0_gfx_resume_instance(adev, inst_id, true);
 	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	return 0;
+
+	return r;
 }
 
 static int sdma_v5_0_ring_preempt_ib(struct amdgpu_ring *ring)
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +2 -4
index 42a25150f83ac..b87a4b44fa939 100644
@@ -1534,10 +1534,8 @@ static int sdma_v5_2_restore_queue(struct amdgpu_ring *ring)
 	r = sdma_v5_2_gfx_resume_instance(adev, inst_id, true);
 
 	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	return 0;
+
+	return r;
 }
 
 static int sdma_v5_2_ring_preempt_ib(struct amdgpu_ring *ring)
Signature · 1 line
2.50.0
#2 lore raw

RE: [PATCH 01/28] drm/amdgpu/sdma: consolidate engine reset handling

[AMD Official Use Only - AMD Internal Distribution Only]

this patch is Reviewed-by: Jesse Zhang <[email protected]>

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Wednesday, July 2, 2025 2:44 AM
To: [email protected]; Koenig, Christian <[email protected]>; Sundararaju, Sathishkumar <[email protected]>
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 01/28] drm/amdgpu/sdma: consolidate engine reset handling

Move the force completion handling into the common engine reset function. No need to duplicate it for every IP version.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c |  5 ++++-  drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 17 +----------------
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c   |  6 ++----
 drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c   |  6 ++----
 4 files changed, 9 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +4 -1
index 89a849640ab91..91e8f45fe886e 100644
@@ -573,9 +573,12 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)
         * to be submitted to the queues after the reset is complete.
         */
        if (!ret) {
+               amdgpu_fence_driver_force_completion(gfx_ring);
                drm_sched_wqueue_start(&gfx_ring->sched);
-               if (adev->sdma.has_page_queue)
+               if (adev->sdma.has_page_queue) {
+                       amdgpu_fence_driver_force_completion(page_ring);
                        drm_sched_wqueue_start(&page_ring->sched);
+               }
        }
        mutex_unlock(&sdma_instance->engine_reset_mutex);
 
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1 -16
index d3072bca43e3f..572d105420ec3 100644
@@ -1714,7 +1714,7 @@ static int sdma_v4_4_2_stop_queue(struct amdgpu_ring *ring)  static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring)  {
        struct amdgpu_device *adev = ring->adev;
-       u32 inst_mask, tmp_mask;
+       u32 inst_mask;
        int i, r;
 
        inst_mask = 1 << ring->me;
@@ -1733,21 +1733,6 @@ static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring)
        }
 
        r = sdma_v4_4_2_inst_start(adev, inst_mask, true);
-       if (r)
-               return r;
-
-       tmp_mask = inst_mask;
-       for_each_inst(i, tmp_mask) {
-               ring = &adev->sdma.instance[i].ring;
-
-               amdgpu_fence_driver_force_completion(ring);
-
-               if (adev->sdma.has_page_queue) {
-                       struct amdgpu_ring *page = &adev->sdma.instance[i].page;
-
-                       amdgpu_fence_driver_force_completion(page);
-               }
-       }
 
        return r;
 }
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2 -4
index 4d72b085b3dd7..ed1706da7deec 100644
@@ -1618,10 +1618,8 @@ static int sdma_v5_0_restore_queue(struct amdgpu_ring *ring)
 
        r = sdma_v5_0_gfx_resume_instance(adev, inst_id, true);
        amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
-       if (r)
-               return r;
-       amdgpu_fence_driver_force_completion(ring);
-       return 0;
+
+       return r;
 }
 
 static int sdma_v5_0_ring_preempt_ib(struct amdgpu_ring *ring) diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c b/drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c

index 42a25150f83ac..b87a4b44fa939 100644

drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +2 -4
@@ -1534,10 +1534,8 @@ static int sdma_v5_2_restore_queue(struct amdgpu_ring *ring)
        r = sdma_v5_2_gfx_resume_instance(adev, inst_id, true);
 
        amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
-       if (r)
-               return r;
-       amdgpu_fence_driver_force_completion(ring);
-       return 0;
+
+       return r;
 }
 
 static int sdma_v5_2_ring_preempt_ib(struct amdgpu_ring *ring)

--
2.50.0

#3 lore raw

Re: [PATCH 01/28] drm/amdgpu/sdma: consolidate engine reset handling

In reply to Alex Deucher
Quoted 44 lines · Alex Deucher

Move the force completion handling into the common engine reset function. No need to duplicate it for every IP version.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c |  5 ++++-
 drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 17 +----------------
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c   |  6 ++----
 drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c   |  6 ++----
 4 files changed, 9 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +4 -1
index 89a849640ab91..91e8f45fe886e 100644
@@ -573,9 +573,12 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)
 	 * to be submitted to the queues after the reset is complete.
 	 */
 	if (!ret) {
+		amdgpu_fence_driver_force_completion(gfx_ring);
 		drm_sched_wqueue_start(&gfx_ring->sched);
-		if (adev->sdma.has_page_queue)
+		if (adev->sdma.has_page_queue) {
+			amdgpu_fence_driver_force_completion(page_ring);
 			drm_sched_wqueue_start(&page_ring->sched);
+		}
 	}
 	mutex_unlock(&sdma_instance->engine_reset_mutex);
 
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1 -1
index d3072bca43e3f..572d105420ec3 100644
@@ -1714,7 +1714,7 @@ static int sdma_v4_4_2_stop_queue(struct amdgpu_ring *ring)
 static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring)
 {
 	struct amdgpu_device *adev = ring->adev;
-	u32 inst_mask, tmp_mask;
+	u32 inst_mask;
 	int i, r;
 
 	inst_mask = 1 << ring->me;

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring) · line 1735

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -0
@@ -1733,21 +1733,6 @@ static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring)
 	}
 
 	r = sdma_v4_4_2_inst_start(adev, inst_mask, true);

Now that you have deleted the below code, I think you can remove the variable 'r' and use 'return sdma_v4_4_2_inst_start'.

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring) · line 1748

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -13
-	if (r)
-		return r;
-
-	tmp_mask = inst_mask;
-	for_each_inst(i, tmp_mask) {
-		ring = &adev->sdma.instance[i].ring;
-
-		amdgpu_fence_driver_force_completion(ring);
-
-		if (adev->sdma.has_page_queue) {
-			struct amdgpu_ring *page = &adev->sdma.instance[i].page;
-
-			amdgpu_fence_driver_force_completion(page);

I guess I'm missing something, but this part is slightly different from amdgpu_sdma_reset_engine since here amdgpu_fence_driver_force_completion() can be called twice in some cases.

Thanks

Quoted 42 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -2
-		}
-	}
 
 	return r;
 }
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2 -4
index 4d72b085b3dd7..ed1706da7deec 100644
@@ -1618,10 +1618,8 @@ static int sdma_v6_0_restore_queue(struct amdgpu_ring *ring)
 
 	r = sdma_v5_0_gfx_resume_instance(adev, inst_id, true);
 	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	return 0;
+
+	return r;
 }
 
 static int sdma_v5_0_ring_preempt_ib(struct amdgpu_ring *ring)
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +2 -4
index 42a25150f83ac..b87a4b44fa939 100644
@@ -1534,10 +1534,8 @@ static int sdma_v5_2_restore_queue(struct amdgpu_ring *ring)
 	r = sdma_v5_2_gfx_resume_instance(adev, inst_id, true);
 
 	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	return 0;
+
+	return r;
 }
 
 static int sdma_v5_2_ring_preempt_ib(struct amdgpu_ring *ring)
Signature · 1 line
2.50.0
Signature · 1 line
Rodrigo Siqueira
#4 lore raw

Re: [PATCH 01/28] drm/amdgpu/sdma: consolidate engine reset handling

Quoted 63 lines · Rodrigo Siqueira
Quoted 44 lines · Alex Deucher

Move the force completion handling into the common engine reset function. No need to duplicate it for every IP version.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c |  5 ++++-
 drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 17 +----------------
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c   |  6 ++----
 drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c   |  6 ++----
 4 files changed, 9 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +4 -1
index 89a849640ab91..91e8f45fe886e 100644
@@ -573,9 +573,12 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)
       * to be submitted to the queues after the reset is complete.
       */
      if (!ret) {
+             amdgpu_fence_driver_force_completion(gfx_ring);
              drm_sched_wqueue_start(&gfx_ring->sched);
-             if (adev->sdma.has_page_queue)
+             if (adev->sdma.has_page_queue) {
+                     amdgpu_fence_driver_force_completion(page_ring);
                      drm_sched_wqueue_start(&page_ring->sched);
+             }
      }
      mutex_unlock(&sdma_instance->engine_reset_mutex);
 
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1 -1
index d3072bca43e3f..572d105420ec3 100644
@@ -1714,7 +1714,7 @@ static int sdma_v4_4_2_stop_queue(struct amdgpu_ring *ring)
 static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring)
 {
      struct amdgpu_device *adev = ring->adev;
-     u32 inst_mask, tmp_mask;
+     u32 inst_mask;
      int i, r;
 
      inst_mask = 1 << ring->me;

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring) · line 1735

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -0
@@ -1733,21 +1733,6 @@ static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring)
      }
 
      r = sdma_v4_4_2_inst_start(adev, inst_mask, true);

Now that you have deleted the below code, I think you can remove the variable 'r' and use 'return sdma_v4_4_2_inst_start'.

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -10
-     if (r)
-             return r;
-
-     tmp_mask = inst_mask;
-     for_each_inst(i, tmp_mask) {
-             ring = &adev->sdma.instance[i].ring;
-
-             amdgpu_fence_driver_force_completion(ring);
-
-             if (adev->sdma.has_page_queue) {
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_restore_queue(struct amdgpu_ring *ring) · line 1748

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -3
-                     struct amdgpu_ring *page = &adev->sdma.instance[i].page;
-
-                     amdgpu_fence_driver_force_completion(page);

I guess I'm missing something, but this part is slightly different from amdgpu_sdma_reset_engine since here amdgpu_fence_driver_force_completion() can be called twice in some cases.

The logic should be the same. There are potentially two kernel rings per instance: gfx and page. This function is only ever called per engine instance so we'd only ever reset one instance.

Alex

Quoted 48 lines

Thanks

Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0 -2
-             }
-     }
 
      return r;
 }
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +2 -4
index 4d72b085b3dd7..ed1706da7deec 100644
@@ -1618,10 +1618,8 @@ static int sdma_v6_0_restore_queue(struct amdgpu_ring *ring)
 
      r = sdma_v5_0_gfx_resume_instance(adev, inst_id, true);
      amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
-     if (r)
-             return r;
-     amdgpu_fence_driver_force_completion(ring);
-     return 0;
+
+     return r;
 }
 
 static int sdma_v5_0_ring_preempt_ib(struct amdgpu_ring *ring)
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +2 -5
index 42a25150f83ac..b87a4b44fa939 100644
@@ -1534,10 +1534,8 @@ static int sdma_v5_2_restore_queue(struct amdgpu_ring *ring)
      r = sdma_v5_2_gfx_resume_instance(adev, inst_id, true);
 
      amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
-     if (r)
-             return r;
-     amdgpu_fence_driver_force_completion(ring);
-     return 0;
+
+     return r;
 }
 
 static int sdma_v5_2_ring_preempt_ib(struct amdgpu_ring *ring)
--
Quoted 2 lines

2.50.0

--
Rodrigo Siqueira

author maintainer
#5 lore raw

PATCH v13 2/28 drm/amdgpu/sdma: allow caller to handle kernel rings in engine reset

In reply to Alex Deucher

Add a parameter to amdgpu_sdma_reset_engine() to let the caller handle the kernel rings. This allows the kernel rings to back up their unprocessed state if the reset comes in via the drm scheduler rather than KFD.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c      | 44 +++++++++++--------
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h      |  3 +-
 drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c      |  2 +-
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c        |  2 +-
 drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c        |  2 +-
 .../drm/amd/amdkfd/kfd_device_queue_manager.c |  2 +-
 6 files changed, 32 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +26 -18
index 91e8f45fe886e..4f98d4920f5cf 100644
@@ -528,10 +528,13 @@ static int amdgpu_sdma_soft_reset(struct amdgpu_device *adev, u32 instance_id)
  * amdgpu_sdma_reset_engine - Reset a specific SDMA engine
  * @adev: Pointer to the AMDGPU device
  * @instance_id: Logical ID of the SDMA engine instance to reset
+ * @caller_handles_kernel_queues: Skip kernel queue processing. Caller
+ * will handle it.
  *
  * Returns: 0 on success, or a negative error code on failure.
  */
-int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)
+int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id,
+			     bool caller_handles_kernel_queues)
 {
 	int ret = 0;
 	struct amdgpu_sdma_instance *sdma_instance = &adev->sdma.instance[instance_id];
@@ -539,14 +542,17 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)
 	struct amdgpu_ring *page_ring = &sdma_instance->page;
 
 	mutex_lock(&sdma_instance->engine_reset_mutex);
-	/* Stop the scheduler's work queue for the GFX and page rings if they are running.
-	* This ensures that no new tasks are submitted to the queues while
-	* the reset is in progress.
-	*/
-	drm_sched_wqueue_stop(&gfx_ring->sched);
 
-	if (adev->sdma.has_page_queue)
-		drm_sched_wqueue_stop(&page_ring->sched);
+	if (!caller_handles_kernel_queues) {
+		/* Stop the scheduler's work queue for the GFX and page rings if they are running.
+		 * This ensures that no new tasks are submitted to the queues while
+		 * the reset is in progress.
+		 */
+		drm_sched_wqueue_stop(&gfx_ring->sched);
+
+		if (adev->sdma.has_page_queue)
+			drm_sched_wqueue_stop(&page_ring->sched);
+	}
 
 	if (sdma_instance->funcs->stop_kernel_queue) {
 		sdma_instance->funcs->stop_kernel_queue(gfx_ring);
@@ -568,16 +574,18 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)
 	}
 
 exit:
-	/* Restart the scheduler's work queue for the GFX and page rings
-	 * if they were stopped by this function. This allows new tasks
-	 * to be submitted to the queues after the reset is complete.
-	 */
-	if (!ret) {
-		amdgpu_fence_driver_force_completion(gfx_ring);
-		drm_sched_wqueue_start(&gfx_ring->sched);
-		if (adev->sdma.has_page_queue) {
-			amdgpu_fence_driver_force_completion(page_ring);
-			drm_sched_wqueue_start(&page_ring->sched);
+	if (!caller_handles_kernel_queues) {
+		/* Restart the scheduler's work queue for the GFX and page rings
+		 * if they were stopped by this function. This allows new tasks
+		 * to be submitted to the queues after the reset is complete.
+		 */
+		if (!ret) {
+			amdgpu_fence_driver_force_completion(gfx_ring);
+			drm_sched_wqueue_start(&gfx_ring->sched);
+			if (adev->sdma.has_page_queue) {
+				amdgpu_fence_driver_force_completion(page_ring);
+				drm_sched_wqueue_start(&page_ring->sched);
+			}
 		}
 	}
 	mutex_unlock(&sdma_instance->engine_reset_mutex);
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +2 -1
index e5f8951bbb6f4..34311f32be4c6 100644
@@ -172,7 +172,8 @@ struct amdgpu_buffer_funcs {
 				 uint32_t byte_count);
 };
 
-int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id);
+int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id,
+			     bool caller_handles_kernel_queues);
 
 #define amdgpu_emit_copy_buffer(adev, ib, s, d, b, t) (adev)->mman.buffer_funcs->emit_copy_buffer((ib),  (s), (d), (b), (t))
 #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1 -1
index 572d105420ec3..c0c418aa2c299 100644
@@ -1668,7 +1668,7 @@ static int sdma_v4_4_2_reset_queue(struct amdgpu_ring *ring,
 		return -EOPNOTSUPP;
 
 	amdgpu_amdkfd_suspend(adev, true);
-	r = amdgpu_sdma_reset_engine(adev, id);
+	r = amdgpu_sdma_reset_engine(adev, id, false);
 	amdgpu_amdkfd_resume(adev, true);
 	return r;
 }
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +1 -1
index ed1706da7deec..5a1098bdd8256 100644
@@ -1548,7 +1548,7 @@ static int sdma_v5_0_reset_queue(struct amdgpu_ring *ring,
 	int r;
 
 	amdgpu_amdkfd_suspend(adev, true);
-	r = amdgpu_sdma_reset_engine(adev, inst_id);
+	r = amdgpu_sdma_reset_engine(adev, inst_id, false);
 	amdgpu_amdkfd_resume(adev, true);
 
 	return r;
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +1 -1
index b87a4b44fa939..6843c2c3d71f5 100644
@@ -1461,7 +1461,7 @@ static int sdma_v5_2_reset_queue(struct amdgpu_ring *ring,
 	int r;
 
 	amdgpu_amdkfd_suspend(adev, true);
-	r = amdgpu_sdma_reset_engine(adev, inst_id);
+	r = amdgpu_sdma_reset_engine(adev, inst_id, false);
 	amdgpu_amdkfd_resume(adev, true);
 
 	return r;
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1 -1
index 76359c6a3f3a4..f0d19f6ed9ba8 100644
@@ -2312,7 +2312,7 @@ static int reset_hung_queues_sdma(struct device_queue_manager *dqm)
 				continue;
 
 			/* Reset engine and check. */
-			if (amdgpu_sdma_reset_engine(dqm->dev->adev, i) ||
+			if (amdgpu_sdma_reset_engine(dqm->dev->adev, i, false) ||
 			    dqm->dev->kfd2kgd->hqd_sdma_get_doorbell(dqm->dev->adev, i, j) ||
 			    !set_sdma_queue_as_reset(dqm, doorbell_off)) {
 				r = -ENOTRECOVERABLE;
Signature · 1 line
2.50.0
#6 lore raw

RE: [PATCH 02/28] drm/amdgpu/sdma: allow caller to handle kernel rings in engine reset

[AMD Official Use Only - AMD Internal Distribution Only]

this patch is Reviewed-by: Jesse Zhang <[email protected]>

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Wednesday, July 2, 2025 2:44 AM
To: [email protected]; Koenig, Christian <[email protected]>; Sundararaju, Sathishkumar <[email protected]>
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 02/28] drm/amdgpu/sdma: allow caller to handle kernel rings in engine reset

Add a parameter to amdgpu_sdma_reset_engine() to let the caller handle the kernel rings. This allows the kernel rings to back up their unprocessed state if the reset comes in via the drm scheduler rather than KFD.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c      | 44 +++++++++++--------
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h      |  3 +-
 drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c      |  2 +-
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c        |  2 +-
 drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c        |  2 +-
 .../drm/amd/amdkfd/kfd_device_queue_manager.c |  2 +-
 6 files changed, 32 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +26 -18
index 91e8f45fe886e..4f98d4920f5cf 100644
@@ -528,10 +528,13 @@ static int amdgpu_sdma_soft_reset(struct amdgpu_device *adev, u32 instance_id)
  * amdgpu_sdma_reset_engine - Reset a specific SDMA engine
  * @adev: Pointer to the AMDGPU device
  * @instance_id: Logical ID of the SDMA engine instance to reset
+ * @caller_handles_kernel_queues: Skip kernel queue processing. Caller
+ * will handle it.
  *
  * Returns: 0 on success, or a negative error code on failure.
  */
-int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)
+int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id,
+                            bool caller_handles_kernel_queues)
 {
        int ret = 0;
        struct amdgpu_sdma_instance *sdma_instance = &adev->sdma.instance[instance_id];
@@ -539,14 +542,17 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)
        struct amdgpu_ring *page_ring = &sdma_instance->page;
 
        mutex_lock(&sdma_instance->engine_reset_mutex);
-       /* Stop the scheduler's work queue for the GFX and page rings if they are running.
-       * This ensures that no new tasks are submitted to the queues while
-       * the reset is in progress.
-       */
-       drm_sched_wqueue_stop(&gfx_ring->sched);
 
-       if (adev->sdma.has_page_queue)
-               drm_sched_wqueue_stop(&page_ring->sched);
+       if (!caller_handles_kernel_queues) {
+               /* Stop the scheduler's work queue for the GFX and page rings if they are running.
+                * This ensures that no new tasks are submitted to the queues while
+                * the reset is in progress.
+                */
+               drm_sched_wqueue_stop(&gfx_ring->sched);
+
+               if (adev->sdma.has_page_queue)
+                       drm_sched_wqueue_stop(&page_ring->sched);
+       }
 
        if (sdma_instance->funcs->stop_kernel_queue) {
                sdma_instance->funcs->stop_kernel_queue(gfx_ring);
@@ -568,16 +574,18 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)
        }
 
 exit:
-       /* Restart the scheduler's work queue for the GFX and page rings
-        * if they were stopped by this function. This allows new tasks
-        * to be submitted to the queues after the reset is complete.
-        */
-       if (!ret) {
-               amdgpu_fence_driver_force_completion(gfx_ring);
-               drm_sched_wqueue_start(&gfx_ring->sched);
-               if (adev->sdma.has_page_queue) {
-                       amdgpu_fence_driver_force_completion(page_ring);
-                       drm_sched_wqueue_start(&page_ring->sched);
+       if (!caller_handles_kernel_queues) {
+               /* Restart the scheduler's work queue for the GFX and page rings
+                * if they were stopped by this function. This allows new tasks
+                * to be submitted to the queues after the reset is complete.
+                */
+               if (!ret) {
+                       amdgpu_fence_driver_force_completion(gfx_ring);
+                       drm_sched_wqueue_start(&gfx_ring->sched);
+                       if (adev->sdma.has_page_queue) {
+                               amdgpu_fence_driver_force_completion(page_ring);
+                               drm_sched_wqueue_start(&page_ring->sched);
+                       }
                }
        }
        mutex_unlock(&sdma_instance->engine_reset_mutex);
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +2 -1
index e5f8951bbb6f4..34311f32be4c6 100644
@@ -172,7 +172,8 @@ struct amdgpu_buffer_funcs {
                                 uint32_t byte_count);
 };
 
-int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id);
+int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id,
+                            bool caller_handles_kernel_queues);
 
 #define amdgpu_emit_copy_buffer(adev, ib, s, d, b, t) (adev)->mman.buffer_funcs->emit_copy_buffer((ib),  (s), (d), (b), (t))  #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b)) diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c

index 572d105420ec3..c0c418aa2c299 100644

drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1 -1
@@ -1668,7 +1668,7 @@ static int sdma_v4_4_2_reset_queue(struct amdgpu_ring *ring,
                return -EOPNOTSUPP;
 
        amdgpu_amdkfd_suspend(adev, true);
-       r = amdgpu_sdma_reset_engine(adev, id);
+       r = amdgpu_sdma_reset_engine(adev, id, false);
        amdgpu_amdkfd_resume(adev, true);
        return r;
 }
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +1 -1
index ed1706da7deec..5a1098bdd8256 100644
@@ -1548,7 +1548,7 @@ static int sdma_v5_0_reset_queue(struct amdgpu_ring *ring,
        int r;
 
        amdgpu_amdkfd_suspend(adev, true);
-       r = amdgpu_sdma_reset_engine(adev, inst_id);
+       r = amdgpu_sdma_reset_engine(adev, inst_id, false);
        amdgpu_amdkfd_resume(adev, true);
 
        return r;
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +1 -1
index b87a4b44fa939..6843c2c3d71f5 100644
@@ -1461,7 +1461,7 @@ static int sdma_v5_2_reset_queue(struct amdgpu_ring *ring,
        int r;
 
        amdgpu_amdkfd_suspend(adev, true);
-       r = amdgpu_sdma_reset_engine(adev, inst_id);
+       r = amdgpu_sdma_reset_engine(adev, inst_id, false);
        amdgpu_amdkfd_resume(adev, true);
 
        return r;
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1 -1
index 76359c6a3f3a4..f0d19f6ed9ba8 100644
@@ -2312,7 +2312,7 @@ static int reset_hung_queues_sdma(struct device_queue_manager *dqm)
                                continue;
 
                        /* Reset engine and check. */
-                       if (amdgpu_sdma_reset_engine(dqm->dev->adev, i) ||
+                       if (amdgpu_sdma_reset_engine(dqm->dev->adev, i, false) ||
                            dqm->dev->kfd2kgd->hqd_sdma_get_doorbell(dqm->dev->adev, i, j) ||
                            !set_sdma_queue_as_reset(dqm, doorbell_off)) {
                                r = -ENOTRECOVERABLE;

--
2.50.0

author maintainer
#7 lore raw

PATCH v13 3/28 drm/amdgpu: track ring state associated with a fence

In reply to Alex Deucher

We need to know the wptr and sequence number associated with a fence so that we can re-emit the unprocessed state after a ring reset. Pre-allocate storage space for the ring buffer contents and add helpers to save off and re-emit the unprocessed state so that it can be re-emitted after the queue is reset.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 90 +++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c    | 15 +++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c   |  4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c  | 67 +++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h  | 18 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c    |  4 +
 6 files changed, 195 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +90 -0
index 2d6b2b486baf7..3f2080aecd5a3 100644
@@ -120,6 +120,7 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f,
 		am_fence = kzalloc(sizeof(*am_fence), GFP_KERNEL);
 		if (!am_fence)
 			return -ENOMEM;
+		am_fence->context = 0;
 	} else {
 		am_fence = af;
 	}
@@ -127,6 +128,7 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f,
 	am_fence->ring = ring;
 
 	seq = ++ring->fence_drv.sync_seq;
+	am_fence->seq = seq;
 	if (af) {
 		dma_fence_init(fence, &amdgpu_job_fence_ops,
 			       &ring->fence_drv.lock,
@@ -141,6 +143,7 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f,
 
 	amdgpu_ring_emit_fence(ring, ring->fence_drv.gpu_addr,
 			       seq, flags | AMDGPU_FENCE_FLAG_INT);
+	amdgpu_fence_save_wptr(fence);
 	pm_runtime_get_noresume(adev_to_drm(adev)->dev);
 	ptr = &ring->fence_drv.fences[seq & ring->fence_drv.num_fences_mask];
 	if (unlikely(rcu_dereference_protected(*ptr, 1))) {
@@ -253,6 +256,7 @@ bool amdgpu_fence_process(struct amdgpu_ring *ring)
 
 	do {
 		struct dma_fence *fence, **ptr;
+		struct amdgpu_fence *am_fence;
 
 		++last_seq;
 		last_seq &= drv->num_fences_mask;
@@ -265,6 +269,12 @@ bool amdgpu_fence_process(struct amdgpu_ring *ring)
 		if (!fence)
 			continue;
 
+		/* Save the wptr in the fence driver so we know what the last processed
+		 * wptr was.  This is required for re-emitting the ring state for
+		 * queues that are reset but are not guilty and thus have no guilty fence.
+		 */
+		am_fence = container_of(fence, struct amdgpu_fence, base);
+		drv->signalled_wptr = am_fence->wptr;
 		dma_fence_signal(fence);
 		dma_fence_put(fence);
 		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
@@ -727,6 +737,86 @@ void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring)
 	amdgpu_fence_process(ring);
 }
 
+
+/**
+ * Kernel queue reset handling
+ *
+ * The driver can reset individual queues for most engines, but those queues
+ * may contain work from multiple contexts.  Resetting the queue will reset
+ * lose all of that state.  In order to minimize the collateral damage, the
+ * driver will save the ring contents which are not associated with the guilty
+ * context prior to resetting the queue.  After resetting the queue the queue
+ * contents from the other contexts is re-emitted to the rings so that it can
+ * be processed by the engine.  To handle this, we save the queue's write
+ * pointer (wptr) in the fences associated with each context.  If we get a
+ * queue timeout, we can then use the wptrs from the fences to determine
+ * which data needs to be saved out of the queue's ring buffer.
+ */
+
+/**
+ * amdgpu_fence_driver_guilty_force_completion - force signal of specified sequence
+ *
+ * @fence: fence of the ring to signal
+ *
+ */
+void amdgpu_fence_driver_guilty_force_completion(struct amdgpu_fence *fence)
+{
+	dma_fence_set_error(&fence->base, -ETIME);
+	amdgpu_fence_write(fence->ring, fence->seq);
+	amdgpu_fence_process(fence->ring);
+}
+
+void amdgpu_fence_save_wptr(struct dma_fence *fence)
+{
+	struct amdgpu_fence *am_fence = container_of(fence, struct amdgpu_fence, base);
+
+	am_fence->wptr = am_fence->ring->wptr;
+}
+
+static void amdgpu_ring_backup_unprocessed_command(struct amdgpu_ring *ring,
+						   u64 start_wptr, u32 end_wptr)
+{
+	unsigned int first_idx = start_wptr & ring->buf_mask;
+	unsigned int last_idx = end_wptr & ring->buf_mask;
+	unsigned int i;
+
+	/* Backup the contents of the ring buffer. */
+	for (i = first_idx; i != last_idx; ++i, i &= ring->buf_mask)
+		ring->ring_backup[ring->ring_backup_entries_to_copy++] = ring->ring[i];
+}
+
+void amdgpu_ring_backup_unprocessed_commands(struct amdgpu_ring *ring,
+					     struct amdgpu_fence *guilty_fence)
+{
+	struct dma_fence *unprocessed;
+	struct dma_fence __rcu **ptr;
+	struct amdgpu_fence *fence;
+	u64 wptr, i, seqno;
+
+	seqno = amdgpu_fence_read(ring);
+	wptr = ring->fence_drv.signalled_wptr;
+	ring->ring_backup_entries_to_copy = 0;
+
+	for (i = seqno + 1; i <= ring->fence_drv.sync_seq; ++i) {
+		ptr = &ring->fence_drv.fences[i & ring->fence_drv.num_fences_mask];
+		rcu_read_lock();
+		unprocessed = rcu_dereference(*ptr);
+
+		if (unprocessed && !dma_fence_is_signaled(unprocessed)) {
+			fence = container_of(unprocessed, struct amdgpu_fence, base);
+
+			/* save everything if the ring is not guilty, otherwise
+			 * just save the content from other contexts.
+			 */
+			if (!guilty_fence || (fence->context != guilty_fence->context))
+				amdgpu_ring_backup_unprocessed_command(ring, wptr,
+								       fence->wptr);
+			wptr = fence->wptr;
+		}
+		rcu_read_unlock();
+	}
+}
+
 /*
  * Common fence implementation
  */
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +14 -1
index 206b70acb29a0..7d9bcb72e8dd3 100644
@@ -139,7 +139,6 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,
 	int vmid = AMDGPU_JOB_GET_VMID(job);
 	bool need_pipe_sync = false;
 	unsigned int cond_exec;
-
 	unsigned int i;
 	int r = 0;
 
@@ -156,6 +155,11 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,
 		gds_va = job->gds_va;
 		init_shadow = job->init_shadow;
 		af = &job->hw_fence;
+		/* Save the context of the job for reset handling.
+		 * The driver needs this so it can skip the ring
+		 * contents for guilty contexts.
+		 */
+		af->context = job->base.s_fence ? job->base.s_fence->finished.context : 0;
 	} else {
 		vm = NULL;
 		fence_ctx = 0;
@@ -307,8 +311,17 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,
 	    ring->hw_prio == AMDGPU_GFX_PIPE_PRIO_HIGH)
 		ring->funcs->emit_wave_limit(ring, false);
 
+	/* Save the wptr associated with this fence.
+	 * This must be last for resets to work properly
+	 * as we need to save the wptr associated with this
+	 * fence so we know what rings contents to backup
+	 * after we reset the queue.
+	 */
+	amdgpu_fence_save_wptr(*f);
+
 	amdgpu_ring_ib_end(ring);
 	amdgpu_ring_commit(ring);
+
 	return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2 -2
index f0b7080dccb8d..45febdc2f3493 100644
@@ -89,8 +89,8 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)
 {
 	struct amdgpu_ring *ring = to_amdgpu_ring(s_job->sched);
 	struct amdgpu_job *job = to_amdgpu_job(s_job);
-	struct amdgpu_task_info *ti;
 	struct amdgpu_device *adev = ring->adev;
+	struct amdgpu_task_info *ti;
 	int idx, r;
 
 	if (!drm_dev_enter(adev_to_drm(adev), &idx)) {
@@ -135,7 +135,7 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)
 	} else if (amdgpu_gpu_recovery && ring->funcs->reset) {
 		dev_err(adev->dev, "Starting %s ring reset\n",
 			s_job->sched->name);
-		r = amdgpu_ring_reset(ring, job->vmid, NULL);
+		r = amdgpu_ring_reset(ring, job->vmid, &job->hw_fence);
 		if (!r) {
 			atomic_inc(&ring->adev->gpu_reset_counter);
 			dev_err(adev->dev, "Ring %s reset succeeded\n",
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +67 -0

94 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +18 -0
index 784ba2ec354c7..309e7bb6001bd 100644
@@ -118,6 +118,7 @@ struct amdgpu_fence_driver {
 	/* sync_seq is protected by ring emission lock */
 	uint32_t			sync_seq;
 	atomic_t			last_seq;
+	u64				signalled_wptr;
 	bool				initialized;
 	struct amdgpu_irq_src		*irq_src;
 	unsigned			irq_type;
@@ -141,6 +142,12 @@ struct amdgpu_fence {
 	/* RB, DMA, etc. */
 	struct amdgpu_ring		*ring;
 	ktime_t				start_timestamp;
+
+	/* wptr for the fence for resets */
+	u64				wptr;
+	/* fence context for resets */
+	u64				context;
+	uint32_t			seq;
 };
 
 extern const struct drm_sched_backend_ops amdgpu_sched_ops;
@@ -148,6 +155,8 @@ extern const struct drm_sched_backend_ops amdgpu_sched_ops;
 void amdgpu_fence_driver_clear_job_fences(struct amdgpu_ring *ring);
 void amdgpu_fence_driver_set_error(struct amdgpu_ring *ring, int error);
 void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring);
+void amdgpu_fence_driver_guilty_force_completion(struct amdgpu_fence *fence);
+void amdgpu_fence_save_wptr(struct dma_fence *fence);
 
 int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring);
 int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
@@ -284,6 +293,9 @@ struct amdgpu_ring {
 
 	struct amdgpu_bo	*ring_obj;
 	uint32_t		*ring;
+	/* backups for resets */
+	uint32_t		*ring_backup;
+	unsigned int		ring_backup_entries_to_copy;
 	unsigned		rptr_offs;
 	u64			rptr_gpu_addr;
 	volatile u32		*rptr_cpu_addr;
@@ -550,4 +562,10 @@ int amdgpu_ib_pool_init(struct amdgpu_device *adev);
 void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
 int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
 bool amdgpu_ring_sched_ready(struct amdgpu_ring *ring);
+void amdgpu_ring_backup_unprocessed_commands(struct amdgpu_ring *ring,
+					     struct amdgpu_fence *guilty_fence);
+void amdgpu_ring_reset_helper_begin(struct amdgpu_ring *ring,
+				    struct amdgpu_fence *guilty_fence);
+int amdgpu_ring_reset_helper_end(struct amdgpu_ring *ring,
+				 struct amdgpu_fence *guilty_fence);
 #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -0
index f042372d9f2e6..ea9b0f050f799 100644
@@ -765,6 +765,7 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,
 	bool cleaner_shader_needed = false;
 	bool pasid_mapping_needed = false;
 	struct dma_fence *fence = NULL;
+	struct amdgpu_fence *af;
 	unsigned int patch;
 	int r;
 
@@ -830,6 +831,9 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,
 		r = amdgpu_fence_emit(ring, &fence, NULL, 0);
 		if (r)
 			return r;
+		/* this is part of the job's context */
+		af = container_of(fence, struct amdgpu_fence, base);
+		af->context = job->base.s_fence ? job->base.s_fence->finished.context : 0;
 	}
 
 	if (vm_flush_needed) {
Signature · 1 line
2.50.0
#8 lore raw

Re: [PATCH 03/28] drm/amdgpu: track ring state associated with a fence

Quoted 98 lines · Alex Deucher

We need to know the wptr and sequence number associated with a fence so that we can re-emit the unprocessed state after a ring reset. Pre-allocate storage space for the ring buffer contents and add helpers to save off and re-emit the unprocessed state so that it can be re-emitted after the queue is reset.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 90 +++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c    | 15 +++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c   |  4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c  | 67 +++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h  | 18 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c    |  4 +
 6 files changed, 195 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +38 -0
index 2d6b2b486baf7..3f2080aecd5a3 100644
@@ -120,6 +120,7 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f,
 		am_fence = kzalloc(sizeof(*am_fence), GFP_KERNEL);
 		if (!am_fence)
 			return -ENOMEM;
+		am_fence->context = 0;
 	} else {
 		am_fence = af;
 	}
@@ -127,6 +128,7 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f,
 	am_fence->ring = ring;
 
 	seq = ++ring->fence_drv.sync_seq;
+	am_fence->seq = seq;
 	if (af) {
 		dma_fence_init(fence, &amdgpu_job_fence_ops,
 			       &ring->fence_drv.lock,
@@ -141,6 +143,7 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f,
 
 	amdgpu_ring_emit_fence(ring, ring->fence_drv.gpu_addr,
 			       seq, flags | AMDGPU_FENCE_FLAG_INT);
+	amdgpu_fence_save_wptr(fence);
 	pm_runtime_get_noresume(adev_to_drm(adev)->dev);
 	ptr = &ring->fence_drv.fences[seq & ring->fence_drv.num_fences_mask];
 	if (unlikely(rcu_dereference_protected(*ptr, 1))) {
@@ -253,6 +256,7 @@ bool amdgpu_fence_process(struct amdgpu_ring *ring)
 
 	do {
 		struct dma_fence *fence, **ptr;
+		struct amdgpu_fence *am_fence;
 
 		++last_seq;
 		last_seq &= drv->num_fences_mask;
@@ -265,6 +269,12 @@ bool amdgpu_fence_process(struct amdgpu_ring *ring)
 		if (!fence)
 			continue;
 
+		/* Save the wptr in the fence driver so we know what the last processed
+		 * wptr was.  This is required for re-emitting the ring state for
+		 * queues that are reset but are not guilty and thus have no guilty fence.
+		 */
+		am_fence = container_of(fence, struct amdgpu_fence, base);
+		drv->signalled_wptr = am_fence->wptr;
 		dma_fence_signal(fence);
 		dma_fence_put(fence);
 		pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
@@ -727,6 +737,86 @@ void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring)
 	amdgpu_fence_process(ring);
 }
 
+
+/**
+ * Kernel queue reset handling
+ *
+ * The driver can reset individual queues for most engines, but those queues
+ * may contain work from multiple contexts.  Resetting the queue will reset
+ * lose all of that state.  In order to minimize the collateral damage, the
+ * driver will save the ring contents which are not associated with the guilty
+ * context prior to resetting the queue.  After resetting the queue the queue
+ * contents from the other contexts is re-emitted to the rings so that it can
+ * be processed by the engine.  To handle this, we save the queue's write
+ * pointer (wptr) in the fences associated with each context.  If we get a
+ * queue timeout, we can then use the wptrs from the fences to determine
+ * which data needs to be saved out of the queue's ring buffer.
+ */
+
+/**
+ * amdgpu_fence_driver_guilty_force_completion - force signal of specified sequence
+ *
+ * @fence: fence of the ring to signal
+ *
+ */
+void amdgpu_fence_driver_guilty_force_completion(struct amdgpu_fence *fence)
+{
+	dma_fence_set_error(&fence->base, -ETIME);
+	amdgpu_fence_write(fence->ring, fence->seq);
+	amdgpu_fence_process(fence->ring);
+}

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring) · line 777

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +10 -0
+
+void amdgpu_fence_save_wptr(struct dma_fence *fence)
+{
+	struct amdgpu_fence *am_fence = container_of(fence, struct amdgpu_fence, base);
+
+	am_fence->wptr = am_fence->ring->wptr;
+}
+
+static void amdgpu_ring_backup_unprocessed_command(struct amdgpu_ring *ring,
+						   u64 start_wptr, u32 end_wptr)

Perhaps you could call this function something like amdgpu_ring_backup() or a similar name? I suggest this change because you also have the same function name for the exported function.

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring) · line 785

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +8 -0
+{
+	unsigned int first_idx = start_wptr & ring->buf_mask;
+	unsigned int last_idx = end_wptr & ring->buf_mask;
+	unsigned int i;
+
+	/* Backup the contents of the ring buffer. */
+	for (i = first_idx; i != last_idx; ++i, i &= ring->buf_mask)
+		ring->ring_backup[ring->ring_backup_entries_to_copy++] = ring->ring[i];

After the backup is done, don't you need to set
ring_backup_entries_to_copy to 0?

Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +16 -0
+}
+
+void amdgpu_ring_backup_unprocessed_commands(struct amdgpu_ring *ring,
+					     struct amdgpu_fence *guilty_fence)
+{
+	struct dma_fence *unprocessed;
+	struct dma_fence __rcu **ptr;
+	struct amdgpu_fence *fence;
+	u64 wptr, i, seqno;
+
+	seqno = amdgpu_fence_read(ring);
+	wptr = ring->fence_drv.signalled_wptr;
+	ring->ring_backup_entries_to_copy = 0;
+
+	for (i = seqno + 1; i <= ring->fence_drv.sync_seq; ++i) {
+		ptr = &ring->fence_drv.fences[i & ring->fence_drv.num_fences_mask];

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring) · line 811

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +10 -0
+		rcu_read_lock();
+		unprocessed = rcu_dereference(*ptr);
+
+		if (unprocessed && !dma_fence_is_signaled(unprocessed)) {
+			fence = container_of(unprocessed, struct amdgpu_fence, base);
+
+			/* save everything if the ring is not guilty, otherwise
+			 * just save the content from other contexts.
+			 */
+			if (!guilty_fence || (fence->context != guilty_fence->context))

Why do you need these two checks? Why is guilty_fence not enough here?

Quoted 192 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +8 -0
+				amdgpu_ring_backup_unprocessed_command(ring, wptr,
+								       fence->wptr);
+			wptr = fence->wptr;
+		}
+		rcu_read_unlock();
+	}
+}
+
 /*
  * Common fence implementation
  */
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +14 -1
index 206b70acb29a0..7d9bcb72e8dd3 100644
@@ -139,7 +139,6 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,
 	int vmid = AMDGPU_JOB_GET_VMID(job);
 	bool need_pipe_sync = false;
 	unsigned int cond_exec;
-
 	unsigned int i;
 	int r = 0;
 
@@ -156,6 +155,11 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,
 		gds_va = job->gds_va;
 		init_shadow = job->init_shadow;
 		af = &job->hw_fence;
+		/* Save the context of the job for reset handling.
+		 * The driver needs this so it can skip the ring
+		 * contents for guilty contexts.
+		 */
+		af->context = job->base.s_fence ? job->base.s_fence->finished.context : 0;
 	} else {
 		vm = NULL;
 		fence_ctx = 0;
@@ -307,8 +311,17 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,
 	    ring->hw_prio == AMDGPU_GFX_PIPE_PRIO_HIGH)
 		ring->funcs->emit_wave_limit(ring, false);
 
+	/* Save the wptr associated with this fence.
+	 * This must be last for resets to work properly
+	 * as we need to save the wptr associated with this
+	 * fence so we know what rings contents to backup
+	 * after we reset the queue.
+	 */
+	amdgpu_fence_save_wptr(*f);
+
 	amdgpu_ring_ib_end(ring);
 	amdgpu_ring_commit(ring);
+
 	return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2 -2
index f0b7080dccb8d..45febdc2f3493 100644
@@ -89,8 +89,8 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)
 {
 	struct amdgpu_ring *ring = to_amdgpu_ring(s_job->sched);
 	struct amdgpu_job *job = to_amdgpu_job(s_job);
-	struct amdgpu_task_info *ti;
 	struct amdgpu_device *adev = ring->adev;
+	struct amdgpu_task_info *ti;
 	int idx, r;
 
 	if (!drm_dev_enter(adev_to_drm(adev), &idx)) {
@@ -135,7 +135,7 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)
 	} else if (amdgpu_gpu_recovery && ring->funcs->reset) {
 		dev_err(adev->dev, "Starting %s ring reset\n",
 			s_job->sched->name);
-		r = amdgpu_ring_reset(ring, job->vmid, NULL);
+		r = amdgpu_ring_reset(ring, job->vmid, &job->hw_fence);
 		if (!r) {
 			atomic_inc(&ring->adev->gpu_reset_counter);
 			dev_err(adev->dev, "Ring %s reset succeeded\n",
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +67 -0
index 426834806fbf2..09d7681b7a754 100644
@@ -99,6 +99,29 @@ int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned int ndw)
 	return 0;
 }
 
+/**
+ * amdgpu_ring_alloc_reemit - allocate space on the ring buffer for reemit
+ *
+ * @ring: amdgpu_ring structure holding ring information
+ * @ndw: number of dwords to allocate in the ring buffer
+ *
+ * Allocate @ndw dwords in the ring buffer (all asics).
+ * doesn't check the max_dw limit as we may be reemitting
+ * several submissions.
+ */
+static void amdgpu_ring_alloc_reemit(struct amdgpu_ring *ring, unsigned int ndw)
+{
+	/* Align requested size with padding so unlock_commit can
+	 * pad safely */
+	ndw = (ndw + ring->funcs->align_mask) & ~ring->funcs->align_mask;
+
+	ring->count_dw = ndw;
+	ring->wptr_old = ring->wptr;
+
+	if (ring->funcs->begin_use)
+		ring->funcs->begin_use(ring);
+}
+
 /** amdgpu_ring_insert_nop - insert NOP packets
  *
  * @ring: amdgpu_ring structure holding ring information
@@ -333,6 +356,12 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 	/*  Initialize cached_rptr to 0 */
 	ring->cached_rptr = 0;
 
+	if (!ring->ring_backup) {
+		ring->ring_backup = kvzalloc(ring->ring_size, GFP_KERNEL);
+		if (!ring->ring_backup)
+			return -ENOMEM;
+	}
+
 	/* Allocate ring buffer */
 	if (ring->ring_obj == NULL) {
 		r = amdgpu_bo_create_kernel(adev, ring->ring_size + ring->funcs->extra_dw, PAGE_SIZE,
@@ -342,6 +371,7 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 					    (void **)&ring->ring);
 		if (r) {
 			dev_err(adev->dev, "(%d) ring create failed\n", r);
+			kvfree(ring->ring_backup);
 			return r;
 		}
 		amdgpu_ring_clear_ring(ring);
@@ -385,6 +415,8 @@ void amdgpu_ring_fini(struct amdgpu_ring *ring)
 	amdgpu_bo_free_kernel(&ring->ring_obj,
 			      &ring->gpu_addr,
 			      (void **)&ring->ring);
+	kvfree(ring->ring_backup);
+	ring->ring_backup = NULL;
 
 	dma_fence_put(ring->vmid_wait);
 	ring->vmid_wait = NULL;
@@ -753,3 +785,38 @@ bool amdgpu_ring_sched_ready(struct amdgpu_ring *ring)
 
 	return true;
 }
+
+void amdgpu_ring_reset_helper_begin(struct amdgpu_ring *ring,
+				    struct amdgpu_fence *guilty_fence)
+{
+	/* Stop the scheduler to prevent anybody else from touching the ring buffer. */
+	drm_sched_wqueue_stop(&ring->sched);
+	/* back up the non-guilty commands */
+	amdgpu_ring_backup_unprocessed_commands(ring, guilty_fence);
+}
+
+int amdgpu_ring_reset_helper_end(struct amdgpu_ring *ring,
+				 struct amdgpu_fence *guilty_fence)
+{
+	unsigned int i;
+	int r;
+
+	/* verify that the ring is functional */
+	r = amdgpu_ring_test_ring(ring);
+	if (r)
+		return r;
+
+	/* signal the fence of the bad job */
+	if (guilty_fence)
+		amdgpu_fence_driver_guilty_force_completion(guilty_fence);
+	/* Re-emit the non-guilty commands */
+	if (ring->ring_backup_entries_to_copy) {
+		amdgpu_ring_alloc_reemit(ring, ring->ring_backup_entries_to_copy);
+		for (i = 0; i < ring->ring_backup_entries_to_copy; i++)
+			amdgpu_ring_write(ring, ring->ring_backup[i]);
+		amdgpu_ring_commit(ring);
+	}
+	/* Start the scheduler again */
+	drm_sched_wqueue_start(&ring->sched);
+	return 0;
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -0
index 784ba2ec354c7..309e7bb6001bd 100644
@@ -118,6 +118,7 @@ struct amdgpu_fence_driver {
 	/* sync_seq is protected by ring emission lock */
 	uint32_t			sync_seq;
 	atomic_t			last_seq;
+	u64				signalled_wptr;
 	bool				initialized;
 	struct amdgpu_irq_src		*irq_src;
 	unsigned			irq_type;

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h struct amdgpu_fence { · line 150

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +6 -0
@@ -141,6 +142,12 @@ struct amdgpu_fence {
 	/* RB, DMA, etc. */
 	struct amdgpu_ring		*ring;
 	ktime_t				start_timestamp;
+
+	/* wptr for the fence for resets */
+	u64				wptr;
+	/* fence context for resets */
+	u64				context;
+	uint32_t			seq;

All of these new fields are associated with reset, and their names are also common in the code (we see wptr, context, and seq everywhere). What do you think of adding a suffix/prefix to identify their purpose in the code clearly? For example, wptr_reset instead of wptr or context_reset instead of context. It does not need to be _reset, but something that helps to identify these field purpose in the code.

Thanks

Quoted 58 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +11 -0
 };
 
 extern const struct drm_sched_backend_ops amdgpu_sched_ops;
@@ -148,6 +155,8 @@ extern const struct drm_sched_backend_ops amdgpu_sched_ops;
 void amdgpu_fence_driver_clear_job_fences(struct amdgpu_ring *ring);
 void amdgpu_fence_driver_set_error(struct amdgpu_ring *ring, int error);
 void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring);
+void amdgpu_fence_driver_guilty_force_completion(struct amdgpu_fence *fence);
+void amdgpu_fence_save_wptr(struct dma_fence *fence);
 
 int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring);
 int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
@@ -284,6 +293,9 @@ struct amdgpu_ring {
 
 	struct amdgpu_bo	*ring_obj;
 	uint32_t		*ring;
+	/* backups for resets */
+	uint32_t		*ring_backup;
+	unsigned int		ring_backup_entries_to_copy;
 	unsigned		rptr_offs;
 	u64			rptr_gpu_addr;
 	volatile u32		*rptr_cpu_addr;
@@ -550,4 +562,10 @@ int amdgpu_ib_pool_init(struct amdgpu_device *adev);
 void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
 int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
 bool amdgpu_ring_sched_ready(struct amdgpu_ring *ring);
+void amdgpu_ring_backup_unprocessed_commands(struct amdgpu_ring *ring,
+					     struct amdgpu_fence *guilty_fence);
+void amdgpu_ring_reset_helper_begin(struct amdgpu_ring *ring,
+				    struct amdgpu_fence *guilty_fence);
+int amdgpu_ring_reset_helper_end(struct amdgpu_ring *ring,
+				 struct amdgpu_fence *guilty_fence);
 #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -0
index f042372d9f2e6..ea9b0f050f799 100644
@@ -765,6 +765,7 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,
 	bool cleaner_shader_needed = false;
 	bool pasid_mapping_needed = false;
 	struct dma_fence *fence = NULL;
+	struct amdgpu_fence *af;
 	unsigned int patch;
 	int r;
 
@@ -830,6 +831,9 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,
 		r = amdgpu_fence_emit(ring, &fence, NULL, 0);
 		if (r)
 			return r;
+		/* this is part of the job's context */
+		af = container_of(fence, struct amdgpu_fence, base);
+		af->context = job->base.s_fence ? job->base.s_fence->finished.context : 0;
 	}
 
 	if (vm_flush_needed) {
Signature · 1 line
2.50.0
Signature · 1 line
Rodrigo Siqueira
#9 lore raw

Re: [PATCH 03/28] drm/amdgpu: track ring state associated with a fence

Quoted 106 lines · Rodrigo Siqueira
Quoted 104 lines · Alex Deucher

We need to know the wptr and sequence number associated with a fence so that we can re-emit the unprocessed state after a ring reset. Pre-allocate storage space for the ring buffer contents and add helpers to save off and re-emit the unprocessed state so that it can be re-emitted after the queue is reset.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 90 +++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c    | 15 +++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c   |  4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c  | 67 +++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h  | 18 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c    |  4 +
 6 files changed, 195 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +44 -0
index 2d6b2b486baf7..3f2080aecd5a3 100644
@@ -120,6 +120,7 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f,
              am_fence = kzalloc(sizeof(*am_fence), GFP_KERNEL);
              if (!am_fence)
                      return -ENOMEM;
+             am_fence->context = 0;
      } else {
              am_fence = af;
      }
@@ -127,6 +128,7 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f,
      am_fence->ring = ring;
 
      seq = ++ring->fence_drv.sync_seq;
+     am_fence->seq = seq;
      if (af) {
              dma_fence_init(fence, &amdgpu_job_fence_ops,
                             &ring->fence_drv.lock,
@@ -141,6 +143,7 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f,
 
      amdgpu_ring_emit_fence(ring, ring->fence_drv.gpu_addr,
                             seq, flags | AMDGPU_FENCE_FLAG_INT);
+     amdgpu_fence_save_wptr(fence);
      pm_runtime_get_noresume(adev_to_drm(adev)->dev);
      ptr = &ring->fence_drv.fences[seq & ring->fence_drv.num_fences_mask];
      if (unlikely(rcu_dereference_protected(*ptr, 1))) {
@@ -253,6 +256,7 @@ bool amdgpu_fence_process(struct amdgpu_ring *ring)
 
      do {
              struct dma_fence *fence, **ptr;
+             struct amdgpu_fence *am_fence;
 
              ++last_seq;
              last_seq &= drv->num_fences_mask;
@@ -265,6 +269,12 @@ bool amdgpu_fence_process(struct amdgpu_ring *ring)
              if (!fence)
                      continue;
 
+             /* Save the wptr in the fence driver so we know what the last processed
+              * wptr was.  This is required for re-emitting the ring state for
+              * queues that are reset but are not guilty and thus have no guilty fence.
+              */
+             am_fence = container_of(fence, struct amdgpu_fence, base);
+             drv->signalled_wptr = am_fence->wptr;
              dma_fence_signal(fence);
              dma_fence_put(fence);
              pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
@@ -727,6 +737,86 @@ void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring)
      amdgpu_fence_process(ring);
 }
 
+
+/**
+ * Kernel queue reset handling
+ *
+ * The driver can reset individual queues for most engines, but those queues
+ * may contain work from multiple contexts.  Resetting the queue will reset
+ * lose all of that state.  In order to minimize the collateral damage, the
+ * driver will save the ring contents which are not associated with the guilty
+ * context prior to resetting the queue.  After resetting the queue the queue
+ * contents from the other contexts is re-emitted to the rings so that it can
+ * be processed by the engine.  To handle this, we save the queue's write
+ * pointer (wptr) in the fences associated with each context.  If we get a
+ * queue timeout, we can then use the wptrs from the fences to determine
+ * which data needs to be saved out of the queue's ring buffer.
+ */
+
+/**
+ * amdgpu_fence_driver_guilty_force_completion - force signal of specified sequence
+ *
+ * @fence: fence of the ring to signal
+ *
+ */
+void amdgpu_fence_driver_guilty_force_completion(struct amdgpu_fence *fence)
+{
+     dma_fence_set_error(&fence->base, -ETIME);
+     amdgpu_fence_write(fence->ring, fence->seq);
+     amdgpu_fence_process(fence->ring);
+}
+
+void amdgpu_fence_save_wptr(struct dma_fence *fence)
+{
+     struct amdgpu_fence *am_fence = container_of(fence, struct amdgpu_fence, base);
+
+     am_fence->wptr = am_fence->ring->wptr;
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring) · line 777

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +4 -0
+}
+
+static void amdgpu_ring_backup_unprocessed_command(struct amdgpu_ring *ring,
+                                                u64 start_wptr, u32 end_wptr)

Perhaps you could call this function something like amdgpu_ring_backup() or a similar name? I suggest this change because you also have the same function name for the exported function.

The names are different:
amdgpu_ring_backup_unprocessed_command()
vs.
amdgpu_ring_backup_unprocessed_commands()
the latter calls the former in a loop to back up all of the necessary commands in the ring.

Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring) · line 785

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +8 -0
+{
+     unsigned int first_idx = start_wptr & ring->buf_mask;
+     unsigned int last_idx = end_wptr & ring->buf_mask;
+     unsigned int i;
+
+     /* Backup the contents of the ring buffer. */
+     for (i = first_idx; i != last_idx; ++i, i &= ring->buf_mask)
+             ring->ring_backup[ring->ring_backup_entries_to_copy++] = ring->ring[i];

After the backup is done, don't you need to set
ring_backup_entries_to_copy to 0?

No. This function is called in a loop so we back up multiple commands from the ring so we need to make sure we keep the index up to date.

Quoted 21 lines
Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +20 -0
+}
+
+void amdgpu_ring_backup_unprocessed_commands(struct amdgpu_ring *ring,
+                                          struct amdgpu_fence *guilty_fence)
+{
+     struct dma_fence *unprocessed;
+     struct dma_fence __rcu **ptr;
+     struct amdgpu_fence *fence;
+     u64 wptr, i, seqno;
+
+     seqno = amdgpu_fence_read(ring);
+     wptr = ring->fence_drv.signalled_wptr;
+     ring->ring_backup_entries_to_copy = 0;
+
+     for (i = seqno + 1; i <= ring->fence_drv.sync_seq; ++i) {
+             ptr = &ring->fence_drv.fences[i & ring->fence_drv.num_fences_mask];
+             rcu_read_lock();
+             unprocessed = rcu_dereference(*ptr);
+
+             if (unprocessed && !dma_fence_is_signaled(unprocessed)) {
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring) · line 811

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +6 -0
+                     fence = container_of(unprocessed, struct amdgpu_fence, base);
+
+                     /* save everything if the ring is not guilty, otherwise
+                      * just save the content from other contexts.
+                      */
+                     if (!guilty_fence || (fence->context != guilty_fence->context))

Why do you need these two checks? Why is guilty_fence not enough here?

There are two cases:
1. The fence innocent, in which case, we can back up all of the unprocessed ring contents.
2. The fence is guilty, in which case, we want to skip ring content associated with all fences associated with the guilty context.

Quoted 201 lines
Quoted 201 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +8 -0
+                             amdgpu_ring_backup_unprocessed_command(ring, wptr,
+                                                                    fence->wptr);
+                     wptr = fence->wptr;
+             }
+             rcu_read_unlock();
+     }
+}
+
 /*
  * Common fence implementation
  */
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +14 -1
index 206b70acb29a0..7d9bcb72e8dd3 100644
@@ -139,7 +139,6 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,
      int vmid = AMDGPU_JOB_GET_VMID(job);
      bool need_pipe_sync = false;
      unsigned int cond_exec;
-
      unsigned int i;
      int r = 0;
 
@@ -156,6 +155,11 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,
              gds_va = job->gds_va;
              init_shadow = job->init_shadow;
              af = &job->hw_fence;
+             /* Save the context of the job for reset handling.
+              * The driver needs this so it can skip the ring
+              * contents for guilty contexts.
+              */
+             af->context = job->base.s_fence ? job->base.s_fence->finished.context : 0;
      } else {
              vm = NULL;
              fence_ctx = 0;
@@ -307,8 +311,17 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,
          ring->hw_prio == AMDGPU_GFX_PIPE_PRIO_HIGH)
              ring->funcs->emit_wave_limit(ring, false);
 
+     /* Save the wptr associated with this fence.
+      * This must be last for resets to work properly
+      * as we need to save the wptr associated with this
+      * fence so we know what rings contents to backup
+      * after we reset the queue.
+      */
+     amdgpu_fence_save_wptr(*f);
+
      amdgpu_ring_ib_end(ring);
      amdgpu_ring_commit(ring);
+
      return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2 -2
index f0b7080dccb8d..45febdc2f3493 100644
@@ -89,8 +89,8 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)
 {
      struct amdgpu_ring *ring = to_amdgpu_ring(s_job->sched);
      struct amdgpu_job *job = to_amdgpu_job(s_job);
-     struct amdgpu_task_info *ti;
      struct amdgpu_device *adev = ring->adev;
+     struct amdgpu_task_info *ti;
      int idx, r;
 
      if (!drm_dev_enter(adev_to_drm(adev), &idx)) {
@@ -135,7 +135,7 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)
      } else if (amdgpu_gpu_recovery && ring->funcs->reset) {
              dev_err(adev->dev, "Starting %s ring reset\n",
                      s_job->sched->name);
-             r = amdgpu_ring_reset(ring, job->vmid, NULL);
+             r = amdgpu_ring_reset(ring, job->vmid, &job->hw_fence);
              if (!r) {
                      atomic_inc(&ring->adev->gpu_reset_counter);
                      dev_err(adev->dev, "Ring %s reset succeeded\n",
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +67 -0
index 426834806fbf2..09d7681b7a754 100644
@@ -99,6 +99,29 @@ int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned int ndw)
      return 0;
 }
 
+/**
+ * amdgpu_ring_alloc_reemit - allocate space on the ring buffer for reemit
+ *
+ * @ring: amdgpu_ring structure holding ring information
+ * @ndw: number of dwords to allocate in the ring buffer
+ *
+ * Allocate @ndw dwords in the ring buffer (all asics).
+ * doesn't check the max_dw limit as we may be reemitting
+ * several submissions.
+ */
+static void amdgpu_ring_alloc_reemit(struct amdgpu_ring *ring, unsigned int ndw)
+{
+     /* Align requested size with padding so unlock_commit can
+      * pad safely */
+     ndw = (ndw + ring->funcs->align_mask) & ~ring->funcs->align_mask;
+
+     ring->count_dw = ndw;
+     ring->wptr_old = ring->wptr;
+
+     if (ring->funcs->begin_use)
+             ring->funcs->begin_use(ring);
+}
+
 /** amdgpu_ring_insert_nop - insert NOP packets
  *
  * @ring: amdgpu_ring structure holding ring information
@@ -333,6 +356,12 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
      /*  Initialize cached_rptr to 0 */
      ring->cached_rptr = 0;
 
+     if (!ring->ring_backup) {
+             ring->ring_backup = kvzalloc(ring->ring_size, GFP_KERNEL);
+             if (!ring->ring_backup)
+                     return -ENOMEM;
+     }
+
      /* Allocate ring buffer */
      if (ring->ring_obj == NULL) {
              r = amdgpu_bo_create_kernel(adev, ring->ring_size + ring->funcs->extra_dw, PAGE_SIZE,
@@ -342,6 +371,7 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
                                          (void **)&ring->ring);
              if (r) {
                      dev_err(adev->dev, "(%d) ring create failed\n", r);
+                     kvfree(ring->ring_backup);
                      return r;
              }
              amdgpu_ring_clear_ring(ring);
@@ -385,6 +415,8 @@ void amdgpu_ring_fini(struct amdgpu_ring *ring)
      amdgpu_bo_free_kernel(&ring->ring_obj,
                            &ring->gpu_addr,
                            (void **)&ring->ring);
+     kvfree(ring->ring_backup);
+     ring->ring_backup = NULL;
 
      dma_fence_put(ring->vmid_wait);
      ring->vmid_wait = NULL;
@@ -753,3 +785,38 @@ bool amdgpu_ring_sched_ready(struct amdgpu_ring *ring)
 
      return true;
 }
+
+void amdgpu_ring_reset_helper_begin(struct amdgpu_ring *ring,
+                                 struct amdgpu_fence *guilty_fence)
+{
+     /* Stop the scheduler to prevent anybody else from touching the ring buffer. */
+     drm_sched_wqueue_stop(&ring->sched);
+     /* back up the non-guilty commands */
+     amdgpu_ring_backup_unprocessed_commands(ring, guilty_fence);
+}
+
+int amdgpu_ring_reset_helper_end(struct amdgpu_ring *ring,
+                              struct amdgpu_fence *guilty_fence)
+{
+     unsigned int i;
+     int r;
+
+     /* verify that the ring is functional */
+     r = amdgpu_ring_test_ring(ring);
+     if (r)
+             return r;
+
+     /* signal the fence of the bad job */
+     if (guilty_fence)
+             amdgpu_fence_driver_guilty_force_completion(guilty_fence);
+     /* Re-emit the non-guilty commands */
+     if (ring->ring_backup_entries_to_copy) {
+             amdgpu_ring_alloc_reemit(ring, ring->ring_backup_entries_to_copy);
+             for (i = 0; i < ring->ring_backup_entries_to_copy; i++)
+                     amdgpu_ring_write(ring, ring->ring_backup[i]);
+             amdgpu_ring_commit(ring);
+     }
+     /* Start the scheduler again */
+     drm_sched_wqueue_start(&ring->sched);
+     return 0;
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +6 -0
index 784ba2ec354c7..309e7bb6001bd 100644
@@ -118,6 +118,7 @@ struct amdgpu_fence_driver {
      /* sync_seq is protected by ring emission lock */
      uint32_t                        sync_seq;
      atomic_t                        last_seq;
+     u64                             signalled_wptr;
      bool                            initialized;
      struct amdgpu_irq_src           *irq_src;
      unsigned                        irq_type;
@@ -141,6 +142,12 @@ struct amdgpu_fence {
      /* RB, DMA, etc. */
      struct amdgpu_ring              *ring;
      ktime_t                         start_timestamp;
+
+     /* wptr for the fence for resets */
+     u64                             wptr;
+     /* fence context for resets */
+     u64                             context;
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h struct amdgpu_fence { · line 150

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -0
+     uint32_t                        seq;

All of these new fields are associated with reset, and their names are also common in the code (we see wptr, context, and seq everywhere). What do you think of adding a suffix/prefix to identify their purpose in the code clearly? For example, wptr_reset instead of wptr or context_reset instead of context. It does not need to be _reset, but something that helps to identify these field purpose in the code.

They are used to facilitate the resets, but at a more general level, they are just tagging the fence with additional metadata. The wptr marks the wptr value associated with the work associated with the fence. seq is the sequence number
associated with the fence (i.e., the value that will get written when the work on the engine completes). The context is the context of the job whose work is associated with the fence.

Alex

Quoted 64 lines

Thanks

Quoted 56 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +11 -0
 };
 
 extern const struct drm_sched_backend_ops amdgpu_sched_ops;
@@ -148,6 +155,8 @@ extern const struct drm_sched_backend_ops amdgpu_sched_ops;
 void amdgpu_fence_driver_clear_job_fences(struct amdgpu_ring *ring);
 void amdgpu_fence_driver_set_error(struct amdgpu_ring *ring, int error);
 void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring);
+void amdgpu_fence_driver_guilty_force_completion(struct amdgpu_fence *fence);
+void amdgpu_fence_save_wptr(struct dma_fence *fence);
 
 int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring);
 int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
@@ -284,6 +293,9 @@ struct amdgpu_ring {
 
      struct amdgpu_bo        *ring_obj;
      uint32_t                *ring;
+     /* backups for resets */
+     uint32_t                *ring_backup;
+     unsigned int            ring_backup_entries_to_copy;
      unsigned                rptr_offs;
      u64                     rptr_gpu_addr;
      volatile u32            *rptr_cpu_addr;
@@ -550,4 +562,10 @@ int amdgpu_ib_pool_init(struct amdgpu_device *adev);
 void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
 int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
 bool amdgpu_ring_sched_ready(struct amdgpu_ring *ring);
+void amdgpu_ring_backup_unprocessed_commands(struct amdgpu_ring *ring,
+                                          struct amdgpu_fence *guilty_fence);
+void amdgpu_ring_reset_helper_begin(struct amdgpu_ring *ring,
+                                 struct amdgpu_fence *guilty_fence);
+int amdgpu_ring_reset_helper_end(struct amdgpu_ring *ring,
+                              struct amdgpu_fence *guilty_fence);
 #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -1
index f042372d9f2e6..ea9b0f050f799 100644
@@ -765,6 +765,7 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,
      bool cleaner_shader_needed = false;
      bool pasid_mapping_needed = false;
      struct dma_fence *fence = NULL;
+     struct amdgpu_fence *af;
      unsigned int patch;
      int r;
 
@@ -830,6 +831,9 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,
              r = amdgpu_fence_emit(ring, &fence, NULL, 0);
              if (r)
                      return r;
+             /* this is part of the job's context */
+             af = container_of(fence, struct amdgpu_fence, base);
+             af->context = job->base.s_fence ? job->base.s_fence->finished.context : 0;
      }
 
      if (vm_flush_needed) {
--
Quoted 2 lines

2.50.0

--
Rodrigo Siqueira

author maintainer
#10 lore raw

PATCH v13 4/28 drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +3 -9
index 76ba664efecb3..30f6b04cf82e4 100644
@@ -7187,7 +7187,7 @@ static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring,
 	if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)
 		return -EINVAL;
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
 	spin_lock_irqsave(&kiq->ring_lock, flags);
 
@@ -7238,19 +7238,13 @@ static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring,
 	}
 	kiq->pmf->kiq_map_queues(kiq_ring, ring);
 	amdgpu_ring_commit(kiq_ring);
-	spin_unlock_irqrestore(&kiq->ring_lock, flags);
 	r = amdgpu_ring_test_ring(kiq_ring);
+	spin_unlock_irqrestore(&kiq->ring_lock, flags);
 	if (r) {
 		DRM_ERROR("fail to remap queue\n");
 		return r;
 	}
-
-	r = amdgpu_ring_test_ring(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static void gfx_v9_ip_print(struct amdgpu_ip_block *ip_block, struct drm_printer *p)
Signature · 1 line
2.50.0
#11 lore raw

RE: [PATCH 04/28] drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset

[AMD Official Use Only - AMD Internal Distribution Only]

[PATCH 04/28] drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset [PATCH 06/28] drm/amdgpu/gfx10: re-emit unprocessed state on ring reset [PATCH 07/28] drm/amdgpu/gfx11: re-emit unprocessed state on ring reset [PATCH 08/28] drm/amdgpu/gfx12: re-emit unprocessed state on ring reset [PATCH 09/28] drm/amdgpu/sdma5: re-emit unprocessed state on ring reset [PATCH 11/28] drm/amdgpu/sdma6: re-emit unprocessed state on ring reset [PATCH 10/28] drm/amdgpu/sdma5.2: re-emit unprocessed state on ring reset

these patches are Reviewed-by: Jesse Zhang <[email protected]>

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Wednesday, July 2, 2025 2:44 AM
To: [email protected]; Koenig, Christian <[email protected]>; Sundararaju, Sathishkumar <[email protected]>
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 04/28] drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +3 -9
index 76ba664efecb3..30f6b04cf82e4 100644
@@ -7187,7 +7187,7 @@ static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring,
        if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)
                return -EINVAL;
 
-       drm_sched_wqueue_stop(&ring->sched);
+       amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
        spin_lock_irqsave(&kiq->ring_lock, flags);
 
@@ -7238,19 +7238,13 @@ static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring,
        }
        kiq->pmf->kiq_map_queues(kiq_ring, ring);
        amdgpu_ring_commit(kiq_ring);
-       spin_unlock_irqrestore(&kiq->ring_lock, flags);
        r = amdgpu_ring_test_ring(kiq_ring);
+       spin_unlock_irqrestore(&kiq->ring_lock, flags);
        if (r) {
                DRM_ERROR("fail to remap queue\n");
                return r;
        }
-
-       r = amdgpu_ring_test_ring(ring);
-       if (r)
-               return r;
-       amdgpu_fence_driver_force_completion(ring);
-       drm_sched_wqueue_start(&ring->sched);
-       return 0;
+       return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static void gfx_v9_ip_print(struct amdgpu_ip_block *ip_block, struct drm_printer *p)

--
2.50.0

#12 lore raw

Re: [PATCH 04/28] drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset

In reply to Alex Deucher
Quoted 21 lines · Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
index 76ba664efecb3..30f6b04cf82e4 100644
@@ -7187,7 +7187,7 @@ static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring,
 	if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)
 		return -EINVAL;
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
 	spin_lock_irqsave(&kiq->ring_lock, flags);
 

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring, · line 7242

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
@@ -7238,19 +7238,13 @@ static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring,
 	}
 	kiq->pmf->kiq_map_queues(kiq_ring, ring);
 	amdgpu_ring_commit(kiq_ring);
-	spin_unlock_irqrestore(&kiq->ring_lock, flags);
 	r = amdgpu_ring_test_ring(kiq_ring);
+	spin_unlock_irqrestore(&kiq->ring_lock, flags);

Is this spin_unlock_irqrestore part something that maybe should be in another commit? Maybe one commit that make this change for all of the GFXs?

Thanks

Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -7
 	if (r) {
 		DRM_ERROR("fail to remap queue\n");
 		return r;
 	}
-
-	r = amdgpu_ring_test_ring(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static void gfx_v9_ip_print(struct amdgpu_ip_block *ip_block, struct drm_printer *p)
Signature · 1 line
2.50.0
Signature · 1 line
Rodrigo Siqueira
#13 lore raw

Re: [PATCH 04/28] drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset

Quoted 22 lines · Rodrigo Siqueira
Quoted 20 lines · Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
index 76ba664efecb3..30f6b04cf82e4 100644
@@ -7187,7 +7187,7 @@ static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring,
      if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)
              return -EINVAL;
 
-     drm_sched_wqueue_stop(&ring->sched);
+     amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
      spin_lock_irqsave(&kiq->ring_lock, flags);
 
Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring, · line 7242

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
@@ -7238,19 +7238,13 @@ static int gfx_v9_0_reset_kcq(struct amdgpu_ring *ring,
      }
      kiq->pmf->kiq_map_queues(kiq_ring, ring);
      amdgpu_ring_commit(kiq_ring);
-     spin_unlock_irqrestore(&kiq->ring_lock, flags);
      r = amdgpu_ring_test_ring(kiq_ring);
+     spin_unlock_irqrestore(&kiq->ring_lock, flags);

Is this spin_unlock_irqrestore part something that maybe should be in another commit? Maybe one commit that make this change for all of the GFXs?

Sure. I'll split them out as bug fixes.

Alex

Quoted 24 lines

Thanks

Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -8
      if (r) {
              DRM_ERROR("fail to remap queue\n");
              return r;
      }
-
-     r = amdgpu_ring_test_ring(ring);
-     if (r)
-             return r;
-     amdgpu_fence_driver_force_completion(ring);
-     drm_sched_wqueue_start(&ring->sched);
-     return 0;
+     return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static void gfx_v9_ip_print(struct amdgpu_ip_block *ip_block, struct drm_printer *p)
--
Quoted 2 lines

2.50.0

--
Rodrigo Siqueira

author maintainer
#14 lore raw

PATCH v13 5/28 drm/amdgpu/gfx9.4.3: re-emit unprocessed state on kcq reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +3 -9
index daed0f187bda5..21bdf9746db7a 100644
@@ -3567,7 +3567,7 @@ static int gfx_v9_4_3_reset_kcq(struct amdgpu_ring *ring,
 	if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)
 		return -EINVAL;
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
 	spin_lock_irqsave(&kiq->ring_lock, flags);
 
@@ -3615,20 +3615,14 @@ static int gfx_v9_4_3_reset_kcq(struct amdgpu_ring *ring,
 	}
 	kiq->pmf->kiq_map_queues(kiq_ring, ring);
 	amdgpu_ring_commit(kiq_ring);
-	spin_unlock_irqrestore(&kiq->ring_lock, flags);
-
 	r = amdgpu_ring_test_ring(kiq_ring);
+	spin_unlock_irqrestore(&kiq->ring_lock, flags);
 	if (r) {
 		dev_err(adev->dev, "fail to remap queue\n");
 		return r;
 	}
 
-	r = amdgpu_ring_test_ring(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 enum amdgpu_gfx_cp_ras_mem_id {
Signature · 1 line
2.50.0
author maintainer
#15 lore raw

PATCH v13 6/28 drm/amdgpu/gfx10: re-emit unprocessed state on ring reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 41 ++++----------------------
 1 file changed, 6 insertions(+), 35 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +6 -35
index 5e099b5dc9a3c..65429afb33ec3 100644
@@ -9046,21 +9046,6 @@ static void gfx_v10_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring,
 							   ref, mask);
 }
 
-static void gfx_v10_0_ring_soft_recovery(struct amdgpu_ring *ring,
-					 unsigned int vmid)
-{
-	struct amdgpu_device *adev = ring->adev;
-	uint32_t value = 0;
-
-	value = REG_SET_FIELD(value, SQ_CMD, CMD, 0x03);
-	value = REG_SET_FIELD(value, SQ_CMD, MODE, 0x01);
-	value = REG_SET_FIELD(value, SQ_CMD, CHECK_VMID, 1);
-	value = REG_SET_FIELD(value, SQ_CMD, VM_ID, vmid);
-	amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
-	WREG32_SOC15(GC, 0, mmSQ_CMD, value);
-	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
-}
-
 static void
 gfx_v10_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev,
 				      uint32_t me, uint32_t pipe,
@@ -9540,7 +9525,7 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring,
 	if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)
 		return -EINVAL;
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
 	spin_lock_irqsave(&kiq->ring_lock, flags);
 
@@ -9589,12 +9574,7 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring,
 	if (r)
 		return r;
 
-	r = amdgpu_ring_test_ring(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,
@@ -9613,7 +9593,7 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,
 	if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)
 		return -EINVAL;
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
 	spin_lock_irqsave(&kiq->ring_lock, flags);
 
@@ -9625,9 +9605,8 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,
 	kiq->pmf->kiq_unmap_queues(kiq_ring, ring, RESET_QUEUES,
 				   0, 0);
 	amdgpu_ring_commit(kiq_ring);
-	spin_unlock_irqrestore(&kiq->ring_lock, flags);
-
 	r = amdgpu_ring_test_ring(kiq_ring);
+	spin_unlock_irqrestore(&kiq->ring_lock, flags);
 	if (r)
 		return r;
 
@@ -9663,18 +9642,12 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,
 	}
 	kiq->pmf->kiq_map_queues(kiq_ring, ring);
 	amdgpu_ring_commit(kiq_ring);
-	spin_unlock_irqrestore(&kiq->ring_lock, flags);
-
 	r = amdgpu_ring_test_ring(kiq_ring);
+	spin_unlock_irqrestore(&kiq->ring_lock, flags);
 	if (r)
 		return r;
 
-	r = amdgpu_ring_test_ring(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static void gfx_v10_ip_print(struct amdgpu_ip_block *ip_block, struct drm_printer *p)
@@ -9909,7 +9882,6 @@ static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_gfx = {
 	.emit_wreg = gfx_v10_0_ring_emit_wreg,
 	.emit_reg_wait = gfx_v10_0_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = gfx_v10_0_ring_emit_reg_write_reg_wait,
-	.soft_recovery = gfx_v10_0_ring_soft_recovery,
 	.emit_mem_sync = gfx_v10_0_emit_mem_sync,
 	.reset = gfx_v10_0_reset_kgq,
 	.emit_cleaner_shader = gfx_v10_0_ring_emit_cleaner_shader,
@@ -9950,7 +9922,6 @@ static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_compute = {
 	.emit_wreg = gfx_v10_0_ring_emit_wreg,
 	.emit_reg_wait = gfx_v10_0_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = gfx_v10_0_ring_emit_reg_write_reg_wait,
-	.soft_recovery = gfx_v10_0_ring_soft_recovery,
 	.emit_mem_sync = gfx_v10_0_emit_mem_sync,
 	.reset = gfx_v10_0_reset_kcq,
 	.emit_cleaner_shader = gfx_v10_0_ring_emit_cleaner_shader,
Signature · 1 line
2.50.0
#16 lore raw

Re: [PATCH 06/28] drm/amdgpu/gfx10: re-emit unprocessed state on ring reset

Quoted 20 lines · Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 41 ++++----------------------
 1 file changed, 6 insertions(+), 35 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -5
index 5e099b5dc9a3c..65429afb33ec3 100644
@@ -9046,21 +9046,6 @@ static void gfx_v10_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring,
 							   ref, mask);
 }
 
-static void gfx_v10_0_ring_soft_recovery(struct amdgpu_ring *ring,
-					 unsigned int vmid)
-{
-	struct amdgpu_device *adev = ring->adev;
-	uint32_t value = 0;

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static void gfx_v10_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring, · line 9063

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -10
-
-	value = REG_SET_FIELD(value, SQ_CMD, CMD, 0x03);
-	value = REG_SET_FIELD(value, SQ_CMD, MODE, 0x01);
-	value = REG_SET_FIELD(value, SQ_CMD, CHECK_VMID, 1);
-	value = REG_SET_FIELD(value, SQ_CMD, VM_ID, vmid);
-	amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
-	WREG32_SOC15(GC, 0, mmSQ_CMD, value);
-	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
-}
-

You are eliminating the gfx_v10_0_ring_soft_recovery here, but why you did not remove it in the GFX9 (previous commit)?

Also, I suppose the new recovery method from this series will replace this soft_recovery, right? If so, I suggest you include this information in the commit message.

Thanks

Quoted 86 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +6 -20
 static void
 gfx_v10_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev,
 				      uint32_t me, uint32_t pipe,
@@ -9540,7 +9525,7 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring,
 	if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)
 		return -EINVAL;
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
 	spin_lock_irqsave(&kiq->ring_lock, flags);
 
@@ -9589,12 +9574,7 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring,
 	if (r)
 		return r;
 
-	r = amdgpu_ring_test_ring(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,
@@ -9613,7 +9593,7 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,
 	if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)
 		return -EINVAL;
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
 	spin_lock_irqsave(&kiq->ring_lock, flags);
 
@@ -9625,9 +9605,8 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,
 	kiq->pmf->kiq_unmap_queues(kiq_ring, ring, RESET_QUEUES,
 				   0, 0);
 	amdgpu_ring_commit(kiq_ring);
-	spin_unlock_irqrestore(&kiq->ring_lock, flags);
-
 	r = amdgpu_ring_test_ring(kiq_ring);
+	spin_unlock_irqrestore(&kiq->ring_lock, flags);
 	if (r)
 		return r;
 
@@ -9663,18 +9642,12 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,
 	}
 	kiq->pmf->kiq_map_queues(kiq_ring, ring);
 	amdgpu_ring_commit(kiq_ring);
-	spin_unlock_irqrestore(&kiq->ring_lock, flags);
-
 	r = amdgpu_ring_test_ring(kiq_ring);
+	spin_unlock_irqrestore(&kiq->ring_lock, flags);
 	if (r)
 		return r;
 
-	r = amdgpu_ring_test_ring(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static void gfx_v10_ip_print(struct amdgpu_ip_block *ip_block, struct drm_printer *p)
@@ -9909,7 +9882,6 @@ static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_gfx = {
 	.emit_wreg = gfx_v10_0_ring_emit_wreg,
 	.emit_reg_wait = gfx_v10_0_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = gfx_v10_0_ring_emit_reg_write_reg_wait,
-	.soft_recovery = gfx_v10_0_ring_soft_recovery,
 	.emit_mem_sync = gfx_v10_0_emit_mem_sync,
 	.reset = gfx_v10_0_reset_kgq,
 	.emit_cleaner_shader = gfx_v10_0_ring_emit_cleaner_shader,
@@ -9950,7 +9922,6 @@ static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_compute = {
 	.emit_wreg = gfx_v10_0_ring_emit_wreg,
 	.emit_reg_wait = gfx_v10_0_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = gfx_v10_0_ring_emit_reg_write_reg_wait,
-	.soft_recovery = gfx_v10_0_ring_soft_recovery,
 	.emit_mem_sync = gfx_v10_0_emit_mem_sync,
 	.reset = gfx_v10_0_reset_kcq,
 	.emit_cleaner_shader = gfx_v10_0_ring_emit_cleaner_shader,
Signature · 1 line
2.50.0
Signature · 1 line
Rodrigo Siqueira
#17 lore raw

Re: [PATCH 06/28] drm/amdgpu/gfx10: re-emit unprocessed state on ring reset

Quoted 27 lines · Rodrigo Siqueira
Quoted 25 lines · Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 41 ++++----------------------
 1 file changed, 6 insertions(+), 35 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -10
index 5e099b5dc9a3c..65429afb33ec3 100644
@@ -9046,21 +9046,6 @@ static void gfx_v10_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring,
                                                         ref, mask);
 }
 
-static void gfx_v10_0_ring_soft_recovery(struct amdgpu_ring *ring,
-                                      unsigned int vmid)
-{
-     struct amdgpu_device *adev = ring->adev;
-     uint32_t value = 0;
-
-     value = REG_SET_FIELD(value, SQ_CMD, CMD, 0x03);
-     value = REG_SET_FIELD(value, SQ_CMD, MODE, 0x01);
-     value = REG_SET_FIELD(value, SQ_CMD, CHECK_VMID, 1);
-     value = REG_SET_FIELD(value, SQ_CMD, VM_ID, vmid);
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static void gfx_v10_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring, · line 9063

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -5
-     amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
-     WREG32_SOC15(GC, 0, mmSQ_CMD, value);
-     amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
-}
-

You are eliminating the gfx_v10_0_ring_soft_recovery here, but why you did not remove it in the GFX9 (previous commit)?

gfx9 doesn't implement graphics reset yet so we still need soft recovery.

Quoted 4 lines

Also, I suppose the new recovery method from this series will replace this soft_recovery, right? If so, I suggest you include this information in the commit message.

Correct. Will update the message.

Alex

Quoted 92 lines

Thanks

Quoted 84 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +6 -21
 static void
 gfx_v10_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev,
                                    uint32_t me, uint32_t pipe,
@@ -9540,7 +9525,7 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring,
      if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)
              return -EINVAL;
 
-     drm_sched_wqueue_stop(&ring->sched);
+     amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
      spin_lock_irqsave(&kiq->ring_lock, flags);
 
@@ -9589,12 +9574,7 @@ static int gfx_v10_0_reset_kgq(struct amdgpu_ring *ring,
      if (r)
              return r;
 
-     r = amdgpu_ring_test_ring(ring);
-     if (r)
-             return r;
-     amdgpu_fence_driver_force_completion(ring);
-     drm_sched_wqueue_start(&ring->sched);
-     return 0;
+     return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,
@@ -9613,7 +9593,7 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,
      if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)
              return -EINVAL;
 
-     drm_sched_wqueue_stop(&ring->sched);
+     amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
      spin_lock_irqsave(&kiq->ring_lock, flags);
 
@@ -9625,9 +9605,8 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,
      kiq->pmf->kiq_unmap_queues(kiq_ring, ring, RESET_QUEUES,
                                 0, 0);
      amdgpu_ring_commit(kiq_ring);
-     spin_unlock_irqrestore(&kiq->ring_lock, flags);
-
      r = amdgpu_ring_test_ring(kiq_ring);
+     spin_unlock_irqrestore(&kiq->ring_lock, flags);
      if (r)
              return r;
 
@@ -9663,18 +9642,12 @@ static int gfx_v10_0_reset_kcq(struct amdgpu_ring *ring,
      }
      kiq->pmf->kiq_map_queues(kiq_ring, ring);
      amdgpu_ring_commit(kiq_ring);
-     spin_unlock_irqrestore(&kiq->ring_lock, flags);
-
      r = amdgpu_ring_test_ring(kiq_ring);
+     spin_unlock_irqrestore(&kiq->ring_lock, flags);
      if (r)
              return r;
 
-     r = amdgpu_ring_test_ring(ring);
-     if (r)
-             return r;
-     amdgpu_fence_driver_force_completion(ring);
-     drm_sched_wqueue_start(&ring->sched);
-     return 0;
+     return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static void gfx_v10_ip_print(struct amdgpu_ip_block *ip_block, struct drm_printer *p)
@@ -9909,7 +9882,6 @@ static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_gfx = {
      .emit_wreg = gfx_v10_0_ring_emit_wreg,
      .emit_reg_wait = gfx_v10_0_ring_emit_reg_wait,
      .emit_reg_write_reg_wait = gfx_v10_0_ring_emit_reg_write_reg_wait,
-     .soft_recovery = gfx_v10_0_ring_soft_recovery,
      .emit_mem_sync = gfx_v10_0_emit_mem_sync,
      .reset = gfx_v10_0_reset_kgq,
      .emit_cleaner_shader = gfx_v10_0_ring_emit_cleaner_shader,
@@ -9950,7 +9922,6 @@ static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_compute = {
      .emit_wreg = gfx_v10_0_ring_emit_wreg,
      .emit_reg_wait = gfx_v10_0_ring_emit_reg_wait,
      .emit_reg_write_reg_wait = gfx_v10_0_ring_emit_reg_write_reg_wait,
-     .soft_recovery = gfx_v10_0_ring_soft_recovery,
      .emit_mem_sync = gfx_v10_0_emit_mem_sync,
      .reset = gfx_v10_0_reset_kcq,
      .emit_cleaner_shader = gfx_v10_0_ring_emit_cleaner_shader,
--
Quoted 2 lines

2.50.0

--
Rodrigo Siqueira

author maintainer
#18 lore raw

PATCH v13 7/28 drm/amdgpu/gfx11: re-emit unprocessed state on ring reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 35 +++-----------------------
 1 file changed, 4 insertions(+), 31 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4 -31
index 37dcec2d07841..04b2e3def5098 100644
@@ -6283,21 +6283,6 @@ static void gfx_v11_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring,
 			       ref, mask, 0x20);
 }
 
-static void gfx_v11_0_ring_soft_recovery(struct amdgpu_ring *ring,
-					 unsigned vmid)
-{
-	struct amdgpu_device *adev = ring->adev;
-	uint32_t value = 0;
-
-	value = REG_SET_FIELD(value, SQ_CMD, CMD, 0x03);
-	value = REG_SET_FIELD(value, SQ_CMD, MODE, 0x01);
-	value = REG_SET_FIELD(value, SQ_CMD, CHECK_VMID, 1);
-	value = REG_SET_FIELD(value, SQ_CMD, VM_ID, vmid);
-	amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
-	WREG32_SOC15(GC, 0, regSQ_CMD, value);
-	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
-}
-
 static void
 gfx_v11_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev,
 				      uint32_t me, uint32_t pipe,
@@ -6821,7 +6806,7 @@ static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring,
 	if (amdgpu_sriov_vf(adev))
 		return -EINVAL;
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
 	r = amdgpu_mes_reset_legacy_queue(ring->adev, ring, vmid, false);
 	if (r) {
@@ -6844,12 +6829,7 @@ static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring,
 		return r;
 	}
 
-	r = amdgpu_ring_test_ring(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static int gfx_v11_0_reset_compute_pipe(struct amdgpu_ring *ring)
@@ -6992,7 +6972,7 @@ static int gfx_v11_0_reset_kcq(struct amdgpu_ring *ring,
 	if (amdgpu_sriov_vf(adev))
 		return -EINVAL;
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
 	r = amdgpu_mes_reset_legacy_queue(ring->adev, ring, vmid, true);
 	if (r) {
@@ -7013,12 +6993,7 @@ static int gfx_v11_0_reset_kcq(struct amdgpu_ring *ring,
 		return r;
 	}
 
-	r = amdgpu_ring_test_ring(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static void gfx_v11_ip_print(struct amdgpu_ip_block *ip_block, struct drm_printer *p)
@@ -7254,7 +7229,6 @@ static const struct amdgpu_ring_funcs gfx_v11_0_ring_funcs_gfx = {
 	.emit_wreg = gfx_v11_0_ring_emit_wreg,
 	.emit_reg_wait = gfx_v11_0_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = gfx_v11_0_ring_emit_reg_write_reg_wait,
-	.soft_recovery = gfx_v11_0_ring_soft_recovery,
 	.emit_mem_sync = gfx_v11_0_emit_mem_sync,
 	.reset = gfx_v11_0_reset_kgq,
 	.emit_cleaner_shader = gfx_v11_0_ring_emit_cleaner_shader,
@@ -7296,7 +7270,6 @@ static const struct amdgpu_ring_funcs gfx_v11_0_ring_funcs_compute = {
 	.emit_wreg = gfx_v11_0_ring_emit_wreg,
 	.emit_reg_wait = gfx_v11_0_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = gfx_v11_0_ring_emit_reg_write_reg_wait,
-	.soft_recovery = gfx_v11_0_ring_soft_recovery,
 	.emit_mem_sync = gfx_v11_0_emit_mem_sync,
 	.reset = gfx_v11_0_reset_kcq,
 	.emit_cleaner_shader = gfx_v11_0_ring_emit_cleaner_shader,
Signature · 1 line
2.50.0
author maintainer
#19 lore raw

PATCH v13 8/28 drm/amdgpu/gfx12: re-emit unprocessed state on ring reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 35 +++-----------------------
 1 file changed, 4 insertions(+), 31 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4 -31
index e4fc42470cf3e..a3be2b46177c3 100644
@@ -4690,21 +4690,6 @@ static void gfx_v12_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring,
 			       ref, mask, 0x20);
 }
 
-static void gfx_v12_0_ring_soft_recovery(struct amdgpu_ring *ring,
-					 unsigned vmid)
-{
-	struct amdgpu_device *adev = ring->adev;
-	uint32_t value = 0;
-
-	value = REG_SET_FIELD(value, SQ_CMD, CMD, 0x03);
-	value = REG_SET_FIELD(value, SQ_CMD, MODE, 0x01);
-	value = REG_SET_FIELD(value, SQ_CMD, CHECK_VMID, 1);
-	value = REG_SET_FIELD(value, SQ_CMD, VM_ID, vmid);
-	amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
-	WREG32_SOC15(GC, 0, regSQ_CMD, value);
-	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
-}
-
 static void
 gfx_v12_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev,
 				      uint32_t me, uint32_t pipe,
@@ -5317,7 +5302,7 @@ static int gfx_v12_0_reset_kgq(struct amdgpu_ring *ring,
 	if (amdgpu_sriov_vf(adev))
 		return -EINVAL;
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
 	r = amdgpu_mes_reset_legacy_queue(ring->adev, ring, vmid, false);
 	if (r) {
@@ -5339,12 +5324,7 @@ static int gfx_v12_0_reset_kgq(struct amdgpu_ring *ring,
 		return r;
 	}
 
-	r = amdgpu_ring_test_ring(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static int gfx_v12_0_reset_compute_pipe(struct amdgpu_ring *ring)
@@ -5440,7 +5420,7 @@ static int gfx_v12_0_reset_kcq(struct amdgpu_ring *ring,
 	if (amdgpu_sriov_vf(adev))
 		return -EINVAL;
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
 	r = amdgpu_mes_reset_legacy_queue(ring->adev, ring, vmid, true);
 	if (r) {
@@ -5461,12 +5441,7 @@ static int gfx_v12_0_reset_kcq(struct amdgpu_ring *ring,
 		return r;
 	}
 
-	r = amdgpu_ring_test_ring(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static void gfx_v12_0_ring_begin_use(struct amdgpu_ring *ring)
@@ -5544,7 +5519,6 @@ static const struct amdgpu_ring_funcs gfx_v12_0_ring_funcs_gfx = {
 	.emit_wreg = gfx_v12_0_ring_emit_wreg,
 	.emit_reg_wait = gfx_v12_0_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = gfx_v12_0_ring_emit_reg_write_reg_wait,
-	.soft_recovery = gfx_v12_0_ring_soft_recovery,
 	.emit_mem_sync = gfx_v12_0_emit_mem_sync,
 	.reset = gfx_v12_0_reset_kgq,
 	.emit_cleaner_shader = gfx_v12_0_ring_emit_cleaner_shader,
@@ -5583,7 +5557,6 @@ static const struct amdgpu_ring_funcs gfx_v12_0_ring_funcs_compute = {
 	.emit_wreg = gfx_v12_0_ring_emit_wreg,
 	.emit_reg_wait = gfx_v12_0_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = gfx_v12_0_ring_emit_reg_write_reg_wait,
-	.soft_recovery = gfx_v12_0_ring_soft_recovery,
 	.emit_mem_sync = gfx_v12_0_emit_mem_sync,
 	.reset = gfx_v12_0_reset_kcq,
 	.emit_cleaner_shader = gfx_v12_0_ring_emit_cleaner_shader,
Signature · 1 line
2.50.0
author maintainer
#20 lore raw

PATCH v13 9/28 drm/amdgpu/sdma5: re-emit unprocessed state on ring reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +14 -3
index 5a1098bdd8256..577b002fe566c 100644
@@ -1544,14 +1544,25 @@ static int sdma_v5_0_reset_queue(struct amdgpu_ring *ring,
 				 struct amdgpu_fence *timedout_fence)
 {
 	struct amdgpu_device *adev = ring->adev;
-	u32 inst_id = ring->me;
 	int r;
 
+	if (amdgpu_sriov_vf(adev))
+		return -EINVAL;
+
+	if (ring->me >= adev->sdma.num_instances) {
+		DRM_ERROR("sdma instance not found\n");
+		return -EINVAL;
+	}
+
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
+
 	amdgpu_amdkfd_suspend(adev, true);
-	r = amdgpu_sdma_reset_engine(adev, inst_id, false);
+	r = amdgpu_sdma_reset_engine(adev, ring->me, true);
 	amdgpu_amdkfd_resume(adev, true);
+	if (r)
+		return r;
 
-	return r;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static int sdma_v5_0_stop_queue(struct amdgpu_ring *ring)
Signature · 1 line
2.50.0
#21 lore raw

Re: [PATCH 09/28] drm/amdgpu/sdma5: re-emit unprocessed state on ring reset

Quoted 15 lines · Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +0 -0
index 5a1098bdd8256..577b002fe566c 100644
@@ -1544,14 +1544,25 @@ static int sdma_v5_0_reset_queue(struct amdgpu_ring *ring,
 				 struct amdgpu_fence *timedout_fence)
 {
 	struct amdgpu_device *adev = ring->adev;

drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c static int sdma_v5_0_reset_queue(struct amdgpu_ring *ring, · line 1555

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +7 -1
-	u32 inst_id = ring->me;
 	int r;
 
+	if (amdgpu_sriov_vf(adev))
+		return -EINVAL;
+
+	if (ring->me >= adev->sdma.num_instances) {
+		DRM_ERROR("sdma instance not found\n");
+		return -EINVAL;
+	}

Nitpick:
Are these checks part of this commit? I noticed you made a similar modification in the next commit. Maybe you can put these checks in a single commit before this one?

Thanks

Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +7 -2
+
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
+
 	amdgpu_amdkfd_suspend(adev, true);
-	r = amdgpu_sdma_reset_engine(adev, inst_id, false);
+	r = amdgpu_sdma_reset_engine(adev, ring->me, true);
 	amdgpu_amdkfd_resume(adev, true);
+	if (r)
+		return r;
 
-	return r;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static int sdma_v5_0_stop_queue(struct amdgpu_ring *ring)
Signature · 1 line
2.50.0
Signature · 1 line
Rodrigo Siqueira
author maintainer
#22 lore raw

PATCH v13 10/28 drm/amdgpu/sdma5.2: re-emit unprocessed state on ring reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +14 -3
index 6843c2c3d71f5..5547d0d948672 100644
@@ -1457,14 +1457,25 @@ static int sdma_v5_2_reset_queue(struct amdgpu_ring *ring,
 				 struct amdgpu_fence *timedout_fence)
 {
 	struct amdgpu_device *adev = ring->adev;
-	u32 inst_id = ring->me;
 	int r;
 
+	if (amdgpu_sriov_vf(adev))
+		return -EINVAL;
+
+	if (ring->me >= adev->sdma.num_instances) {
+		DRM_ERROR("sdma instance not found\n");
+		return -EINVAL;
+	}
+
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
+
 	amdgpu_amdkfd_suspend(adev, true);
-	r = amdgpu_sdma_reset_engine(adev, inst_id, false);
+	r = amdgpu_sdma_reset_engine(adev, ring->me, true);
 	amdgpu_amdkfd_resume(adev, true);
+	if (r)
+		return r;
 
-	return r;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static int sdma_v5_2_stop_queue(struct amdgpu_ring *ring)
Signature · 1 line
2.50.0
author maintainer
#23 lore raw

PATCH v13 11/28 drm/amdgpu/sdma6: re-emit unprocessed state on ring reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c +6 -12
index d2effa5318176..3e9bff854e5a9 100644
@@ -1575,33 +1575,27 @@ static int sdma_v6_0_reset_queue(struct amdgpu_ring *ring,
 				 struct amdgpu_fence *timedout_fence)
 {
 	struct amdgpu_device *adev = ring->adev;
-	int i, r;
+	int r;
 
 	if (amdgpu_sriov_vf(adev))
 		return -EINVAL;
 
-	for (i = 0; i < adev->sdma.num_instances; i++) {
-		if (ring == &adev->sdma.instance[i].ring)
-			break;
-	}
-
-	if (i == adev->sdma.num_instances) {
+	if (ring->me >= adev->sdma.num_instances) {
 		DRM_ERROR("sdma instance not found\n");
 		return -EINVAL;
 	}
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
 	r = amdgpu_mes_reset_legacy_queue(adev, ring, vmid, true);
 	if (r)
 		return r;
 
-	r = sdma_v6_0_gfx_resume_instance(adev, i, true);
+	r = sdma_v6_0_gfx_resume_instance(adev, ring->me, true);
 	if (r)
 		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static int sdma_v6_0_set_trap_irq_state(struct amdgpu_device *adev,
Signature · 1 line
2.50.0
author maintainer
#24 lore raw

PATCH v13 12/28 drm/amdgpu/sdma7: re-emit unprocessed state on ring reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c +6 -12
index 99a080bad2a3d..64322a836ebbe 100644
@@ -807,33 +807,27 @@ static int sdma_v7_0_reset_queue(struct amdgpu_ring *ring,
 				 struct amdgpu_fence *timedout_fence)
 {
 	struct amdgpu_device *adev = ring->adev;
-	int i, r;
+	int r;
 
 	if (amdgpu_sriov_vf(adev))
 		return -EINVAL;
 
-	for (i = 0; i < adev->sdma.num_instances; i++) {
-		if (ring == &adev->sdma.instance[i].ring)
-			break;
-	}
-
-	if (i == adev->sdma.num_instances) {
+	if (ring->me >= adev->sdma.num_instances) {
 		DRM_ERROR("sdma instance not found\n");
 		return -EINVAL;
 	}
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
 	r = amdgpu_mes_reset_legacy_queue(adev, ring, vmid, true);
 	if (r)
 		return r;
 
-	r = sdma_v7_0_gfx_resume_instance(adev, i, true);
+	r = sdma_v7_0_gfx_resume_instance(adev, ring->me, true);
 	if (r)
 		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 /**
Signature · 1 line
2.50.0
#25 lore raw

RE: [PATCH 12/28] drm/amdgpu/sdma7: re-emit unprocessed state on ring reset

[AMD Official Use Only - AMD Internal Distribution Only]

this patch is Reviewed-by: Jesse Zhang <[email protected]>

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Wednesday, July 2, 2025 2:45 AM
To: [email protected]; Koenig, Christian <[email protected]>; Sundararaju, Sathishkumar <[email protected]>
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 12/28] drm/amdgpu/sdma7: re-emit unprocessed state on ring reset

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c +6 -13
index 99a080bad2a3d..64322a836ebbe 100644
@@ -807,33 +807,27 @@ static int sdma_v7_0_reset_queue(struct amdgpu_ring *ring,
                                 struct amdgpu_fence *timedout_fence)  {
        struct amdgpu_device *adev = ring->adev;
-       int i, r;
+       int r;
 
        if (amdgpu_sriov_vf(adev))
                return -EINVAL;
 
-       for (i = 0; i < adev->sdma.num_instances; i++) {
-               if (ring == &adev->sdma.instance[i].ring)
-                       break;
-       }
-
-       if (i == adev->sdma.num_instances) {
+       if (ring->me >= adev->sdma.num_instances) {
                DRM_ERROR("sdma instance not found\n");
                return -EINVAL;
        }
 
-       drm_sched_wqueue_stop(&ring->sched);
+       amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
        r = amdgpu_mes_reset_legacy_queue(adev, ring, vmid, true);
        if (r)
                return r;
 
-       r = sdma_v7_0_gfx_resume_instance(adev, i, true);
+       r = sdma_v7_0_gfx_resume_instance(adev, ring->me, true);
        if (r)
                return r;
-       amdgpu_fence_driver_force_completion(ring);
-       drm_sched_wqueue_start(&ring->sched);
-       return 0;
+
+       return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 /**
--

2.50.0

author maintainer
#26 lore raw

PATCH v13 13/28 drm/amdgpu/jpeg2: re-emit unprocessed state on ring reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +2 -9
index 781a5a8a83614..cb66eff499662 100644
@@ -768,17 +768,10 @@ static int jpeg_v2_0_ring_reset(struct amdgpu_ring *ring,
 				unsigned int vmid,
 				struct amdgpu_fence *timedout_fence)
 {
-	int r;
-
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 	jpeg_v2_0_stop(ring->adev);
 	jpeg_v2_0_start(ring->adev);
-	r = amdgpu_ring_test_helper(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static const struct amd_ip_funcs jpeg_v2_0_ip_funcs = {
Signature · 1 line
2.50.0
author maintainer
#27 lore raw

PATCH v13 14/28 drm/amdgpu/jpeg2.5: re-emit unprocessed state on ring reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +2 -9
index 5be9cdcae32c1..7432990f77507 100644
@@ -647,17 +647,10 @@ static int jpeg_v2_5_ring_reset(struct amdgpu_ring *ring,
 				unsigned int vmid,
 				struct amdgpu_fence *timedout_fence)
 {
-	int r;
-
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 	jpeg_v2_5_stop_inst(ring->adev, ring->me);
 	jpeg_v2_5_start_inst(ring->adev, ring->me);
-	r = amdgpu_ring_test_helper(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static const struct amd_ip_funcs jpeg_v2_5_ip_funcs = {
Signature · 1 line
2.50.0
author maintainer
#28 lore raw

PATCH v13 15/28 drm/amdgpu/jpeg3: re-emit unprocessed state on ring reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +2 -9
index a24bd833d6442..5598fa40764a7 100644
@@ -559,17 +559,10 @@ static int jpeg_v3_0_ring_reset(struct amdgpu_ring *ring,
 				unsigned int vmid,
 				struct amdgpu_fence *timedout_fence)
 {
-	int r;
-
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 	jpeg_v3_0_stop(ring->adev);
 	jpeg_v3_0_start(ring->adev);
-	r = amdgpu_ring_test_helper(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static const struct amd_ip_funcs jpeg_v3_0_ip_funcs = {
Signature · 1 line
2.50.0
author maintainer
#29 lore raw

PATCH v13 16/28 drm/amdgpu/jpeg4: re-emit unprocessed state on ring reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +2 -9
index 1d4edd77837d0..e9acbd5afbb7b 100644
@@ -724,20 +724,13 @@ static int jpeg_v4_0_ring_reset(struct amdgpu_ring *ring,
 				unsigned int vmid,
 				struct amdgpu_fence *timedout_fence)
 {
-	int r;
-
 	if (amdgpu_sriov_vf(ring->adev))
 		return -EINVAL;
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 	jpeg_v4_0_stop(ring->adev);
 	jpeg_v4_0_start(ring->adev);
-	r = amdgpu_ring_test_helper(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static const struct amd_ip_funcs jpeg_v4_0_ip_funcs = {
Signature · 1 line
2.50.0
author maintainer
#30 lore raw

PATCH v13 17/28 drm/amdgpu/jpeg4.0.3: re-emit unprocessed state on ring reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +2 -9
index 78441f8fce972..c3f73a2a911b4 100644
@@ -1147,20 +1147,13 @@ static int jpeg_v4_0_3_ring_reset(struct amdgpu_ring *ring,
 				  unsigned int vmid,
 				  struct amdgpu_fence *timedout_fence)
 {
-	int r;
-
 	if (amdgpu_sriov_vf(ring->adev))
 		return -EOPNOTSUPP;
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 	jpeg_v4_0_3_core_stall_reset(ring);
 	jpeg_v4_0_3_start_jrbc(ring);
-	r = amdgpu_ring_test_helper(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static const struct amd_ip_funcs jpeg_v4_0_3_ip_funcs = {
Signature · 1 line
2.50.0
author maintainer
#31 lore raw

PATCH v13 18/28 drm/amdgpu/jpeg4.0.5: add queue reset

In reply to Alex Deucher

Add queue reset support for jpeg 4.0.5.
Use the new helpers to re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +11 -0
index 974030a5c03c9..e6e90496135b6 100644
@@ -767,6 +767,16 @@ static int jpeg_v4_0_5_process_interrupt(struct amdgpu_device *adev,
 	return 0;
 }
 
+static int jpeg_v4_0_5_ring_reset(struct amdgpu_ring *ring,
+				  unsigned int vmid,
+				  struct amdgpu_fence *timedout_fence)
+{
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
+	jpeg_v4_0_5_stop(ring->adev);
+	jpeg_v4_0_5_start(ring->adev);
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
+}
+
 static const struct amd_ip_funcs jpeg_v4_0_5_ip_funcs = {
 	.name = "jpeg_v4_0_5",
 	.early_init = jpeg_v4_0_5_early_init,
@@ -812,6 +822,7 @@ static const struct amdgpu_ring_funcs jpeg_v4_0_5_dec_ring_vm_funcs = {
 	.emit_wreg = jpeg_v2_0_dec_ring_emit_wreg,
 	.emit_reg_wait = jpeg_v2_0_dec_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
+	.reset = jpeg_v4_0_5_ring_reset,
 };
 
 static void jpeg_v4_0_5_set_dec_ring_funcs(struct amdgpu_device *adev)
Signature · 1 line
2.50.0
#32 lore raw

Re: [PATCH 18/28] drm/amdgpu/jpeg4.0.5: add queue reset

Quoted 16 lines · Alex Deucher

Add queue reset support for jpeg 4.0.5.
Use the new helpers to re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +0 -0
index 974030a5c03c9..e6e90496135b6 100644

drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c static int jpeg_v4_0_5_process_interrupt(struct amdgpu_device *adev, · line 776

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +7 -0
@@ -767,6 +767,16 @@ static int jpeg_v4_0_5_process_interrupt(struct amdgpu_device *adev,
 	return 0;
 }
 
+static int jpeg_v4_0_5_ring_reset(struct amdgpu_ring *ring,
+				  unsigned int vmid,
+				  struct amdgpu_fence *timedout_fence)
+{
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
+	jpeg_v4_0_5_stop(ring->adev);
+	jpeg_v4_0_5_start(ring->adev);

Stop and start return values in case of errors. Maybe you can add a check here? If something goes wrong, you can add a log message.

Thanks

Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +4 -0
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
+}
+
 static const struct amd_ip_funcs jpeg_v4_0_5_ip_funcs = {
 	.name = "jpeg_v4_0_5",
 	.early_init = jpeg_v4_0_5_early_init,
@@ -812,6 +822,7 @@ static const struct amdgpu_ring_funcs jpeg_v4_0_5_dec_ring_vm_funcs = {
 	.emit_wreg = jpeg_v2_0_dec_ring_emit_wreg,
 	.emit_reg_wait = jpeg_v2_0_dec_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
+	.reset = jpeg_v4_0_5_ring_reset,
 };
 
 static void jpeg_v4_0_5_set_dec_ring_funcs(struct amdgpu_device *adev)
Signature · 1 line
2.50.0
Signature · 1 line
Rodrigo Siqueira
author maintainer
#33 lore raw

PATCH v13 19/28 drm/amdgpu/jpeg5: add queue reset

In reply to Alex Deucher

Add queue reset support for jpeg 5.0.0.
Use the new helpers to re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +14 -0
index 31d213ccbe0a8..351e21494365d 100644
@@ -644,6 +644,19 @@ static int jpeg_v5_0_0_process_interrupt(struct amdgpu_device *adev,
 	return 0;
 }
 
+static int jpeg_v5_0_0_ring_reset(struct amdgpu_ring *ring,
+				  unsigned int vmid,
+				  struct amdgpu_fence *timedout_fence)
+{
+	if (amdgpu_sriov_vf(ring->adev))
+		return -EINVAL;
+
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
+	jpeg_v5_0_0_stop(ring->adev);
+	jpeg_v5_0_0_start(ring->adev);
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
+}
+
 static const struct amd_ip_funcs jpeg_v5_0_0_ip_funcs = {
 	.name = "jpeg_v5_0_0",
 	.early_init = jpeg_v5_0_0_early_init,
@@ -689,6 +702,7 @@ static const struct amdgpu_ring_funcs jpeg_v5_0_0_dec_ring_vm_funcs = {
 	.emit_wreg = jpeg_v4_0_3_dec_ring_emit_wreg,
 	.emit_reg_wait = jpeg_v4_0_3_dec_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
+	.reset = jpeg_v5_0_0_ring_reset,
 };
 
 static void jpeg_v5_0_0_set_dec_ring_funcs(struct amdgpu_device *adev)
Signature · 1 line
2.50.0
author maintainer
#34 lore raw

PATCH v13 20/28 drm/amdgpu/jpeg5.0.1: re-emit unprocessed state on ring reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +2 -9
index 6f8a16da9d608..5473cbaa5c0e8 100644
@@ -838,20 +838,13 @@ static int jpeg_v5_0_1_ring_reset(struct amdgpu_ring *ring,
 				  unsigned int vmid,
 				  struct amdgpu_fence *timedout_fence)
 {
-	int r;
-
 	if (amdgpu_sriov_vf(ring->adev))
 		return -EOPNOTSUPP;
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 	jpeg_v5_0_1_core_stall_reset(ring);
 	jpeg_v5_0_1_init_jrbc(ring);
-	r = amdgpu_ring_test_helper(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static const struct amd_ip_funcs jpeg_v5_0_1_ip_funcs = {
Signature · 1 line
2.50.0
author maintainer
#35 lore raw

PATCH v13 21/28 drm/amdgpu/vcn4: re-emit unprocessed state on ring reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +2 -9
index eec9133e1b2c4..9bf1a345ac2cf 100644
@@ -1973,21 +1973,14 @@ static int vcn_v4_0_ring_reset(struct amdgpu_ring *ring,
 {
 	struct amdgpu_device *adev = ring->adev;
 	struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me];
-	int r;
 
 	if (!(adev->vcn.supported_reset & AMDGPU_RESET_TYPE_PER_QUEUE))
 		return -EOPNOTSUPP;
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 	vcn_v4_0_stop(vinst);
 	vcn_v4_0_start(vinst);
-
-	r = amdgpu_ring_test_helper(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static struct amdgpu_ring_funcs vcn_v4_0_unified_ring_vm_funcs = {
Signature · 1 line
2.50.0
author maintainer
#36 lore raw

PATCH v13 22/28 drm/amdgpu/vcn4.0.3: re-emit unprocessed state on ring reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +3 -7
index d8fd32c1e38ec..3bda19b92cde7 100644
@@ -1609,7 +1609,7 @@ static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring,
 	if (!(adev->vcn.supported_reset & AMDGPU_RESET_TYPE_PER_QUEUE))
 		return -EOPNOTSUPP;
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 
 	vcn_inst = GET_INST(VCN, ring->me);
 	r = amdgpu_dpm_reset_vcn(adev, 1 << vcn_inst);
@@ -1624,12 +1624,8 @@ static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring,
 		adev->vcn.caps |= AMDGPU_VCN_CAPS(RRMT_ENABLED);
 	vcn_v4_0_3_hw_init_inst(vinst);
 	vcn_v4_0_3_start_dpg_mode(vinst, adev->vcn.inst[ring->me].indirect_sram);
-	r = amdgpu_ring_test_helper(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static const struct amdgpu_ring_funcs vcn_v4_0_3_unified_ring_vm_funcs = {
Signature · 1 line
2.50.0
author maintainer
#37 lore raw

PATCH v13 23/28 drm/amdgpu/vcn4.0.5: re-emit unprocessed state on ring reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +2 -9
index 7e37ddea63550..faf2df7ed3fd3 100644
@@ -1471,21 +1471,14 @@ static int vcn_v4_0_5_ring_reset(struct amdgpu_ring *ring,
 {
 	struct amdgpu_device *adev = ring->adev;
 	struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me];
-	int r;
 
 	if (!(adev->vcn.supported_reset & AMDGPU_RESET_TYPE_PER_QUEUE))
 		return -EOPNOTSUPP;
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 	vcn_v4_0_5_stop(vinst);
 	vcn_v4_0_5_start(vinst);
-
-	r = amdgpu_ring_test_helper(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static struct amdgpu_ring_funcs vcn_v4_0_5_unified_ring_vm_funcs = {
Signature · 1 line
2.50.0
author maintainer
#38 lore raw

PATCH v13 24/28 drm/amdgpu/vcn5: re-emit unprocessed state on ring reset

In reply to Alex Deucher

Re-emit the unprocessed state after resetting the queue.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +2 -9
index 47c0bcc9e7d80..5997927ac6db1 100644
@@ -1198,21 +1198,14 @@ static int vcn_v5_0_0_ring_reset(struct amdgpu_ring *ring,
 {
 	struct amdgpu_device *adev = ring->adev;
 	struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[ring->me];
-	int r;
 
 	if (!(adev->vcn.supported_reset & AMDGPU_RESET_TYPE_PER_QUEUE))
 		return -EOPNOTSUPP;
 
-	drm_sched_wqueue_stop(&ring->sched);
+	amdgpu_ring_reset_helper_begin(ring, timedout_fence);
 	vcn_v5_0_0_stop(vinst);
 	vcn_v5_0_0_start(vinst);
-
-	r = amdgpu_ring_test_helper(ring);
-	if (r)
-		return r;
-	amdgpu_fence_driver_force_completion(ring);
-	drm_sched_wqueue_start(&ring->sched);
-	return 0;
+	return amdgpu_ring_reset_helper_end(ring, timedout_fence);
 }
 
 static const struct amdgpu_ring_funcs vcn_v5_0_0_unified_ring_vm_funcs = {
Signature · 1 line
2.50.0
author maintainer
#39 lore raw

PATCH v13 25/28 drm/amdgpu/vcn: add a helper framework for engine resets

In reply to Alex Deucher

With engine resets we reset all queues on the engine rather than just a single queue. Add a framework to handle this similar to SDMA.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 76 +++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h |  6 +-
 2 files changed, 81 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +76 -0
index c8885c3d54b33..f1f67521c29ca 100644
@@ -134,6 +134,7 @@ int amdgpu_vcn_sw_init(struct amdgpu_device *adev, int i)
 
 	mutex_init(&adev->vcn.inst[i].vcn1_jpeg1_workaround);
 	mutex_init(&adev->vcn.inst[i].vcn_pg_lock);
+	mutex_init(&adev->vcn.inst[i].engine_reset_mutex);
 	atomic_set(&adev->vcn.inst[i].total_submission_cnt, 0);
 	INIT_DELAYED_WORK(&adev->vcn.inst[i].idle_work, amdgpu_vcn_idle_work_handler);
 	atomic_set(&adev->vcn.inst[i].dpg_enc_submission_cnt, 0);
@@ -1451,3 +1452,78 @@ int vcn_set_powergating_state(struct amdgpu_ip_block *ip_block,
 
 	return ret;
 }
+
+/**
+ * amdgpu_vcn_reset_engine - Reset a specific VCN engine
+ * @adev: Pointer to the AMDGPU device
+ * @instance_id: VCN engine instance to reset
+ *
+ * Returns: 0 on success, or a negative error code on failure.
+ */
+static int amdgpu_vcn_reset_engine(struct amdgpu_device *adev,
+				   uint32_t instance_id)
+{
+	struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[instance_id];
+	int r, i;
+
+	mutex_lock(&vinst->engine_reset_mutex);
+	/* Stop the scheduler's work queue for the dec and enc rings if they are running.
+	 * This ensures that no new tasks are submitted to the queues while
+	 * the reset is in progress.
+	 */
+	drm_sched_wqueue_stop(&vinst->ring_dec.sched);
+	for (i = 0; i < vinst->num_enc_rings; i++)
+		drm_sched_wqueue_stop(&vinst->ring_enc[i].sched);
+
+	/* Perform the VCN reset for the specified instance */
+	r = vinst->reset(vinst);
+	if (r)
+		goto unlock;
+	r = amdgpu_ring_test_ring(&vinst->ring_dec);
+	if (r)
+		goto unlock;
+	for (i = 0; i < vinst->num_enc_rings; i++) {
+		r = amdgpu_ring_test_ring(&vinst->ring_enc[i]);
+		if (r)
+			goto unlock;
+	}
+	amdgpu_fence_driver_force_completion(&vinst->ring_dec);
+	for (i = 0; i < vinst->num_enc_rings; i++)
+		amdgpu_fence_driver_force_completion(&vinst->ring_enc[i]);
+
+	/* Restart the scheduler's work queue for the dec and enc rings
+	 * if they were stopped by this function. This allows new tasks
+	 * to be submitted to the queues after the reset is complete.
+	 */
+	drm_sched_wqueue_start(&vinst->ring_dec.sched);
+	for (i = 0; i < vinst->num_enc_rings; i++)
+		drm_sched_wqueue_start(&vinst->ring_enc[i].sched);
+
+unlock:
+	mutex_unlock(&vinst->engine_reset_mutex);
+
+	return r;
+}
+
+/**
+ * amdgpu_vcn_ring_reset - Reset a VCN ring
+ * @ring: ring to reset
+ * @vmid: vmid of guilty job
+ * @timedout_fence: fence of timed out job
+ *
+ * This helper is for VCN blocks without unified queues because
+ * resetting the engine resets all queues in that case.  With
+ * unified queues we have one queue per engine.
+ * Returns: 0 on success, or a negative error code on failure.
+ */
+int amdgpu_vcn_ring_reset(struct amdgpu_ring *ring,
+			  unsigned int vmid,
+			  struct amdgpu_fence *timedout_fence)
+{
+	struct amdgpu_device *adev = ring->adev;
+
+	if (adev->vcn.inst[ring->me].using_unified_queue)
+		return -EINVAL;
+
+	return amdgpu_vcn_reset_engine(adev, ring->me);
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +5 -1
index 83adf81defc71..0bc0a94d7cf0f 100644
@@ -330,7 +330,9 @@ struct amdgpu_vcn_inst {
 			      struct dpg_pause_state *new_state);
 	int (*set_pg_state)(struct amdgpu_vcn_inst *vinst,
 			    enum amd_powergating_state state);
+	int (*reset)(struct amdgpu_vcn_inst *vinst);
 	bool using_unified_queue;
+	struct mutex		engine_reset_mutex;
 };
 
 struct amdgpu_vcn_ras {
@@ -552,5 +554,7 @@ void amdgpu_debugfs_vcn_sched_mask_init(struct amdgpu_device *adev);
 
 int vcn_set_powergating_state(struct amdgpu_ip_block *ip_block,
 			      enum amd_powergating_state state);
-
+int amdgpu_vcn_ring_reset(struct amdgpu_ring *ring,
+			  unsigned int vmid,
+			  struct amdgpu_fence *guilty_fence);
 #endif
Signature · 1 line
2.50.0
author maintainer
#40 lore raw

PATCH v13 26/28 drm/amdgpu/vcn2: implement ring reset

In reply to Alex Deucher

Use the new helpers to handle engine resets for VCN.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +12 -0
index 148b651be7ca7..33d210a61483f 100644
@@ -98,6 +98,8 @@ static int vcn_v2_0_set_pg_state(struct amdgpu_vcn_inst *vinst,
 static int vcn_v2_0_pause_dpg_mode(struct amdgpu_vcn_inst *vinst,
 				   struct dpg_pause_state *new_state);
 static int vcn_v2_0_start_sriov(struct amdgpu_device *adev);
+static int vcn_v2_0_reset(struct amdgpu_vcn_inst *vinst);
+
 /**
  * vcn_v2_0_early_init - set function pointers and load microcode
  *
@@ -213,6 +215,7 @@ static int vcn_v2_0_sw_init(struct amdgpu_ip_block *ip_block)
 	}
 
 	adev->vcn.inst[0].pause_dpg_mode = vcn_v2_0_pause_dpg_mode;
+	adev->vcn.inst[0].reset = vcn_v2_0_reset;
 
 	r = amdgpu_virt_alloc_mm_table(adev);
 	if (r)
@@ -1355,6 +1358,13 @@ static int vcn_v2_0_pause_dpg_mode(struct amdgpu_vcn_inst *vinst,
 	return 0;
 }
 
+static int vcn_v2_0_reset(struct amdgpu_vcn_inst *vinst)
+{
+	vcn_v2_0_stop(vinst);
+	vcn_v2_0_start(vinst);
+	return 0;
+}
+
 static bool vcn_v2_0_is_idle(struct amdgpu_ip_block *ip_block)
 {
 	struct amdgpu_device *adev = ip_block->adev;
@@ -2176,6 +2186,7 @@ static const struct amdgpu_ring_funcs vcn_v2_0_dec_ring_vm_funcs = {
 	.emit_wreg = vcn_v2_0_dec_ring_emit_wreg,
 	.emit_reg_wait = vcn_v2_0_dec_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
+	.reset = amdgpu_vcn_ring_reset,
 };
 
 static const struct amdgpu_ring_funcs vcn_v2_0_enc_ring_vm_funcs = {
@@ -2205,6 +2216,7 @@ static const struct amdgpu_ring_funcs vcn_v2_0_enc_ring_vm_funcs = {
 	.emit_wreg = vcn_v2_0_enc_ring_emit_wreg,
 	.emit_reg_wait = vcn_v2_0_enc_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
+	.reset = amdgpu_vcn_ring_reset,
 };
 
 static void vcn_v2_0_set_dec_ring_funcs(struct amdgpu_device *adev)
Signature · 1 line
2.50.0
author maintainer
#41 lore raw

PATCH v13 27/28 drm/amdgpu/vcn2.5: implement ring reset

In reply to Alex Deucher

Use the new helpers to handle engine resets for VCN.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +11 -0
index 58b527a6b795f..49ec4a7775f90 100644
@@ -102,6 +102,7 @@ static int vcn_v2_5_pause_dpg_mode(struct amdgpu_vcn_inst *vinst,
 				   struct dpg_pause_state *new_state);
 static int vcn_v2_5_sriov_start(struct amdgpu_device *adev);
 static void vcn_v2_5_set_ras_funcs(struct amdgpu_device *adev);
+static int vcn_v2_5_reset(struct amdgpu_vcn_inst *vinst);
 
 static int amdgpu_ih_clientid_vcns[] = {
 	SOC15_IH_CLIENTID_VCN,
@@ -404,6 +405,7 @@ static int vcn_v2_5_sw_init(struct amdgpu_ip_block *ip_block)
 
 		if (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG)
 			adev->vcn.inst[j].pause_dpg_mode = vcn_v2_5_pause_dpg_mode;
+		adev->vcn.inst[j].reset = vcn_v2_5_reset;
 	}
 
 	if (amdgpu_sriov_vf(adev)) {
@@ -1816,6 +1818,7 @@ static const struct amdgpu_ring_funcs vcn_v2_5_dec_ring_vm_funcs = {
 	.emit_wreg = vcn_v2_0_dec_ring_emit_wreg,
 	.emit_reg_wait = vcn_v2_0_dec_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
+	.reset = amdgpu_vcn_ring_reset,
 };
 
 /**
@@ -1914,6 +1917,7 @@ static const struct amdgpu_ring_funcs vcn_v2_5_enc_ring_vm_funcs = {
 	.emit_wreg = vcn_v2_0_enc_ring_emit_wreg,
 	.emit_reg_wait = vcn_v2_0_enc_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
+	.reset = amdgpu_vcn_ring_reset,
 };
 
 static void vcn_v2_5_set_dec_ring_funcs(struct amdgpu_device *adev)
@@ -1942,6 +1946,13 @@ static void vcn_v2_5_set_enc_ring_funcs(struct amdgpu_device *adev)
 	}
 }
 
+static int vcn_v2_5_reset(struct amdgpu_vcn_inst *vinst)
+{
+	vcn_v2_5_stop(vinst);
+	vcn_v2_5_start(vinst);
+	return 0;
+}
+
 static bool vcn_v2_5_is_idle(struct amdgpu_ip_block *ip_block)
 {
 	struct amdgpu_device *adev = ip_block->adev;
Signature · 1 line
2.50.0
author maintainer
#42 lore raw

PATCH v13 28/28 drm/amdgpu/vcn3: implement ring reset

In reply to Alex Deucher

Use the new helpers to handle engine resets for VCN.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +13 -0
index 9fb0d53805892..dd015bc6fd0ee 100644
@@ -110,6 +110,7 @@ static int vcn_v3_0_set_pg_state(struct amdgpu_vcn_inst *vinst,
 				 enum amd_powergating_state state);
 static int vcn_v3_0_pause_dpg_mode(struct amdgpu_vcn_inst *vinst,
 				   struct dpg_pause_state *new_state);
+static int vcn_v3_0_reset(struct amdgpu_vcn_inst *vinst);
 
 static void vcn_v3_0_dec_ring_set_wptr(struct amdgpu_ring *ring);
 static void vcn_v3_0_enc_ring_set_wptr(struct amdgpu_ring *ring);
@@ -289,6 +290,7 @@ static int vcn_v3_0_sw_init(struct amdgpu_ip_block *ip_block)
 
 		if (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG)
 			adev->vcn.inst[i].pause_dpg_mode = vcn_v3_0_pause_dpg_mode;
+		adev->vcn.inst[i].reset = vcn_v3_0_reset;
 	}
 
 	if (amdgpu_sriov_vf(adev)) {
@@ -2033,6 +2035,7 @@ static const struct amdgpu_ring_funcs vcn_v3_0_dec_ring_vm_funcs = {
 	.emit_wreg = vcn_v2_0_dec_ring_emit_wreg,
 	.emit_reg_wait = vcn_v2_0_dec_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
+	.reset = amdgpu_vcn_ring_reset,
 };
 
 /**
@@ -2131,6 +2134,7 @@ static const struct amdgpu_ring_funcs vcn_v3_0_enc_ring_vm_funcs = {
 	.emit_wreg = vcn_v2_0_enc_ring_emit_wreg,
 	.emit_reg_wait = vcn_v2_0_enc_ring_emit_reg_wait,
 	.emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper,
+	.reset = amdgpu_vcn_ring_reset,
 };
 
 static void vcn_v3_0_set_dec_ring_funcs(struct amdgpu_device *adev)
@@ -2164,6 +2168,15 @@ static void vcn_v3_0_set_enc_ring_funcs(struct amdgpu_device *adev)
 	}
 }
 
+static int vcn_v3_0_reset(struct amdgpu_vcn_inst *vinst)
+{
+	vcn_v3_0_stop(vinst);
+	vcn_v3_0_enable_clock_gating(vinst);
+	vcn_v3_0_enable_static_power_gating(vinst);
+	vcn_v3_0_start(vinst);
+	return 0;
+}
+
 static bool vcn_v3_0_is_idle(struct amdgpu_ip_block *ip_block)
 {
 	struct amdgpu_device *adev = ip_block->adev;
Signature · 1 line
2.50.0
#43 lore raw
In reply to Alex Deucher
Quoted 10 lines · Alex Deucher

This set improves per queue reset support for a number of IPs. When we reset the queue, the queue is lost so we need to re-emit the unprocessed state from subsequent submissions. This is handled in gfx/compute queues via switch buffer and pipeline sync packets. However, you can still end up with parallel execution across queues. For correctness in that cause, enforce isolation needs to be enabled. That can impact certain use cases however and in most cases, the guilty job is correctly identified even without enforce isolation.

Quoted 2 lines

Tested on GC 10 and 11 chips with a game running and then running hang tests. The game pauses when the

Hi Alex,

Which hang test did you run?

Thanks

Quoted 123 lines

hang happens, then continues after the queue reset.

The same approach is extended to SDMA and VCN. They don't need enforce isolation because those engines are single threaded so they always operate serially.

Rework re-emit to signal the seq number of the bad job and verify that to verify that the reset worked, then re-emit the rest of the non-guilty state. This way we are not waiting on the rest of the state to complete, and if the subsequent state also contains a bad job, we'll end up in queue reset again rather than adapter reset.

Patches apply to the amd-staging-drm-next or drm-next branches in my git tree.

Git tree:
https://gitlab.freedesktop.org/agd5f/linux/-/commits/kq_resets?ref_type=heads

The IGT deadlock tests need the following fixes to properly handle -ETIME fences:
https://patchwork.freedesktop.org/series/150724/

v4: Drop explicit padding patches
Drop new timeout macro
Rework re-emit sequence
v5: Add a helper for reemit
Convert VCN, JPEG, SDMA to use new helpers
v6: Update SDMA 4.4.2 to use new helpers
Move ptr tracking to amdgpu_fence
Skip all jobs from the bad context on the ring
v7: Rework the backup logic
Move and clean up the guilty logic for engine resets Integrate suggestions from Christian
Add JPEG 4.0.5 support
v8: Add non-guilty ring backup handling
Clean up new function signatures
Reorder some bug fixes to the start of the series
v9: Clean up fence_emit
SDMA 5.x fixes
Add new reset helpers
sched wqueue stop/start cleanup
Add support for VCNs without unified queues
v10: Drop enforce isolation default change
Add more documentation
Clean up ring backup logic
v11: SDMA6/7 fixes
v12: Ring backup and reemit fixes
SDMA cleanups
SDMA5.x reemit support
GFX10 KGQ reset fix
v13: drop SDMA cleaups, they caused regressions in some IGT tests

Alex Deucher (28):
drm/amdgpu/sdma: consolidate engine reset handling drm/amdgpu/sdma: allow caller to handle kernel rings in engine reset drm/amdgpu: track ring state associated with a fence drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset drm/amdgpu/gfx9.4.3: re-emit unprocessed state on kcq reset drm/amdgpu/gfx10: re-emit unprocessed state on ring reset drm/amdgpu/gfx11: re-emit unprocessed state on ring reset drm/amdgpu/gfx12: re-emit unprocessed state on ring reset drm/amdgpu/sdma5: re-emit unprocessed state on ring reset drm/amdgpu/sdma5.2: re-emit unprocessed state on ring reset drm/amdgpu/sdma6: re-emit unprocessed state on ring reset drm/amdgpu/sdma7: re-emit unprocessed state on ring reset drm/amdgpu/jpeg2: re-emit unprocessed state on ring reset drm/amdgpu/jpeg2.5: re-emit unprocessed state on ring reset drm/amdgpu/jpeg3: re-emit unprocessed state on ring reset drm/amdgpu/jpeg4: re-emit unprocessed state on ring reset drm/amdgpu/jpeg4.0.3: re-emit unprocessed state on ring reset drm/amdgpu/jpeg4.0.5: add queue reset
drm/amdgpu/jpeg5: add queue reset
drm/amdgpu/jpeg5.0.1: re-emit unprocessed state on ring reset drm/amdgpu/vcn4: re-emit unprocessed state on ring reset drm/amdgpu/vcn4.0.3: re-emit unprocessed state on ring reset drm/amdgpu/vcn4.0.5: re-emit unprocessed state on ring reset drm/amdgpu/vcn5: re-emit unprocessed state on ring reset drm/amdgpu/vcn: add a helper framework for engine resets drm/amdgpu/vcn2: implement ring reset
drm/amdgpu/vcn2.5: implement ring reset
drm/amdgpu/vcn3: implement ring reset

 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c     | 90 +++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c        | 15 +++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c       |  4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c      | 67 ++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h      | 18 ++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c      | 43 +++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h      |  3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c       | 76 ++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h       |  6 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        |  4 +
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c        | 41 ++-------
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c        | 35 +-------
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c        | 35 +-------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         | 12 +--
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c       | 12 +--
 drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c        | 11 +--
 drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c        | 11 +--
 drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c        | 11 +--
 drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c        | 11 +--
 drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c      | 11 +--
 drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c      | 11 +++
 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c      | 14 +++
 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c      | 11 +--
 drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c      | 19 +---
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c        | 23 +++--
 drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c        | 23 +++--
 drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c        | 18 ++--
 drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c        | 18 ++--
 drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c         | 12 +++
 drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c         | 11 +++
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c         | 13 +++
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c         | 11 +--
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c       | 10 +--
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c       | 11 +--
 drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c       | 11 +--
 .../drm/amd/amdkfd/kfd_device_queue_manager.c |  2 +-
 36 files changed, 454 insertions(+), 280 deletions(-)
Signature · 1 line
2.50.0
Signature · 1 line
Rodrigo Siqueira
#44 lore raw
Quoted 12 lines · Rodrigo Siqueira
Quoted 10 lines · Alex Deucher

This set improves per queue reset support for a number of IPs. When we reset the queue, the queue is lost so we need to re-emit the unprocessed state from subsequent submissions. This is handled in gfx/compute queues via switch buffer and pipeline sync packets. However, you can still end up with parallel execution across queues. For correctness in that cause, enforce isolation needs to be enabled. That can impact certain use cases however and in most cases, the guilty job is correctly identified even without enforce isolation.

Quoted 6 lines
Quoted 2 lines

Tested on GC 10 and 11 chips with a game running and then running hang tests. The game pauses when the

Hi Alex,

Which hang test did you run?

The hang tests in HangTestSuite and IGT.

Alex

Quoted 129 lines

Thanks

Quoted 120 lines

hang happens, then continues after the queue reset.

The same approach is extended to SDMA and VCN. They don't need enforce isolation because those engines are single threaded so they always operate serially.

Rework re-emit to signal the seq number of the bad job and verify that to verify that the reset worked, then re-emit the rest of the non-guilty state. This way we are not waiting on the rest of the state to complete, and if the subsequent state also contains a bad job, we'll end up in queue reset again rather than adapter reset.

Patches apply to the amd-staging-drm-next or drm-next branches in my git tree.

Git tree:
https://gitlab.freedesktop.org/agd5f/linux/-/commits/kq_resets?ref_type=heads

The IGT deadlock tests need the following fixes to properly handle -ETIME fences:
https://patchwork.freedesktop.org/series/150724/

v4: Drop explicit padding patches
Drop new timeout macro
Rework re-emit sequence
v5: Add a helper for reemit
Convert VCN, JPEG, SDMA to use new helpers
v6: Update SDMA 4.4.2 to use new helpers
Move ptr tracking to amdgpu_fence
Skip all jobs from the bad context on the ring
v7: Rework the backup logic
Move and clean up the guilty logic for engine resets Integrate suggestions from Christian
Add JPEG 4.0.5 support
v8: Add non-guilty ring backup handling
Clean up new function signatures
Reorder some bug fixes to the start of the series
v9: Clean up fence_emit
SDMA 5.x fixes
Add new reset helpers
sched wqueue stop/start cleanup
Add support for VCNs without unified queues
v10: Drop enforce isolation default change
Add more documentation
Clean up ring backup logic
v11: SDMA6/7 fixes
v12: Ring backup and reemit fixes
SDMA cleanups
SDMA5.x reemit support
GFX10 KGQ reset fix
v13: drop SDMA cleaups, they caused regressions in some IGT tests

Alex Deucher (28):
drm/amdgpu/sdma: consolidate engine reset handling drm/amdgpu/sdma: allow caller to handle kernel rings in engine reset drm/amdgpu: track ring state associated with a fence drm/amdgpu/gfx9: re-emit unprocessed state on kcq reset drm/amdgpu/gfx9.4.3: re-emit unprocessed state on kcq reset drm/amdgpu/gfx10: re-emit unprocessed state on ring reset drm/amdgpu/gfx11: re-emit unprocessed state on ring reset drm/amdgpu/gfx12: re-emit unprocessed state on ring reset drm/amdgpu/sdma5: re-emit unprocessed state on ring reset drm/amdgpu/sdma5.2: re-emit unprocessed state on ring reset drm/amdgpu/sdma6: re-emit unprocessed state on ring reset drm/amdgpu/sdma7: re-emit unprocessed state on ring reset drm/amdgpu/jpeg2: re-emit unprocessed state on ring reset drm/amdgpu/jpeg2.5: re-emit unprocessed state on ring reset drm/amdgpu/jpeg3: re-emit unprocessed state on ring reset drm/amdgpu/jpeg4: re-emit unprocessed state on ring reset drm/amdgpu/jpeg4.0.3: re-emit unprocessed state on ring reset drm/amdgpu/jpeg4.0.5: add queue reset
drm/amdgpu/jpeg5: add queue reset
drm/amdgpu/jpeg5.0.1: re-emit unprocessed state on ring reset drm/amdgpu/vcn4: re-emit unprocessed state on ring reset drm/amdgpu/vcn4.0.3: re-emit unprocessed state on ring reset drm/amdgpu/vcn4.0.5: re-emit unprocessed state on ring reset drm/amdgpu/vcn5: re-emit unprocessed state on ring reset drm/amdgpu/vcn: add a helper framework for engine resets drm/amdgpu/vcn2: implement ring reset
drm/amdgpu/vcn2.5: implement ring reset
drm/amdgpu/vcn3: implement ring reset

 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c     | 90 +++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c        | 15 +++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c       |  4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c      | 67 ++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h      | 18 ++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c      | 43 +++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h      |  3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c       | 76 ++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h       |  6 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        |  4 +
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c        | 41 ++-------
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c        | 35 +-------
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c        | 35 +-------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         | 12 +--
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c       | 12 +--
 drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c        | 11 +--
 drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c        | 11 +--
 drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c        | 11 +--
 drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c        | 11 +--
 drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c      | 11 +--
 drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c      | 11 +++
 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c      | 14 +++
 drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c      | 11 +--
 drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c      | 19 +---
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c        | 23 +++--
 drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c        | 23 +++--
 drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c        | 18 ++--
 drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c        | 18 ++--
 drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c         | 12 +++
 drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c         | 11 +++
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c         | 13 +++
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c         | 11 +--
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c       | 10 +--
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c       | 11 +--
 drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c       | 11 +--
 .../drm/amd/amdkfd/kfd_device_queue_manager.c |  2 +-
 36 files changed, 454 insertions(+), 280 deletions(-)
Quoted 3 lines

--
2.50.0

--
Rodrigo Siqueira