Skip to contentSkip to conversation

Finishing drm_exec cleanup

PATCH New Christian König 4 participants 9 messages Apr 24 – Apr 28

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

Hi Zack,

VMWGFX is the only DRM driver who is still using the old ttm_execbuf framework and while going over my TODO branches I've found that I never upstreamed the patches to clean that up and fully move over to drm_exec.

It should be a trivial 1 to 1 replacement now, but I can only compile test it.

There can be more cleanup on top of this, for example as far as I can see vmw_resource_check_buffer() actually doesn't need a ticket. But this isn't the topic of this patch set.

Please let me know what you think since that would allow remove quite a bunch of otherwise unmaintained code.

Thanks,
Christian.

#1 lore raw

PATCH 1/4 drm/vmwgfx: use single locking in vmw_resource_check_buffer

Replacing some unnecessary complex calls with just just single BO dma_resv locking.

No intentional functional change, but only compile tested.

v2: fix kerneldoc issues
v3: rebase on upstream changes

---
 drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 58 ++++++++----------------
 1 file changed, 20 insertions(+), 38 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +20 -38
index 388011696941..1a518ab81b28 100644
@@ -510,17 +510,16 @@ void vmw_resource_unreserve(struct vmw_resource *res,
  * @res:            The resource for which to allocate a backup buffer.
  * @interruptible:  Whether any sleeps during allocation should be
  *                  performed while interruptible.
- * @val_buf:        On successful return contains data about the
- *                  reserved and validated backup buffer.
+ * @bo:             On successful return contains the reserved and validated
+ *                  backup buffer.
  */
 static int
 vmw_resource_check_buffer(struct ww_acquire_ctx *ticket,
 			  struct vmw_resource *res,
 			  bool interruptible,
-			  struct ttm_validate_buffer *val_buf)
+			  struct ttm_buffer_object **bo)
 {
 	struct ttm_operation_ctx ctx = { true, false };
-	struct list_head val_list;
 	bool guest_memory_dirty = false;
 	int ret;
 
@@ -530,12 +529,13 @@ vmw_resource_check_buffer(struct ww_acquire_ctx *ticket,
 			return ret;
 	}
 
-	INIT_LIST_HEAD(&val_list);
-	val_buf->bo = &res->guest_memory_bo->tbo;
-	val_buf->num_shared = 0;
-	drm_gem_object_get(&val_buf->bo->base);
-	list_add_tail(&val_buf->head, &val_list);
-	ret = ttm_eu_reserve_buffers(ticket, &val_list, interruptible, NULL);
+	*bo = &res->guest_memory_bo->tbo;
+	drm_gem_object_get(&(*bo)->base);
+
+	if (ticket)
+		ww_acquire_init(ticket, &reservation_ww_class);
+
+	ret = ttm_bo_reserve(*bo, interruptible, (ticket == NULL), ticket);
 	if (unlikely(ret != 0))
 		goto out_no_reserve;
 
@@ -555,10 +555,12 @@ vmw_resource_check_buffer(struct ww_acquire_ctx *ticket,
 	return 0;
 
 out_no_validate:
-	ttm_eu_backoff_reservation(ticket, &val_list);
+	dma_resv_unlock((*bo)->base.resv);
+	if (ticket)
+		ww_acquire_fini(ticket);
 out_no_reserve:
-	drm_gem_object_put(&val_buf->bo->base);
-	val_buf->bo = NULL;
+	drm_gem_object_put(&(*bo)->base);
+	*bo = NULL;
 	if (guest_memory_dirty)
 		vmw_user_bo_unref(&res->guest_memory_bo);
 
@@ -600,29 +602,6 @@ int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
 	return 0;
 }
 
-/**
- * vmw_resource_backoff_reservation - Unreserve and unreference a
- *                                    guest memory buffer
- *.
- * @ticket:         The ww acquire ctx used for reservation.
- * @val_buf:        Guest memory buffer information.
- */
-static void
-vmw_resource_backoff_reservation(struct ww_acquire_ctx *ticket,
-				 struct ttm_validate_buffer *val_buf)
-{
-	struct list_head val_list;
-
-	if (likely(val_buf->bo == NULL))
-		return;
-
-	INIT_LIST_HEAD(&val_list);
-	list_add_tail(&val_buf->head, &val_list);
-	ttm_eu_backoff_reservation(ticket, &val_list);
-	drm_gem_object_put(&val_buf->bo->base);
-	val_buf->bo = NULL;
-}
-
 /**
  * vmw_resource_do_evict - Evict a resource, and transfer its data
  *                         to a backup buffer.
@@ -642,7 +621,7 @@ static int vmw_resource_do_evict(struct ww_acquire_ctx *ticket,
 
 	val_buf.bo = NULL;
 	val_buf.num_shared = 0;
-	ret = vmw_resource_check_buffer(ticket, res, interruptible, &val_buf);
+	ret = vmw_resource_check_buffer(ticket, res, interruptible, &val_buf.bo);
 	if (unlikely(ret != 0))
 		return ret;
 
@@ -657,7 +636,10 @@ static int vmw_resource_do_evict(struct ww_acquire_ctx *ticket,
 	res->guest_memory_dirty = true;
 	res->res_dirty = false;
 out_no_unbind:
-	vmw_resource_backoff_reservation(ticket, &val_buf);
+	dma_resv_unlock(val_buf.bo->base.resv);
+	if (ticket)
+		ww_acquire_fini(ticket);
+	drm_gem_object_put(&val_buf.bo->base);
 
 	return ret;
 }
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/4 drm/vmwgfx: use the new drm_exec object v3

In reply to Christian König

Basically just switching over to the new infrastructure like we did for all other drivers as well.

No intentional functional change, but only compile tested.

v2: fix kerneldoc issues
v3: use DMA_RESV_USAGE_WRITE instead of _READ

---
 drivers/gpu/drm/vmwgfx/vmwgfx_validation.c | 55 +++++++++++++++++++++-
 drivers/gpu/drm/vmwgfx/vmwgfx_validation.h | 41 ++--------------
 2 files changed, 58 insertions(+), 38 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_validation.c +53 -2
index 35dc94c3db39..1f2d16a5e6a3 100644
@@ -818,6 +818,58 @@ int vmw_validation_preload_res(struct vmw_validation_context *ctx,
 	return 0;
 }
 
+/**
+ * vmw_validation_bo_reserve - Reserve buffer objects registered with a
+ * validation context
+ * @ctx: The validation context
+ * @intr: Perform waits interruptible
+ *
+ * Return: Zero on success, -ERESTARTSYS when interrupted, negative error
+ * code on failure
+ */
+int vmw_validation_bo_reserve(struct vmw_validation_context *ctx, bool intr)
+{
+	struct vmw_validation_bo_node *entry;
+	int ret;
+
+	drm_exec_init(&ctx->exec, intr ? DRM_EXEC_INTERRUPTIBLE_WAIT : 0, 0);
+	drm_exec_until_all_locked(&ctx->exec) {
+		list_for_each_entry(entry, &ctx->bo_list, base.head) {
+			ret = drm_exec_prepare_obj(&ctx->exec,
+						   &entry->base.bo->base, 1);
+			drm_exec_retry_on_contention(&ctx->exec);
+			if (ret)
+				goto error;
+		}
+	}
+	return 0;
+
+error:
+	drm_exec_fini(&ctx->exec);
+	return ret;
+}
+
+/**
+ * vmw_validation_bo_fence - Unreserve and fence buffer objects registered
+ * with a validation context
+ * @ctx: The validation context
+ * @fence: The fence to add
+ *
+ * This function unreserves the buffer objects previously reserved using
+ * vmw_validation_bo_reserve, and fences them with a fence object.
+ */
+void vmw_validation_bo_fence(struct vmw_validation_context *ctx,
+			     struct vmw_fence_obj *fence)
+{
+	struct vmw_validation_bo_node *entry;
+
+	list_for_each_entry(entry, &ctx->bo_list, base.head) {
+		dma_resv_add_fence(entry->base.bo->base.resv, &fence->base,
+				   DMA_RESV_USAGE_WRITE);
+	}
+	drm_exec_fini(&ctx->exec);
+}
+
 /**
  * vmw_validation_bo_backoff - Unreserve buffer objects registered with a
  * validation context
@@ -843,6 +895,5 @@ void vmw_validation_bo_backoff(struct vmw_validation_context *ctx)
 				vmw_bo_dirty_release(vbo);
 		}
 	}
-
-	ttm_eu_backoff_reservation(&ctx->ticket, &ctx->bo_list);
+	drm_exec_fini(&ctx->exec);
 }
drivers/gpu/drm/vmwgfx/vmwgfx_validation.h +5 -36

65 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw

PATCH 3/4 drm/vmwgfx: replace ttm_validate_buffer with separate struct

In reply to Christian König

Finish removing the ttm_exec_buf dependency.

No intentional functional change, but only compile tested.

---
 drivers/gpu/drm/vmwgfx/vmwgfx_context.c       | 16 ++++++-------
 drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c       | 12 +++++-----
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h           |  1 -
 drivers/gpu/drm/vmwgfx/vmwgfx_resource.c      | 14 ++++-------
 drivers/gpu/drm/vmwgfx/vmwgfx_resource_priv.h |  4 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_shader.c        | 16 ++++++-------
 drivers/gpu/drm/vmwgfx/vmwgfx_streamoutput.c  |  8 +++----
 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c       | 24 +++++++++----------
 drivers/gpu/drm/vmwgfx/vmwgfx_validation.c    |  5 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_validation.h    | 10 ++++++++
 10 files changed, 57 insertions(+), 53 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_context.c +8 -8
index bd96f4d5e090..15b8378f81a1 100644
@@ -48,17 +48,17 @@ vmw_user_context_base_to_res(struct ttm_base_object *base);
 
 static int vmw_gb_context_create(struct vmw_resource *res);
 static int vmw_gb_context_bind(struct vmw_resource *res,
-			       struct ttm_validate_buffer *val_buf);
+			       struct vmw_validate_buffer *val_buf);
 static int vmw_gb_context_unbind(struct vmw_resource *res,
 				 bool readback,
-				 struct ttm_validate_buffer *val_buf);
+				 struct vmw_validate_buffer *val_buf);
 static int vmw_gb_context_destroy(struct vmw_resource *res);
 static int vmw_dx_context_create(struct vmw_resource *res);
 static int vmw_dx_context_bind(struct vmw_resource *res,
-			       struct ttm_validate_buffer *val_buf);
+			       struct vmw_validate_buffer *val_buf);
 static int vmw_dx_context_unbind(struct vmw_resource *res,
 				 bool readback,
-				 struct ttm_validate_buffer *val_buf);
+				 struct vmw_validate_buffer *val_buf);
 static int vmw_dx_context_destroy(struct vmw_resource *res);
 
 static const struct vmw_user_resource_conv user_context_conv = {
@@ -339,7 +339,7 @@ static int vmw_gb_context_create(struct vmw_resource *res)
 }
 
 static int vmw_gb_context_bind(struct vmw_resource *res,
-			       struct ttm_validate_buffer *val_buf)
+			       struct vmw_validate_buffer *val_buf)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
 	struct {
@@ -367,7 +367,7 @@ static int vmw_gb_context_bind(struct vmw_resource *res,
 
 static int vmw_gb_context_unbind(struct vmw_resource *res,
 				 bool readback,
-				 struct ttm_validate_buffer *val_buf)
+				 struct vmw_validate_buffer *val_buf)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
 	struct ttm_buffer_object *bo = val_buf->bo;
@@ -506,7 +506,7 @@ static int vmw_dx_context_create(struct vmw_resource *res)
 }
 
 static int vmw_dx_context_bind(struct vmw_resource *res,
-			       struct ttm_validate_buffer *val_buf)
+			       struct vmw_validate_buffer *val_buf)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
 	struct {
@@ -576,7 +576,7 @@ void vmw_dx_context_scrub_cotables(struct vmw_resource *ctx,
 
 static int vmw_dx_context_unbind(struct vmw_resource *res,
 				 bool readback,
-				 struct ttm_validate_buffer *val_buf)
+				 struct vmw_validate_buffer *val_buf)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
 	struct ttm_buffer_object *bo = val_buf->bo;
drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c +6 -6
index 091f1039a052..19108c9be75b 100644
@@ -122,10 +122,10 @@ const SVGACOTableType vmw_cotable_scrub_order[] = {
 };
 
 static int vmw_cotable_bind(struct vmw_resource *res,
-			    struct ttm_validate_buffer *val_buf);
+			    struct vmw_validate_buffer *val_buf);
 static int vmw_cotable_unbind(struct vmw_resource *res,
 			      bool readback,
-			      struct ttm_validate_buffer *val_buf);
+			      struct vmw_validate_buffer *val_buf);
 static int vmw_cotable_create(struct vmw_resource *res);
 static int vmw_cotable_destroy(struct vmw_resource *res);
 
@@ -214,14 +214,14 @@ static int vmw_cotable_unscrub(struct vmw_resource *res)
  * vmw_cotable_bind - Undo a cotable unscrub operation
  *
  * @res: Pointer to the cotable resource
- * @val_buf: Pointer to a struct ttm_validate_buffer prepared by the caller
+ * @val_buf: Pointer to a struct vmw_validate_buffer prepared by the caller
  * for convenience / fencing.
  *
  * This function issues commands to (re)bind the cotable to
  * its backing mob, which needs to be validated and reserved at this point.
  */
 static int vmw_cotable_bind(struct vmw_resource *res,
-			    struct ttm_validate_buffer *val_buf)
+			    struct vmw_validate_buffer *val_buf)
 {
 	/*
 	 * The create() callback may have changed @res->backup without
@@ -313,14 +313,14 @@ int vmw_cotable_scrub(struct vmw_resource *res, bool readback)
  *
  * @res: Pointer to the cotable resource.
  * @readback: Whether to read back cotable data to the backup buffer.
- * @val_buf: Pointer to a struct ttm_validate_buffer prepared by the caller
+ * @val_buf: Pointer to a struct vmw_validate_buffer prepared by the caller
  * for convenience / fencing.
  *
  * Unbinds the cotable from the device and fences the backup buffer.
  */
 static int vmw_cotable_unbind(struct vmw_resource *res,
 			      bool readback,
-			      struct ttm_validate_buffer *val_buf)
+			      struct vmw_validate_buffer *val_buf)
 {
 	struct vmw_cotable *vcotbl = vmw_cotable(res);
 	struct vmw_private *dev_priv = res->dev_priv;
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +0 -1
index 57465f69c687..622b924472bf 100644
@@ -19,7 +19,6 @@
 #include <drm/drm_print.h>
 #include <drm/drm_rect.h>
 
-#include <drm/ttm/ttm_execbuf_util.h>
 #include <drm/ttm/ttm_tt.h>
 #include <drm/ttm/ttm_placement.h>
 #include <drm/ttm/ttm_bo.h>
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +5 -9
index 1a518ab81b28..79e53e39644d 100644
@@ -130,10 +130,9 @@ static void vmw_resource_release(struct kref *kref)
 		BUG_ON(ret);
 		if (vmw_resource_mob_attached(res) &&
 		    res->func->unbind != NULL) {
-			struct ttm_validate_buffer val_buf;
+			struct vmw_validate_buffer val_buf;
 
 			val_buf.bo = bo;
-			val_buf.num_shared = 0;
 			res->func->unbind(res, false, &val_buf);
 		}
 		res->guest_memory_size = false;
@@ -370,7 +369,7 @@ static int vmw_resource_buf_alloc(struct vmw_resource *res,
  * should be retried once resources have been freed up.
  */
 static int vmw_resource_do_validate(struct vmw_resource *res,
-				    struct ttm_validate_buffer *val_buf,
+				    struct vmw_validate_buffer *val_buf,
 				    bool dirtying)
 {
 	int ret = 0;
@@ -613,14 +612,13 @@ int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
 static int vmw_resource_do_evict(struct ww_acquire_ctx *ticket,
 				 struct vmw_resource *res, bool interruptible)
 {
-	struct ttm_validate_buffer val_buf;
+	struct vmw_validate_buffer val_buf;
 	const struct vmw_res_func *func = res->func;
 	int ret;
 
 	BUG_ON(!func->may_evict);
 
 	val_buf.bo = NULL;
-	val_buf.num_shared = 0;
 	ret = vmw_resource_check_buffer(ticket, res, interruptible, &val_buf.bo);
 	if (unlikely(ret != 0))
 		return ret;
@@ -667,14 +665,13 @@ int vmw_resource_validate(struct vmw_resource *res, bool intr,
 	struct vmw_resource *evict_res;
 	struct vmw_private *dev_priv = res->dev_priv;
 	struct list_head *lru_list = &dev_priv->res_lru[res->func->res_type];
-	struct ttm_validate_buffer val_buf;
+	struct vmw_validate_buffer val_buf;
 	unsigned err_count = 0;
 
 	if (!res->func->create)
 		return 0;
 
 	val_buf.bo = NULL;
-	val_buf.num_shared = 0;
 	if (res->guest_memory_bo)
 		val_buf.bo = &res->guest_memory_bo->tbo;
 	do {
@@ -741,9 +738,8 @@ int vmw_resource_validate(struct vmw_resource *res, bool intr,
  */
 void vmw_resource_unbind_list(struct vmw_bo *vbo)
 {
-	struct ttm_validate_buffer val_buf = {
+	struct vmw_validate_buffer val_buf = {
 		.bo = &vbo->tbo,
-		.num_shared = 0
 	};
 
 	dma_resv_assert_held(vbo->tbo.base.resv);
drivers/gpu/drm/vmwgfx/vmwgfx_resource_priv.h +2 -2
index aa7cbd396bea..ac2ea9d688c1 100644
@@ -93,10 +93,10 @@ struct vmw_res_func {
 	int (*create) (struct vmw_resource *res);
 	int (*destroy) (struct vmw_resource *res);
 	int (*bind) (struct vmw_resource *res,
-		     struct ttm_validate_buffer *val_buf);
+		     struct vmw_validate_buffer *val_buf);
 	int (*unbind) (struct vmw_resource *res,
 		       bool readback,
-		       struct ttm_validate_buffer *val_buf);
+		       struct vmw_validate_buffer *val_buf);
 	void (*commit_notify)(struct vmw_resource *res,
 			      enum vmw_cmdbuf_res_state state);
 	int (*dirty_alloc)(struct vmw_resource *res);
drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +8 -8
index eca4e3e97eb4..dc6bce2d3283 100644
@@ -60,18 +60,18 @@ vmw_user_shader_base_to_res(struct ttm_base_object *base);
 
 static int vmw_gb_shader_create(struct vmw_resource *res);
 static int vmw_gb_shader_bind(struct vmw_resource *res,
-			       struct ttm_validate_buffer *val_buf);
+			       struct vmw_validate_buffer *val_buf);
 static int vmw_gb_shader_unbind(struct vmw_resource *res,
 				 bool readback,
-				 struct ttm_validate_buffer *val_buf);
+				 struct vmw_validate_buffer *val_buf);
 static int vmw_gb_shader_destroy(struct vmw_resource *res);
 
 static int vmw_dx_shader_create(struct vmw_resource *res);
 static int vmw_dx_shader_bind(struct vmw_resource *res,
-			       struct ttm_validate_buffer *val_buf);
+			       struct vmw_validate_buffer *val_buf);
 static int vmw_dx_shader_unbind(struct vmw_resource *res,
 				 bool readback,
-				 struct ttm_validate_buffer *val_buf);
+				 struct vmw_validate_buffer *val_buf);
 static void vmw_dx_shader_commit_notify(struct vmw_resource *res,
 					enum vmw_cmdbuf_res_state state);
 static bool vmw_shader_id_ok(u32 user_key, SVGA3dShaderType shader_type);
@@ -243,7 +243,7 @@ static int vmw_gb_shader_create(struct vmw_resource *res)
 }
 
 static int vmw_gb_shader_bind(struct vmw_resource *res,
-			      struct ttm_validate_buffer *val_buf)
+			      struct vmw_validate_buffer *val_buf)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
 	struct {
@@ -271,7 +271,7 @@ static int vmw_gb_shader_bind(struct vmw_resource *res,
 
 static int vmw_gb_shader_unbind(struct vmw_resource *res,
 				bool readback,
-				struct ttm_validate_buffer *val_buf)
+				struct vmw_validate_buffer *val_buf)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
 	struct {
@@ -443,7 +443,7 @@ static int vmw_dx_shader_create(struct vmw_resource *res)
  *
  */
 static int vmw_dx_shader_bind(struct vmw_resource *res,
-			      struct ttm_validate_buffer *val_buf)
+			      struct vmw_validate_buffer *val_buf)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
 	struct ttm_buffer_object *bo = val_buf->bo;
@@ -505,7 +505,7 @@ static int vmw_dx_shader_scrub(struct vmw_resource *res)
  */
 static int vmw_dx_shader_unbind(struct vmw_resource *res,
 				bool readback,
-				struct ttm_validate_buffer *val_buf)
+				struct vmw_validate_buffer *val_buf)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
 	struct vmw_fence_obj *fence;
drivers/gpu/drm/vmwgfx/vmwgfx_streamoutput.c +4 -4
index 52c6cfa163da..e66479cc14f7 100644
@@ -55,9 +55,9 @@ struct vmw_dx_streamoutput {
 
 static int vmw_dx_streamoutput_create(struct vmw_resource *res);
 static int vmw_dx_streamoutput_bind(struct vmw_resource *res,
-				    struct ttm_validate_buffer *val_buf);
+				    struct vmw_validate_buffer *val_buf);
 static int vmw_dx_streamoutput_unbind(struct vmw_resource *res, bool readback,
-				      struct ttm_validate_buffer *val_buf);
+				      struct vmw_validate_buffer *val_buf);
 static void vmw_dx_streamoutput_commit_notify(struct vmw_resource *res,
 					      enum vmw_cmdbuf_res_state state);
 
@@ -136,7 +136,7 @@ static int vmw_dx_streamoutput_create(struct vmw_resource *res)
 }
 
 static int vmw_dx_streamoutput_bind(struct vmw_resource *res,
-				    struct ttm_validate_buffer *val_buf)
+				    struct vmw_validate_buffer *val_buf)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
 	struct ttm_buffer_object *bo = val_buf->bo;
@@ -191,7 +191,7 @@ static int vmw_dx_streamoutput_scrub(struct vmw_resource *res)
 }
 
 static int vmw_dx_streamoutput_unbind(struct vmw_resource *res, bool readback,
-				      struct ttm_validate_buffer *val_buf)
+				      struct vmw_validate_buffer *val_buf)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
 	struct vmw_fence_obj *fence;
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +12 -12
index b2d3927b5567..aa76e426e3fa 100644
@@ -63,18 +63,18 @@ static void vmw_user_surface_free(struct vmw_resource *res);
 static struct vmw_resource *
 vmw_user_surface_base_to_res(struct ttm_base_object *base);
 static int vmw_legacy_srf_bind(struct vmw_resource *res,
-			       struct ttm_validate_buffer *val_buf);
+			       struct vmw_validate_buffer *val_buf);
 static int vmw_legacy_srf_unbind(struct vmw_resource *res,
 				 bool readback,
-				 struct ttm_validate_buffer *val_buf);
+				 struct vmw_validate_buffer *val_buf);
 static int vmw_legacy_srf_create(struct vmw_resource *res);
 static int vmw_legacy_srf_destroy(struct vmw_resource *res);
 static int vmw_gb_surface_create(struct vmw_resource *res);
 static int vmw_gb_surface_bind(struct vmw_resource *res,
-			       struct ttm_validate_buffer *val_buf);
+			       struct vmw_validate_buffer *val_buf);
 static int vmw_gb_surface_unbind(struct vmw_resource *res,
 				 bool readback,
-				 struct ttm_validate_buffer *val_buf);
+				 struct vmw_validate_buffer *val_buf);
 static int vmw_gb_surface_destroy(struct vmw_resource *res);
 static int
 vmw_gb_surface_define_internal(struct drm_device *dev,
@@ -443,7 +443,7 @@ static int vmw_legacy_srf_create(struct vmw_resource *res)
  *
  * @res:            Pointer to a struct vmw_res embedded in a struct
  *                  vmw_surface.
- * @val_buf:        Pointer to a struct ttm_validate_buffer containing
+ * @val_buf:        Pointer to a struct vmw_validate_buffer containing
  *                  information about the backup buffer.
  * @bind:           Boolean wether to DMA to the surface.
  *
@@ -455,7 +455,7 @@ static int vmw_legacy_srf_create(struct vmw_resource *res)
  * will also be returned reserved iff @bind is true.
  */
 static int vmw_legacy_srf_dma(struct vmw_resource *res,
-			      struct ttm_validate_buffer *val_buf,
+			      struct vmw_validate_buffer *val_buf,
 			      bool bind)
 {
 	SVGAGuestPtr ptr;
@@ -497,14 +497,14 @@ static int vmw_legacy_srf_dma(struct vmw_resource *res,
  *
  * @res:            Pointer to a struct vmw_res embedded in a struct
  *                  vmw_surface.
- * @val_buf:        Pointer to a struct ttm_validate_buffer containing
+ * @val_buf:        Pointer to a struct vmw_validate_buffer containing
  *                  information about the backup buffer.
  *
  * This function will copy backup data to the surface if the
  * backup buffer is dirty.
  */
 static int vmw_legacy_srf_bind(struct vmw_resource *res,
-			       struct ttm_validate_buffer *val_buf)
+			       struct vmw_validate_buffer *val_buf)
 {
 	if (!res->guest_memory_dirty)
 		return 0;
@@ -520,14 +520,14 @@ static int vmw_legacy_srf_bind(struct vmw_resource *res,
  * @res:            Pointer to a struct vmw_res embedded in a struct
  *                  vmw_surface.
  * @readback:       Readback - only true if dirty
- * @val_buf:        Pointer to a struct ttm_validate_buffer containing
+ * @val_buf:        Pointer to a struct vmw_validate_buffer containing
  *                  information about the backup buffer.
  *
  * This function will copy backup data from the surface.
  */
 static int vmw_legacy_srf_unbind(struct vmw_resource *res,
 				 bool readback,
-				 struct ttm_validate_buffer *val_buf)
+				 struct vmw_validate_buffer *val_buf)
 {
 	if (unlikely(readback))
 		return vmw_legacy_srf_dma(res, val_buf, false);
@@ -1254,7 +1254,7 @@ static int vmw_gb_surface_create(struct vmw_resource *res)
 
 
 static int vmw_gb_surface_bind(struct vmw_resource *res,
-			       struct ttm_validate_buffer *val_buf)
+			       struct vmw_validate_buffer *val_buf)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
 	struct {
@@ -1300,7 +1300,7 @@ static int vmw_gb_surface_bind(struct vmw_resource *res,
 
 static int vmw_gb_surface_unbind(struct vmw_resource *res,
 				 bool readback,
-				 struct ttm_validate_buffer *val_buf)
+				 struct vmw_validate_buffer *val_buf)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
 	struct ttm_buffer_object *bo = val_buf->bo;
drivers/gpu/drm/vmwgfx/vmwgfx_validation.c +2 -3
index 1f2d16a5e6a3..98aa8deed98b 100644
@@ -43,7 +43,7 @@
  * large numbers and space conservation is desired.
  */
 struct vmw_validation_bo_node {
-	struct ttm_validate_buffer base;
+	struct vmw_validate_buffer base;
 	struct vmwgfx_hash_item hash;
 	unsigned int coherent_count;
 };
@@ -250,7 +250,7 @@ int vmw_validation_add_bo(struct vmw_validation_context *ctx,
 
 	bo_node = vmw_validation_find_bo_dup(ctx, vbo);
 	if (!bo_node) {
-		struct ttm_validate_buffer *val_buf;
+		struct vmw_validate_buffer *val_buf;
 
 		bo_node = vmw_validation_mem_alloc(ctx, sizeof(*bo_node));
 		if (!bo_node)
@@ -264,7 +264,6 @@ int vmw_validation_add_bo(struct vmw_validation_context *ctx,
 		val_buf = &bo_node->base;
 		vmw_bo_reference(vbo);
 		val_buf->bo = &vbo->tbo;
-		val_buf->num_shared = 0;
 		list_add_tail(&val_buf->head, &ctx->bo_list);
 	}
 
drivers/gpu/drm/vmwgfx/vmwgfx_validation.h +10 -0
index 55a7d8b68d5c..f68cc1fd1eb4 100644
@@ -65,6 +65,16 @@ struct vmw_validation_context {
 	u8 *page_address;
 };
 
+/**
+ * struct vmw_validate_buffer - Linked list of TTM BOs for validation
+ * @head: linked list node
+ * @bo: The TTM BO
+ */
+struct vmw_validate_buffer {
+	struct list_head head;
+	struct ttm_buffer_object *bo;
+};
+
 struct vmw_bo;
 struct vmw_resource;
 struct vmw_fence_obj;
Signature · 1 line
2.43.0
#4 lore raw

PATCH 4/4 drm/ttm: remove ttm_execbuf_util

In reply to Christian König

Replaced by drm_exec and not used any more.

---
 drivers/gpu/drm/ttm/Makefile           |   4 +-
 drivers/gpu/drm/ttm/ttm_execbuf_util.c | 163 -------------------------
 include/drm/ttm/ttm_execbuf_util.h     | 119 ------------------
 3 files changed, 2 insertions(+), 284 deletions(-)
 delete mode 100644 drivers/gpu/drm/ttm/ttm_execbuf_util.c
 delete mode 100644 include/drm/ttm/ttm_execbuf_util.h
drivers/gpu/drm/ttm/Makefile +2 -2
index 40d07a35293a..e35724b02528 100644
@@ -3,8 +3,8 @@
 # Makefile for the drm device driver.  This driver provides support for the
 
 ttm-y := ttm_tt.o ttm_bo.o ttm_bo_util.o ttm_bo_vm.o ttm_module.o \
-	ttm_execbuf_util.o ttm_range_manager.o ttm_resource.o ttm_pool.o \
-	ttm_device.o ttm_sys_manager.o ttm_backup.o
+	ttm_range_manager.o ttm_resource.o ttm_pool.o ttm_device.o \
+	ttm_sys_manager.o ttm_backup.o
 ttm-$(CONFIG_AGP) += ttm_agp_backend.o
 
 obj-$(CONFIG_DRM_TTM) += ttm.o
drivers/gpu/drm/ttm/ttm_execbuf_util.c deleted +0 -163

163 lines not on this page · raw message

include/drm/ttm/ttm_execbuf_util.h deleted +0 -119

119 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw
In reply to Christian König

When I tested this last time the first patch was fine but applying subsequent patches broke vmwgfx. I did get it to work but it required some hacks and at the time there was a major conflict with the ttm -> gem reference counting series. I will try again now that the reference counting changes are done but some changes will be needed in vmw_cotable_resize.

Quoted 20 lines · Christian König

Hi Zack,

VMWGFX is the only DRM driver who is still using the old ttm_execbuf framework and while going over my TODO branches I've found that I never upstreamed the patches to clean that up and fully move over to drm_exec.

It should be a trivial 1 to 1 replacement now, but I can only compile test it.

There can be more cleanup on top of this, for example as far as I can see vmw_resource_check_buffer() actually doesn't need a ticket. But this isn't the topic of this patch set.

Please let me know what you think since that would allow remove quite a bunch of otherwise unmaintained code.

Thanks,
Christian.

#6 lore raw
Quoted 1 line · Ian Forbes

When I tested this last time the first patch was fine but applying subsequent patches broke vmwgfx. I did get it to work but it required some hacks and at the time there was a major conflict with the ttm -> gem reference counting series. I will try again now that the reference counting changes are done but some changes will be needed in vmw_cotable_resize.

Yes since the ttm -> gem reference counting change is already completed it is now the patch set becomes a trivial replacing the old function with the new one.

Of hand I don't see any dependency with vmw_cotable_resize() any more, but it clearly needs some testing.

Thanks,
Christian.

Quoted 22 lines · On Fri, Apr 24, 2026 at 4:20 AM Christian König…

Hi Zack,

VMWGFX is the only DRM driver who is still using the old ttm_execbuf framework and while going over my TODO branches I've found that I never upstreamed the patches to clean that up and fully move over to drm_exec.

It should be a trivial 1 to 1 replacement now, but I can only compile test it.

There can be more cleanup on top of this, for example as far as I can see vmw_resource_check_buffer() actually doesn't need a ticket. But this isn't the topic of this patch set.

Please let me know what you think since that would allow remove quite a bunch of otherwise unmaintained code.

Thanks,
Christian.

#7 lore raw

The problem is that we create and reserve a new BO in vmw_cotable_resize as part of the validation phase but this BO is not added to the drm_exec context so it never gets unreserved. This only worked previously because we operated on the vmw_validation_context::bo_list. This can be hacked around by using vmw_bo_fence_single in vmw_cotable_resize but the correct solution is to remove vmw_validation_context::bo_list and only iterate over the drm_exec list. This then requires plumbing the drm_exec object through all bind and create resource function hooks.

Quoted 47 lines · Christian König
Quoted 1 line · Ian Forbes

When I tested this last time the first patch was fine but applying

subsequent patches broke vmwgfx. I did get it to work but it required some hacks and at the time there was a major conflict with the ttm -> gem reference counting series. I will try again now that the reference counting changes are done but some changes will be needed in vmw_cotable_resize.

Yes since the ttm -> gem reference counting change is already completed it is now the patch set becomes a trivial replacing the old function with the new one.

Of hand I don't see any dependency with vmw_cotable_resize() any more, but it clearly needs some testing.

Thanks,
Christian.

Quoted 2 lines

On Fri, Apr 24, 2026 at 4:20 AM Christian König <

[email protected] <mailto:[email protected]>>

Quoted 5 lines · wrote:

Hi Zack,

VMWGFX is the only DRM driver who is still using the old ttm_execbuf framework and while going over my TODO branches I've found that I

never

Quoted 1 line

upstreamed the patches to clean that up and fully move over to

drm_exec.

Quoted 6 lines

It should be a trivial 1 to 1 replacement now, but I can only compile test it.

There can be more cleanup on top of this, for example as far as I can see vmw_resource_check_buffer() actually doesn't need a ticket. But

this

Quoted 3 lines

isn't the topic of this patch set.

Please let me know what you think since that would allow remove

quite a

Quoted 5 lines

bunch of otherwise unmaintained code.

Thanks,
Christian.

maintainer
#8 lore raw
Quoted 2 lines · Ian Forbes

The problem is that we create and reserve a new BO in vmw_cotable_resize as part of the validation phase but this BO is not added to the drm_exec context so it never gets unreserved. This only worked previously because we operated on the vmw_validation_context::bo_list. This can be hacked around by using vmw_bo_fence_single in vmw_cotable_resize but the correct solution is to remove vmw_validation_context::bo_list and only iterate over the drm_exec list. This then requires plumbing the drm_exec object through all bind and create resource function hooks.

Yea, I think that's a good approach. I prototyped that, attached. Do you think you could test/try finishing this? It'd be great if we could wrap up the work Christian completed for us.

z

From bfd51c8219fd57580350a6112a23fd0647604c24 Mon Sep 17 00:00:00 2001
From: Zack Rusin <[email protected]>
Date: Mon, 27 Apr 2026 23:55:03 -0400
Subject: [PATCH] drm/vmwgfx: Make drm_exec own validation BO locking

vmw_cotable_resize() can create and reserve a replacement cotable BO while resources are being validated. After the drm_exec conversion that BO must be added to the drm_exec context, otherwise the final validation cleanup never sees it and the reservation is leaked. Using one-off fencing in the cotable path only papers over part of the problem, because the validation code still has two competing sources of truth for reserved BOs.

Make drm_exec authoritative for BO lock, fence, and unlock handling. Keep the validation BO list only as metadata for duplicate detection, validation refs, and coherent dirty tracking, and iterate the drm_exec object list for BO validation and final fencing. Remove struct vmw_validate_buffer and pass the direct ttm_buffer_object through resource bind/unbind hooks.

Plumb drm_exec through resource create/bind hooks so cotable resize can add its freshly reserved BO to the active exec context. Refresh the local backup BO after create(), since cotable create may replace res->guest_memory_bo, and keep pin and reservation ownership separate in the cotable error path.

---
 drivers/gpu/drm/drm_exec.c                    |  23 +++
 drivers/gpu/drm/vmwgfx/vmwgfx_context.c       |  36 ++---
 drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c       |  77 +++++-----
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h           |   5 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_resource.c      |  75 +++++-----
 drivers/gpu/drm/vmwgfx/vmwgfx_resource_priv.h |  11 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_shader.c        |  42 +++---
 drivers/gpu/drm/vmwgfx/vmwgfx_so.c            |   6 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_streamoutput.c  |  19 +--
 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c       |  59 ++++----
 drivers/gpu/drm/vmwgfx/vmwgfx_validation.c    | 135 +++++++++++-------
 drivers/gpu/drm/vmwgfx/vmwgfx_validation.h    |  26 ++--
 include/drm/drm_exec.h                        |   1 +
 13 files changed, 303 insertions(+), 212 deletions(-)
drivers/gpu/drm/drm_exec.c +23 -0
index 8d0601400182..69270667bce6 100644
@@ -250,6 +250,29 @@ int drm_exec_lock_obj(struct drm_exec *exec, struct drm_gem_object *obj)
 }
 EXPORT_SYMBOL(drm_exec_lock_obj);
 
+/**
+ * drm_exec_add_locked_obj - add an already locked GEM object
+ * @exec: the drm_exec object with the state
+ * @obj: the GEM object to track
+ *
+ * Adds @obj to the drm_exec context without trying to lock it. The caller must
+ * already hold @obj's dma_resv lock and must ensure @obj is not already tracked
+ * by @exec.
+ *
+ * This helper only transfers unlock/reference tracking to @exec. It does not
+ * reserve fence slots and it does not perform any driver-specific cleanup such
+ * as unpinning.
+ *
+ * Returns: -ENOMEM when memory allocation failed and zero for success.
+ */
+int drm_exec_add_locked_obj(struct drm_exec *exec, struct drm_gem_object *obj)
+{
+	dma_resv_assert_held(obj->resv);
+
+	return drm_exec_obj_locked(exec, obj);
+}
+EXPORT_SYMBOL(drm_exec_add_locked_obj);
+
 /**
  * drm_exec_unlock_obj - unlock a GEM object in this exec context
  * @exec: the drm_exec object with the state
drivers/gpu/drm/vmwgfx/vmwgfx_context.c +20 -16
index 15b8378f81a1..17f3a6d39edc 100644
@@ -46,19 +46,23 @@ static void vmw_user_context_free(struct vmw_resource *res);
 static struct vmw_resource *
 vmw_user_context_base_to_res(struct ttm_base_object *base);
 
-static int vmw_gb_context_create(struct vmw_resource *res);
+static int vmw_gb_context_create(struct vmw_resource *res,
+				 struct drm_exec *exec);
 static int vmw_gb_context_bind(struct vmw_resource *res,
-			       struct vmw_validate_buffer *val_buf);
+			       struct ttm_buffer_object *bo,
+			       struct drm_exec *exec);
 static int vmw_gb_context_unbind(struct vmw_resource *res,
 				 bool readback,
-				 struct vmw_validate_buffer *val_buf);
+				 struct ttm_buffer_object *bo);
 static int vmw_gb_context_destroy(struct vmw_resource *res);
-static int vmw_dx_context_create(struct vmw_resource *res);
+static int vmw_dx_context_create(struct vmw_resource *res,
+				 struct drm_exec *exec);
 static int vmw_dx_context_bind(struct vmw_resource *res,
-			       struct vmw_validate_buffer *val_buf);
+			       struct ttm_buffer_object *bo,
+			       struct drm_exec *exec);
 static int vmw_dx_context_unbind(struct vmw_resource *res,
 				 bool readback,
-				 struct vmw_validate_buffer *val_buf);
+				 struct ttm_buffer_object *bo);
 static int vmw_dx_context_destroy(struct vmw_resource *res);
 
 static const struct vmw_user_resource_conv user_context_conv = {
@@ -295,7 +299,8 @@ static int vmw_context_init(struct vmw_private *dev_priv,
  * GB context.
  */
 
-static int vmw_gb_context_create(struct vmw_resource *res)
+static int vmw_gb_context_create(struct vmw_resource *res,
+				 struct drm_exec *exec)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
 	int ret;
@@ -339,14 +344,14 @@ static int vmw_gb_context_create(struct vmw_resource *res)
 }
 
 static int vmw_gb_context_bind(struct vmw_resource *res,
-			       struct vmw_validate_buffer *val_buf)
+			       struct ttm_buffer_object *bo,
+			       struct drm_exec *exec)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
 	struct {
 		SVGA3dCmdHeader header;
 		SVGA3dCmdBindGBContext body;
 	} *cmd;
-	struct ttm_buffer_object *bo = val_buf->bo;
 
 	BUG_ON(bo->resource->mem_type != VMW_PL_MOB);
 
@@ -367,10 +372,9 @@ static int vmw_gb_context_bind(struct vmw_resource *res,
 
 static int vmw_gb_context_unbind(struct vmw_resource *res,
 				 bool readback,
-				 struct vmw_validate_buffer *val_buf)
+				 struct ttm_buffer_object *bo)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
-	struct ttm_buffer_object *bo = val_buf->bo;
 	struct vmw_fence_obj *fence;
 	struct vmw_user_context *uctx =
 		container_of(res, struct vmw_user_context, res);
@@ -462,7 +466,8 @@ static int vmw_gb_context_destroy(struct vmw_resource *res)
  * DX context.
  */
 
-static int vmw_dx_context_create(struct vmw_resource *res)
+static int vmw_dx_context_create(struct vmw_resource *res,
+				 struct drm_exec *exec)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
 	int ret;
@@ -506,14 +511,14 @@ static int vmw_dx_context_create(struct vmw_resource *res)
 }
 
 static int vmw_dx_context_bind(struct vmw_resource *res,
-			       struct vmw_validate_buffer *val_buf)
+			       struct ttm_buffer_object *bo,
+			       struct drm_exec *exec)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
 	struct {
 		SVGA3dCmdHeader header;
 		SVGA3dCmdDXBindContext body;
 	} *cmd;
-	struct ttm_buffer_object *bo = val_buf->bo;
 
 	BUG_ON(bo->resource->mem_type != VMW_PL_MOB);
 
@@ -576,10 +581,9 @@ void vmw_dx_context_scrub_cotables(struct vmw_resource *ctx,
 
 static int vmw_dx_context_unbind(struct vmw_resource *res,
 				 bool readback,
-				 struct vmw_validate_buffer *val_buf)
+				 struct ttm_buffer_object *bo)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
-	struct ttm_buffer_object *bo = val_buf->bo;
 	struct vmw_fence_obj *fence;
 	struct vmw_user_context *uctx =
 		container_of(res, struct vmw_user_context, res);
drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c +45 -32

171 lines not on this page · raw message

drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +3 -2
index 622b924472bf..8a6f9bf4b15f 100644
@@ -96,7 +96,7 @@ struct vmwgfx_hash_item {
 struct vmw_res_func;
 
 struct vmw_bo;
-struct vmw_bo;
+struct vmw_validation_context;
 struct vmw_resource_dirty;
 
 /**
@@ -780,7 +780,8 @@ extern void vmw_resource_unreference(struct vmw_resource **p_res);
 extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
 extern struct vmw_resource *
 vmw_resource_reference_unless_doomed(struct vmw_resource *res);
-extern int vmw_resource_validate(struct vmw_resource *res, bool intr,
+extern int vmw_resource_validate(struct vmw_resource *res,
+				 struct vmw_validation_context *ctx, bool intr,
 				 bool dirtying);
 extern int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
 				bool no_backup);
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +43 -32

189 lines not on this page · raw message

drivers/gpu/drm/vmwgfx/vmwgfx_resource_priv.h +8 -3
index ac2ea9d688c1..c2e79d2bfdd1 100644
@@ -30,6 +30,9 @@
 
 #include "vmwgfx_drv.h"
 
+struct drm_exec;
+struct vmw_validation_context;
+
 /*
  * Extra memory required by the resource id's ida storage, which is allocated
  * separately from the base object itself. We estimate an on-average 128 bytes
@@ -90,13 +93,15 @@ struct vmw_res_func {
 	u32 prio;
 	u32 dirty_prio;
 
-	int (*create) (struct vmw_resource *res);
+	int (*create) (struct vmw_resource *res,
+		       struct drm_exec *exec);
 	int (*destroy) (struct vmw_resource *res);
 	int (*bind) (struct vmw_resource *res,
-		     struct vmw_validate_buffer *val_buf);
+		     struct ttm_buffer_object *bo,
+		     struct drm_exec *exec);
 	int (*unbind) (struct vmw_resource *res,
 		       bool readback,
-		       struct vmw_validate_buffer *val_buf);
+		       struct ttm_buffer_object *bo);
 	void (*commit_notify)(struct vmw_resource *res,
 			      enum vmw_cmdbuf_res_state state);
 	int (*dirty_alloc)(struct vmw_resource *res);
drivers/gpu/drm/vmwgfx/vmwgfx_shader.c +24 -18

118 lines not on this page · raw message

drivers/gpu/drm/vmwgfx/vmwgfx_so.c +4 -2
index d199e718cb2d..17938382f955 100644
@@ -74,7 +74,8 @@ struct vmw_view {
 	u32 cmd[];		       /* Immutable */
 };
 
-static int vmw_view_create(struct vmw_resource *res);
+static int vmw_view_create(struct vmw_resource *res,
+			   struct drm_exec *exec);
 static int vmw_view_destroy(struct vmw_resource *res);
 static void vmw_hw_view_destroy(struct vmw_resource *res);
 static void vmw_view_commit_notify(struct vmw_resource *res,
@@ -157,7 +158,8 @@ static void vmw_view_commit_notify(struct vmw_resource *res,
  * Create a hardware view. Typically used if that view has previously been
  * destroyed by an eviction operation.
  */
-static int vmw_view_create(struct vmw_resource *res)
+static int vmw_view_create(struct vmw_resource *res,
+			   struct drm_exec *exec)
 {
 	struct vmw_view *view = vmw_view(res);
 	struct vmw_surface *srf = vmw_res_to_srf(view->srf);
drivers/gpu/drm/vmwgfx/vmwgfx_streamoutput.c +11 -8
index e66479cc14f7..7cef0888ebce 100644
@@ -53,11 +53,13 @@ struct vmw_dx_streamoutput {
 	bool committed;
 };
 
-static int vmw_dx_streamoutput_create(struct vmw_resource *res);
+static int vmw_dx_streamoutput_create(struct vmw_resource *res,
+				      struct drm_exec *exec);
 static int vmw_dx_streamoutput_bind(struct vmw_resource *res,
-				    struct vmw_validate_buffer *val_buf);
+				    struct ttm_buffer_object *bo,
+				    struct drm_exec *exec);
 static int vmw_dx_streamoutput_unbind(struct vmw_resource *res, bool readback,
-				      struct vmw_validate_buffer *val_buf);
+				      struct ttm_buffer_object *bo);
 static void vmw_dx_streamoutput_commit_notify(struct vmw_resource *res,
 					      enum vmw_cmdbuf_res_state state);
 
@@ -116,7 +118,8 @@ static int vmw_dx_streamoutput_unscrub(struct vmw_resource *res)
 	return 0;
 }
 
-static int vmw_dx_streamoutput_create(struct vmw_resource *res)
+static int vmw_dx_streamoutput_create(struct vmw_resource *res,
+				      struct drm_exec *exec)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
 	struct vmw_dx_streamoutput *so = vmw_res_to_dx_streamoutput(res);
@@ -136,10 +139,10 @@ static int vmw_dx_streamoutput_create(struct vmw_resource *res)
 }
 
 static int vmw_dx_streamoutput_bind(struct vmw_resource *res,
-				    struct vmw_validate_buffer *val_buf)
+				    struct ttm_buffer_object *bo,
+				    struct drm_exec *exec)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
-	struct ttm_buffer_object *bo = val_buf->bo;
 	int ret;
 
 	if (WARN_ON(bo->resource->mem_type != VMW_PL_MOB))
@@ -191,7 +194,7 @@ static int vmw_dx_streamoutput_scrub(struct vmw_resource *res)
 }
 
 static int vmw_dx_streamoutput_unbind(struct vmw_resource *res, bool readback,
-				      struct vmw_validate_buffer *val_buf)
+				      struct ttm_buffer_object *bo)
 {
 	struct vmw_private *dev_priv = res->dev_priv;
 	struct vmw_fence_obj *fence;
@@ -208,7 +211,7 @@ static int vmw_dx_streamoutput_unbind(struct vmw_resource *res, bool readback,
 		return ret;
 
 	(void) vmw_execbuf_fence_commands(NULL, dev_priv, &fence, NULL);
-	vmw_bo_fence_single(val_buf->bo, fence);
+	vmw_bo_fence_single(bo, fence);
 
 	if (fence != NULL)
 		vmw_fence_obj_unreference(&fence);
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +31 -28

172 lines not on this page · raw message

drivers/gpu/drm/vmwgfx/vmwgfx_validation.c +82 -53

287 lines not on this page · raw message

drivers/gpu/drm/vmwgfx/vmwgfx_validation.h +8 -18
index f68cc1fd1eb4..cc1c4d42c3fd 100644
@@ -39,13 +39,13 @@
 
 /**
  * struct vmw_validation_context - Per command submission validation context
- * @ht: Hash table used to find resource- or buffer object duplicates
+ * @sw_context: Software context holding the duplicate-detection hash table
  * @resource_list: List head for resource validation metadata
  * @resource_ctx_list: List head for resource validation metadata for
  * resources that need to be validated before those in @resource_list
- * @bo_list: List head for buffer objects
+ * @bo_meta_list: List head for buffer object validation metadata
  * @page_list: List of pages used by the memory allocator
- * @ticket: Ticked used for ww mutex locking
+ * @exec: Execution context used for BO reservations
  * @res_mutex: Pointer to mutex used for resource reserving
  * @merge_dups: Whether to merge metadata for duplicate resources or
  * buffer objects
@@ -56,7 +56,7 @@ struct vmw_validation_context {
 	struct vmw_sw_context *sw_context;
 	struct list_head resource_list;
 	struct list_head resource_ctx_list;
-	struct list_head bo_list;
+	struct list_head bo_meta_list;
 	struct list_head page_list;
 	struct drm_exec exec;
 	struct mutex *res_mutex;
@@ -65,16 +65,6 @@ struct vmw_validation_context {
 	u8 *page_address;
 };
 
-/**
- * struct vmw_validate_buffer - Linked list of TTM BOs for validation
- * @head: linked list node
- * @bo: The TTM BO
- */
-struct vmw_validate_buffer {
-	struct list_head head;
-	struct ttm_buffer_object *bo;
-};
-
 struct vmw_bo;
 struct vmw_resource;
 struct vmw_fence_obj;
@@ -95,7 +85,7 @@ struct vmw_fence_obj;
 	{ .sw_context = _sw_context,					\
 	  .resource_list = LIST_HEAD_INIT((_name).resource_list),	\
 	  .resource_ctx_list = LIST_HEAD_INIT((_name).resource_ctx_list), \
-	  .bo_list = LIST_HEAD_INIT((_name).bo_list),			\
+	  .bo_meta_list = LIST_HEAD_INIT((_name).bo_meta_list),		\
 	  .page_list = LIST_HEAD_INIT((_name).page_list),		\
 	  .res_mutex = NULL,						\
 	  .merge_dups = _merge_dups,					\
@@ -104,15 +94,15 @@ struct vmw_fence_obj;
 
 /**
  * vmw_validation_has_bos - return whether the validation context has
- * any buffer objects registered.
+ * any buffer objects registered or locked.
  *
  * @ctx: The validation context
- * Returns: Whether any buffer objects are registered
+ * Returns: Whether any buffer objects are registered or locked
  */
 static inline bool
 vmw_validation_has_bos(struct vmw_validation_context *ctx)
 {
-	return !list_empty(&ctx->bo_list);
+	return ctx->exec.num_objects || !list_empty(&ctx->bo_meta_list);
 }
 
 /**
include/drm/drm_exec.h +1 -0
index aa786b828a0a..bc8da55b2818 100644
@@ -139,6 +139,7 @@ void drm_exec_init(struct drm_exec *exec, u32 flags, unsigned nr);
 void drm_exec_fini(struct drm_exec *exec);
 bool drm_exec_cleanup(struct drm_exec *exec);
 int drm_exec_lock_obj(struct drm_exec *exec, struct drm_gem_object *obj);
+int drm_exec_add_locked_obj(struct drm_exec *exec, struct drm_gem_object *obj);
 void drm_exec_unlock_obj(struct drm_exec *exec, struct drm_gem_object *obj);
 int drm_exec_prepare_obj(struct drm_exec *exec, struct drm_gem_object *obj,
 			 unsigned int num_fences);
Signature · 1 line
2.51.0