Skip to contentSkip to conversation

drm/vmwgfx: Update last_read_seqno under the fence lock

PATCH Superseded Ian Forbes 2 participants 4 messages Apr 10, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ian Forbes

author
#0 lore raw

PATCH 1/2 drm/vmwgfx: Update last_read_seqno under the fence lock

There was a possible race in vmw_update_seqno. Because of this race it was possible for last_read_seqno to go backwards. Remove this function and replace it with vmw_update_fences which now sets and returns the last_read_seqno while holding the fence lock. This serialization via the fence lock ensures that last_read_seqno is monotonic again.

---
 drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c     |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h     |  1 -
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c |  3 +--
 drivers/gpu/drm/vmwgfx/vmwgfx_fence.c   | 18 +++++++++---------
 drivers/gpu/drm/vmwgfx/vmwgfx_fence.h   |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_irq.c     | 12 +-----------
 6 files changed, 13 insertions(+), 25 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c +1 -1
index dd4ca6a9c690..8fe02131a6c4 100644
@@ -544,7 +544,7 @@ int vmw_cmd_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
 	cmd_fence = (struct svga_fifo_cmd_fence *) fm;
 	cmd_fence->fence = *seqno;
 	vmw_cmd_commit_flush(dev_priv, bytes);
-	vmw_update_seqno(dev_priv);
+	vmw_fences_update(dev_priv->fman);
 
 out_err:
 	return ret;
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +0 -1
index 594af8eb04c6..6d4a68f0ae37 100644
@@ -1006,7 +1006,6 @@ extern int vmw_fallback_wait(struct vmw_private *dev_priv,
 			     uint32_t seqno,
 			     bool interruptible,
 			     unsigned long timeout);
-extern void vmw_update_seqno(struct vmw_private *dev_priv);
 extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
 extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
 extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +1 -2
index e831e324e737..90ce5372343b 100644
@@ -3878,8 +3878,7 @@ vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
 
 		fence_rep.handle = fence_handle;
 		fence_rep.seqno = fence->base.seqno;
-		vmw_update_seqno(dev_priv);
-		fence_rep.passed_seqno = dev_priv->last_read_seqno;
+		fence_rep.passed_seqno = vmw_fences_update(dev_priv->fman);
 	}
 
 	/*
drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +9 -9
index 588d50ababf6..9d1465558839 100644
@@ -172,7 +172,7 @@ vmwgfx_wait_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
 	wake_up_process(wait->task);
 }
 
-static void __vmw_fences_update(struct vmw_fence_manager *fman);
+static u32 __vmw_fences_update(struct vmw_fence_manager *fman);
 
 static long vmw_fence_wait(struct dma_fence *f, bool intr, signed long timeout)
 {
@@ -457,7 +457,7 @@ static bool vmw_fence_goal_check_locked(struct vmw_fence_obj *fence)
 	return true;
 }
 
-static void __vmw_fences_update(struct vmw_fence_manager *fman)
+static u32 __vmw_fences_update(struct vmw_fence_manager *fman)
 {
 	struct vmw_fence_obj *fence, *next_fence;
 	struct list_head action_list;
@@ -495,13 +495,16 @@ static void __vmw_fences_update(struct vmw_fence_manager *fman)
 
 	if (!list_empty(&fman->cleanup_list))
 		(void) schedule_work(&fman->work);
+	return (fman->dev_priv->last_read_seqno = seqno);
 }
 
-void vmw_fences_update(struct vmw_fence_manager *fman)
+u32 vmw_fences_update(struct vmw_fence_manager *fman)
 {
+	u32 seqno;
 	spin_lock(&fman->lock);
-	__vmw_fences_update(fman);
+	seqno = __vmw_fences_update(fman);
 	spin_unlock(&fman->lock);
+	return seqno;
 }
 
 bool vmw_fence_obj_signaled(struct vmw_fence_obj *fence)
@@ -778,7 +781,6 @@ int vmw_fence_obj_signaled_ioctl(struct drm_device *dev, void *data,
 		(struct drm_vmw_fence_signaled_arg *) data;
 	struct ttm_base_object *base;
 	struct vmw_fence_obj *fence;
-	struct vmw_fence_manager *fman;
 	struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
 	struct vmw_private *dev_priv = vmw_priv(dev);
 
@@ -787,14 +789,12 @@ int vmw_fence_obj_signaled_ioctl(struct drm_device *dev, void *data,
 		return PTR_ERR(base);
 
 	fence = &(container_of(base, struct vmw_user_fence, base)->fence);
-	fman = fman_from_fence(fence);
 
 	arg->signaled = vmw_fence_obj_signaled(fence);
 
 	arg->signaled_flags = arg->flags;
-	spin_lock(&fman->lock);
-	arg->passed_seqno = dev_priv->last_read_seqno;
-	spin_unlock(&fman->lock);
+	arg->passed_seqno = READ_ONCE(dev_priv->last_read_seqno);
+
 
 	ttm_base_object_unref(&base);
 
drivers/gpu/drm/vmwgfx/vmwgfx_fence.h +1 -1
index a7eee579c76a..10264dab5f6a 100644
@@ -86,7 +86,7 @@ vmw_fence_obj_reference(struct vmw_fence_obj *fence)
 	return fence;
 }
 
-extern void vmw_fences_update(struct vmw_fence_manager *fman);
+u32 vmw_fences_update(struct vmw_fence_manager *fman);
 
 extern bool vmw_fence_obj_signaled(struct vmw_fence_obj *fence);
 
drivers/gpu/drm/vmwgfx/vmwgfx_irq.c +1 -11
index 086e69a130d4..548ef2f86508 100644
@@ -123,16 +123,6 @@ static bool vmw_fifo_idle(struct vmw_private *dev_priv, uint32_t seqno)
 	return (vmw_read(dev_priv, SVGA_REG_BUSY) == 0);
 }
 
-void vmw_update_seqno(struct vmw_private *dev_priv)
-{
-	uint32_t seqno = vmw_fence_read(dev_priv);
-
-	if (dev_priv->last_read_seqno != seqno) {
-		dev_priv->last_read_seqno = seqno;
-		vmw_fences_update(dev_priv->fman);
-	}
-}
-
 bool vmw_seqno_passed(struct vmw_private *dev_priv,
 			 uint32_t seqno)
 {
@@ -141,7 +131,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
 	if (likely(dev_priv->last_read_seqno - seqno < VMW_FENCE_WRAP))
 		return true;
 
-	vmw_update_seqno(dev_priv);
+	vmw_fences_update(dev_priv->fman);
 	if (likely(dev_priv->last_read_seqno - seqno < VMW_FENCE_WRAP))
 		return true;
 
Signature · 1 line
2.49.0
author
#1 lore raw

PATCH 2/2 drm/vmwgfx: Implement dma_fence_ops properly

vmwgfx's fencing predates dma_fence and as a result dma_fence_ops was never properly implemented, especially with respect to enabling signaling.

Because of this dma_fence callbacks don't work properly. This change implements enable_signaling properly so that dma_fence callbacks now work as expected.

It also removes vmwgfx's custom implementation of fence callbacks and removes vmwgfx's custom dma_fence_ops::wait function which is no longer necessary now that enable_signaling works.

---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h     |  16 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c |  26 --
 drivers/gpu/drm/vmwgfx/vmwgfx_fence.c   | 479 ++++--------------------
 drivers/gpu/drm/vmwgfx/vmwgfx_fence.h   |  19 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_irq.c     |  44 ++-
 5 files changed, 99 insertions(+), 485 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +8 -8
index 6d4a68f0ae37..6df61c22d442 100644
@@ -1006,14 +1006,14 @@ extern int vmw_fallback_wait(struct vmw_private *dev_priv,
 			     uint32_t seqno,
 			     bool interruptible,
 			     unsigned long timeout);
-extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
-extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
-extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
-extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
-extern void vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag,
-				   int *waiter_count);
-extern void vmw_generic_waiter_remove(struct vmw_private *dev_priv,
-				      u32 flag, int *waiter_count);
+bool vmw_seqno_waiter_add(struct vmw_private *dev_priv);
+bool vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
+bool vmw_goal_waiter_add(struct vmw_private *dev_priv);
+bool vmw_goal_waiter_remove(struct vmw_private *dev_priv);
+bool vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag,
+			    int *waiter_count);
+bool vmw_generic_waiter_remove(struct vmw_private *dev_priv,
+			       u32 flag, int *waiter_count);
 
 /**
  * Kernel modesetting - vmwgfx_kms.c
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +0 -26
index 90ce5372343b..819704ac675d 100644
@@ -4067,23 +4067,6 @@ static int vmw_execbuf_tie_context(struct vmw_private *dev_priv,
 	return 0;
 }
 
-/*
- * DMA fence callback to remove a seqno_waiter
- */
-struct seqno_waiter_rm_context {
-	struct dma_fence_cb base;
-	struct vmw_private *dev_priv;
-};
-
-static void seqno_waiter_rm_cb(struct dma_fence *f, struct dma_fence_cb *cb)
-{
-	struct seqno_waiter_rm_context *ctx =
-		container_of(cb, struct seqno_waiter_rm_context, base);
-
-	vmw_seqno_waiter_remove(ctx->dev_priv);
-	kfree(ctx);
-}
-
 int vmw_execbuf_process(struct drm_file *file_priv,
 			struct vmw_private *dev_priv,
 			void __user *user_commands, void *kernel_commands,
@@ -4264,15 +4247,6 @@ int vmw_execbuf_process(struct drm_file *file_priv,
 		} else {
 			/* Link the fence with the FD created earlier */
 			fd_install(out_fence_fd, sync_file->file);
-			struct seqno_waiter_rm_context *ctx =
-				kmalloc(sizeof(*ctx), GFP_KERNEL);
-			ctx->dev_priv = dev_priv;
-			vmw_seqno_waiter_add(dev_priv);
-			if (dma_fence_add_callback(&fence->base, &ctx->base,
-						   seqno_waiter_rm_cb) < 0) {
-				vmw_seqno_waiter_remove(dev_priv);
-				kfree(ctx);
-			}
 		}
 	}
 
drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +64 -415

658 lines not on this page · raw message

drivers/gpu/drm/vmwgfx/vmwgfx_fence.h +1 -18
index 10264dab5f6a..e897cccae1ae 100644
@@ -39,27 +39,10 @@ struct drm_pending_event;
 struct vmw_private;
 struct vmw_fence_manager;
 
-/**
- *
- *
- */
-enum vmw_action_type {
-	VMW_ACTION_EVENT = 0,
-	VMW_ACTION_MAX
-};
-
-struct vmw_fence_action {
-	struct list_head head;
-	enum vmw_action_type type;
-	void (*seq_passed) (struct vmw_fence_action *action);
-	void (*cleanup) (struct vmw_fence_action *action);
-};
-
 struct vmw_fence_obj {
 	struct dma_fence base;
-
+	bool   waiter_added;
 	struct list_head head;
-	struct list_head seq_passed_actions;
 	void (*destroy)(struct vmw_fence_obj *fence);
 };
 
drivers/gpu/drm/vmwgfx/vmwgfx_irq.c +26 -18

77 lines not on this page · raw message

Signature · 1 line
2.49.0
#2 lore raw
In reply to Ian Forbes
Quoted 78 lines · Ian Forbes

There was a possible race in vmw_update_seqno. Because of this race it was possible for last_read_seqno to go backwards. Remove this function and replace it with vmw_update_fences which now sets and returns the last_read_seqno while holding the fence lock. This serialization via the fence lock ensures that last_read_seqno is monotonic again.

---
 drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c     |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h     |  1 -
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c |  3 +--
 drivers/gpu/drm/vmwgfx/vmwgfx_fence.c   | 18 +++++++++---------
 drivers/gpu/drm/vmwgfx/vmwgfx_fence.h   |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_irq.c     | 12 +-----------
 6 files changed, 13 insertions(+), 25 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c +1 -1
index dd4ca6a9c690..8fe02131a6c4 100644
@@ -544,7 +544,7 @@ int vmw_cmd_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
 	cmd_fence = (struct svga_fifo_cmd_fence *) fm;
 	cmd_fence->fence = *seqno;
 	vmw_cmd_commit_flush(dev_priv, bytes);
-	vmw_update_seqno(dev_priv);
+	vmw_fences_update(dev_priv->fman);
 
 out_err:
 	return ret;
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +0 -1
index 594af8eb04c6..6d4a68f0ae37 100644
@@ -1006,7 +1006,6 @@ extern int vmw_fallback_wait(struct vmw_private *dev_priv,
 			     uint32_t seqno,
 			     bool interruptible,
 			     unsigned long timeout);
-extern void vmw_update_seqno(struct vmw_private *dev_priv);
 extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
 extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
 extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +1 -2
index e831e324e737..90ce5372343b 100644
@@ -3878,8 +3878,7 @@ vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
 
 		fence_rep.handle = fence_handle;
 		fence_rep.seqno = fence->base.seqno;
-		vmw_update_seqno(dev_priv);
-		fence_rep.passed_seqno = dev_priv->last_read_seqno;
+		fence_rep.passed_seqno = vmw_fences_update(dev_priv->fman);
 	}
 
 	/*
drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +2 -2
index 588d50ababf6..9d1465558839 100644
@@ -172,7 +172,7 @@ vmwgfx_wait_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
 	wake_up_process(wait->task);
 }
 
-static void __vmw_fences_update(struct vmw_fence_manager *fman);
+static u32 __vmw_fences_update(struct vmw_fence_manager *fman);
 
 static long vmw_fence_wait(struct dma_fence *f, bool intr, signed long timeout)
 {
@@ -457,7 +457,7 @@ static bool vmw_fence_goal_check_locked(struct vmw_fence_obj *fence)
 	return true;
 }
 
-static void __vmw_fences_update(struct vmw_fence_manager *fman)
+static u32 __vmw_fences_update(struct vmw_fence_manager *fman)
 {
 	struct vmw_fence_obj *fence, *next_fence;
 	struct list_head action_list;

drivers/gpu/drm/vmwgfx/vmwgfx_fence.c static void __vmw_fences_update(struct vmw_fence_manager *fman) · line 498

Quoted 4 lines
drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +1 -0
@@ -495,13 +495,16 @@ static void __vmw_fences_update(struct vmw_fence_manager *fman)
 
 	if (!list_empty(&fman->cleanup_list))
 		(void) schedule_work(&fman->work);
+	return (fman->dev_priv->last_read_seqno = seqno);

Should this be WRITE_ONCE(fman->dev_priv->last_read_seqno) = seqno ?

Quoted 82 lines
drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +6 -7
 }
 
-void vmw_fences_update(struct vmw_fence_manager *fman)
+u32 vmw_fences_update(struct vmw_fence_manager *fman)
 {
+	u32 seqno;
 	spin_lock(&fman->lock);
-	__vmw_fences_update(fman);
+	seqno = __vmw_fences_update(fman);
 	spin_unlock(&fman->lock);
+	return seqno;
 }
 
 bool vmw_fence_obj_signaled(struct vmw_fence_obj *fence)
@@ -778,7 +781,6 @@ int vmw_fence_obj_signaled_ioctl(struct drm_device *dev, void *data,
 		(struct drm_vmw_fence_signaled_arg *) data;
 	struct ttm_base_object *base;
 	struct vmw_fence_obj *fence;
-	struct vmw_fence_manager *fman;
 	struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
 	struct vmw_private *dev_priv = vmw_priv(dev);
 
@@ -787,14 +789,12 @@ int vmw_fence_obj_signaled_ioctl(struct drm_device *dev, void *data,
 		return PTR_ERR(base);
 
 	fence = &(container_of(base, struct vmw_user_fence, base)->fence);
-	fman = fman_from_fence(fence);
 
 	arg->signaled = vmw_fence_obj_signaled(fence);
 
 	arg->signaled_flags = arg->flags;
-	spin_lock(&fman->lock);
-	arg->passed_seqno = dev_priv->last_read_seqno;
-	spin_unlock(&fman->lock);
+	arg->passed_seqno = READ_ONCE(dev_priv->last_read_seqno);
+
 
 	ttm_base_object_unref(&base);
 
drivers/gpu/drm/vmwgfx/vmwgfx_fence.h +1 -1
index a7eee579c76a..10264dab5f6a 100644
@@ -86,7 +86,7 @@ vmw_fence_obj_reference(struct vmw_fence_obj *fence)
 	return fence;
 }
 
-extern void vmw_fences_update(struct vmw_fence_manager *fman);
+u32 vmw_fences_update(struct vmw_fence_manager *fman);
 
 extern bool vmw_fence_obj_signaled(struct vmw_fence_obj *fence);
 
drivers/gpu/drm/vmwgfx/vmwgfx_irq.c +1 -11
index 086e69a130d4..548ef2f86508 100644
@@ -123,16 +123,6 @@ static bool vmw_fifo_idle(struct vmw_private *dev_priv, uint32_t seqno)
 	return (vmw_read(dev_priv, SVGA_REG_BUSY) == 0);
 }
 
-void vmw_update_seqno(struct vmw_private *dev_priv)
-{
-	uint32_t seqno = vmw_fence_read(dev_priv);
-
-	if (dev_priv->last_read_seqno != seqno) {
-		dev_priv->last_read_seqno = seqno;
-		vmw_fences_update(dev_priv->fman);
-	}
-}
-
 bool vmw_seqno_passed(struct vmw_private *dev_priv,
 			 uint32_t seqno)
 {
@@ -141,7 +131,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
 	if (likely(dev_priv->last_read_seqno - seqno < VMW_FENCE_WRAP))
 		return true;
 
-	vmw_update_seqno(dev_priv);
+	vmw_fences_update(dev_priv->fman);
 	if (likely(dev_priv->last_read_seqno - seqno < VMW_FENCE_WRAP))
 		return true;
 
Signature · 1 line
Maaz Mombasawala <[email protected]>
#3 lore raw
In reply to Ian Forbes
Quoted 108 lines · Ian Forbes

There was a possible race in vmw_update_seqno. Because of this race it was possible for last_read_seqno to go backwards. Remove this function and replace it with vmw_update_fences which now sets and returns the last_read_seqno while holding the fence lock. This serialization via the fence lock ensures that last_read_seqno is monotonic again.

---
 drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c     |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h     |  1 -
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c |  3 +--
 drivers/gpu/drm/vmwgfx/vmwgfx_fence.c   | 18 +++++++++---------
 drivers/gpu/drm/vmwgfx/vmwgfx_fence.h   |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_irq.c     | 12 +-----------
 6 files changed, 13 insertions(+), 25 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c +1 -1
index dd4ca6a9c690..8fe02131a6c4 100644
@@ -544,7 +544,7 @@ int vmw_cmd_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
 	cmd_fence = (struct svga_fifo_cmd_fence *) fm;
 	cmd_fence->fence = *seqno;
 	vmw_cmd_commit_flush(dev_priv, bytes);
-	vmw_update_seqno(dev_priv);
+	vmw_fences_update(dev_priv->fman);
 
 out_err:
 	return ret;
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +0 -1
index 594af8eb04c6..6d4a68f0ae37 100644
@@ -1006,7 +1006,6 @@ extern int vmw_fallback_wait(struct vmw_private *dev_priv,
 			     uint32_t seqno,
 			     bool interruptible,
 			     unsigned long timeout);
-extern void vmw_update_seqno(struct vmw_private *dev_priv);
 extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
 extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
 extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +1 -2
index e831e324e737..90ce5372343b 100644
@@ -3878,8 +3878,7 @@ vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
 
 		fence_rep.handle = fence_handle;
 		fence_rep.seqno = fence->base.seqno;
-		vmw_update_seqno(dev_priv);
-		fence_rep.passed_seqno = dev_priv->last_read_seqno;
+		fence_rep.passed_seqno = vmw_fences_update(dev_priv->fman);
 	}
 
 	/*
drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +7 -5
index 588d50ababf6..9d1465558839 100644
@@ -172,7 +172,7 @@ vmwgfx_wait_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
 	wake_up_process(wait->task);
 }
 
-static void __vmw_fences_update(struct vmw_fence_manager *fman);
+static u32 __vmw_fences_update(struct vmw_fence_manager *fman);
 
 static long vmw_fence_wait(struct dma_fence *f, bool intr, signed long timeout)
 {
@@ -457,7 +457,7 @@ static bool vmw_fence_goal_check_locked(struct vmw_fence_obj *fence)
 	return true;
 }
 
-static void __vmw_fences_update(struct vmw_fence_manager *fman)
+static u32 __vmw_fences_update(struct vmw_fence_manager *fman)
 {
 	struct vmw_fence_obj *fence, *next_fence;
 	struct list_head action_list;
@@ -495,13 +495,16 @@ static void __vmw_fences_update(struct vmw_fence_manager *fman)
 
 	if (!list_empty(&fman->cleanup_list))
 		(void) schedule_work(&fman->work);
+	return (fman->dev_priv->last_read_seqno = seqno);
 }
 
-void vmw_fences_update(struct vmw_fence_manager *fman)
+u32 vmw_fences_update(struct vmw_fence_manager *fman)
 {
+	u32 seqno;
 	spin_lock(&fman->lock);
-	__vmw_fences_update(fman);
+	seqno = __vmw_fences_update(fman);
 	spin_unlock(&fman->lock);
+	return seqno;
 }
 
 bool vmw_fence_obj_signaled(struct vmw_fence_obj *fence)
@@ -778,7 +781,6 @@ int vmw_fence_obj_signaled_ioctl(struct drm_device *dev, void *data,
 		(struct drm_vmw_fence_signaled_arg *) data;
 	struct ttm_base_object *base;
 	struct vmw_fence_obj *fence;
-	struct vmw_fence_manager *fman;
 	struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
 	struct vmw_private *dev_priv = vmw_priv(dev);
 
@@ -787,14 +789,12 @@ int vmw_fence_obj_signaled_ioctl(struct drm_device *dev, void *data,
 		return PTR_ERR(base);
 
 	fence = &(container_of(base, struct vmw_user_fence, base)->fence);

drivers/gpu/drm/vmwgfx/vmwgfx_fence.c int vmw_fence_obj_signaled_ioctl(struct drm_device *dev, void *data, · line 797

Quoted 10 lines
drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +2 -4
-	fman = fman_from_fence(fence);
 
 	arg->signaled = vmw_fence_obj_signaled(fence);
 
 	arg->signaled_flags = arg->flags;
-	spin_lock(&fman->lock);
-	arg->passed_seqno = dev_priv->last_read_seqno;
-	spin_unlock(&fman->lock);
+	arg->passed_seqno = READ_ONCE(dev_priv->last_read_seqno);
+

Why are is the spinlock being removed here? As far as I understand it, READ_ONCE() will prevent compiler optimizations that might change how the variable is read, but we would still need the lock to synchronize access at runtime, since we are using that lock for write access when invoking __vmw_fences_update(). Also, if we are using the spinlock, doesn't that make READ_ONCE() redundant?

Quoted 46 lines
drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +0 -0
 	ttm_base_object_unref(&base);
 
drivers/gpu/drm/vmwgfx/vmwgfx_fence.h +1 -1
index a7eee579c76a..10264dab5f6a 100644
@@ -86,7 +86,7 @@ vmw_fence_obj_reference(struct vmw_fence_obj *fence)
 	return fence;
 }
 
-extern void vmw_fences_update(struct vmw_fence_manager *fman);
+u32 vmw_fences_update(struct vmw_fence_manager *fman);
 
 extern bool vmw_fence_obj_signaled(struct vmw_fence_obj *fence);
 
drivers/gpu/drm/vmwgfx/vmwgfx_irq.c +1 -11
index 086e69a130d4..548ef2f86508 100644
@@ -123,16 +123,6 @@ static bool vmw_fifo_idle(struct vmw_private *dev_priv, uint32_t seqno)
 	return (vmw_read(dev_priv, SVGA_REG_BUSY) == 0);
 }
 
-void vmw_update_seqno(struct vmw_private *dev_priv)
-{
-	uint32_t seqno = vmw_fence_read(dev_priv);
-
-	if (dev_priv->last_read_seqno != seqno) {
-		dev_priv->last_read_seqno = seqno;
-		vmw_fences_update(dev_priv->fman);
-	}
-}
-
 bool vmw_seqno_passed(struct vmw_private *dev_priv,
 			 uint32_t seqno)
 {
@@ -141,7 +131,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
 	if (likely(dev_priv->last_read_seqno - seqno < VMW_FENCE_WRAP))
 		return true;
 
-	vmw_update_seqno(dev_priv);
+	vmw_fences_update(dev_priv->fman);
 	if (likely(dev_priv->last_read_seqno - seqno < VMW_FENCE_WRAP))
 		return true;
 
Signature · 1 line
Maaz Mombasawala <[email protected]>