Skip to contentSkip to conversation

drm/v3d: Take a lock across GPU scheduler job creation and queuing.

PATCH Superseded Eric Anholt 3 participants 10 messages Jun 5, 2018 – Jun 8, 2018

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

PATCH 1/3 drm/v3d: Take a lock across GPU scheduler job creation and queuing.

Between creation and queueing of a job, you need to prevent any other job from being created and queued. Otherwise the scheduler's fences may be signaled out of seqno order.

Fixes 57692c94dcbe ("drm/v3d: Introduce a new DRM driver for Broadcom V3D V3.x+")

---

ccing amd-gfx due to interaction of this series with the scheduler.

 drivers/gpu/drm/v3d/v3d_drv.h |  5 +++++
 drivers/gpu/drm/v3d/v3d_gem.c | 11 +++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)
drivers/gpu/drm/v3d/v3d_drv.h +5 -0
index a043ac3aae98..26005abd9c5d 100644
@@ -85,6 +85,11 @@ struct v3d_dev {
 	 */
 	struct mutex reset_lock;
 
+	/* Lock taken when creating and pushing the GPU scheduler
+	 * jobs, to keep the sched-fence seqnos in order.
+	 */
+	struct mutex sched_lock;
+
 	struct {
 		u32 num_allocated;
 		u32 pages_allocated;
drivers/gpu/drm/v3d/v3d_gem.c +9 -2
index b513f9189caf..9ea83bdb9a30 100644
@@ -550,13 +550,16 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
 	if (ret)
 		goto fail;
 
+	mutex_lock(&v3d->sched_lock);
 	if (exec->bin.start != exec->bin.end) {
 		ret = drm_sched_job_init(&exec->bin.base,
 					 &v3d->queue[V3D_BIN].sched,
 					 &v3d_priv->sched_entity[V3D_BIN],
 					 v3d_priv);
-		if (ret)
+		if (ret) {
+			mutex_unlock(&v3d->sched_lock);
 			goto fail_unreserve;
+		}
 
 		exec->bin_done_fence =
 			dma_fence_get(&exec->bin.base.s_fence->finished);
@@ -570,12 +573,15 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
 				 &v3d->queue[V3D_RENDER].sched,
 				 &v3d_priv->sched_entity[V3D_RENDER],
 				 v3d_priv);
-	if (ret)
+	if (ret) {
+		mutex_unlock(&v3d->sched_lock);
 		goto fail_unreserve;
+	}
 
 	kref_get(&exec->refcount); /* put by scheduler job completion */
 	drm_sched_entity_push_job(&exec->render.base,
 				  &v3d_priv->sched_entity[V3D_RENDER]);
+	mutex_unlock(&v3d->sched_lock);
 
 	v3d_attach_object_fences(exec);
 
@@ -615,6 +621,7 @@ v3d_gem_init(struct drm_device *dev)
 	spin_lock_init(&v3d->job_lock);
 	mutex_init(&v3d->bo_lock);
 	mutex_init(&v3d->reset_lock);
+	mutex_init(&v3d->sched_lock);
 
 	/* Note: We don't allocate address 0.  Various bits of HW
 	 * treat 0 as special, such as the occlusion query counters
Signature · 6 lines
2.17.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#1 lore raw

PATCH 2/3 drm/v3d: Remove the bad signaled() implementation.

Since our seqno value comes from a counter associated with the GPU ring, not the entity (aka client), they'll be completed out of order. There's actually no need for this code at all, since we don't have enable_signaling() and thus DMA_FENCE_SIGNALED_BIT will be set before we could be called.

---
 drivers/gpu/drm/v3d/v3d_drv.h   |  1 -
 drivers/gpu/drm/v3d/v3d_fence.c | 13 ++++---------
 drivers/gpu/drm/v3d/v3d_gem.c   |  7 ++-----
 drivers/gpu/drm/v3d/v3d_irq.c   |  3 ---
 4 files changed, 6 insertions(+), 18 deletions(-)
drivers/gpu/drm/v3d/v3d_drv.h +0 -1
index 26005abd9c5d..f32ac8c98f37 100644
@@ -25,7 +25,6 @@ struct v3d_queue_state {
 
 	u64 fence_context;
 	u64 emit_seqno;
-	u64 finished_seqno;
 };
 
 struct v3d_dev {
drivers/gpu/drm/v3d/v3d_fence.c +4 -9
index 087d49c8cb12..bfe31a89668b 100644
@@ -40,19 +40,14 @@ static bool v3d_fence_enable_signaling(struct dma_fence *fence)
 	return true;
 }
 
-static bool v3d_fence_signaled(struct dma_fence *fence)
-{
-	struct v3d_fence *f = to_v3d_fence(fence);
-	struct v3d_dev *v3d = to_v3d_dev(f->dev);
-
-	return v3d->queue[f->queue].finished_seqno >= f->seqno;
-}
-
 const struct dma_fence_ops v3d_fence_ops = {
 	.get_driver_name = v3d_fence_get_driver_name,
 	.get_timeline_name = v3d_fence_get_timeline_name,
 	.enable_signaling = v3d_fence_enable_signaling,
-	.signaled = v3d_fence_signaled,
+	/* Each of our fences gets signaled as complete by the IRQ
+	 * handler, so we rely on the core's tracking of signaling.
+	 */
+	.signaled = NULL,
 	.wait = dma_fence_default_wait,
 	.release = dma_fence_free,
 };
drivers/gpu/drm/v3d/v3d_gem.c +2 -5
index 9ea83bdb9a30..d06d6697e089 100644
@@ -657,17 +657,14 @@ void
 v3d_gem_destroy(struct drm_device *dev)
 {
 	struct v3d_dev *v3d = to_v3d_dev(dev);
-	enum v3d_queue q;
 
 	v3d_sched_fini(v3d);
 
 	/* Waiting for exec to finish would need to be done before
 	 * unregistering V3D.
 	 */
-	for (q = 0; q < V3D_MAX_QUEUES; q++) {
-		WARN_ON(v3d->queue[q].emit_seqno !=
-			v3d->queue[q].finished_seqno);
-	}
+	WARN_ON(v3d->bin_job);
+	WARN_ON(v3d->render_job);
 
 	drm_mm_takedown(&v3d->mm);
 
drivers/gpu/drm/v3d/v3d_irq.c +0 -3
index 77e1fa046c10..e07514eb11b5 100644
@@ -87,15 +87,12 @@ v3d_irq(int irq, void *arg)
 	}
 
 	if (intsts & V3D_INT_FLDONE) {
-		v3d->queue[V3D_BIN].finished_seqno++;
 		dma_fence_signal(v3d->bin_job->bin.done_fence);
 		status = IRQ_HANDLED;
 	}
 
 	if (intsts & V3D_INT_FRDONE) {
-		v3d->queue[V3D_RENDER].finished_seqno++;
 		dma_fence_signal(v3d->render_job->render.done_fence);
-
 		status = IRQ_HANDLED;
 	}
 
Signature · 6 lines
2.17.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] drm/v3d: Remove the bad signaled() implementation.

Am Dienstag, den 05.06.2018, 12:03 -0700 schrieb Eric Anholt:

Quoted 7 lines

Since our seqno value comes from a counter associated with the GPU ring, not the entity (aka client), they'll be completed out of order. There's actually no need for this code at all, since we don't have enable_signaling() and thus DMA_FENCE_SIGNALED_BIT will be set before we could be called.

Quoted 92 lines

---
 drivers/gpu/drm/v3d/v3d_drv.h   |  1 - drivers/gpu/drm/v3d/v3d_fence.c | 13 ++++--------- drivers/gpu/drm/v3d/v3d_gem.c   |  7 ++----- drivers/gpu/drm/v3d/v3d_irq.c   |  3 ---

 4 files changed, 6 insertions(+), 18 deletions(-)
drivers/gpu/drm/v3d/v3d_drv.h +0 -0
index 26005abd9c5d..f32ac8c98f37 100644
@@ -25,7 +25,6 @@ struct v3d_queue_state {


  u64 fence_context;
  u64 emit_seqno;

drivers/gpu/drm/v3d/v3d_drv.h +0 -1
-	u64 finished_seqno;

 };

 struct v3d_dev {

drivers/gpu/drm/v3d/v3d_fence.c +0 -0
index 087d49c8cb12..bfe31a89668b 100644
@@ -40,19 +40,14 @@ static bool v3d_fence_enable_signaling(struct
 dma_fence *fence)
  	return true;
  }

drivers/gpu/drm/v3d/v3d_fence.c +0 -8
-static bool v3d_fence_signaled(struct dma_fence *fence)
-{
-	struct v3d_fence *f = to_v3d_fence(fence);
-	struct v3d_dev *v3d = to_v3d_dev(f->dev);
-
-	return v3d->queue[f->queue].finished_seqno >= f->seqno;
-}
-

 const struct dma_fence_ops v3d_fence_ops = { .get_driver_name = v3d_fence_get_driver_name, .get_timeline_name = v3d_fence_get_timeline_name, .enable_signaling = v3d_fence_enable_signaling,

drivers/gpu/drm/v3d/v3d_fence.c +4 -1
-	.signaled = v3d_fence_signaled,
+	/* Each of our fences gets signaled as complete by the IRQ
+	 * handler, so we rely on the core's tracking of signaling.
+	 */
+	.signaled = NULL,

  .wait = dma_fence_default_wait,
  .release = dma_fence_free,
 };

drivers/gpu/drm/v3d/v3d_gem.c +0 -1
index 9ea83bdb9a30..d06d6697e089 100644
@@ -657,17 +657,14 @@ void
  v3d_gem_destroy(struct drm_device *dev)
  {
  	struct v3d_dev *v3d = to_v3d_dev(dev);
-	enum v3d_queue q;


  v3d_sched_fini(v3d);

  /* Waiting for exec to finish would need to be done before
   * unregistering V3D.
   */

drivers/gpu/drm/v3d/v3d_gem.c +2 -4
-	for (q = 0; q < V3D_MAX_QUEUES; q++) {
-		WARN_ON(v3d->queue[q].emit_seqno !=
-			v3d->queue[q].finished_seqno);
-	}
+	WARN_ON(v3d->bin_job);
+	WARN_ON(v3d->render_job);


  drm_mm_takedown(&v3d->mm);

drivers/gpu/drm/v3d/v3d_irq.c +0 -0
index 77e1fa046c10..e07514eb11b5 100644
@@ -87,15 +87,12 @@ v3d_irq(int irq, void *arg)
  	}


  if (intsts & V3D_INT_FLDONE) {

drivers/gpu/drm/v3d/v3d_irq.c +0 -1
-		v3d->queue[V3D_BIN].finished_seqno++;

  dma_fence_signal(v3d->bin_job->bin.done_fence); status = IRQ_HANDLED;
  }

  if (intsts & V3D_INT_FRDONE) {

drivers/gpu/drm/v3d/v3d_irq.c +0 -1
-		v3d->queue[V3D_RENDER].finished_seqno++;

  dma_fence_signal(v3d->render_job-

Quoted 5 lines
Quoted 1 line

render.done_fence);

-
  status = IRQ_HANDLED;
  }

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

PATCH 3/3 drm/v3d: Add a note about locking of v3d_fence_create().

In reply to Eric Anholt

This isn't the first time I've had to argue to myself why the '++' was safe.

---
 drivers/gpu/drm/v3d/v3d_fence.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/v3d/v3d_fence.c +3 -0
index bfe31a89668b..6265e9ab4a13 100644
@@ -3,6 +3,9 @@
 
 #include "v3d_drv.h"
 
+/* Note that V3D fences are created during v3d_job_run(), so we're
+ * already implictly locked.
+ */
 struct dma_fence *v3d_fence_create(struct v3d_dev *v3d, enum v3d_queue queue)
 {
 	struct v3d_fence *fence;
Signature · 6 lines
2.17.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

Re: [PATCH 3/3] drm/v3d: Add a note about locking of v3d_fence_create().

Am Dienstag, den 05.06.2018, 12:03 -0700 schrieb Eric Anholt:

Quoted 2 lines

This isn't the first time I've had to argue to myself why the '++' was safe.

And now you need to do the same thing with me...

Quoted 10 lines

---
 drivers/gpu/drm/v3d/v3d_fence.c | 3 +++

 1 file changed, 3 insertions(+)
drivers/gpu/drm/v3d/v3d_fence.c +0 -0
index bfe31a89668b..6265e9ab4a13 100644
@@ -3,6 +3,9 @@
Quoted 6 lines


 #include "v3d_drv.h"

+/* Note that V3D fences are created during v3d_job_run(), so we're
+ * already implictly locked.
+ */

I don't see where you would be locked in the job_run path. I think what you mean is that this path needs no locks, as it is driven by a single scheduler thread, right?

Regards,
Lucas
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw

Re: [PATCH 3/3] drm/v3d: Add a note about locking of v3d_fence_create().

Quoted 11 lines · Lucas Stach

Am Dienstag, den 05.06.2018, 12:03 -0700 schrieb Eric Anholt:

Quoted 2 lines

This isn't the first time I've had to argue to myself why the '++' was safe.

And now you need to do the same thing with me...

Quoted 5 lines

---
 drivers/gpu/drm/v3d/v3d_fence.c | 3 +++

 1 file changed, 3 insertions(+)
Quoted 14 lines
Quoted 11 lines
drivers/gpu/drm/v3d/v3d_fence.c +0 -0
index bfe31a89668b..6265e9ab4a13 100644
@@ -3,6 +3,9 @@


 #include "v3d_drv.h"

+/* Note that V3D fences are created during v3d_job_run(), so we're
+ * already implictly locked.
+ */

I don't see where you would be locked in the job_run path. I think what you mean is that this path needs no locks, as it is driven by a single scheduler thread, right?

Yeah, it's only called from run_job, and run_job can't reenter.

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#6 lore raw
In reply to Eric Anholt

Am Dienstag, den 05.06.2018, 12:03 -0700 schrieb Eric Anholt:

Quoted 38 lines

Between creation and queueing of a job, you need to prevent any other job from being created and queued.  Otherwise the scheduler's fences may be signaled out of seqno order.

Quoted 1 line
Fixes 57692c94dcbe ("drm/v3d: Introduce a new DRM driver for Broadcom V3D V3.x+")

---

ccing amd-gfx due to interaction of this series with the scheduler.

 drivers/gpu/drm/v3d/v3d_drv.h |  5 +++++
 drivers/gpu/drm/v3d/v3d_gem.c | 11 +++++++++--

 2 files changed, 14 insertions(+), 2 deletions(-)
drivers/gpu/drm/v3d/v3d_drv.h +0 -0
index a043ac3aae98..26005abd9c5d 100644
@@ -85,6 +85,11 @@ struct v3d_dev {
Quoted 2 lines

   */
  struct mutex reset_lock;

drivers/gpu/drm/v3d/v3d_drv.h struct v3d_dev { · line 91

Quoted 4 lines
drivers/gpu/drm/v3d/v3d_drv.h +4 -0
+	/* Lock taken when creating and pushing the GPU scheduler
+	 * jobs, to keep the sched-fence seqnos in order.
+	 */
+	struct mutex sched_lock;

+

Quoted 3 lines

  struct {
  u32 num_allocated;
  u32 pages_allocated;

drivers/gpu/drm/v3d/v3d_gem.c +0 -0
index b513f9189caf..9ea83bdb9a30 100644
@@ -550,13 +550,16 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
 >  	if (ret)
 >  		goto fail;

Quoted 10 lines

drivers/gpu/drm/v3d/v3d_gem.c v3d_submit_cl_ioctl(struct drm_device *dev, void *data, · line 560

Quoted 9 lines
drivers/gpu/drm/v3d/v3d_gem.c +1 -0
+	mutex_lock(&v3d->sched_lock);

  if (exec->bin.start != exec->bin.end) {
  ret = drm_sched_job_init(&exec->bin.base, &v3d->queue[V3D_BIN].sched, &v3d_priv->sched_entity[V3D_BIN], v3d_priv);

drivers/gpu/drm/v3d/v3d_gem.c +2 -1
-		if (ret)
+		if (ret) {
+			mutex_unlock(&v3d->sched_lock);

  goto fail_unreserve;

I don't see any path where you would go to fail_unreserve with the mutex not yet locked, so you could just fold the mutex_unlock into this error path for a bit less code duplication.

Otherwise this looks fine.

Regards,
Lucas

Quoted 26 lines
drivers/gpu/drm/v3d/v3d_gem.c +1 -0
+		}

Quoted 2 lines

  exec->bin_done_fence = dma_fence_get(&exec->bin.base.s_fence->finished);

drivers/gpu/drm/v3d/v3d_gem.c +0 -0
@@ -570,12 +573,15 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
 >  				 &v3d->queue[V3D_RENDER].sched,
 >  				 &v3d_priv->sched_entity[V3D_RENDER],
 >  				 v3d_priv);
 > -	if (ret)
 > +	if (ret) {
 > +		mutex_unlock(&v3d->sched_lock);
 >  		goto fail_unreserve;
 > +	}

Review

Quoted 4 lines

  kref_get(&exec->refcount); /* put by scheduler job completion */ drm_sched_entity_push_job(&exec->render.base, &v3d_priv->sched_entity[V3D_RENDER]);

(quoted diff) +1 -0
+	mutex_unlock(&v3d->sched_lock);

Quoted 1 line

  v3d_attach_object_fences(exec);

drivers/gpu/drm/v3d/v3d_gem.c +0 -0
@@ -615,6 +621,7 @@ v3d_gem_init(struct drm_device *dev)
 >  	spin_lock_init(&v3d->job_lock);
 >  	mutex_init(&v3d->bo_lock);
 >  	mutex_init(&v3d->reset_lock);
 > +	mutex_init(&v3d->sched_lock);
Quoted 3 lines

Quoted 2 lines

  /* Note: We don't allocate address 0.  Various bits of HW
   * treat 0 as special, such as the occlusion query counters

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#7 lore raw

Am 06.06.2018 um 10:46 schrieb Lucas Stach:

Quoted 49 lines

Am Dienstag, den 05.06.2018, 12:03 -0700 schrieb Eric Anholt:

Quoted 38 lines

Between creation and queueing of a job, you need to prevent any other job from being created and queued.  Otherwise the scheduler's fences may be signaled out of seqno order.

Quoted 1 line
Fixes 57692c94dcbe ("drm/v3d: Introduce a new DRM driver for Broadcom V3D V3.x+")

---

ccing amd-gfx due to interaction of this series with the scheduler.

  drivers/gpu/drm/v3d/v3d_drv.h |  5 +++++
  drivers/gpu/drm/v3d/v3d_gem.c | 11 +++++++++--
  2 files changed, 14 insertions(+), 2 deletions(-)
drivers/gpu/drm/v3d/v3d_drv.h +0 -0
index a043ac3aae98..26005abd9c5d 100644
@@ -85,6 +85,11 @@ struct v3d_dev {

drivers/gpu/drm/v3d/v3d_drv.h struct v3d_dev { · line 91

Quoted 7 lines

   */
  struct mutex reset_lock;

drivers/gpu/drm/v3d/v3d_drv.h +4 -0
+	/* Lock taken when creating and pushing the GPU scheduler
+	 * jobs, to keep the sched-fence seqnos in order.
+	 */
+	struct mutex sched_lock;

+

Quoted 3 lines

  struct {
  u32 num_allocated;
  u32 pages_allocated;

drivers/gpu/drm/v3d/v3d_gem.c +0 -0
index b513f9189caf..9ea83bdb9a30 100644
@@ -550,13 +550,16 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
 >   	if (ret)
 >   		goto fail;
 

drivers/gpu/drm/v3d/v3d_gem.c v3d_submit_cl_ioctl(struct drm_device *dev, void *data, · line 562

Quoted 10 lines
drivers/gpu/drm/v3d/v3d_gem.c +0 -0
 > +	mutex_lock(&v3d->sched_lock);
 >   	if (exec->bin.start != exec->bin.end) {
 >   		ret = drm_sched_job_init(&exec->bin.base,
 >   					 &v3d->queue[V3D_BIN].sched,
 >   					 &v3d_priv->sched_entity[V3D_BIN],
 >   					 v3d_priv);
 > -		if (ret)
 > +		if (ret) {
 > +			mutex_unlock(&v3d->sched_lock);
  			goto fail_unreserve;
Quoted 5 lines

I don't see any path where you would go to fail_unreserve with the mutex not yet locked, so you could just fold the mutex_unlock into this error path for a bit less code duplication.

Otherwise this looks fine.

Yeah, agree that could be cleaned up.

I can't judge the correctness of the driver, but at least the scheduler handling looks good to me.

Regards,
Christian.

Quoted 37 lines

Regards,
Lucas

Quoted 27 lines
drivers/gpu/drm/v3d/v3d_gem.c +1 -0
+		}
Quoted 3 lines

  exec->bin_done_fence = dma_fence_get(&exec->bin.base.s_fence->finished);

drivers/gpu/drm/v3d/v3d_gem.c +0 -0
@@ -570,12 +573,15 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
 >   				 &v3d->queue[V3D_RENDER].sched,
 >   				 &v3d_priv->sched_entity[V3D_RENDER],
 >   				 v3d_priv);
 > -	if (ret)
 > +	if (ret) {
 > +		mutex_unlock(&v3d->sched_lock);
 >   		goto fail_unreserve;
 > +	}
 
Quoted 6 lines

  kref_get(&exec->refcount); /* put by scheduler job completion */ drm_sched_entity_push_job(&exec->render.base, &v3d_priv->sched_entity[V3D_RENDER]);

drivers/gpu/drm/v3d/v3d_gem.c +1 -0
+	mutex_unlock(&v3d->sched_lock);
 
  	v3d_attach_object_fences(exec);
drivers/gpu/drm/v3d/v3d_gem.c +0 -0
@@ -615,6 +621,7 @@ v3d_gem_init(struct drm_device *dev)
 >   	spin_lock_init(&v3d->job_lock);
 >   	mutex_init(&v3d->bo_lock);
 >   	mutex_init(&v3d->reset_lock);
 > +	mutex_init(&v3d->sched_lock);
 
Quoted 2 lines
Quoted 2 lines

  /* Note: We don't allocate address 0.  Various bits of HW
   * treat 0 as special, such as the occlusion query counters

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#8 lore raw

PATCH v2 1/3 drm/v3d: Take a lock across GPU scheduler job creation and queuing.

In reply to Lucas Stach

Between creation and queueing of a job, you need to prevent any other job from being created and queued. Otherwise the scheduler's fences may be signaled out of seqno order.

v2: move mutex unlock to the error label.

Fixes 57692c94dcbe ("drm/v3d: Introduce a new DRM driver for Broadcom V3D V3.x+")
---
 drivers/gpu/drm/v3d/v3d_drv.h | 5 +++++
 drivers/gpu/drm/v3d/v3d_gem.c | 4 ++++
 2 files changed, 9 insertions(+)
drivers/gpu/drm/v3d/v3d_drv.h +5 -0
index a043ac3aae98..26005abd9c5d 100644
@@ -85,6 +85,11 @@ struct v3d_dev {
 	 */
 	struct mutex reset_lock;
 
+	/* Lock taken when creating and pushing the GPU scheduler
+	 * jobs, to keep the sched-fence seqnos in order.
+	 */
+	struct mutex sched_lock;
+
 	struct {
 		u32 num_allocated;
 		u32 pages_allocated;
drivers/gpu/drm/v3d/v3d_gem.c +4 -0
index b513f9189caf..269fe16379c0 100644
@@ -550,6 +550,7 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
 	if (ret)
 		goto fail;
 
+	mutex_lock(&v3d->sched_lock);
 	if (exec->bin.start != exec->bin.end) {
 		ret = drm_sched_job_init(&exec->bin.base,
 					 &v3d->queue[V3D_BIN].sched,
@@ -576,6 +577,7 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
 	kref_get(&exec->refcount); /* put by scheduler job completion */
 	drm_sched_entity_push_job(&exec->render.base,
 				  &v3d_priv->sched_entity[V3D_RENDER]);
+	mutex_unlock(&v3d->sched_lock);
 
 	v3d_attach_object_fences(exec);
 
@@ -594,6 +596,7 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
 	return 0;
 
 fail_unreserve:
+	mutex_unlock(&v3d->sched_lock);
 	v3d_unlock_bo_reservations(dev, exec, &acquire_ctx);
 fail:
 	v3d_exec_put(exec);
@@ -615,6 +618,7 @@ v3d_gem_init(struct drm_device *dev)
 	spin_lock_init(&v3d->job_lock);
 	mutex_init(&v3d->bo_lock);
 	mutex_init(&v3d->reset_lock);
+	mutex_init(&v3d->sched_lock);
 
 	/* Note: We don't allocate address 0.  Various bits of HW
 	 * treat 0 as special, such as the occlusion query counters
Signature · 6 lines
2.17.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v2 1/3
#9 lore raw

Am Mittwoch, den 06.06.2018, 10:48 -0700 schrieb Eric Anholt:

Quoted 8 lines

Between creation and queueing of a job, you need to prevent any other job from being created and queued.  Otherwise the scheduler's fences may be signaled out of seqno order.

v2: move mutex unlock to the error label.

Quoted 1 line
Fixes 57692c94dcbe ("drm/v3d: Introduce a new DRM driver for Broadcom V3D V3.x+")
Quoted 54 lines

---
 drivers/gpu/drm/v3d/v3d_drv.h | 5 +++++
 drivers/gpu/drm/v3d/v3d_gem.c | 4 ++++

 2 files changed, 9 insertions(+)
drivers/gpu/drm/v3d/v3d_drv.h +0 -0
index a043ac3aae98..26005abd9c5d 100644
@@ -85,6 +85,11 @@ struct v3d_dev {
Quoted 2 lines

   */
  struct mutex reset_lock;

drivers/gpu/drm/v3d/v3d_drv.h struct v3d_dev { · line 91

Quoted 4 lines
drivers/gpu/drm/v3d/v3d_drv.h +4 -0
+	/* Lock taken when creating and pushing the GPU scheduler
+	 * jobs, to keep the sched-fence seqnos in order.
+	 */
+	struct mutex sched_lock;

+

Quoted 3 lines

  struct {
  u32 num_allocated;
  u32 pages_allocated;

drivers/gpu/drm/v3d/v3d_gem.c +0 -0
index b513f9189caf..269fe16379c0 100644
@@ -550,6 +550,7 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
 >  	if (ret)
 >  		goto fail;

Quoted 4 lines
drivers/gpu/drm/v3d/v3d_gem.c +1 -0
+	mutex_lock(&v3d->sched_lock);

  if (exec->bin.start != exec->bin.end) {
  ret = drm_sched_job_init(&exec->bin.base, &v3d->queue[V3D_BIN].sched,

drivers/gpu/drm/v3d/v3d_gem.c +0 -0
@@ -576,6 +577,7 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,

Review

Quoted 4 lines

  kref_get(&exec->refcount); /* put by scheduler job completion */ drm_sched_entity_push_job(&exec->render.base, &v3d_priv->sched_entity[V3D_RENDER]);

(quoted diff) +1 -0
+	mutex_unlock(&v3d->sched_lock);

Quoted 1 line

  v3d_attach_object_fences(exec);

drivers/gpu/drm/v3d/v3d_gem.c +0 -0
@@ -594,6 +596,7 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
 >  	return 0;


 fail_unreserve:

Quoted 2 lines
(quoted diff) +1 -0
+	mutex_unlock(&v3d->sched_lock);

  v3d_unlock_bo_reservations(dev, exec, &acquire_ctx);

 fail:

Quoted 1 line

  v3d_exec_put(exec);

drivers/gpu/drm/v3d/v3d_gem.c +0 -0
@@ -615,6 +618,7 @@ v3d_gem_init(struct drm_device *dev)
 >  	spin_lock_init(&v3d->job_lock);
 >  	mutex_init(&v3d->bo_lock);
 >  	mutex_init(&v3d->reset_lock);
 > +	mutex_init(&v3d->sched_lock);
Quoted 3 lines

Quoted 2 lines

  /* Note: We don't allocate address 0.  Various bits of HW
   * treat 0 as special, such as the occlusion query counters

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel