| From d16dffa06e94a766cc508fb659b0d88b8ae6fc6a Mon Sep 17 00:00:00 2001 |
| From: Sasha Levin <sashal@kernel.org> |
| Date: Sat, 13 Jun 2020 20:30:25 +0800 |
| Subject: drm/ttm: Fix dma_fence refcnt leak when adding move fence |
| MIME-Version: 1.0 |
| Content-Type: text/plain; charset=UTF-8 |
| Content-Transfer-Encoding: 8bit |
| |
| From: Xiyu Yang <xiyuyang19@fudan.edu.cn> |
| |
| [ Upstream commit 11425c4519e2c974a100fc984867046d905b9380 ] |
| |
| ttm_bo_add_move_fence() invokes dma_fence_get(), which returns a |
| reference of the specified dma_fence object to "fence" with increased |
| refcnt. |
| |
| When ttm_bo_add_move_fence() returns, local variable "fence" becomes |
| invalid, so the refcount should be decreased to keep refcount balanced. |
| |
| The reference counting issue happens in one exception handling path of |
| ttm_bo_add_move_fence(). When no_wait_gpu flag is equals to true, the |
| function forgets to decrease the refcnt increased by dma_fence_get(), |
| causing a refcnt leak. |
| |
| Fix this issue by calling dma_fence_put() when no_wait_gpu flag is |
| equals to true. |
| |
| Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn> |
| Signed-off-by: Xin Tan <tanxin.ctf@gmail.com> |
| Reviewed-by: Christian König <christian.koenig@amd.com> |
| Link: https://patchwork.freedesktop.org/patch/370221/ |
| Signed-off-by: Christian König <christian.koenig@amd.com> |
| Signed-off-by: Sasha Levin <sashal@kernel.org> |
| --- |
| drivers/gpu/drm/ttm/ttm_bo.c | 4 +++- |
| 1 file changed, 3 insertions(+), 1 deletion(-) |
| |
| diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c |
| index abf165b2f64fc..3ce8ad7603c7f 100644 |
| --- a/drivers/gpu/drm/ttm/ttm_bo.c |
| +++ b/drivers/gpu/drm/ttm/ttm_bo.c |
| @@ -941,8 +941,10 @@ static int ttm_bo_add_move_fence(struct ttm_buffer_object *bo, |
| if (!fence) |
| return 0; |
| |
| - if (no_wait_gpu) |
| + if (no_wait_gpu) { |
| + dma_fence_put(fence); |
| return -EBUSY; |
| + } |
| |
| dma_resv_add_shared_fence(bo->base.resv, fence); |
| |
| -- |
| 2.25.1 |
| |