[PATCH 1/4] drm/virtio: Fix memory leak during framebuffer destruction.

Damir Shaikhutdinov lost404 at gmail.com
Fri Jul 20 14:11:40 UTC 2018


In function virtio_gpufb_create, a virtio_gpu_object is allocated for
framebuffer using virtio_gpu_alloc_object.

In virtio_gpu_fbdev_destroy, instead of freeing the object, pointer to
it is set to NULL. This leads to memory leak during framebuffer
destruction, which is reported to kmesg with a message like this:

	Memory manager not clean during takedown.

With DRM_DEBUG_MM enabled, following additional information is printed
about the leak:
	node [00100000 + 000001d5]: inserted at
	save_stack.isra.9+0x67/0xc0
	drm_mm_insert_node_in_range+0x325/0x4f0
	drm_vma_offset_add+0x46/0x60
	ttm_bo_init_reserved+0x2c9/0x400
	ttm_bo_init+0x2a/0x80
	virtio_gpu_object_create+0x139/0x180
	virtio_gpu_alloc_object+0x2f/0x60
	virtio_gpufb_create+0xac/0x2a0

Correctly freeing virtio_gpu_object during framebuffer destruction
fixes the issue.

Signed-off-by: Damir Shaikhutdinov <damir.shaikhutdinov at opensynergy.com>
Signed-off-by: Kiran Pawar <kiran.pawar at opensynergy.com>
---
 drivers/gpu/drm/virtio/virtgpu_fb.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_fb.c b/drivers/gpu/drm/virtio/virtgpu_fb.c
index 15d18fd0c64b..10a66a387bfb 100644
--- a/drivers/gpu/drm/virtio/virtgpu_fb.c
+++ b/drivers/gpu/drm/virtio/virtgpu_fb.c
@@ -301,11 +301,14 @@ static int virtio_gpu_fbdev_destroy(struct drm_device *dev,
 
 	drm_fb_helper_unregister_fbi(&vgfbdev->helper);
 
-	if (vgfb->obj)
-		vgfb->obj = NULL;
 	drm_fb_helper_fini(&vgfbdev->helper);
 	drm_framebuffer_cleanup(&vgfb->base);
 
+	if (vgfb->obj) {
+		virtio_gpu_gem_free_object(vgfb->obj);
+		vgfb->obj = NULL;
+	}
+
 	return 0;
 }
 static const struct drm_fb_helper_funcs virtio_gpu_fb_helper_funcs = {
-- 
2.17.1



More information about the dri-devel mailing list