Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] drm/amdgpu: user queue race and UAF during gfx_v11_0_soft_reset_engine() - [Medium] drm/amdgpu/gfx11: missing pre-pulse CP_VMID_RESET clear in soft reset - [Medium] drm/amdgpu/gfx11: kernel gfx queue left mapped when disable_kq is true --
commit 37d8357ec5fb17ab702d211aa8fb7b20ac9e9a2a Author: Jesse Zhang <[email protected]> drm/amdgpu/gfx11: enable the gfx engine soft reset This commit enables AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESET for GFX rings on GC 11.5.1 and 11.5.3 when MES is enabled and SR-IOV VF is not active. > diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c > b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c > index 824d7914bece9..a878aaee1b74b 100644 > --- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c > +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c > @@ -1965,6 +1965,13 @@ static int gfx_v11_0_sw_init(struct amdgpu_ip_block > *ip_block) > break; > } > > + /* Only on the GC versions it was verified on */ > + if ((amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(11, 5, 1) || > + amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(11, 5, 3)) && > + !amdgpu_sriov_vf(adev) && adev->enable_mes && > + !adev->debug_disable_ip_block_soft_reset) > + adev->gfx.gfx_supported_reset |= > AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESET; > + > if (!adev->enable_mes_kiq) { > r = amdgpu_gfx_kiq_init(adev, GFX11_MEC_HPD_SIZE, 0); > if (r) { [Severity: High] Can enabling engine soft reset cause a use-after-free on struct amdgpu_usermode_queue in amdgpu_userq_save_hqds() and amdgpu_userq_restore_hqds()? When funcs->soft_reset_engine is set, amdgpu_device_ip_soft_reset() only takes down_read(&adev->reset_domain->sem) before calling gfx_v11_0_soft_reset_engine(). Because amdgpu_userq_detach_doorbell(), amdgpu_userq_unmap_helper(), and amdgpu_userq_map_helper() also only take down_read(&adev->reset_domain->sem), they are not blocked during an engine soft reset. Inside gfx_v11_0_soft_reset_engine(), amdgpu_userq_save_hqds() and amdgpu_userq_restore_hqds() iterate adev->userq_doorbell_xa with xa_for_each() without taking a reference on queue or locking uq_mgr->userq_mutex: CPU0 CPU1 amdgpu_device_ip_soft_reset() down_read(&adev->reset_domain->sem) gfx_v11_0_soft_reset_engine() amdgpu_userq_restore_hqds() xa_for_each(..., queue) amdgpu_userq_destroy() mutex_lock(&uq_mgr->userq_mutex) amdgpu_userq_detach_doorbell() down_read(&reset_domain->sem) xa_erase(&userq_doorbell_xa, ...) ... uq_funcs->mqd_destroy(queue) kfree(queue) userq_funcs->unmap(queue) ... <-- use-after-free Concurrent eviction and restore workers (amdgpu_userq_evict_all() and amdgpu_userq_restore_all()) also only take a read lock on reset_domain->sem, so they can issue MES map/unmap requests and mutate queue->state while MES is suspended and amdgpu_userq_restore_hqds() is updating the queues without uq_mgr->userq_mutex. [Severity: Medium] Should gfx_v11_0_soft_reset_gfx_cp() clear regCP_VMID_RESET before pulsing regGRBM_SOFT_RESET, as gfx_v12_0_soft_reset_gfx_cp() does? drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c:gfx_v11_0_soft_reset_gfx_cp() { ... /* 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); ... } When a prior per-queue or per-pipe reset via mes_v11_0_reset_queue_mmio() times out because PFP or ME is hung, the VMID reset request written to regCP_VMID_RESET remains pending when fallback reaches gfx_v11_0_soft_reset_gfx_cp(). gfx_v11_0_soft_reset_gfx_cp() only zeroes regCP_VMID_RESET after the reset pulse, leaving the VMID reset active during the CP soft reset and causing the soft reset to fail and escalate to a full GPU reset. [Severity: Medium] Does gfx_v11_0_soft_reset_engine() leave the kernel GFX queue mapped when adev->gfx.disable_kq is true? drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c:gfx_v11_0_soft_reset_engine() { ... /* 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); ... } On GFX11, adev->gfx.num_gfx_rings is 1 even when adev->gfx.disable_kq is true so gfx_ring[0] can be used to submit clear-state initialization packets, after which gfx_v11_0_cp_resume() unmaps it via amdgpu_gfx_disable_kgq(adev, 0) so MES can use pipe 0 queue 0 for user queues. When a hung GFX user queue triggers gfx_v11_0_soft_reset_engine() with disable_kq set, gfx_ring[0] is mapped with amdgpu_gfx_enable_kgq() and never unmapped afterward, leaving the legacy kernel queue mapped on pipe 0 queue 0 in conflict with MES user queues. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=15
