Re: [PATCH 1/3 v2] drm/v3d: Take a lock across GPU scheduler job creation and queuing.
From: Lucas Stach
Date: Thu Jun 07 2018 - 04:37:48 EST
Am Mittwoch, den 06.06.2018, 10:48 -0700 schrieb Eric Anholt:
> 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.
>
> > Signed-off-by: Eric Anholt <eric@xxxxxxxxxx>
> Fixes: 57692c94dcbe ("drm/v3d: Introduce a new DRM driver for Broadcom V3D V3.x+")
Reviewed-by: Lucas Stach <l.stach@xxxxxxxxxxxxxx>
> ---
> Âdrivers/gpu/drm/v3d/v3d_drv.h | 5 +++++
> Âdrivers/gpu/drm/v3d/v3d_gem.c | 4 ++++
> Â2 files changed, 9 insertions(+)
>
> diff --git a/drivers/gpu/drm/v3d/v3d_drv.h b/drivers/gpu/drm/v3d/v3d_drv.h
> index a043ac3aae98..26005abd9c5d 100644
> --- a/drivers/gpu/drm/v3d/v3d_drv.h
> +++ b/drivers/gpu/drm/v3d/v3d_drv.h
> @@ -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;
> diff --git a/drivers/gpu/drm/v3d/v3d_gem.c b/drivers/gpu/drm/v3d/v3d_gem.c
> index b513f9189caf..269fe16379c0 100644
> --- a/drivers/gpu/drm/v3d/v3d_gem.c
> +++ b/drivers/gpu/drm/v3d/v3d_gem.c
> @@ -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