amd-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: fix memleak of ring sched and fence driver
@ 2025-08-26  9:25 Lin.Cao
  2025-08-26 12:10 ` Christian König
  0 siblings, 1 reply; 2+ messages in thread
From: Lin.Cao @ 2025-08-26  9:25 UTC (permalink / raw)
  To: amd-gfx; +Cc: Christian König, Deucher Alexander, Lin.Cao

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()
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@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);
 
-- 
2.46.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/amdgpu: fix memleak of ring sched and fence driver
  2025-08-26  9:25 [PATCH] drm/amdgpu: fix memleak of ring sched and fence driver Lin.Cao
@ 2025-08-26 12:10 ` Christian König
  0 siblings, 0 replies; 2+ messages in thread
From: Christian König @ 2025-08-26 12:10 UTC (permalink / raw)
  To: Lin.Cao, amd-gfx; +Cc: Deucher Alexander

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@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);
>  


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-08-26 12:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-26  9:25 [PATCH] drm/amdgpu: fix memleak of ring sched and fence driver Lin.Cao
2025-08-26 12:10 ` Christian König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).