@@ -795,6 +795,70 @@ static struct sg_table * __map_dma_buf(struct dma_buf_attachment *attach,
795
795
return sg_table ;
796
796
}
797
797
798
+ /**
799
+ * DOC: locking convention
800
+ *
801
+ * In order to avoid deadlock situations between dma-buf exports and importers,
802
+ * all dma-buf API users must follow the common dma-buf locking convention.
803
+ *
804
+ * Convention for importers
805
+ *
806
+ * 1. Importers must hold the dma-buf reservation lock when calling these
807
+ * functions:
808
+ *
809
+ * - dma_buf_pin()
810
+ * - dma_buf_unpin()
811
+ * - dma_buf_map_attachment()
812
+ * - dma_buf_unmap_attachment()
813
+ * - dma_buf_vmap()
814
+ * - dma_buf_vunmap()
815
+ *
816
+ * 2. Importers must not hold the dma-buf reservation lock when calling these
817
+ * functions:
818
+ *
819
+ * - dma_buf_attach()
820
+ * - dma_buf_dynamic_attach()
821
+ * - dma_buf_detach()
822
+ * - dma_buf_export(
823
+ * - dma_buf_fd()
824
+ * - dma_buf_get()
825
+ * - dma_buf_put()
826
+ * - dma_buf_mmap()
827
+ * - dma_buf_begin_cpu_access()
828
+ * - dma_buf_end_cpu_access()
829
+ * - dma_buf_map_attachment_unlocked()
830
+ * - dma_buf_unmap_attachment_unlocked()
831
+ * - dma_buf_vmap_unlocked()
832
+ * - dma_buf_vunmap_unlocked()
833
+ *
834
+ * Convention for exporters
835
+ *
836
+ * 1. These &dma_buf_ops callbacks are invoked with unlocked dma-buf
837
+ * reservation and exporter can take the lock:
838
+ *
839
+ * - &dma_buf_ops.attach()
840
+ * - &dma_buf_ops.detach()
841
+ * - &dma_buf_ops.release()
842
+ * - &dma_buf_ops.begin_cpu_access()
843
+ * - &dma_buf_ops.end_cpu_access()
844
+ *
845
+ * 2. These &dma_buf_ops callbacks are invoked with locked dma-buf
846
+ * reservation and exporter can't take the lock:
847
+ *
848
+ * - &dma_buf_ops.pin()
849
+ * - &dma_buf_ops.unpin()
850
+ * - &dma_buf_ops.map_dma_buf()
851
+ * - &dma_buf_ops.unmap_dma_buf()
852
+ * - &dma_buf_ops.mmap()
853
+ * - &dma_buf_ops.vmap()
854
+ * - &dma_buf_ops.vunmap()
855
+ *
856
+ * 3. Exporters must hold the dma-buf reservation lock when calling these
857
+ * functions:
858
+ *
859
+ * - dma_buf_move_notify()
860
+ */
861
+
798
862
/**
799
863
* dma_buf_dynamic_attach - Add the device to dma_buf's attachments list
800
864
* @dmabuf: [in] buffer to attach device to.
0 commit comments