drm/amdgpu/gfx: add a reset_engine callback
Subsystems (2)
PATCH 1/13 drm/amdgpu/gfx: add a reset_engine callback
Some gfx hangs can't be recovered by a queue or a pipe reset, eg. a CP front-end stuck in the middle of a packet. They currently end in a full GPU reset, and VRAM is lost. Resetting only the graphics engine is enough for them, and leaves the compute engine running.
Add an optional reset_engine callback to amdgpu_gfx_funcs that resets only the graphics or only the compute engine. The split is specific to the GFX IP, eg. CP_SOFT_RESET_CNTL has GFX_ONLY_SOFT_RESET and CMP_ONLY_SOFT_RESET, so it doesn't belong in the amd_ip_funcs that all IP blocks share.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +10 -0
@@ -345,6 +345,13 @@ struct amdgpu_gfx_shadow_info {u32 eop_alignment; }; +/* The engines of the GFX IP that can be reset on their own. */ +enum amdgpu_gfx_engine { +AMDGPU_GFX_ENGINE_GFX ,/* PFP/ME and the gfx part of the CP front-end */ +AMDGPU_GFX_ENGINE_COMPUTE ,/* MEC and the compute part of the CP front-end */ +AMDGPU_GFX_ENGINE_NUM , +}; +struct amdgpu_gfx_funcs {/* get the gpu clock counter */ uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
@@ -376,6 +383,9 @@ struct amdgpu_gfx_funcs {/* find the gfx HQD slot (me/pipe/queue) for a doorbell */ bool (*detect_hung_queue)(struct amdgpu_device *adev,u32 doorbell_index,u32 *me,u32 *pipe,u32 *queue); +/* reset one engine, leaving the other one running; mec.reset_mutex held */ +int (*reset_engine)(struct amdgpu_device *adev, +enum amdgpu_gfx_engine engine); };struct sq_work {
Signature · 1 line
2.50.1
PATCH 2/13 drm/amdgpu/gfx12: add a gfx engine reset
A PM4 packet that declares more DWORDs than its IB has left leaves the gfx streaming engine waiting for data that never arrives. Neither a queue reset nor a pipe reset can stop it, so the recovery currently ends in a full GPU reset, and VRAM is lost.
Implement the reset_engine callback for the graphics engine:
- halt PFP/ME;
- wait for the memory requests of the CP DMA to complete;
- with CP_SOFT_RESET_CNTL.GFX_ONLY_SOFT_RESET and GFX_HQD_REG_RESET set, pulse GRBM_SOFT_RESET.SOFT_RESET_CPF/CPG. A CPF reset alone does not clear the stuck stream;
- restart PFP/ME and restore CP_PFP_IB_CONTROL;
- remap the kernel gfx queue through MES from its MQD backup.
MEC and the compute part of CPF/CPG aren't reset. On Navi48, compute work from kernel queues, KFD and user queues completed normally across thousands of engine resets, also with more compute queues than MES had HQDs for.
MES fetches its own queues through CPF, though. A MES command that was in flight during the reset never completed, so hold the MES lock across the reset.
When the reset hit memory requests of the CP DMA in flight, eg. the ME was halted in the middle of a DMA through TCIU, the ME stayed busy after the reset, and running MES on it failed the next MES commands until MES didn't respond at all. On Navi48 they completed within about 1 ms after the halt; waiting for them made that go away in hundreds of resets under load. The DMA of a hung stream may never complete: reset anyway after the usual timeout then. If the CP still doesn't go idle once PFP/ME were restarted, fail the reset so that a full reset follows. Check only
then: after the hang above, the PFP stays busy until restarted, so only wait for the memory requests after the pulse too.
The reset also clears the HQDs of the gfx user queues, the caller has to handle them.
The callback relies on the caller to only use it when the IP reports AMDGPU_RESET_TYPE_PER_ENGINE, which a later patch enables with MES and async gfx rings.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 142 +++++++++++++++++++++++++ 1 file changed, 142 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +142 -0
@@ -274,6 +274,8 @@ static void gfx_v12_0_set_imu_funcs(struct amdgpu_device *adev);static int gfx_v12_0_get_cu_info (struct amdgpu_device *adev,struct amdgpu_cu_info *cu_info);static uint64_t gfx_v12_0_get_gpu_clock_counter (struct amdgpu_device *adev); +static int gfx_v12_0_reset_engine (struct amdgpu_device *adev, +enum amdgpu_gfx_engine engine);static void gfx_v12_0_select_se_sh (struct amdgpu_device *adev,u32 se_num,u32 sh_num,u32 instance,int xcc_id);static u32 gfx_v12_0_get_wgp_active_bitmap_per_sh (struct amdgpu_device *adev);
@@ -959,6 +961,7 @@ static const struct amdgpu_gfx_funcs gfx_v12_0_gfx_funcs = { .update_perfmon_mgcg = &gfx_v12_0_update_perf_clk, .get_gfx_shadow_info = &gfx_v12_0_get_gfx_shadow_info, .get_hdp_flush_mask = &amdgpu_gfx_get_hdp_flush_mask, + .reset_engine = &gfx_v12_0_reset_engine, };static int gfx_v12_0_gpu_early_init (struct amdgpu_device *adev)
@@ -3844,6 +3847,145 @@ static int gfx_v12_0_wait_for_idle(struct amdgpu_ip_block *ip_block)return -ETIMEDOUT ; } +/* The CP DMA and the interfaces its memory requests go through */ +#define GFX12_CP_STAT_MEM_BUSY (CP_STAT__DMA_BUSY_MASK | \ + CP_STAT__TCIU_BUSY_MASK | \ + CP_STAT__RCIU_BUSY_MASK | \ + CP_STAT__UTCL2IU_BUSY_MASK) + +/* +* Soft reset the gfx CP and restart PFP and ME. Returns -ETIMEDOUT if the CP +* is still busy once restarted. +*/ +static int gfx_v12_0_soft_reset_gfx_cp (struct amdgpu_device *adev) +{ +u32 tmp, cntl, me_cntl, ib_control; +int i; + +amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); + +/* +* MES fetches its own queues through CPF: a MES command that is in +* flight during the reset doesn't complete. Keep MES commands out +* until the reset is released. +*/ +amdgpu_mes_lock (&adev->mes); + + me_cntl =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); +/* Cleared by the reset, but otherwise only set by the RLC on GFXOFF exit. */ + ib_control =RREG32_SOC15 (GC ,0 , regCP_PFP_IB_CONTROL); + + tmp =REG_SET_FIELD (me_cntl,CP_ME_CNTL ,ME_HALT ,1 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_HALT ,1 ); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +udelay (50 ); + +/* +* Let the memory requests of the CP DMA complete: when they are +* still in flight during the reset, the ME stays busy after it. The +* DMA of a hung stream may never complete, reset anyway then. +*/ +for (i =0 ; i < adev->usec_timeout; i++) { +if (!(RREG32_SOC15 (GC ,0 , regCP_STAT) &GFX12_CP_STAT_MEM_BUSY )) +break ; +udelay (1 ); + } + +/* Without GFX_ONLY_SOFT_RESET, a CPF reset would also hit compute and MES. */ + cntl =RREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL); + tmp =REG_SET_FIELD (cntl,CP_SOFT_RESET_CNTL ,GFX_ONLY_SOFT_RESET ,1 ); + tmp =REG_SET_FIELD (tmp,CP_SOFT_RESET_CNTL ,GFX_HQD_REG_RESET ,1 ); +WREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL, tmp); + +/* Both are needed: a CPF reset alone leaves the streaming engine stuck. */ + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); + tmp =REG_SET_FIELD (tmp,GRBM_SOFT_RESET ,SOFT_RESET_CPF ,1 ); + tmp =REG_SET_FIELD (tmp,GRBM_SOFT_RESET ,SOFT_RESET_CPG ,1 ); +WREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); +udelay (50 ); + tmp =REG_SET_FIELD (tmp,GRBM_SOFT_RESET ,SOFT_RESET_CPF ,0 ); + tmp =REG_SET_FIELD (tmp,GRBM_SOFT_RESET ,SOFT_RESET_CPG ,0 ); +WREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); + +WREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL, cntl); + +/* +* Let the memory requests in flight drain before PFP/ME restart. Not +* the whole CP: after a hang, the halted PFP stays busy until it is +* restarted. +*/ +for (i =0 ; i < adev->usec_timeout; i++) { +if (!(RREG32_SOC15 (GC ,0 , regCP_STAT) &GFX12_CP_STAT_MEM_BUSY )) +break ; +udelay (1 ); + } +amdgpu_mes_unlock (&adev->mes); + +/* Restart PFP and ME from the start of their firmware. */ +gfx_v12_0_set_pfp_ucode_start_addr (adev); +gfx_v12_0_set_me_ucode_start_addr (adev); + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,CE_HALT , +REG_GET_FIELD (me_cntl,CP_ME_CNTL ,CE_HALT )); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +WREG32_SOC15 (GC ,0 , regCP_PFP_IB_CONTROL, ib_control); +amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); + + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,ME_HALT ,0 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_HALT ,0 ); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +for (i =0 ; i < adev->usec_timeout; i++) { +if (!RREG32_SOC15 (GC ,0 , regCP_STAT)) +return 0 ; +udelay (1 ); + } +return -ETIMEDOUT ; +} + +/* +* Reset the graphics engine: the CP front-end (CPF/CPG), PFP/ME and the gfx +* HQDs. MEC, MES and the compute queues keep running. +* +* A malformed packet whose length runs past the end of an IB leaves the gfx +* streaming engine waiting for data that never arrives. Neither a queue nor +* a pipe reset can stop it, but a CPF/CPG soft reset limited to gfx can. +*/ +static int gfx_v12_0_reset_engine (struct amdgpu_device *adev, +enum amdgpu_gfx_engine engine) +{ +int i, r; + +lockdep_assert_held (&adev->gfx.mec.reset_mutex); + +if (engine !=AMDGPU_GFX_ENGINE_GFX ) +return -EOPNOTSUPP ; + +amdgpu_gfx_off_ctrl (adev, false); + +/* Leave a CP that doesn't go idle to a full reset. */ + r =gfx_v12_0_soft_reset_gfx_cp (adev); +if (r) +dev_err (adev->dev,"gfx CP still busy after reset, CP_STAT 0x%08x\n" , +RREG32_SOC15 (GC ,0 , regCP_STAT)); + +/* MES still has the kernel gfx queue mapped on the cleared HQD. */ +if (!r) + r =amdgpu_gfx_disable_kgq (adev,0 ); +if (!r) { +for (i =0 ; i < adev->gfx.num_gfx_rings; i++) +amdgpu_gfx_mqd_reset_restore (&adev->gfx.gfx_ring[i]); + r =amdgpu_gfx_enable_kgq (adev,0 ); + } +if (!r) + r =gfx_v12_0_cp_gfx_start (adev); + +amdgpu_gfx_off_ctrl (adev, true); +return r; +} +static uint64_t gfx_v12_0_get_gpu_clock_counter (struct amdgpu_device *adev) {uint64_t clock =0 ;
Signature · 1 line
2.50.1
PATCH 3/13 drm/amdgpu/gfx11: add a gfx engine reset
In reply to Jesse ZhangImplement the reset_engine callback for the graphics engine of gfx11, as for gfx12: a PM4 packet that runs past the end of its IB leaves the gfx streaming engine stuck, and neither a queue nor a pipe reset recovers it.
- halt PFP/ME and wait for the memory requests of the CP DMA to complete;
- with CP_SOFT_RESET_CNTL.GFX_ONLY_SOFT_RESET and GFX_HQD_REG_RESET set, pulse GRBM_SOFT_RESET.SOFT_RESET_CPF/CPG, holding the MES lock, and wait for the memory requests again;
- clear CP_VMID_RESET;
- restart PFP/ME from the start of their RS64 firmware and restore CP_PFP_IB_CONTROL; if the CP doesn't go idle then, fail the reset so that a full reset follows;
- remap the kernel gfx queue through MES from its MQD backup and init the CP registers.
MES resets a gfx queue by writing CP_VMID_RESET, which the PFP handles. When the PFP hung, eg. on a bad opcode, the request stays pending across the CPF/CPG reset, and the restarted PFP then waits on it forever for queues the reset already cleared. On Navi31, clearing it turned the engine resets after a failed queue reset of a bad opcode from 0 of 25 into 25 of 25.
Unlike gfx_v11_0_cp_gfx_start(), don't write the clear state to the kernel gfx ring: with enforced isolation, a ring write stops the user queues, which the caller keeps from being mapped or unmapped meanwhile. The queue reset doesn't write it either.
gfx11 has no helper to restart PFP/ME from their start addresses outside of the firmware load: add one. A later patch enables the reset with MES, async gfx rings and the RS64 firmware.
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 202 +++++++++++++++++++++++++ 1 file changed, 202 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +202 -0
@@ -363,6 +363,8 @@ static void gfx_v11_0_ring_invalidate_tlbs(struct amdgpu_ring *ring,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 int gfx_v11_0_reset_engine (struct amdgpu_device *adev, +enum amdgpu_gfx_engine engine);static void gfx_v11_0_update_perf_clk (struct amdgpu_device *adev,bool enable);
@@ -1150,6 +1152,7 @@ static const struct amdgpu_gfx_funcs gfx_v11_0_gfx_funcs = { .get_gfx_shadow_info = &gfx_v11_0_get_gfx_shadow_info, .get_hdp_flush_mask = &amdgpu_gfx_get_hdp_flush_mask, .detect_hung_queue = &gfx_v11_0_detect_hung_queue, + .reset_engine = &gfx_v11_0_reset_engine, };static int gfx_v11_0_gpu_early_init (struct amdgpu_device *adev)
@@ -6916,6 +6919,205 @@ static void gfx_v11_0_emit_mem_sync(struct amdgpu_ring *ring)amdgpu_ring_write (ring, gcr_cntl);/* GCR_CNTL */ } +/* Restart the PFP and ME pipes from the start of their RS64 firmware. */ +static void gfx_v11_0_restart_gfx_rs64 (struct amdgpu_device *adev) +{ +const struct gfx_firmware_header_v2_0 *pfp_hdr, *me_hdr; +u32 pipe_id, tmp; + + pfp_hdr = (const struct gfx_firmware_header_v2_0 *)adev->gfx.pfp_fw->data; + me_hdr = (const struct gfx_firmware_header_v2_0 *)adev->gfx.me_fw->data; + +mutex_lock (&adev->srbm_mutex); +for (pipe_id =0 ; pipe_id < adev->gfx.me.num_pipe_per_me; pipe_id++) { +soc21_grbm_select (adev,0 , pipe_id,0 ,0 ); +WREG32_SOC15 (GC ,0 , regCP_PFP_PRGRM_CNTR_START, + (pfp_hdr->ucode_start_addr_hi <<30 ) | + (pfp_hdr->ucode_start_addr_lo >>2 )); +WREG32_SOC15 (GC ,0 , regCP_PFP_PRGRM_CNTR_START_HI, + pfp_hdr->ucode_start_addr_hi >>2 ); +WREG32_SOC15 (GC ,0 , regCP_ME_PRGRM_CNTR_START, + (me_hdr->ucode_start_addr_hi <<30 ) | + (me_hdr->ucode_start_addr_lo >>2 )); +WREG32_SOC15 (GC ,0 , regCP_ME_PRGRM_CNTR_START_HI, + me_hdr->ucode_start_addr_hi >>2 ); + +/* A pipe reset takes the start addresses. */ + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); +if (pipe_id ==0 ) { + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_PIPE0_RESET ,1 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,ME_PIPE0_RESET ,1 ); + }else { + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_PIPE1_RESET ,1 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,ME_PIPE1_RESET ,1 ); + } +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +if (pipe_id ==0 ) { + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_PIPE0_RESET ,0 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,ME_PIPE0_RESET ,0 ); + }else { + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_PIPE1_RESET ,0 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,ME_PIPE1_RESET ,0 ); + } +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); + } +soc21_grbm_select (adev,0 ,0 ,0 ,0 ); +mutex_unlock (&adev->srbm_mutex); +} + +/* The CP DMA and the interfaces its memory requests go through */ +#define GFX11_CP_STAT_MEM_BUSY (CP_STAT__DMA_BUSY_MASK | \ + CP_STAT__TCIU_BUSY_MASK | \ + CP_STAT__RCIU_BUSY_MASK | \ + CP_STAT__UTCL2IU_BUSY_MASK) + +/* +* Soft reset the gfx CP and restart PFP and ME. Returns -ETIMEDOUT if the CP +* is still busy once restarted. +*/ +static int gfx_v11_0_soft_reset_gfx_cp (struct amdgpu_device *adev) +{ +u32 tmp, cntl, me_cntl, ib_control; +int i; + +amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); + +/* +* MES fetches its own queues through CPF: a MES command that is in +* flight during the reset doesn't complete. Keep MES commands out +* until the reset is released. +*/ +amdgpu_mes_lock (&adev->mes); + + me_cntl =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); +/* Cleared by the reset, but otherwise only set by the RLC on GFXOFF exit. */ + ib_control =RREG32_SOC15 (GC ,0 , regCP_PFP_IB_CONTROL); + + tmp =REG_SET_FIELD (me_cntl,CP_ME_CNTL ,ME_HALT ,1 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_HALT ,1 ); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +udelay (50 ); + +/* +* Let the memory requests of the CP DMA complete: when they are +* still in flight during the reset, the ME stays busy after it. The +* DMA of a hung stream may never complete, reset anyway then. +*/ +for (i =0 ; i < adev->usec_timeout; i++) { +if (!(RREG32_SOC15 (GC ,0 , regCP_STAT) &GFX11_CP_STAT_MEM_BUSY )) +break ; +udelay (1 ); + } + +/* Without GFX_ONLY_SOFT_RESET, a CPF reset would also hit compute and MES. */ + cntl =RREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL); + tmp =REG_SET_FIELD (cntl,CP_SOFT_RESET_CNTL ,GFX_ONLY_SOFT_RESET ,1 ); + tmp =REG_SET_FIELD (tmp,CP_SOFT_RESET_CNTL ,GFX_HQD_REG_RESET ,1 ); +WREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL, tmp); + +/* Both are needed: a CPF reset alone leaves the streaming engine stuck. */ + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); + tmp =REG_SET_FIELD (tmp,GRBM_SOFT_RESET ,SOFT_RESET_CPF ,1 ); + tmp =REG_SET_FIELD (tmp,GRBM_SOFT_RESET ,SOFT_RESET_CPG ,1 ); +WREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); +udelay (50 ); + tmp =REG_SET_FIELD (tmp,GRBM_SOFT_RESET ,SOFT_RESET_CPF ,0 ); + tmp =REG_SET_FIELD (tmp,GRBM_SOFT_RESET ,SOFT_RESET_CPG ,0 ); +WREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); + +WREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL, cntl); + +/* +* Let the memory requests in flight drain before PFP/ME restart. Not +* the whole CP: after a hang, the halted PFP stays busy until it is +* restarted. +*/ +for (i =0 ; i < adev->usec_timeout; i++) { +if (!(RREG32_SOC15 (GC ,0 , regCP_STAT) &GFX11_CP_STAT_MEM_BUSY )) +break ; +udelay (1 ); + } + +/* +* MES resets a gfx queue through CP_VMID_RESET, which the PFP handles. +* A request the hung PFP never handled survives the reset, and the +* restarted PFP then waits on it for queues the reset already cleared. +*/ +WREG32_SOC15 (GC ,0 , regCP_VMID_RESET,0 ); +amdgpu_mes_unlock (&adev->mes); + +gfx_v11_0_restart_gfx_rs64 (adev); + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,CE_HALT , +REG_GET_FIELD (me_cntl,CP_ME_CNTL ,CE_HALT )); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +WREG32_SOC15 (GC ,0 , regCP_PFP_IB_CONTROL, ib_control); +amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); + + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,ME_HALT ,0 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_HALT ,0 ); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +for (i =0 ; i < adev->usec_timeout; i++) { +if (!RREG32_SOC15 (GC ,0 , regCP_STAT)) +return 0 ; +udelay (1 ); + } +return -ETIMEDOUT ; +} + +/* +* Reset the graphics engine: the CP front-end (CPF/CPG), PFP/ME and the gfx +* HQDs. MEC, MES and the compute queues keep running. +* +* A malformed packet whose length runs past the end of an IB leaves the gfx +* streaming engine waiting for data that never arrives. Neither a queue nor +* a pipe reset can stop it, but a CPF/CPG soft reset limited to gfx can. +*/ +static int gfx_v11_0_reset_engine (struct amdgpu_device *adev, +enum amdgpu_gfx_engine engine) +{ +int i, r; + +lockdep_assert_held (&adev->gfx.mec.reset_mutex); + +if (engine !=AMDGPU_GFX_ENGINE_GFX ) +return -EOPNOTSUPP ; + +amdgpu_gfx_off_ctrl (adev, false); + +/* Leave a CP that doesn't go idle to a full reset. */ + r =gfx_v11_0_soft_reset_gfx_cp (adev); +if (r) +dev_err (adev->dev,"gfx CP still busy after reset, CP_STAT 0x%08x\n" , +RREG32_SOC15 (GC ,0 , regCP_STAT)); + +/* MES still has the kernel gfx queue mapped on the cleared HQD. */ +if (!r) + r =amdgpu_gfx_disable_kgq (adev,0 ); +if (!r) { +for (i =0 ; i < adev->gfx.num_gfx_rings; i++) +amdgpu_gfx_mqd_reset_restore (&adev->gfx.gfx_ring[i]); + r =amdgpu_gfx_enable_kgq (adev,0 ); + } +/* +* Only init the CP registers: gfx_v11_0_cp_gfx_start() also writes the +* clear state to the kernel gfx ring, and a ring write with enforced +* isolation stops the user queues, which the caller keeps from being +* mapped or unmapped. +*/ +if (!r) { +WREG32_SOC15 (GC ,0 , regCP_MAX_CONTEXT, + adev->gfx.config.max_hw_contexts -1 ); +WREG32_SOC15 (GC ,0 , regCP_DEVICE_ID,1 ); + } + +amdgpu_gfx_off_ctrl (adev, true); +return r; +} +static int gfx_v11_0_reset_kgq (struct amdgpu_ring *ring,unsigned int vmid,struct amdgpu_fence *timedout_fence)
Signature · 1 line
2.50.1
PATCH 4/13 drm/amdgpu/userq: add a lock to keep user queues stable in an engine reset
In reply to Jesse ZhangAn engine reset, eg. of the gfx engine, only takes the reset domain for
read: taking it for write would fail the queue operations of the compute engine, eg. KFD adds and removes queues only with a read trylock. Unlike in a full reset, that doesn't keep a user queue from being mapped, unmapped or freed while the reset handles it.
Add a userq_engine_reset_sem per engine of the GFX IP. A reset that handles the user queues of an engine holds it for write from saving their state before the reset to recovering them after it. The queue map/unmap/preempt/restore helpers, and removing a queue from the doorbell xarray before it is freed, take the one of the queue's engine for read: they only need to keep the reset out, and the queues of different processes keep changing state concurrently. A preemption, for example, polls its suspend fence for up to usec_timeout after it released the MES lock. The queues of the other IPs, eg. SDMA, don't take any, and the reset of one engine doesn't hold up the queues of the other.
Each semaphore gets a lockdep class of its own: a compute reset may stop the gfx user queues for enforced isolation.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 5 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 51 ++++++++++++++++++++++ 3 files changed, 59 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
@@ -3871,6 +3871,9 @@ int amdgpu_device_init(struct amdgpu_device *adev,INIT_LIST_HEAD (&adev->pm.od_kobj_list);xa_init_flags (&adev->userq_doorbell_xa,XA_FLAGS_LOCK_IRQ ); +/* A lockdep class each: a compute reset may stop gfx user queues. */ +init_rwsem (&adev->gfx.userq_engine_reset_sem[AMDGPU_GFX_ENGINE_GFX ]); +init_rwsem (&adev->gfx.userq_engine_reset_sem[AMDGPU_GFX_ENGINE_COMPUTE ]);INIT_DELAYED_WORK (&adev->delayed_init_work, amdgpu_device_delayed_init_work_handler);
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +5 -0
@@ -550,6 +550,11 @@ struct amdgpu_gfx {struct amdgpu_isolation_work enforce_isolation[MAX_XCP ];/* Mutex for synchronizing KFD scheduler operations */ struct mutex userq_sch_mutex; +/* +* Per engine: held for write by a reset that handles the user queues +* of the engine, and for read to change the state of one or free it. +*/ +struct rw_semaphore userq_engine_reset_sem[AMDGPU_GFX_ENGINE_NUM ];u64 userq_sch_req_count[MAX_XCP ];bool userq_sch_inactive[MAX_XCP ];/* atomic bitmap of faulted gfx UQ slots (index = pipe | queue << 2) */
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +51 -0
95 lines not on this page · raw message
Signature · 1 line
2.50.1
PATCH 5/13 drm/amdgpu/userq: add a walk over the user queues of one type
In reply to Jesse ZhangA reset of the queues of one engine of the GFX IP only holds the reset lock of that engine: the user queues of the other engines can be freed meanwhile, and their type can't be read then.
Add amdgpu_userq_next_of_type() and for_each_userq_of_type(), which check the type of a queue under the xarray lock, before it can be freed. A queue of the walked type is kept from being freed by the reset lock of its engine, which the caller holds.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 22 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 8 ++++++++ 2 files changed, 30 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +22 -0
@@ -1591,6 +1591,28 @@ void amdgpu_userq_gem_va_unmap_validate(struct amdgpu_device *adev, false, MAX_SCHEDULE_TIMEOUT); } +/* +* The next user queue of @queue_type at or after *@index. An engine reset +* only keeps the queues of its engine from being freed: check the type of +* the others under the xarray lock, before they can be. +*/ +struct amdgpu_usermode_queue * +amdgpu_userq_next_of_type (struct amdgpu_device *adev,unsigned long *index, +u32 queue_type) +{ +struct xarray *xa = &adev->userq_doorbell_xa; +struct amdgpu_usermode_queue *queue; +unsigned long flags; + +xa_lock_irqsave (xa, flags); +xa_for_each_start (xa, *index, queue, *index) { +if (queue->queue_type == queue_type) +break ; + } +xa_unlock_irqrestore (xa, flags); +return queue; +} +void amdgpu_userq_pre_reset (struct amdgpu_device *adev) {const struct amdgpu_userq_funcs *userq_funcs;
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +8 -0
@@ -179,6 +179,14 @@ int amdgpu_userq_stop_sched_for_enforce_isolation(struct amdgpu_device *adev,int amdgpu_userq_start_sched_for_enforce_isolation (struct amdgpu_device *adev,u32 idx);void amdgpu_userq_reset_work (struct work_struct *work); +struct amdgpu_usermode_queue * +amdgpu_userq_next_of_type (struct amdgpu_device *adev,unsigned long *index, +u32 queue_type); +/* Walk the user queues of an engine while the queues of others get freed. */ +#define for_each_userq_of_type (adev, index, queue, queue_type) \ + for (index = 0; \ + (queue = amdgpu_userq_next_of_type(adev, &index, queue_type)); \ + index++)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);
Signature · 1 line
2.50.1
Christian König
maintainerRe: [PATCH 05/13] drm/amdgpu/userq: add a walk over the user queues of one type
Quoted 8 lines · Jesse Zhang
A reset of the queues of one engine of the GFX IP only holds the reset lock of that engine: the user queues of the other engines can be freed meanwhile, and their type can't be read then.
Add
amdgpu_userq_next_of_type()andfor_each_userq_of_type(), which check the type of a queue under the xarray lock, before it can be freed. A queue of the walked type is kept from being freed by the reset lock of its engine, which the caller holds.
Absolutely clear NAK to that!
You *CAN'T* touch the userqueues from the reset handler like this nor keep them alive with an extra lock.
The only thing which we can do from the reset handler is to take the xa_lock_irqsave() and iterate the queues to change their state.
Everything else is *STRICTLY* forbidden from inside a reset handler!
Regards,
Christian.
Quoted 59 lines
Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 22 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 8 ++++++++ 2 files changed, 30 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +22
-0@@ -1591,6 +1591,28 @@ void amdgpu_userq_gem_va_unmap_validate(struct amdgpu_device *adev, false, MAX_SCHEDULE_TIMEOUT); } +/* +* The next user queue of @queue_type at or after *@index. An engine reset +* only keeps the queues of its engine from being freed: check the type of +* the others under the xarray lock, before they can be. +*/ +struct amdgpu_usermode_queue * +amdgpu_userq_next_of_type (struct amdgpu_device *adev,unsigned long *index, +u32 queue_type) +{ +struct xarray *xa = &adev->userq_doorbell_xa; +struct amdgpu_usermode_queue *queue; +unsigned long flags; + +xa_lock_irqsave (xa, flags); +xa_for_each_start (xa, *index, queue, *index) { +if (queue->queue_type == queue_type) +break ; + } +xa_unlock_irqrestore (xa, flags); +return queue; +} +void amdgpu_userq_pre_reset (struct amdgpu_device *adev) {const struct amdgpu_userq_funcs *userq_funcs;drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +8
-0@@ -179,6 +179,14 @@ int amdgpu_userq_stop_sched_for_enforce_isolation(struct amdgpu_device *adev,int amdgpu_userq_start_sched_for_enforce_isolation (struct amdgpu_device *adev,u32 idx);void amdgpu_userq_reset_work (struct work_struct *work); +struct amdgpu_usermode_queue * +amdgpu_userq_next_of_type (struct amdgpu_device *adev,unsigned long *index, +u32 queue_type); +/* Walk the user queues of an engine while the queues of others get freed. */ +#define for_each_userq_of_type (adev, index, queue, queue_type) \ + for (index = 0; \ + (queue = amdgpu_userq_next_of_type(adev, &index, queue_type)); \ + index++)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);
PATCH 6/13 drm/amdgpu/userq: add helpers to reset the user queues of one engine
In reply to Jesse ZhangAn engine reset, eg. of the gfx engine, only resets the queues of one engine of the GFX IP, while the queues of the other engines keep running. amdgpu_userq_pre_reset() and amdgpu_userq_post_reset() handle all the user queues for a full reset. Add separate helpers for the queues of one engine, which walk them with for_each_userq_of_type():
- amdgpu_userq_pre_engine_reset(), called before the reset, cancels their pending hang detection and marks them hung. It doesn't unmap the mapped and the preempted queues: the scheduler firmware can't preempt the queues of a hung engine, and the reset clears their state anyway. A queue that was unmapped before, eg. evicted, is marked hung too:
mapping it again later would resume its work across the reset.
- amdgpu_userq_post_engine_reset(), called after the reset but before the scheduler firmware resumes the queues of the engine, unmaps the queues the reset left mapped and signals the fences of the dropped queues. It returns an error if a queue couldn't be unmapped, so that a full reset can follow.
- amdgpu_userq_cancel_engine_reset() drops the records of a failed engine reset. amdgpu_userq_pre_reset() drops them too.
The records are kept in a struct of their own in the queue.
The scheduler firmware drops a user queue even when unmapping it fails. Track that, and don't unmap such a queue again.
The caller of an engine reset holds the userq_engine_reset_sem of the engine for write.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 110 +++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 18 ++++ drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 2 + 3 files changed, 130 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +110 -0
@@ -1613,6 +1613,13 @@ amdgpu_userq_next_of_type(struct amdgpu_device *adev, unsigned long *index,return queue; } +/** +* amdgpu_userq_pre_reset - unmap the user queues for a full reset +* @adev: amdgpu device +* +* The queues stay hung until amdgpu_userq_post_reset(), which maps them again +* if VRAM survived. +*/ void amdgpu_userq_pre_reset (struct amdgpu_device *adev) {const struct amdgpu_userq_funcs *userq_funcs;
@@ -1621,6 +1628,8 @@ void amdgpu_userq_pre_reset(struct amdgpu_device *adev)/* TODO: We probably need a new lock for the queue state */ xa_for_each (&adev->userq_doorbell_xa, queue_id, queue) { +/* Drop what a failed engine reset left behind. */ +memset (&queue->engine_reset,0 ,sizeof (queue->engine_reset));if (queue->state ==AMDGPU_USERQ_STATE_MAPPED ) {trace_amdgpu_userq_state_start (queue); userq_funcs = adev->userq_funcs[queue->queue_type];
@@ -1670,3 +1679,104 @@ int amdgpu_userq_post_reset(struct amdgpu_device *adev, bool vram_lost)return ret; } + +/** +* amdgpu_userq_pre_engine_reset - prepare the user queues for an engine reset +* @adev: amdgpu device +* @queue_type: AMDGPU_HW_IP_* type of the queues on the reset engine +* +* Call it before the reset, for amdgpu_userq_post_engine_reset() after it. +* The queues stay hung until then. +* +* The firmware can't unmap the queues of a hung engine, and the reset clears +* the state of the mapped and the preempted ones: they are dropped, and +* unmapped after the reset. A queue that was already unmapped, eg. evicted, +* is dropped too: mapping it again later would resume its work across the +* reset. The caller holds the userq_engine_reset_sem of the engine for write. +*/ +void amdgpu_userq_pre_engine_reset (struct amdgpu_device *adev,u32 queue_type) +{ +struct amdgpu_usermode_queue *queue; +unsigned long queue_id; + +for_each_userq_of_type (adev, queue_id, queue, queue_type) { +struct amdgpu_userq_engine_reset *er = &queue->engine_reset; + +/* The queue is reset with the engine, don't reset it again. */ +cancel_delayed_work (&queue->hang_detect_work); + +if (queue->state ==AMDGPU_USERQ_STATE_MAPPED || + queue->state ==AMDGPU_USERQ_STATE_PREEMPTED ) { +trace_amdgpu_userq_state_start (queue); + er->unmap = true; +trace_amdgpu_userq_state_changed (queue,AMDGPU_USERQ_STATE_HUNG ); + queue->state =AMDGPU_USERQ_STATE_HUNG ; + }else if (queue->state ==AMDGPU_USERQ_STATE_UNMAPPED ) { +/* +* Unmapped before the reset, eg. evicted: mapping it +* again later would resume its work across the reset. +*/ +trace_amdgpu_userq_state_changed (queue,AMDGPU_USERQ_STATE_HUNG ); + queue->state =AMDGPU_USERQ_STATE_HUNG ; + } + } +} + +/** +* amdgpu_userq_post_engine_reset - recover the user queues after an engine reset +* @adev: amdgpu device +* @queue_type: AMDGPU_HW_IP_* type of the queues on the reset engine +* +* Call it after the reset, before the scheduler firmware resumes the queues +* of the engine: it would resume them from a state that didn't survive the +* reset. Unmap the queues the reset left mapped, and signal the fences of +* the dropped queues. +* +* Returns an error if a step failed for a queue: the caller then falls back +* to a full reset. +*/ +int amdgpu_userq_post_engine_reset (struct amdgpu_device *adev,u32 queue_type) +{ +const struct amdgpu_userq_funcs *userq_funcs; +struct amdgpu_usermode_queue *queue; +unsigned long queue_id; +int ret =0 , r; + +for_each_userq_of_type (adev, queue_id, queue, queue_type) { +struct amdgpu_userq_engine_reset er = queue->engine_reset; + +memset (&queue->engine_reset,0 ,sizeof (queue->engine_reset)); +if (queue->state !=AMDGPU_USERQ_STATE_HUNG ) +continue ; + + userq_funcs = adev->userq_funcs[queue->queue_type]; +/* Not mapped in the firmware since a failed unmap. */ +if (er.unmap && !queue->unmap_failed) { + r = userq_funcs->unmap (queue); +if (r) + ret = r; + } + +amdgpu_userq_fence_driver_force_completion (queue); + } + +return ret; +} + +/** +* amdgpu_userq_cancel_engine_reset - drop the records of a failed engine reset +* @adev: amdgpu device +* @queue_type: AMDGPU_HW_IP_* type of the queues on the reset engine +* +* The queues amdgpu_userq_pre_engine_reset() prepared stay hung, for the +* full reset that follows to handle them. +*/ +void amdgpu_userq_cancel_engine_reset (struct amdgpu_device *adev, +u32 queue_type) +{ +struct amdgpu_usermode_queue *queue; +unsigned long queue_id; + +for_each_userq_of_type (adev, queue_id, queue, queue_type) +memset (&queue->engine_reset,0 ,sizeof (queue->engine_reset)); +}
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +18 -0
@@ -89,6 +89,20 @@ struct amdgpu_usermode_queue {struct delayed_work hang_detect_work;struct kref refcount; +/** +* @unmap_failed: +* +* The scheduler firmware drops a user queue even when unmapping it +* fails: it isn't mapped there until it is mapped again. +*/ +bool unmap_failed; + +/** @engine_reset: what an engine reset recorded to recover the queue */ +struct amdgpu_userq_engine_reset { +/* left mapped by the reset: unmap it after */ +bool unmap; + } engine_reset; + union { struct { u64 queue_rb;
@@ -189,6 +203,10 @@ amdgpu_userq_next_of_type(struct amdgpu_device *adev, unsigned long *index, index++)void amdgpu_userq_pre_reset (struct amdgpu_device *adev);int amdgpu_userq_post_reset (struct amdgpu_device *adev,bool vram_lost); +void amdgpu_userq_pre_engine_reset (struct amdgpu_device *adev,u32 queue_type); +int amdgpu_userq_post_engine_reset (struct amdgpu_device *adev,u32 queue_type); +void amdgpu_userq_cancel_engine_reset (struct amdgpu_device *adev, +u32 queue_type);void amdgpu_userq_start_hang_detect_work (struct amdgpu_usermode_queue *queue);void amdgpu_userq_process_fence_irq (struct amdgpu_device *adev,u32 doorbell);
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2 -0
@@ -176,6 +176,7 @@ static int mes_userq_map(struct amdgpu_usermode_queue *queue)DRM_ERROR ("Failed to map queue in HW, err (%d)\n" , r);return r; } + queue->unmap_failed = false;amdgpu_mes_userq_queue_mapped (adev);
@@ -203,6 +204,7 @@ static int mes_userq_unmap(struct amdgpu_usermode_queue *queue)amdgpu_mes_unlock (&adev->mes);if (mes->use_rs64mem)amdgpu_mes_free_gang_ctx_index (mes, queue->gang_ctx_array_index); + queue->unmap_failed = !!r;if (r) {DRM_ERROR ("Failed to unmap queue in HW, err (%d)\n" , r);return r;
Signature · 1 line
2.50.1
PATCH 7/13 drm/amdgpu/gfx: add a gfx engine reset helper
In reply to Jesse ZhangAdd amdgpu_gfx_reset_gfx_engine() around the reset_engine callback, and AMDGPU_RESET_TYPE_PER_ENGINE for a reset of a single engine of an IP block, eg. only the graphics engine of the GFX IP, that leaves its other engines running. The helper only resets the engine when the IP reports that reset type, which none does yet.
As for a pipe reset, the other kernel gfx rings are backed up, tested and replayed, and MES is suspended across the reset, so that it doesn't schedule the queues of the compute engine meanwhile. Their work is only paused.
MES fetches its commands through the CP front-end though. A gfx stream stuck in the front-end, eg. on a packet that runs past the end of its IB, can keep MES from completing the suspend. MES responds again once the CPF/CPG reset freed the front-end, so reset the engine anyway. MES then runs the commands it was stuck on right away, while the engine
restarts: it maps gfx queues on the HQDs the reset just cleared, which the PFP no longer dequeues, and the kernel gfx queue and the user queues couldn't be unmapped anymore. Once MES responds, suspend it again and reset the engine once more, which clears those HQDs too.
It only takes the reset domain for read. That keeps full resets away while the compute engine keeps working. KFD, for example, adds and removes MES queues only after a read trylock of the reset domain, and taking it for write would fail those calls with -EIO.
The reset also clears the HQDs of the gfx user queues, and MES would resume them from there. Hold the gfx engine's userq_engine_reset_sem for write once the schedulers of the kernel gfx rings stopped and until before the ring tests and the replay: with enforced isolation, a job submission preempts the user queues, which takes it for read. Call amdgpu_userq_pre_engine_reset() for the gfx queues before the reset, and amdgpu_userq_post_engine_reset() after it, before MES resumes. If a queue can't be recovered, the engine reset fails and a full reset follows; amdgpu_userq_cancel_engine_reset() drops what the reset recorded for it.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 103 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 3 + 3 files changed, 107 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -309,6 +309,7 @@ extern uint amdgpu_hdmi_hpd_debounce_delay_ms;#define AMDGPU_RESET_TYPE_PER_QUEUE (1 << 2)/* per queue */ #define AMDGPU_RESET_TYPE_PER_PIPE (1 << 3)/* per pipe */ #define AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESET (1 << 4)/* soft-resets an IP block */ +#define AMDGPU_RESET_TYPE_PER_ENGINE (1 << 5)/* resets the engine of one ring type */ /* max cursor sizes (in pixels) */ #define CIK_CURSOR_WIDTH 128
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +103 -0
109 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +3 -0
@@ -732,6 +732,9 @@ int amdgpu_gfx_reset_mes_gfx(struct amdgpu_device *adev,struct amdgpu_fence *guilty_fence, struct amdgpu_usermode_queue *queue, unsigned int vmid, bool use_mmio); +int amdgpu_gfx_reset_gfx_engine (struct amdgpu_device *adev, +struct amdgpu_ring *guilty_ring, +struct amdgpu_fence *guilty_fence);static inline const char *amdgpu_gfx_compute_mode_desc (int mode) {
Signature · 1 line
2.50.1
PATCH 8/13 drm/amdgpu/gfx: reset the gfx engine when a kernel gfx queue reset fails
In reply to Jesse ZhangWhen neither the queue nor the pipe reset recovered a kernel gfx queue, amdgpu_gfx_mes_reset_queue() now falls back to a gfx engine reset, if the IP supports it. The pipe reset already escalates there, so the job timeout handler doesn't change.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +10 -5
@@ -2295,13 +2295,18 @@ int amdgpu_gfx_mes_reset_queue(struct amdgpu_ring *ring,if (!amdgpu_gfx_me_pipe_reset_supported (adev)) { r =amdgpu_gfx_mes_reset_queue_start (ring, vmid, timedout_fence, use_mmio); -if (r) -return r; -return amdgpu_ring_reset_helper_end (ring, timedout_fence); +if (!r) + r =amdgpu_ring_reset_helper_end (ring, timedout_fence); + }else { + r =amdgpu_gfx_reset_mes_gfx (adev, ring, timedout_fence,NULL , + vmid, use_mmio); } -return amdgpu_gfx_reset_mes_gfx (adev, ring, timedout_fence,NULL , vmid, - use_mmio); +/* Neither the queue nor the pipe reset recovered it: try the engine. */ +if (r && ring->funcs->type ==AMDGPU_RING_TYPE_GFX && + adev->gfx.funcs->reset_engine) + r =amdgpu_gfx_reset_gfx_engine (adev, ring, timedout_fence); +return r; } static DEVICE_ATTR(run_cleaner_shader, 0200,
Signature · 1 line
2.50.1
PATCH 9/13 drm/amdgpu/userq: reset the gfx engine when a gfx user queue reset fails
In reply to Jesse ZhangWhen neither the queue nor the pipe reset recovered a gfx user queue, fall back to a gfx engine reset before a full reset, as for the kernel gfx queues.
The hung queue can't be unmapped before the reset, so mark it hung first. That keeps amdgpu_userq_pre_engine_reset() from recording it to map it again, and the queue from being mapped again otherwise. Mark it for amdgpu_userq_post_engine_reset() to remove it from MES once the reset cleared its HQD.
--- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 31 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +28 -3
@@ -237,11 +237,28 @@ int mes_userq_reset_hw(struct amdgpu_usermode_queue *queue,return 0 ; } +/* +* Neither the queue nor the pipe reset recovered a gfx user queue: reset the +* gfx engine. The hung queue can't be unmapped before, so drop it, and remove +* it from MES once the reset cleared its HQD. +*/ +static int mes_userq_reset_gfx_engine (struct amdgpu_usermode_queue *queue) +{ +struct amdgpu_device *adev = queue->userq_mgr->adev; + +trace_amdgpu_userq_state_changed (queue,AMDGPU_USERQ_STATE_HUNG ); + queue->state =AMDGPU_USERQ_STATE_HUNG ; + queue->engine_reset.unmap = true; + +return amdgpu_gfx_reset_gfx_engine (adev,NULL ,NULL ); +} +int mes_userq_reset (struct amdgpu_usermode_queue *queue) {struct amdgpu_userq_mgr *uq_mgr = queue->userq_mgr;struct amdgpu_device *adev = uq_mgr->adev;struct mes_reset_queue_input queue_input; +int r;/* already reset by an earlier job's hang-detect; just signal and bail */ if (queue->state ==AMDGPU_USERQ_STATE_HUNG )
@@ -250,8 +267,12 @@ int mes_userq_reset(struct amdgpu_usermode_queue *queue)/* A GFX pipe reset also affects the kernel rings on that pipe. */ if (queue->queue_type ==AMDGPU_HW_IP_GFX && adev->gfx.funcs->detect_hung_queue && -amdgpu_gfx_me_pipe_reset_supported (adev)) -return amdgpu_gfx_reset_mes_gfx (adev,NULL ,NULL , queue,0 , true); +amdgpu_gfx_me_pipe_reset_supported (adev)) { + r =amdgpu_gfx_reset_mes_gfx (adev,NULL ,NULL , queue,0 , true); +if (r && adev->gfx.funcs->reset_engine) + r =mes_userq_reset_gfx_engine (queue); +return r; + }memset (&queue_input,0x0 ,sizeof (struct mes_reset_queue_input )); queue_input.doorbell_offset = queue->doorbell_index;
@@ -279,7 +300,11 @@ int mes_userq_reset(struct amdgpu_usermode_queue *queue) } } -return mes_userq_reset_hw (queue, &queue_input); + r =mes_userq_reset_hw (queue, &queue_input); +if (r && queue->queue_type ==AMDGPU_HW_IP_GFX && + adev->gfx.funcs->reset_engine) + r =mes_userq_reset_gfx_engine (queue); +return r; } int mes_userq_reset_queue(struct amdgpu_device *adev,
Signature · 1 line
2.50.1
PATCH 10/13 drm/amdgpu: show the engine reset in the reset masks
In reply to Jesse ZhangShow AMDGPU_RESET_TYPE_PER_ENGINE as "engine" in the reset mask sysfs files, eg. gfx_reset_mask.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
@@ -6834,6 +6834,9 @@ ssize_t amdgpu_show_reset_mask(char *buf, uint32_t supported_reset)if (supported_reset &AMDGPU_RESET_TYPE_PER_PIPE ) size +=sysfs_emit_at (buf, size,"pipe " ); +if (supported_reset &AMDGPU_RESET_TYPE_PER_ENGINE ) + size +=sysfs_emit_at (buf, size,"engine " ); +if (supported_reset &AMDGPU_RESET_TYPE_FULL ) size +=sysfs_emit_at (buf, size,"full " );
Signature · 1 line
2.50.1
PATCH 11/13 drm/amdgpu: add a debug_mask bit to disable the engine reset
In reply to Jesse ZhangAdd amdgpu.debug_mask=0x4000 to keep the IPs from reporting AMDGPU_RESET_TYPE_PER_ENGINE, eg. to test the recovery without the engine reset.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 6 ++++++ 2 files changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -951,6 +951,7 @@ struct amdgpu_device {bool debug_enable_ce_cs;bool debug_hibernation_thaw_resume_gpu;bool debug_disable_ip_block_soft_reset; +bool debug_disable_engine_reset;/* Protection for the following isolation structure */ struct mutex enforce_isolation_mutex;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +6 -0
@@ -150,6 +150,7 @@ enum AMDGPU_DEBUG_MASK {AMDGPU_DEBUG_HIBERNATION_THAW_RESUME_GPU =BIT (11 ),AMDGPU_DEBUG_DISABLE_IP_BLOCK_SOFT_RESET =BIT (12 ),AMDGPU_DEBUG_SDMA_RB_CMD =BIT (13 ), + AMDGPU_DEBUG_DISABLE_ENGINE_RESET = BIT(14), };unsigned int amdgpu_vram_limit =UINT_MAX ;
@@ -2341,6 +2342,11 @@ static void amdgpu_init_debug_options(struct amdgpu_device *adev) adev->debug_disable_ip_block_soft_reset = true; } +if (amdgpu_debug_mask &AMDGPU_DEBUG_DISABLE_ENGINE_RESET ) { +pr_info ("debug: engine reset disabled\n" ); + adev->debug_disable_engine_reset = true; + } +if (amdgpu_debug_mask &AMDGPU_DEBUG_SDMA_RB_CMD ) {pr_info ("debug: enable SDMA RB command switch\n" ); adev->sdma.sdma_debug = true;
Signature · 1 line
2.50.1
PATCH 12/13 drm/amdgpu/gfx12: enable the gfx engine reset
In reply to Jesse ZhangReport AMDGPU_RESET_TYPE_PER_ENGINE for the graphics engine when the reset_engine callback can be used: with MES and async gfx rings. The reset remaps the kernel gfx queue through MES from its MQD, and without async gfx rings the kernel gfx queue has no MQD. It is programmed through the CP_RB0 registers, which the reset clears. Not on SR-IOV VFs.
The kernel gfx queue and gfx user queue resets then fall back to a gfx engine reset before a full reset.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +15 -0
@@ -274,6 +274,7 @@ static void gfx_v12_0_set_imu_funcs(struct amdgpu_device *adev);static int gfx_v12_0_get_cu_info (struct amdgpu_device *adev,struct amdgpu_cu_info *cu_info);static uint64_t gfx_v12_0_get_gpu_clock_counter (struct amdgpu_device *adev); +static bool gfx_v12_0_engine_reset_supported (struct amdgpu_device *adev);static int gfx_v12_0_reset_engine (struct amdgpu_device *adev,enum amdgpu_gfx_engine engine); static void gfx_v12_0_select_se_sh(struct amdgpu_device *adev, u32 se_num,
@@ -1586,6 +1587,10 @@ static int gfx_v12_0_sw_init(struct amdgpu_ip_block *ip_block)break ; } +if (gfx_v12_0_engine_reset_supported (adev) && + !adev->debug_disable_engine_reset) + adev->gfx.gfx_supported_reset |=AMDGPU_RESET_TYPE_PER_ENGINE ; +if (!adev->enable_mes_kiq) { r =amdgpu_gfx_kiq_init (adev,GFX12_MEC_HPD_SIZE ,0 );if (r) {
@@ -3847,6 +3852,16 @@ static int gfx_v12_0_wait_for_idle(struct amdgpu_ip_block *ip_block)return -ETIMEDOUT ; } +/* +* The gfx engine reset remaps the kernel gfx queue through MES from its MQD. +* Without async gfx rings, the kernel gfx queue has no MQD: it is programmed +* through the CP_RB0 registers, which the reset clears. +*/ +static bool gfx_v12_0_engine_reset_supported (struct amdgpu_device *adev) +{ +return !amdgpu_sriov_vf (adev) && adev->enable_mes && amdgpu_async_gfx_ring; +} +/* The CP DMA and the interfaces its memory requests go through */ #define GFX12_CP_STAT_MEM_BUSY (CP_STAT__DMA_BUSY_MASK | \ CP_STAT__TCIU_BUSY_MASK | \
Signature · 1 line
2.50.1
PATCH 13/13 drm/amdgpu/gfx11: enable the gfx engine reset
In reply to Jesse ZhangReport AMDGPU_RESET_TYPE_PER_ENGINE for the graphics engine when the reset_engine callback can be used: with MES, async gfx rings and the RS64 firmware. The reset restarts PFP and ME from the start of their RS64 firmware, and remaps the kernel gfx queue through MES from its MQD, which the kernel gfx queue only has with async gfx rings. Not on SR-IOV VFs.
The kernel gfx queue and gfx user queue resets then fall back to a gfx engine reset before a full reset.
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +17 -0
@@ -363,6 +363,7 @@ static void gfx_v11_0_ring_invalidate_tlbs(struct amdgpu_ring *ring,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 bool gfx_v11_0_engine_reset_supported (struct amdgpu_device *adev);static int gfx_v11_0_reset_engine (struct amdgpu_device *adev,enum amdgpu_gfx_engine engine); static void gfx_v11_0_update_perf_clk(struct amdgpu_device *adev,
@@ -1937,6 +1938,10 @@ static int gfx_v11_0_sw_init(struct amdgpu_ip_block *ip_block)break ; } +if (gfx_v11_0_engine_reset_supported (adev) && + !adev->debug_disable_engine_reset) + adev->gfx.gfx_supported_reset |=AMDGPU_RESET_TYPE_PER_ENGINE ; +if (!adev->enable_mes_kiq) { r =amdgpu_gfx_kiq_init (adev,GFX11_MEC_HPD_SIZE ,0 );if (r) {
@@ -6919,6 +6924,18 @@ static void gfx_v11_0_emit_mem_sync(struct amdgpu_ring *ring)amdgpu_ring_write (ring, gcr_cntl);/* GCR_CNTL */ } +/* +* The gfx engine reset restarts PFP and ME from the start of their firmware, +* which needs the RS64 firmware, and remaps the kernel gfx queue through MES +* from its MQD. Without async gfx rings, the kernel gfx queue has no MQD: it +* is programmed through the CP_RB0 registers, which the reset clears. +*/ +static bool gfx_v11_0_engine_reset_supported (struct amdgpu_device *adev) +{ +return !amdgpu_sriov_vf (adev) && adev->enable_mes && + amdgpu_async_gfx_ring && adev->gfx.rs64_enable; +} +/* Restart the PFP and ME pipes from the start of their RS64 firmware. */ static void gfx_v11_0_restart_gfx_rs64 (struct amdgpu_device *adev) {
Signature · 1 line
2.50.1