Commit 5d75ec2e5f17 for kernel

commit 5d75ec2e5f1736c2f10c7d6f4565bf1bf29f29a7
Author: Jesse Zhang <Jesse.Zhang@amd.com>
Date:   Fri Jul 10 16:45:42 2026 +0800

    drm/amdgpu/userq: fix indefinite fence wait during GPU reset

    pre_reset only force-completes fences of MAPPED queues. A queue in any
    other state (e.g. mid-eviction) keeps its last_fence pending; after a
    GPU reset that fence never signals, so the eviction/suspend worker and
    process teardown (amdgpu_evf_mgr_flush_suspend) wait on it forever and
    wedge the machine:

      INFO: task kworker/6:28 blocked for more than 120 seconds.
      Workqueue: events amdgpu_eviction_fence_suspend_worker [amdgpu]
      Call Trace:
       dma_fence_wait_timeout+0x7e/0x130
       amdgpu_userq_evict+0x67/0x140 [amdgpu]
       amdgpu_eviction_fence_suspend_worker+0xd8/0x160 [amdgpu]
       process_scheduled_works+0xa6/0x420

    Force-complete every queue's fence regardless of state. The unmap and
    mark-hung step stays gated on MAPPED, since unmapping a queue that is
    not mapped is invalid.

    Fixes: 290f46cf5726 ("drm/amdgpu: Implement user queue reset functionality")
    Reviewed-by: Christian König <christian.koenig@amd.com>
    Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>
    Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
    (cherry picked from commit 9102b39fa924dcc3dc75a3137bfa9633c40b88c0)
    Cc: stable@vger.kernel.org

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index d854343b3734..572f2949cb64 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -1376,16 +1376,19 @@ void amdgpu_userq_pre_reset(struct amdgpu_device *adev)

 	/* TODO: We probably need a new lock for the queue state */
 	xa_for_each(&adev->userq_doorbell_xa, queue_id, queue) {
-		if (queue->state != AMDGPU_USERQ_STATE_MAPPED)
-			continue;
-
-		userq_funcs = adev->userq_funcs[queue->queue_type];
-		userq_funcs->unmap(queue);
-		/* just mark all queues as hung at this point.
-		 * if unmap succeeds, we could map again
-		 * in amdgpu_userq_post_reset() if vram is not lost
+		if (queue->state == AMDGPU_USERQ_STATE_MAPPED) {
+			userq_funcs = adev->userq_funcs[queue->queue_type];
+			userq_funcs->unmap(queue);
+			/* just mark all queues as hung at this point.
+			 * if unmap succeeds, we could map again
+			 * in amdgpu_userq_post_reset() if vram is not lost
+			 */
+			queue->state = AMDGPU_USERQ_STATE_HUNG;
+		}
+		/* Force-complete any pending fence regardless of queue state so
+		 * that eviction/suspend and queue teardown waiters don't block
+		 * forever on a fence that will never signal after the reset.
 		 */
-		queue->state = AMDGPU_USERQ_STATE_HUNG;
 		amdgpu_userq_fence_driver_force_completion(queue);
 	}
 }