drm/amdgpu: track faulted gfx user-queue slots
Subsystems (2)
PATCH v4 1/5 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
@@ -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
PATCH v4 2/5 drm/amdgpu/gfx11: add priv-fault user-queue recovery worker
A gfx user-queue priv/bad-op fault is raised by the ME and carries only the HW slot, not the faulting queue's doorbell. Add a per-IP worker that drains adev->gfx.userq_priv_fault_slots, reads the doorbell back from each HQD via soc21_grbm_select (regCP_RB_DOORBELL_CONTROL), looks up the user queue and kicks its per-queue reset.
The shared amdgpu_gfx_handle_priv_fault() helper schedules this worker for a gfx user-queue fault; wiring the helper up is done in a later patch.
v2:
- gate on adev->gfx.disable_uq instead of !adev->enable_mes (Alex)
- document why both the doorbell (compute) and HW-slot (gfx) reset paths are needed (Alex)
v3:
- rebase amd-staging-drm-next. adapt to the deduplicated amdgpu_gfx_handle_priv_fault() helper (commit d8ab7636160e); no functional change
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +39 -0
@@ -362,6 +362,7 @@ static void gfx_v11_0_ring_invalidate_tlbs(struct amdgpu_ring *ring, bool all_hub, uint8_t dst_sel);static void gfx_v11_0_set_safe_mode (struct amdgpu_device *adev,int xcc_id);static void gfx_v11_0_unset_safe_mode (struct amdgpu_device *adev,int xcc_id); +static void gfx_v11_0_userq_priv_fault_work (struct work_struct *work);static void gfx_v11_0_update_perf_clk (struct amdgpu_device *adev,bool enable);
@@ -1932,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 ; }
@@ -1969,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++)
@@ -6711,6 +6716,40 @@ 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) {
Signature · 1 line
2.49.0
PATCH v4 3/5 drm/amdgpu/gfx12: add priv-fault user-queue recovery worker
In reply to Jesse ZhangMirror the gfx11 priv-fault user-queue recovery worker for GFX12, reading the doorbell back from the HQD via soc24_grbm_select.
The shared amdgpu_gfx_handle_priv_fault() helper schedules this worker for a gfx user-queue fault; wiring the helper up is done in a later patch.
v2:
- gate on adev->gfx.disable_uq instead of !adev->enable_mes (Alex)
- document why both the doorbell (compute) and HW-slot (gfx) reset paths are needed (Alex)
v3:
- rebase amd-staging-drm-next. adapt to the deduplicated amdgpu_gfx_handle_priv_fault() helper (commit d8ab7636160e); no functional change
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +39 -0
@@ -286,6 +286,7 @@ static void gfx_v12_0_ring_invalidate_tlbs(struct amdgpu_ring *ring, bool all_hub, uint8_t dst_sel);static void gfx_v12_0_set_safe_mode (struct amdgpu_device *adev,int xcc_id);static void gfx_v12_0_unset_safe_mode (struct amdgpu_device *adev,int xcc_id); +static void gfx_v12_0_userq_priv_fault_work (struct work_struct *work);static void gfx_v12_0_update_perf_clk (struct amdgpu_device *adev,bool enable);
@@ -1609,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 ; }
@@ -1646,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++)
@@ -5048,6 +5053,40 @@ 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) {
Signature · 1 line
2.49.0
PATCH v4 4/5 drm/amdgpu: recover user queues in the shared priv-fault helper
In reply to Jesse ZhangIf a priv/bad-op fault does not match a kernel queue slot, it belongs to a MES-scheduled user queue. Extend the shared amdgpu_gfx_handle_priv_fault() helper introduced by commit d8ab7636160e ("drm/amd/amdgpu: remove duplicated code in gfx_v11 and gfx_v12") to recover it: gate on adev->gfx.disable_uq, reset a compute user queue directly from its doorbell, and for a gfx user queue (whose IV carries no doorbell) record the HW slot and schedule the per-IP recovery worker.
v2:
- gate on adev->gfx.disable_uq instead of !adev->enable_mes (Alex)
- document why both the doorbell (compute) and HW-slot (gfx) reset paths are needed (Alex)
v3:
- rebase amd-staing-drm-next. adapt to the deduplicated amdgpu_gfx_handle_priv_fault() helper (commit d8ab7636160e); no functional change
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +17 -3
@@ -866,7 +866,8 @@ int amdgpu_gfx_enable_kgq(struct amdgpu_device *adev, int xcc_id)* @queue_id: queue ID of the faulty ring * * This function handles privileged instruction faults by identifying -* the faulty ring (gfx or compute) and triggering a scheduler fault +* the faulty ring (gfx or compute) and triggering a scheduler fault, or by +* recovering the faulting user queue. */ void amdgpu_gfx_handle_priv_fault(struct amdgpu_device *adev, struct amdgpu_iv_entry *entry,
@@ -901,12 +902,25 @@ void amdgpu_gfx_handle_priv_fault(struct amdgpu_device *adev, } } +/* No KQ matched: the faulting slot belongs to a user queue. */ +if (adev->gfx.disable_uq) +return ; + doorbell_offset = entry->src_data[0 ] &AMDGPU_CTXID0_DOORBELL_ID_MASK ; -/* No KQ matched: HW slot is a MES-scheduled user queue. */ -if (adev->enable_mes && doorbell_offset) +/* +* A compute user-queue fault IV carries the doorbell offset, so reset +* the queue directly from it. A gfx user-queue fault is raised by the +* ME and carries only the HW slot (no doorbell); record the slot and +* let the worker read the doorbell back from the HQD. +*/ +if (doorbell_offset) {amdgpu_userq_process_reset_irq (adev, entry->pasid, doorbell_offset); + }else { +set_bit (pipe_id | (queue_id <<2 ), &adev->gfx.userq_priv_fault_slots); +schedule_work (&adev->gfx.userq_priv_fault_work); + } } static void amdgpu_gfx_do_off_ctrl(struct amdgpu_device *adev, bool enable,
Signature · 1 line
2.49.0
PATCH v4 5/5 drm/amdgpu/userq: mark a queue unmapped after a per-queue reset
In reply to Jesse Zhangmes_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
@@ -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
@@ -205,7 +206,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