This way we always call the the map/unmap callbacks with the reservation
object held if pin/unpin is also implemented.

For static dma-buf exporters we still have the fallback of using cached sgt.

v2: reordered
v3: rebased on sgt caching
v4: use the cached sgt when possible
v5: cleanup further

Signed-off-by: Christian König <christian.koe...@amd.com>
---
 drivers/dma-buf/dma-buf.c | 10 +++++-----
 include/linux/dma-buf.h   |  3 +++
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
index a18d10c4425a..0aa97bb05636 100644
--- a/drivers/dma-buf/dma-buf.c
+++ b/drivers/dma-buf/dma-buf.c
@@ -691,13 +691,15 @@ struct sg_table *dma_buf_map_attachment(struct 
dma_buf_attachment *attach,
 
        reservation_object_lock(attach->dmabuf->resv, NULL);
        r = dma_buf_pin(attach->dmabuf);
-       reservation_object_unlock(attach->dmabuf->resv);
-       if (r)
+       if (r) {
+               reservation_object_unlock(attach->dmabuf->resv);
                return ERR_PTR(r);
+       }
 
        sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction);
        if (!sg_table)
                sg_table = ERR_PTR(-ENOMEM);
+       reservation_object_unlock(attach->dmabuf->resv);
 
        return sg_table;
 }
@@ -725,10 +727,8 @@ void dma_buf_unmap_attachment(struct dma_buf_attachment 
*attach,
        if (attach->sgt == sg_table)
                return;
 
-       attach->dmabuf->ops->unmap_dma_buf(attach, sg_table,
-                                               direction);
-
        reservation_object_lock(attach->dmabuf->resv, NULL);
+       attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, direction);
        dma_buf_unpin(attach->dmabuf);
        reservation_object_unlock(attach->dmabuf->resv);
 }
diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
index b9d0719581cd..425a771d229c 100644
--- a/include/linux/dma-buf.h
+++ b/include/linux/dma-buf.h
@@ -144,6 +144,9 @@ struct dma_buf_ops {
         * any other kind of sharing that the exporter might wish to make
         * available to buffer-users.
         *
+        * This is always called with the dmabuf->resv object locked when
+        * the pin/unpin callbacks are implemented.
+        *
         * Returns:
         *
         * A &sg_table scatter list of or the backing storage of the DMA buffer,
-- 
2.17.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reply via email to