Skip to contentSkip to conversation

dma-buf: fix unintended pin/unpin warnings

PATCH In review Christian König 3 participants 5 messages May 17, 2021 – May 20, 2021 DMA buffer sharing framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dma-buf: fix unintended pin/unpin warnings

DMA-buf internal users call the pin/unpin functions without having a dynamic attachment. Avoid the warning and backtrace in the logs.

Bugs: https://gitlab.freedesktop.org/drm/intel/-/issues/3481

Fixes c545781e1c55 ("dma-buf: doc polish for pin/unpin")
---
 drivers/dma-buf/dma-buf.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/dma-buf/dma-buf.c +5 -5
index f264b70c383e..eadd1eaa2fb5 100644
@@ -760,7 +760,7 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
 
 		if (dma_buf_is_dynamic(attach->dmabuf)) {
 			dma_resv_lock(attach->dmabuf->resv, NULL);
-			ret = dma_buf_pin(attach);
+			ret = dmabuf->ops->pin(attach);
 			if (ret)
 				goto err_unlock;
 		}
@@ -786,7 +786,7 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
 
 err_unpin:
 	if (dma_buf_is_dynamic(attach->dmabuf))
-		dma_buf_unpin(attach);
+		dmabuf->ops->unpin(attach);
 
 err_unlock:
 	if (dma_buf_is_dynamic(attach->dmabuf))
@@ -843,7 +843,7 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
 		__unmap_dma_buf(attach, attach->sgt, attach->dir);
 
 		if (dma_buf_is_dynamic(attach->dmabuf)) {
-			dma_buf_unpin(attach);
+			dmabuf->ops->unpin(attach);
 			dma_resv_unlock(attach->dmabuf->resv);
 		}
 	}
@@ -956,7 +956,7 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
 	if (dma_buf_is_dynamic(attach->dmabuf)) {
 		dma_resv_assert_held(attach->dmabuf->resv);
 		if (!IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY)) {
-			r = dma_buf_pin(attach);
+			r = attach->dmabuf->ops->pin(attach);
 			if (r)
 				return ERR_PTR(r);
 		}
@@ -968,7 +968,7 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
 
 	if (IS_ERR(sg_table) && dma_buf_is_dynamic(attach->dmabuf) &&
 	     !IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY))
-		dma_buf_unpin(attach);
+		attach->dmabuf->ops->unpin(attach);
 
 	if (!IS_ERR(sg_table) && attach->dmabuf->ops->cache_sgt_mapping) {
 		attach->sgt = sg_table;
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Christian König

DMA-buf internal users call the pin/unpin functions without having a dynamic attachment. Avoid the warning and backtrace in the logs.

Bugs: https://gitlab.freedesktop.org/drm/intel/-/issues/3481

Fixes c545781e1c55 ("dma-buf: doc polish for pin/unpin")
Quoted 56 lines
---
 drivers/dma-buf/dma-buf.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/dma-buf/dma-buf.c +5 -6
index f264b70c383e..eadd1eaa2fb5 100644
@@ -760,7 +760,7 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
 
                if (dma_buf_is_dynamic(attach->dmabuf)) {
                        dma_resv_lock(attach->dmabuf->resv, NULL);
-                       ret = dma_buf_pin(attach);
+                       ret = dmabuf->ops->pin(attach);
                        if (ret)
                                goto err_unlock;
                }
@@ -786,7 +786,7 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
 
 err_unpin:
        if (dma_buf_is_dynamic(attach->dmabuf))
-               dma_buf_unpin(attach);
+               dmabuf->ops->unpin(attach);
 
 err_unlock:
        if (dma_buf_is_dynamic(attach->dmabuf))
@@ -843,7 +843,7 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
                __unmap_dma_buf(attach, attach->sgt, attach->dir);
 
                if (dma_buf_is_dynamic(attach->dmabuf)) {
-                       dma_buf_unpin(attach);
+                       dmabuf->ops->unpin(attach);
                        dma_resv_unlock(attach->dmabuf->resv);
                }
        }
@@ -956,7 +956,7 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
        if (dma_buf_is_dynamic(attach->dmabuf)) {
                dma_resv_assert_held(attach->dmabuf->resv);
                if (!IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY)) {
-                       r = dma_buf_pin(attach);
+                       r = attach->dmabuf->ops->pin(attach);
                        if (r)
                                return ERR_PTR(r);
                }
@@ -968,7 +968,7 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
 
        if (IS_ERR(sg_table) && dma_buf_is_dynamic(attach->dmabuf) &&
             !IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY))
-               dma_buf_unpin(attach);
+               attach->dmabuf->ops->unpin(attach);
 
        if (!IS_ERR(sg_table) && attach->dmabuf->ops->cache_sgt_mapping) {
                attach->sgt = sg_table;
--

2.25.1

#2 lore raw
Quoted 6 lines · Alex Deucher
Quoted 4 lines · Christian König

DMA-buf internal users call the pin/unpin functions without having a dynamic attachment. Avoid the warning and backtrace in the logs.

Quoted 6 lines
Quoted 4 lines

Bugs: https://gitlab.freedesktop.org/drm/intel/-/issues/3481

Fixes c545781e1c55 ("dma-buf: doc polish for pin/unpin")

Hm this means we're losing the dma_resv_assert_held check, do we have that in amdgpu callbacks to make sure we're not accidentally breaking stuff later on?

But yeah lgtm, Reviewed-by: Daniel Vetter <[email protected]>

Quoted 57 lines
Quoted 57 lines
---
 drivers/dma-buf/dma-buf.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/dma-buf/dma-buf.c +5 -6
index f264b70c383e..eadd1eaa2fb5 100644
@@ -760,7 +760,7 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
 
                if (dma_buf_is_dynamic(attach->dmabuf)) {
                        dma_resv_lock(attach->dmabuf->resv, NULL);
-                       ret = dma_buf_pin(attach);
+                       ret = dmabuf->ops->pin(attach);
                        if (ret)
                                goto err_unlock;
                }
@@ -786,7 +786,7 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
 
 err_unpin:
        if (dma_buf_is_dynamic(attach->dmabuf))
-               dma_buf_unpin(attach);
+               dmabuf->ops->unpin(attach);
 
 err_unlock:
        if (dma_buf_is_dynamic(attach->dmabuf))
@@ -843,7 +843,7 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
                __unmap_dma_buf(attach, attach->sgt, attach->dir);
 
                if (dma_buf_is_dynamic(attach->dmabuf)) {
-                       dma_buf_unpin(attach);
+                       dmabuf->ops->unpin(attach);
                        dma_resv_unlock(attach->dmabuf->resv);
                }
        }
@@ -956,7 +956,7 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
        if (dma_buf_is_dynamic(attach->dmabuf)) {
                dma_resv_assert_held(attach->dmabuf->resv);
                if (!IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY)) {
-                       r = dma_buf_pin(attach);
+                       r = attach->dmabuf->ops->pin(attach);
                        if (r)
                                return ERR_PTR(r);
                }
@@ -968,7 +968,7 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
 
        if (IS_ERR(sg_table) && dma_buf_is_dynamic(attach->dmabuf) &&
             !IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY))
-               dma_buf_unpin(attach);
+               attach->dmabuf->ops->unpin(attach);
 
        if (!IS_ERR(sg_table) && attach->dmabuf->ops->cache_sgt_mapping) {
                attach->sgt = sg_table;
--

2.25.1

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#3 lore raw

Am 17.05.21 um 16:57 schrieb Daniel Vetter:

Quoted 6 lines · Alex Deucher
Quoted 5 lines
Quoted 3 lines · Christian König

DMA-buf internal users call the pin/unpin functions without having a dynamic attachment. Avoid the warning and backtrace in the logs.

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

Bugs: https://gitlab.freedesktop.org/drm/intel/-/issues/3481

Fixes c545781e1c55 ("dma-buf: doc polish for pin/unpin")

Hm this means we're losing the dma_resv_assert_held check, do we have that in amdgpu callbacks to make sure we're not accidentally breaking stuff later on?

Mhm, well this is just for calling the pin/unpin internally from the DMA-buf framework itself.

Need to double check, but I think all those cases either have a dma_resv_assert_held() or are locking the reservation themselves before calling the function.

But yeah, rather good point.

Christian.

Quoted 59 lines

But yeah lgtm, Reviewed-by: Daniel Vetter <[email protected]>

Quoted 56 lines
Quoted 56 lines
---
  drivers/dma-buf/dma-buf.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
drivers/dma-buf/dma-buf.c +5 -6
index f264b70c383e..eadd1eaa2fb5 100644
@@ -760,7 +760,7 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
 
                 if (dma_buf_is_dynamic(attach->dmabuf)) {
                         dma_resv_lock(attach->dmabuf->resv, NULL);
-                       ret = dma_buf_pin(attach);
+                       ret = dmabuf->ops->pin(attach);
                         if (ret)
                                 goto err_unlock;
                 }
@@ -786,7 +786,7 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
 
  err_unpin:
         if (dma_buf_is_dynamic(attach->dmabuf))
-               dma_buf_unpin(attach);
+               dmabuf->ops->unpin(attach);
 
  err_unlock:
         if (dma_buf_is_dynamic(attach->dmabuf))
@@ -843,7 +843,7 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
                 __unmap_dma_buf(attach, attach->sgt, attach->dir);
 
                 if (dma_buf_is_dynamic(attach->dmabuf)) {
-                       dma_buf_unpin(attach);
+                       dmabuf->ops->unpin(attach);
                         dma_resv_unlock(attach->dmabuf->resv);
                 }
         }
@@ -956,7 +956,7 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
         if (dma_buf_is_dynamic(attach->dmabuf)) {
                 dma_resv_assert_held(attach->dmabuf->resv);
                 if (!IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY)) {
-                       r = dma_buf_pin(attach);
+                       r = attach->dmabuf->ops->pin(attach);
                         if (r)
                                 return ERR_PTR(r);
                 }
@@ -968,7 +968,7 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
 
         if (IS_ERR(sg_table) && dma_buf_is_dynamic(attach->dmabuf) &&
              !IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY))
-               dma_buf_unpin(attach);
+               attach->dmabuf->ops->unpin(attach);
 
         if (!IS_ERR(sg_table) && attach->dmabuf->ops->cache_sgt_mapping) {
                 attach->sgt = sg_table;
--

2.25.1

#4 lore raw
Quoted 11 lines · Christian König

Am 17.05.21 um 16:57 schrieb Daniel Vetter:

Quoted 10 lines · Alex Deucher
Quoted 9 lines
Quoted 7 lines · Christian König

DMA-buf internal users call the pin/unpin functions without having a dynamic attachment. Avoid the warning and backtrace in the logs.

Bugs: https://gitlab.freedesktop.org/drm/intel/-/issues/3481

Fixes c545781e1c55 ("dma-buf: doc polish for pin/unpin")
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Hm this means we're losing the dma_resv_assert_held check, do we have that in amdgpu callbacks to make sure we're not accidentally breaking stuff later on?

Mhm, well this is just for calling the pin/unpin internally from the DMA-buf framework itself.

It's both, but currently I think no users for it (since it would be pinning for display).

Maybe we could do __ internal wrappers to keep the lockdep checks?

Quoted 3 lines

Need to double check, but I think all those cases either have a dma_resv_assert_held() or are locking the reservation themselves before calling the function.

Yeah right now it's still all good, but that changes easily :-)

Quoted 1 line

But yeah, rather good point.

Do you plan to type something that I can ack?
-Daniel

Quoted 63 lines

Christian.

Quoted 59 lines

But yeah lgtm, Reviewed-by: Daniel Vetter <[email protected]>

Quoted 56 lines
Quoted 56 lines
---
  drivers/dma-buf/dma-buf.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
drivers/dma-buf/dma-buf.c +5 -6
index f264b70c383e..eadd1eaa2fb5 100644
@@ -760,7 +760,7 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
 
                 if (dma_buf_is_dynamic(attach->dmabuf)) {
                         dma_resv_lock(attach->dmabuf->resv, NULL);
-                       ret = dma_buf_pin(attach);
+                       ret = dmabuf->ops->pin(attach);
                         if (ret)
                                 goto err_unlock;
                 }
@@ -786,7 +786,7 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
 
  err_unpin:
         if (dma_buf_is_dynamic(attach->dmabuf))
-               dma_buf_unpin(attach);
+               dmabuf->ops->unpin(attach);
 
  err_unlock:
         if (dma_buf_is_dynamic(attach->dmabuf))
@@ -843,7 +843,7 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
                 __unmap_dma_buf(attach, attach->sgt, attach->dir);
 
                 if (dma_buf_is_dynamic(attach->dmabuf)) {
-                       dma_buf_unpin(attach);
+                       dmabuf->ops->unpin(attach);
                         dma_resv_unlock(attach->dmabuf->resv);
                 }
         }
@@ -956,7 +956,7 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
         if (dma_buf_is_dynamic(attach->dmabuf)) {
                 dma_resv_assert_held(attach->dmabuf->resv);
                 if (!IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY)) {
-                       r = dma_buf_pin(attach);
+                       r = attach->dmabuf->ops->pin(attach);
                         if (r)
                                 return ERR_PTR(r);
                 }
@@ -968,7 +968,7 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
 
         if (IS_ERR(sg_table) && dma_buf_is_dynamic(attach->dmabuf) &&
              !IS_ENABLED(CONFIG_DMABUF_MOVE_NOTIFY))
-               dma_buf_unpin(attach);
+               attach->dmabuf->ops->unpin(attach);
 
         if (!IS_ERR(sg_table) && attach->dmabuf->ops->cache_sgt_mapping) {
                 attach->sgt = sg_table;
--

2.25.1

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch