LOCKING CONVENTION(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… locking convention(9) πŸ’…

okay so bestie, this is locking convention(9) from the Kernel API Manual, and it's basically the group-chat rules for dma-buf locking. ✨ The whole reason this exists? Deadlock situations between dma-buf exports and importers are a vibe killer, so all dma-buf API users must follow the common dma-buf locking convention. No cap. 🫢


🧚 Convention for importers 🧚

  1. Importers must hold the dma-buf reservation lock when calling these functions:
    • dma_buf_pin
    • dma_buf_unpin
    • dma_buf_map_attachment
    • dma_buf_unmap_attachment
    • dma_buf_vmap
    • dma_buf_vunmap
  2. Importers must not hold the dma-buf reservation lock when calling these functions:
    • dma_buf_attach
    • dma_buf_dynamic_attach
    • dma_buf_detach
    • dma_buf_export
    • dma_buf_fd
    • dma_buf_get
    • dma_buf_put
    • dma_buf_mmap
    • dma_buf_begin_cpu_access
    • dma_buf_end_cpu_access
    • dma_buf_map_attachment_unlocked
    • dma_buf_unmap_attachment_unlocked
    • dma_buf_vmap_unlocked
    • dma_buf_vunmap_unlocked

πŸ‘‘ Convention for exporters πŸ‘‘

  1. These dma_buf_ops callbacks are invoked with unlocked dma-buf reservation and exporter can take the lock:
    • dma_buf_ops.attach
    • dma_buf_ops.detach
    • dma_buf_ops.release
    • dma_buf_ops.begin_cpu_access
    • dma_buf_ops.end_cpu_access
    • dma_buf_ops.mmap
  2. These dma_buf_ops callbacks are invoked with locked dma-buf reservation and exporter can't take the lock:
    • dma_buf_ops.pin
    • dma_buf_ops.unpin
    • dma_buf_ops.map_dma_buf
    • dma_buf_ops.unmap_dma_buf
    • dma_buf_ops.vmap
    • dma_buf_ops.vunmap
  3. Exporters must hold the dma-buf reservation lock when calling these functions:
    • dma_buf_invalidate_mappings

🌈 SEE ALSO 🌈

Kernel file ./drivers/dma-buf/dma-buf.c plus these iconic references: dma_buf_iter_begin(9), dma_buf_iter_next(9), implicit fence polling(9), dma_buf_set_name(9), dma buf device access(9), dma_buf_export(9), dma_buf_fd(9), dma_buf_fd_install(9), dma_buf_get(9), dma_buf_put(9), dma_buf_dynamic_attach(9), dma_buf_attach(9), dma_buf_detach(9), dma_buf_pin(9), dma_buf_unpin(9), dma_buf_map_attachment(9), dma_buf_map_attachment_unlocked(9), dma_buf_unmap_attachment(9), dma_buf_unmap_attachment_unlocked(9), dma_buf_attach_revocable(9), dma_buf_invalidate_mappings(9), cpu access(9), dma_buf_begin_cpu_access(9), dma_buf_end_cpu_access(9), dma_buf_mmap(9), dma_buf_vmap(9), dma_buf_vmap_unlocked(9), dma_buf_vunmap(9), dma_buf_vunmap_unlocked(9). πŸ’–


πŸ’– that's the whole page, bestie! source/version: ./drivers/dma-buf Β· date: October 2026 Β· go forth and lock responsibly πŸ’–

πŸ“¦ where this page comes from