drm/prime: drop reference on imported dma-buf come from gem
Subsystems (8)
Seung-Woo Kim
maintainerPATCH 1/1 drm/prime: drop reference on imported dma-buf come from gem
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.
--- 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(-)
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +5 -0
@@ -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; } }
drivers/gpu/drm/i915/i915_gem_dmabuf.c +5 -0
@@ -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; } }
drivers/gpu/drm/nouveau/nouveau_prime.c +1 -0
@@ -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; } }
drivers/gpu/drm/radeon/radeon_prime.c +1 -0
@@ -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; } }
drivers/staging/omapdrm/omap_gem_dmabuf.c +5 -0
@@ -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; } }
Signature · 1 line
1.7.4.1
fwiw, I had a similar patch:
https://patchwork.kernel.org/patch/1229161/
although it was on top of some locking fixes from Daniel (which I think are also needed):
https://patchwork.kernel.org/patch/1227251/
although that seemed to cause/trigger some explosions which I think still need to be debugged..
BR,
-R
Quoted 105 lines · Seung-Woo Kim
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_countof 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 havingprime_importandprime_exportcapabilities. With this, only gem ref count is increased if importing gem exported from gem of same driver.Signed-off-by Seung-Woo Kim <[email protected]>Signed-off-by Kyungmin.park <[email protected]>Cc Inki Dae <[email protected]>Cc Daniel Vetter <[email protected]>Cc Rob Clark <[email protected]>Cc Alex Deucher <[email protected]>--- 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(-)drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +5
-0@@ -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; } }drivers/gpu/drm/i915/i915_gem_dmabuf.c +5
-0@@ -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; } }drivers/gpu/drm/nouveau/nouveau_prime.c +1
-0@@ -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; } }drivers/gpu/drm/radeon/radeon_prime.c +1
-0@@ -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; } }drivers/staging/omapdrm/omap_gem_dmabuf.c +5
-1@@ -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; } } --1.7.4.1
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
김승우
maintainerHi Rob,
Quoted 3 lines · Rob Clark
fwiw, I had a similar patch:
Yes, I already check your patch and even my patch's title is a bit from your patch.
I thought locking issue blocks your patch, so I sent simple fixes on current state. How do you think merging bug-fixes at first?
Best Regards,
- Seung-Woo Kim
Quoted 119 lines
although it was on top of some locking fixes from Daniel (which I think are also needed):
https://patchwork.kernel.org/patch/1227251/
although that seemed to cause/trigger some explosions which I think still need to be debugged..
BR,
-RQuoted 105 lines · Seung-Woo Kim
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_countof 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 havingprime_importandprime_exportcapabilities. With this, only gem ref count is increased if importing gem exported from gem of same driver.Signed-off-by Seung-Woo Kim <[email protected]>Signed-off-by Kyungmin.park <[email protected]>Cc Inki Dae <[email protected]>Cc Daniel Vetter <[email protected]>Cc Rob Clark <[email protected]>Cc Alex Deucher <[email protected]>--- 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(-)drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +5
-0@@ -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; } }drivers/gpu/drm/i915/i915_gem_dmabuf.c +5
-0@@ -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; } }drivers/gpu/drm/nouveau/nouveau_prime.c +1
-0@@ -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; } }drivers/gpu/drm/radeon/radeon_prime.c +1
-0@@ -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; } }drivers/staging/omapdrm/omap_gem_dmabuf.c +5
-1@@ -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; } } --1.7.4.1
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 8 lines
Seung-Woo Kim Samsung Software R&D Center -- _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 5 lines · 김승우
Hi Rob,
Quoted 2 lines · Rob Clark
fwiw, I had a similar patch:
Quoted 7 lines
Quoted 1 line
Yes, I already check your patch and even my patch's title is a bit from your patch.
I thought locking issue blocks your patch, so I sent simple fixes on current state. How do you think merging bug-fixes at first?
well, the lack of locking is a real problem too.. although I didn't see quite what the locking changes could have to do with the crash that Dave had seen. But I don't know if anyone has looked at it more, and I only re-import my own buffers in omapdrm so I don't think I can trigger the same scenario myself.
I guess if no one else has a chance to take at least a quick look at the locking crash, maybe we should take this patch. But I would be interested get the locking patch too. We are needing both patches on our product kernels to fix some issues.
BR,
-R
Quoted 128 lines
Best Regards,
- Seung-Woo KimQuoted 114 lines
although it was on top of some locking fixes from Daniel (which I think are also needed):
https://patchwork.kernel.org/patch/1227251/
although that seemed to cause/trigger some explosions which I think still need to be debugged..
BR,
-RQuoted 101 lines · Seung-Woo Kim
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_countof 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 havingprime_importandprime_exportcapabilities. With this, only gem ref count is increased if importing gem exported from gem of same driver.Signed-off-by Seung-Woo Kim <[email protected]>Signed-off-by Kyungmin.park <[email protected]>Cc Inki Dae <[email protected]>Cc Daniel Vetter <[email protected]>Cc Rob Clark <[email protected]>Cc Alex Deucher <[email protected]>--- 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(-)drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +5
-0@@ -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; } }drivers/gpu/drm/i915/i915_gem_dmabuf.c +5
-0@@ -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; } }drivers/gpu/drm/nouveau/nouveau_prime.c +1
-0@@ -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; } }drivers/gpu/drm/radeon/radeon_prime.c +1
-0@@ -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; } }drivers/staging/omapdrm/omap_gem_dmabuf.c +5
-1@@ -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; } } --1.7.4.1
Quoted 5 lines
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel--
Seung-Woo Kim
Samsung Software R&D Center
--
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Jani Nikula
maintainerQuoted 8 lines · Seung-Woo Kim
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_countof 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 havingprime_importandprime_exportcapabilities. With this, only gem ref count is increased if importing gem exported from gem of same driver.
There's a reference leak bug [1] related to prime self import found by intel-gpu-tools tests. Without much thinking, I just applied this patch to see if it makes a difference. Instead, it now fails with:
prime_self_import: prime_self_import.c:61: check_bo: Assertion `ptr1' failed.
The assert is at [2].
I haven't looked into why this happens at all, so I'm just sharing this in case you guys find it helpful.
BR,
Jani.
[1] https://bugs.freedesktop.org/show_bug.cgi?id=54111
[2] http://cgit.freedesktop.org/xorg/app/intel-gpu-tools/tree/tests/prime_self_import.c#n61
Quoted 97 lines
Signed-off-by Seung-Woo Kim <[email protected]>Signed-off-by Kyungmin.park <[email protected]>Cc Inki Dae <[email protected]>Cc Daniel Vetter <[email protected]>Cc Rob Clark <[email protected]>Cc Alex Deucher <[email protected]>--- 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(-)drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +5
-0@@ -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; } }drivers/gpu/drm/i915/i915_gem_dmabuf.c +5
-0@@ -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; } }drivers/gpu/drm/nouveau/nouveau_prime.c +1
-0@@ -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; } }drivers/gpu/drm/radeon/radeon_prime.c +1
-0@@ -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; } }drivers/staging/omapdrm/omap_gem_dmabuf.c +5
-0@@ -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; } }Signature · 6 lines
1.7.4.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
김승우
maintainerHi Jani,
Sorry for late reply.
Quoted 10 lines · Jani Nikula
Quoted 8 lines · Seung-Woo Kim
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_countof 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 havingprime_importandprime_exportcapabilities. With this, only gem ref count is increased if importing gem exported from gem of same driver.
Quoted 8 lines
There's a reference leak bug [1] related to prime self import found by intel-gpu-tools tests. Without much thinking, I just applied this patch to see if it makes a difference. Instead, it now fails with:
prime_self_import: prime_self_import.c:61:check_bo: Assertion `ptr1' failed.The assert is at [2].
I think it was possible to re-use a handle imported_buf list which is already deleted, and it was fixed after Dave's commit "drm/prime: add exported buffers to current fprivs imported buffer list (v2)".
Quoted 3 lines
I haven't looked into why this happens at all, so I'm just sharing this in case you guys find it helpful.
If you still have same assert, I think it will be very helpful to let me know exactly where the assert occurs from 5 check_bo() in test application in your link.
Thanks and Best Regards,
- Seung-Woo Kim
Quoted 108 lines
BR,
Jani.[1] https://bugs.freedesktop.org/show_bug.cgi?id=54111
[2] http://cgit.freedesktop.org/xorg/app/intel-gpu-tools/tree/tests/prime_self_import.c#n61Quoted 97 lines
Signed-off-by Seung-Woo Kim <[email protected]>Signed-off-by Kyungmin.park <[email protected]>Cc Inki Dae <[email protected]>Cc Daniel Vetter <[email protected]>Cc Rob Clark <[email protected]>Cc Alex Deucher <[email protected]>--- 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(-)drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +5
-0@@ -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; } }drivers/gpu/drm/i915/i915_gem_dmabuf.c +5
-0@@ -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; } }drivers/gpu/drm/nouveau/nouveau_prime.c +1
-0@@ -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; } }drivers/gpu/drm/radeon/radeon_prime.c +1
-0@@ -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; } }drivers/staging/omapdrm/omap_gem_dmabuf.c +5
-0@@ -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; } }Signature · 6 lines
1.7.4.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 8 lines
Seung-Woo Kim Samsung Software R&D Center -- _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Seung-Woo Kim
maintainerPATCH RESEND 1/1 drm/prime: drop reference on imported dma-buf come from gem
In reply to Seung-Woo KimIncreasing 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.
---
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(-)
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +5 -0
@@ -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; } }
drivers/gpu/drm/i915/i915_gem_dmabuf.c +5 -0
@@ -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; } }
drivers/gpu/drm/nouveau/nouveau_prime.c +1 -0
@@ -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; } }
drivers/gpu/drm/radeon/radeon_prime.c +1 -0
@@ -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; } }
drivers/staging/omapdrm/omap_gem_dmabuf.c +5 -0
@@ -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; } }
Signature · 1 line
1.7.4.1
Hi All,
This patch has been tested with only Exynos driver so other maintainers may need to test this.
2012/11/15 Seung-Woo Kim <[email protected]>
Quoted 126 lines
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_countof 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 havingprime_importandprime_exportcapabilities. With this, only gem ref count is increased if importing gem exported from gem of same driver.Signed-off-by Seung-Woo Kim <[email protected]>Signed-off-by Kyungmin.park <[email protected]>Cc Inki Dae <[email protected]>Cc Daniel Vetter <[email protected]>Cc Rob Clark <[email protected]>Cc Alex Deucher <[email protected]>---
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(-)drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +2
-0@@ -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 gemincreases
+ * refcount on gem itself instead off_countof
dmabuf.drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +2
-0+*/ drm_gem_object_reference (obj); +dma_buf_put (dma_buf);return obj; } }drivers/gpu/drm/i915/i915_gem_dmabuf.c +2
-0@@ -188,7 +188,12 @@ struct drm_gem_object *i915_gem_prime_import(structdrm_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 off_countof
dmabuf.drivers/gpu/drm/i915/i915_gem_dmabuf.c +2
-0+*/ drm_gem_object_reference (&obj->base); +dma_buf_put (dma_buf);return &obj->base; } }drivers/gpu/drm/nouveau/nouveau_prime.c +1
-0@@ -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; }}drivers/gpu/drm/radeon/radeon_prime.c +1
-0@@ -195,6 +195,7 @@ struct drm_gem_object *radeon_gem_prime_import(structdrm_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; }}drivers/staging/omapdrm/omap_gem_dmabuf.c +2
-0@@ -207,7 +207,12 @@ struct drm_gem_object * omap_gem_prime_import(structdrm_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 off_countof
dmabuf.drivers/staging/omapdrm/omap_gem_dmabuf.c +2
-1+*/ drm_gem_object_reference (obj); +dma_buf_put (buffer);return obj; } } --1.7.4.1
Quoted 5 lines
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Op 15-11-12 04:52, Seung-Woo Kim schreef:
Quoted 16 lines
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_countof 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 havingprime_importandprime_exportcapabilities. With this, only gem ref count is increased if importing gem exported from gem of same driver.Signed-off-by Seung-Woo Kim <[email protected]>Signed-off-by Kyungmin.park <[email protected]>Cc Inki Dae <[email protected]>Cc Daniel Vetter <[email protected]>Cc Rob Clark <[email protected]>Cc Alex Deucher <[email protected]>
Quoted 8 lines
---
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.
I fear that this won't solve the issue completely and keeps open a small race.
I don't like the current destruction path either. It really looks like export_dma_buf should be unset when the exported buffer is closed in the original file. Anything else is racy. Especially setting export_dma_buf to NULL won't work with the current delayed fput semantics.
So to me it seems instead we should do something like this:
- dmabuf_release callback is a noop, no ref is held by the dma-buf.
- attach and detach ops increase reference by 1*.
- when the buffer is exported, export_dma_buf is set by core code and kept around alive until the gem object is closed.
- dma_buf_put is not called by import function. This reference removed as part of gem object close instead.
~Maarten
*) Lockdep will rightfully hate this as it reopens a locking inversion, some solution for that is needed.
Maybe a post detach callback for dma-buf with all locks dropped would be best here? Other way would be to schedule delayed work with the sole purpose of unreffing in the detach op, similar to how atomic_dec_and_mutex_lock works.
김승우
maintainerHi Maarten,
Quoted 22 lines · Maarten Lankhorst
Op 15-11-12 04:52, Seung-Woo Kim schreef:
Quoted 21 lines
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_countof 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 havingprime_importandprime_exportcapabilities. With this, only gem ref count is increased if importing gem exported from gem of same driver.Signed-off-by Seung-Woo Kim <[email protected]>Signed-off-by Kyungmin.park <[email protected]>Cc Inki Dae <[email protected]>Cc Daniel Vetter <[email protected]>Cc Rob Clark <[email protected]>Cc Alex Deucher <[email protected]>---
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.
Quoted 4 lines
Quoted 3 lines
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.
I fear that this won't solve the issue completely and keeps open a small race.
I don't believe my patch can fix all issue related with gem prime completely. But it seems that it can solve unrecoverable memory leak caused by re-importing GEM. Anyway, can you give me an example of other race issue?
Quoted 4 lines
I don't like the current destruction path either. It really looks like
export_dma_bufshould be unset when the exported buffer is closed in the original file. Anything else is racy. Especially settingexport_dma_bufto NULL won't work with the current delayed fput semantics.
I cannot figure out all aspect of delayed fput, but until delayed work is called, dma_buf is not released so export_dma_buf is valid. Considering this, I can't find possible issue of delayed fput.
Quoted 11 lines
So to me it seems instead we should do something like this:
-
dmabuf_releasecallback is a noop, no ref is held by the dma-buf.
- attach and detach ops increase reference by 1*.- when the buffer is exported,
export_dma_bufis set by core code and kept around alive until the gem object is closed.-
dma_buf_putis not called by import function. This reference removed as part of gem object close instead.
Considering re-import, where drm file priv is different from exporter's file priv, attach and detach are not called because gem object is reused.
How do you think remove checking whether dma_buf is came from driver own exporter? Because without this checking, gem object is newly created, and then re-import issue will disappear.
Thanks and Regards,
- Seung-Woo Kim
Quoted 10 lines
~Maarten
*) Lockdep will rightfully hate this as it reopens a locking inversion, some solution for that is needed.
Maybe a post detach callback for dma-buf with all locks dropped would be best here? Other way would be to schedule delayed work with the sole purpose of unreffing in the detach op, similar to how
atomic_dec_and_mutex_lockworks.
Signature · 8 lines
Seung-Woo Kim Samsung Software R&D Center -- _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Op 20-11-12 02:03, 김승우 schreef:
Quoted 25 lines
Hi Maarten,
Quoted 22 lines · Maarten Lankhorst
Op 15-11-12 04:52, Seung-Woo Kim schreef:
Quoted 21 lines
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_countof 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 havingprime_importandprime_exportcapabilities. With this, only gem ref count is increased if importing gem exported from gem of same driver.Signed-off-by Seung-Woo Kim <[email protected]>Signed-off-by Kyungmin.park <[email protected]>Cc Inki Dae <[email protected]>Cc Daniel Vetter <[email protected]>Cc Rob Clark <[email protected]>Cc Alex Deucher <[email protected]>---
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.
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
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.
I fear that this won't solve the issue completely and keeps open a small race.
I don't believe my patch can fix all issue related with gem prime completely. But it seems that it can solve unrecoverable memory leak caused by re-importing GEM. Anyway, can you give me an example of other race issue?
When the dma_buf is unreffed and refcount drops to 0, work is queued to free it.
Until then export_dma_buf member points to something, but refcount is 0 on it.
Importing to itself, then closing fd then re-export from the new place would probably trigger it.
Quoted 6 lines
Quoted 3 lines
I don't like the current destruction path either. It really looks like
export_dma_bufshould be unset when the exported buffer is closed in the original file. Anything else is racy. Especially settingexport_dma_bufto NULL won't work with the current delayed fput semantics.I cannot figure out all aspect of delayed fput, but until delayed work is called,
dma_bufis not released soexport_dma_bufis valid. Considering this, I can't find possible issue of delayed fput.
I'm fairly sure that when refcount drops to 0, even though the memory may not be freed yet, you no longer have a guarantee that the memory is still valid.
And of course after importing into a different process with its own drm namespace, how does file_priv->prime.lock still protect serialization?
I don't see any hierarchy either. export_dma_buf needs to be set to NULL before the dma_buf_put is called that is used for the reference inside export_dma_buf.
The release function should only release a reference to whatever backing memory is used.
Quoted 8 lines
Quoted 8 lines
So to me it seems instead we should do something like this:
-
dmabuf_releasecallback is a noop, no ref is held by the dma-buf.
- attach and detach ops increase reference by 1*.- when the buffer is exported,
export_dma_bufis set by core code and kept around alive until the gem object is closed.
Quoted 8 lines
Quoted 2 lines
-
dma_buf_putis not called by import function. This reference removed as part of gem object close instead.Considering re-import, where drm file priv is different from exporter's file priv, attach and detach are not called because gem object is reused.
How do you think remove checking whether
dma_bufis came from driver own exporter? Because without this checking, gem object is newly created, and then re-import issue will disappear.
The whole refcounting is a circular mess, sadly with no easy solution. :/
It seems to me that using gem reference counts is solving this problem at the wrong layer. A secondary type of reference count is needed for the underlying memory backing.
For those who use ttm, I would recommend that the dma_buf increases refcount on ttm_bo by one, so that the gem object can be destroyed and release its reference on the dma_buf.
WIthout a secondary refcount you end up in a position where you can't reliably and race free unref the gem object and dma_buf at the same time, since they're both independent interfaces with possibly different lifetimes.
It would really help if there were hard rules on lifetime of the export_dma_buf member, until then we're just patching one broken thing with another.
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
김승우
maintainerQuoted 34 lines · Maarten Lankhorst
Op 20-11-12 02:03, 김승우 schreef:
Quoted 25 lines
Hi Maarten,
Quoted 22 lines · Maarten Lankhorst
Op 15-11-12 04:52, Seung-Woo Kim schreef:
Quoted 21 lines
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_countof 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 havingprime_importandprime_exportcapabilities. With this, only gem ref count is increased if importing gem exported from gem of same driver.Signed-off-by Seung-Woo Kim <[email protected]>Signed-off-by Kyungmin.park <[email protected]>Cc Inki Dae <[email protected]>Cc Daniel Vetter <[email protected]>Cc Rob Clark <[email protected]>Cc Alex Deucher <[email protected]>---
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.Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
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.
I fear that this won't solve the issue completely and keeps open a small race.
I don't believe my patch can fix all issue related with gem prime completely. But it seems that it can solve unrecoverable memory leak caused by re-importing GEM. Anyway, can you give me an example of other race issue?
Quoted 6 lines
When the
dma_bufis unreffed and refcount drops to 0, work is queued to free it.Until then
export_dma_bufmember points to something, but refcount is 0 on it.Importing to itself, then closing fd then re-export from the new place would probably trigger it.
Ok, I understood about issue from delayed fput also in your below comment. Anyway, IMO, it is already on current drm prime.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
I don't like the current destruction path either. It really looks like
export_dma_bufshould be unset when the exported buffer is closed in the original file. Anything else is racy. Especially settingexport_dma_bufto NULL won't work with the current delayed fput semantics.I cannot figure out all aspect of delayed fput, but until delayed work is called,
dma_bufis not released soexport_dma_bufis valid. Considering this, I can't find possible issue of delayed fput.I'm fairly sure that when refcount drops to 0, even though the memory may not be freed yet, you no longer have a guarantee that the memory is still valid.
I missed that delayed fput is triggered after recount drops to 0, and now I understood it can cause invalid access.
Quoted 30 lines
And of course after importing into a different process with its own drm namespace, how does
file_priv->prime.lockstill protect serialization?I don't see any hierarchy either.
export_dma_bufneeds to be set to NULL before thedma_buf_putis called that is used for the reference insideexport_dma_buf.The release function should only release a reference to whatever backing memory is used.
Quoted 8 lines
Quoted 8 lines
So to me it seems instead we should do something like this:
-
dmabuf_releasecallback is a noop, no ref is held by the dma-buf.
- attach and detach ops increase reference by 1*.- when the buffer is exported,
export_dma_bufis set by core code and kept around alive until the gem object is closed.Quoted 8 lines
Quoted 2 lines
-
dma_buf_putis not called by import function. This reference removed as part of gem object close instead.Considering re-import, where drm file priv is different from exporter's file priv, attach and detach are not called because gem object is reused.
How do you think remove checking whether
dma_bufis came from driver own exporter? Because without this checking, gem object is newly created, and then re-import issue will disappear.The whole refcounting is a circular mess, sadly with no easy solution. :/
It seems to me that using gem reference counts is solving this problem at the wrong layer. A secondary type of reference count is needed for the underlying memory backing.
Quoted 6 lines
For those who use ttm, I would recommend that the
dma_bufincreases refcount onttm_boby one, so that the gem object can be destroyed and release its reference on thedma_buf.WIthout a secondary refcount you end up in a position where you can't reliably and race free unref the gem object and
dma_bufat the same time, since they're both independent interfaces with possibly different lifetimes.
If there is no checking whether dma_buf is came from driver own exporter, gem_object is newly allocated and refcount of it can be a secondary refcount at least form mermoy leak issue. So I mentioned about removing check for exporter.
But I prefer processing re-import as gem_open without considering dma-buf as current implementation.
Quoted 3 lines
It would really help if there were hard rules on lifetime of the
export_dma_bufmember, until then we're just patching one broken thing with another.
Issue about memory leak of re-import was also reported on i915 and there was Rob's patch set, but other locking issue blocked the patch. I'm not sure all issue can be solved at once and someone is handling this at the moment.
Best Regards,
- Seung-Woo Kim
Quoted 5 lines
~Maarten
Signature · 8 lines
Seung-Woo Kim Samsung Software R&D Center -- _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Dave Airlie
maintainerQuoted 8 lines · Seung-Woo Kim
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_countof 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 havingprime_importandprime_exportcapabilities. With this, only gem ref count is increased if importing gem exported from gem of same driver.
Okay its taken me a while to circle around and get back to this, but yes I admit this is needed, but I hate implementing it like this
But I think I'll push it and work out a cleaner solution, I should also go back and look at the older patches.
Dave.
김승우
maintainerHi Dave,
Quoted 10 lines · Dave Airlie
Quoted 8 lines · Seung-Woo Kim
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_countof 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 havingprime_importandprime_exportcapabilities. With this, only gem ref count is increased if importing gem exported from gem of same driver.
Quoted 5 lines
Okay its taken me a while to circle around and get back to this, but yes I admit this is needed, but I hate implementing it like this
But I think I'll push it and work out a cleaner solution, I should also go back and look at the older patches.
I want to also report some strange thing in dma-buf prime export.
In drm_prime_handle_to_fd_ioctl(), flags is cleared to only support DRM_CLOEXEC but in gem_prime_export() callbacks of each driver, it uses 0600 as flags for dma_buf_export() like following.
return dma_buf_export(obj, &i915_dmabuf_ops, obj->base.size, 0600);
Best Regards,
- Seung-Woo Kim
Quoted 3 lines
Dave.
Signature · 8 lines
Seung-Woo Kim Samsung Software R&D Center -- _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Dave Airlie
maintainerQuoted 5 lines
In
drm_prime_handle_to_fd_ioctl(), flags is cleared to only supportDRM_CLOEXECbut ingem_prime_export()callbacks of each driver, it uses 0600 as flags fordma_buf_export()like following.return
dma_buf_export(obj, &i915_dmabuf_ops, obj->base.size, 0600);
Oops, nice catch, radeon and nouveau did the correct thing here, I'll send a patch to fix that.
Dave.