Skip to contentSkip to conversation

drm/amdgpu/user: add reset helpers for error interrupts

PATCH In review Jesse Zhang 2 participants 10 messages Jun 5 – Jun 11

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

PATCH 1/6 drm/amdgpu/user: add reset helpers for error interrupts

From: Alex Deucher <[email protected]>

If we get an interrupt for a bad user queue (bad opcode, etc.), add a helper to handle the reset for user queues.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 13 +++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h |  1 +
 2 files changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +13 -0
index de6848b4fd67..99c5adf3cb24 100644
@@ -1111,6 +1111,19 @@ static void amdgpu_userq_restore_worker(struct work_struct *work)
 	dma_fence_put(ev_fence);
 }
 
+void amdgpu_userq_process_reset_irq(struct amdgpu_device *adev, u32 doorbell)
+{
+	struct xarray *xa = &adev->userq_doorbell_xa;
+	struct amdgpu_usermode_queue *queue;
+	unsigned long flags;
+
+	xa_lock_irqsave(xa, flags);
+	queue = xa_load(xa, doorbell);
+	if (queue)
+		amdgpu_userq_start_hang_detect_work(queue);
+	xa_unlock_irqrestore(xa, flags);
+}
+
 static int
 amdgpu_userq_evict_all(struct amdgpu_userq_mgr *uq_mgr)
 {
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +1 -0
index 9df1b78407f5..5a2ae33135da 100644
@@ -175,6 +175,7 @@ void amdgpu_userq_pre_reset(struct amdgpu_device *adev);
 int amdgpu_userq_post_reset(struct amdgpu_device *adev, bool vram_lost);
 void amdgpu_userq_start_hang_detect_work(struct amdgpu_usermode_queue *queue);
 void amdgpu_userq_process_fence_irq(struct amdgpu_device *adev, u32 doorbell);
+void amdgpu_userq_process_reset_irq(struct amdgpu_device *adev, u32 doorbell);
 
 int amdgpu_userq_input_va_validate(struct amdgpu_device *adev,
 				   struct amdgpu_usermode_queue *queue,
Signature · 1 line
2.49.0
#1 lore raw

PATCH 2/6 drm/amdgpu/gfx11: handle error interrupts for userqs

From: Alex Deucher <[email protected]>

Call the new userq reset helper.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +9 -7
index 0bd9d8a21f5e..ea323d241324 100644
@@ -6681,15 +6681,17 @@ static int gfx_v11_0_set_priv_inst_fault_state(struct amdgpu_device *adev,
 static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,
 					struct amdgpu_iv_entry *entry)
 {
-	u8 me_id, pipe_id, queue_id;
-	struct amdgpu_ring *ring;
-	int i;
+	u32 doorbell_offset = entry->src_data[0];
 
-	me_id = (entry->ring_id & 0x0c) >> 2;
-	pipe_id = (entry->ring_id & 0x03) >> 0;
-	queue_id = (entry->ring_id & 0x70) >> 4;
+	if (adev->enable_mes && doorbell_offset) {
+		amdgpu_userq_process_reset_irq(adev, doorbell_offset);
+	} else if (!adev->gfx.disable_kq) {
+		u8 me_id = (entry->ring_id & 0x0c) >> 2;
+		u8 pipe_id = (entry->ring_id & 0x03) >> 0;
+		u8 queue_id = (entry->ring_id & 0x70) >> 4;
+		struct amdgpu_ring *ring;
+		int i;
 
-	if (!adev->gfx.disable_kq) {
 		switch (me_id) {
 		case 0:
 			for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
Signature · 1 line
2.49.0
#2 lore raw

PATCH 3/6 drm/amdgpu/gfx12: handle error interrupts for userqs

In reply to Jesse Zhang

From: Alex Deucher <[email protected]>

Call the new userq reset helper.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +11 -7
index 380ba062134e..b3f1bbf3fc13 100644
@@ -5009,15 +5009,19 @@ static int gfx_v12_0_set_priv_inst_fault_state(struct amdgpu_device *adev,
 static void gfx_v12_0_handle_priv_fault(struct amdgpu_device *adev,
 					struct amdgpu_iv_entry *entry)
 {
-	u8 me_id, pipe_id, queue_id;
-	struct amdgpu_ring *ring;
-	int i;
+	u32 doorbell_offset = entry->src_data[0];
 
-	me_id = (entry->ring_id & 0x0c) >> 2;
-	pipe_id = (entry->ring_id & 0x03) >> 0;
-	queue_id = (entry->ring_id & 0x70) >> 4;
+	if (adev->enable_mes && doorbell_offset) {
+		amdgpu_userq_process_reset_irq(adev, doorbell_offset);
+	} else if (!adev->gfx.disable_kq) {
+		u8 me_id, pipe_id, queue_id;
+		struct amdgpu_ring *ring;
+		int i;
+
+		me_id = (entry->ring_id & 0x0c) >> 2;
+		pipe_id = (entry->ring_id & 0x03) >> 0;
+		queue_id = (entry->ring_id & 0x70) >> 4;
 
-	if (!adev->gfx.disable_kq) {
 		switch (me_id) {
 		case 0:
 			for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
Signature · 1 line
2.49.0
#3 lore raw

PATCH 4/6 drm/amdgpu/userq: identify guilty user queue from priv-fault IRQ

In reply to Jesse Zhang

CP priv-fault IRQ carries the offending queue's per-process doorbell_id in src_data[0][9:0] (same encoding KFD extracts via KFD_CTXID0_DOORBELL_ID_MASK), with pasid in entry->pasid. The existing lookup against BAR-absolute doorbell_index never matches this payload, so the targeted-reset path is never taken.

Cache args->in.doorbell_offset on the queue and look it up by the (vm->pasid, doorbell_offset) pair. Add a queue->guilty flag set by the IRQ and consumed via xchg in hang_detect_work; on a hit, route compute reset through amdgpu_gfx_reset_mes_compute(..., queue, ...) and fire hang_detect immediately via mod_delayed_work(..., 0) (queue_delayed_work() is a no-op when the work is already armed at submit time).

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 37 ++++++++++++++++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h |  5 ++-
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c    | 10 ++++--
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c    | 10 ++++--
 4 files changed, 49 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +29 -8
index 99c5adf3cb24..231ffb29fe5e 100644
@@ -140,9 +140,14 @@ static void amdgpu_userq_hang_detect_work(struct work_struct *work)
 						 AMDGPU_RESET_TYPE_PER_QUEUE)) {
 		int r;
 
-		if (queue->queue_type == AMDGPU_HW_IP_COMPUTE)
-			r = amdgpu_gfx_reset_mes_compute(adev, NULL, NULL, NULL, NULL, NULL);
-		else
+		if (queue->queue_type == AMDGPU_HW_IP_COMPUTE) {
+			struct amdgpu_usermode_queue *guilty_uq;
+
+			/* IRQ-side WRITE_ONCE(guilty,true) hand-off via xchg */
+			guilty_uq = xchg(&queue->guilty, false) ? queue : NULL;
+			r = amdgpu_gfx_reset_mes_compute(adev, NULL, NULL,
+							 guilty_uq, NULL, NULL);
+		} else
 			r = userq_funcs->reset(queue);
 		if (r)
 			gpu_reset = true;
@@ -671,6 +676,7 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	}
 
 	queue->doorbell_index = index;
+	queue->doorbell_offset = (u32)args->in.doorbell_offset;
 	r = uq_funcs->mqd_create(queue, &args->in);
 	if (r) {
 		drm_file_err(uq_mgr->file, "Failed to create Queue\n");
@@ -1111,16 +1117,31 @@ static void amdgpu_userq_restore_worker(struct work_struct *work)
 	dma_fence_put(ev_fence);
 }
 
-void amdgpu_userq_process_reset_irq(struct amdgpu_device *adev, u32 doorbell)
+void amdgpu_userq_process_reset_irq(struct amdgpu_device *adev,
+				    u32 pasid, u32 doorbell_offset)
 {
 	struct xarray *xa = &adev->userq_doorbell_xa;
 	struct amdgpu_usermode_queue *queue;
-	unsigned long flags;
+	unsigned long flags, idx;
 
+	/*
+	 * CP priv-fault payload is (pasid, src_data[0] & 0x3ff) — the same
+	 * per-process doorbell encoding KFD extracts via
+	 * KFD_CTXID0_DOORBELL_ID_MASK. Find the offending queue by the
+	 * (vm->pasid, doorbell_offset) pair, mark it guilty and fire
+	 * hang_detect immediately (queue_delayed_work() would no-op if the
+	 * work is already armed at submit time).
+	 */
 	xa_lock_irqsave(xa, flags);
-	queue = xa_load(xa, doorbell);
-	if (queue)
-		amdgpu_userq_start_hang_detect_work(queue);
+	xa_for_each(xa, idx, queue) {
+		if (queue->vm && queue->vm->pasid == pasid &&
+		    queue->doorbell_offset == doorbell_offset) {
+			WRITE_ONCE(queue->guilty, true);
+			mod_delayed_work(adev->reset_domain->wq,
+					 &queue->hang_detect_work, 0);
+			break;
+		}
+	}
 	xa_unlock_irqrestore(xa, flags);
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +4 -1
index 5a2ae33135da..1e765cd765ab 100644
@@ -53,6 +53,7 @@ struct amdgpu_usermode_queue {
 	enum amdgpu_userq_state state;
 	uint64_t		doorbell_handle;
 	uint64_t		doorbell_index;
+	u32			doorbell_offset;
 	uint64_t		flags;
 	struct amdgpu_mqd_prop	*userq_prop;
 	struct amdgpu_userq_mgr *userq_mgr;
@@ -86,6 +87,7 @@ struct amdgpu_usermode_queue {
 	 * Delayed work which runs when userq_fences time out.
 	 */
 	struct delayed_work	hang_detect_work;
+	bool			guilty;
 	struct kref		refcount;
 
 	union {
@@ -175,7 +177,8 @@ void amdgpu_userq_pre_reset(struct amdgpu_device *adev);
 int amdgpu_userq_post_reset(struct amdgpu_device *adev, bool vram_lost);
 void amdgpu_userq_start_hang_detect_work(struct amdgpu_usermode_queue *queue);
 void amdgpu_userq_process_fence_irq(struct amdgpu_device *adev, u32 doorbell);
-void amdgpu_userq_process_reset_irq(struct amdgpu_device *adev, u32 doorbell);
+void amdgpu_userq_process_reset_irq(struct amdgpu_device *adev,
+				    u32 pasid, u32 doorbell_offset);
 
 int amdgpu_userq_input_va_validate(struct amdgpu_device *adev,
 				   struct amdgpu_usermode_queue *queue,
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +8 -2
index ea323d241324..27d0a3dbfce8 100644
@@ -6681,10 +6681,16 @@ static int gfx_v11_0_set_priv_inst_fault_state(struct amdgpu_device *adev,
 static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,
 					struct amdgpu_iv_entry *entry)
 {
-	u32 doorbell_offset = entry->src_data[0];
+	/*
+	 * CP packs the per-process doorbell_id in src_data[0][9:0]; upper
+	 * bits hold other CTXID0 fields. Same mask KFD uses
+	 * (KFD_CTXID0_DOORBELL_ID_MASK).
+	 */
+	u32 doorbell_offset = entry->src_data[0] & 0x3ff;
 
 	if (adev->enable_mes && doorbell_offset) {
-		amdgpu_userq_process_reset_irq(adev, doorbell_offset);
+		amdgpu_userq_process_reset_irq(adev, entry->pasid,
+					       doorbell_offset);
 	} else if (!adev->gfx.disable_kq) {
 		u8 me_id = (entry->ring_id & 0x0c) >> 2;
 		u8 pipe_id = (entry->ring_id & 0x03) >> 0;
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +8 -2
index b3f1bbf3fc13..7c269cb75e07 100644
@@ -5009,10 +5009,16 @@ static int gfx_v12_0_set_priv_inst_fault_state(struct amdgpu_device *adev,
 static void gfx_v12_0_handle_priv_fault(struct amdgpu_device *adev,
 					struct amdgpu_iv_entry *entry)
 {
-	u32 doorbell_offset = entry->src_data[0];
+	/*
+	 * CP packs the per-process doorbell_id in src_data[0][9:0]; upper
+	 * bits hold other CTXID0 fields. Same mask KFD uses
+	 * (KFD_CTXID0_DOORBELL_ID_MASK).
+	 */
+	u32 doorbell_offset = entry->src_data[0] & 0x3ff;
 
 	if (adev->enable_mes && doorbell_offset) {
-		amdgpu_userq_process_reset_irq(adev, doorbell_offset);
+		amdgpu_userq_process_reset_irq(adev, entry->pasid,
+					       doorbell_offset);
 	} else if (!adev->gfx.disable_kq) {
 		u8 me_id, pipe_id, queue_id;
 		struct amdgpu_ring *ring;
Signature · 1 line
2.49.0
#4 lore raw

Re: [PATCH 4/6] drm/amdgpu/userq: identify guilty user queue from priv-fault IRQ

Quoted 7 lines · Jesse Zhang

CP priv-fault IRQ carries the offending queue's per-process doorbell_id in src_data[0][9:0] (same encoding KFD extracts via KFD_CTXID0_DOORBELL_ID_MASK), with pasid in entry->pasid. The existing lookup against BAR-absolute doorbell_index never matches this payload, so the targeted-reset path is never taken.

Quoted 7 lines

Cache args->in.doorbell_offset on the queue and look it up by the (vm->pasid, doorbell_offset) pair. Add a queue->guilty flag set by the IRQ and consumed via xchg in hang_detect_work; on a hit, route compute reset through amdgpu_gfx_reset_mes_compute(..., queue, ...) and fire hang_detect immediately via mod_delayed_work(..., 0) (queue_delayed_work() is a no-op when the work is already armed at submit time).

I would reorder/squash these patches to add support for handling the IH token format for this interrupt and then implement the interrupt handling for the user queues.

Alex

Quoted 155 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 37 ++++++++++++++++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h |  5 ++-
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c    | 10 ++++--
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c    | 10 ++++--
 4 files changed, 49 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +29 -8
index 99c5adf3cb24..231ffb29fe5e 100644
@@ -140,9 +140,14 @@ static void amdgpu_userq_hang_detect_work(struct work_struct *work)
                                                 AMDGPU_RESET_TYPE_PER_QUEUE)) {
                int r;
 
-               if (queue->queue_type == AMDGPU_HW_IP_COMPUTE)
-                       r = amdgpu_gfx_reset_mes_compute(adev, NULL, NULL, NULL, NULL, NULL);
-               else
+               if (queue->queue_type == AMDGPU_HW_IP_COMPUTE) {
+                       struct amdgpu_usermode_queue *guilty_uq;
+
+                       /* IRQ-side WRITE_ONCE(guilty,true) hand-off via xchg */
+                       guilty_uq = xchg(&queue->guilty, false) ? queue : NULL;
+                       r = amdgpu_gfx_reset_mes_compute(adev, NULL, NULL,
+                                                        guilty_uq, NULL, NULL);
+               } else
                        r = userq_funcs->reset(queue);
                if (r)
                        gpu_reset = true;
@@ -671,6 +676,7 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
        }
 
        queue->doorbell_index = index;
+       queue->doorbell_offset = (u32)args->in.doorbell_offset;
        r = uq_funcs->mqd_create(queue, &args->in);
        if (r) {
                drm_file_err(uq_mgr->file, "Failed to create Queue\n");
@@ -1111,16 +1117,31 @@ static void amdgpu_userq_restore_worker(struct work_struct *work)
        dma_fence_put(ev_fence);
 }
 
-void amdgpu_userq_process_reset_irq(struct amdgpu_device *adev, u32 doorbell)
+void amdgpu_userq_process_reset_irq(struct amdgpu_device *adev,
+                                   u32 pasid, u32 doorbell_offset)
 {
        struct xarray *xa = &adev->userq_doorbell_xa;
        struct amdgpu_usermode_queue *queue;
-       unsigned long flags;
+       unsigned long flags, idx;
 
+       /*
+        * CP priv-fault payload is (pasid, src_data[0] & 0x3ff) — the same
+        * per-process doorbell encoding KFD extracts via
+        * KFD_CTXID0_DOORBELL_ID_MASK. Find the offending queue by the
+        * (vm->pasid, doorbell_offset) pair, mark it guilty and fire
+        * hang_detect immediately (queue_delayed_work() would no-op if the
+        * work is already armed at submit time).
+        */
        xa_lock_irqsave(xa, flags);
-       queue = xa_load(xa, doorbell);
-       if (queue)
-               amdgpu_userq_start_hang_detect_work(queue);
+       xa_for_each(xa, idx, queue) {
+               if (queue->vm && queue->vm->pasid == pasid &&
+                   queue->doorbell_offset == doorbell_offset) {
+                       WRITE_ONCE(queue->guilty, true);
+                       mod_delayed_work(adev->reset_domain->wq,
+                                        &queue->hang_detect_work, 0);
+                       break;
+               }
+       }
        xa_unlock_irqrestore(xa, flags);
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +4 -1
index 5a2ae33135da..1e765cd765ab 100644
@@ -53,6 +53,7 @@ struct amdgpu_usermode_queue {
        enum amdgpu_userq_state state;
        uint64_t                doorbell_handle;
        uint64_t                doorbell_index;
+       u32                     doorbell_offset;
        uint64_t                flags;
        struct amdgpu_mqd_prop  *userq_prop;
        struct amdgpu_userq_mgr *userq_mgr;
@@ -86,6 +87,7 @@ struct amdgpu_usermode_queue {
         * Delayed work which runs when userq_fences time out.
         */
        struct delayed_work     hang_detect_work;
+       bool                    guilty;
        struct kref             refcount;
 
        union {
@@ -175,7 +177,8 @@ void amdgpu_userq_pre_reset(struct amdgpu_device *adev);
 int amdgpu_userq_post_reset(struct amdgpu_device *adev, bool vram_lost);
 void amdgpu_userq_start_hang_detect_work(struct amdgpu_usermode_queue *queue);
 void amdgpu_userq_process_fence_irq(struct amdgpu_device *adev, u32 doorbell);
-void amdgpu_userq_process_reset_irq(struct amdgpu_device *adev, u32 doorbell);
+void amdgpu_userq_process_reset_irq(struct amdgpu_device *adev,
+                                   u32 pasid, u32 doorbell_offset);
 
 int amdgpu_userq_input_va_validate(struct amdgpu_device *adev,
                                   struct amdgpu_usermode_queue *queue,
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +8 -2
index ea323d241324..27d0a3dbfce8 100644
@@ -6681,10 +6681,16 @@ static int gfx_v11_0_set_priv_inst_fault_state(struct amdgpu_device *adev,
 static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,
                                        struct amdgpu_iv_entry *entry)
 {
-       u32 doorbell_offset = entry->src_data[0];
+       /*
+        * CP packs the per-process doorbell_id in src_data[0][9:0]; upper
+        * bits hold other CTXID0 fields. Same mask KFD uses
+        * (KFD_CTXID0_DOORBELL_ID_MASK).
+        */
+       u32 doorbell_offset = entry->src_data[0] & 0x3ff;
 
        if (adev->enable_mes && doorbell_offset) {
-               amdgpu_userq_process_reset_irq(adev, doorbell_offset);
+               amdgpu_userq_process_reset_irq(adev, entry->pasid,
+                                              doorbell_offset);
        } else if (!adev->gfx.disable_kq) {
                u8 me_id = (entry->ring_id & 0x0c) >> 2;
                u8 pipe_id = (entry->ring_id & 0x03) >> 0;
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +8 -3
index b3f1bbf3fc13..7c269cb75e07 100644
@@ -5009,10 +5009,16 @@ static int gfx_v12_0_set_priv_inst_fault_state(struct amdgpu_device *adev,
 static void gfx_v12_0_handle_priv_fault(struct amdgpu_device *adev,
                                        struct amdgpu_iv_entry *entry)
 {
-       u32 doorbell_offset = entry->src_data[0];
+       /*
+        * CP packs the per-process doorbell_id in src_data[0][9:0]; upper
+        * bits hold other CTXID0 fields. Same mask KFD uses
+        * (KFD_CTXID0_DOORBELL_ID_MASK).
+        */
+       u32 doorbell_offset = entry->src_data[0] & 0x3ff;
 
        if (adev->enable_mes && doorbell_offset) {
-               amdgpu_userq_process_reset_irq(adev, doorbell_offset);
+               amdgpu_userq_process_reset_irq(adev, entry->pasid,
+                                              doorbell_offset);
        } else if (!adev->gfx.disable_kq) {
                u8 me_id, pipe_id, queue_id;
                struct amdgpu_ring *ring;
--

2.49.0

#5 lore raw

RE: [PATCH 4/6] drm/amdgpu/userq: identify guilty user queue from priv-fault IRQ

AMD General

Quoted 25 lines

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Saturday, June 6, 2026 4:14 AM
To: Zhang, Jesse(Jie) <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 4/6] drm/amdgpu/userq: identify guilty user queue from priv- fault IRQ

Quoted 7 lines · Jesse Zhang

CP priv-fault IRQ carries the offending queue's per-process doorbell_id in src_data[0][9:0] (same encoding KFD extracts via KFD_CTXID0_DOORBELL_ID_MASK), with pasid in entry->pasid. The existing lookup against BAR-absolute doorbell_index never matches this payload, so the targeted-reset path is never taken.

Quoted 7 lines

Cache args->in.doorbell_offset on the queue and look it up by the (vm->pasid, doorbell_offset) pair. Add a queue->guilty flag set by the IRQ and consumed via xchg in hang_detect_work; on a hit, route compute reset through amdgpu_gfx_reset_mes_compute(..., queue, ...) and fire hang_detect immediately via mod_delayed_work(..., 0) (queue_delayed_work() is a no-op when the work is already armed at submit time).

Quoted 3 lines

I would reorder/squash these patches to add support for handling the IH token format for this interrupt and then implement the interrupt handling for the user queues.

I will do that at V2 .

Thanks
Jesse

Quoted 170 lines

Alex

Quoted 5 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 37

++++++++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 5

++-

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static void amdgpu_userq_hang_detect_work(struct

Quoted 10 lines
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c    | 10 ++++--
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c    | 10 ++++--
 4 files changed, 49 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0 -0
index 99c5adf3cb24..231ffb29fe5e 100644
@@ -140,9 +140,14 @@ static void amdgpu_userq_hang_detect_work(struct

work_struct *work)

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static void amdgpu_userq_hang_detect_work(struct work_struct *work)

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0 -2
                                                 AMDGPU_RESET_TYPE_PER_QUEUE)) {
                int r;
 
-               if (queue->queue_type == AMDGPU_HW_IP_COMPUTE)
-                       r = amdgpu_gfx_reset_mes_compute(adev, NULL, NULL, NULL,

NULL, NULL);

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +8 -1
-               else
+               if (queue->queue_type == AMDGPU_HW_IP_COMPUTE) {
+                       struct amdgpu_usermode_queue *guilty_uq;
+
+                       /* IRQ-side WRITE_ONCE(guilty,true) hand-off via xchg */
+                       guilty_uq = xchg(&queue->guilty, false) ? queue : NULL;
+                       r = amdgpu_gfx_reset_mes_compute(adev, NULL, NULL,
+                                                        guilty_uq, NULL, NULL);
+               } else
                        r = userq_funcs->reset(queue);
                if (r)
                        gpu_reset = true; @@ -671,6 +676,7 @@

amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)

Quoted 8 lines
        }

        queue->doorbell_index = index;
+       queue->doorbell_offset = (u32)args->in.doorbell_offset;
        r = uq_funcs->mqd_create(queue, &args->in);
        if (r) {
                drm_file_err(uq_mgr->file, "Failed to create

Queue\n"); @@ -1111,16 +1117,31 @@ static void

amdgpu_userq_restore_worker(struct work_struct *work)

Quoted 75 lines
        dma_fence_put(ev_fence);

}

-void amdgpu_userq_process_reset_irq(struct amdgpu_device *adev, u32 doorbell)

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +20 -4
+void amdgpu_userq_process_reset_irq(struct amdgpu_device *adev,
+                                   u32 pasid, u32 doorbell_offset)
 {
        struct xarray *xa = &adev->userq_doorbell_xa;
        struct amdgpu_usermode_queue *queue;
-       unsigned long flags;
+       unsigned long flags, idx;
 
+       /*
+        * CP priv-fault payload is (pasid, src_data[0] & 0x3ff) — the same
+        * per-process doorbell encoding KFD extracts via
+        * KFD_CTXID0_DOORBELL_ID_MASK. Find the offending queue by the
+        * (vm->pasid, doorbell_offset) pair, mark it guilty and fire
+        * hang_detect immediately (queue_delayed_work() would no-op if the
+        * work is already armed at submit time).
+        */
        xa_lock_irqsave(xa, flags);
-       queue = xa_load(xa, doorbell);
-       if (queue)
-               amdgpu_userq_start_hang_detect_work(queue);
+       xa_for_each(xa, idx, queue) {
+               if (queue->vm && queue->vm->pasid == pasid &&
+                   queue->doorbell_offset == doorbell_offset) {
+                       WRITE_ONCE(queue->guilty, true);
+                       mod_delayed_work(adev->reset_domain->wq,
+                                        &queue->hang_detect_work, 0);
+                       break;
+               }
+       }
        xa_unlock_irqrestore(xa, flags);  }
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +1 -0
index 5a2ae33135da..1e765cd765ab 100644
@@ -53,6 +53,7 @@ struct amdgpu_usermode_queue {
        enum amdgpu_userq_state state;
        uint64_t                doorbell_handle;
        uint64_t                doorbell_index;
+       u32                     doorbell_offset;
        uint64_t                flags;
        struct amdgpu_mqd_prop  *userq_prop;
        struct amdgpu_userq_mgr *userq_mgr; @@ -86,6 +87,7 @@ struct
amdgpu_usermode_queue {
         * Delayed work which runs when userq_fences time out.
         */
        struct delayed_work     hang_detect_work;
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +1 -0
+       bool                    guilty;
        struct kref             refcount;
 
        union {
@@ -175,7 +177,8 @@ void amdgpu_userq_pre_reset(struct amdgpu_device
 *adev);  int amdgpu_userq_post_reset(struct amdgpu_device *adev, bool

vram_lost); void amdgpu_userq_start_hang_detect_work(struct amdgpu_usermode_queue *queue); void amdgpu_userq_process_fence_irq(struct amdgpu_device *adev, u32 doorbell); -void amdgpu_userq_process_reset_irq(struct amdgpu_device *adev, u32 doorbell);

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +2 -0
+void amdgpu_userq_process_reset_irq(struct amdgpu_device *adev,
+                                   u32 pasid, u32 doorbell_offset);
 
 int amdgpu_userq_input_va_validate(struct amdgpu_device *adev,
                                   struct amdgpu_usermode_queue

*queue, diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
index ea323d241324..27d0a3dbfce8 100644

drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0 -0
@@ -6681,10 +6681,16 @@ static int
Quoted 1 line

gfx_v11_0_set_priv_inst_fault_state(struct amdgpu_device *adev, static void

gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,

Quoted 23 lines

struct amdgpu_iv_entry *entry)
{

drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +8 -2
-       u32 doorbell_offset = entry->src_data[0];
+       /*
+        * CP packs the per-process doorbell_id in src_data[0][9:0]; upper
+        * bits hold other CTXID0 fields. Same mask KFD uses
+        * (KFD_CTXID0_DOORBELL_ID_MASK).
+        */
+       u32 doorbell_offset = entry->src_data[0] & 0x3ff;
 
        if (adev->enable_mes && doorbell_offset) {
-               amdgpu_userq_process_reset_irq(adev, doorbell_offset);
+               amdgpu_userq_process_reset_irq(adev, entry->pasid,
+                                              doorbell_offset);
        } else if (!adev->gfx.disable_kq) {
                u8 me_id = (entry->ring_id & 0x0c) >> 2;
                u8 pipe_id = (entry->ring_id & 0x03) >> 0; diff --git

a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
index b3f1bbf3fc13..7c269cb75e07 100644

drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +0 -0
@@ -5009,10 +5009,16 @@ static int
Quoted 1 line

gfx_v12_0_set_priv_inst_fault_state(struct amdgpu_device *adev, static void

gfx_v12_0_handle_priv_fault(struct amdgpu_device *adev,

Quoted 20 lines

struct amdgpu_iv_entry *entry)
{

drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +8 -3
-       u32 doorbell_offset = entry->src_data[0];
+       /*
+        * CP packs the per-process doorbell_id in src_data[0][9:0]; upper
+        * bits hold other CTXID0 fields. Same mask KFD uses
+        * (KFD_CTXID0_DOORBELL_ID_MASK).
+        */
+       u32 doorbell_offset = entry->src_data[0] & 0x3ff;
 
        if (adev->enable_mes && doorbell_offset) {
-               amdgpu_userq_process_reset_irq(adev, doorbell_offset);
+               amdgpu_userq_process_reset_irq(adev, entry->pasid,
+                                              doorbell_offset);
        } else if (!adev->gfx.disable_kq) {
                u8 me_id, pipe_id, queue_id;
                struct amdgpu_ring *ring;
--

2.49.0

#6 lore raw

PATCH 5/6 drm/amdgpu/gfx11: try KQ ring_id match before user-queue lookup

In reply to Jesse Zhang

KCQ and user queues never share a HW slot, so a KQ ring_id hit is authoritative. Match KQ first; only call into the userq path when no KQ owns the faulting slot.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +17 -6
index 27d0a3dbfce8..1f159c9333a5 100644
@@ -6688,10 +6688,12 @@ static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,
 	 */
 	u32 doorbell_offset = entry->src_data[0] & 0x3ff;
 
-	if (adev->enable_mes && doorbell_offset) {
-		amdgpu_userq_process_reset_irq(adev, entry->pasid,
-					       doorbell_offset);
-	} else if (!adev->gfx.disable_kq) {
+	/*
+	 * Try KQ first by ring_id (HW slot is authoritative). The MES <->
+	 * KMD compute_hqd_mask contract guarantees KCQ and user queues
+	 * never share a HW slot.
+	 */
+	if (!adev->gfx.disable_kq) {
 		u8 me_id = (entry->ring_id & 0x0c) >> 2;
 		u8 pipe_id = (entry->ring_id & 0x03) >> 0;
 		u8 queue_id = (entry->ring_id & 0x70) >> 4;
@@ -6703,8 +6705,10 @@ static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,
 			for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
 				ring = &adev->gfx.gfx_ring[i];
 				if (ring->me == me_id && ring->pipe == pipe_id &&
-				    ring->queue == queue_id)
+				    ring->queue == queue_id) {
 					drm_sched_fault(&ring->sched);
+					return;
+				}
 			}
 			break;
 		case 1:
@@ -6712,8 +6716,10 @@ static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,
 			for (i = 0; i < adev->gfx.num_compute_rings; i++) {
 				ring = &adev->gfx.compute_ring[i];
 				if (ring->me == me_id && ring->pipe == pipe_id &&
-				    ring->queue == queue_id)
+				    ring->queue == queue_id) {
 					drm_sched_fault(&ring->sched);
+					return;
+				}
 			}
 			break;
 		default:
@@ -6721,6 +6727,11 @@ static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,
 			break;
 		}
 	}
+
+	/* No KQ matched: HW slot is a MES-scheduled user queue. */
+	if (adev->enable_mes && doorbell_offset)
+		amdgpu_userq_process_reset_irq(adev, entry->pasid,
+					       doorbell_offset);
 }
 
 static int gfx_v11_0_priv_reg_irq(struct amdgpu_device *adev,
Signature · 1 line
2.49.0
#7 lore raw

Re: [PATCH 5/6] drm/amdgpu/gfx11: try KQ ring_id match before user-queue lookup

Quoted 56 lines · Jesse Zhang

KCQ and user queues never share a HW slot, so a KQ ring_id hit is authoritative. Match KQ first; only call into the userq path when no KQ owns the faulting slot.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +12 -6
index 27d0a3dbfce8..1f159c9333a5 100644
@@ -6688,10 +6688,12 @@ static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,
         */
        u32 doorbell_offset = entry->src_data[0] & 0x3ff;
 
-       if (adev->enable_mes && doorbell_offset) {
-               amdgpu_userq_process_reset_irq(adev, entry->pasid,
-                                              doorbell_offset);
-       } else if (!adev->gfx.disable_kq) {
+       /*
+        * Try KQ first by ring_id (HW slot is authoritative). The MES <->
+        * KMD compute_hqd_mask contract guarantees KCQ and user queues
+        * never share a HW slot.
+        */
+       if (!adev->gfx.disable_kq) {
                u8 me_id = (entry->ring_id & 0x0c) >> 2;
                u8 pipe_id = (entry->ring_id & 0x03) >> 0;
                u8 queue_id = (entry->ring_id & 0x70) >> 4;
@@ -6703,8 +6705,10 @@ static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,
                        for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
                                ring = &adev->gfx.gfx_ring[i];
                                if (ring->me == me_id && ring->pipe == pipe_id &&
-                                   ring->queue == queue_id)
+                                   ring->queue == queue_id) {
                                        drm_sched_fault(&ring->sched);
+                                       return;
+                               }
                        }
                        break;
                case 1:
@@ -6712,8 +6716,10 @@ static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,
                        for (i = 0; i < adev->gfx.num_compute_rings; i++) {
                                ring = &adev->gfx.compute_ring[i];
                                if (ring->me == me_id && ring->pipe == pipe_id &&
-                                   ring->queue == queue_id)
+                                   ring->queue == queue_id) {
                                        drm_sched_fault(&ring->sched);
+                                       return;
+                               }
                        }
                        break;
                default:

drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev, · line 6734

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5 -0
@@ -6721,6 +6727,11 @@ static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,
                        break;
                }
        }
+
+       /* No KQ matched: HW slot is a MES-scheduled user queue. */
+       if (adev->enable_mes && doorbell_offset)
+               amdgpu_userq_process_reset_irq(adev, entry->pasid,
+                                              doorbell_offset);

While you are at it, can you check if gfx_v11_0_eop_irq() and gfx_v12_0_eop_irq() have similar issues? Maybe those should be reworked similarly.

Alex

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0 -1
 }
 
 static int gfx_v11_0_priv_reg_irq(struct amdgpu_device *adev,
--

2.49.0

#8 lore raw

RE: [PATCH 5/6] drm/amdgpu/gfx11: try KQ ring_id match before user-queue lookup

AMD General

Quoted 80 lines

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Saturday, June 6, 2026 4:11 AM
To: Zhang, Jesse(Jie) <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 5/6] drm/amdgpu/gfx11: try KQ ring_id match before user- queue lookup

drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static void gfx_v11_0_handle_priv_fault(struct

Quoted 16 lines · Jesse Zhang

KCQ and user queues never share a HW slot, so a KQ ring_id hit is authoritative. Match KQ first; only call into the userq path when no KQ owns the faulting slot.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0 -0
index 27d0a3dbfce8..1f159c9333a5 100644
@@ -6688,10 +6688,12 @@ static void gfx_v11_0_handle_priv_fault(struct

amdgpu_device *adev,

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0 -4
         */
        u32 doorbell_offset = entry->src_data[0] & 0x3ff;
 
-       if (adev->enable_mes && doorbell_offset) {
-               amdgpu_userq_process_reset_irq(adev, entry->pasid,
-                                              doorbell_offset);
-       } else if (!adev->gfx.disable_kq) {

drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +7 -0
+       /*
+        * Try KQ first by ring_id (HW slot is authoritative). The MES <->
+        * KMD compute_hqd_mask contract guarantees KCQ and user queues
+        * never share a HW slot.
+        */
+       if (!adev->gfx.disable_kq) {
                u8 me_id = (entry->ring_id & 0x0c) >> 2;
                u8 pipe_id = (entry->ring_id & 0x03) >> 0;
                u8 queue_id = (entry->ring_id & 0x70) >> 4; @@ -6703,8
+6705,10 @@ static void gfx_v11_0_handle_priv_fault(struct amdgpu_device

*adev,

drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static void gfx_v11_0_handle_priv_fault(struct

Quoted 12 lines
                        for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
                                ring = &adev->gfx.gfx_ring[i];
                                if (ring->me == me_id && ring->pipe == pipe_id &&
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3 -1
-                                   ring->queue == queue_id)
+                                   ring->queue == queue_id) {
                                        drm_sched_fault(&ring->sched);
+                                       return;
+                               }
                        }
                        break;
                case 1:
@@ -6712,8 +6716,10 @@ static void gfx_v11_0_handle_priv_fault(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static void gfx_v11_0_handle_priv_fault(struct

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3 -1
                        for (i = 0; i < adev->gfx.num_compute_rings; i++) {
                                ring = &adev->gfx.compute_ring[i];
                                if (ring->me == me_id && ring->pipe == pipe_id &&
-                                   ring->queue == queue_id)
+                                   ring->queue == queue_id) {
                                        drm_sched_fault(&ring->sched);
+                                       return;
+                               }
                        }
                        break;
                default:
@@ -6721,6 +6727,11 @@ static void gfx_v11_0_handle_priv_fault(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev, · line 6734

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5 -0
                        break;
                }
        }
+
+       /* No KQ matched: HW slot is a MES-scheduled user queue. */
+       if (adev->enable_mes && doorbell_offset)
+               amdgpu_userq_process_reset_irq(adev, entry->pasid,
+                                              doorbell_offset);
Quoted 4 lines

While you are at it, can you check if gfx_v11_0_eop_irq() and gfx_v12_0_eop_irq() have similar issues? Maybe those should be reworked similarly.

Thanks Alex, I will try that and update.
Jesse

Quoted 8 lines

Alex

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0 -1
 }
 
 static int gfx_v11_0_priv_reg_irq(struct amdgpu_device *adev,
--

2.49.0

#9 lore raw

PATCH 6/6 drm/amdgpu/gfx12: try KQ ring_id match before user-queue lookup

In reply to Jesse Zhang

KCQ and user queues never share a HW slot, so a KQ ring_id hit is authoritative. Match KQ first; only call into the userq path when no KQ owns the faulting slot.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +16 -6
index 7c269cb75e07..e32dfc654ee7 100644
@@ -5016,10 +5016,11 @@ static void gfx_v12_0_handle_priv_fault(struct amdgpu_device *adev,
 	 */
 	u32 doorbell_offset = entry->src_data[0] & 0x3ff;
 
-	if (adev->enable_mes && doorbell_offset) {
-		amdgpu_userq_process_reset_irq(adev, entry->pasid,
-					       doorbell_offset);
-	} else if (!adev->gfx.disable_kq) {
+	/*
+	 * Try KQ first by ring_id; UQ as fallback. KCQ and UQ never share
+	 * a HW slot (compute_hqd_mask contract).
+	 */
+	if (!adev->gfx.disable_kq) {
 		u8 me_id, pipe_id, queue_id;
 		struct amdgpu_ring *ring;
 		int i;
@@ -5033,8 +5034,10 @@ static void gfx_v12_0_handle_priv_fault(struct amdgpu_device *adev,
 			for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
 				ring = &adev->gfx.gfx_ring[i];
 				if (ring->me == me_id && ring->pipe == pipe_id &&
-				    ring->queue == queue_id)
+				    ring->queue == queue_id) {
 					drm_sched_fault(&ring->sched);
+					return;
+				}
 			}
 			break;
 		case 1:
@@ -5042,8 +5045,10 @@ static void gfx_v12_0_handle_priv_fault(struct amdgpu_device *adev,
 			for (i = 0; i < adev->gfx.num_compute_rings; i++) {
 				ring = &adev->gfx.compute_ring[i];
 				if (ring->me == me_id && ring->pipe == pipe_id &&
-				    ring->queue == queue_id)
+				    ring->queue == queue_id) {
 					drm_sched_fault(&ring->sched);
+					return;
+				}
 			}
 			break;
 		default:
@@ -5051,6 +5056,11 @@ static void gfx_v12_0_handle_priv_fault(struct amdgpu_device *adev,
 			break;
 		}
 	}
+
+	/* No KQ matched: HW slot is a MES-scheduled user queue. */
+	if (adev->enable_mes && doorbell_offset)
+		amdgpu_userq_process_reset_irq(adev, entry->pasid,
+					       doorbell_offset);
 }
 
 static int gfx_v12_0_priv_reg_irq(struct amdgpu_device *adev,
Signature · 1 line
2.49.0