Skip to contentSkip to conversation

drm/amdgpu: add user queue reset source

PATCH Superseded Jesse.Zhang 3 participants 16 messages May 30, 2025

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/14 drm/amdgpu: add user queue reset source

From: Alex Deucher <[email protected]>

Track resets from user queues.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h | 1 +
 2 files changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c +3 -0
index dabfbdf6f1ce..28c4ad62f50e 100644
@@ -340,6 +340,9 @@ void amdgpu_reset_get_desc(struct amdgpu_reset_context *rst_ctxt, char *buf,
 	case AMDGPU_RESET_SRC_USER:
 		strscpy(buf, "user trigger", len);
 		break;
+	case AMDGPU_RESET_SRC_USERQ:
+		strscpy(buf, "user queue trigger", len);
+		break;
 	default:
 		strscpy(buf, "unknown", len);
 	}
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +1 -0
index 4d9b9701139b..ebcea44dd743 100644
@@ -43,6 +43,7 @@ enum AMDGPU_RESET_SRCS {
 	AMDGPU_RESET_SRC_MES,
 	AMDGPU_RESET_SRC_HWS,
 	AMDGPU_RESET_SRC_USER,
+	AMDGPU_RESET_SRC_USERQ,
 };
 
 struct amdgpu_reset_context {
Signature · 1 line
2.49.0
#1 lore raw

PATCH 2/14 drm/amdgpu/userq: add callback for reset

From: Alex Deucher <[email protected]>

This is used to reset a queue.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +2 -0
index ec040c2fd6c9..3cc0ad8919f4 100644
@@ -77,6 +77,8 @@ struct amdgpu_userq_funcs {
 		     struct amdgpu_usermode_queue *queue);
 	int (*map)(struct amdgpu_userq_mgr *uq_mgr,
 		   struct amdgpu_usermode_queue *queue);
+	int (*reset)(struct amdgpu_userq_mgr *uq_mgr,
+		     struct amdgpu_usermode_queue *queue);
 };
 
 /* Usermode queues for gfx */
Signature · 1 line
2.49.0
#2 lore raw

PATCH 3/14 drm/amdgpu: add mes userq reset callback

In reply to Jesse.Zhang

From: Alex Deucher <[email protected]>

Used to reset a hung queue.

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +21 -0
index d6f50b13e2ba..650fdb68db12 100644
@@ -347,9 +347,30 @@ mes_userq_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr,
 	amdgpu_userq_destroy_object(uq_mgr, &queue->mqd);
 }
 
+static int mes_userq_reset(struct amdgpu_userq_mgr *uq_mgr,
+			   struct amdgpu_usermode_queue *queue)
+{
+	struct amdgpu_device *adev = uq_mgr->adev;
+	struct mes_reset_queue_input queue_input;
+	int r;
+
+	memset(&queue_input, 0x0, sizeof(struct mes_reset_queue_input));
+
+	queue_input.doorbell_offset = queue->doorbell_index;
+	queue_input.queue_type = queue->queue_type;
+
+	amdgpu_mes_lock(&adev->mes);
+	r = adev->mes.funcs->reset_hw_queue(&adev->mes, &queue_input);
+	amdgpu_mes_unlock(&adev->mes);
+	if (r)
+		dev_err(adev->dev, "Failed to reset queue, err (%d)\n", r);
+	return r;
+}
+
 const struct amdgpu_userq_funcs userq_mes_funcs = {
 	.mqd_create = mes_userq_mqd_create,
 	.mqd_destroy = mes_userq_mqd_destroy,
 	.unmap = mes_userq_unmap,
 	.map = mes_userq_map,
+	.reset = mes_userq_reset,
 };
Signature · 1 line
2.49.0
#3 lore raw

PATCH 4/14 drm/amdgpu/userq: add force completion helpers

In reply to Jesse.Zhang

From: Alex Deucher <[email protected]>

Add support for forcing completion of userq fences.
This is needed for userq resets and asic resets so that we can set the error on the fence and force completion.

v2: drop rcu_dereference_protected (Christian)

---
 .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c   | 40 +++++++++++++++++++
 .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.h   |  1 +
 2 files changed, 41 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +40 -0
index fc4d0d42e223..e21a82a3b0a8 100644
@@ -67,6 +67,14 @@ static u64 amdgpu_userq_fence_read(struct amdgpu_userq_fence_driver *fence_drv)
 	return le64_to_cpu(*fence_drv->cpu_addr);
 }
 
+static void
+amdgpu_userq_fence_write(struct amdgpu_userq_fence_driver *fence_drv,
+			 u64 seq)
+{
+	if (fence_drv->cpu_addr)
+		*fence_drv->cpu_addr = cpu_to_le64(seq);
+}
+
 int amdgpu_userq_fence_driver_alloc(struct amdgpu_device *adev,
 				    struct amdgpu_usermode_queue *userq)
 {
@@ -409,6 +417,38 @@ static void amdgpu_userq_fence_cleanup(struct dma_fence *fence)
 	dma_fence_put(fence);
 }
 
+static void
+amdgpu_userq_fence_driver_set_error(struct amdgpu_userq_fence *fence,
+				    int error)
+{
+	struct amdgpu_userq_fence_driver *fence_drv = fence->fence_drv;
+	unsigned long flags;
+	struct dma_fence *f;
+
+	spin_lock_irqsave(&fence_drv->fence_list_lock, flags);
+	f = &fence->base;
+	if (f && !dma_fence_is_signaled_locked(f))
+		dma_fence_set_error(f, error);
+	spin_unlock_irqrestore(&fence_drv->fence_list_lock, flags);
+}
+
+void
+amdgpu_userq_fence_driver_force_completion(struct amdgpu_usermode_queue *userq)
+{
+	struct dma_fence *f = userq->last_fence;
+
+	if (f) {
+		struct amdgpu_userq_fence *fence = to_amdgpu_userq_fence(f);
+		struct amdgpu_userq_fence_driver *fence_drv = fence->fence_drv;
+		u64 wptr = fence->base.seqno;
+
+		amdgpu_userq_fence_driver_set_error(fence, -ECANCELED);
+		amdgpu_userq_fence_write(fence_drv, wptr);
+		amdgpu_userq_fence_driver_process(fence_drv);
+
+	}
+}
+
 int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
 			      struct drm_file *filp)
 {
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.h +1 -0
index 97a125ab8a78..d76add2afc77 100644
@@ -67,6 +67,7 @@ int amdgpu_userq_fence_driver_alloc(struct amdgpu_device *adev,
 				    struct amdgpu_usermode_queue *userq);
 void amdgpu_userq_fence_driver_free(struct amdgpu_usermode_queue *userq);
 void amdgpu_userq_fence_driver_process(struct amdgpu_userq_fence_driver *fence_drv);
+void amdgpu_userq_fence_driver_force_completion(struct amdgpu_usermode_queue *userq);
 void amdgpu_userq_fence_driver_destroy(struct kref *ref);
 int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
 			      struct drm_file *filp);
Signature · 1 line
2.49.0
#4 lore raw

PATCH 5/14 drm/amdgpu/userq: implement resets

In reply to Jesse.Zhang

From: Alex Deucher <[email protected]>

If map or unmap fails, or a user fence times out, attempt to reset the queue. If that fails, schedule a GPU reset.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |   8 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c  | 123 +++++++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h  |   5 +
 4 files changed, 128 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index a5ccd0ada16a..7365558f47a1 100644
@@ -1303,6 +1303,7 @@ struct amdgpu_device {
 	struct list_head		userq_mgr_list;
 	struct mutex                    userq_mutex;
 	bool                            userq_halt_for_enforce_isolation;
+	struct work_struct		userq_reset_work;
 };
 
 static inline uint32_t amdgpu_ip_version(const struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8 -0
index 72e41781afb0..2c90a7d256e2 100644
@@ -4426,6 +4426,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 	}
 
 	INIT_WORK(&adev->xgmi_reset_work, amdgpu_device_xgmi_reset_func);
+	INIT_WORK(&adev->userq_reset_work, amdgpu_userq_reset_work);
 
 	adev->gfx.gfx_off_req_count = 1;
 	adev->gfx.gfx_off_residency = 0;
@@ -5768,6 +5769,10 @@ 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), false);
 
 				/*
@@ -5990,6 +5995,7 @@ static inline void amdgpu_device_stop_pending_resets(struct amdgpu_device *adev)
 	if (!amdgpu_sriov_vf(adev))
 		cancel_work(&adev->reset_work);
 #endif
+	cancel_work(&adev->userq_reset_work);
 
 	if (adev->kfd.dev)
 		cancel_work(&adev->kfd.reset_work);
@@ -6100,6 +6106,8 @@ static int amdgpu_device_halt_activities(struct amdgpu_device *adev,
 		      amdgpu_device_ip_need_full_reset(tmp_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_userq.c +114 -9

189 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +5 -0
index 3cc0ad8919f4..9d62befcdb24 100644
@@ -134,4 +134,9 @@ int amdgpu_userq_stop_sched_for_enforce_isolation(struct amdgpu_device *adev,
 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);
+
 #endif
Signature · 1 line
2.49.0
#5 lore raw

Re: [PATCH 05/14] drm/amdgpu/userq: implement resets

Quoted 113 lines · Jesse.Zhang

From: Alex Deucher <[email protected]>

If map or unmap fails, or a user fence times out, attempt to reset the queue. If that fails, schedule a GPU reset.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |   8 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c  | 123 +++++++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h  |   5 +
 4 files changed, 128 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index a5ccd0ada16a..7365558f47a1 100644
@@ -1303,6 +1303,7 @@ struct amdgpu_device {
        struct list_head                userq_mgr_list;
        struct mutex                    userq_mutex;
        bool                            userq_halt_for_enforce_isolation;
+       struct work_struct              userq_reset_work;
 };
 
 static inline uint32_t amdgpu_ip_version(const struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8 -0
index 72e41781afb0..2c90a7d256e2 100644
@@ -4426,6 +4426,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
        }
 
        INIT_WORK(&adev->xgmi_reset_work, amdgpu_device_xgmi_reset_func);
+       INIT_WORK(&adev->userq_reset_work, amdgpu_userq_reset_work);
 
        adev->gfx.gfx_off_req_count = 1;
        adev->gfx.gfx_off_residency = 0;
@@ -5768,6 +5769,10 @@ 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), false);
 
                                /*
@@ -5990,6 +5995,7 @@ static inline void amdgpu_device_stop_pending_resets(struct amdgpu_device *adev)
        if (!amdgpu_sriov_vf(adev))
                cancel_work(&adev->reset_work);
 #endif
+       cancel_work(&adev->userq_reset_work);
 
        if (adev->kfd.dev)
                cancel_work(&adev->kfd.reset_work);
@@ -6100,6 +6106,8 @@ static int amdgpu_device_halt_activities(struct amdgpu_device *adev,
                      amdgpu_device_ip_need_full_reset(tmp_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_userq.c +30 -0
index 295e7186e156..d4f807256383 100644
@@ -26,7 +26,10 @@
 #include <drm/drm_exec.h>
 #include <linux/pm_runtime.h>
 
+#include <drm/drm_drv.h>
+
 #include "amdgpu.h"
+#include "amdgpu_reset.h"
 #include "amdgpu_vm.h"
 #include "amdgpu_userq.h"
 #include "amdgpu_userq_fence.h"
@@ -44,6 +47,44 @@ u32 amdgpu_userq_get_supported_ip_mask(struct amdgpu_device *adev)
        return userq_ip_mask;
 }
 
+static void amdgpu_userq_gpu_reset(struct amdgpu_device *adev)
+{
+
+       if (amdgpu_device_should_recover_gpu(adev))
+               amdgpu_reset_domain_schedule(adev->reset_domain,
+                                            &adev->userq_reset_work);
+}
+
+static bool
+amdgpu_userq_queue_reset_helper(struct amdgpu_userq_mgr *uq_mgr,
+                               struct amdgpu_usermode_queue *queue)
+{
+       struct amdgpu_device *adev = uq_mgr->adev;
+       const struct amdgpu_userq_funcs *userq_funcs =
+               adev->userq_funcs[queue->queue_type];
+       bool gpu_reset = false;
+       int r;
+
+       if (unlikely(adev->debug_disable_gpu_ring_reset)) {
+               dev_err(adev->dev, "userq reset disabled by debug mask\n");
+       } else if (amdgpu_gpu_recovery && userq_funcs->reset) {
+               r = userq_funcs->reset(uq_mgr, queue);
+               if (r) {
+                       dev_err(adev->dev, "userq reset failed\n");
+                       gpu_reset = true;
+               } else {
+                       dev_err(adev->dev, "userq reset succeeded\n");

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c u32 amdgpu_userq_get_supported_ip_mask(struct amdgpu_device *adev) · line 86

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +10 -0
+                       atomic_inc(&adev->gpu_reset_counter);
+                       amdgpu_userq_fence_driver_force_completion(queue);
+                       drm_dev_wedged_event(adev_to_drm(adev), DRM_WEDGE_RECOVERY_NONE);
+               }
+       } else if (amdgpu_gpu_recovery && !userq_funcs->reset) {
+               gpu_reset = true;
+       }
+
+       return gpu_reset;
+}

After our discussions with the MES team, I think we should approach this slightly differently. I see two options:

1. Use the existing userq reset callback but rather than trying to use the reset single queue API, use the detect and reset API instead.
2. Add a new higher level callback (e.g., mes vs. umsch, etc.) for detect and reset and update the queue status for all hung queues. Then call that new callback in all the places amdgpu_userq.c where we call amdgpu_userq_unmap_helper(). E.g.,

    /* detect all the queues that are hung, reset, and update their
status to hung */
    amdgpu_userq_detect_and_reset_queues()
    idr_for_each_entry(&uq_mgr->userq_idr, queue, queue_id) {
                /* only unmap the queues that are not already marked as hung */
                r = amdgpu_userq_unmap_helper(uq_mgr, queue);
               ...
    }

The second option has the advantage of only needing to call the MES API once rather than per queue.

Alex

Quoted 161 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +74 -9
+
 static int
 amdgpu_userq_unmap_helper(struct amdgpu_userq_mgr *uq_mgr,
                          struct amdgpu_usermode_queue *queue)
@@ -51,15 +92,22 @@ amdgpu_userq_unmap_helper(struct amdgpu_userq_mgr *uq_mgr,
        struct amdgpu_device *adev = uq_mgr->adev;
        const struct amdgpu_userq_funcs *userq_funcs =
                adev->userq_funcs[queue->queue_type];
+       bool gpu_reset = false;
        int r = 0;
 
        if (queue->state == AMDGPU_USERQ_STATE_MAPPED) {
                r = userq_funcs->unmap(uq_mgr, queue);
-               if (r)
+               if (r) {
                        queue->state = AMDGPU_USERQ_STATE_HUNG;
-               else
+                       gpu_reset = amdgpu_userq_queue_reset_helper(uq_mgr, queue);
+               } else {
                        queue->state = AMDGPU_USERQ_STATE_UNMAPPED;
+               }
        }
+
+       if (gpu_reset)
+               amdgpu_userq_gpu_reset(adev);
+
        return r;
 }
 
@@ -70,16 +118,22 @@ amdgpu_userq_map_helper(struct amdgpu_userq_mgr *uq_mgr,
        struct amdgpu_device *adev = uq_mgr->adev;
        const struct amdgpu_userq_funcs *userq_funcs =
                adev->userq_funcs[queue->queue_type];
+       bool gpu_reset = false;
        int r = 0;
 
        if (queue->state == AMDGPU_USERQ_STATE_UNMAPPED) {
                r = userq_funcs->map(uq_mgr, queue);
                if (r) {
                        queue->state = AMDGPU_USERQ_STATE_HUNG;
+                       gpu_reset = amdgpu_userq_queue_reset_helper(uq_mgr, queue);
                } else {
                        queue->state = AMDGPU_USERQ_STATE_MAPPED;
                }
        }
+
+       if (gpu_reset)
+               amdgpu_userq_gpu_reset(adev);
+
        return r;
 }
 
@@ -703,6 +757,23 @@ amdgpu_userq_evict_all(struct amdgpu_userq_mgr *uq_mgr)
        return ret;
 }
 
+void amdgpu_userq_reset_work(struct work_struct *work)
+{
+       struct amdgpu_device *adev = container_of(work, struct amdgpu_device,
+                                                 userq_reset_work);
+       struct amdgpu_reset_context reset_context;
+
+       memset(&reset_context, 0, sizeof(reset_context));
+
+       reset_context.method = AMD_RESET_METHOD_NONE;
+       reset_context.reset_req_dev = adev;
+       reset_context.src = AMDGPU_RESET_SRC_USERQ;
+       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);
+}
+
 static int
 amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr)
 {
@@ -729,22 +800,18 @@ void
 amdgpu_userq_evict(struct amdgpu_userq_mgr *uq_mgr,
                   struct amdgpu_eviction_fence *ev_fence)
 {
-       int ret;
        struct amdgpu_fpriv *fpriv = uq_mgr_to_fpriv(uq_mgr);
        struct amdgpu_eviction_fence_mgr *evf_mgr = &fpriv->evf_mgr;
+       int ret;
 
        /* Wait for any pending userqueue fence work to finish */
        ret = amdgpu_userq_wait_for_signal(uq_mgr);
-       if (ret) {
+       if (ret)
                drm_file_err(uq_mgr->file, "Not evicting userqueue, timeout waiting for work\n");
-               return;
-       }
 
        ret = amdgpu_userq_evict_all(uq_mgr);
-       if (ret) {
+       if (ret)
                drm_file_err(uq_mgr->file, "Failed to evict userqueue\n");
-               return;
-       }
 
        /* Signal current eviction fence */
        amdgpu_eviction_fence_signal(evf_mgr, ev_fence);
@@ -922,3 +989,41 @@ int amdgpu_userq_start_sched_for_enforce_isolation(struct amdgpu_device *adev,
        mutex_unlock(&adev->userq_mutex);
        return ret;
 }
+
+void amdgpu_userq_pre_reset(struct amdgpu_device *adev)
+{
+       const struct amdgpu_userq_funcs *userq_funcs;
+       struct amdgpu_usermode_queue *queue;
+       struct amdgpu_userq_mgr *uqm, *tmp;
+       int queue_id;
+
+       mutex_lock(&adev->userq_mutex);
+       list_for_each_entry_safe(uqm, tmp, &adev->userq_mgr_list, list) {
+               cancel_delayed_work_sync(&uqm->resume_work);
+               mutex_lock(&uqm->userq_mutex);
+               idr_for_each_entry(&uqm->userq_idr, queue, queue_id) {
+                       if (queue->state == AMDGPU_USERQ_STATE_MAPPED) {
+                               amdgpu_userq_wait_for_last_fence(uqm, queue);
+                               userq_funcs = adev->userq_funcs[queue->queue_type];
+                               userq_funcs->unmap(uqm, 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;
+                               amdgpu_userq_fence_driver_force_completion(queue);
+                       }
+               }
+               mutex_unlock(&uqm->userq_mutex);
+       }
+       mutex_unlock(&adev->userq_mutex);
+}
+
+int amdgpu_userq_post_reset(struct amdgpu_device *adev, bool vram_lost)
+{
+       /* if any queue state is AMDGPU_USERQ_STATE_UNMAPPED
+        * at this point, we should be able to map it again
+        * and continue if vram is not lost.
+        */
+       return 0;
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +5 -1
index 3cc0ad8919f4..9d62befcdb24 100644
@@ -134,4 +134,9 @@ int amdgpu_userq_stop_sched_for_enforce_isolation(struct amdgpu_device *adev,
 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);
+
 #endif
--

2.49.0

#6 lore raw

PATCH 6/14 drm/amdgpu: add UAPI for user queue query status

In reply to Jesse.Zhang

From: Alex Deucher <[email protected]>

Add an API to query queue status such as whether the queue is hung or whether vram is lost.

---
 include/uapi/drm/amdgpu_drm.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
include/uapi/drm/amdgpu_drm.h +14 -0
index 45c4fa13499c..62e3152bfdc7 100644
@@ -328,6 +328,7 @@ union drm_amdgpu_ctx {
 /* user queue IOCTL operations */
 #define AMDGPU_USERQ_OP_CREATE	1
 #define AMDGPU_USERQ_OP_FREE	2
+#define AMDGPU_USERQ_OP_QUERY_STATUS	3
 
 /* queue priority levels */
 /* low < normal low < normal high < high */
@@ -340,6 +341,12 @@ union drm_amdgpu_ctx {
 /* for queues that need access to protected content */
 #define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE  (1 << 2)
 
+
+/* the queue is hung */
+#define AMDGPU_USERQ_QUERY_STATUS_FLAGS_HUNG    (1 << 0)
+/* indicate vram lost since queue was created */
+#define AMDGPU_USERQ_QUERY_STATUS_FLAGS_VRAMLOST (1 << 1)
+
 /*
  * This structure is a container to pass input configuration
  * info for all supported userqueue related operations.
@@ -421,9 +428,16 @@ struct drm_amdgpu_userq_out {
 	__u32 _pad;
 };
 
+/* The structure to carry output of userqueue ops */
+struct drm_amdgpu_userq_out_query_state {
+	__u32 flags;
+	__u32 _pad;
+};
+
 union drm_amdgpu_userq {
 	struct drm_amdgpu_userq_in in;
 	struct drm_amdgpu_userq_out out;
+	struct drm_amdgpu_userq_out_query_state out_qs;
 };
 
 /* GFX V11 IP specific MQD parameters */
Signature · 1 line
2.49.0
#7 lore raw

PATCH 7/14 drm/amdgpu/userq: implement support for query status

In reply to Jesse.Zhang

From: Alex Deucher <[email protected]>

Query the status of the user queue, currently whether the queue is hung and whether or not VRAM is lost.

v2: Misc cleanups

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 35 ++++++++++++++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h |  1 +
 2 files changed, 35 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +34 -1
index d4f807256383..b7b1c26067f5 100644
@@ -469,6 +469,7 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	queue->queue_type = args->in.ip_type;
 	queue->vm = &fpriv->vm;
 	queue->priority = priority;
+	queue->generation = amdgpu_vm_generation(adev, &fpriv->vm);
 
 	db_info.queue_type = queue->queue_type;
 	db_info.doorbell_handle = queue->doorbell_handle;
@@ -539,6 +540,34 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	return r;
 }
 
+static int
+amdgpu_userq_query_status(struct drm_file *filp, union drm_amdgpu_userq *args)
+{
+	struct amdgpu_fpriv *fpriv = filp->driver_priv;
+	struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
+	struct amdgpu_device *adev = uq_mgr->adev;
+	struct amdgpu_usermode_queue *queue;
+	int queue_id = args->in.queue_id;
+
+	mutex_lock(&uq_mgr->userq_mutex);
+
+	queue = amdgpu_userq_find(uq_mgr, queue_id);
+	if (!queue) {
+		dev_dbg(adev->dev, "Invalid queue id to query\n");
+		mutex_unlock(&uq_mgr->userq_mutex);
+		return -EINVAL;
+	}
+	args->out_qs.flags = 0;
+	if (queue->state == AMDGPU_USERQ_STATE_HUNG)
+		args->out_qs.flags |= AMDGPU_USERQ_QUERY_STATUS_FLAGS_HUNG;
+	if (queue->generation != amdgpu_vm_generation(adev, &fpriv->vm))
+		args->out_qs.flags |= AMDGPU_USERQ_QUERY_STATUS_FLAGS_VRAMLOST;
+
+	mutex_unlock(&uq_mgr->userq_mutex);
+
+	return 0;
+}
+
 int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
 		       struct drm_file *filp)
 {
@@ -572,7 +601,11 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
 		if (r)
 			drm_file_err(filp, "Failed to destroy usermode queue\n");
 		break;
-
+	case AMDGPU_USERQ_OP_QUERY_STATUS:
+		r = amdgpu_userq_query_status(filp, args);
+		if (r)
+			drm_file_err(filp, "Failed to query usermode queue status\n");
+		break;
 	default:
 		drm_dbg_driver(dev, "Invalid user queue op specified: %d\n", args->in.op);
 		return -EINVAL;
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +1 -0
index 9d62befcdb24..cdc3dcc62dce 100644
@@ -65,6 +65,7 @@ struct amdgpu_usermode_queue {
 	struct dma_fence	*last_fence;
 	u32			xcp_id;
 	int			priority;
+	uint64_t		generation;
 };
 
 struct amdgpu_userq_funcs {
Signature · 1 line
2.49.0
#8 lore raw

PATCH 8/14 drm/amd/amdgpu: Add hang detection before GFX queue reset in MES

In reply to Jesse.Zhang

This change introduces a new parameter hang_detect_then_reset in the MES reset queue input structure to handle GFX queue resets more robustly.

The change includes:
1. Adding the hang_detect_then_reset flag to mes_reset_queue_input
2. Setting this flag when resetting GFX queues in mes_userq_reset
3. Implementing the hang detection path in mes_v11_0_reset_hw_queue

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h    | 1 +
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c     | 3 +++
 3 files changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +1 -0
index c0d2c195fe2e..31826a20c56b 100644
@@ -277,6 +277,7 @@ struct mes_reset_queue_input {
 	uint64_t                           wptr_addr;
 	uint32_t                           vmid;
 	bool                               legacy_gfx;
+	bool				   hang_detect_then_reset;
 	bool                               is_kq;
 };
 
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2 -0
index 650fdb68db12..2b5bd3691766 100644
@@ -358,6 +358,8 @@ static int mes_userq_reset(struct amdgpu_userq_mgr *uq_mgr,
 
 	queue_input.doorbell_offset = queue->doorbell_index;
 	queue_input.queue_type = queue->queue_type;
+	if (queue->queue_type == AMDGPU_RING_TYPE_GFX)
+		queue_input.hang_detect_then_reset = true;
 
 	amdgpu_mes_lock(&adev->mes);
 	r = adev->mes.funcs->reset_hw_queue(&adev->mes, &queue_input);
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +3 -0
index c9eba537de09..25ea06b507c0 100644
@@ -773,6 +773,9 @@ static int mes_v11_0_reset_hw_queue(struct amdgpu_mes *mes,
 		mes_reset_queue_pkt.doorbell_offset_lp = input->doorbell_offset;
 		mes_reset_queue_pkt.wptr_addr_lp = input->wptr_addr;
 		mes_reset_queue_pkt.vmid_id_lp = input->vmid;
+	} else if (input->hang_detect_then_reset) {
+		mes_reset_queue_pkt.hang_detect_then_reset = 1;
+		mes_reset_queue_pkt.doorbell_offset = input->doorbell_offset;
 	} else {
 		mes_reset_queue_pkt.reset_queue_only = 1;
 		mes_reset_queue_pkt.doorbell_offset = input->doorbell_offset;
Signature · 1 line
2.49.0
#9 lore raw

PATCH 9/14 drm/amd/amdgpu: Add hang detect support for MES v12.0

In reply to Jesse.Zhang

Adds the hang detection path for GFX queue resets in MES v12.0,

The change implements:
- Handling of the hang_detect_then_reset flag in mes_v12_0_reset_hw_queue

---
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +3 -0
index b4f17332d466..f763f91ff9d7 100644
@@ -864,6 +864,9 @@ static int mes_v12_0_reset_hw_queue(struct amdgpu_mes *mes,
 		mes_reset_queue_pkt.doorbell_offset_lp = input->doorbell_offset;
 		mes_reset_queue_pkt.wptr_addr_lp = input->wptr_addr;
 		mes_reset_queue_pkt.vmid_id_lp = input->vmid;
+	} else if (input->hang_detect_then_reset) {
+		mes_reset_queue_pkt.hang_detect_then_reset = 1;
+		mes_reset_queue_pkt.doorbell_offset = input->doorbell_offset;
 	} else {
 		mes_reset_queue_pkt.reset_queue_only = 1;
 		mes_reset_queue_pkt.doorbell_offset = input->doorbell_offset;
Signature · 1 line
2.49.0
#10 lore raw

PATCH 10/14 drm/amdgpu: Implement active VMID detection in MES queue reset for GFX

In reply to Jesse.Zhang

MES queue reset functionality for GFX queues. The changes include:

1. Added detection of active VMIDs by reading CP_CNTX_STAT and CP_VMID registers to properly identify contexts that need resetting

2. Implemented fallback to HPD status method when no active VMIDs are found, checking both pipe 0 and pipe 1 queues

3. Extended the MES reset packet with:
- active_vmids bitmap
- connected_queue_index for pipe 0
- connected_queue_index_p1 for pipe 1

---
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 52 ++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +52 -0
index f763f91ff9d7..86d51614f207 100644
@@ -840,6 +840,12 @@ static int mes_v12_0_reset_hw_queue(struct amdgpu_mes *mes,
 				    struct mes_reset_queue_input *input)
 {
 	union MESAPI__RESET mes_reset_queue_pkt;
+	struct amdgpu_device *adev = mes->adev;
+	uint32_t active_vmids = 0;
+	uint32_t connected_queue_index = 0;
+	uint32_t queue_status = 0;
+	uint32_t connected_queue_index_p1 = 0;
+	uint32_t queue_status_p1 = 0;
 	int pipe;
 
 	if (input->use_mmio)
@@ -856,6 +862,52 @@ static int mes_v12_0_reset_hw_queue(struct amdgpu_mes *mes,
 	mes_reset_queue_pkt.queue_type =
 		convert_to_mes_queue_type(input->queue_type);
 
+	/* Add VMID detection for GFX queues */
+	if (input->queue_type == AMDGPU_RING_TYPE_GFX &&
+		input->hang_detect_then_reset) {
+		uint32_t cp_cntx_stat = RREG32_SOC15(GC, 0, regCP_CNTX_STAT);
+		uint32_t cp_vmid, grbm_gfx_cntl;
+
+		/* Check active contexts in CP_CNTX_STAT */
+		for (uint32_t i = 0; i < 8; i++) {
+			if ((cp_cntx_stat >> (0x14 + i)) & 0x1) {
+				grbm_gfx_cntl = (i << 11);
+				WREG32_SOC15(GC, 0, regGRBM_GFX_CNTL, grbm_gfx_cntl);
+				cp_vmid = RREG32_SOC15(GC, 0, regCP_CP_VMID);
+				active_vmids |= (1 << cp_vmid);
+			}
+		}
+
+		/* Fallback to HPD status if no active VMIDs found */
+		if (active_vmids == 0) {
+			uint32_t hpd_status;
+
+			/* Pipe 0 */
+			WREG32_SOC15(GC, 0, regGRBM_GFX_CNTL, 0);
+			hpd_status = RREG32_SOC15(GC, 0, regCP_GFX_HPD_STATUS0);
+			queue_status = hpd_status & 0x1F;
+			connected_queue_index = (hpd_status & 0xE0) >> 5;
+
+			/* Pipe 1 */
+			WREG32_SOC15(GC, 0, regGRBM_GFX_CNTL, (1 << 6));
+			hpd_status = RREG32_SOC15(GC, 0, regCP_GFX_HPD_STATUS0);
+			queue_status_p1 = hpd_status & 0x1F;
+			connected_queue_index_p1 = (hpd_status & 0xE0) >> 5;
+		}
+
+		mes_reset_queue_pkt.active_vmids = active_vmids;
+		if (active_vmids == 0) {
+			if (queue_status != 0) {
+				mes_reset_queue_pkt.use_connected_queue_index = 1;
+				mes_reset_queue_pkt.connected_queue_index = connected_queue_index;
+			}
+			if (queue_status_p1 != 0) {
+				mes_reset_queue_pkt.use_connected_queue_index_p1 = 1;
+				mes_reset_queue_pkt.connected_queue_index_p1 = connected_queue_index_p1;
+			}
+		}
+	}
+
 	if (input->legacy_gfx) {
 		mes_reset_queue_pkt.reset_legacy_gfx = 1;
 		mes_reset_queue_pkt.pipe_id_lp = input->pipe_id;
Signature · 1 line
2.49.0
#11 lore raw

PATCH 11/14 drm/amd/amdgpu: Add HQD PQ address retrieval support for GFX11

In reply to Jesse.Zhang

This commit introduces HQD PQ address retrieval functionality for GFX11 hardware by:

1. Adding hqd_get_pq_addr function pointer to amdgpu_mqd structure
2. Implementing gfx_v11_0_hqd_get_pq_addr() for GFX11
3. Registering the function in gfx_v11_0_set_mqd_funcs()

Key features:
- Supports XCC instances for Compute queues
- Checks HQD active status before accessing registers
- Provides accurate queue address calculation combining high/low registers
- Maintains compatibility with existing reset mechanisms

This functionality will be used for hang detection and queue management operations that need to identify specific hardware queues.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h    |  4 +++
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 49 ++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
index 7365558f47a1..927375ebafa1 100644
@@ -892,6 +892,10 @@ struct amdgpu_mqd {
 	unsigned mqd_size;
 	int (*init_mqd)(struct amdgpu_device *adev, void *mqd,
 			struct amdgpu_mqd_prop *p);
+	uint64_t (*hqd_get_pq_addr)(struct amdgpu_device *adev, uint32_t queue_type,
+				    uint32_t me_id, uint32_t pipe_id, uint32_t queue_id,
+				    uint32_t xcc_id, uint32_t *vmid);
+
 };
 
 struct amdgpu_pcie_reset_ctx {
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +49 -0

66 lines not on this page · raw message

Signature · 1 line
2.49.0
#12 lore raw

PATCH 12/14 drm/amd/amdgpu: Implement HQD PQ address retrieval for GFX12

In reply to Jesse.Zhang

This commit adds HQD PQ address lookup functionality for GFX12.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 49 ++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +49 -0
index f09d96bfee16..34a20a67c00b 100644
@@ -3047,6 +3047,51 @@ static int gfx_v12_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,
 	return 0;
 }
 
+static uint64_t gfx_v12_0_hqd_get_pq_addr(struct amdgpu_device *adev, uint32_t queue_type,
+                    uint32_t me_id, uint32_t pipe_id, uint32_t queue_id,
+                    uint32_t xcc_id, uint32_t *vmid)
+{
+	uint32_t low = 0, high = 0, active = 0;
+	uint64_t queue_addr = 0;
+
+	mutex_lock(&adev->srbm_mutex);
+	/* Enter safe mode to safely access HQD registers */
+	amdgpu_gfx_rlc_enter_safe_mode(adev, xcc_id);
+
+
+	/* Select the specific ME/PIPE/QUEUE to access its HQD registers */
+	soc24_grbm_select(adev, me_id, pipe_id, queue_id, 0);
+
+	if (queue_type == AMDGPU_RING_TYPE_GFX) {
+		active = RREG32_SOC15(GC, 0, regCP_GFX_HQD_ACTIVE);
+		if (!(active & 1))
+			goto unlock_out;
+
+		*vmid = RREG32_SOC15(GC, 0, regCP_GFX_HQD_VMID);
+		low = RREG32_SOC15(GC, 0, regCP_GFX_HQD_BASE);
+		high = RREG32_SOC15(GC, 0, regCP_GFX_HQD_BASE_HI);
+
+		queue_addr = (((uint64_t)high << 32) | low) << 8;
+	} else if (queue_type == AMDGPU_RING_TYPE_COMPUTE) {
+		active = RREG32_SOC15(GC, 0, regCP_HQD_ACTIVE);
+		if (!(active & 1))
+			goto unlock_out;
+
+		*vmid = RREG32_SOC15(GC, 0, regCP_HQD_VMID);
+		low = RREG32_SOC15(GC, 0, regCP_HQD_PQ_BASE);
+		high = RREG32_SOC15(GC, 0, regCP_HQD_PQ_BASE_HI);
+
+		queue_addr = (((uint64_t)high << 32) | low) << 8;
+	}
+
+unlock_out:
+	soc24_grbm_select(adev, 0, 0, 0, 0);
+	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
+	mutex_unlock(&adev->srbm_mutex);
+
+	return queue_addr;
+}
+
 static int gfx_v12_0_kgq_init_queue(struct amdgpu_ring *ring, bool reset)
 {
 	struct amdgpu_device *adev = ring->adev;
@@ -5672,11 +5717,15 @@ static void gfx_v12_0_set_mqd_funcs(struct amdgpu_device *adev)
 		sizeof(struct v12_gfx_mqd);
 	adev->mqds[AMDGPU_HW_IP_GFX].init_mqd =
 		gfx_v12_0_gfx_mqd_init;
+	adev->mqds[AMDGPU_HW_IP_GFX].hqd_get_pq_addr =
+		gfx_v12_0_hqd_get_pq_addr;
 	/* set compute eng mqd */
 	adev->mqds[AMDGPU_HW_IP_COMPUTE].mqd_size =
 		sizeof(struct v12_compute_mqd);
 	adev->mqds[AMDGPU_HW_IP_COMPUTE].init_mqd =
 		gfx_v12_0_compute_mqd_init;
+	adev->mqds[AMDGPU_HW_IP_COMPUTE].hqd_get_pq_addr =
+		gfx_v12_0_hqd_get_pq_addr;
 }
 
 static void gfx_v12_0_set_user_wgp_inactive_bitmap_per_sh(struct amdgpu_device *adev,
Signature · 1 line
2.49.0
#13 lore raw

PATCH 13/14 drm/amd/amdgpu: Implement usermode queue hang detection

In reply to Jesse.Zhang

This commit introduces hang detection infrastructure for usermode queues by:

1. Adding userq_hang_info structure to track:
- Queue identification (ME/MEC, pipe, queue)
- VMID and XCC ID
- Queue GPU address

2. Implementing amdgpu_userqueue_detect_hang() which:
- Scans active hardware queues to find matching HQD addresses
- Supports both GFX and Compute queue types
- Properly handles queue identification hierarchy
- Stores found queue information in hang_info structure

3. Integrating hang detection with existing queue structures:
- Added hang_info to amdgpu_usermode_queue
- Maintained compatibility with existing reset mechanisms

The implementation:
- Matches hardware queue organization (ME->pipe->queue)
- Uses existing MQD functions for HQD address lookup
- Provides all necessary information for targeted resets

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 79 +++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 12 ++++
 2 files changed, 91 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +79 -0
index b7b1c26067f5..028989e1538c 100644
@@ -55,6 +55,85 @@ static void amdgpu_userq_gpu_reset(struct amdgpu_device *adev)
 					     &adev->userq_reset_work);
 }
 
+/**
+ * Detect if a given usermode queue is hung by comparing its GPU address
+ * to existing HQD addresses in the hardware.
+ *
+ * @uqm   - User queue manager containing context and tracking structures
+ * @queue - The usermode queue to check for hang
+ *
+ * @return - bool, hang detection info is stored in hang_info if match found.
+ */
+static bool amdgpu_userqueue_detect_hang(struct amdgpu_userq_mgr *uqm, struct amdgpu_usermode_queue *queue)
+{
+	struct amdgpu_device *adev = uqm->adev;
+	struct userq_hang_info *hang_info = &queue->hang_info;
+	struct amdgpu_mqd *mqd_hw_default = &adev->mqds[queue->queue_type];
+
+	int queue_type = queue->queue_type;
+	uint64_t hdq_pq_base = queue->userq_prop->hqd_base_gpu_addr;
+
+	uint64_t hqd_addr = 0;
+	uint32_t mec, me, pipe, q, vmid;
+
+	switch (queue_type) {
+	case AMDGPU_HW_IP_GFX:
+		for (me = 0; me < adev->gfx.me.num_me; me++) {
+			for (q = 0; q < adev->gfx.me.num_queue_per_pipe; q++) {
+				for (pipe = 0; pipe < adev->gfx.me.num_pipe_per_me; pipe++) {
+
+					hqd_addr = mqd_hw_default->hqd_get_pq_addr(adev, queue_type,
+						me, pipe, q, 0, &vmid);
+					if (!hqd_addr)
+						continue;
+					/* Check if this HQD matches the target queue */
+					if (hqd_addr == hdq_pq_base) {
+						hang_info->me = me;
+						hang_info->pipe = pipe;
+						hang_info->queue = q;
+						hang_info->queue_address = hqd_addr;
+						hang_info->vmid = vmid;
+						return true;
+					}
+				}
+			}
+		}
+	break;
+	case AMDGPU_HW_IP_COMPUTE:
+		for (mec = 0; mec < adev->gfx.mec.num_mec; ++mec) {
+			/* mec0 is me1 */
+			mec +=1;
+			for (q = 0; q < adev->gfx.mec.num_queue_per_pipe; q++) {
+				for (pipe = 0; pipe < adev->gfx.mec.num_pipe_per_mec; pipe++) {
+					hqd_addr = mqd_hw_default->hqd_get_pq_addr(adev, queue_type,
+									mec, pipe, q, 0, &vmid);
+					if (!hqd_addr)
+					    continue;
+
+					/* Check for address match to determine hang */
+					if (hqd_addr == hdq_pq_base) {
+						hang_info->mec = mec;
+						hang_info->pipe = pipe;
+						hang_info->queue = q;
+						hang_info->queue_address = hqd_addr;
+						hang_info->vmid = vmid;
+						return true;
+					}
+				}
+			}
+		}
+	break;
+	case AMDGPU_HW_IP_DMA:
+	case AMDGPU_HW_IP_VCN_ENC:
+	case AMDGPU_HW_IP_VPE:
+	default:
+	/* These queue types are not yet supported in hang detection */
+	break;
+	}
+
+	return false;
+}
+
 static bool
 amdgpu_userq_queue_reset_helper(struct amdgpu_userq_mgr *uq_mgr,
 				struct amdgpu_usermode_queue *queue)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +12 -0
index cdc3dcc62dce..0b33df8f0793 100644
@@ -47,6 +47,16 @@ struct amdgpu_userq_obj {
 	struct amdgpu_bo *obj;
 };
 
+struct userq_hang_info {
+	int me;
+	int mec;
+	int pipe;
+	int queue;
+	int xcc_id;
+	int vmid;
+	uint64_t queue_address;
+};
+
 struct amdgpu_usermode_queue {
 	int			queue_type;
 	enum amdgpu_userq_state state;
@@ -66,6 +76,8 @@ struct amdgpu_usermode_queue {
 	u32			xcp_id;
 	int			priority;
 	uint64_t		generation;
+	/* for per-queue reset support */
+	struct userq_hang_info hang_info;
 };
 
 struct amdgpu_userq_funcs {
Signature · 1 line
2.49.0
#14 lore raw

PATCH 14/14 drm/amd/amdgpu: Improve compute queue reset handling

In reply to Jesse.Zhang

This commit enhances compute queue reset reliability by:

1. Adding hang detection verification before compute queue resets
- Checks HQD address match to confirm actual hang
- Returns early if no hang is detected
- Prevents unnecessary resets of healthy queues

2. Implementing MES suspend/resume during compute queue reset
- Suspends MES before resetting compute queues
- Resumes MES after reset completes
- Prevents potential race conditions during reset

3. Enabling MMIO path for compute queue resets
- Sets use_mmio flag for compute queue resets

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c  | 18 ++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c |  3 ++-
 2 files changed, 20 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +18 -0
index 028989e1538c..6d3597244ac4 100644
@@ -142,11 +142,25 @@ amdgpu_userq_queue_reset_helper(struct amdgpu_userq_mgr *uq_mgr,
 	const struct amdgpu_userq_funcs *userq_funcs =
 		adev->userq_funcs[queue->queue_type];
 	bool gpu_reset = false;
+	bool gpu_suspend = false;
 	int r;
 
 	if (unlikely(adev->debug_disable_gpu_ring_reset)) {
 		dev_err(adev->dev, "userq reset disabled by debug mask\n");
 	} else if (amdgpu_gpu_recovery && userq_funcs->reset) {
+		if (queue->queue_type == AMDGPU_RING_TYPE_COMPUTE) {
+			if (!amdgpu_userqueue_detect_hang(uq_mgr, queue)) {
+				dev_err(adev->dev, "userq not detected hang\n");
+				return true;
+			}
+
+			r = amdgpu_mes_suspend(adev);
+			if (!r) {
+				dev_err(adev->dev, "userq suspend gangs from MES succeeded\n");
+				gpu_suspend = true;
+			}
+		}
+
 		r = userq_funcs->reset(uq_mgr, queue);
 		if (r) {
 			dev_err(adev->dev, "userq reset failed\n");
@@ -157,6 +171,10 @@ amdgpu_userq_queue_reset_helper(struct amdgpu_userq_mgr *uq_mgr,
 			amdgpu_userq_fence_driver_force_completion(queue);
 			drm_dev_wedged_event(adev_to_drm(adev), DRM_WEDGE_RECOVERY_NONE);
 		}
+
+		if (gpu_suspend)
+			amdgpu_mes_resume(adev);
+
 	} else if (amdgpu_gpu_recovery && !userq_funcs->reset) {
 		gpu_reset = true;
 	}
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2 -1
index 2b5bd3691766..997b25f9fe45 100644
@@ -360,7 +360,8 @@ static int mes_userq_reset(struct amdgpu_userq_mgr *uq_mgr,
 	queue_input.queue_type = queue->queue_type;
 	if (queue->queue_type == AMDGPU_RING_TYPE_GFX)
 		queue_input.hang_detect_then_reset = true;
-
+	else if (queue->queue_type == AMDGPU_RING_TYPE_COMPUTE)
+		queue_input.use_mmio = true;
 	amdgpu_mes_lock(&adev->mes);
 	r = adev->mes.funcs->reset_hw_queue(&adev->mes, &queue_input);
 	amdgpu_mes_unlock(&adev->mes);
Signature · 1 line
2.49.0
#15 lore raw
In reply to Jesse.Zhang
Quoted 17 lines · Jesse.Zhang

From: Alex Deucher <[email protected]>

Track resets from user queues.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h | 1 +
 2 files changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c +0 -0
index dabfbdf6f1ce..28c4ad62f50e 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c void amdgpu_reset_get_desc(struct amdgpu_reset_context *rst_ctxt, char *buf, · line 345

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c +3 -0
@@ -340,6 +340,9 @@ void amdgpu_reset_get_desc(struct amdgpu_reset_context *rst_ctxt, char *buf,
 	case AMDGPU_RESET_SRC_USER:
 		strscpy(buf, "user trigger", len);
 		break;
+	case AMDGPU_RESET_SRC_USERQ:
+		strscpy(buf, "user queue trigger", len);
+		break;

This in itself is not that helpful. Not sure what data can be inferred out of this.

Thanks,
Lijo

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.c +0 -0
 	default:
 		strscpy(buf, "unknown", len);
 	}
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +1 -0
index 4d9b9701139b..ebcea44dd743 100644
@@ -43,6 +43,7 @@ enum AMDGPU_RESET_SRCS {
 	AMDGPU_RESET_SRC_MES,
 	AMDGPU_RESET_SRC_HWS,
 	AMDGPU_RESET_SRC_USER,
+	AMDGPU_RESET_SRC_USERQ,
 };
 
 struct amdgpu_reset_context {