Skip to contentSkip to conversation

drm/vmwgfx: Reserve the buffer during surface lookup

PATCH New Changyul Lee 1 participant 1 message Nov 20

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/vmwgfx: Reserve the buffer during surface lookup

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")
---
 drivers/gpu/drm/vmwgfx/vmwgfx_bo.c      | 2 ++
 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 2 ++
 2 files changed, 4 insertions(+)
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +2 -0
index a6d7156e4281..625c4b33daa2 100644
@@ -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;
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +2 -0
index 3064a2a960e1..13548fdfa84c 100644
@@ -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

Signature · 1 line
2.43.0