[PATCH] drm/amdgpu: fix memleak of ring sched and fence driver
Christian König
christian.koenig at amd.com
Tue Aug 26 12:10:12 UTC 2025
On 26.08.25 11:25, Lin.Cao wrote:
> commit 4220d2c7c41b ("drm/amdgpu: remove is_mes_queue flag") set
> ring->adev->ring[ring-idx] as NULL at the end of function amdgpu_ring_fini()
That is a bug and should probably be fixed instead of this here.
Regards,
Christian.
> which will cause function amdgpu_fence_driver_sw_fini() skip
> drm_sched_fini() and free fence_drv.fence then cause memory leak.
>
> Release these resource at the beginning of amdgpu_ring_fini() to fix
> this issue.
>
> Fixes: 4220d2c7c41b ("drm/amdgpu: remove is_mes_queue flag")
> Signed-off-by: Lin.Cao <lincao12 at amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
> index 6379bb25bf5c..cf6f19a122df 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
> @@ -406,6 +406,19 @@ void amdgpu_ring_fini(struct amdgpu_ring *ring)
>
> ring->sched.ready = false;
>
> + if (ring->fence_drv.initialized) {
> + int i = 0;
> +
> + if (ring->sched.ops)
> + drm_sched_fini(&ring->sched);
> +
> + for (i = 0; i <= ring->fence_drv.num_fences_mask; ++i)
> + dma_fence_put(ring->fence_drv.fences[i]);
> + kfree(ring->fence_drv.fences);
> + ring->fence_drv.fences = NULL;
> + ring->fence_drv.initialized = false;
> + }
> +
> amdgpu_device_wb_free(ring->adev, ring->rptr_offs);
> amdgpu_device_wb_free(ring->adev, ring->wptr_offs);
>
More information about the amd-gfx
mailing list