Skip to contentSkip to conversation

drm/amdgpu: defer userq reset after eviction failure

PATCH In review Prike Liang 4 participants 30 messages Sep 29 – Oct 9

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

PATCH v2 1/14 drm/amdgpu: defer userq reset after eviction failure

Eviction recovery must not run while the suspend worker holds userq_mutex or is in a DMA-fence signalling critical section. Queue the reset after dropping both, and retry a requested eviction after successful recovery. Meanwhile, retry and force signal the pending signal eviction fence to avoid the dead userq attached the reservation fences forever.

Fixes c8ed2de0f2ee ("drm/amdgpu: rework userq reset work handling")
---
 .../drm/amd/amdgpu/amdgpu_eviction_fence.c    | 14 +++++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c     | 22 ++++++++++++-------
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h     |  2 +-
 3 files changed, 26 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +11 -3
index a0802012de49..15897c3eacb7 100644
@@ -65,6 +65,7 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)
 	struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
 	struct dma_fence *ev_fence;
 	bool cookie;
+	int r;
 
 	mutex_lock(&uq_mgr->userq_mutex);
 
@@ -79,21 +80,28 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)
 	cookie = dma_fence_begin_signalling();
 
 	ev_fence = amdgpu_evf_mgr_get_fence(evf_mgr);
-	amdgpu_userq_evict(uq_mgr);
+	r = amdgpu_userq_evict(uq_mgr);
 
 	/*
 	 * Signaling the eviction fence must be done while holding the
 	 * userq_mutex. Otherwise we won't resume the queues before issuing the
 	 * next fence.
 	 */
-	dma_fence_signal(ev_fence);
+	if (!r)
+		dma_fence_signal(ev_fence);
 	dma_fence_end_signalling(cookie);
 	dma_fence_put(ev_fence);
 
-	if (!evf_mgr->shutdown)
+	if (!r && !evf_mgr->shutdown)
 		schedule_delayed_work(&uq_mgr->resume_work, 0);
 
 	mutex_unlock(&uq_mgr->userq_mutex);
+
+	if (r) {
+		/* Failed removal does not establish that DMA has stopped. */
+		amdgpu_reset_domain_schedule(uq_mgr->adev->reset_domain,
+					     &uq_mgr->reset_work);
+	}
 }
 
 int amdgpu_evf_mgr_attach_fence(struct amdgpu_eviction_fence_mgr *evf_mgr,
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +14 -8
index 75d5ceaa53c6..fa8ffa060fa5 100644
@@ -91,6 +91,8 @@ static void amdgpu_userq_mgr_reset_work(struct work_struct *work)
 			     reset_work);
 	struct amdgpu_device *adev = uq_mgr->adev;
 	struct amdgpu_reset_context reset_context;
+	struct amdgpu_fpriv *fpriv = uq_mgr->file->driver_priv;
+	struct dma_fence *ev_fence;
 
 	if (unlikely(adev->debug_disable_gpu_ring_reset)) {
 		dev_err(adev->dev, "userq reset disabled by debug mask\n");
@@ -112,7 +114,15 @@ static void amdgpu_userq_mgr_reset_work(struct work_struct *work)
 	set_bit(AMDGPU_NEED_FULL_RESET, &reset_context.flags);
 	/*set_bit(AMDGPU_SKIP_COREDUMP, &reset_context.flags);*/
 
-	amdgpu_device_gpu_recover(adev, NULL, &reset_context);
+	if (amdgpu_device_gpu_recover(adev, NULL, &reset_context))
+		return;
+
+	/* Retry a pending eviction only after successful recovery. */
+	ev_fence = amdgpu_evf_mgr_get_fence(&fpriv->evf_mgr);
+	if (test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, &ev_fence->flags) &&
+	    !dma_fence_is_signaled(ev_fence))
+		schedule_work(&fpriv->evf_mgr.suspend_work);
+	dma_fence_put(ev_fence);
 }
 
 static void amdgpu_userq_hang_detect_work(struct work_struct *work)
@@ -368,8 +378,7 @@ static int amdgpu_userq_unmap_helper(struct amdgpu_usermode_queue *queue)
 
 		r = userq_funcs->unmap(queue);
 		if (r) {
-			trace_amdgpu_userq_state_changed(queue, AMDGPU_USERQ_STATE_HUNG);
-			queue->state = AMDGPU_USERQ_STATE_HUNG;
+			/* Keep removal retryable until hardware quiescence is known. */
 			return r;
 		} else {
 			trace_amdgpu_userq_state_changed(queue, AMDGPU_USERQ_STATE_UNMAPPED);
@@ -1287,9 +1296,6 @@ amdgpu_userq_evict_all(struct amdgpu_userq_mgr *uq_mgr)
 	if (ret) {
 		drm_file_err(uq_mgr->file,
 			     "Couldn't unmap all the queues, eviction failed ret=%d\n", ret);
-		amdgpu_reset_domain_schedule(uq_mgr->adev->reset_domain,
-					     &uq_mgr->reset_work);
-		flush_work(&uq_mgr->reset_work);
 	}
 	return ret;
 }
@@ -1310,10 +1316,10 @@ amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr)
 	}
 }
 
-void
+int
 amdgpu_userq_evict(struct amdgpu_userq_mgr *uq_mgr)
 {
-	amdgpu_userq_evict_all(uq_mgr);
+	return amdgpu_userq_evict_all(uq_mgr);
 }
 
 int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct drm_file *file_priv,
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +1 -1
index 488dc21d7c81..4dcf6151de6a 100644
@@ -163,7 +163,7 @@ void amdgpu_userq_mgr_cancel_resume(struct amdgpu_userq_mgr *userq_mgr);
 void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr);
 
 void amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr);
-void amdgpu_userq_evict(struct amdgpu_userq_mgr *uq_mgr);
+int amdgpu_userq_evict(struct amdgpu_userq_mgr *uq_mgr);
 
 void amdgpu_userq_ensure_ev_fence(struct amdgpu_userq_mgr *userq_mgr,
 				  struct amdgpu_eviction_fence_mgr *evf_mgr);
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 2/14 drm/amdgpu: skip VKMS mode-config helpers during GPU reset

GPU recovery already notifies DRM clients. Skip the VKMS mode-config suspend/resume helpers during that internal reset to avoid duplicate client notification and atomic-state handling under the reset lock. Keep ordinary system suspend and resume unchanged.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c +6 -0
index d6b51b3f216b..a49c7dda4c4e 100644
@@ -491,6 +491,9 @@ static int amdgpu_vkms_suspend(struct amdgpu_ip_block *ip_block)
 	struct amdgpu_device *adev = ip_block->adev;
 	int r;
 
+	if (amdgpu_in_reset(adev))
+		return 0;
+
 	r = drm_mode_config_helper_suspend(adev_to_drm(adev));
 	if (r)
 		return r;
@@ -505,6 +508,9 @@ static int amdgpu_vkms_resume(struct amdgpu_ip_block *ip_block)
 	r = amdgpu_vkms_hw_init(ip_block);
 	if (r)
 		return r;
+	if (amdgpu_in_reset(ip_block->adev))
+		return 0;
+
 	return drm_mode_config_helper_resume(adev_to_drm(ip_block->adev));
 }
 
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 3/14 drm/amdgpu: serialize userq eviction and restore with GPU reset

In reply to Prike Liang

Hold the reset-domain semaphore for read around queue eviction. If it cannot be acquired immediately under userq_mutex, release the mutex, wait for recovery, and retry the queue and fence checks. Protect eviction-fence publication and hardware mapping with the same semaphore. BO validation can wait for evictions, so it must not hold the reset semaphore across those waits.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c |  9 +++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c          | 12 ++++++++++++
 2 files changed, 21 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +9 -0
index 15897c3eacb7..f0cc49213c01 100644
@@ -67,10 +67,18 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)
 	bool cookie;
 	int r;
 
+retry:
 	mutex_lock(&uq_mgr->userq_mutex);
 
 	/* Fence waits are not allowed in a fence signalling critical section. */
 	amdgpu_userq_wait_for_signal(uq_mgr);
+	if (!down_read_trylock(&uq_mgr->adev->reset_domain->sem)) {
+		mutex_unlock(&uq_mgr->userq_mutex);
+
+		down_read(&uq_mgr->adev->reset_domain->sem);
+		up_read(&uq_mgr->adev->reset_domain->sem);
+		goto retry;
+	}
 
 	/*
 	 * This is intentionally after taking the userq_mutex since we do
@@ -81,6 +89,7 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)
 
 	ev_fence = amdgpu_evf_mgr_get_fence(evf_mgr);
 	r = amdgpu_userq_evict(uq_mgr);
+	up_read(&uq_mgr->adev->reset_domain->sem);
 
 	/*
 	 * Signaling the eviction fence must be done while holding the
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +12 -0
index fa8ffa060fa5..322c95201494 100644
@@ -1219,13 +1219,21 @@ amdgpu_userq_vm_validate_and_restore_queue(struct amdgpu_userq_mgr *uq_mgr)
 		queue->wptr_obj.gpu_addr = amdgpu_bo_gpu_offset(bo);
 	}
 
+	/* Back off without publishing a fence if recovery owns the hardware. */
+	if (!down_read_trylock(&adev->reset_domain->sem)) {
+		ret = -EAGAIN;
+		goto unlock_all;
+	}
+
 	ret = amdgpu_evf_mgr_rearm(&fpriv->evf_mgr, &exec);
 	if (ret) {
+		up_read(&adev->reset_domain->sem);
 		drm_file_err(uq_mgr->file, "Failed to replace eviction fence\n");
 		goto unlock_all;
 	}
 
 	ret = amdgpu_userq_restore_all(uq_mgr);
+	up_read(&adev->reset_domain->sem);
 
 unlock_all:
 	drm_exec_fini(&exec);
@@ -1252,6 +1260,10 @@ static void amdgpu_userq_restore_worker(struct work_struct *work)
 		goto put_fence;
 
 	ret = amdgpu_userq_vm_validate_and_restore_queue(uq_mgr);
+	if (ret == -EAGAIN) {
+		schedule_delayed_work(&uq_mgr->resume_work, msecs_to_jiffies(10));
+		goto put_fence;
+	}
 	if (ret) {
 		drm_file_err(uq_mgr->file, "Failed to validate BOs to restore ret=%d\n", ret);
 		goto put_fence;
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 4/14 drm/amdgpu: skip VMHUB fault handling while the device is inaccessible

In reply to Prike Liang

Skip GFX11 retry-fault processing and VMHUB status MMIO when reset is in progress or hardware access has been disabled. Retain a rate-limited diagnostic containing the fault address and client.

---
 drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +7 -0
index 3cdc7893587a..07b7ad753fe4 100644
@@ -115,6 +115,13 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev,
 	addr = (u64)entry->src_data[0] << 12;
 	addr |= ((u64)entry->src_data[1] & 0xf) << 44;
 
+	if (amdgpu_in_reset(adev) || adev->no_hw_access) {
+		dev_err_ratelimited(adev->dev,
+				    "[inaccessible device] page fault address 0x%016llx from client %d\n",
+				    addr, entry->client_id);
+		return 0;
+	}
+
 	if (retry_fault) {
 		cam_index = entry->src_data[2] & 0x3ff;
 
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 5/14 drm/amdgpu/userq: complete hung queue fences after successful removal

In reply to Prike Liang

Only mark an additional MES queue as hung and complete its fences after both hardware reset and removal succeed. A failed operation leaves its dependencies pending for device recovery; it does not prove DMA stopped.

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +3 -2
index fe49aa4dc5ff..3b973ea0c24a 100644
@@ -282,7 +282,6 @@ int mes_userq_reset_queue(struct amdgpu_device *adev,
 			if (uq == guilty_uq)
 				continue;
 			if (uq->doorbell_index == db) {
-				uq->state = AMDGPU_USERQ_STATE_HUNG;
 				if (use_mmio)
 					r = amdgpu_mes_reset_queue_mmio(adev, queue_type, 0, 1, pipe, queue, 0);
 				else
@@ -292,8 +291,10 @@ int mes_userq_reset_queue(struct amdgpu_device *adev,
 				r = mes_userq_unmap(uq);
 				if (r)
 					return r;
+				trace_amdgpu_userq_state_changed(uq, AMDGPU_USERQ_STATE_HUNG);
+				uq->state = AMDGPU_USERQ_STATE_HUNG;
 				amdgpu_userq_fence_driver_force_completion(uq);
-				break;
+				return 0;
 			}
 		}
 	}
Signature · 1 line
2.34.1
#5 lore raw

RE: [PATCH v2 05/14] drm/amdgpu/userq: complete hung queue fences after successful removal

AMD General

Ping..

Regards,
Prike

Quoted 48 lines

-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Tuesday, September 29, 2026 11:47 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH v2 05/14] drm/amdgpu/userq: complete hung queue fences after successful removal

Only mark an additional MES queue as hung and complete its fences after both hardware reset and removal succeed. A failed operation leaves its dependencies pending for device recovery; it does not prove DMA stopped.

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0 -1
index fe49aa4dc5ff..3b973ea0c24a 100644
@@ -282,7 +282,6 @@ int mes_userq_reset_queue(struct amdgpu_device *adev,
                      if (uq == guilty_uq)
                              continue;
                      if (uq->doorbell_index == db) {
-                             uq->state = AMDGPU_USERQ_STATE_HUNG;
                              if (use_mmio)
                                      r = amdgpu_mes_reset_queue_mmio(adev,
 queue_type, 0, 1, pipe, queue, 0);

else

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +3 -1
@@ -292,8 +291,10 @@ int mes_userq_reset_queue(struct amdgpu_device *adev,
                              r = mes_userq_unmap(uq);
                              if (r)
                                      return r;
+                             trace_amdgpu_userq_state_changed(uq,
 AMDGPU_USERQ_STATE_HUNG);
+                             uq->state = AMDGPU_USERQ_STATE_HUNG;
                              amdgpu_userq_fence_driver_force_completion(uq);
-                             break;
+                             return 0;
                      }
              }
      }

--
2.34.1

#6 lore raw

PATCH v2 6/14 drm/amdgpu/mes: move RS64 query buffer setup to software init

In reply to Prike Liang

Place the RS64 context-size query buffer's allocation with software initialization, outside reset-time hardware initialization and its firmware locks. Hardware initialization only consumes the buffer.

---
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +9 -10
index 51bfb672bed7..2f62214ab24f 100644
@@ -1746,6 +1746,7 @@ static int mes_v11_0_sw_init(struct amdgpu_ip_block *ip_block)
 	struct amdgpu_device *adev = ip_block->adev;
 	int pipe, r, bo_size;
 
+	adev->mes.use_rs64mem = false;
 	adev->mes.funcs = &mes_v11_0_funcs;
 	adev->mes.kiq_hw_init = &mes_v11_0_kiq_hw_init;
 	adev->mes.kiq_hw_fini = &mes_v11_0_kiq_hw_fini;
@@ -1796,6 +1797,14 @@ static int mes_v11_0_sw_init(struct amdgpu_ip_block *ip_block)
 		return r;
 	}
 
+	/* Allocate GPU buffer for array size query results */
+	r = amdgpu_mes_rs64mem_init(&adev->mes);
+	if (r) {
+		dev_warn(adev->dev,
+			 "RS64 memory init failed (%d), using system memory\n", r);
+		adev->mes.use_rs64mem = false;
+	}
+
 	return 0;
 }
 
@@ -1973,8 +1982,6 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block *ip_block)
 	if (adev->mes.ring[0].sched.ready)
 		goto out;
 
-	adev->mes.use_rs64mem = false;
-
 	if (!adev->enable_mes_kiq) {
 		if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT) {
 			r = mes_v11_0_load_microcode(adev,
@@ -1992,14 +1999,6 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block *ip_block)
 	if (r)
 		goto failure;
 
-	/* Allocate GPU buffer for array size query results */
-	r = amdgpu_mes_rs64mem_init(&adev->mes);
-	if (r) {
-		dev_warn(adev->dev,
-			 "RS64 local memory init failed (%d),"
-			 "falling back to system memory path\n", r);
-		adev->mes.use_rs64mem = false;
-	}
 	r = mes_v11_0_set_hw_resources(&adev->mes);
 
 	if (r)
Signature · 1 line
2.34.1
#7 lore raw

RE: [PATCH v2 06/14] drm/amdgpu/mes: move RS64 query buffer setup to software init

AMD General

Ping, any comments?

Regards,
Prike

Quoted 76 lines

-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Tuesday, September 29, 2026 11:47 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH v2 06/14] drm/amdgpu/mes: move RS64 query buffer setup to software init

Place the RS64 context-size query buffer's allocation with software initialization, outside reset-time hardware initialization and its firmware locks. Hardware initialization only consumes the buffer.

---
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +1 -0
index 51bfb672bed7..2f62214ab24f 100644
@@ -1746,6 +1746,7 @@ static int mes_v11_0_sw_init(struct amdgpu_ip_block
 *ip_block)
      struct amdgpu_device *adev = ip_block->adev;
      int pipe, r, bo_size;
 
+     adev->mes.use_rs64mem = false;
      adev->mes.funcs = &mes_v11_0_funcs;
      adev->mes.kiq_hw_init = &mes_v11_0_kiq_hw_init;
      adev->mes.kiq_hw_fini = &mes_v11_0_kiq_hw_fini; @@ -1796,6 +1797,14
@@ static int mes_v11_0_sw_init(struct amdgpu_ip_block *ip_block)
              return r;
      }
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +8 -2
+     /* Allocate GPU buffer for array size query results */
+     r = amdgpu_mes_rs64mem_init(&adev->mes);
+     if (r) {
+             dev_warn(adev->dev,
+                      "RS64 memory init failed (%d), using system memory\n", r);
+             adev->mes.use_rs64mem = false;
+     }
+
      return 0;
 }
@@ -1973,8 +1982,6 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block
 *ip_block)
      if (adev->mes.ring[0].sched.ready)
              goto out;
 
-     adev->mes.use_rs64mem = false;
-
      if (!adev->enable_mes_kiq) {
              if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT) {
                      r = mes_v11_0_load_microcode(adev,
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +0 -8
@@ -1992,14 +1999,6 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block
 *ip_block)
      if (r)
              goto failure;
 
-     /* Allocate GPU buffer for array size query results */
-     r = amdgpu_mes_rs64mem_init(&adev->mes);
-     if (r) {
-             dev_warn(adev->dev,
-                      "RS64 local memory init failed (%d),"
-                      "falling back to system memory path\n", r);
-             adev->mes.use_rs64mem = false;
-     }
      r = mes_v11_0_set_hw_resources(&adev->mes);
 
      if (r)

--
2.34.1

#8 lore raw

RE: [PATCH v2 06/14] drm/amdgpu/mes: move RS64 query buffer setup to software init

AMD General

Looks good to me .
You can add me as RB .

Shaoyun.liu

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Liang, Prike
Sent: Thursday, October 8, 2026 8:30 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Prosyak, Vitaly <[email protected]>; Chen, Michael <[email protected]>
Subject: RE: [PATCH v2 06/14] drm/amdgpu/mes: move RS64 query buffer setup to software init

AMD General

Ping, any comments?

Regards,
Prike

Quoted 78 lines

-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Tuesday, September 29, 2026 11:47 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH v2 06/14] drm/amdgpu/mes: move RS64 query buffer setup to software init

Place the RS64 context-size query buffer's allocation with software initialization, outside reset-time hardware initialization and its firmware locks. Hardware initialization only consumes the buffer.

---
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +0 -0
index 51bfb672bed7..2f62214ab24f 100644
@@ -1746,6 +1746,7 @@ static int mes_v11_0_sw_init(struct

amdgpu_ip_block
*ip_block)

      struct amdgpu_device *adev = ip_block->adev;
      int pipe, r, bo_size;
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +10 -0
+     adev->mes.use_rs64mem = false;
      adev->mes.funcs = &mes_v11_0_funcs;
      adev->mes.kiq_hw_init = &mes_v11_0_kiq_hw_init;
      adev->mes.kiq_hw_fini = &mes_v11_0_kiq_hw_fini; @@ -1796,6
+1797,14 @@ static int mes_v11_0_sw_init(struct amdgpu_ip_block *ip_block)
              return r;
      }
 
+     /* Allocate GPU buffer for array size query results */
+     r = amdgpu_mes_rs64mem_init(&adev->mes);
+     if (r) {
+             dev_warn(adev->dev,
+                      "RS64 memory init failed (%d), using system memory\n", r);
+             adev->mes.use_rs64mem = false;
+     }
+
      return 0;
 }
@@ -1973,8 +1982,6 @@ static int mes_v11_0_hw_init(struct

amdgpu_ip_block
*ip_block)

      if (adev->mes.ring[0].sched.ready)
              goto out;
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +1 -2
-     adev->mes.use_rs64mem = false;
-
      if (!adev->enable_mes_kiq) {
              if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT) {
                      r = mes_v11_0_load_microcode(adev, @@ -1992,14
+1999,6 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block

*ip_block)

      if (r)
              goto failure;
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +0 -9
-     /* Allocate GPU buffer for array size query results */
-     r = amdgpu_mes_rs64mem_init(&adev->mes);
-     if (r) {
-             dev_warn(adev->dev,
-                      "RS64 local memory init failed (%d),"
-                      "falling back to system memory path\n", r);
-             adev->mes.use_rs64mem = false;
-     }
      r = mes_v11_0_set_hw_resources(&adev->mes);
 
      if (r)
--

2.34.1

#9 lore raw

PATCH v2 7/14 drm/amdgpu: finish GPU recovery callbacks before restarting schedulers

In reply to Prike Liang

Run GPU post-reset callbacks, including KFD and display-audio resume, before restarting DRM scheduler workqueues. IP hardware initialization already happens inside ASIC recovery; this change orders the remaining callbacks before new scheduler submissions. Preserve the emergency-stop and guity job completition path's callbacks without starting schedulers,

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7 -6
index fa67de6d066c..83d98c9191b0 100644
@@ -5783,8 +5783,10 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
 
 	amdgpu_device_halt_activities(adev, job, reset_context, &device_list,
 				      hive, need_emergency_restart);
-	if (need_emergency_restart)
-		goto skip_sched_resume;
+	if (need_emergency_restart) {
+		amdgpu_device_gpu_resume(adev, &device_list, need_emergency_restart);
+		goto reset_unlock;
+	}
 	/*
 	 * Must check guilty signal here since after this point all old
 	 * HW fences are force signaled.
@@ -5794,18 +5796,17 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
 	if (job && (dma_fence_get_status(&job->hw_fence->base) > 0)) {
 		job_signaled = true;
 		dev_info(adev->dev, "Guilty job already signaled, skipping HW reset");
-		goto skip_hw_reset;
+		goto post_resume;
 	}
 
 	r = amdgpu_device_asic_reset(adev, &device_list, reset_context);
 	if (r)
 		goto reset_unlock;
-skip_hw_reset:
+post_resume:
+	amdgpu_device_gpu_resume(adev, &device_list, need_emergency_restart);
 	r = amdgpu_device_sched_resume(&device_list, reset_context, job_signaled);
 	if (r)
 		goto reset_unlock;
-skip_sched_resume:
-	amdgpu_device_gpu_resume(adev, &device_list, need_emergency_restart);
 reset_unlock:
 	amdgpu_device_recovery_put_reset_lock(adev, &device_list);
 	amdgpu_ras_post_reset(adev, &device_list);
Signature · 1 line
2.34.1
#10 lore raw

RE: [PATCH v2 07/14] drm/amdgpu: finish GPU recovery callbacks before restarting schedulers

AMD General

Ping, reviews are appreciated.

Regards,
Prike

Quoted 68 lines

-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Tuesday, September 29, 2026 11:47 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH v2 07/14] drm/amdgpu: finish GPU recovery callbacks before restarting schedulers

Run GPU post-reset callbacks, including KFD and display-audio resume, before restarting DRM scheduler workqueues. IP hardware initialization already happens inside ASIC recovery; this change orders the remaining callbacks before new scheduler submissions. Preserve the emergency-stop and guity job completition path's callbacks without starting schedulers,

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -2
index fa67de6d066c..83d98c9191b0 100644
@@ -5783,8 +5783,10 @@ int amdgpu_device_gpu_recover(struct amdgpu_device
 *adev,
 
      amdgpu_device_halt_activities(adev, job, reset_context, &device_list,
                                    hive, need_emergency_restart);
-     if (need_emergency_restart)
-             goto skip_sched_resume;
+     if (need_emergency_restart) {
+             amdgpu_device_gpu_resume(adev, &device_list,
 need_emergency_restart);
+             goto reset_unlock;
+     }
      /*

* Must check guilty signal here since after this point all old
* HW fences are force signaled.

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -4
@@ -5794,18 +5796,17 @@ int amdgpu_device_gpu_recover(struct
 amdgpu_device *adev,
      if (job && (dma_fence_get_status(&job->hw_fence->base) > 0)) {
              job_signaled = true;
              dev_info(adev->dev, "Guilty job already signaled, skipping HW
 reset");
-             goto skip_hw_reset;
+             goto post_resume;
      }
 
      r = amdgpu_device_asic_reset(adev, &device_list, reset_context);
      if (r)
              goto reset_unlock;
-skip_hw_reset:
+post_resume:
+     amdgpu_device_gpu_resume(adev, &device_list, need_emergency_restart);
      r = amdgpu_device_sched_resume(&device_list, reset_context,
 job_signaled);
      if (r)
              goto reset_unlock;
-skip_sched_resume:
-     amdgpu_device_gpu_resume(adev, &device_list, need_emergency_restart);

reset_unlock:

      amdgpu_device_recovery_put_reset_lock(adev, &device_list);
      amdgpu_ras_post_reset(adev, &device_list);

--
2.34.1

#11 lore raw

PATCH v2 8/14 drm/amdgpu: drop userq_mutex before waiting for GPU reset

In reply to Prike Liang

Use a reset-domain read trylock for queue mapping and teardown. On contention, drop userq_mutex, wait for reset, then retry. Doorbell removal requires that read lock from its caller instead of acquiring it inside the queue mutex. Disabling the work prevents an IRQ from rearming it between the initial cancellation and removal from the doorbell xarray. Apply the same drain to creation's error path after unpublishing the doorbell.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 60 ++++++++++++++++++-----
 1 file changed, 49 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +49 -11
index 322c95201494..a745c752f459 100644
@@ -428,9 +428,12 @@ static void amdgpu_userq_detach_doorbell(struct amdgpu_usermode_queue *queue)
 {
 	struct amdgpu_device *adev = queue->userq_mgr->adev;
 
-	down_read(&adev->reset_domain->sem);
+	/*
+	 * The caller serializes doorbell removal against an in-progress GPU
+	 * reset by holding adev->reset_domain->sem for read.
+	 */
+	lockdep_assert_held_read(&adev->reset_domain->sem);
 	xa_erase_irq(&adev->userq_doorbell_xa, queue->doorbell_index);
-	up_read(&adev->reset_domain->sem);
 }
 
 /**
@@ -549,13 +552,32 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que
 	trace_amdgpu_userq_destroy_start(queue);
 
 	cancel_delayed_work_sync(&uq_mgr->resume_work);
-	/* Cancel before taking userq_mutex: cancel_delayed_work_sync() waits
-	 * for any running instance, which itself takes userq_mutex.
+	/* Keep hang recovery available until the last submission completes. */
+	amdgpu_userq_wait_for_last_fence(queue);
+	/*
+	 * Disable IRQ requeueing before draining hang detection. The worker
+	 * may take userq_mutex and trigger recovery, so neither that mutex nor
+	 * the reset semaphore may be held while waiting for it.
 	 */
-	cancel_delayed_work_sync(&queue->hang_detect_work);
-
+	disable_delayed_work_sync(&queue->hang_detect_work);
+retry:
 	mutex_lock(&uq_mgr->userq_mutex);
-	amdgpu_userq_wait_for_last_fence(queue);
+
+	/*
+	 * Serialize queue teardown (doorbell detach and MES unmap) against an
+	 * in-progress GPU reset. Do not block on the reset semaphore while
+	 * holding userq_mutex: recovery takes the semaphore for write and then
+	 * (transitively) userq_mutex, so blocking here would invert that order
+	 * and deadlock. If the trylock fails, drop userq_mutex, wait for
+	 * recovery to finish, and retry.
+	 */
+	if (!down_read_trylock(&adev->reset_domain->sem)) {
+		mutex_unlock(&uq_mgr->userq_mutex);
+
+		down_read(&adev->reset_domain->sem);
+		up_read(&adev->reset_domain->sem);
+		goto retry;
+	}
 
 	amdgpu_userq_detach_doorbell(queue);
 
@@ -566,6 +588,7 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que
 	atomic_dec(&uq_mgr->userq_count[queue->queue_type]);
 	amdgpu_userq_fence_driver_free(queue);
 	queue->fence_drv = NULL;
+	up_read(&adev->reset_domain->sem);
 	mutex_unlock(&uq_mgr->userq_mutex);
 
 	/*
@@ -761,16 +784,28 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	if (r)
 		goto clean_mqd;
 
+map_retry:
 	amdgpu_userq_ensure_ev_fence(&fpriv->userq_mgr, &fpriv->evf_mgr);
 
 	/* don't map the queue if scheduling is halted */
 	if (!adev->userq_halt_for_enforce_isolation ||
 	    ((queue->queue_type != AMDGPU_HW_IP_GFX) &&
 	     (queue->queue_type != AMDGPU_HW_IP_COMPUTE))) {
-		/* Serialize the map against an in-progress GPU reset (MES is
-		 * unresponsive during recovery), matching amdgpu_userq_detach_doorbell().
+		/*
+		 * Serialize the map against an in-progress GPU reset (MES is
+		 * unresponsive during recovery). Do not block on the reset
+		 * semaphore while holding userq_mutex: recovery takes the
+		 * semaphore for write and then (transitively) userq_mutex, so
+		 * blocking here would invert that order and deadlock. If the
+		 * trylock fails, drop userq_mutex, wait for recovery, and retry.
 		 */
-		down_read(&adev->reset_domain->sem);
+		if (!down_read_trylock(&adev->reset_domain->sem)) {
+			mutex_unlock(&uq_mgr->userq_mutex);
+
+			down_read(&adev->reset_domain->sem);
+			up_read(&adev->reset_domain->sem);
+			goto map_retry;
+		}
 		r = amdgpu_userq_map_helper(queue);
 		up_read(&adev->reset_domain->sem);
 		if (r) {
@@ -803,7 +838,10 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	return 0;
 
 erase_doorbell:
-	xa_erase_irq(&adev->userq_doorbell_xa, index);
+	down_read(&adev->reset_domain->sem);
+	amdgpu_userq_detach_doorbell(queue);
+	up_read(&adev->reset_domain->sem);
+	disable_delayed_work_sync(&queue->hang_detect_work);
 clean_mqd:
 	uq_funcs->mqd_destroy(queue);
 clean_doorbell_bo:
Signature · 1 line
2.34.1
#12 lore raw

PATCH v2 9/14 drm/amdgpu: defer JPEG and VCN idle work across GPU reset

In reply to Prike Liang

Protect media idle workers with a reset-domain read trylock. On contention, requeue the idle timeout and return without hardware access. Keep the ordinary end-use scheduling event, including from reset-time ring tests, so otherwise idle engines eventually power down and VCN drops its profile.

A blocking read acquisition would deadlock with reset-time synchronous cancellation of these workers, so the workers must only try the lock.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 7 +++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 7 +++++++
 2 files changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +7 -0
index 9887a4f99aed..7b10260ad0d4 100644
@@ -114,6 +114,12 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work)
 	unsigned int fences = 0;
 	unsigned int i, j;
 
+	/* Reset may cancel this worker synchronously while holding the writer. */
+	if (!down_read_trylock(&adev->reset_domain->sem)) {
+		schedule_delayed_work(&adev->jpeg.idle_work, JPEG_IDLE_TIMEOUT);
+		return;
+	}
+
 	for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) {
 		if (adev->jpeg.harvest_config & (1U << i))
 			continue;
@@ -129,6 +135,7 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work)
 		mutex_unlock(&adev->jpeg.jpeg_pg_lock);
 	} else
 		schedule_delayed_work(&adev->jpeg.idle_work, JPEG_IDLE_TIMEOUT);
+	up_read(&adev->reset_domain->sem);
 }
 
 void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +7 -0
index 17db7264269e..f851a6ecea1b 100644
@@ -470,6 +470,12 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work)
 	if (adev->vcn.harvest_config & (1 << i))
 		return;
 
+	/* Reset may cancel this worker synchronously while holding the writer. */
+	if (!down_read_trylock(&adev->reset_domain->sem)) {
+		schedule_delayed_work(&vcn_inst->idle_work, VCN_IDLE_TIMEOUT);
+		return;
+	}
+
 	for (j = 0; j < adev->vcn.inst[i].num_enc_rings; ++j)
 		fence[i] += amdgpu_fence_count_emitted(&vcn_inst->ring_enc[j]);
 
@@ -499,6 +505,7 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work)
 	} else {
 		schedule_delayed_work(&vcn_inst->idle_work, VCN_IDLE_TIMEOUT);
 	}
+	up_read(&adev->reset_domain->sem);
 }
 
 void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring)
Signature · 1 line
2.34.1
#13 lore raw

RE: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

AMD General

Ping the fix for VCN/JPEG idle work.

Regards,
Prike

Quoted 86 lines

-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Tuesday, September 29, 2026 11:47 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Protect media idle workers with a reset-domain read trylock. On contention, requeue the idle timeout and return without hardware access. Keep the ordinary end-use scheduling event, including from reset-time ring tests, so otherwise idle engines eventually power down and VCN drops its profile.

A blocking read acquisition would deadlock with reset-time synchronous cancellation of these workers, so the workers must only try the lock.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 7 +++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 7 +++++++
 2 files changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +6 -0
index 9887a4f99aed..7b10260ad0d4 100644
@@ -114,6 +114,12 @@ static void amdgpu_jpeg_idle_work_handler(struct
 work_struct *work)
      unsigned int fences = 0;
      unsigned int i, j;
 
+     /* Reset may cancel this worker synchronously while holding the writer. */
+     if (!down_read_trylock(&adev->reset_domain->sem)) {
+             schedule_delayed_work(&adev->jpeg.idle_work,
 JPEG_IDLE_TIMEOUT);
+             return;
+     }
+
      for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) {
              if (adev->jpeg.harvest_config & (1U << i))
                      continue;
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -0
@@ -129,6 +135,7 @@ static void amdgpu_jpeg_idle_work_handler(struct
 work_struct *work)
              mutex_unlock(&adev->jpeg.jpeg_pg_lock);
      } else
              schedule_delayed_work(&adev->jpeg.idle_work,
 JPEG_IDLE_TIMEOUT);
+     up_read(&adev->reset_domain->sem);
 }

void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring) diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
index 17db7264269e..f851a6ecea1b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +6 -0
@@ -470,6 +470,12 @@ static void amdgpu_vcn_idle_work_handler(struct
 work_struct *work)
      if (adev->vcn.harvest_config & (1 << i))
              return;
 
+     /* Reset may cancel this worker synchronously while holding the writer. */
+     if (!down_read_trylock(&adev->reset_domain->sem)) {
+             schedule_delayed_work(&vcn_inst->idle_work,
 VCN_IDLE_TIMEOUT);
+             return;
+     }
+
      for (j = 0; j < adev->vcn.inst[i].num_enc_rings; ++j)
              fence[i] += amdgpu_fence_count_emitted(&vcn_inst->ring_enc[j]);
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +1 -0
@@ -499,6 +505,7 @@ static void amdgpu_vcn_idle_work_handler(struct
 work_struct *work)
      } else {
              schedule_delayed_work(&vcn_inst->idle_work,
 VCN_IDLE_TIMEOUT);
      }
+     up_read(&adev->reset_domain->sem);
 }

void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring)
--
2.34.1

#14 lore raw

Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

In reply to Prike Liang
Quoted 19 lines · Prike Liang

Protect media idle workers with a reset-domain read trylock. On contention, requeue the idle timeout and return without hardware access. Keep the ordinary end-use scheduling event, including from reset-time ring tests, so otherwise idle engines eventually power down and VCN drops its profile.

A blocking read acquisition would deadlock with reset-time synchronous cancellation of these workers, so the workers must only try the lock.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 7 +++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 7 +++++++
  2 files changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0 -0
index 9887a4f99aed..7b10260ad0d4 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c static void amdgpu_jpeg_idle_work_handler(struct work_struct *work) · line 119

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3 -0
@@ -114,6 +114,12 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work)
  	unsigned int fences = 0;
  	unsigned int i, j;
 
+	/* Reset may cancel this worker synchronously while holding the writer. */
+	if (!down_read_trylock(&adev->reset_domain->sem)) {
+		schedule_delayed_work(&adev->jpeg.idle_work, JPEG_IDLE_TIMEOUT);

Is there any need to schedule this work here? Being not able to get the lock indicates that a reset is in progress already.

Thanks,
Lijo

Quoted 39 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +4 -0
+		return;
+	}
+
  	for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) {
  		if (adev->jpeg.harvest_config & (1U << i))
  			continue;
@@ -129,6 +135,7 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work)
  		mutex_unlock(&adev->jpeg.jpeg_pg_lock);
  	} else
  		schedule_delayed_work(&adev->jpeg.idle_work, JPEG_IDLE_TIMEOUT);
+	up_read(&adev->reset_domain->sem);
  }
 
  void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +7 -0
index 17db7264269e..f851a6ecea1b 100644
@@ -470,6 +470,12 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work)
  	if (adev->vcn.harvest_config & (1 << i))
  		return;
 
+	/* Reset may cancel this worker synchronously while holding the writer. */
+	if (!down_read_trylock(&adev->reset_domain->sem)) {
+		schedule_delayed_work(&vcn_inst->idle_work, VCN_IDLE_TIMEOUT);
+		return;
+	}
+
  	for (j = 0; j < adev->vcn.inst[i].num_enc_rings; ++j)
  		fence[i] += amdgpu_fence_count_emitted(&vcn_inst->ring_enc[j]);
 
@@ -499,6 +505,7 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work)
  	} else {
  		schedule_delayed_work(&vcn_inst->idle_work, VCN_IDLE_TIMEOUT);
  	}
+	up_read(&adev->reset_domain->sem);
  }
 
  void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring)
maintainer
#15 lore raw

Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Quoted 17 lines · Lijo
Quoted 14 lines · Prike Liang

Protect media idle workers with a reset-domain read trylock. On contention, requeue the idle timeout and return without hardware access. Keep the ordinary end-use scheduling event, including from reset-time ring tests, so otherwise idle engines eventually power down and VCN drops its profile.

A blocking read acquisition would deadlock with reset-time synchronous cancellation of these workers, so the workers must only try the lock.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 7 +++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 7 +++++++

  2 files changed, 14 insertions(+)
Quoted 12 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0 -0
index 9887a4f99aed..7b10260ad0d4 100644
@@ -114,6 +114,12 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work)
       unsigned int fences = 0;
       unsigned int i, j;

  +    /* Reset may cancel this worker synchronously while holding the writer. */ +    if (!down_read_trylock(&adev->reset_domain->sem)) {
+        schedule_delayed_work(&adev->jpeg.idle_work, JPEG_IDLE_TIMEOUT);

Is there any need to schedule this work here? Being not able to get the lock indicates that a reset is in progress already.

Yeah agree. We should just block for the GPU reset to finish.

So a simple down_read(&adev->reset_domain->sem) should do it.

Regards,
Christian.

Quoted 40 lines

Thanks,
Lijo

Quoted 35 lines

+        return;
+    }
+
      for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) { if (adev->jpeg.harvest_config & (1U << i)) continue;

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -0
@@ -129,6 +135,7 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work)
           mutex_unlock(&adev->jpeg.jpeg_pg_lock);
       } else
           schedule_delayed_work(&adev->jpeg.idle_work, JPEG_IDLE_TIMEOUT);
+    up_read(&adev->reset_domain->sem);
   }
     void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0 -0
index 17db7264269e..f851a6ecea1b 100644
@@ -470,6 +470,12 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work)
       if (adev->vcn.harvest_config & (1 << i))
           return;

  +    /* Reset may cancel this worker synchronously while holding the writer. */ +    if (!down_read_trylock(&adev->reset_domain->sem)) {
+        schedule_delayed_work(&vcn_inst->idle_work, VCN_IDLE_TIMEOUT);
+        return;
+    }
+
      for (j = 0; j < adev->vcn.inst[i].num_enc_rings; ++j)
          fence[i] += amdgpu_fence_count_emitted(&vcn_inst->ring_enc[j]); @@ -499,6 +505,7 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) } else {
          schedule_delayed_work(&vcn_inst->idle_work, VCN_IDLE_TIMEOUT);
      }
+    up_read(&adev->reset_domain->sem);
  }
    void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring)

#16 lore raw

RE: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

AMD General

Regards,
Prike

Quoted 45 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, October 8, 2026 8:34 PM
To: Lazar, Lijo <[email protected]>; Liang, Prike <[email protected]>; amd- [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Quoted 7 lines · Lijo
Quoted 4 lines · Prike Liang

Protect media idle workers with a reset-domain read trylock. On contention, requeue the idle timeout and return without hardware access. Keep the ordinary end-use scheduling event, including from reset-time ring tests, so otherwise idle engines eventually power down and VCN

drops its profile.

Quoted 10 lines
Quoted 10 lines

A blocking read acquisition would deadlock with reset-time synchronous cancellation of these workers, so the workers must only try the lock.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 7 +++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 7 +++++++
  2 files changed, 14 insertions(+)
Quoted 16 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0 -0
index 9887a4f99aed..7b10260ad0d4 100644
@@ -114,6 +114,12 @@ static void amdgpu_jpeg_idle_work_handler(struct
 work_struct *work)
      unsigned int fences = 0;
      unsigned int i, j;
  +    /* Reset may cancel this worker synchronously while holding

the writer. */

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3 -0
+    if (!down_read_trylock(&adev->reset_domain->sem)) {
+        schedule_delayed_work(&adev->jpeg.idle_work,
+JPEG_IDLE_TIMEOUT);

Is there any need to schedule this work here? Being not able to get the lock

Quoted 5 lines

indicates that a reset is in progress already.

Yeah agree. We should just block for the GPU reset to finish.

So a simple down_read(&adev->reset_domain->sem) should do it.

This patch wants to schedule a delay idle work during processing a gpu reset process, and then retry to run the VCN idle at the next scheduled loop.

Quoted 52 lines

Regards,
Christian.

Quoted 49 lines

Thanks,
Lijo

Quoted 44 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +4 -0
+        return;
+    }
+
      for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) {
          if (adev->jpeg.harvest_config & (1U << i))
              continue;
@@ -129,6 +135,7 @@ static void amdgpu_jpeg_idle_work_handler(struct
 work_struct *work)
          mutex_unlock(&adev->jpeg.jpeg_pg_lock);
      } else
          schedule_delayed_work(&adev->jpeg.idle_work,
 JPEG_IDLE_TIMEOUT);
+    up_read(&adev->reset_domain->sem);
  }

void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring) diff
--git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
index 17db7264269e..f851a6ecea1b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0 -0
@@ -470,6 +470,12 @@ static void amdgpu_vcn_idle_work_handler(struct
 work_struct *work)
      if (adev->vcn.harvest_config & (1 << i))
          return;
  +    /* Reset may cancel this worker synchronously while holding

the writer. */

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +6 -0
+    if (!down_read_trylock(&adev->reset_domain->sem)) {
+        schedule_delayed_work(&vcn_inst->idle_work,
+VCN_IDLE_TIMEOUT);
+        return;
+    }
+
      for (j = 0; j < adev->vcn.inst[i].num_enc_rings; ++j)
          fence[i] +=

amdgpu_fence_count_emitted(&vcn_inst->ring_enc[j]);
@@ -499,6 +505,7 @@ static void amdgpu_vcn_idle_work_handler(struct
work_struct *work)

      } else {
          schedule_delayed_work(&vcn_inst->idle_work,
VCN_IDLE_TIMEOUT);
      }

+ up_read(&adev->reset_domain->sem);
}
void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring)

#17 lore raw

RE: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

AMD General

Regards,
Prike

Quoted 64 lines

-----Original Message-----
From: Liang, Prike
Sent: Thursday, October 8, 2026 8:42 PM
To: Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Regards,
Prike

Quoted 13 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, October 8, 2026 8:34 PM
To: Lazar, Lijo <[email protected]>; Liang, Prike <[email protected]>; amd- [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Quoted 2 lines · Lijo
Quoted 10 lines
Quoted 6 lines · Prike Liang
Quoted 5 lines

Protect media idle workers with a reset-domain read trylock. On contention, requeue the idle timeout and return without hardware access. Keep the ordinary end-use scheduling event, including from reset-time ring tests, so otherwise idle engines eventually power down and VCN

drops its profile.

Quoted 3 lines
Quoted 3 lines

A blocking read acquisition would deadlock with reset-time synchronous cancellation of these workers, so the workers must only try the

lock.

Quoted 25 lines
Quoted 25 lines
Quoted 19 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 7 +++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 7 +++++++
  2 files changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0 -0
index 9887a4f99aed..7b10260ad0d4 100644
@@ -114,6 +114,12 @@ static void

amdgpu_jpeg_idle_work_handler(struct
work_struct *work)

      unsigned int fences = 0;
      unsigned int i, j;

+ /* Reset may cancel this worker synchronously while holding
the writer. */

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3 -0
+    if (!down_read_trylock(&adev->reset_domain->sem)) {
+        schedule_delayed_work(&adev->jpeg.idle_work,
+JPEG_IDLE_TIMEOUT);

Is there any need to schedule this work here? Being not able to get the lock

Quoted 8 lines
Quoted 5 lines

indicates that a reset is in progress already.

Yeah agree. We should just block for the GPU reset to finish.

So a simple down_read(&adev->reset_domain->sem) should do it.

This patch wants to schedule a delay idle work during processing a gpu reset process, and then retry to run the VCN idle at the next scheduled loop.

A potential deadlock can occur if the VCN/JPEG idle worker runs during a GPU reset while performing a blocking wait for the reset to complete. This patch resolves the issue by using a retry-based wait on the GPU reset semaphore within the idle worker callback.

Thanks,
Prike

Quoted 56 lines
Quoted 56 lines

Regards,
Christian.

Quoted 52 lines

Thanks,
Lijo

Quoted 47 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3 -0
+        return;
+    }
+
      for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) {
          if (adev->jpeg.harvest_config & (1U << i))
              continue;
@@ -129,6 +135,7 @@ static void

amdgpu_jpeg_idle_work_handler(struct
work_struct *work)

          mutex_unlock(&adev->jpeg.jpeg_pg_lock);
      } else
          schedule_delayed_work(&adev->jpeg.idle_work,

JPEG_IDLE_TIMEOUT);
+ up_read(&adev->reset_domain->sem);
}
void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring) diff
--git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
index 17db7264269e..f851a6ecea1b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0 -0
@@ -470,6 +470,12 @@ static void

amdgpu_vcn_idle_work_handler(struct
work_struct *work)

      if (adev->vcn.harvest_config & (1 << i))
          return;

+ /* Reset may cancel this worker synchronously while holding
the writer. */

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +6 -0
+    if (!down_read_trylock(&adev->reset_domain->sem)) {
+        schedule_delayed_work(&vcn_inst->idle_work,
+VCN_IDLE_TIMEOUT);
+        return;
+    }
+
      for (j = 0; j < adev->vcn.inst[i].num_enc_rings; ++j)
          fence[i] +=

amdgpu_fence_count_emitted(&vcn_inst->ring_enc[j]);
@@ -499,6 +505,7 @@ static void
amdgpu_vcn_idle_work_handler(struct work_struct *work)

      } else {
          schedule_delayed_work(&vcn_inst->idle_work,
VCN_IDLE_TIMEOUT);
      }

+ up_read(&adev->reset_domain->sem);
}
void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring)

#18 lore raw

Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Quoted 71 lines · Prike

AMD General

Regards,
Prike

Quoted 66 lines

-----Original Message-----
From: Liang, Prike
Sent: Thursday, October 8, 2026 8:42 PM
To: Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Regards,
Prike

Quoted 13 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, October 8, 2026 8:34 PM
To: Lazar, Lijo <[email protected]>; Liang, Prike <[email protected]>; amd- [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Quoted 2 lines · Lijo
Quoted 10 lines
Quoted 6 lines · Prike Liang
Quoted 5 lines

Protect media idle workers with a reset-domain read trylock. On contention, requeue the idle timeout and return without hardware access. Keep the ordinary end-use scheduling event, including from reset-time ring tests, so otherwise idle engines eventually power down and VCN

drops its profile.

Quoted 3 lines
Quoted 3 lines

A blocking read acquisition would deadlock with reset-time synchronous cancellation of these workers, so the workers must only try the

lock.

Quoted 27 lines
Quoted 17 lines
Quoted 17 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 7 +++++++
   drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 7 +++++++
   2 files changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0 -0
index 9887a4f99aed..7b10260ad0d4 100644
@@ -114,6 +114,12 @@ static void

amdgpu_jpeg_idle_work_handler(struct
work_struct *work)

       unsigned int fences = 0;
       unsigned int i, j;
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c

Quoted 5 lines

+ /* Reset may cancel this worker synchronously while holding
the writer. */

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3 -0
+    if (!down_read_trylock(&adev->reset_domain->sem)) {
+        schedule_delayed_work(&adev->jpeg.idle_work,
+JPEG_IDLE_TIMEOUT);

Is there any need to schedule this work here? Being not able to get the lock

indicates that a reset is in progress already.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

Yeah agree. We should just block for the GPU reset to finish.

So a simple down_read(&adev->reset_domain->sem) should do it.

This patch wants to schedule a delay idle work during processing a gpu reset process, and then retry to run the VCN idle at the next scheduled loop.

A potential deadlock can occur if the VCN/JPEG idle worker runs during a GPU reset while performing a blocking wait for the reset to complete. This patch resolves the issue by using a retry-based wait on the GPU reset semaphore within the idle worker callback.

VCN is going to be idle after a reset. The next idle worker will be scheduled after a fresh job submission is complete. Why we need to reschedule idle work here?

Thanks,
Lijo

Quoted 59 lines

Thanks,
Prike

Quoted 56 lines
Quoted 56 lines

Regards,
Christian.

Quoted 52 lines

Thanks,
Lijo

Quoted 47 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3 -0
+        return;
+    }
+
       for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) {
           if (adev->jpeg.harvest_config & (1U << i))
               continue;
@@ -129,6 +135,7 @@ static void

amdgpu_jpeg_idle_work_handler(struct
work_struct *work)

           mutex_unlock(&adev->jpeg.jpeg_pg_lock);
       } else
           schedule_delayed_work(&adev->jpeg.idle_work,

JPEG_IDLE_TIMEOUT);
+ up_read(&adev->reset_domain->sem);
}
void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring) diff
--git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
index 17db7264269e..f851a6ecea1b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0 -0
@@ -470,6 +470,12 @@ static void

amdgpu_vcn_idle_work_handler(struct
work_struct *work)

       if (adev->vcn.harvest_config & (1 << i))
           return;

+ /* Reset may cancel this worker synchronously while holding
the writer. */

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +6 -0
+    if (!down_read_trylock(&adev->reset_domain->sem)) {
+        schedule_delayed_work(&vcn_inst->idle_work,
+VCN_IDLE_TIMEOUT);
+        return;
+    }
+
       for (j = 0; j < adev->vcn.inst[i].num_enc_rings; ++j)
           fence[i] +=
amdgpu_fence_count_emitted(&vcn_inst->ring_enc[j]);
   @@ -499,6 +505,7 @@ static void
amdgpu_vcn_idle_work_handler(struct
work_struct *work)
       } else {
           schedule_delayed_work(&vcn_inst->idle_work,
VCN_IDLE_TIMEOUT);
       }

+ up_read(&adev->reset_domain->sem);
}
void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring)

#19 lore raw

RE: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

AMD General

Regards,
Prike

Quoted 92 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, October 9, 2026 12:50 PM
To: Liang, Prike <[email protected]>; Koenig, Christian <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Quoted 79 lines · Prike

AMD General

Regards,
Prike

Quoted 73 lines

-----Original Message-----
From: Liang, Prike
Sent: Thursday, October 8, 2026 8:42 PM
To: Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Regards,
Prike

Quoted 13 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, October 8, 2026 8:34 PM
To: Lazar, Lijo <[email protected]>; Liang, Prike <[email protected]>; amd- [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Quoted 2 lines · Lijo
Quoted 11 lines
Quoted 6 lines · Prike Liang
Quoted 5 lines

Protect media idle workers with a reset-domain read trylock. On contention, requeue the idle timeout and return without hardware access. Keep the ordinary end-use scheduling event, including from reset-time ring tests, so otherwise idle engines eventually power down and VCN

drops its profile.

Quoted 4 lines
Quoted 4 lines

A blocking read acquisition would deadlock with reset-time synchronous cancellation of these workers, so the workers must only try the

lock.

Quoted 25 lines
Quoted 17 lines
Quoted 17 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 7 +++++++
   drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 7 +++++++
   2 files changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0 -0
index 9887a4f99aed..7b10260ad0d4 100644
@@ -114,6 +114,12 @@ static void

amdgpu_jpeg_idle_work_handler(struct
work_struct *work)

       unsigned int fences = 0;
       unsigned int i, j;
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c

Quoted 5 lines

+ /* Reset may cancel this worker synchronously while holding
the writer. */

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3 -0
+    if (!down_read_trylock(&adev->reset_domain->sem)) {
+        schedule_delayed_work(&adev->jpeg.idle_work,
+JPEG_IDLE_TIMEOUT);

Is there any need to schedule this work here? Being not able to get the lock

Quoted 5 lines

indicates that a reset is in progress already.

Yeah agree. We should just block for the GPU reset to finish.

So a simple down_read(&adev->reset_domain->sem) should do it.

This patch wants to schedule a delay idle work during processing a gpu reset process, and then retry to run the VCN idle at the next scheduled loop.

Quoted 8 lines
Quoted 1 line

A potential deadlock can occur if the VCN/JPEG idle worker runs during a GPU

reset while performing a blocking wait for the reset to complete. This patch resolves the issue by using a retry-based wait on the GPU reset semaphore within the idle worker callback.

Quoted 1 line

VCN is going to be idle after a reset. The next idle worker will be scheduled after a fresh job submission is complete. Why we need to reschedule idle work here?

If the VCN idle worker runs while GPU reset holds the semaphore, returning without rescheduling could leave VCN ungated if no new jobs arrive. However, blocking on the semaphore in VCN idle worker could deadlock because the reset path may synchronously cancel the worker while holding the semaphore. Using a trylock and rescheduling on contention avoids this deadlock while ensuring VCN can be power gated once reset completes.

Thanks,
Prike

Quoted 62 lines

Thanks,
Lijo

Quoted 59 lines

Thanks,
Prike

Quoted 56 lines
Quoted 56 lines

Regards,
Christian.

Quoted 52 lines

Thanks,
Lijo

Quoted 47 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3 -0
+        return;
+    }
+
       for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) {
           if (adev->jpeg.harvest_config & (1U << i))
               continue;
@@ -129,6 +135,7 @@ static void

amdgpu_jpeg_idle_work_handler(struct
work_struct *work)

           mutex_unlock(&adev->jpeg.jpeg_pg_lock);
       } else
           schedule_delayed_work(&adev->jpeg.idle_work,

JPEG_IDLE_TIMEOUT);

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -0
+    up_read(&adev->reset_domain->sem);
   }
     void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0 -0
index 17db7264269e..f851a6ecea1b 100644
@@ -470,6 +470,12 @@ static void

amdgpu_vcn_idle_work_handler(struct
work_struct *work)

       if (adev->vcn.harvest_config & (1 << i))
           return;

+ /* Reset may cancel this worker synchronously while holding
the writer. */

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +6 -0
+    if (!down_read_trylock(&adev->reset_domain->sem)) {
+        schedule_delayed_work(&vcn_inst->idle_work,
+VCN_IDLE_TIMEOUT);
+        return;
+    }
+
       for (j = 0; j < adev->vcn.inst[i].num_enc_rings; ++j)
           fence[i] +=
amdgpu_fence_count_emitted(&vcn_inst->ring_enc[j]);
   @@ -499,6 +505,7 @@ static void
amdgpu_vcn_idle_work_handler(struct
work_struct *work)
       } else {
           schedule_delayed_work(&vcn_inst->idle_work,
VCN_IDLE_TIMEOUT);
       }

+ up_read(&adev->reset_domain->sem);
}
void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring)

#20 lore raw

Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Quoted 103 lines · Prike

AMD General

Regards,
Prike

Quoted 98 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, October 9, 2026 12:50 PM
To: Liang, Prike <[email protected]>; Koenig, Christian <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Quoted 72 lines · Prike

AMD General

Regards,
Prike

Quoted 67 lines

-----Original Message-----
From: Liang, Prike
Sent: Thursday, October 8, 2026 8:42 PM
To: Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Regards,
Prike

Quoted 13 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, October 8, 2026 8:34 PM
To: Lazar, Lijo <[email protected]>; Liang, Prike <[email protected]>; amd- [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Quoted 2 lines · Lijo
Quoted 11 lines
Quoted 6 lines · Prike Liang
Quoted 5 lines

Protect media idle workers with a reset-domain read trylock. On contention, requeue the idle timeout and return without hardware access. Keep the ordinary end-use scheduling event, including from reset-time ring tests, so otherwise idle engines eventually power down and VCN

drops its profile.

Quoted 4 lines
Quoted 4 lines

A blocking read acquisition would deadlock with reset-time synchronous cancellation of these workers, so the workers must only try the

lock.

Quoted 27 lines
Quoted 17 lines
Quoted 17 lines
---
    drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 7 +++++++
    drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 7 +++++++
    2 files changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0 -0
index 9887a4f99aed..7b10260ad0d4 100644
@@ -114,6 +114,12 @@ static void

amdgpu_jpeg_idle_work_handler(struct
work_struct *work)

        unsigned int fences = 0;
        unsigned int i, j;
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c

Quoted 5 lines

+ /* Reset may cancel this worker synchronously while holding
the writer. */

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3 -0
+    if (!down_read_trylock(&adev->reset_domain->sem)) {
+        schedule_delayed_work(&adev->jpeg.idle_work,
+JPEG_IDLE_TIMEOUT);

Is there any need to schedule this work here? Being not able to get the lock

indicates that a reset is in progress already.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Yeah agree. We should just block for the GPU reset to finish.

So a simple down_read(&adev->reset_domain->sem) should do it.

This patch wants to schedule a delay idle work during processing a gpu reset process, and then retry to run the VCN idle at the next scheduled loop.

A potential deadlock can occur if the VCN/JPEG idle worker runs during a GPU

reset while performing a blocking wait for the reset to complete. This patch resolves the issue by using a retry-based wait on the GPU reset semaphore within the idle worker callback.

Quoted 1 line
Quoted 5 lines
Quoted 2 lines

VCN is going to be idle after a reset. The next idle worker will be scheduled after a fresh job submission is complete. Why we need to reschedule idle work here?

If the VCN idle worker runs while GPU reset holds the semaphore, returning without rescheduling could leave VCN ungated if no new jobs arrive. However, blocking on the semaphore in VCN idle worker could deadlock because the reset path may synchronously cancel the worker while holding the semaphore. Using a trylock and rescheduling on contention avoids this deadlock while ensuring VCN can be power gated once reset completes.

Could you clarify on the ungated part? Typically after reset, VCN ring/ib tests are run. After that it should go to idle similar to a driver load scenario.

Thanks,
Lijo

Quoted 66 lines

Thanks,
Prike

Quoted 62 lines

Thanks,
Lijo

Quoted 59 lines

Thanks,
Prike

Quoted 56 lines
Quoted 56 lines

Regards,
Christian.

Quoted 52 lines

Thanks,
Lijo

Quoted 47 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3 -0
+        return;
+    }
+
        for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) {
            if (adev->jpeg.harvest_config & (1U << i))
                continue;
@@ -129,6 +135,7 @@ static void

amdgpu_jpeg_idle_work_handler(struct
work_struct *work)

            mutex_unlock(&adev->jpeg.jpeg_pg_lock);
        } else
            schedule_delayed_work(&adev->jpeg.idle_work,

JPEG_IDLE_TIMEOUT);

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -0
+    up_read(&adev->reset_domain->sem);
    }
      void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0 -0
index 17db7264269e..f851a6ecea1b 100644
@@ -470,6 +470,12 @@ static void

amdgpu_vcn_idle_work_handler(struct
work_struct *work)

        if (adev->vcn.harvest_config & (1 << i))
            return;
    +    /* Reset may cancel this worker synchronously while holding

the writer. */

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +6 -0
+    if (!down_read_trylock(&adev->reset_domain->sem)) {
+        schedule_delayed_work(&vcn_inst->idle_work,
+VCN_IDLE_TIMEOUT);
+        return;
+    }
+
        for (j = 0; j < adev->vcn.inst[i].num_enc_rings; ++j)
            fence[i] +=
amdgpu_fence_count_emitted(&vcn_inst->ring_enc[j]);
    @@ -499,6 +505,7 @@ static void
amdgpu_vcn_idle_work_handler(struct
work_struct *work)
        } else {
            schedule_delayed_work(&vcn_inst->idle_work,
VCN_IDLE_TIMEOUT);
        }

+ up_read(&adev->reset_domain->sem);
}
void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring)

#21 lore raw

RE: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

AMD General

Regards,
Prike

Quoted 130 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, October 9, 2026 2:36 PM
To: Liang, Prike <[email protected]>; Koenig, Christian <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Quoted 96 lines · Prike

AMD General

Regards,
Prike

Quoted 91 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, October 9, 2026 12:50 PM
To: Liang, Prike <[email protected]>; Koenig, Christian <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Quoted 78 lines · Prike

AMD General

Regards,
Prike

Quoted 73 lines

-----Original Message-----
From: Liang, Prike
Sent: Thursday, October 8, 2026 8:42 PM
To: Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Regards,
Prike

Quoted 13 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, October 8, 2026 8:34 PM
To: Lazar, Lijo <[email protected]>; Liang, Prike <[email protected]>; amd- [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Quoted 2 lines · Lijo
Quoted 11 lines
Quoted 6 lines · Prike Liang
Quoted 5 lines

Protect media idle workers with a reset-domain read trylock. On contention, requeue the idle timeout and return without hardware access. Keep the ordinary end-use scheduling event, including from reset-time ring tests, so otherwise idle engines eventually power down and VCN

drops its profile.

Quoted 4 lines
Quoted 4 lines

A blocking read acquisition would deadlock with reset-time synchronous cancellation of these workers, so the workers must only try the

lock.

Quoted 25 lines
Quoted 17 lines
Quoted 17 lines
---
    drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 7 +++++++
    drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 7 +++++++
    2 files changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0 -0
index 9887a4f99aed..7b10260ad0d4 100644
@@ -114,6 +114,12 @@ static void

amdgpu_jpeg_idle_work_handler(struct
work_struct *work)

        unsigned int fences = 0;
        unsigned int i, j;
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c

Quoted 5 lines

+ /* Reset may cancel this worker synchronously while holding
the writer. */

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3 -0
+    if (!down_read_trylock(&adev->reset_domain->sem)) {
+        schedule_delayed_work(&adev->jpeg.idle_work,
+JPEG_IDLE_TIMEOUT);

Is there any need to schedule this work here? Being not able to get the lock

Quoted 5 lines

indicates that a reset is in progress already.

Yeah agree. We should just block for the GPU reset to finish.

So a simple down_read(&adev->reset_domain->sem) should do it.

This patch wants to schedule a delay idle work during processing a gpu reset process, and then retry to run the VCN idle at the next scheduled

loop.

Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

A potential deadlock can occur if the VCN/JPEG idle worker runs during a GPU

reset while performing a blocking wait for the reset to complete. This patch resolves the issue by using a retry-based wait on the GPU reset semaphore within the idle worker callback.

Quoted 1 line

VCN is going to be idle after a reset. The next idle worker will be scheduled after a fresh job submission is complete. Why we need to reschedule

idle work here?

Quoted 2 lines

If the VCN idle worker runs while GPU reset holds the semaphore, returning

without rescheduling could leave VCN ungated if no new jobs arrive. However, blocking on the semaphore in VCN idle worker could deadlock because the reset path may synchronously cancel the worker while holding the semaphore. Using a trylock and rescheduling on contention avoids this deadlock while ensuring VCN can be power gated once reset completes.

Quoted 1 line
Quoted 2 lines

Could you clarify on the ungated part? Typically after reset, VCN ring/ib tests are run. After that it should go to idle similar to a driver load scenario.

By “ungated,” I mean that if the VCN idle worker schedules and fails to acquire the reset semaphore during GPU reset holds reset semaphore and returns without rescheduling, it skips power gating through amdgpu_device_ip_set_powergating_state(). VCN may then remain ungated if no new VCN jobs arrive to schedule another idle worker.

The VCN ring/IB tests run during the recovery resume phase while the reset path may still hold the semaphore. If idle work scheduled by those tests runs before the semaphore is released, hardware accesses from the worker can trigger warnings and may be unreliable. Using a trylock and rescheduling on contention lets the worker safely gate VCN after GPU reset completes, while avoiding deadlocks and unsafe hardware accesses.

Thanks,
Prike

Quoted 69 lines

Thanks,
Lijo

Quoted 66 lines

Thanks,
Prike

Quoted 62 lines

Thanks,
Lijo

Quoted 59 lines

Thanks,
Prike

Quoted 56 lines
Quoted 56 lines

Regards,
Christian.

Quoted 52 lines

Thanks,
Lijo

Quoted 47 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3 -0
+        return;
+    }
+
        for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) {
            if (adev->jpeg.harvest_config & (1U << i))
                continue;
@@ -129,6 +135,7 @@ static void

amdgpu_jpeg_idle_work_handler(struct
work_struct *work)

            mutex_unlock(&adev->jpeg.jpeg_pg_lock);
        } else
            schedule_delayed_work(&adev->jpeg.idle_work,

JPEG_IDLE_TIMEOUT);

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -0
+    up_read(&adev->reset_domain->sem);
    }
      void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0 -0
index 17db7264269e..f851a6ecea1b 100644
@@ -470,6 +470,12 @@ static void

amdgpu_vcn_idle_work_handler(struct
work_struct *work)

        if (adev->vcn.harvest_config & (1 << i))
            return;
    +    /* Reset may cancel this worker synchronously while holding

the writer. */

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +6 -0
+    if (!down_read_trylock(&adev->reset_domain->sem)) {
+        schedule_delayed_work(&vcn_inst->idle_work,
+VCN_IDLE_TIMEOUT);
+        return;
+    }
+
        for (j = 0; j < adev->vcn.inst[i].num_enc_rings; ++j)
            fence[i] +=
amdgpu_fence_count_emitted(&vcn_inst->ring_enc[j]);
    @@ -499,6 +505,7 @@ static void
amdgpu_vcn_idle_work_handler(struct
work_struct *work)
        } else {
            schedule_delayed_work(&vcn_inst->idle_work,
VCN_IDLE_TIMEOUT);
        }

+ up_read(&adev->reset_domain->sem);
}
void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring)

maintainer
#22 lore raw

Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

In reply to Liang, Prike
Quoted 103 lines · Prike

AMD General

Regards,
Prike

Quoted 98 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, October 9, 2026 12:50 PM
To: Liang, Prike <[email protected]>; Koenig, Christian <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Quoted 72 lines · Prike

AMD General

Regards,
Prike

Quoted 67 lines

-----Original Message-----
From: Liang, Prike
Sent: Thursday, October 8, 2026 8:42 PM
To: Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Regards,
Prike

Quoted 13 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, October 8, 2026 8:34 PM
To: Lazar, Lijo <[email protected]>; Liang, Prike <[email protected]>; amd- [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Quoted 2 lines · Lijo
Quoted 11 lines
Quoted 6 lines · Prike Liang
Quoted 5 lines

Protect media idle workers with a reset-domain read trylock. On contention, requeue the idle timeout and return without hardware access. Keep the ordinary end-use scheduling event, including from reset-time ring tests, so otherwise idle engines eventually power down and VCN

drops its profile.

Quoted 4 lines
Quoted 4 lines

A blocking read acquisition would deadlock with reset-time synchronous cancellation of these workers, so the workers must only try the

lock.

Quoted 27 lines
Quoted 17 lines
Quoted 17 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 7 +++++++
   drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 7 +++++++
   2 files changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0 -0
index 9887a4f99aed..7b10260ad0d4 100644
@@ -114,6 +114,12 @@ static void

amdgpu_jpeg_idle_work_handler(struct
work_struct *work)

       unsigned int fences = 0;
       unsigned int i, j;
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c

Quoted 5 lines

+ /* Reset may cancel this worker synchronously while holding
the writer. */

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3 -0
+    if (!down_read_trylock(&adev->reset_domain->sem)) {
+        schedule_delayed_work(&adev->jpeg.idle_work,
+JPEG_IDLE_TIMEOUT);

Is there any need to schedule this work here? Being not able to get the lock

indicates that a reset is in progress already.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Yeah agree. We should just block for the GPU reset to finish.

So a simple down_read(&adev->reset_domain->sem) should do it.

This patch wants to schedule a delay idle work during processing a gpu reset process, and then retry to run the VCN idle at the next scheduled loop.

A potential deadlock can occur if the VCN/JPEG idle worker runs during a GPU

reset while performing a blocking wait for the reset to complete. This patch resolves the issue by using a retry-based wait on the GPU reset semaphore within the idle worker callback.

Quoted 1 line
Quoted 4 lines
Quoted 2 lines

VCN is going to be idle after a reset. The next idle worker will be scheduled after a fresh job submission is complete. Why we need to reschedule idle work here?

If the VCN idle worker runs while GPU reset holds the semaphore, returning without rescheduling could leave VCN ungated if no new jobs arrive. However, blocking on the semaphore in VCN idle worker could deadlock because the reset path may synchronously cancel the worker while holding the semaphore. Using a trylock and rescheduling on contention avoids this deadlock while ensuring VCN can be power gated once reset completes.

In this case absolutely clear NAK to that! Approaches like that are completely illegal upstream.

The reset work handler *CAN'T* depend on the idle work and so also can't synchronously cancel it. That is an absolutely clear NO-GO.

Just use down_read() to make sure that lockdep starts complaining when the reset handler does such nasty things.

Regards,
Christian.

Quoted 67 lines

Thanks,
Prike

Quoted 62 lines

Thanks,
Lijo

Quoted 59 lines

Thanks,
Prike

Quoted 56 lines
Quoted 56 lines

Regards,
Christian.

Quoted 52 lines

Thanks,
Lijo

Quoted 47 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3 -0
+        return;
+    }
+
       for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) {
           if (adev->jpeg.harvest_config & (1U << i))
               continue;
@@ -129,6 +135,7 @@ static void

amdgpu_jpeg_idle_work_handler(struct
work_struct *work)

           mutex_unlock(&adev->jpeg.jpeg_pg_lock);
       } else
           schedule_delayed_work(&adev->jpeg.idle_work,

JPEG_IDLE_TIMEOUT);

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -0
+    up_read(&adev->reset_domain->sem);
   }
     void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0 -0
index 17db7264269e..f851a6ecea1b 100644
@@ -470,6 +470,12 @@ static void

amdgpu_vcn_idle_work_handler(struct
work_struct *work)

       if (adev->vcn.harvest_config & (1 << i))
           return;

+ /* Reset may cancel this worker synchronously while holding
the writer. */

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +6 -0
+    if (!down_read_trylock(&adev->reset_domain->sem)) {
+        schedule_delayed_work(&vcn_inst->idle_work,
+VCN_IDLE_TIMEOUT);
+        return;
+    }
+
       for (j = 0; j < adev->vcn.inst[i].num_enc_rings; ++j)
           fence[i] +=
amdgpu_fence_count_emitted(&vcn_inst->ring_enc[j]);
   @@ -499,6 +505,7 @@ static void
amdgpu_vcn_idle_work_handler(struct
work_struct *work)
       } else {
           schedule_delayed_work(&vcn_inst->idle_work,
VCN_IDLE_TIMEOUT);
       }

+ up_read(&adev->reset_domain->sem);
}
void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring)

#23 lore raw

RE: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

AMD General

Regards,
Prike

Quoted 127 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Friday, October 9, 2026 3:42 PM
To: Liang, Prike <[email protected]>; Lazar, Lijo <[email protected]>; amd- [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Quoted 96 lines · Prike

AMD General

Regards,
Prike

Quoted 91 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, October 9, 2026 12:50 PM
To: Liang, Prike <[email protected]>; Koenig, Christian <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Quoted 78 lines · Prike

AMD General

Regards,
Prike

Quoted 73 lines

-----Original Message-----
From: Liang, Prike
Sent: Thursday, October 8, 2026 8:42 PM
To: Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Regards,
Prike

Quoted 13 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, October 8, 2026 8:34 PM
To: Lazar, Lijo <[email protected]>; Liang, Prike <[email protected]>; amd- [email protected]
Cc: Deucher, Alexander <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH v2 09/14] drm/amdgpu: defer JPEG and VCN idle work across GPU reset

Quoted 2 lines · Lijo
Quoted 11 lines
Quoted 6 lines · Prike Liang
Quoted 5 lines

Protect media idle workers with a reset-domain read trylock. On contention, requeue the idle timeout and return without hardware access. Keep the ordinary end-use scheduling event, including from reset-time ring tests, so otherwise idle engines eventually power down and VCN

drops its profile.

Quoted 4 lines
Quoted 4 lines

A blocking read acquisition would deadlock with reset-time synchronous cancellation of these workers, so the workers must only try the

lock.

Quoted 25 lines
Quoted 17 lines
Quoted 17 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 7 +++++++
   drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c  | 7 +++++++
   2 files changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0 -0
index 9887a4f99aed..7b10260ad0d4 100644
@@ -114,6 +114,12 @@ static void

amdgpu_jpeg_idle_work_handler(struct
work_struct *work)

       unsigned int fences = 0;
       unsigned int i, j;
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c

Quoted 5 lines

+ /* Reset may cancel this worker synchronously while holding
the writer. */

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3 -0
+    if (!down_read_trylock(&adev->reset_domain->sem)) {
+        schedule_delayed_work(&adev->jpeg.idle_work,
+JPEG_IDLE_TIMEOUT);

Is there any need to schedule this work here? Being not able to get the lock

Quoted 5 lines

indicates that a reset is in progress already.

Yeah agree. We should just block for the GPU reset to finish.

So a simple down_read(&adev->reset_domain->sem) should do it.

This patch wants to schedule a delay idle work during processing a gpu reset process, and then retry to run the VCN idle at the next scheduled

loop.

Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

A potential deadlock can occur if the VCN/JPEG idle worker runs during a GPU

reset while performing a blocking wait for the reset to complete. This patch resolves the issue by using a retry-based wait on the GPU reset semaphore within the idle worker callback.

Quoted 1 line

VCN is going to be idle after a reset. The next idle worker will be scheduled after a fresh job submission is complete. Why we need to reschedule

idle work here?

Quoted 2 lines

If the VCN idle worker runs while GPU reset holds the semaphore, returning

without rescheduling could leave VCN ungated if no new jobs arrive. However, blocking on the semaphore in VCN idle worker could deadlock because the reset path may synchronously cancel the worker while holding the semaphore. Using a trylock and rescheduling on contention avoids this deadlock while ensuring VCN can be power gated once reset completes.

Quoted 8 lines

In this case absolutely clear NAK to that! Approaches like that are completely illegal upstream.

The reset work handler *CAN'T* depend on the idle work and so also can't synchronously cancel it. That is an absolutely clear NO-GO.

Just use down_read() to make sure that lockdep starts complaining when the reset handler does such nasty things.

Thanks for the suggestion, will use a blocking reset read lock in the idle worker, and remove synchronous dependencies on that worker from paths holding the reset write lock.

Thanks,
Prike

Quoted 70 lines

Regards,
Christian.

Quoted 67 lines

Thanks,
Prike

Quoted 62 lines

Thanks,
Lijo

Quoted 59 lines

Thanks,
Prike

Quoted 56 lines
Quoted 56 lines

Regards,
Christian.

Quoted 52 lines

Thanks,
Lijo

Quoted 47 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3 -0
+        return;
+    }
+
       for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) {
           if (adev->jpeg.harvest_config & (1U << i))
               continue;
@@ -129,6 +135,7 @@ static void

amdgpu_jpeg_idle_work_handler(struct
work_struct *work)

           mutex_unlock(&adev->jpeg.jpeg_pg_lock);
       } else
           schedule_delayed_work(&adev->jpeg.idle_work,

JPEG_IDLE_TIMEOUT);

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -0
+    up_read(&adev->reset_domain->sem);
   }
     void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0 -0
index 17db7264269e..f851a6ecea1b 100644
@@ -470,6 +470,12 @@ static void

amdgpu_vcn_idle_work_handler(struct
work_struct *work)

       if (adev->vcn.harvest_config & (1 << i))
           return;

+ /* Reset may cancel this worker synchronously while holding
the writer. */

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +6 -0
+    if (!down_read_trylock(&adev->reset_domain->sem)) {
+        schedule_delayed_work(&vcn_inst->idle_work,
+VCN_IDLE_TIMEOUT);
+        return;
+    }
+
       for (j = 0; j < adev->vcn.inst[i].num_enc_rings; ++j)
           fence[i] +=
amdgpu_fence_count_emitted(&vcn_inst->ring_enc[j]);
   @@ -499,6 +505,7 @@ static void
amdgpu_vcn_idle_work_handler(struct
work_struct *work)
       } else {
           schedule_delayed_work(&vcn_inst->idle_work,
VCN_IDLE_TIMEOUT);
       }

+ up_read(&adev->reset_domain->sem);
}
void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring)

#24 lore raw

PATCH v2 10/14 drm/amdgpu/mes: defer unmap notifications across GPU reset

In reply to Prike Liang

Acquire the reset-domain semaphore for read with a trylock before sending the MES unmap notification. If recovery owns it, skip the hardware access but retain the periodic rearm while queues remain oversubscribed.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +5 -1
index 4cb37cdbf821..4138080edbea 100644
@@ -1192,7 +1192,11 @@ static void amdgpu_mes_userq_notify_unmap_work_handler(struct work_struct *work)
 					       userq_notify_unmap_work.work);
 	struct amdgpu_device *adev = mes->adev;
 
-	amdgpu_mes_notify_unmap_queue(adev);
+	/* Do not block reset-time cancellation or lose the periodic retry. */
+	if (down_read_trylock(&adev->reset_domain->sem)) {
+		amdgpu_mes_notify_unmap_queue(adev);
+		up_read(&adev->reset_domain->sem);
+	}
 
 	/* Re-arm if still oversubscribed */
 	if (atomic_read(&mes->userq_hw_queue_count) >
Signature · 1 line
2.34.1
#25 lore raw

RE: [PATCH v2 10/14] drm/amdgpu/mes: defer unmap notifications across GPU reset

AMD General

This will keep the MES unmap notify sent out of a GPU recovery, which make sure an available MES for serving the unmap notify request.

Ping. Any comments on this patch? Reviews are appreciated.

Regards,
Prike

Quoted 40 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Prike Liang
Sent: Tuesday, September 29, 2026 11:47 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH v2 10/14] drm/amdgpu/mes: defer unmap notifications across GPU reset

Acquire the reset-domain semaphore for read with a trylock before sending the MES unmap notification. If recovery owns it, skip the hardware access but retain the periodic rearm while queues remain oversubscribed.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +5 -1
index 4cb37cdbf821..4138080edbea 100644
@@ -1192,7 +1192,11 @@ static void
 amdgpu_mes_userq_notify_unmap_work_handler(struct work_struct *work)
                                             userq_notify_unmap_work.work);
      struct amdgpu_device *adev = mes->adev;
 
-     amdgpu_mes_notify_unmap_queue(adev);
+     /* Do not block reset-time cancellation or lose the periodic retry. */
+     if (down_read_trylock(&adev->reset_domain->sem)) {
+             amdgpu_mes_notify_unmap_queue(adev);
+             up_read(&adev->reset_domain->sem);
+     }
 
      /* Re-arm if still oversubscribed */
      if (atomic_read(&mes->userq_hw_queue_count) >

--
2.34.1

#26 lore raw

PATCH v2 11/14 drm/amdgpu/userq: complete eviction fences after hardware reset

In reply to Prike Liang

A process eviction fence protects every queue sharing its VM. Completing it from the per-queue fence helper releases sibling queues' BO dependencies and allows raw post-reset mapping with an already-signaled eviction fence.

Complete process eviction fences only after a successful device hardware reset, before resume can allocate BOs. Retire every old queue, then complete queue fences before acquiring manager mutexes to release the eviction dependencies. Old queues remain terminal even when VRAM survives; applications must recreate them. Safe transparent remapping would require a separate context and VM validation design, including a fresh eviction fence.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    | 19 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c     |  6 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c     | 98 ++++++++++++-------
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h     |  3 +-
 .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c   | 22 +++++
 5 files changed, 105 insertions(+), 43 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +12 -7
index 83d98c9191b0..74030d588a36 100644
@@ -4794,6 +4794,7 @@ static int amdgpu_device_reset_sriov(struct amdgpu_device *adev,
 		return r;
 
 	amdgpu_ras_clear_err_state(adev);
+	amdgpu_userq_reset_complete(adev);
 	amdgpu_irq_gpu_reset_resume_helper(adev);
 
 	/* some sw clean up VF needs to do before recover */
@@ -5024,6 +5025,8 @@ int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,
 		test_bit(AMDGPU_NEED_FULL_RESET, &reset_context->flags);
 	int i, r;
 
+	amdgpu_userq_pre_reset(adev);
+
 	if (reset_context->reset_req_dev == adev)
 		job = reset_context->job;
 
@@ -5192,10 +5195,6 @@ int amdgpu_device_reinit_after_reset(struct amdgpu_reset_context *reset_context)
 				if (r)
 					goto out;
 
-				r = amdgpu_userq_post_reset(tmp_adev, vram_lost);
-				if (r)
-					goto out;
-
 				drm_client_dev_resume(adev_to_drm(tmp_adev));
 
 				/*
@@ -5306,7 +5305,15 @@ int amdgpu_do_asic_reset(struct list_head *device_list_handle,
 		}
 	}
 
-	if (!r && amdgpu_ras_intr_triggered()) {
+	if (r)
+		goto out;
+
+	if (!skip_hw_reset && need_full_reset) {
+		list_for_each_entry(tmp_adev, device_list_handle, reset_list)
+			amdgpu_userq_reset_complete(tmp_adev);
+	}
+
+	if (amdgpu_ras_intr_triggered()) {
 		list_for_each_entry(tmp_adev, device_list_handle, reset_list) {
 			amdgpu_ras_reset_error_count(tmp_adev,
 						     AMDGPU_RAS_BLOCK__MMHUB);
@@ -5536,8 +5543,6 @@ static void amdgpu_device_halt_activities(struct amdgpu_device *adev,
 		if (!need_emergency_restart && !amdgpu_reset_in_dpc(adev))
 			amdgpu_ras_suspend(tmp_adev);
 
-		amdgpu_userq_pre_reset(tmp_adev);
-
 		for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
 			struct amdgpu_ring *ring = tmp_adev->rings[i];
 
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c +6 -0
index c8016fa55a92..fbc30e85a398 100644
@@ -250,6 +250,7 @@ int amdgpu_reset_prepare_hwcontext(struct amdgpu_device *adev,
 int amdgpu_reset_perform_reset(struct amdgpu_device *adev,
 			       struct amdgpu_reset_context *reset_context)
 {
+	struct amdgpu_device *tmp_adev;
 	int ret;
 	struct amdgpu_reset_handler *reset_handler = NULL;
 
@@ -263,6 +264,11 @@ int amdgpu_reset_perform_reset(struct amdgpu_device *adev,
 	if (ret)
 		return ret;
 
+	if (reset_context->reset_device_list) {
+		list_for_each_entry(tmp_adev, reset_context->reset_device_list, reset_list)
+			amdgpu_userq_reset_complete(tmp_adev);
+	}
+
 	return reset_handler->restore_hwcontext(adev->reset_cntl,
 						reset_context);
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +63 -35

161 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +2 -1
index 4dcf6151de6a..d17dbc284688 100644
@@ -38,6 +38,7 @@ enum amdgpu_userq_state {
 	AMDGPU_USERQ_STATE_PREEMPTED,
 	AMDGPU_USERQ_STATE_HUNG,
 	AMDGPU_USERQ_STATE_INVALID_VA,
+	AMDGPU_USERQ_STATE_RESET_PENDING,
 };
 
 struct amdgpu_mqd_prop;
@@ -180,7 +181,7 @@ int amdgpu_userq_start_sched_for_enforce_isolation(struct amdgpu_device *adev,
 						   u32 idx);
 void amdgpu_userq_reset_work(struct work_struct *work);
 void amdgpu_userq_pre_reset(struct amdgpu_device *adev);
-int amdgpu_userq_post_reset(struct amdgpu_device *adev, bool vram_lost);
+void amdgpu_userq_reset_complete(struct amdgpu_device *adev);
 void amdgpu_userq_start_hang_detect_work(struct amdgpu_usermode_queue *queue);
 void amdgpu_userq_process_fence_irq(struct amdgpu_device *adev, u32 doorbell);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +22 -0
index c270635c907b..b9e6753ec4cc 100644
@@ -556,11 +556,25 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
 	/* We are here means UQ is active, make sure the eviction fence is valid */
 	amdgpu_userq_ensure_ev_fence(&fpriv->userq_mgr, &fpriv->evf_mgr);
 
+	if (!down_read_trylock(&adev->reset_domain->sem)) {
+		r = -EAGAIN;
+		mutex_unlock(&userq_mgr->userq_mutex);
+		goto free_fence;
+	}
+	if (queue->state == AMDGPU_USERQ_STATE_HUNG ||
+	    queue->state == AMDGPU_USERQ_STATE_RESET_PENDING) {
+		r = -ECANCELED;
+		up_read(&adev->reset_domain->sem);
+		mutex_unlock(&userq_mgr->userq_mutex);
+		goto free_fence;
+	}
+
 	/* Create the new fence */
 	amdgpu_userq_fence_init(queue, fence, wptr);
 
 	trace_amdgpu_userq_emit_fence(dev->dev, queue, fence);
 
+	up_read(&adev->reset_domain->sem);
 	mutex_unlock(&userq_mgr->userq_mutex);
 
 	/*
@@ -609,6 +623,14 @@ int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
 	dma_fence_put(&fence->base);
 
 	drm_exec_fini(&exec);
+	goto put_queue;
+
+free_fence:
+	/* Allocation transferred the external fence-driver references. */
+	amdgpu_userq_fence_put_fence_drv_array(fence);
+	amdgpu_userq_fence_driver_put(fence->fence_drv);
+	kvfree(fence->fence_drv_array);
+	kfree(fence);
 put_queue:
 	amdgpu_userq_put(queue);
 put_gobj_write:
Signature · 1 line
2.34.1
#27 lore raw

PATCH v2 12/14 drm/amdgpu: bracket pre-reset userq removal with MES suspend and resume

In reply to Prike Liang

Suspend MES gangs before attempting to remove user queues, and resume them in the same function. Skip the operation when there are no user queues. Suspend, removal and resume are best effort while preparing hardware reset; a firmware error must not prevent that reset or be treated as proof that DMA has stopped. Queue and process fences remain pending until hardware reset succeeds.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +10 -0
index 2eba234a504e..e6ce9d12bdb4 100644
@@ -1607,6 +1607,12 @@ void amdgpu_userq_pre_reset(struct amdgpu_device *adev)
 	unsigned long queue_id;
 
 	lockdep_assert_held_write(&adev->reset_domain->sem);
+	if (xa_empty(&adev->userq_doorbell_xa))
+		return;
+
+	/* Best effort: only the subsequent hardware reset proves quiescence. */
+	if (amdgpu_mes_suspend(adev, 0))
+		dev_dbg(adev->dev, "Continuing GPU reset after MES suspend failure\n");
 
 	xa_for_each(&adev->userq_doorbell_xa, queue_id, queue) {
 		if (queue->state == AMDGPU_USERQ_STATE_MAPPED ||
@@ -1619,6 +1625,10 @@ void amdgpu_userq_pre_reset(struct amdgpu_device *adev)
 		trace_amdgpu_userq_state_changed(queue, AMDGPU_USERQ_STATE_RESET_PENDING);
 		queue->state = AMDGPU_USERQ_STATE_RESET_PENDING;
 	}
+
+	/* Pair locally, including partial suspension and failed queue removal. */
+	if (amdgpu_mes_resume(adev, 0))
+		dev_dbg(adev->dev, "Continuing GPU reset after MES resume failure\n");
 }
 
 /* Called after successful hardware reset, before allocations during resume. */
Signature · 1 line
2.34.1
#28 lore raw

PATCH v2 13/14 drm/amdgpu: prepare all locked BOs before userq rearm

In reply to Prike Liang

An individual BO can leave the VM idle list while drm_exec backs off on contention during userq restore. The retry prelocks that BO and retains it in exec->objects, but the restarted VM-list walk can skip its drm_exec_prepare_obj() call.

amdgpu_evf_mgr_rearm() still attaches an eviction fence to every locked object. With CONFIG_DEBUG_MUTEXES, the preceding unlock resets max_fences to num_fences. If ttm_bo_validate() returns without moving the BO and no existing fence can be replaced, dma_resv_add_fence() hits its capacity BUG.

---
 .../drm/amd/amdgpu/amdgpu_eviction_fence.c    |  7 +++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c     | 26 ++++++++++++++++++-
 2 files changed, 28 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +3 -4
index f0cc49213c01..8b2e25770bdf 100644
@@ -159,11 +159,10 @@ int amdgpu_evf_mgr_rearm(struct amdgpu_eviction_fence_mgr *evf_mgr,
 	dma_fence_put(evf_mgr->ev_fence);
 	evf_mgr->ev_fence = &ev_fence->base;
 
-	/* And add it to all existing BOs */
+	/* The caller has validated and reserved space on every locked BO. */
 	drm_exec_for_each_locked_object(exec, index, obj) {
-		struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
-
-		amdgpu_evf_mgr_attach_fence(evf_mgr, bo);
+		dma_resv_add_fence(obj->resv, &ev_fence->base,
+				   DMA_RESV_USAGE_BOOKKEEP);
 	}
 	return 0;
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +25 -1
index e6ce9d12bdb4..0f509e67ca1a 100644
@@ -1105,6 +1105,7 @@ amdgpu_userq_vm_validate_and_restore_queue(struct amdgpu_userq_mgr *uq_mgr)
 	struct amdgpu_bo_va *bo_va;
 	struct amdgpu_usermode_queue *queue;
 	struct amdgpu_bo *bo;
+	struct drm_gem_object *obj;
 	struct drm_exec exec;
 	struct xarray xa;
 	int ret;
@@ -1184,7 +1185,21 @@ amdgpu_userq_vm_validate_and_restore_queue(struct amdgpu_userq_mgr *uq_mgr)
 		invalidated = false;
 	}
 
-	ret = amdgpu_vm_handle_moved(adev, vm, NULL);
+	/*
+	 * A contended BO can change VM lists while drm_exec drops the locks.
+	 * Prepare every finally locked object before updating PTEs or publishing
+	 * the replacement eviction fence, including prelocked retry objects.
+	 */
+	drm_exec_for_each_locked_object(&exec, tmp_key, obj) {
+		ret = dma_resv_reserve_fences(obj->resv, TTM_NUM_MOVE_FENCES + 1);
+		if (ret)
+			goto unlock_all;
+		ret = amdgpu_userq_validate_vm(NULL, gem_to_amdgpu_bo(obj));
+		if (ret)
+			goto unlock_all;
+	}
+
+	ret = amdgpu_vm_handle_moved(adev, vm, &exec.ticket);
 	if (ret)
 		goto unlock_all;
 
@@ -1255,6 +1270,8 @@ amdgpu_userq_vm_validate_and_restore_queue(struct amdgpu_userq_mgr *uq_mgr)
 	 */
 	list_for_each_entry(bo_va, &vm->always_valid.idle, base.vm_status)
 		dma_fence_wait(bo_va->last_pt_update, false);
+	list_for_each_entry(bo_va, &vm->individual.idle, base.vm_status)
+		dma_fence_wait(bo_va->last_pt_update, false);
 	/*
 	 * The PRT bo_va is kept off the state lists, so its PTE update fence
 	 * lands in prt_va->last_pt_update rather than vm->last_update; wait on
@@ -1281,6 +1298,13 @@ amdgpu_userq_vm_validate_and_restore_queue(struct amdgpu_userq_mgr *uq_mgr)
 		queue->wptr_obj.gpu_addr = amdgpu_bo_gpu_offset(bo);
 	}
 
+	/* Page-table updates may have consumed the earlier reservation slots. */
+	drm_exec_for_each_locked_object(&exec, tmp_key, obj) {
+		ret = dma_resv_reserve_fences(obj->resv, 1);
+		if (ret)
+			goto unlock_all;
+	}
+
 	/* Back off without publishing a fence if recovery owns the hardware. */
 	if (!down_read_trylock(&adev->reset_domain->sem)) {
 		ret = -EAGAIN;
Signature · 1 line
2.34.1
#29 lore raw

PATCH v2 14/14 drm/amdgpu/userq: skip MES removal before device reset

In reply to Prike Liang

Retire all old queues after successful hardware reset. Pre-reset suspension, removal and resumption are therefore unnecessary for that lifecycle. Remove these firmware operations and only mark the queues RESET_PENDING. Leave their fences pending until hardware reset establishes quiescence, including when reset fails or is skipped. Clear the count before draining to prevent a running worker from rearming.

Fixes a33a2db6af0a ("drm/amdgpu: bracket pre-reset userq removal with MES suspend and resume")
Fixes 99f2f5b9ef67 ("drm/amdgpu/userq: complete eviction fences after hardware reset")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c    | 17 +++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h    |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c  | 33 +++++++++-------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h  |  3 ++
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 17 +++++++++--
 5 files changed, 48 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +17 -0
index 4138080edbea..851405d9fea4 100644
@@ -1243,6 +1243,23 @@ void amdgpu_mes_userq_queue_unmapped(struct amdgpu_device *adev)
 		cancel_delayed_work(&adev->mes.userq_notify_unmap_work);
 }
 
+/* Hardware reset discarded all old user queues, including failed removals. */
+void amdgpu_mes_userq_reset_complete(struct amdgpu_device *adev)
+{
+	lockdep_assert_held_write(&adev->reset_domain->sem);
+
+	if (!adev->enable_mes || amdgpu_sriov_vf(adev))
+		return;
+
+	if (!(amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(11, 0, 0) &&
+	      amdgpu_ip_version(adev, GC_HWIP, 0) < IP_VERSION(12, 0, 0)))
+		return;
+
+	/* Stop rearming before draining a worker that may have dropped its lock. */
+	atomic_set(&adev->mes.userq_hw_queue_count, 0);
+	cancel_delayed_work_sync(&adev->mes.userq_notify_unmap_work);
+}
+
 #if defined(CONFIG_DEBUG_FS)
 
 static int amdgpu_debugfs_mes_event_log_show(struct seq_file *m, void *unused)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +1 -0
index 5160b227943b..738226b3ac2a 100644
@@ -653,5 +653,6 @@ void amdgpu_mes_free_gang_ctx_index(struct amdgpu_mes *mes,
 int amdgpu_mes_notify_unmap_queue(struct amdgpu_device *adev);
 void amdgpu_mes_userq_queue_mapped(struct amdgpu_device *adev);
 void amdgpu_mes_userq_queue_unmapped(struct amdgpu_device *adev);
+void amdgpu_mes_userq_reset_complete(struct amdgpu_device *adev);
 
 #endif /* __AMDGPU_MES_H__ */
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +13 -20
index 0f509e67ca1a..5fe16185b887 100644
@@ -1626,33 +1626,21 @@ void amdgpu_userq_gem_va_unmap_validate(struct amdgpu_device *adev,
 
 void amdgpu_userq_pre_reset(struct amdgpu_device *adev)
 {
-	const struct amdgpu_userq_funcs *userq_funcs;
 	struct amdgpu_usermode_queue *queue;
 	unsigned long queue_id;
 
 	lockdep_assert_held_write(&adev->reset_domain->sem);
-	if (xa_empty(&adev->userq_doorbell_xa))
-		return;
-
-	/* Best effort: only the subsequent hardware reset proves quiescence. */
-	if (amdgpu_mes_suspend(adev, 0))
-		dev_dbg(adev->dev, "Continuing GPU reset after MES suspend failure\n");
 
+	/*
+	 * Device reset will retire these queues. Asking a faulted MES to suspend
+	 * or remove them can time out once per queue and delays the reset. Do
+	 * not resume them either: keep their memory protected until hardware
+	 * reset proves that all queue access has stopped.
+	 */
 	xa_for_each(&adev->userq_doorbell_xa, queue_id, queue) {
-		if (queue->state == AMDGPU_USERQ_STATE_MAPPED ||
-		    queue->state == AMDGPU_USERQ_STATE_PREEMPTED) {
-			trace_amdgpu_userq_state_start(queue);
-			userq_funcs = adev->userq_funcs[queue->queue_type];
-			userq_funcs->unmap(queue);
-		}
-		/* A failed unmap is not proof that hardware access has stopped. */
 		trace_amdgpu_userq_state_changed(queue, AMDGPU_USERQ_STATE_RESET_PENDING);
 		queue->state = AMDGPU_USERQ_STATE_RESET_PENDING;
 	}
-
-	/* Pair locally, including partial suspension and failed queue removal. */
-	if (amdgpu_mes_resume(adev, 0))
-		dev_dbg(adev->dev, "Continuing GPU reset after MES resume failure\n");
 }
 
 /* Called after successful hardware reset, before allocations during resume. */
@@ -1661,13 +1649,18 @@ void amdgpu_userq_reset_complete(struct amdgpu_device *adev)
 	struct amdgpu_usermode_queue *queue;
 	unsigned long queue_id;
 
+	lockdep_assert_held_write(&adev->reset_domain->sem);
+	amdgpu_mes_userq_reset_complete(adev);
+
 	if (xa_empty(&adev->userq_doorbell_xa))
 		return;
 
-	lockdep_assert_held_write(&adev->reset_domain->sem);
-
 	/* Release queue-fence waiters before acquiring their manager mutexes. */
 	xa_for_each(&adev->userq_doorbell_xa, queue_id, queue) {
+		const struct amdgpu_userq_funcs *funcs = adev->userq_funcs[queue->queue_type];
+
+		if (funcs->reset_complete)
+			funcs->reset_complete(queue);
 		trace_amdgpu_userq_state_changed(queue, AMDGPU_USERQ_STATE_HUNG);
 		queue->state = AMDGPU_USERQ_STATE_HUNG;
 		amdgpu_userq_fence_driver_force_completion(queue);
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +3 -0
index d17dbc284688..eb4e51613908 100644
@@ -103,6 +103,7 @@ struct amdgpu_usermode_queue {
 	} userq_vas;
 
 	uint32_t	gang_ctx_array_index;
+	bool		gang_ctx_allocated;
 };
 
 struct amdgpu_userq_funcs {
@@ -116,6 +117,8 @@ struct amdgpu_userq_funcs {
 	int (*preempt)(struct amdgpu_usermode_queue *queue);
 	int (*restore)(struct amdgpu_usermode_queue *queue);
 	int (*reset)(struct amdgpu_usermode_queue *queue);
+	/* Release software resources only after successful device reset. */
+	void (*reset_complete)(struct amdgpu_usermode_queue *queue);
 };
 
 /* Usermode queues for gfx */
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +14 -3
index 3b973ea0c24a..fa67899fcd32 100644
@@ -161,6 +161,7 @@ static int mes_userq_map(struct amdgpu_usermode_queue *queue)
 			DRM_ERROR("Failed to allocate userq gang index err:%d\n", r);
 			return r;
 		}
+		queue->gang_ctx_allocated = true;
 		queue_input.process_context_array_index = uq_mgr->proc_ctx_array_index;
 		queue_input.gang_context_array_index = queue->gang_ctx_array_index;
 	}
@@ -178,13 +179,23 @@ static int mes_userq_map(struct amdgpu_usermode_queue *queue)
 	return 0;
 }
 
+/* The queue must have been removed successfully or stopped by device reset. */
+static void mes_userq_release_gang_ctx(struct amdgpu_usermode_queue *queue)
+{
+	struct amdgpu_mes *mes = &queue->userq_mgr->adev->mes;
+
+	if (queue->gang_ctx_allocated) {
+		amdgpu_mes_free_gang_ctx_index(mes, queue->gang_ctx_array_index);
+		queue->gang_ctx_allocated = false;
+	}
+}
+
 static int mes_userq_unmap(struct amdgpu_usermode_queue *queue)
 {
 	struct amdgpu_userq_mgr *uq_mgr = queue->userq_mgr;
 	struct amdgpu_device *adev = uq_mgr->adev;
 	struct mes_remove_queue_input queue_input;
 	struct amdgpu_userq_obj *ctx = &queue->fw_obj;
-	struct amdgpu_mes *mes = &adev->mes;
 	int r;
 
 	memset(&queue_input, 0x0, sizeof(struct mes_remove_queue_input));
@@ -196,13 +207,12 @@ static int mes_userq_unmap(struct amdgpu_usermode_queue *queue)
 	amdgpu_mes_lock(&adev->mes);
 	r = adev->mes.funcs->remove_hw_queue(&adev->mes, &queue_input);
 	amdgpu_mes_unlock(&adev->mes);
-	if (mes->use_rs64mem)
-		amdgpu_mes_free_gang_ctx_index(mes, queue->gang_ctx_array_index);
 	if (r) {
 		DRM_ERROR("Failed to unmap queue in HW, err (%d)\n", r);
 		return r;
 	}
 
+	mes_userq_release_gang_ctx(queue);
 	amdgpu_mes_userq_queue_unmapped(adev);
 	return 0;
 }
@@ -646,4 +656,5 @@ const struct amdgpu_userq_funcs userq_mes_funcs = {
 	.preempt = mes_userq_preempt,
 	.restore = mes_userq_restore,
 	.reset = mes_userq_reset,
+	.reset_complete = mes_userq_release_gang_ctx,
 };
Signature · 1 line
2.34.1