Skip to content

Commit

Permalink
drm/msm: Protect ring->submits with it's own lock
Browse files Browse the repository at this point in the history
One less place to rely on dev->struct_mutex.

Signed-off-by: Rob Clark <[email protected]>
Reviewed-by: Jordan Crouse <[email protected]>
Reviewed-by: Kristian H. Kristensen <[email protected]>
Signed-off-by: Rob Clark <[email protected]>
  • Loading branch information
robclark committed Nov 5, 2020
1 parent 77c4060 commit 77d2052
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
2 changes: 2 additions & 0 deletions drivers/gpu/drm/msm/msm_gem_submit.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ void msm_gem_submit_free(struct msm_gem_submit *submit)
unsigned i;

dma_fence_put(submit->fence);
spin_lock(&submit->ring->submit_lock);
list_del(&submit->node);
spin_unlock(&submit->ring->submit_lock);
put_pid(submit->pid);
msm_submitqueue_put(submit->queue);

Expand Down
37 changes: 30 additions & 7 deletions drivers/gpu/drm/msm/msm_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,15 @@ static void update_fences(struct msm_gpu *gpu, struct msm_ringbuffer *ring,
{
struct msm_gem_submit *submit;

spin_lock(&ring->submit_lock);
list_for_each_entry(submit, &ring->submits, node) {
if (submit->seqno > fence)
break;

msm_update_fence(submit->ring->fctx,
submit->fence->seqno);
}
spin_unlock(&ring->submit_lock);
}

#ifdef CONFIG_DEV_COREDUMP
Expand Down Expand Up @@ -429,11 +431,14 @@ find_submit(struct msm_ringbuffer *ring, uint32_t fence)
{
struct msm_gem_submit *submit;

WARN_ON(!mutex_is_locked(&ring->gpu->dev->struct_mutex));

list_for_each_entry(submit, &ring->submits, node)
if (submit->seqno == fence)
spin_lock(&ring->submit_lock);
list_for_each_entry(submit, &ring->submits, node) {
if (submit->seqno == fence) {
spin_unlock(&ring->submit_lock);
return submit;
}
}
spin_unlock(&ring->submit_lock);

return NULL;
}
Expand Down Expand Up @@ -530,8 +535,10 @@ static void recover_worker(struct kthread_work *work)
for (i = 0; i < gpu->nr_rings; i++) {
struct msm_ringbuffer *ring = gpu->rb[i];

spin_lock(&ring->submit_lock);
list_for_each_entry(submit, &ring->submits, node)
gpu->funcs->submit(gpu, submit);
spin_unlock(&ring->submit_lock);
}
}

Expand Down Expand Up @@ -717,7 +724,6 @@ static void retire_submit(struct msm_gpu *gpu, struct msm_ringbuffer *ring,
static void retire_submits(struct msm_gpu *gpu)
{
struct drm_device *dev = gpu->dev;
struct msm_gem_submit *submit, *tmp;
int i;

WARN_ON(!mutex_is_locked(&dev->struct_mutex));
Expand All @@ -726,9 +732,24 @@ static void retire_submits(struct msm_gpu *gpu)
for (i = 0; i < gpu->nr_rings; i++) {
struct msm_ringbuffer *ring = gpu->rb[i];

list_for_each_entry_safe(submit, tmp, &ring->submits, node) {
if (dma_fence_is_signaled(submit->fence))
while (true) {
struct msm_gem_submit *submit = NULL;

spin_lock(&ring->submit_lock);
submit = list_first_entry_or_null(&ring->submits,
struct msm_gem_submit, node);
spin_unlock(&ring->submit_lock);

/*
* If no submit, we are done. If submit->fence hasn't
* been signalled, then later submits are not signalled
* either, so we are also done.
*/
if (submit && dma_fence_is_signaled(submit->fence)) {
retire_submit(gpu, ring, submit);
} else {
break;
}
}
}
}
Expand Down Expand Up @@ -770,7 +791,9 @@ void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit)

submit->seqno = ++ring->seqno;

spin_lock(&ring->submit_lock);
list_add_tail(&submit->node, &ring->submits);
spin_unlock(&ring->submit_lock);

msm_rd_dump_submit(priv->rd, submit, NULL);

Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/msm/msm_ringbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id,
ring->memptrs_iova = memptrs_iova;

INIT_LIST_HEAD(&ring->submits);
spin_lock_init(&ring->submit_lock);
spin_lock_init(&ring->preempt_lock);

snprintf(name, sizeof(name), "gpu-ring-%d", ring->id);
Expand Down
6 changes: 6 additions & 0 deletions drivers/gpu/drm/msm/msm_ringbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ struct msm_ringbuffer {
int id;
struct drm_gem_object *bo;
uint32_t *start, *end, *cur, *next;

/*
* List of in-flight submits on this ring. Protected by submit_lock.
*/
struct list_head submits;
spinlock_t submit_lock;

uint64_t iova;
uint32_t seqno;
uint32_t hangcheck_fence;
Expand Down

0 comments on commit 77d2052

Please sign in to comment.