mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/vmwgfx: Reserve the buffer during surface lookup
@ 2026-11-20  3:11 Changyul Lee
  0 siblings, 0 replies; only message in thread
From: Changyul Lee @ 2026-11-20  3:11 UTC (permalink / raw)
  To: Zack Rusin, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter
  Cc: Broadcom internal kernel review list, Maaz Mombasawala,
	Martin Krastev, dri-devel, linux-kernel, Changyul Lee

A GEM reference keeps the buffer alive, but it does not keep its
surfaces alive. vmw_bo_surface() walks the buffer's resource tree
without holding the buffer reservation. A concurrent surface release
can remove and free a surface while the lookup is still using its
tree node. The caller enters its RCU read-side critical section only
after the walk.

Reserve the buffer before calling vmw_bo_surface() and keep it
reserved until the lookup has tried to take a surface reference.
The reservation prevents the surface from being detached during
the lookup, and kref_get_unless_zero() rejects a surface whose
reference count has already reached zero. Assert that the caller
holds the reservation in vmw_bo_surface().

Fixes: d6667f0ddf46 ("drm/vmwgfx: Fix handling of dumb buffers")
Signed-off-by: Changyul Lee <lcy8047@gmail.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.c      | 2 ++
 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
index a6d7156e4281..625c4b33daa2 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
@@ -864,6 +864,8 @@ struct vmw_surface *vmw_bo_surface(struct vmw_bo *vbo)
 	struct vmw_surface *surf = NULL;
 	struct rb_node *rb_itr = vbo->res_tree.rb_node;
 
+	dma_resv_assert_held(vbo->tbo.base.resv);
+
 	if (vbo->is_dumb && vbo->dumb_surface) {
 		res = &vbo->dumb_surface->res;
 		goto out;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
index 3064a2a960e1..13548fdfa84c 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
@@ -877,6 +877,7 @@ vmw_lookup_user_surface_for_buffer(struct vmw_private *vmw, struct vmw_bo *bo,
 	struct vmw_surface *surf;
 	struct ttm_base_object *base;
 
+	ttm_bo_reserve(&bo->tbo, false, false, NULL);
 	surf = vmw_bo_surface(bo);
 	if (surf) {
 		rcu_read_lock();
@@ -891,6 +892,7 @@ vmw_lookup_user_surface_for_buffer(struct vmw_private *vmw, struct vmw_bo *bo,
 		}
 		rcu_read_unlock();
 	}
+	ttm_bo_unreserve(&bo->tbo);
 
 	return user_srf;
 }

base-commit: af1cf92e8617a7f7aa24b415596cbf64b76a12e7
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-20  3:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20  3:11 [PATCH] drm/vmwgfx: Reserve the buffer during surface lookup Changyul Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®