From patchwork Thu Nov 15 03:52:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seung-Woo Kim X-Patchwork-Id: 1745251 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 8D8F43FCA5 for ; Thu, 15 Nov 2012 03:52:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F40DC9E82D for ; Wed, 14 Nov 2012 19:52:53 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by gabe.freedesktop.org (Postfix) with ESMTP id 5D8DA9E733 for ; Wed, 14 Nov 2012 19:52:41 -0800 (PST) Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MDI00BLQG3N6CI0@mailout3.samsung.com> for dri-devel@lists.freedesktop.org; Thu, 15 Nov 2012 12:52:39 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [203.254.230.46]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 10.3D.12699.70764A05; Thu, 15 Nov 2012 12:52:39 +0900 (KST) X-AuditID: cbfee61b-b7f616d00000319b-7f-50a467070ad1 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 7F.2D.12699.70764A05; Thu, 15 Nov 2012 12:52:39 +0900 (KST) Received: from localhost.localdomain ([10.90.51.68]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MDI002YWG3O2530@mmp1.samsung.com> for dri-devel@lists.freedesktop.org; Thu, 15 Nov 2012 12:52:39 +0900 (KST) From: Seung-Woo Kim To: dri-devel@lists.freedesktop.org, airlied@linux.ie Subject: [RESEND][PATCH] drm/prime: drop reference on imported dma-buf come from gem Date: Thu, 15 Nov 2012 12:52:54 +0900 Message-id: <1352951574-19228-1-git-send-email-sw0312.kim@samsung.com> X-Mailer: git-send-email 1.7.4.1 In-reply-to: <1348727406-4191-1-git-send-email-sw0312.kim@samsung.com> References: <1348727406-4191-1-git-send-email-sw0312.kim@samsung.com> DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrLLMWRmVeSWpSXmKPExsVy+t8zPV329CUBBlsnK1hc+fqezYHR4373 caYAxigum5TUnMyy1CJ9uwSujGUtj9kKfihWnH01kaWB8Zd0FyMnh4SAicSTS1MYIWwxiQv3 1rOB2EICyxglzj8Rhqn5//cZSxcjF1B8EaPE1+0noJwVTBLb2tayglSxCehI7F/yG8wWETCV OHv5GjNIEbPAVkaJQ8tfgyWEBcIkns7YCLaORUBVYsq+m2A2r4CbxLT/m5kh1ilILLj3FuwM TqD4u5mLoE5ylWj738MK0Ssg8W3yIaArOIDqZSU2HQDbJSFwmU1i/71+Jog5khIHV9xgmcAo vICRYRWjaGpBckFxUnqukV5xYm5xaV66XnJ+7iZGSBhK72Bc1WBxiFGAg1GJh9fi4+IAIdbE suLK3EOMEhzMSiK8Lw4ChXhTEiurUovy44tKc1KLDzH6AF0ykVlKNDkfGCN5JfGGxgbGhoaW hmamlqYGOISVxHmbPVIChATSE0tSs1NTC1KLYMYxcXBKNTA2vfuQ+44v9MjKOau7zDtEZ13j b7wSUXVXrLX6bmT3np3TFmQ+09uu6KEzP/PtpP8JTNc2Oxbv/MV21Nbs2KePAUl+jrcCpVyN mhd9339AYfXp1wZ9UqKbPsfVzy7iqplitfWO1lbGxp3OksJL72m/kNp08MC2VVWXXlZG/3jc yc566PfCP4XKSizFGYmGWsxFxYkAiEDWo3ACAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplkeLIzCtJLcpLzFFi42I5/e+xgC57+pIAg4VvBSyufH3P5sDocb/7 OFMAY1QDo01GamJKapFCal5yfkpmXrqtkndwvHO8qZmBoa6hpYW5kkJeYm6qrZKLT4CuW2YO 0FglhbLEnFKgUEBicbGSvh2mCaEhbroWMI0Rur4hQXA9RgZoIGEdY8aylsdsBT8UK86+msjS wPhLuouRk0NCwETi/99nLBC2mMSFe+vZuhi5OIQEFjFKfN1+ggXCWcEksa1tLStIFZuAjsT+ Jb/BbBEBU4mzl68xgxQxC2xllDi0/DVYQlggTOLpjI2MIDaLgKrElH03wWxeATeJaf83M0Os U5BYcO8tG4jNCRR/N3MRmC0k4CrR9r+HdQIj7wJGhlWMoqkFyQXFSem5RnrFibnFpXnpesn5 uZsYwWH+THoH46oGi0OMAhyMSjy8Fh8XBwixJpYVV+YeYpTgYFYS4X1xECjEm5JYWZValB9f VJqTWnyI0QfoqonMUqLJ+cAYzCuJNzQ2MTOyNDIzNjE3NsYhrCTO2+yREiAkkJ5YkpqdmlqQ WgQzjomDU6qBsf3rctWPFxJ5gv8Vbdp+Xn/qkpDC31WGezgroszLklRLgpatujx/Q/vOaRs9 /k65kpqpGqxkcvmpIKuIyyPNh2qaZ28cDjvfGKu0PqPnM5+Szk/NSext2XvWq8U0ndSo/Mlz j01r4raeRcxLb3R1zF2vs+gr26/Ua7lizgsdcmS2X33xYKVLkBJLcUaioRZzUXEiAGWcynmg AgAA X-CFilter-Loop: Reflected Cc: daniel.vetter@ffwll.ch, sw0312.kim@samsung.com, rob.clark@linaro.org, kyungmin.park@samsung.com, alexander.deucher@amd.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Increasing ref counts of both dma-buf and gem for imported dma-buf come from gem makes memory leak. release function of dma-buf cannot be called because f_count of dma-buf increased by importing gem and gem ref count cannot be decrease because of exported dma-buf. So I add dma_buf_put() for imported gem come from its own gem into each drivers having prime_import and prime_export capabilities. With this, only gem ref count is increased if importing gem exported from gem of same driver. Signed-off-by: Seung-Woo Kim Signed-off-by: Kyungmin.park Cc: Inki Dae Cc: Daniel Vetter Cc: Rob Clark Cc: Alex Deucher Acked-by: Inki Dae --- Mmap failiure in i915 was reported by Jani, and I think it was fixed with Dave's commit "drm/prime: add exported buffers to current fprivs imported buffer list (v2)", so I resend this patch. I can send exynos only, but this issue is common in all drm driver having both prime inport and export, IMHO, it's better to send for all drivers. drivers/gpu/drm/exynos/exynos_drm_dmabuf.c | 5 +++++ drivers/gpu/drm/i915/i915_gem_dmabuf.c | 5 +++++ drivers/gpu/drm/nouveau/nouveau_prime.c | 1 + drivers/gpu/drm/radeon/radeon_prime.c | 1 + drivers/staging/omapdrm/omap_gem_dmabuf.c | 5 +++++ 5 files changed, 17 insertions(+), 0 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c b/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c index ae13feb..b0897c9 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +++ b/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c @@ -211,7 +211,12 @@ struct drm_gem_object *exynos_dmabuf_prime_import(struct drm_device *drm_dev, /* is it from our device? */ if (obj->dev == drm_dev) { + /* + * Importing dmabuf exported from out own gem increases + * refcount on gem itself instead of f_count of dmabuf. + */ drm_gem_object_reference(obj); + dma_buf_put(dma_buf); return obj; } } diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c index aa308e1..32e6287 100644 --- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c +++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c @@ -188,7 +188,12 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev, obj = dma_buf->priv; /* is it from our device? */ if (obj->base.dev == dev) { + /* + * Importing dmabuf exported from out own gem increases + * refcount on gem itself instead of f_count of dmabuf. + */ drm_gem_object_reference(&obj->base); + dma_buf_put(dma_buf); return &obj->base; } } diff --git a/drivers/gpu/drm/nouveau/nouveau_prime.c b/drivers/gpu/drm/nouveau/nouveau_prime.c index a25cf2c..bb653c6 100644 --- a/drivers/gpu/drm/nouveau/nouveau_prime.c +++ b/drivers/gpu/drm/nouveau/nouveau_prime.c @@ -199,6 +199,7 @@ struct drm_gem_object *nouveau_gem_prime_import(struct drm_device *dev, if (nvbo->gem) { if (nvbo->gem->dev == dev) { drm_gem_object_reference(nvbo->gem); + dma_buf_put(dma_buf); return nvbo->gem; } } diff --git a/drivers/gpu/drm/radeon/radeon_prime.c b/drivers/gpu/drm/radeon/radeon_prime.c index 6bef46a..d344a3be 100644 --- a/drivers/gpu/drm/radeon/radeon_prime.c +++ b/drivers/gpu/drm/radeon/radeon_prime.c @@ -195,6 +195,7 @@ struct drm_gem_object *radeon_gem_prime_import(struct drm_device *dev, bo = dma_buf->priv; if (bo->gem_base.dev == dev) { drm_gem_object_reference(&bo->gem_base); + dma_buf_put(dma_buf); return &bo->gem_base; } } diff --git a/drivers/staging/omapdrm/omap_gem_dmabuf.c b/drivers/staging/omapdrm/omap_gem_dmabuf.c index 42728e0..5b50eb6 100644 --- a/drivers/staging/omapdrm/omap_gem_dmabuf.c +++ b/drivers/staging/omapdrm/omap_gem_dmabuf.c @@ -207,7 +207,12 @@ struct drm_gem_object * omap_gem_prime_import(struct drm_device *dev, obj = buffer->priv; /* is it from our device? */ if (obj->dev == dev) { + /* + * Importing dmabuf exported from out own gem increases + * refcount on gem itself instead of f_count of dmabuf. + */ drm_gem_object_reference(obj); + dma_buf_put(buffer); return obj; } }