Skip to contentSkip to conversation

drm/v3d: create a dedicated lock for dma fence

PATCH In review Melissa Wen 3 participants 3 messages Sep 16, 2025 – Sep 17, 2025

Subsystems (3)
lore
Share & tools
lore

Melissa Wen

author maintainer
#0 lore raw

PATCH 1/1 drm/v3d: create a dedicated lock for dma fence

Don't mix dma fence lock with the active_job lock. The issue was uncovered when PREEMPT_RT on.

Fixes fa6a20c87470 ("drm/v3d: Address race-condition between per-fd GPU stats and fd release")
---
 drivers/gpu/drm/v3d/v3d_drv.h   | 1 +
 drivers/gpu/drm/v3d/v3d_fence.c | 2 +-
 drivers/gpu/drm/v3d/v3d_gem.c   | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/v3d/v3d_drv.h +1 -0
index 0317f3d7452a..b1c41af87e17 100644
@@ -62,6 +62,7 @@ struct v3d_queue_state {
 	/* Currently active job for this queue */
 	struct v3d_job *active_job;
 	spinlock_t queue_lock;
+	spinlock_t fence_lock;
 };
 
 /* Performance monitor object. The perform lifetime is controlled by userspace
drivers/gpu/drm/v3d/v3d_fence.c +1 -1
index 8f8471adae34..c82500a1df73 100644
@@ -15,7 +15,7 @@ struct dma_fence *v3d_fence_create(struct v3d_dev *v3d, enum v3d_queue q)
 	fence->dev = &v3d->drm;
 	fence->queue = q;
 	fence->seqno = ++queue->emit_seqno;
-	dma_fence_init(&fence->base, &v3d_fence_ops, &queue->queue_lock,
+	dma_fence_init(&fence->base, &v3d_fence_ops, &queue->fence_lock,
 		       queue->fence_context, fence->seqno);
 
 	return &fence->base;
drivers/gpu/drm/v3d/v3d_gem.c +1 -0
index c77d90aa9b82..bb110d35f749 100644
@@ -273,6 +273,7 @@ v3d_gem_init(struct drm_device *dev)
 		seqcount_init(&queue->stats.lock);
 
 		spin_lock_init(&queue->queue_lock);
+		spin_lock_init(&queue->fence_lock);
 	}
 
 	spin_lock_init(&v3d->mm_lock);
Signature · 1 line
2.47.2
Acked-by on v1 1/1
#1 lore raw

Thanks Melissa!

Quoted 57 lines · Melissa Wen

Don't mix dma fence lock with the active_job lock. The issue was uncovered when PREEMPT_RT on.

Fixes fa6a20c87470 ("drm/v3d: Address race-condition between per-fd

GPU stats and fd release")

---
 drivers/gpu/drm/v3d/v3d_drv.h   | 1 +
 drivers/gpu/drm/v3d/v3d_fence.c | 2 +-
 drivers/gpu/drm/v3d/v3d_gem.c   | 1 +

 3 files changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/v3d/v3d_drv.h +1 -0
index 0317f3d7452a..b1c41af87e17 100644
@@ -62,6 +62,7 @@ struct v3d_queue_state {
  	/* Currently active job for this queue */
  	struct v3d_job *active_job;
  	spinlock_t queue_lock;
+	spinlock_t fence_lock;
  };


 /* Performance monitor object. The perform lifetime is controlled by userspace

drivers/gpu/drm/v3d/v3d_fence.c +1 -1
index 8f8471adae34..c82500a1df73 100644
@@ -15,7 +15,7 @@ struct dma_fence *v3d_fence_create(struct v3d_dev
 *v3d, enum v3d_queue q)
  	fence->dev = &v3d->drm;
  	fence->queue = q;
  	fence->seqno = ++queue->emit_seqno;
-	dma_fence_init(&fence->base, &v3d_fence_ops, &queue-
 >queue_lock,
+	dma_fence_init(&fence->base, &v3d_fence_ops, &queue-
 >fence_lock,

         queue->fence_context, fence->seqno);
  return &fence->base;

drivers/gpu/drm/v3d/v3d_gem.c +0 -0
index c77d90aa9b82..bb110d35f749 100644
@@ -273,6 +273,7 @@ v3d_gem_init(struct drm_device *dev)
  		seqcount_init(&queue->stats.lock);


  spin_lock_init(&queue->queue_lock);

drivers/gpu/drm/v3d/v3d_gem.c +1 -0
+		spin_lock_init(&queue->fence_lock);

  }

  spin_lock_init(&v3d->mm_lock);

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Melissa Wen

Hi Melissa,

Quoted 2 lines · Melissa Wen

Don't mix dma fence lock with the active_job lock. The issue was uncovered when PREEMPT_RT on.

Maybe you could add a bit more detail about the issue in the commit message? If I wasn't already familiar to the issue, I believe I wouldn't be able to understand it from the commit message.

Quoted 4 lines
Fixes fa6a20c87470 ("drm/v3d: Address race-condition between per-fd GPU stats and fd release")

Thanks for fixing this issue!

Best Regards,
- Maíra

Quoted 39 lines
---
  drivers/gpu/drm/v3d/v3d_drv.h   | 1 +
  drivers/gpu/drm/v3d/v3d_fence.c | 2 +-
  drivers/gpu/drm/v3d/v3d_gem.c   | 1 +
  3 files changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/v3d/v3d_drv.h +1 -0
index 0317f3d7452a..b1c41af87e17 100644
@@ -62,6 +62,7 @@ struct v3d_queue_state {
  	/* Currently active job for this queue */
  	struct v3d_job *active_job;
  	spinlock_t queue_lock;
+	spinlock_t fence_lock;
  };
    /* Performance monitor object. The perform lifetime is controlled by userspace
drivers/gpu/drm/v3d/v3d_fence.c +1 -1
index 8f8471adae34..c82500a1df73 100644
@@ -15,7 +15,7 @@ struct dma_fence *v3d_fence_create(struct v3d_dev *v3d, enum v3d_queue q)
  	fence->dev = &v3d->drm;
  	fence->queue = q;
  	fence->seqno = ++queue->emit_seqno;
-	dma_fence_init(&fence->base, &v3d_fence_ops, &queue->queue_lock,
+	dma_fence_init(&fence->base, &v3d_fence_ops, &queue->fence_lock,
  		       queue->fence_context, fence->seqno);
    	return &fence->base;
drivers/gpu/drm/v3d/v3d_gem.c +1 -0
index c77d90aa9b82..bb110d35f749 100644
@@ -273,6 +273,7 @@ v3d_gem_init(struct drm_device *dev)
  		seqcount_init(&queue->stats.lock);
    		spin_lock_init(&queue->queue_lock);
+		spin_lock_init(&queue->fence_lock);
  	}
    	spin_lock_init(&v3d->mm_lock);