Skip to content

Commit

Permalink
drm/msm: Fix hw_fence error path cleanup
Browse files Browse the repository at this point in the history
[ Upstream commit 1cd0787 ]

In an error path where the submit is free'd without the job being run,
the hw_fence pointer is simply a kzalloc'd block of memory.  In this
case we should just kfree() it, rather than trying to decrement it's
reference count.  Fortunately we can tell that this is the case by
checking for a zero refcount, since if the job was run, the submit would
be holding a reference to the hw_fence.

Fixes: f94e6a5 ("drm/msm: Pre-allocate hw_fence")
Signed-off-by: Rob Clark <robdclark@chromium.org>
Patchwork: https://patchwork.freedesktop.org/patch/547088/
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
robclark authored and gregkh committed Aug 3, 2023
1 parent 8ac09b9 commit e280832
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions drivers/gpu/drm/msm/msm_fence.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ msm_fence_init(struct dma_fence *fence, struct msm_fence_context *fctx)

f->fctx = fctx;

/*
* Until this point, the fence was just some pre-allocated memory,
* no-one should have taken a reference to it yet.
*/
WARN_ON(kref_read(&fence->refcount));

dma_fence_init(&f->base, &msm_fence_ops, &fctx->spinlock,
fctx->context, ++fctx->last_fence);
}
14 changes: 13 additions & 1 deletion drivers/gpu/drm/msm/msm_gem_submit.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,19 @@ void __msm_gem_submit_destroy(struct kref *kref)
}

dma_fence_put(submit->user_fence);
dma_fence_put(submit->hw_fence);

/*
* If the submit is freed before msm_job_run(), then hw_fence is
* just some pre-allocated memory, not a reference counted fence.
* Once the job runs and the hw_fence is initialized, it will
* have a refcount of at least one, since the submit holds a ref
* to the hw_fence.
*/
if (kref_read(&submit->hw_fence->refcount) == 0) {
kfree(submit->hw_fence);
} else {
dma_fence_put(submit->hw_fence);
}

put_pid(submit->pid);
msm_submitqueue_put(submit->queue);
Expand Down

0 comments on commit e280832

Please sign in to comment.