linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/ttm: Fix dma_fence refcnt leak in ttm_bo_vm_fault_reserved
@ 2020-06-13 12:28 Xiyu Yang
  2020-06-13 15:08 ` Christian König
  0 siblings, 1 reply; 2+ messages in thread
From: Xiyu Yang @ 2020-06-13 12:28 UTC (permalink / raw)
  To: Christian Koenig, Huang Rui, David Airlie, Daniel Vetter,
	Sumit Semwal, dri-devel, linux-kernel, linux-media,
	linaro-mm-sig
  Cc: yuanxzhang, kjlu, Xiyu Yang, Xin Tan

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>
---
 drivers/gpu/drm/ttm/ttm_bo_vm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index a43aa7275f12..fa03fab02076 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -300,8 +300,10 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,
 			break;
 		case -EBUSY:
 		case -ERESTARTSYS:
+			dma_fence_put(moving);
 			return VM_FAULT_NOPAGE;
 		default:
+			dma_fence_put(moving);
 			return VM_FAULT_SIGBUS;
 		}
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/ttm: Fix dma_fence refcnt leak in ttm_bo_vm_fault_reserved
  2020-06-13 12:28 [PATCH] drm/ttm: Fix dma_fence refcnt leak in ttm_bo_vm_fault_reserved Xiyu Yang
@ 2020-06-13 15:08 ` Christian König
  0 siblings, 0 replies; 2+ messages in thread
From: Christian König @ 2020-06-13 15:08 UTC (permalink / raw)
  To: Xiyu Yang, Huang Rui, David Airlie, Daniel Vetter, Sumit Semwal,
	dri-devel, linux-kernel, linux-media, linaro-mm-sig
  Cc: yuanxzhang, kjlu, Xin Tan

Am 13.06.20 um 14:28 schrieb Xiyu Yang:
> 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>

Good catch, Reviewed-by: Christian König <christian.koenig@amd.com>.

Going to pick that up for drm-misc-fixes.

Christian.

> ---
>   drivers/gpu/drm/ttm/ttm_bo_vm.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> index a43aa7275f12..fa03fab02076 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> @@ -300,8 +300,10 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,
>   			break;
>   		case -EBUSY:
>   		case -ERESTARTSYS:
> +			dma_fence_put(moving);
>   			return VM_FAULT_NOPAGE;
>   		default:
> +			dma_fence_put(moving);
>   			return VM_FAULT_SIGBUS;
>   		}
>   


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-13 15:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-13 12:28 [PATCH] drm/ttm: Fix dma_fence refcnt leak in ttm_bo_vm_fault_reserved Xiyu Yang
2020-06-13 15:08 ` Christian König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).