Skip to contentSkip to conversation

drm/amdgpu: track faulted gfx user-queue slots

PATCH Superseded Jesse Zhang 2 participants 7 messages Jul 22 – Jul 30

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 drm/amdgpu: track faulted gfx user-queue slots

A gfx priv/bad-op fault IV carries only the HW slot (ring_id), not the faulting user queue's doorbell. Add userq_priv_fault_slots (an atomic bitmap of faulted slots, so concurrent faults are not dropped) and userq_priv_fault_work to struct amdgpu_gfx; a worker drains the bitmap and reads the doorbell back from each HQD to locate and reset the queue.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +3 -0
index aefd4f03b443..f83afa7e0aa5 100644
@@ -535,6 +535,9 @@ struct amdgpu_gfx {
 	struct mutex                    userq_sch_mutex;
 	u64				userq_sch_req_count[MAX_XCP];
 	bool				userq_sch_inactive[MAX_XCP];
+	/* atomic bitmap of faulted gfx UQ slots (index = pipe | queue << 2) */
+	unsigned long			userq_priv_fault_slots;
+	struct work_struct		userq_priv_fault_work;
 	unsigned long			enforce_isolation_jiffies[MAX_XCP];
 	unsigned long			enforce_isolation_time[MAX_XCP];
 
Signature · 1 line
2.49.0
#1 lore raw

PATCH v2 2/4 drm/amdgpu/gfx11: recover gfx user queues on priv-fault

If a priv/bad-op fault does not match a kernel queue slot, it belongs to a MES-scheduled user queue. Compute IVs carry the doorbell and use the existing path; gfx IVs do not, so record the faulted slot and let a worker read the doorbell back from the HQD (regCP_RB_DOORBELL_CONTROL), look up the user queue and reset it.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 60 +++++++++++++++++++++++---
 1 file changed, 55 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +55 -5
index 0cbbdc3694f4..a802b0ac1544 100644
@@ -1601,6 +1601,8 @@ static void gfx_v11_0_alloc_ip_dump(struct amdgpu_device *adev)
 	}
 }
 
+static void gfx_v11_0_userq_priv_fault_work(struct work_struct *work);
+
 static int gfx_v11_0_sw_init(struct amdgpu_ip_block *ip_block)
 {
 	int i, j, k, r, ring_id;
@@ -1931,6 +1933,8 @@ static int gfx_v11_0_sw_init(struct amdgpu_ip_block *ip_block)
 
 	mutex_init(&adev->gfx.mec.reset_mutex);
 
+	INIT_WORK(&adev->gfx.userq_priv_fault_work, gfx_v11_0_userq_priv_fault_work);
+
 	return 0;
 }
 
@@ -1968,6 +1972,8 @@ static int gfx_v11_0_sw_fini(struct amdgpu_ip_block *ip_block)
 	int i;
 	struct amdgpu_device *adev = ip_block->adev;
 
+	cancel_work_sync(&adev->gfx.userq_priv_fault_work);
+
 	for (i = 0; i < adev->gfx.num_gfx_rings; i++)
 		amdgpu_ring_fini(&adev->gfx.gfx_ring[i]);
 	for (i = 0; i < adev->gfx.num_compute_rings; i++)
@@ -6707,10 +6713,47 @@ static int gfx_v11_0_set_priv_inst_fault_state(struct amdgpu_device *adev,
 	return 0;
 }
 
+/*
+ * A gfx exception IV carries no doorbell. For each faulted slot, read the
+ * doorbell back from the HQD (left in place by the fatal fault), look up the
+ * user queue and kick its per-queue reset.
+ */
+static void gfx_v11_0_userq_priv_fault_work(struct work_struct *work)
+{
+	struct amdgpu_device *adev =
+		container_of(work, struct amdgpu_device, gfx.userq_priv_fault_work);
+	unsigned long slots = xchg(&adev->gfx.userq_priv_fault_slots, 0);
+	unsigned int id;
+
+	for_each_set_bit(id, &slots, BITS_PER_LONG) {
+		u8 pipe = id & 0x3;
+		u8 queue = (id >> 2) & 0x7;
+		struct amdgpu_usermode_queue *q;
+		u32 db_ctrl, doorbell;
+
+		amdgpu_gfx_off_ctrl(adev, false);
+		mutex_lock(&adev->srbm_mutex);
+		soc21_grbm_select(adev, 0, pipe, queue, 0);
+		db_ctrl = RREG32_SOC15(GC, 0, regCP_RB_DOORBELL_CONTROL);
+		soc21_grbm_select(adev, 0, 0, 0, 0);
+		mutex_unlock(&adev->srbm_mutex);
+		amdgpu_gfx_off_ctrl(adev, true);
+
+		doorbell = (db_ctrl & CP_RB_DOORBELL_CONTROL__DOORBELL_OFFSET_MASK) >>
+			   CP_RB_DOORBELL_CONTROL__DOORBELL_OFFSET__SHIFT;
+		q = xa_load(&adev->userq_doorbell_xa, doorbell);
+		if (q)
+			amdgpu_userq_start_hang_detect_work(q);
+	}
+}
+
 static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,
 					struct amdgpu_iv_entry *entry)
 {
 	u32 doorbell_offset = entry->src_data[0] & AMDGPU_CTXID0_DOORBELL_ID_MASK;
+	u8 me_id = (entry->ring_id & 0x0c) >> 2;
+	u8 pipe_id = (entry->ring_id & 0x03) >> 0;
+	u8 queue_id = (entry->ring_id & 0x70) >> 4;
 
 	/*
 	 * Try KQ first by ring_id (HW slot is authoritative). The
@@ -6718,9 +6761,6 @@ static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,
 	 * 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;
 		struct amdgpu_ring *ring;
 		int i;
 
@@ -6752,10 +6792,20 @@ static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,
 		}
 	}
 
-	/* No KQ matched: HW slot is a MES-scheduled user queue. */
-	if (adev->enable_mes && doorbell_offset)
+	/* No KQ matched: the faulting slot belongs to a user queue. */
+	if (!adev->enable_mes)
+		return;
+
+	if (doorbell_offset) {
 		amdgpu_userq_process_reset_irq(adev, entry->pasid,
 					       doorbell_offset);
+	} else {
+		/* GFX IVs lack the doorbell; record the slot and let the
+		 * worker read it back from the HQD.
+		 */
+		set_bit(pipe_id | (queue_id << 2), &adev->gfx.userq_priv_fault_slots);
+		schedule_work(&adev->gfx.userq_priv_fault_work);
+	}
 }
 
 static int gfx_v11_0_priv_reg_irq(struct amdgpu_device *adev,
Signature · 1 line
2.49.0
#2 lore raw

Re: [PATCH v2 2/4] drm/amdgpu/gfx11: recover gfx user queues on priv-fault

Quoted 103 lines · Jesse Zhang

If a priv/bad-op fault does not match a kernel queue slot, it belongs to a MES-scheduled user queue. Compute IVs carry the doorbell and use the existing path; gfx IVs do not, so record the faulted slot and let a worker read the doorbell back from the HQD (regCP_RB_DOORBELL_CONTROL), look up the user queue and reset it.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 60 +++++++++++++++++++++++---
 1 file changed, 55 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +43 -3
index 0cbbdc3694f4..a802b0ac1544 100644
@@ -1601,6 +1601,8 @@ static void gfx_v11_0_alloc_ip_dump(struct amdgpu_device *adev)
        }
 }
 
+static void gfx_v11_0_userq_priv_fault_work(struct work_struct *work);
+
 static int gfx_v11_0_sw_init(struct amdgpu_ip_block *ip_block)
 {
        int i, j, k, r, ring_id;
@@ -1931,6 +1933,8 @@ static int gfx_v11_0_sw_init(struct amdgpu_ip_block *ip_block)
 
        mutex_init(&adev->gfx.mec.reset_mutex);
 
+       INIT_WORK(&adev->gfx.userq_priv_fault_work, gfx_v11_0_userq_priv_fault_work);
+
        return 0;
 }
 
@@ -1968,6 +1972,8 @@ static int gfx_v11_0_sw_fini(struct amdgpu_ip_block *ip_block)
        int i;
        struct amdgpu_device *adev = ip_block->adev;
 
+       cancel_work_sync(&adev->gfx.userq_priv_fault_work);
+
        for (i = 0; i < adev->gfx.num_gfx_rings; i++)
                amdgpu_ring_fini(&adev->gfx.gfx_ring[i]);
        for (i = 0; i < adev->gfx.num_compute_rings; i++)
@@ -6707,10 +6713,47 @@ static int gfx_v11_0_set_priv_inst_fault_state(struct amdgpu_device *adev,
        return 0;
 }
 
+/*
+ * A gfx exception IV carries no doorbell. For each faulted slot, read the
+ * doorbell back from the HQD (left in place by the fatal fault), look up the
+ * user queue and kick its per-queue reset.
+ */
+static void gfx_v11_0_userq_priv_fault_work(struct work_struct *work)
+{
+       struct amdgpu_device *adev =
+               container_of(work, struct amdgpu_device, gfx.userq_priv_fault_work);
+       unsigned long slots = xchg(&adev->gfx.userq_priv_fault_slots, 0);
+       unsigned int id;
+
+       for_each_set_bit(id, &slots, BITS_PER_LONG) {
+               u8 pipe = id & 0x3;
+               u8 queue = (id >> 2) & 0x7;
+               struct amdgpu_usermode_queue *q;
+               u32 db_ctrl, doorbell;
+
+               amdgpu_gfx_off_ctrl(adev, false);
+               mutex_lock(&adev->srbm_mutex);
+               soc21_grbm_select(adev, 0, pipe, queue, 0);
+               db_ctrl = RREG32_SOC15(GC, 0, regCP_RB_DOORBELL_CONTROL);
+               soc21_grbm_select(adev, 0, 0, 0, 0);
+               mutex_unlock(&adev->srbm_mutex);
+               amdgpu_gfx_off_ctrl(adev, true);
+
+               doorbell = (db_ctrl & CP_RB_DOORBELL_CONTROL__DOORBELL_OFFSET_MASK) >>
+                          CP_RB_DOORBELL_CONTROL__DOORBELL_OFFSET__SHIFT;
+               q = xa_load(&adev->userq_doorbell_xa, doorbell);
+               if (q)
+                       amdgpu_userq_start_hang_detect_work(q);
+       }
+}
+
 static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,
                                        struct amdgpu_iv_entry *entry)
 {
        u32 doorbell_offset = entry->src_data[0] & AMDGPU_CTXID0_DOORBELL_ID_MASK;
+       u8 me_id = (entry->ring_id & 0x0c) >> 2;
+       u8 pipe_id = (entry->ring_id & 0x03) >> 0;
+       u8 queue_id = (entry->ring_id & 0x70) >> 4;
 
        /*
         * Try KQ first by ring_id (HW slot is authoritative). The
@@ -6718,9 +6761,6 @@ static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,
         * 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;
                struct amdgpu_ring *ring;
                int i;
 

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

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2 -2
@@ -6752,10 +6792,20 @@ static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,
                }
        }
 
-       /* No KQ matched: HW slot is a MES-scheduled user queue. */
-       if (adev->enable_mes && doorbell_offset)
+       /* No KQ matched: the faulting slot belongs to a user queue. */
+       if (!adev->enable_mes)

I think this should be:

if (adev->gfx.disable_uq)

    return;

Same comment for patch 3.

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

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3 -0
+               return;
+
+       if (doorbell_offset) {
                amdgpu_userq_process_reset_irq(adev, entry->pasid,
                                               doorbell_offset);

If the doorbell offset is not provided, do we need to keep this code? Same comment for patch 3.

Alex

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +7 -1
+       } else {
+               /* GFX IVs lack the doorbell; record the slot and let the
+                * worker read it back from the HQD.
+                */
+               set_bit(pipe_id | (queue_id << 2), &adev->gfx.userq_priv_fault_slots);
+               schedule_work(&adev->gfx.userq_priv_fault_work);
+       }
 }
 
 static int gfx_v11_0_priv_reg_irq(struct amdgpu_device *adev,
--

2.49.0

#3 lore raw

RE: [PATCH v2 2/4] drm/amdgpu/gfx11: recover gfx user queues on priv-fault

AMD General

Quoted 138 lines

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, July 29, 2026 10:54 PM
To: Zhang, Jesse(Jie) <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Mario Sopena-Novales <[email protected]>
Subject: Re: [PATCH v2 2/4] drm/amdgpu/gfx11: recover gfx user queues on priv- fault

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

Quoted 20 lines · Jesse Zhang

If a priv/bad-op fault does not match a kernel queue slot, it belongs to a MES-scheduled user queue. Compute IVs carry the doorbell and use the existing path; gfx IVs do not, so record the faulted slot and let a worker read the doorbell back from the HQD (regCP_RB_DOORBELL_CONTROL), look up the user queue and reset it.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 60
+++++++++++++++++++++++---
 1 file changed, 55 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0 -0
index 0cbbdc3694f4..a802b0ac1544 100644
@@ -1601,6 +1601,8 @@ static void gfx_v11_0_alloc_ip_dump(struct

amdgpu_device *adev)

drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_sw_fini(struct amdgpu_ip_block

Quoted 20 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +6 -0
        }
 }
 
+static void gfx_v11_0_userq_priv_fault_work(struct work_struct
+*work);
+
 static int gfx_v11_0_sw_init(struct amdgpu_ip_block *ip_block)  {
        int i, j, k, r, ring_id;
@@ -1931,6 +1933,8 @@ static int gfx_v11_0_sw_init(struct
 amdgpu_ip_block *ip_block)
 
        mutex_init(&adev->gfx.mec.reset_mutex);
 
+       INIT_WORK(&adev->gfx.userq_priv_fault_work,
+ gfx_v11_0_userq_priv_fault_work);
+
        return 0;
 }
@@ -1968,6 +1972,8 @@ static int gfx_v11_0_sw_fini(struct amdgpu_ip_block

*ip_block)

drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_sw_fini(struct amdgpu_ip_block *ip_block)

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3 -0
        int i;
        struct amdgpu_device *adev = ip_block->adev;
 
+       cancel_work_sync(&adev->gfx.userq_priv_fault_work);
+
        for (i = 0; i < adev->gfx.num_gfx_rings; i++)
                amdgpu_ring_fini(&adev->gfx.gfx_ring[i]);
        for (i = 0; i < adev->gfx.num_compute_rings; i++) @@ -6707,10
+6713,47 @@ static int gfx_v11_0_set_priv_inst_fault_state(struct

amdgpu_device *adev,

Quoted 17 lines
        return 0;

}

drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +14 -0
+/*
+ * A gfx exception IV carries no doorbell. For each faulted slot,
+read the
+ * doorbell back from the HQD (left in place by the fatal fault),
+look up the
+ * user queue and kick its per-queue reset.
+ */
+static void gfx_v11_0_userq_priv_fault_work(struct work_struct *work)
+{
+       struct amdgpu_device *adev =
+               container_of(work, struct amdgpu_device, gfx.userq_priv_fault_work);
+       unsigned long slots = xchg(&adev->gfx.userq_priv_fault_slots, 0);
+       unsigned int id;
+

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

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10 -0
+       for_each_set_bit(id, &slots, BITS_PER_LONG) {
+               u8 pipe = id & 0x3;
+               u8 queue = (id >> 2) & 0x7;
+               struct amdgpu_usermode_queue *q;
+               u32 db_ctrl, doorbell;
+
+               amdgpu_gfx_off_ctrl(adev, false);
+               mutex_lock(&adev->srbm_mutex);
+               soc21_grbm_select(adev, 0, pipe, queue, 0);
+               db_ctrl = RREG32_SOC15(GC, 0,

regCP_RB_DOORBELL_CONTROL);

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

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5 -0
+               soc21_grbm_select(adev, 0, 0, 0, 0);
+               mutex_unlock(&adev->srbm_mutex);
+               amdgpu_gfx_off_ctrl(adev, true);
+
+               doorbell = (db_ctrl &

CP_RB_DOORBELL_CONTROL__DOORBELL_OFFSET_MASK) >>

Quoted 1 line

+

CP_RB_DOORBELL_CONTROL__DOORBELL_OFFSET__SHIFT;

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +6 -0
+               q = xa_load(&adev->userq_doorbell_xa, doorbell);
+               if (q)
+                       amdgpu_userq_start_hang_detect_work(q);
+       }
+}
+
 static void gfx_v11_0_handle_priv_fault(struct amdgpu_device *adev,
                                        struct amdgpu_iv_entry *entry)
{
        u32 doorbell_offset = entry->src_data[0] &

AMDGPU_CTXID0_DOORBELL_ID_MASK;

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

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3 -1
+       u8 me_id = (entry->ring_id & 0x0c) >> 2;
+       u8 pipe_id = (entry->ring_id & 0x03) >> 0;
+       u8 queue_id = (entry->ring_id & 0x70) >> 4;
 
        /*
         * Try KQ first by ring_id (HW slot is authoritative). The @@
-6718,9 +6761,6 @@ 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 10 lines
         * never share a HW slot.
         */
        if (!adev->gfx.disable_kq) {
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0 -3
-               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;
@@ -6752,10 +6792,20 @@ 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 6796

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2 -2
                }
        }
 
-       /* No KQ matched: HW slot is a MES-scheduled user queue. */
-       if (adev->enable_mes && doorbell_offset)
+       /* No KQ matched: the faulting slot belongs to a user queue. */
+       if (!adev->enable_mes)
Quoted 6 lines

I think this should be:

if (adev->gfx.disable_uq)

    return;

Same comment for patch 3.

Thanks Alex, will fix it.

Quoted 9 lines

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

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3 -0
+               return;
+
+       if (doorbell_offset) {
                amdgpu_userq_process_reset_irq(adev, entry->pasid,
                                               doorbell_offset);

If the doorbell offset is not provided, do we need to keep this code? Same comment for patch 3.

both paths are needed. A compute user-queue fault IV carries the doorbell offset, so we reset the queue directly from it.
A gfx user-queue fault is raised by the ME and carries only the HW slot (no doorbell) .-that's exactly why the else branch records the slot and lets the worker read the doorbell back from the HQD.

Thanks
Jesse

Quoted 16 lines

Alex

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +7 -1
+       } else {
+               /* GFX IVs lack the doorbell; record the slot and let the
+                * worker read it back from the HQD.
+                */
+               set_bit(pipe_id | (queue_id << 2), &adev->gfx.userq_priv_fault_slots);
+               schedule_work(&adev->gfx.userq_priv_fault_work);
+       }
 }
 
 static int gfx_v11_0_priv_reg_irq(struct amdgpu_device *adev,
--

2.49.0

#4 lore raw

PATCH v2 3/4 drm/amdgpu/gfx12: recover gfx user queues on priv-fault

In reply to Jesse Zhang

Mirror the gfx11 priv-fault user-queue recovery for GFX12, reading the doorbell back from the HQD via soc24_grbm_select.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 62 +++++++++++++++++++++++---
 1 file changed, 55 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +55 -7
index b3887c5262a0..7b8a841d23fa 100644
@@ -1400,6 +1400,8 @@ static void gfx_v12_0_alloc_ip_dump(struct amdgpu_device *adev)
 	}
 }
 
+static void gfx_v12_0_userq_priv_fault_work(struct work_struct *work);
+
 static int gfx_v12_0_sw_init(struct amdgpu_ip_block *ip_block)
 {
 	int i, j, k, r, ring_id = 0;
@@ -1608,6 +1610,8 @@ static int gfx_v12_0_sw_init(struct amdgpu_ip_block *ip_block)
 
 	mutex_init(&adev->gfx.mec.reset_mutex);
 
+	INIT_WORK(&adev->gfx.userq_priv_fault_work, gfx_v12_0_userq_priv_fault_work);
+
 	return 0;
 }
 
@@ -1645,6 +1649,8 @@ static int gfx_v12_0_sw_fini(struct amdgpu_ip_block *ip_block)
 	int i;
 	struct amdgpu_device *adev = ip_block->adev;
 
+	cancel_work_sync(&adev->gfx.userq_priv_fault_work);
+
 	for (i = 0; i < adev->gfx.num_gfx_rings; i++)
 		amdgpu_ring_fini(&adev->gfx.gfx_ring[i]);
 	for (i = 0; i < adev->gfx.num_compute_rings; i++)
@@ -5038,24 +5044,56 @@ static int gfx_v12_0_set_priv_inst_fault_state(struct amdgpu_device *adev,
 	return 0;
 }
 
+/*
+ * A gfx exception IV carries no doorbell. For each faulted slot, read the
+ * doorbell back from the HQD (left in place by the fatal fault), look up the
+ * user queue and kick its per-queue reset.
+ */
+static void gfx_v12_0_userq_priv_fault_work(struct work_struct *work)
+{
+	struct amdgpu_device *adev =
+		container_of(work, struct amdgpu_device, gfx.userq_priv_fault_work);
+	unsigned long slots = xchg(&adev->gfx.userq_priv_fault_slots, 0);
+	unsigned int id;
+
+	for_each_set_bit(id, &slots, BITS_PER_LONG) {
+		u8 pipe = id & 0x3;
+		u8 queue = (id >> 2) & 0x7;
+		struct amdgpu_usermode_queue *q;
+		u32 db_ctrl, doorbell;
+
+		amdgpu_gfx_off_ctrl(adev, false);
+		mutex_lock(&adev->srbm_mutex);
+		soc24_grbm_select(adev, 0, pipe, queue, 0);
+		db_ctrl = RREG32_SOC15(GC, 0, regCP_RB_DOORBELL_CONTROL);
+		soc24_grbm_select(adev, 0, 0, 0, 0);
+		mutex_unlock(&adev->srbm_mutex);
+		amdgpu_gfx_off_ctrl(adev, true);
+
+		doorbell = (db_ctrl & CP_RB_DOORBELL_CONTROL__DOORBELL_OFFSET_MASK) >>
+			   CP_RB_DOORBELL_CONTROL__DOORBELL_OFFSET__SHIFT;
+		q = xa_load(&adev->userq_doorbell_xa, doorbell);
+		if (q)
+			amdgpu_userq_start_hang_detect_work(q);
+	}
+}
+
 static void gfx_v12_0_handle_priv_fault(struct amdgpu_device *adev,
 					struct amdgpu_iv_entry *entry)
 {
 	u32 doorbell_offset = entry->src_data[0] & AMDGPU_CTXID0_DOORBELL_ID_MASK;
+	u8 me_id = (entry->ring_id & 0x0c) >> 2;
+	u8 pipe_id = (entry->ring_id & 0x03) >> 0;
+	u8 queue_id = (entry->ring_id & 0x70) >> 4;
 
 	/*
 	 * 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;
 
-		me_id = (entry->ring_id & 0x0c) >> 2;
-		pipe_id = (entry->ring_id & 0x03) >> 0;
-		queue_id = (entry->ring_id & 0x70) >> 4;
-
 		switch (me_id) {
 		case 0:
 			for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
@@ -5084,10 +5122,20 @@ static void gfx_v12_0_handle_priv_fault(struct amdgpu_device *adev,
 		}
 	}
 
-	/* No KQ matched: HW slot is a MES-scheduled user queue. */
-	if (adev->enable_mes && doorbell_offset)
+	/* No KQ matched: the faulting slot belongs to a user queue. */
+	if (!adev->enable_mes)
+		return;
+
+	if (doorbell_offset) {
 		amdgpu_userq_process_reset_irq(adev, entry->pasid,
 					       doorbell_offset);
+	} else {
+		/* GFX IVs lack the doorbell; record the slot and let the
+		 * worker read it back from the HQD.
+		 */
+		set_bit(pipe_id | (queue_id << 2), &adev->gfx.userq_priv_fault_slots);
+		schedule_work(&adev->gfx.userq_priv_fault_work);
+	}
 }
 
 static int gfx_v12_0_priv_reg_irq(struct amdgpu_device *adev,
Signature · 1 line
2.49.0
#5 lore raw

PATCH v2 4/4 drm/amdgpu/userq: mark a queue unmapped after a per-queue reset

In reply to Jesse Zhang

mes_userq_reset() unmaps the queue via the low-level mes_userq_unmap() (REMOVE_QUEUE) but does not update queue->state, so the queue still looks MAPPED. The destroy path then issues a second, redundant REMOVE_QUEUE for the already-removed queue; for gfx that unmap waits on an EOP that never arrives, times out (-110) and escalates to a full GPU reset.

Mark the queue UNMAPPED on a successful reset-path unmap so destroy skips the redundant REMOVE_QUEUE.

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +11 -1
index df4efdea1136..b5d5065415d4 100644
@@ -26,6 +26,7 @@
 #include "amdgpu_gfx.h"
 #include "mes_userqueue.h"
 #include "amdgpu_userq_fence.h"
+#include "amdgpu_trace.h"
 
 #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE
 #define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
@@ -209,7 +210,16 @@ int mes_userq_reset(struct amdgpu_usermode_queue *queue)
 	amdgpu_mes_unlock(&adev->mes);
 	if (r)
 		return r;
-	return mes_userq_unmap(queue);
+
+	/* mes_userq_unmap() does not update queue->state; mark it UNMAPPED so the
+	 * destroy path does not issue a second REMOVE_QUEUE for the removed queue.
+	 */
+	r = mes_userq_unmap(queue);
+	if (!r) {
+		trace_amdgpu_userq_state_changed(queue, AMDGPU_USERQ_STATE_UNMAPPED);
+		queue->state = AMDGPU_USERQ_STATE_UNMAPPED;
+	}
+	return r;
 }
 
 int mes_userq_reset_queue(struct amdgpu_device *adev,
Signature · 1 line
2.49.0
#6 lore raw
In reply to Jesse Zhang

AMD General

Ping..

Quoted 36 lines

-----Original Message-----
From: Jesse Zhang <[email protected]>
Sent: Wednesday, July 22, 2026 11:21 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH v2 1/4] drm/amdgpu: track faulted gfx user-queue slots

A gfx priv/bad-op fault IV carries only the HW slot (ring_id), not the faulting user queue's doorbell. Add userq_priv_fault_slots (an atomic bitmap of faulted slots, so concurrent faults are not dropped) and userq_priv_fault_work to struct amdgpu_gfx; a worker drains the bitmap and reads the doorbell back from each HQD to locate and reset the queue.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +3 -1
index aefd4f03b443..f83afa7e0aa5 100644
@@ -535,6 +535,9 @@ struct amdgpu_gfx {
      struct mutex                    userq_sch_mutex;
      u64                             userq_sch_req_count[MAX_XCP];
      bool                            userq_sch_inactive[MAX_XCP];
+     /* atomic bitmap of faulted gfx UQ slots (index = pipe | queue << 2) */
+     unsigned long                   userq_priv_fault_slots;
+     struct work_struct              userq_priv_fault_work;
      unsigned long                   enforce_isolation_jiffies[MAX_XCP];
      unsigned long                   enforce_isolation_time[MAX_XCP];
 
--

2.49.0