Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] amdgpu: missing pre-pulse CP_VMID_RESET clear in gfx_v11_0_soft_reset_gfx_cp() - [Medium] amdgpu: gfx_ring[0] left mapped on disable_kq in gfx_v11_0_soft_reset_engine() --
commit 4f83c926ed3d12feae57fed7044a2f21e92280c8 Author: Jesse Zhang <[email protected]> drm/amdgpu/gfx11: add a gfx engine soft reset This commit implements the soft_reset_engine() callback for the graphics engine on GFX11 by resetting CPF/CPG, PFP/ME, and the GFX HQDs, then restarting the kernel and usermode GFX queues. > diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c > b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c > index ecf8a156b7ec4..a0ed3363f84d1 100644 > --- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c > +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c > @@ -6820,6 +6820,132 @@ static void gfx_v11_0_emit_mem_sync(struct > amdgpu_ring *ring) > amdgpu_ring_write(ring, gcr_cntl); /* GCR_CNTL */ > } > > +/* 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) > + > +/* Reset CPF/CPG, PFP/ME and the gfx HQDs, then boot PFP/ME again. */ > +static int gfx_v11_0_soft_reset_gfx_cp(struct amdgpu_device *adev) > +{ > + u32 tmp, cntl, me_cntl; > + int i; > + > + amdgpu_gfx_rlc_enter_safe_mode(adev, 0); > + /* MES fetches its queues through CPF: keep it out of the reset. */ > + amdgpu_mes_lock(&adev->mes); > + > + me_cntl = RREG32_SOC15(GC, 0, regCP_ME_CNTL); > + > + 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); > + > + /* A CP DMA in flight during the reset leaves the ME busy after it. */ > + for (i = 0; i < adev->usec_timeout; i++) { > + if (!(RREG32_SOC15(GC, 0, regCP_STAT) & GFX11_CP_STAT_MEM_BUSY)) > + break; > + udelay(1); > + } > + > + /* GFX_ONLY keeps compute and MES out; CPF alone leaves the stream > stuck. */ > + 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); > + > + 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); > + > + /* The halted PFP stays busy: only wait for the memory requests. */ > + for (i = 0; i < adev->usec_timeout; i++) { > + if (!(RREG32_SOC15(GC, 0, regCP_STAT) & GFX11_CP_STAT_MEM_BUSY)) > + break; > + udelay(1); > + } > + /* A VMID reset the hung PFP didn't handle survives the reset. */ > + WREG32_SOC15(GC, 0, regCP_VMID_RESET, 0); [Severity: Medium] Should regCP_VMID_RESET also be cleared to 0 before asserting SOFT_RESET_CPF and SOFT_RESET_CPG in regGRBM_SOFT_RESET, as gfx_v12_0_soft_reset_gfx_cp() does? When PFP is hung, the preceding per-queue and per-pipe MMIO resets in mes_v11_0_reset_queue_mmio() and mes_v11_0_reset_gfx_pipe_mmio() write a reset request to regCP_VMID_RESET and time out waiting for PFP to clear it. Pulsing regGRBM_SOFT_RESET while that VMID reset is still active can cause the CP soft reset to fail and escalate to a full GPU reset. [ ... ] > +static int gfx_v11_0_soft_reset_engine(struct amdgpu_ip_block *ip_block, > + enum amdgpu_ring_type ring_type, u32 > inst, > + struct amdgpu_usermode_queue > *guilty_queue) > +{ > + struct amdgpu_device *adev = ip_block->adev; > + int i, r; > + > + if (ring_type != AMDGPU_RING_TYPE_GFX || inst) > + return -EOPNOTSUPP; > + > + mutex_lock(&adev->gfx.mec.reset_mutex); > + amdgpu_gfx_off_ctrl(adev, false); > + > + /* A hung gfx stream can keep MES from suspending: reset anyway. */ > + amdgpu_mes_suspend(adev, 0); > + amdgpu_userq_save_hqds(adev, AMDGPU_HW_IP_GFX); > + > + 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)); > + goto fail; > + } > + > + /* The reset cleared the HQD of the kernel gfx queue: map it again. */ > + r = amdgpu_gfx_disable_kgq(adev, 0); > + if (r) > + goto fail; > + 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_v11_0_cp_gfx_start(adev); > + if (r) > + goto fail; > + > + amdgpu_userq_restore_hqds(adev, AMDGPU_HW_IP_GFX, guilty_queue); > + r = amdgpu_mes_resume(adev, 0); [Severity: Medium] Does this leave adev->gfx.gfx_ring[0] mapped on HQD 0 when adev->gfx.disable_kq is true? Unlike GFX12, gfx_v11_0_early_init() keeps adev->gfx.num_gfx_rings = 1 when disable_kq is set so gfx_v11_0_cp_gfx_start() can submit the clear state on gfx_ring[0], while amdgpu_mes_init() gives HQD 0 to MES for user queues. In gfx_v11_0_cp_resume(), the driver drains gfx_ring[0] and unmaps it before user queues run: drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c:gfx_v11_0_cp_resume() { ... if (adev->gfx.disable_kq) { for (i = 0; i < adev->gfx.num_gfx_rings; i++) { ring = &adev->gfx.gfx_ring[i]; /* we don't want to set ring->ready */ r = amdgpu_ring_test_ring(ring); if (r) return r; } amdgpu_gfx_disable_kgq(adev, 0); } ... } Here, gfx_v11_0_soft_reset_engine() calls amdgpu_gfx_disable_kgq() while gfx_ring[0] is already unmapped, then maps gfx_ring[0] and submits the clear state without testing the ring or calling amdgpu_gfx_disable_kgq() afterward, leaving the temporary kernel ring mapped on HQD 0 in conflict with restored MES usermode queues. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=10
