DMA BUF DEVICE ACCESS(9)
π dma buf device access β a Kernel API Manual moment (section 9, bestie)
okay so picture this: you're a device, you want DMA access to a shared DMA buffer, and you're like "how do I even". girl, the usual sequence of operations is actually pretty simple, no cap. let me walk you through it π«Ά
β¨ the sequence (step by step, we love a process)
- the exporter era β the exporter defines their exporter instance using
DEFINE_DMA_BUF_EXPORT_INFOand then callsdma_buf_exportto wrap a private buffer object into adma_buf. then it exports thatdma_bufto userspace as a file descriptor by callingdma_buf_fd. iconic behavior, honestly π - sharing is caring β userspace passes this file-descriptor to all the drivers it wants this buffer shared with. first the file descriptor gets converted to a
dma_bufusingdma_buf_get. then the buffer is attached to the device usingdma_buf_attach. bestie networking but for buffers π
lowkey important: up to this stage the exporter is still free to migrate or reallocate the backing storage. so don't get attached (pun intended) β it can still move π
- DMA time β once the buffer is attached to all devices, userspace can initiate DMA access to the shared buffer. in the kernel this is done by calling
dma_buf_map_attachmentanddma_buf_unmap_attachment. slay, map it and unmap it, that's the whole vibe β¨ - the clean exit β once a driver is done with a shared buffer it needs to call
dma_buf_detach(after cleaning up any mappings!) and then release the reference it acquired withdma_buf_getby callingdma_buf_put. no ghosting your references, that's so not the move π
πΈ the fine print
for the detailed semantics that exporters are expected to implement, see dma_buf_ops. that's where the actual rules live, iykyk π
π¦ SEE ALSO
- Kernel file
./drivers/dma-buf/dma-buf.c dma_buf_iter_begin(9)dma_buf_iter_next(9)implicit fence polling(9)dma_buf_set_name(9)dma_buf_export(9)dma_buf_fd(9)dma_buf_fd_install(9)dma_buf_get(9)dma_buf_put(9)locking convention(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)
and that's the whole page, bestie, you ate that π this little gem lives over in ./drivers/dma-buf and it's stamped October 2026 β go off, kernel docs, periodt β¨π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms