Skip to contentSkip to conversation

Small i915/exynos prime cleanup

PATCH In review Daniel Vetter 7 participants 30 messages Aug 7, 2013 – Aug 8, 2013

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover Small i915/exynos prime cleanup

Hi all,

I need to get my prime fixes in since they're blocking QA from running -nightly prime tests. Which is a prerequisite of mine before I start touching dma-buf for real to look at fencing and ww-mutex integration for i915.

These three patches are just a bit of prep cleanup and one bugfix that Maarten spotted.

Cheers, Daniel

Daniel Vetter (3):
drm: use common drm_gem_dmabuf_release in i915/exynos drivers drm/i915: unpin backing storage in dmabuf_unmap drm/i915: explicit store base gem object in dma_buf->priv

 drivers/gpu/drm/drm_prime.c                |  3 ++-
 drivers/gpu/drm/exynos/exynos_drm_dmabuf.c | 23 +-------------------
 drivers/gpu/drm/i915/i915_gem_dmabuf.c     | 34 +++++++++++++-----------------
 include/drm/drmP.h                         |  1 +
 4 files changed, 19 insertions(+), 42 deletions(-)
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH 1/3 drm: use common drm_gem_dmabuf_release in i915/exynos drivers

Note that this is slightly tricky since both drivers store their native objects in dma_buf->priv. But both also embed the base drm_gem_object at the first position, so the implicit cast is ok.

To use the release helper we need to export it, too.

Cc Inki Dae <[email protected]>
Cc Intel Graphics Development <[email protected]>
---
 drivers/gpu/drm/drm_prime.c                |  3 ++-
 drivers/gpu/drm/exynos/exynos_drm_dmabuf.c | 23 +----------------------
 drivers/gpu/drm/i915/i915_gem_dmabuf.c     | 13 +------------
 include/drm/drmP.h                         |  1 +
 4 files changed, 5 insertions(+), 35 deletions(-)
drivers/gpu/drm/drm_prime.c +2 -1
index 85e450e..a35f206 100644
@@ -192,7 +192,7 @@ static void drm_gem_unmap_dma_buf(struct dma_buf_attachment *attach,
 	/* nothing to be done here */
 }
 
-static void drm_gem_dmabuf_release(struct dma_buf *dma_buf)
+void drm_gem_dmabuf_release(struct dma_buf *dma_buf)
 {
 	struct drm_gem_object *obj = dma_buf->priv;
 
@@ -202,6 +202,7 @@ static void drm_gem_dmabuf_release(struct dma_buf *dma_buf)
 		drm_gem_object_unreference_unlocked(obj);
 	}
 }
+EXPORT_SYMBOL(drm_gem_dmabuf_release);
 
 static void *drm_gem_dmabuf_vmap(struct dma_buf *dma_buf)
 {
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +1 -22
index a0f997e..3cd56e1 100644
@@ -127,27 +127,6 @@ static void exynos_gem_unmap_dma_buf(struct dma_buf_attachment *attach,
 	/* Nothing to do. */
 }
 
-static void exynos_dmabuf_release(struct dma_buf *dmabuf)
-{
-	struct exynos_drm_gem_obj *exynos_gem_obj = dmabuf->priv;
-
-	/*
-	 * exynos_dmabuf_release() call means that file object's
-	 * f_count is 0 and it calls drm_gem_object_handle_unreference()
-	 * to drop the references that these values had been increased
-	 * at drm_prime_handle_to_fd()
-	 */
-	if (exynos_gem_obj->base.export_dma_buf == dmabuf) {
-		exynos_gem_obj->base.export_dma_buf = NULL;
-
-		/*
-		 * drop this gem object refcount to release allocated buffer
-		 * and resources.
-		 */
-		drm_gem_object_unreference_unlocked(&exynos_gem_obj->base);
-	}
-}
-
 static void *exynos_gem_dmabuf_kmap_atomic(struct dma_buf *dma_buf,
 						unsigned long page_num)
 {
@@ -193,7 +172,7 @@ static struct dma_buf_ops exynos_dmabuf_ops = {
 	.kunmap			= exynos_gem_dmabuf_kunmap,
 	.kunmap_atomic		= exynos_gem_dmabuf_kunmap_atomic,
 	.mmap			= exynos_gem_dmabuf_mmap,
-	.release		= exynos_dmabuf_release,
+	.release		= drm_gem_dmabuf_release,
 };
 
 struct dma_buf *exynos_dmabuf_prime_export(struct drm_device *drm_dev,
drivers/gpu/drm/i915/i915_gem_dmabuf.c +1 -12
index f2e185c..63ee1a9 100644
@@ -90,17 +90,6 @@ static void i915_gem_unmap_dma_buf(struct dma_buf_attachment *attachment,
 	kfree(sg);
 }
 
-static void i915_gem_dmabuf_release(struct dma_buf *dma_buf)
-{
-	struct drm_i915_gem_object *obj = dma_buf->priv;
-
-	if (obj->base.export_dma_buf == dma_buf) {
-		/* drop the reference on the export fd holds */
-		obj->base.export_dma_buf = NULL;
-		drm_gem_object_unreference_unlocked(&obj->base);
-	}
-}
-
 static void *i915_gem_dmabuf_vmap(struct dma_buf *dma_buf)
 {
 	struct drm_i915_gem_object *obj = dma_buf->priv;
@@ -211,7 +200,7 @@ static int i915_gem_begin_cpu_access(struct dma_buf *dma_buf, size_t start, size
 static const struct dma_buf_ops i915_dmabuf_ops =  {
 	.map_dma_buf = i915_gem_map_dma_buf,
 	.unmap_dma_buf = i915_gem_unmap_dma_buf,
-	.release = i915_gem_dmabuf_release,
+	.release = drm_gem_dmabuf_release,
 	.kmap = i915_gem_dmabuf_kmap,
 	.kmap_atomic = i915_gem_dmabuf_kmap_atomic,
 	.kunmap = i915_gem_dmabuf_kunmap,
include/drm/drmP.h +1 -0
index 4b518e0..cc991a2 100644
@@ -1537,6 +1537,7 @@ extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
 		struct dma_buf *dma_buf);
 extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
 		struct drm_file *file_priv, int prime_fd, uint32_t *handle);
+extern void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
 
 extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
 					struct drm_file *file_priv);
Signature · 1 line
1.8.3.2
Reviewed-by on v1 1/3
#2 lore raw

Re: [Intel-gfx] [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

Quoted 9 lines · Daniel Vetter

Note that this is slightly tricky since both drivers store their native objects in dma_buf->priv. But both also embed the base drm_gem_object at the first position, so the implicit cast is ok.

To use the release helper we need to export it, too.

Cc Inki Dae <[email protected]>
Cc Intel Graphics Development <[email protected]>

Any perverse driver could always call into drm_gem_dmabuf_release() with container_of().

-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
maintainer
#3 lore raw

Re: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

In reply to Daniel Vetter
Quoted 10 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]]
Sent: Wednesday, August 07, 2013 6:15 PM
To: DRI Development
Cc: Intel Graphics Development; Daniel Vetter; Inki Dae
Subject: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

Quoted 5 lines

Note that this is slightly tricky since both drivers store their native objects in dma_buf->priv. But both also embed the base drm_gem_object at the first position, so the implicit cast is ok.

To use the release helper we need to export it, too.

Yeah, may I repost this patch with additional work? We also need to export with a gem object instead of specific one like you did.

Thanks,
Inki Dae

Quoted 127 lines
Cc Inki Dae <[email protected]>
Cc Intel Graphics Development <[email protected]>
---
 drivers/gpu/drm/drm_prime.c                |  3 ++-
 drivers/gpu/drm/exynos/exynos_drm_dmabuf.c | 23 +----------------------
 drivers/gpu/drm/i915/i915_gem_dmabuf.c     | 13 +------------
 include/drm/drmP.h                         |  1 +
 4 files changed, 5 insertions(+), 35 deletions(-)
drivers/gpu/drm/drm_prime.c +2 -1
index 85e450e..a35f206 100644
@@ -192,7 +192,7 @@ static void drm_gem_unmap_dma_buf(struct
 dma_buf_attachment *attach,
 	/* nothing to be done here */
 }
 
-static void drm_gem_dmabuf_release(struct dma_buf *dma_buf)
+void drm_gem_dmabuf_release(struct dma_buf *dma_buf)
 {
 	struct drm_gem_object *obj = dma_buf->priv;
@@ -202,6 +202,7 @@ static void drm_gem_dmabuf_release(struct dma_buf
 *dma_buf)
 		drm_gem_object_unreference_unlocked(obj);
 	}
 }
+EXPORT_SYMBOL(drm_gem_dmabuf_release);
 
 static void *drm_gem_dmabuf_vmap(struct dma_buf *dma_buf)

{

drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +0 -21
index a0f997e..3cd56e1 100644
@@ -127,27 +127,6 @@ static void exynos_gem_unmap_dma_buf(struct
 dma_buf_attachment *attach,
 	/* Nothing to do. */
 }
 
-static void exynos_dmabuf_release(struct dma_buf *dmabuf)
-{
-	struct exynos_drm_gem_obj *exynos_gem_obj = dmabuf->priv;
-
-	/*
-	 * exynos_dmabuf_release() call means that file object's
-	 * f_count is 0 and it calls drm_gem_object_handle_unreference()
-	 * to drop the references that these values had been increased
-	 * at drm_prime_handle_to_fd()
-	 */
-	if (exynos_gem_obj->base.export_dma_buf == dmabuf) {
-		exynos_gem_obj->base.export_dma_buf = NULL;
-
-		/*
-		 * drop this gem object refcount to release allocated buffer
-		 * and resources.
-		 */
-		drm_gem_object_unreference_unlocked(&exynos_gem_obj->base);
-	}
-}
-
 static void *exynos_gem_dmabuf_kmap_atomic(struct dma_buf *dma_buf,
 						unsigned long page_num)

{

drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +1 -1
@@ -193,7 +172,7 @@ static struct dma_buf_ops exynos_dmabuf_ops = {
 	.kunmap			= exynos_gem_dmabuf_kunmap,
 	.kunmap_atomic		= exynos_gem_dmabuf_kunmap_atomic,
 	.mmap			= exynos_gem_dmabuf_mmap,
-	.release		= exynos_dmabuf_release,
+	.release		= drm_gem_dmabuf_release,
 };
 
 struct dma_buf *exynos_dmabuf_prime_export(struct drm_device *drm_dev,
drivers/gpu/drm/i915/i915_gem_dmabuf.c +0 -11
index f2e185c..63ee1a9 100644
@@ -90,17 +90,6 @@ static void i915_gem_unmap_dma_buf(struct
 dma_buf_attachment *attachment,
 	kfree(sg);
 }
 
-static void i915_gem_dmabuf_release(struct dma_buf *dma_buf)
-{
-	struct drm_i915_gem_object *obj = dma_buf->priv;
-
-	if (obj->base.export_dma_buf == dma_buf) {
-		/* drop the reference on the export fd holds */
-		obj->base.export_dma_buf = NULL;
-		drm_gem_object_unreference_unlocked(&obj->base);
-	}
-}
-
 static void *i915_gem_dmabuf_vmap(struct dma_buf *dma_buf)
 {
drivers/gpu/drm/i915/i915_gem_dmabuf.c +1 -1
 	struct drm_i915_gem_object *obj = dma_buf->priv;
@@ -211,7 +200,7 @@ static int i915_gem_begin_cpu_access(struct dma_buf
 *dma_buf, size_t start, size
 static const struct dma_buf_ops i915_dmabuf_ops =  {
 	.map_dma_buf = i915_gem_map_dma_buf,
 	.unmap_dma_buf = i915_gem_unmap_dma_buf,
-	.release = i915_gem_dmabuf_release,
+	.release = drm_gem_dmabuf_release,
 	.kmap = i915_gem_dmabuf_kmap,
 	.kmap_atomic = i915_gem_dmabuf_kmap_atomic,
drivers/gpu/drm/i915/i915_gem_dmabuf.c +0 -0
 	.kunmap = i915_gem_dmabuf_kunmap,
include/drm/drmP.h +1 -0
index 4b518e0..cc991a2 100644
@@ -1537,6 +1537,7 @@ extern struct drm_gem_object
 *drm_gem_prime_import(struct drm_device *dev,
 		struct dma_buf *dma_buf);
 extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
 		struct drm_file *file_priv, int prime_fd, uint32_t *handle);
+extern void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
 
 extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void

*data,
struct drm_file *file_priv);
--
1.8.3.2

#4 lore raw

Re: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

Quoted 8 lines · Inki Dae
Quoted 8 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]]
Sent: Wednesday, August 07, 2013 6:15 PM
To: DRI Development
Cc: Intel Graphics Development; Daniel Vetter; Inki Dae
Subject: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

Quoted 8 lines
Quoted 5 lines

Note that this is slightly tricky since both drivers store their native objects in dma_buf->priv. But both also embed the base drm_gem_object at the first position, so the implicit cast is ok.

To use the release helper we need to export it, too.

Yeah, may I repost this patch with additional work? We also need to export with a gem object instead of specific one like you did.

I'm confused here what you mean, so pls just submit the patch. That usually helps ;-)
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#5 lore raw

Re: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

Quoted 9 lines · Daniel Vetter
Quoted 8 lines · Inki Dae
Quoted 8 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]]
Sent: Wednesday, August 07, 2013 6:15 PM
To: DRI Development
Cc: Intel Graphics Development; Daniel Vetter; Inki Dae
Subject: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

Note that this is slightly tricky since both drivers store their native objects in dma_buf->priv. But both also embed the base drm_gem_object at the first position, so the implicit cast is ok.

To use the release helper we need to export it, too.

Yeah, may I repost this patch with additional work? We also need to export with a gem object instead of specific one like you did.

I think dmabuf stuff of exynos can be replaced to common drm_gem_dmabuf. Already dmabuf stuff of drm_gem_cma_helper.c was substituted to common drm_gem_dmabuf with low-level hook functions to use prime helpers.

Thanks.

Quoted 3 lines

I'm confused here what you mean, so pls just submit the patch. That usually helps ;-)
-Daniel

#6 lore raw

Re: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

Quoted 14 lines · Joonyoung Shim
Quoted 13 lines · Daniel Vetter
Quoted 12 lines · Inki Dae
Quoted 12 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]]
Sent: Wednesday, August 07, 2013 6:15 PM
To: DRI Development
Cc: Intel Graphics Development; Daniel Vetter; Inki Dae
Subject: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

Note that this is slightly tricky since both drivers store their native objects in dma_buf->priv. But both also embed the base drm_gem_object at the first position, so the implicit cast is ok.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

To use the release helper we need to export it, too.

Yeah, may I repost this patch with additional work? We also need to export with a gem object instead of specific one like you did.

I think dmabuf stuff of exynos can be replaced to common drm_gem_dmabuf. Already dmabuf stuff of drm_gem_cma_helper.c was substituted to common drm_gem_dmabuf with low-level hook functions to use prime helpers.

Ah, but that can easily be done on top of this, right? -Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#7 lore raw

Re: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

Quoted 15 lines · Daniel Vetter
Quoted 14 lines · Joonyoung Shim
Quoted 13 lines · Daniel Vetter
Quoted 12 lines · Inki Dae
Quoted 12 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]]
Sent: Wednesday, August 07, 2013 6:15 PM
To: DRI Development
Cc: Intel Graphics Development; Daniel Vetter; Inki Dae
Subject: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

Note that this is slightly tricky since both drivers store their native objects in dma_buf->priv. But both also embed the base drm_gem_object at the first position, so the implicit cast is ok.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

To use the release helper we need to export it, too.

Yeah, may I repost this patch with additional work? We also need to export with a gem object instead of specific one like you did.

I think dmabuf stuff of exynos can be replaced to common drm_gem_dmabuf. Already dmabuf stuff of drm_gem_cma_helper.c was substituted to common drm_gem_dmabuf with low-level hook functions to use prime helpers.

Ah, but that can easily be done on top of this, right? -Daniel

I think it doesn't matter.

maintainer
#8 lore raw

Re: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

In reply to Daniel Vetter

2013/8/7 Daniel Vetter <[email protected]>

Quoted 18 lines · Joonyoung Shim
Quoted 8 lines · Daniel Vetter
Quoted 7 lines · Inki Dae
Quoted 6 lines
Quoted 6 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]]
Sent: Wednesday, August 07, 2013 6:15 PM
To: DRI Development
Cc: Intel Graphics Development; Daniel Vetter; Inki Dae
Subject: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in

i915/exynos

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

drivers

Note that this is slightly tricky since both drivers store their native objects in dma_buf->priv. But both also embed the base drm_gem_object at the first position, so the implicit cast is ok.

To use the release helper we need to export it, too.

Yeah, may I repost this patch with additional work? We also need to

Quoted 9 lines

export

Quoted 5 lines
Quoted 1 line
Quoted 1 line

with a gem object instead of specific one like you did.

I think dmabuf stuff of exynos can be replaced to common drm_gem_dmabuf. Already dmabuf stuff of drm_gem_cma_helper.c was substituted to common drm_gem_dmabuf with low-level hook functions to use prime helpers.

Ah, but that can easily be done on top of this, right?

Daniel, could you remove exynos related codes from your patch set? Your patch set would make exynos broken because you didn't consider exporting with a gem object for exynos like [PATCH 3/3] drm/i915: explicit store base gem object in dma_buf->priv. So I think your patch set is not complete set, and That is why exynos needs the additional work I mentioned above. So I just wanted to repost your patch set + new one. However, I think not only exynos could go to common drm_gem_dmabuf directly but also it would make your patch set to be complete set if you remove exynos related codes from your patch set. Otherwise, we have to work twice. one is the additional work for resolving exynos broken issue by your patch set, and other is to replace existing dmabuf stuff of exynos to common drm_gem_dmabuf.

Thanks,
Inki Dae

Quoted 10 lines

-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#9 lore raw

Re: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

Quoted 32 lines · Inki Dae

2013/8/7 Daniel Vetter <[email protected]>

Quoted 22 lines · Joonyoung Shim
Quoted 20 lines · Daniel Vetter
Quoted 18 lines · Inki Dae
Quoted 17 lines
Quoted 9 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]]
Sent: Wednesday, August 07, 2013 6:15 PM
To: DRI Development
Cc: Intel Graphics Development; Daniel Vetter; Inki Dae
Subject: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos
drivers

Quoted 5 lines

Note that this is slightly tricky since both drivers store their native objects in dma_buf->priv. But both also embed the base drm_gem_object at the first position, so the implicit cast is ok.

To use the release helper we need to export it, too.

Yeah, may I repost this patch with additional work? We also need to export
with a gem object instead of specific one like you did.

Quoted 5 lines
Quoted 3 lines

I think dmabuf stuff of exynos can be replaced to common drm_gem_dmabuf. Already dmabuf stuff of drm_gem_cma_helper.c was substituted to common drm_gem_dmabuf with low-level hook functions to use prime helpers.

Ah, but that can easily be done on top of this, right?

Quoted 6 lines

Daniel, could you remove exynos related codes from your patch set? Your patch set would make exynos broken because you didn't consider exporting with a gem object for exynos like [PATCH 3/3] drm/i915: explicit store base gem object in dma_buf->priv. So I think your patch set is not complete set, and That is why exynos needs the additional work I mentioned above. So I just wanted to repost your patch set + new one.

Nope, my patch should not break exynos since the base gem_object is the first member of the exynos object, so we don't have any issues with upcasting in exynos dma-buf code. The same applies to i915 dma-buf code, my follow-up patch just makes the code a bit safer.

Quoted 6 lines

However, I think not only exynos could go to common drm_gem_dmabuf directly but also it would make your patch set to be complete set if you remove exynos related codes from your patch set. Otherwise, we have to work twice. one is the additional work for resolving exynos broken issue by your patch set, and other is to replace existing dmabuf stuff of exynos to common drm_gem_dmabuf.

Yeah np, I'll drop exynos then.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
maintainer
#10 lore raw

Re: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

2013/8/7 Daniel Vetter <[email protected]>

Quoted 38 lines · Inki Dae
Quoted 7 lines

2013/8/7 Daniel Vetter <[email protected]>

Quoted 4 lines · Joonyoung Shim
Quoted 2 lines · Daniel Vetter
Quoted 1 line

On Wed, Aug 7, 2013 at 11:40 AM, Inki Dae <[email protected]>

Quoted 13 lines · wrote:
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]]
Sent: Wednesday, August 07, 2013 6:15 PM
To: DRI Development
Cc: Intel Graphics Development; Daniel Vetter; Inki Dae
Subject: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos
drivers

Note that this is slightly tricky since both drivers store their native objects in dma_buf->priv. But both also embed the base drm_gem_object at the first position, so the implicit cast is ok.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

To use the release helper we need to export it, too.

Yeah, may I repost this patch with additional work? We also need to export
with a gem object instead of specific one like you did.

I think dmabuf stuff of exynos can be replaced to common

drm_gem_dmabuf.

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

Already dmabuf stuff of drm_gem_cma_helper.c was substituted to common drm_gem_dmabuf with low-level hook functions to use prime helpers.

Ah, but that can easily be done on top of this, right?

Daniel, could you remove exynos related codes from your patch set? Your patch set would make exynos broken because you didn't consider exporting with a gem object for exynos like [PATCH 3/3] drm/i915: explicit store

Quoted 9 lines

base

Quoted 1 line

gem object in dma_buf->priv. So I think your patch set is not complete

set,

Quoted 2 lines

and That is why exynos needs the additional work I mentioned above. So I just wanted to repost your patch set + new one.

Nope, my patch should not break exynos since the base gem_object is the first member of the exynos object, so we don't have any issues

Ah, right. However, it does not seem like good way.

Quoted 13 lines

with upcasting in exynos dma-buf code. The same applies to i915 dma-buf code, my follow-up patch just makes the code a bit safer.

However, I think not only exynos could go to common drm_gem_dmabuf directly

Quoted 2 lines

but also it would make your patch set to be complete set if you remove exynos related codes from your patch set. Otherwise, we have to work

Quoted 8 lines

twice.

Quoted 1 line

one is the additional work for resolving exynos broken issue by your

patch

Quoted 2 lines

set, and other is to replace existing dmabuf stuff of exynos to common drm_gem_dmabuf.

Yeah np, I'll drop exynos then.

Thanks a lot. :)

Thanks,
Inki Dae

Quoted 10 lines

-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
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

#11 lore raw

Re: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

Quoted 68 lines · Inki Dae

2013/8/7 Daniel Vetter <[email protected]>

Quoted 38 lines · Inki Dae
Quoted 7 lines

2013/8/7 Daniel Vetter <[email protected]>

Quoted 4 lines · Joonyoung Shim
Quoted 2 lines · Daniel Vetter
Quoted 1 line

On Wed, Aug 7, 2013 at 11:40 AM, Inki Dae <[email protected]>

Quoted 13 lines · wrote:
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]]
Sent: Wednesday, August 07, 2013 6:15 PM
To: DRI Development
Cc: Intel Graphics Development; Daniel Vetter; Inki Dae
Subject: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos
drivers

Note that this is slightly tricky since both drivers store their native objects in dma_buf->priv. But both also embed the base drm_gem_object at the first position, so the implicit cast is ok.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

To use the release helper we need to export it, too.

Yeah, may I repost this patch with additional work? We also need to export
with a gem object instead of specific one like you did.

I think dmabuf stuff of exynos can be replaced to common

drm_gem_dmabuf.

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

Already dmabuf stuff of drm_gem_cma_helper.c was substituted to common drm_gem_dmabuf with low-level hook functions to use prime helpers.

Ah, but that can easily be done on top of this, right?

Daniel, could you remove exynos related codes from your patch set? Your patch set would make exynos broken because you didn't consider exporting with a gem object for exynos like [PATCH 3/3] drm/i915: explicit store

Quoted 9 lines

base

Quoted 1 line

gem object in dma_buf->priv. So I think your patch set is not complete

set,

Quoted 2 lines

and That is why exynos needs the additional work I mentioned above. So I just wanted to repost your patch set + new one.

Nope, my patch should not break exynos since the base gem_object is the first member of the exynos object, so we don't have any issues

Ah, right. However, it does not seem like good way.

Quoted 15 lines

with upcasting in exynos dma-buf code. The same applies to i915 dma-buf code, my follow-up patch just makes the code a bit safer.

However, I think not only exynos could go to common drm_gem_dmabuf directly

Quoted 2 lines

but also it would make your patch set to be complete set if you remove exynos related codes from your patch set. Otherwise, we have to work

twice.

Quoted 1 line

one is the additional work for resolving exynos broken issue by your

Quoted 8 lines
Quoted 6 lines

patch

Quoted 2 lines

set, and other is to replace existing dmabuf stuff of exynos to common drm_gem_dmabuf.

Yeah np, I'll drop exynos then.

Thanks a lot. :)

Ah, I remember again why I want to also convert over exynos to the common dma buf release function: Later patches in my prime locking series will change things in there to avoid a userspace-triggerable oops. If we leave out exynos it'll break rather badly for dma-buf export.

I need to think a bit more about what stuff looks like atm, but if I resend those parts I'll include exynos. It's a bit tricky that it still works, but that way you can fix it up without the introduction of a bisect failure point.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
maintainer
#12 lore raw

RE: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

Quoted 40 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Thursday, August 08, 2013 8:21 AM
To: Inki Dae
Cc: Daniel Vetter; Intel Graphics Development; DRI Development
Subject: Re: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

Quoted 21 lines · Inki Dae

2013/8/7 Daniel Vetter <[email protected]>

Quoted 19 lines · Inki Dae
Quoted 7 lines

2013/8/7 Daniel Vetter <[email protected]>

Quoted 4 lines · Joonyoung Shim
Quoted 2 lines · Daniel Vetter
Quoted 1 line

On Wed, Aug 7, 2013 at 11:40 AM, Inki Dae <[email protected]>

Quoted 10 lines · wrote:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]]
Sent: Wednesday, August 07, 2013 6:15 PM
To: DRI Development
Cc: Intel Graphics Development; Daniel Vetter; Inki Dae
Subject: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos
drivers

Note that this is slightly tricky since both drivers store

their

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

native objects in dma_buf->priv. But both also embed the base drm_gem_object at the first position, so the implicit cast is

ok.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

To use the release helper we need to export it, too.

Yeah, may I repost this patch with additional work? We also

Quoted 9 lines

need to

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

export
with a gem object instead of specific one like you did.

I think dmabuf stuff of exynos can be replaced to common

drm_gem_dmabuf.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Already dmabuf stuff of drm_gem_cma_helper.c was substituted to

common

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drm_gem_dmabuf with low-level hook functions to use prime

helpers.

Quoted 56 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

Ah, but that can easily be done on top of this, right?

Daniel, could you remove exynos related codes from your patch set?

Your

Quoted 1 line
Quoted 1 line
Quoted 1 line

patch set would make exynos broken because you didn't consider

exporting

Quoted 1 line
Quoted 1 line
Quoted 1 line

with a gem object for exynos like [PATCH 3/3] drm/i915: explicit

store

Quoted 2 lines
Quoted 2 lines

base

Quoted 1 line

gem object in dma_buf->priv. So I think your patch set is not

complete

Quoted 2 lines
Quoted 2 lines

set,

Quoted 1 line

and That is why exynos needs the additional work I mentioned above.

So I

Quoted 21 lines
Quoted 5 lines
Quoted 1 line

just wanted to repost your patch set + new one.

Nope, my patch should not break exynos since the base gem_object is the first member of the exynos object, so we don't have any issues

Ah, right. However, it does not seem like good way.

Quoted 12 lines

with upcasting in exynos dma-buf code. The same applies to i915 dma-buf code, my follow-up patch just makes the code a bit safer.

However, I think not only exynos could go to common drm_gem_dmabuf directly

Quoted 1 line

but also it would make your patch set to be complete set if you

remove

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

exynos related codes from your patch set. Otherwise, we have to work

twice.

Quoted 1 line

one is the additional work for resolving exynos broken issue by your

patch

Quoted 1 line

set, and other is to replace existing dmabuf stuff of exynos to

common

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

drm_gem_dmabuf.

Yeah np, I'll drop exynos then.

Thanks a lot. :)

Ah, I remember again why I want to also convert over exynos to the common dma buf release function: Later patches in my prime locking series will change things in there to avoid a userspace-triggerable oops. If we leave out exynos it'll break rather badly for dma-buf export.

Quoted 4 lines

I need to think a bit more about what stuff looks like atm, but if I resend those parts I'll include exynos. It's a bit tricky that it still works, but that way you can fix it up without the introduction of a bisect failure point.

I'll repost your patch set + new one that exports to a common gem object; already worked and tested. I think it's good for they to be one set because only using the patch 1/3 doesn't look good even though Exynos works fine with the path 1/3.

So I'll repost it like below if you agree with me,
[PATCH 0/4] Small i915/exynos prime cleanup
[PATCH 1/4] drm: use common drm_gem_dmabuf_release in i915/exynos drivers [PATCH 2/4] drm/i915: unpin backing storage in dmabuf_unmap [PATCH 3/4] drm/i915: explicit store base gem object in dma_buf->priv [PATCH 4/4] drm/exynos: explicit store base gem object in dma_buf->priv

After this, you can take care of them until merged to next. Or you can repost this patch set including my patch again. What you proper doesn't matter to me. :)

And it seems better that exynos keeps using existing dmabuf interfaces without replacing them to common drm_gem_dmabuf ones because we may need features only for Exynos. Actually, now exynos dmabuf includes some features related to v4l2 and gpu driver for more performance.

Thanks,
Inki Dae

Quoted 5 lines

-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

maintainer
#13 lore raw

PATCH 1/4 drm/exynos: explicit store base gem object in dma_buf->priv

---
 drivers/gpu/drm/exynos/exynos_drm_dmabuf.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +8 -4
index 3cd56e1..fd76449 100644
@@ -22,6 +22,11 @@ struct exynos_drm_dmabuf_attachment {
 	bool is_mapped;
 };
 
+static struct exynos_drm_gem_obj *dma_buf_to_obj(struct dma_buf *buf)
+{
+	return to_exynos_gem_obj(buf->priv);
+}
+
 static int exynos_gem_attach_dma_buf(struct dma_buf *dmabuf,
 					struct device *dev,
 					struct dma_buf_attachment *attach)
@@ -63,7 +68,7 @@ static struct sg_table *
 					enum dma_data_direction dir)
 {
 	struct exynos_drm_dmabuf_attachment *exynos_attach = attach->priv;
-	struct exynos_drm_gem_obj *gem_obj = attach->dmabuf->priv;
+	struct exynos_drm_gem_obj *gem_obj = dma_buf_to_obj(attach->dmabuf);
 	struct drm_device *dev = gem_obj->base.dev;
 	struct exynos_drm_gem_buf *buf;
 	struct scatterlist *rd, *wr;
@@ -180,7 +185,7 @@ struct dma_buf *exynos_dmabuf_prime_export(struct drm_device *drm_dev,
 {
 	struct exynos_drm_gem_obj *exynos_gem_obj = to_exynos_gem_obj(obj);
 
-	return dma_buf_export(exynos_gem_obj, &exynos_dmabuf_ops,
+	return dma_buf_export(obj, &exynos_dmabuf_ops,
 				exynos_gem_obj->base.size, flags);
 }
 
@@ -198,8 +203,7 @@ struct drm_gem_object *exynos_dmabuf_prime_import(struct drm_device *drm_dev,
 	if (dma_buf->ops == &exynos_dmabuf_ops) {
 		struct drm_gem_object *obj;
 
-		exynos_gem_obj = dma_buf->priv;
-		obj = &exynos_gem_obj->base;
+		obj = dma_buf->priv;
 
 		/* is it from our device? */
 		if (obj->dev == drm_dev) {
Signature · 1 line
1.7.5.4
maintainer
#14 lore raw

RE: [PATCH 1/4] drm/exynos: explicit store base gem object in dma_buf->priv

Hi, Daniel. You can repost your patch set including the below my patch. And my patch numbering is wrong. Sorry about that.

[PATCH 1/4] -> [PATCH 4/4]

Thanks,
Inki Dae

Quoted 64 lines

-----Original Message-----
From: Inki Dae [mailto:[email protected]]
Sent: Thursday, August 08, 2013 1:40 PM
To: [email protected]
Cc: [email protected]; [email protected]; Inki Dae; Kyungmin Park
Subject: [PATCH 1/4] drm/exynos: explicit store base gem object in dma_buf->priv

---
 drivers/gpu/drm/exynos/exynos_drm_dmabuf.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +8 -4
index 3cd56e1..fd76449 100644
@@ -22,6 +22,11 @@ struct exynos_drm_dmabuf_attachment {
 	bool is_mapped;
 };
 
+static struct exynos_drm_gem_obj *dma_buf_to_obj(struct dma_buf *buf)
+{
+	return to_exynos_gem_obj(buf->priv);
+}
+
 static int exynos_gem_attach_dma_buf(struct dma_buf *dmabuf,
 					struct device *dev,
 					struct dma_buf_attachment *attach)
@@ -63,7 +68,7 @@ static struct sg_table *
 					enum dma_data_direction dir)
 {
 	struct exynos_drm_dmabuf_attachment *exynos_attach = attach->priv;
-	struct exynos_drm_gem_obj *gem_obj = attach->dmabuf->priv;
+	struct exynos_drm_gem_obj *gem_obj = dma_buf_to_obj(attach->dmabuf);
 	struct drm_device *dev = gem_obj->base.dev;
 	struct exynos_drm_gem_buf *buf;
 	struct scatterlist *rd, *wr;
@@ -180,7 +185,7 @@ struct dma_buf *exynos_dmabuf_prime_export(struct
 drm_device *drm_dev,
 {
 	struct exynos_drm_gem_obj *exynos_gem_obj = to_exynos_gem_obj(obj);
 
-	return dma_buf_export(exynos_gem_obj, &exynos_dmabuf_ops,
+	return dma_buf_export(obj, &exynos_dmabuf_ops,
 				exynos_gem_obj->base.size, flags);
 }
@@ -198,8 +203,7 @@ struct drm_gem_object
 *exynos_dmabuf_prime_import(struct drm_device *drm_dev,
 	if (dma_buf->ops == &exynos_dmabuf_ops) {
 		struct drm_gem_object *obj;
 
-		exynos_gem_obj = dma_buf->priv;
-		obj = &exynos_gem_obj->base;
+		obj = dma_buf->priv;
 
 		/* is it from our device? */

if (obj->dev == drm_dev) {
--
1.7.5.4

#15 lore raw

Re: [PATCH 1/4] drm/exynos: explicit store base gem object in dma_buf->priv

Hi Inki,

Quoted 2 lines · Inki Dae

Hi, Daniel. You can repost your patch set including the below my patch. And my patch numbering is wrong. Sorry about that.

Thanks for the patch, I'll submit it toghether with the other ones soon. -Daniel

Quoted 72 lines

[PATCH 1/4] -> [PATCH 4/4]

Thanks,
Inki Dae

Quoted 64 lines

-----Original Message-----
From: Inki Dae [mailto:[email protected]]
Sent: Thursday, August 08, 2013 1:40 PM
To: [email protected]
Cc: [email protected]; [email protected]; Inki Dae; Kyungmin Park
Subject: [PATCH 1/4] drm/exynos: explicit store base gem object in dma_buf->priv

---
 drivers/gpu/drm/exynos/exynos_drm_dmabuf.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +8 -4
index 3cd56e1..fd76449 100644
@@ -22,6 +22,11 @@ struct exynos_drm_dmabuf_attachment {
 	bool is_mapped;
 };
 
+static struct exynos_drm_gem_obj *dma_buf_to_obj(struct dma_buf *buf)
+{
+	return to_exynos_gem_obj(buf->priv);
+}
+
 static int exynos_gem_attach_dma_buf(struct dma_buf *dmabuf,
 					struct device *dev,
 					struct dma_buf_attachment *attach)
@@ -63,7 +68,7 @@ static struct sg_table *
 					enum dma_data_direction dir)
 {
 	struct exynos_drm_dmabuf_attachment *exynos_attach = attach->priv;
-	struct exynos_drm_gem_obj *gem_obj = attach->dmabuf->priv;
+	struct exynos_drm_gem_obj *gem_obj = dma_buf_to_obj(attach->dmabuf);
 	struct drm_device *dev = gem_obj->base.dev;
 	struct exynos_drm_gem_buf *buf;
 	struct scatterlist *rd, *wr;
@@ -180,7 +185,7 @@ struct dma_buf *exynos_dmabuf_prime_export(struct
 drm_device *drm_dev,
 {
 	struct exynos_drm_gem_obj *exynos_gem_obj = to_exynos_gem_obj(obj);
 
-	return dma_buf_export(exynos_gem_obj, &exynos_dmabuf_ops,
+	return dma_buf_export(obj, &exynos_dmabuf_ops,
 				exynos_gem_obj->base.size, flags);
 }
@@ -198,8 +203,7 @@ struct drm_gem_object
 *exynos_dmabuf_prime_import(struct drm_device *drm_dev,
 	if (dma_buf->ops == &exynos_dmabuf_ops) {
 		struct drm_gem_object *obj;
 
-		exynos_gem_obj = dma_buf->priv;
-		obj = &exynos_gem_obj->base;
+		obj = dma_buf->priv;
 
 		/* is it from our device? */

if (obj->dev == drm_dev) {
--
1.7.5.4

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#16 lore raw

Re: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

In reply to Inki Dae
Quoted 123 lines · Inki Dae
Quoted 40 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Thursday, August 08, 2013 8:21 AM
To: Inki Dae
Cc: Daniel Vetter; Intel Graphics Development; DRI Development
Subject: Re: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos drivers

Quoted 21 lines · Inki Dae

2013/8/7 Daniel Vetter <[email protected]>

Quoted 19 lines · Inki Dae
Quoted 7 lines

2013/8/7 Daniel Vetter <[email protected]>

Quoted 4 lines · Joonyoung Shim
Quoted 2 lines · Daniel Vetter
Quoted 1 line

On Wed, Aug 7, 2013 at 11:40 AM, Inki Dae <[email protected]>

Quoted 10 lines · wrote:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]]
Sent: Wednesday, August 07, 2013 6:15 PM
To: DRI Development
Cc: Intel Graphics Development; Daniel Vetter; Inki Dae
Subject: [PATCH 1/3] drm: use common drm_gem_dmabuf_release in i915/exynos
drivers

Note that this is slightly tricky since both drivers store

their

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

native objects in dma_buf->priv. But both also embed the base drm_gem_object at the first position, so the implicit cast is

ok.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

To use the release helper we need to export it, too.

Yeah, may I repost this patch with additional work? We also

Quoted 9 lines

need to

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

export
with a gem object instead of specific one like you did.

I think dmabuf stuff of exynos can be replaced to common

drm_gem_dmabuf.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Already dmabuf stuff of drm_gem_cma_helper.c was substituted to

common

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drm_gem_dmabuf with low-level hook functions to use prime

helpers.

Quoted 56 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

Ah, but that can easily be done on top of this, right?

Daniel, could you remove exynos related codes from your patch set?

Your

Quoted 1 line
Quoted 1 line
Quoted 1 line

patch set would make exynos broken because you didn't consider

exporting

Quoted 1 line
Quoted 1 line
Quoted 1 line

with a gem object for exynos like [PATCH 3/3] drm/i915: explicit

store

Quoted 2 lines
Quoted 2 lines

base

Quoted 1 line

gem object in dma_buf->priv. So I think your patch set is not

complete

Quoted 2 lines
Quoted 2 lines

set,

Quoted 1 line

and That is why exynos needs the additional work I mentioned above.

So I

Quoted 21 lines
Quoted 5 lines
Quoted 1 line

just wanted to repost your patch set + new one.

Nope, my patch should not break exynos since the base gem_object is the first member of the exynos object, so we don't have any issues

Ah, right. However, it does not seem like good way.

Quoted 12 lines

with upcasting in exynos dma-buf code. The same applies to i915 dma-buf code, my follow-up patch just makes the code a bit safer.

However, I think not only exynos could go to common drm_gem_dmabuf directly

Quoted 1 line

but also it would make your patch set to be complete set if you

remove

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

exynos related codes from your patch set. Otherwise, we have to work

twice.

Quoted 1 line

one is the additional work for resolving exynos broken issue by your

patch

Quoted 1 line

set, and other is to replace existing dmabuf stuff of exynos to

common

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

drm_gem_dmabuf.

Yeah np, I'll drop exynos then.

Thanks a lot. :)

Ah, I remember again why I want to also convert over exynos to the common dma buf release function: Later patches in my prime locking series will change things in there to avoid a userspace-triggerable oops. If we leave out exynos it'll break rather badly for dma-buf export.

Quoted 4 lines

I need to think a bit more about what stuff looks like atm, but if I resend those parts I'll include exynos. It's a bit tricky that it still works, but that way you can fix it up without the introduction of a bisect failure point.

I'll repost your patch set + new one that exports to a common gem object; already worked and tested. I think it's good for they to be one set because only using the patch 1/3 doesn't look good even though Exynos works fine with the path 1/3.

So I'll repost it like below if you agree with me,
[PATCH 0/4] Small i915/exynos prime cleanup
[PATCH 1/4] drm: use common drm_gem_dmabuf_release in i915/exynos drivers [PATCH 2/4] drm/i915: unpin backing storage in dmabuf_unmap [PATCH 3/4] drm/i915: explicit store base gem object in dma_buf->priv [PATCH 4/4] drm/exynos: explicit store base gem object in dma_buf->priv

Quoted 3 lines

After this, you can take care of them until merged to next. Or you can repost this patch set including my patch again. What you proper doesn't matter to me. :)

Yeah, sounds like a plan. And I think those 4 patches can go in earlier, the later patches I have need some more thought. Note that the i915 patches have new versions meanwhile, so if you just submit the exynos one I can integrate into my series.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#17 lore raw

PATCH 2/3 drm/i915: unpin backing storage in dmabuf_unmap

In reply to Daniel Vetter

This fixes a WARN in i915_gem_free_object when the obj->pages_pin_count isn't 0.

---
 drivers/gpu/drm/i915/i915_gem_dmabuf.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/i915/i915_gem_dmabuf.c +4 -0
index 63ee1a9..0bf3d51 100644
@@ -85,9 +85,13 @@ static void i915_gem_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				   struct sg_table *sg,
 				   enum dma_data_direction dir)
 {
+	struct drm_i915_gem_object *obj = attachment->dmabuf->priv;
+
 	dma_unmap_sg(attachment->dev, sg->sgl, sg->nents, dir);
 	sg_free_table(sg);
 	kfree(sg);
+
+	i915_gem_object_unpin_pages(obj);
 }
 
 static void *i915_gem_dmabuf_vmap(struct dma_buf *dma_buf)
Signature · 1 line
1.8.3.2
#18 lore raw

Re: [PATCH 2/3] drm/i915: unpin backing storage in dmabuf_unmap

Quoted 6 lines · Daniel Vetter

This fixes a WARN in i915_gem_free_object when the obj->pages_pin_count isn't 0.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=67391

Quoted 25 lines
---
 drivers/gpu/drm/i915/i915_gem_dmabuf.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/i915/i915_gem_dmabuf.c +4 -0
index 63ee1a9..0bf3d51 100644
@@ -85,9 +85,13 @@ static void i915_gem_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				   struct sg_table *sg,
 				   enum dma_data_direction dir)
 {
+	struct drm_i915_gem_object *obj = attachment->dmabuf->priv;
+
 	dma_unmap_sg(attachment->dev, sg->sgl, sg->nents, dir);
 	sg_free_table(sg);
 	kfree(sg);
+
+	i915_gem_object_unpin_pages(obj);
 }
 
 static void *i915_gem_dmabuf_vmap(struct dma_buf *dma_buf)
Signature · 1 line
1.8.3.2
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#19 lore raw

Re: [Intel-gfx] [PATCH 2/3] drm/i915: unpin backing storage in dmabuf_unmap

In reply to Daniel Vetter
Quoted 6 lines · Daniel Vetter

This fixes a WARN in i915_gem_free_object when the obj->pages_pin_count isn't 0.

Papers over the WARN with iffy locking. Not all callers hold struct_mutex, right? Worse some do, some don't...

What's the long term plan here?
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#20 lore raw

Re: [Intel-gfx] [PATCH 2/3] drm/i915: unpin backing storage in dmabuf_unmap

Quoted 10 lines · Chris Wilson
Quoted 6 lines · Daniel Vetter

This fixes a WARN in i915_gem_free_object when the obj->pages_pin_count isn't 0.

Papers over the WARN with iffy locking. Not all callers hold struct_mutex, right? Worse some do, some don't...

Oops, that needs mutex locking here. I've checked the code and none of the callers here should ever hold our own dev->struct_mutex (due to the self-import checks we bypass dma-buf for our own objects) so no immediate deadlock. But it's easy to create circles and piss off lockded ofc.

Quoted 1 line

What's the long term plan here?

Per-bo locking with ww mutexes. Locking is done by the callers of map/unmap, sonce only those can properly do the ww locking dance on all relevent buffers of a batch upfront. It's going to be fun ;-)

Looking closer I've also spotted that our map_buf callback has a call to i915_mutex_lock_interruptible, which means the map can fail with -EINTR. Currently it seems unspec'ed whether map is allowed to do that, but current callers certainly can't cope with this. I'll throw a 2nd patch on top.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#21 lore raw

PATCH 1/2 drm/i915: unpin backing storage in dmabuf_unmap

This fixes a WARN in i915_gem_free_object when the obj->pages_pin_count isn't 0.

v2: Add locking to unmap, noticed by Chris Wilson. Note that even though we call unmap with our own dev->struct_mutex held that won't result in an immediate deadlock since we never go through the dma_buf interfaces for our own, reimported buffers. But it's still easy to blow up and anger lockdep, but that's already the case with our ->map implementation. Fixing this for real will involve per dma-buf ww mutex locking by the callers. And lots of fun. So go with the duct-tape approach for now.

---
 drivers/gpu/drm/i915/i915_gem_dmabuf.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/i915/i915_gem_dmabuf.c +8 -0
index 63ee1a9..f7e1682 100644
@@ -85,9 +85,17 @@ static void i915_gem_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				   struct sg_table *sg,
 				   enum dma_data_direction dir)
 {
+	struct drm_i915_gem_object *obj = attachment->dmabuf->priv;
+
+	mutex_lock(&obj->base.dev->struct_mutex);
+
 	dma_unmap_sg(attachment->dev, sg->sgl, sg->nents, dir);
 	sg_free_table(sg);
 	kfree(sg);
+
+	i915_gem_object_unpin_pages(obj);
+
+	mutex_unlock(&obj->base.dev->struct_mutex);
 }
 
 static void *i915_gem_dmabuf_vmap(struct dma_buf *dma_buf)
Signature · 1 line
1.8.3.2
#22 lore raw

PATCH 2/2 drm/i915: no interruptible locking for dma_buf->map

It's unclear whether ->map is allowed to fail with -EINTR, but looking at current callers it's pretty clear that they don't expect this to happen. So use a blocking mutex_lock call. Since we don't wait for the gpu in our ->map callback the lack of the gpu hang checks doesn't matter.

Furthermore the goal is to eventually have per dma-buf locking done by callers with ww mutexes, so this will then be removed.

---
 drivers/gpu/drm/i915/i915_gem_dmabuf.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_gem_dmabuf.c +1 -3
index f7e1682..63c0818 100644
@@ -35,9 +35,7 @@ static struct sg_table *i915_gem_map_dma_buf(struct dma_buf_attachment *attachme
 	struct scatterlist *src, *dst;
 	int ret, i;
 
-	ret = i915_mutex_lock_interruptible(obj->base.dev);
-	if (ret)
-		return ERR_PTR(ret);
+	mutex_lock(&obj->base.dev->struct_mutex);
 
 	ret = i915_gem_object_get_pages(obj);
 	if (ret) {
Signature · 1 line
1.8.3.2
#23 lore raw

Re: [PATCH 2/2] drm/i915: no interruptible locking for dma_buf->map

Quoted 11 lines · Daniel Vetter

It's unclear whether ->map is allowed to fail with -EINTR, but looking at current callers it's pretty clear that they don't expect this to happen. So use a blocking mutex_lock call. Since we don't wait for the gpu in our ->map callback the lack of the gpu hang checks doesn't matter.

Furthermore the goal is to eventually have per dma-buf locking done by callers with ww mutexes, so this will then be removed.

Ugh, who can't handle EINTR here but can handle all the other errors? -Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#24 lore raw

Re: [PATCH 2/2] drm/i915: no interruptible locking for dma_buf->map

Quoted 7 lines · Chris Wilson
Quoted 6 lines · Daniel Vetter

It's unclear whether ->map is allowed to fail with -EINTR, but looking at current callers it's pretty clear that they don't expect this to happen. So use a blocking mutex_lock call. Since we don't wait for the gpu in our ->map callback the lack of the gpu hang checks doesn't matter.

Quoted 7 lines
Quoted 5 lines

Furthermore the goal is to eventually have per dma-buf locking done by callers with ww mutexes, so this will then be removed.

Ugh, who can't handle EINTR here but can handle all the other errors?

Ok, I've re-read the code and I think callers can actually cope. I'm just freaked out that we don't have test coverage for these case, but that should be a moot point once all the locking is converted over to ww mutexes. So I'll drop this patch here.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#25 lore raw

Re: [PATCH 1/2] drm/i915: unpin backing storage in dmabuf_unmap

In reply to Daniel Vetter

Op 07-08-13 12:09, Daniel Vetter schreef:

Quoted 12 lines

This fixes a WARN in i915_gem_free_object when the obj->pages_pin_count isn't 0.

v2: Add locking to unmap, noticed by Chris Wilson. Note that even though we call unmap with our own dev->struct_mutex held that won't result in an immediate deadlock since we never go through the dma_buf interfaces for our own, reimported buffers. But it's still easy to blow up and anger lockdep, but that's already the case with our ->map implementation. Fixing this for real will involve per dma-buf ww mutex locking by the callers. And lots of fun. So go with the duct-tape approach for now.

Quoted 6 lines

Acked, this was my original patch to solve the issue.

I want to note that locking struct_mutex here will break lockdep, but it's a problem in drm, not this patch.

~Maarten

#26 lore raw

Re: [PATCH 1/2] drm/i915: unpin backing storage in dmabuf_unmap

In reply to Daniel Vetter
Quoted 28 lines · Daniel Vetter

This fixes a WARN in i915_gem_free_object when the obj->pages_pin_count isn't 0.

v2: Add locking to unmap, noticed by Chris Wilson. Note that even though we call unmap with our own dev->struct_mutex held that won't result in an immediate deadlock since we never go through the dma_buf interfaces for our own, reimported buffers. But it's still easy to blow up and anger lockdep, but that's already the case with our ->map implementation. Fixing this for real will involve per dma-buf ww mutex locking by the callers. And lots of fun. So go with the duct-tape approach for now.

---
 drivers/gpu/drm/i915/i915_gem_dmabuf.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/i915/i915_gem_dmabuf.c +0 -0
index 63ee1a9..f7e1682 100644
@@ -85,9 +85,17 @@ static void i915_gem_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				   struct sg_table *sg,
 				   enum dma_data_direction dir)

drivers/gpu/drm/i915/i915_gem_dmabuf.c static void i915_gem_unmap_dma_buf(struct dma_buf_attachment *attachment, · line 96

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_dmabuf.c +6 -0
 {
+	struct drm_i915_gem_object *obj = attachment->dmabuf->priv;
+
+	mutex_lock(&obj->base.dev->struct_mutex);
+
 	dma_unmap_sg(attachment->dev, sg->sgl, sg->nents, dir);
 	sg_free_table(sg);
 	kfree(sg);
+
+	i915_gem_object_unpin_pages(obj);

I am curious - would it logic of first unpinning, and then doing the dma_unmap_sg make more sense? As in, in the map path we do:

dma_map
pin

And in here you do the same:

dma_unmap
unpin

But I would have thought that on a unroll you would do it in reverse order, so:

unpin
dma_unmap

Quoted 12 lines
drivers/gpu/drm/i915/i915_gem_dmabuf.c +2 -0
+
+	mutex_unlock(&obj->base.dev->struct_mutex);
 }
 
 static void *i915_gem_dmabuf_vmap(struct dma_buf *dma_buf)
Signature · 6 lines
1.8.3.2

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#27 lore raw

Re: [PATCH 1/2] drm/i915: unpin backing storage in dmabuf_unmap

Quoted 43 lines · Konrad Rzeszutek Wilk
Quoted 28 lines · Daniel Vetter

This fixes a WARN in i915_gem_free_object when the obj->pages_pin_count isn't 0.

v2: Add locking to unmap, noticed by Chris Wilson. Note that even though we call unmap with our own dev->struct_mutex held that won't result in an immediate deadlock since we never go through the dma_buf interfaces for our own, reimported buffers. But it's still easy to blow up and anger lockdep, but that's already the case with our ->map implementation. Fixing this for real will involve per dma-buf ww mutex locking by the callers. And lots of fun. So go with the duct-tape approach for now.

---
 drivers/gpu/drm/i915/i915_gem_dmabuf.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/i915/i915_gem_dmabuf.c +0 -0
index 63ee1a9..f7e1682 100644
@@ -85,9 +85,17 @@ static void i915_gem_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				   struct sg_table *sg,
 				   enum dma_data_direction dir)

drivers/gpu/drm/i915/i915_gem_dmabuf.c static void i915_gem_unmap_dma_buf(struct dma_buf_attachment *attachment, · line 96

Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_dmabuf.c +6 -0
 {
+	struct drm_i915_gem_object *obj = attachment->dmabuf->priv;
+
+	mutex_lock(&obj->base.dev->struct_mutex);
+
 	dma_unmap_sg(attachment->dev, sg->sgl, sg->nents, dir);
 	sg_free_table(sg);
 	kfree(sg);
+
+	i915_gem_object_unpin_pages(obj);

I am curious - would it logic of first unpinning, and then doing the dma_unmap_sg make more sense? As in, in the map path we do:

Quoted 2 lines

dma_map
pin

Actually this is the wrong way around, and is a potential issue. Hindsight is a powerful tool.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#28 lore raw

PATCH 3/3 drm/i915: explicit store base gem object in dma_buf->priv

In reply to Daniel Vetter

Makes it more obviously correct what tricks we play by reusing the drm prime release helper.

---
 drivers/gpu/drm/i915/i915_gem_dmabuf.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_gem_dmabuf.c +12 -9
index 0bf3d51..3c0edaf 100644
@@ -27,10 +27,15 @@
 #include "i915_drv.h"
 #include <linux/dma-buf.h>
 
+static struct drm_i915_gem_object *dma_buf_to_obj(struct dma_buf *buf)
+{
+	return to_intel_bo(buf->priv);
+}
+
 static struct sg_table *i915_gem_map_dma_buf(struct dma_buf_attachment *attachment,
 					     enum dma_data_direction dir)
 {
-	struct drm_i915_gem_object *obj = attachment->dmabuf->priv;
+	struct drm_i915_gem_object *obj = dma_buf_to_obj(attachment->dmabuf);
 	struct sg_table *st;
 	struct scatterlist *src, *dst;
 	int ret, i;
@@ -85,7 +90,7 @@ static void i915_gem_unmap_dma_buf(struct dma_buf_attachment *attachment,
 				   struct sg_table *sg,
 				   enum dma_data_direction dir)
 {
-	struct drm_i915_gem_object *obj = attachment->dmabuf->priv;
+	struct drm_i915_gem_object *obj = dma_buf_to_obj(attachment->dmabuf);
 
 	dma_unmap_sg(attachment->dev, sg->sgl, sg->nents, dir);
 	sg_free_table(sg);
@@ -96,7 +101,7 @@ static void i915_gem_unmap_dma_buf(struct dma_buf_attachment *attachment,
 
 static void *i915_gem_dmabuf_vmap(struct dma_buf *dma_buf)
 {
-	struct drm_i915_gem_object *obj = dma_buf->priv;
+	struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
 	struct drm_device *dev = obj->base.dev;
 	struct sg_page_iter sg_iter;
 	struct page **pages;
@@ -144,7 +149,7 @@ error:
 
 static void i915_gem_dmabuf_vunmap(struct dma_buf *dma_buf, void *vaddr)
 {
-	struct drm_i915_gem_object *obj = dma_buf->priv;
+	struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
 	struct drm_device *dev = obj->base.dev;
 	int ret;
 
@@ -187,7 +192,7 @@ static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *
 
 static int i915_gem_begin_cpu_access(struct dma_buf *dma_buf, size_t start, size_t length, enum dma_data_direction direction)
 {
-	struct drm_i915_gem_object *obj = dma_buf->priv;
+	struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
 	struct drm_device *dev = obj->base.dev;
 	int ret;
 	bool write = (direction == DMA_BIDIRECTIONAL || direction == DMA_TO_DEVICE);
@@ -218,9 +223,7 @@ static const struct dma_buf_ops i915_dmabuf_ops =  {
 struct dma_buf *i915_gem_prime_export(struct drm_device *dev,
 				      struct drm_gem_object *gem_obj, int flags)
 {
-	struct drm_i915_gem_object *obj = to_intel_bo(gem_obj);
-
-	return dma_buf_export(obj, &i915_dmabuf_ops, obj->base.size, flags);
+	return dma_buf_export(gem_obj, &i915_dmabuf_ops, gem_obj->size, flags);
 }
 
 static int i915_gem_object_get_pages_dmabuf(struct drm_i915_gem_object *obj)
@@ -257,7 +260,7 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
 
 	/* is this one of own objects? */
 	if (dma_buf->ops == &i915_dmabuf_ops) {
-		obj = dma_buf->priv;
+		obj = dma_buf_to_obj(dma_buf);
 		/* is it from our device? */
 		if (obj->base.dev == dev) {
 			/*
Signature · 1 line
1.8.3.2
Reviewed-by on v1 3/3
#29 lore raw

Re: [PATCH 3/3] drm/i915: explicit store base gem object in dma_buf->priv

Quoted 4 lines · Daniel Vetter

Makes it more obviously correct what tricks we play by reusing the drm prime release helper.

I do like these little typesafe cast helpers.

-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre