drm/amdgpu/user: add reset helpers for error interrupts
Subsystems (2)
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
@@ -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
@@ -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
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
@@ -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
PATCH 3/6 drm/amdgpu/gfx12: handle error interrupts for userqs
In reply to Jesse ZhangFrom: 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
@@ -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
PATCH 4/6 drm/amdgpu/userq: identify guilty user queue from priv-fault IRQ
In reply to Jesse ZhangCP 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
@@ -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
@@ -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
@@ -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
@@ -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
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_idin src_data[0][9:0] (same encoding KFD extracts viaKFD_CTXID0_DOORBELL_ID_MASK), with pasid inentry->pasid. The existing lookup against BAR-absolutedoorbell_indexnever matches this payload, so the targeted-reset path is never taken.
Quoted 7 lines
Cache
args->in.doorbell_offseton the queue and look it up by the (vm->pasid,doorbell_offset) pair. Add aqueue->guiltyflag set by the IRQ and consumed via xchg inhang_detect_work; on a hit, route compute reset throughamdgpu_gfx_reset_mes_compute(..., queue, ...)and firehang_detectimmediately viamod_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
Signed-off-by Jesse Zhang <[email protected]>--- 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@@ -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@@ -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@@ -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@@ -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
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 IRQQuoted 7 lines · Jesse Zhang
CP priv-fault IRQ carries the offending queue's per-process
doorbell_idin src_data[0][9:0] (same encoding KFD extracts viaKFD_CTXID0_DOORBELL_ID_MASK), with pasid inentry->pasid. The existing lookup against BAR-absolutedoorbell_indexnever matches this payload, so the targeted-reset path is never taken.Quoted 7 lines
Cache
args->in.doorbell_offseton the queue and look it up by the (vm->pasid,doorbell_offset) pair. Add aqueue->guiltyflag set by the IRQ and consumed via xchg inhang_detect_work; on a hit, route compute reset throughamdgpu_gfx_reset_mes_compute(..., queue, ...)and firehang_detectimmediately viamod_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
Signed-off-by Jesse Zhang <[email protected]>--- 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@@ -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
-2AMDGPU_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 createQueue\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@@ -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 @@ structamdgpu_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); voidamdgpu_userq_start_hang_detect_work(struct amdgpu_usermode_queue *queue); voidamdgpu_userq_process_fence_irq(struct amdgpu_device *adev, u32 doorbell); -voidamdgpu_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.cb/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
indexea323d241324..27d0a3dbfce8100644drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -6681,10 +6681,16 @@ static intQuoted 1 line
gfx_v11_0_set_priv_inst_fault_state(struct
amdgpu_device*adev, static voidgfx_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.cb/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
indexb3f1bbf3fc13..7c269cb75e07100644drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +0
-0@@ -5009,10 +5009,16 @@ static intQuoted 1 line
gfx_v12_0_set_priv_inst_fault_state(struct
amdgpu_device*adev, static voidgfx_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
PATCH 5/6 drm/amdgpu/gfx11: try KQ ring_id match before user-queue lookup
In reply to Jesse ZhangKCQ 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
@@ -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
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_idhit is authoritative. Match KQ first; only call into the userq path when no KQ owns the faulting slot.Signed-off-by Jesse Zhang <[email protected]>--- 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@@ -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
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 KQring_idmatch before user- queue lookupdrivers/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_idhit is authoritative. Match KQ first; only call into the userq path when no KQ owns the faulting slot.Signed-off-by Jesse Zhang <[email protected]>--- 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@@ -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
-1for (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
-0break ; } } + +/* 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()andgfx_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
PATCH 6/6 drm/amdgpu/gfx12: try KQ ring_id match before user-queue lookup
In reply to Jesse ZhangKCQ 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
@@ -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