drm/ttm: Fix dma_fence refcnt leak in ttm_bo_vm_fault_reserved
authorXiyu Yang <xiyuyang19@fudan.edu.cn>
Sat, 13 Jun 2020 12:28:38 +0000 (20:28 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 16 Jul 2020 06:13:11 +0000 (08:13 +0200)
commitf5e6ec57e3cbe37cd3ef52d18de6be9953ee105a
treec1dc64517c2b8a411c1afc0c8bb07629aa730b20
parent130ca84cdc6a0db0a06fb43e0792222a46198eef
drm/ttm: Fix dma_fence refcnt leak in ttm_bo_vm_fault_reserved

[ Upstream commit 37cc4b95d13f311c04aa8e9daacca3905ad45ca7 ]

ttm_bo_vm_fault_reserved() invokes dma_fence_get(), which returns a
reference of the specified dma_fence object to "moving" with increased
refcnt.

When ttm_bo_vm_fault_reserved() returns, local variable "moving" becomes
invalid, so the refcount should be decreased to keep refcount balanced.

The reference counting issue happens in several exception handling paths
of ttm_bo_vm_fault_reserved(). When those error scenarios occur such as
"err" equals to -EBUSY, 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/370219/
Signed-off-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/ttm/ttm_bo_vm.c