Skip to contentSkip to conversation

drm/vmwgfx: Fix dumb buffer leak

PATCH Superseded Ian Forbes 2 participants 5 messages Jan 17, 2025 – Jan 30, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ian Forbes

author
#0 lore raw

PATCH 1/1 drm/vmwgfx: Fix dumb buffer leak

Fixes d6667f0ddf46 ("drm/vmwgfx: Fix handling of dumb buffers")
---
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.c      | 2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +1 -1
index a0e433fbcba67..491062e1eb981 100644
@@ -73,7 +73,7 @@ static void vmw_bo_free(struct ttm_buffer_object *bo)
 {
 	struct vmw_bo *vbo = to_vmw_bo(&bo->base);
 
-	WARN_ON(vbo->dirty);
+	WARN_ON(vbo->dirty && !vbo->is_dumb);
 	WARN_ON(!RB_EMPTY_ROOT(&vbo->res_tree));
 	vmw_bo_release(vbo);
 	kfree(vbo);
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +1 -0
index 5721c74da3e0b..3210941cca302 100644
@@ -2358,6 +2358,7 @@ int vmw_dumb_create(struct drm_file *file_priv,
 	vbo = res->guest_memory_bo;
 	vbo->is_dumb = true;
 	vbo->dumb_surface = vmw_res_to_srf(res);
+	drm_gem_object_put(&vbo->tbo.base);
 
 err:
 	if (res)
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 34 lines · Ian Forbes
Fixes d6667f0ddf46 ("drm/vmwgfx: Fix handling of dumb buffers")
---
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.c      | 2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +1 -1
index a0e433fbcba67..491062e1eb981 100644
@@ -73,7 +73,7 @@ static void vmw_bo_free(struct ttm_buffer_object *bo)
 {
        struct vmw_bo *vbo = to_vmw_bo(&bo->base);
 
-       WARN_ON(vbo->dirty);
+       WARN_ON(vbo->dirty && !vbo->is_dumb);
        WARN_ON(!RB_EMPTY_ROOT(&vbo->res_tree));
        vmw_bo_release(vbo);
        kfree(vbo);
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +1 -1
index 5721c74da3e0b..3210941cca302 100644
@@ -2358,6 +2358,7 @@ int vmw_dumb_create(struct drm_file *file_priv,
        vbo = res->guest_memory_bo;
        vbo->is_dumb = true;
        vbo->dumb_surface = vmw_res_to_srf(res);
+       drm_gem_object_put(&vbo->tbo.base);
 
 err:
        if (res)
--
Quoted 2 lines

2.34.1

You're going to have to explain that one in the commit message a lot better because as is it doesn't make sense to me. Especially the !vbo->is_dumb in vmw_bo_free.

z

author
#2 lore raw
Quoted 6 lines · Zack Rusin

You're going to have to explain that one in the commit message a lot better because as is it doesn't make sense to me. Especially the !vbo->is_dumb in vmw_bo_free.

z

The dirty tracker is freed later in vmw_bo_release when it's a coherent dumb_buffer.
Alternatively I can move the WARN_ON below vmw_bo_release and remove the is_dumb check.

maintainer
#3 lore raw
Quoted 11 lines · Ian Forbes
Quoted 6 lines · Zack Rusin

You're going to have to explain that one in the commit message a lot better because as is it doesn't make sense to me. Especially the !vbo->is_dumb in vmw_bo_free.

z

The dirty tracker is freed later in vmw_bo_release when it's a coherent dumb_buffer.

Ah, that makes sense. If you could improve the commit message that'd be great (just describe both issues. i.e. the buffer handle being allocated via vmw_gem_object_create_with_handle which create a gem handle that holds the reference and the dirty being explicitly freed for dumb buffers in vmw_bo_release).

If you don't have anything too important on your plate right now maybe you could try to come up with some way of testing the creation/destruction of buffers matches. IGT could technically use the debugfs file that Maaz added that should contain all the buffer stats. Even for the above change it'd be a lot nicer if you could just add to the commit message the debugfs output before and after this change while running gnome or kde that shows the leak has been fixed.

z

author
#4 lore raw
Quoted 16 lines · Zack Rusin

Ah, that makes sense. If you could improve the commit message that'd be great (just describe both issues. i.e. the buffer handle being allocated via vmw_gem_object_create_with_handle which create a gem handle that holds the reference and the dirty being explicitly freed for dumb buffers in vmw_bo_release).

If you don't have anything too important on your plate right now maybe you could try to come up with some way of testing the creation/destruction of buffers matches. IGT could technically use the debugfs file that Maaz added that should contain all the buffer stats. Even for the above change it'd be a lot nicer if you could just add to the commit message the debugfs output before and after this change while running gnome or kde that shows the leak has been fixed.

Quoted 1 line

z

The total number of BOs in use is exposed through /sys/kernel/debug/ttm/buffer_objects.
After shutting down the GUI it should always be 11 for the otable and fbdev allocations.