Skip to contentSkip to conversation

drm/amdgpu: fix memleak of ring sched and fence driver

PATCH Superseded Lin.Cao 2 participants 2 messages Aug 26, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Lin.Cao

author
#0 lore raw

PATCH 1/1 drm/amdgpu: fix memleak of ring sched and fence driver

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")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +13 -0
index 6379bb25bf5c..cf6f19a122df 100644
@@ -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);
 
Signature · 1 line
2.46.1
maintainer
#1 lore raw
Quoted 2 lines · 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()

That is a bug and should probably be fixed instead of this here.

Regards,
Christian.

Quoted 36 lines

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")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +13 -0
index 6379bb25bf5c..cf6f19a122df 100644
@@ -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);