<br>Hi All,<br><br>This patch has been tested with only Exynos driver so other maintainers may need to test this.<br><br>Acked-by: Inki Dae <<a href="mailto:inki.dae@samsung.com">inki.dae@samsung.com</a>><br><br><br>
<div class="gmail_quote">2012/11/15 Seung-Woo Kim <span dir="ltr"><<a href="mailto:sw0312.kim@samsung.com" target="_blank">sw0312.kim@samsung.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">Increasing ref counts of both dma-buf and gem for imported dma-buf<br>
come from gem makes memory leak. release function of dma-buf cannot<br>
be called because f_count of dma-buf increased by importing gem and<br>
gem ref count cannot be decrease because of exported dma-buf.<br>
<br>
So I add dma_buf_put() for imported gem come from its own gem into<br>
each drivers having prime_import and prime_export capabilities. With<br>
this, only gem ref count is increased if importing gem exported from<br>
gem of same driver.<br>
<br>
Signed-off-by: Seung-Woo Kim <<a href="mailto:sw0312.kim@samsung.com">sw0312.kim@samsung.com</a>><br>
Signed-off-by: Kyungmin.park <<a href="mailto:kyungmin.park@samsung.com">kyungmin.park@samsung.com</a>><br>
Cc: Inki Dae <<a href="mailto:inki.dae@samsung.com">inki.dae@samsung.com</a>><br>
Cc: Daniel Vetter <<a href="mailto:daniel.vetter@ffwll.ch">daniel.vetter@ffwll.ch</a>><br>
Cc: Rob Clark <<a href="mailto:rob.clark@linaro.org">rob.clark@linaro.org</a>><br>
Cc: Alex Deucher <<a href="mailto:alexander.deucher@amd.com">alexander.deucher@amd.com</a>><br>
---<br>
</div>Mmap failiure in i915 was reported by Jani, and I think it was fixed<br>
with Dave's commit "drm/prime: add exported buffers to current fprivs<br>
imported buffer list (v2)", so I resend this patch.<br>
<br>
I can send exynos only, but this issue is common in all drm driver<br>
having both prime inport and export, IMHO, it's better to send for<br>
all drivers.<br>
<div class="HOEnZb"><div class="h5"><br>
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c | 5 +++++<br>
drivers/gpu/drm/i915/i915_gem_dmabuf.c | 5 +++++<br>
drivers/gpu/drm/nouveau/nouveau_prime.c | 1 +<br>
drivers/gpu/drm/radeon/radeon_prime.c | 1 +<br>
drivers/staging/omapdrm/omap_gem_dmabuf.c | 5 +++++<br>
5 files changed, 17 insertions(+), 0 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c b/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c<br>
index ae13feb..b0897c9 100644<br>
--- a/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c<br>
+++ b/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c<br>
@@ -211,7 +211,12 @@ struct drm_gem_object *exynos_dmabuf_prime_import(struct drm_device *drm_dev,<br>
<br>
/* is it from our device? */<br>
if (obj->dev == drm_dev) {<br>
+ /*<br>
+ * Importing dmabuf exported from out own gem increases<br>
+ * refcount on gem itself instead of f_count of dmabuf.<br>
+ */<br>
drm_gem_object_reference(obj);<br>
+ dma_buf_put(dma_buf);<br>
return obj;<br>
}<br>
}<br>
diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c<br>
index aa308e1..32e6287 100644<br>
--- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c<br>
+++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c<br>
@@ -188,7 +188,12 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,<br>
obj = dma_buf->priv;<br>
/* is it from our device? */<br>
if (obj->base.dev == dev) {<br>
+ /*<br>
+ * Importing dmabuf exported from out own gem increases<br>
+ * refcount on gem itself instead of f_count of dmabuf.<br>
+ */<br>
drm_gem_object_reference(&obj->base);<br>
+ dma_buf_put(dma_buf);<br>
return &obj->base;<br>
}<br>
}<br>
diff --git a/drivers/gpu/drm/nouveau/nouveau_prime.c b/drivers/gpu/drm/nouveau/nouveau_prime.c<br>
index a25cf2c..bb653c6 100644<br>
--- a/drivers/gpu/drm/nouveau/nouveau_prime.c<br>
+++ b/drivers/gpu/drm/nouveau/nouveau_prime.c<br>
@@ -199,6 +199,7 @@ struct drm_gem_object *nouveau_gem_prime_import(struct drm_device *dev,<br>
if (nvbo->gem) {<br>
if (nvbo->gem->dev == dev) {<br>
drm_gem_object_reference(nvbo->gem);<br>
+ dma_buf_put(dma_buf);<br>
return nvbo->gem;<br>
}<br>
}<br>
diff --git a/drivers/gpu/drm/radeon/radeon_prime.c b/drivers/gpu/drm/radeon/radeon_prime.c<br>
index 6bef46a..d344a3be 100644<br>
--- a/drivers/gpu/drm/radeon/radeon_prime.c<br>
+++ b/drivers/gpu/drm/radeon/radeon_prime.c<br>
@@ -195,6 +195,7 @@ struct drm_gem_object *radeon_gem_prime_import(struct drm_device *dev,<br>
bo = dma_buf->priv;<br>
if (bo->gem_base.dev == dev) {<br>
drm_gem_object_reference(&bo->gem_base);<br>
+ dma_buf_put(dma_buf);<br>
return &bo->gem_base;<br>
}<br>
}<br>
diff --git a/drivers/staging/omapdrm/omap_gem_dmabuf.c b/drivers/staging/omapdrm/omap_gem_dmabuf.c<br>
index 42728e0..5b50eb6 100644<br>
--- a/drivers/staging/omapdrm/omap_gem_dmabuf.c<br>
+++ b/drivers/staging/omapdrm/omap_gem_dmabuf.c<br>
@@ -207,7 +207,12 @@ struct drm_gem_object * omap_gem_prime_import(struct drm_device *dev,<br>
obj = buffer->priv;<br>
/* is it from our device? */<br>
if (obj->dev == dev) {<br>
+ /*<br>
+ * Importing dmabuf exported from out own gem increases<br>
+ * refcount on gem itself instead of f_count of dmabuf.<br>
+ */<br>
drm_gem_object_reference(obj);<br>
+ dma_buf_put(buffer);<br>
return obj;<br>
}<br>
}<br>
--<br>
1.7.4.1<br>
<br>
_______________________________________________<br>
dri-devel mailing list<br>
<a href="mailto:dri-devel@lists.freedesktop.org">dri-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/dri-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/dri-devel</a><br>
</div></div></blockquote></div><br>