STRUCT DMA_BUF(9)
π NAME π
struct dma_buf β the shared buffer object, bestie. It's the kernel API manual page, and we're gonna get you so comfy with this struct.
Okay so before we dive in: this whole thing is one giant C struct that represents a buffer lots of different devices can share. Think of it as the group chat of memory β everyone's in it, everyone can see the messages, and there are rules about who gets to type when. π«Ά
β¨ SYNOPSIS β¨
Here's the whole struct, laid out exactly how it lives in the kernel. No cap, this is the real shape:
struct dma_buf {
size_t size;
struct file *file;
struct list_head attachments;
const struct dma_buf_ops *ops;
unsigned vmapping_counter;
struct iosys_map vmap_ptr;
const char *exp_name;
const char *name;
spinlock_t name_lock;
struct module *owner;
struct list_head list_node;
void *priv;
struct dma_resv *resv;
wait_queue_head_t poll;
struct dma_buf_poll_cb_t {
struct dma_fence_cb cb;
wait_queue_head_t *poll;
__poll_t active;
} cb_in, cb_out;
};
π Members π
Time for a member-by-member vibe check. Every single one, in order, because we don't skip. π
sizeβ how big the buffer is. It's an invariant over the lifetime of the buffer, meaning it does not change, periodt. Set it and forget it.fileβ the file pointer, used for sharing buffers across, and for refcounting. Peepdma_buf_getanddma_buf_putfor the whole refcount situation.attachmentsβ a list ofdma_buf_attachmentthat denotes all the devices attached, and it's protected by thedma_resvlockresv. Like a guest list, andresvis the bouncer.opsβ thedma_buf_opsassociated with this buffer object. The behavior package, iykyk.vmapping_counterβ used internally to refcnt the vmaps returned bydma_buf_vmap. Protected byresv. Internal business only, don't touch. πvmap_ptrβ the current vmap ptr ifvmapping_counter > 0. Protected byresv.exp_nameβ name of the exporter. Useful for debugging. And it must not be NULL. Like, at all. π¨nameβ the userspace-provided name. Default value isNULL. If it's notNULL, the length cannot be longer thanDMA_BUF_NAME_LEN, including the NIL char. Useful for accounting and debugging. Read/Write accesses are protected byname_lock.
See the IOCTLs DMA_BUF_SET_NAME or DMA_BUF_SET_NAME_A/B.
name_lockβ spinlock to protect name access for read access.ownerβ pointer to the exporter module; used for refcounting when the exporter is a kernel module.list_nodeβ node fordma_bufaccounting and debugging.privβ exporter specific private data for this buffer object. Exporter's own little diary. πresvβ the reservation object linked to this dma-buf.
π₯ IMPLICIT SYNCHRONIZATION RULES: π₯
Drivers which support implicit synchronization of buffer access as e.g. exposed in Implicit Fence Poll Support_ must follow the below rules. No exceptions, bestie, this is the whole assignment:
- Drivers must add a read fence through
dma_resv_add_fencewith theDMA_RESV_USAGE_READflag for anything the userspace API considers a read access. This highly depends upon the API and window system. - Similarly, drivers must add a write fence through
dma_resv_add_fencewith theDMA_RESV_USAGE_WRITEflag for anything the userspace API considers write access. - Drivers may just always add a write fence, since that only causes unnecessary synchronization, but no correctness issues. Slightly extra, but valid. π
- Some drivers only expose a synchronous userspace API with no pipelining across drivers. These do not set any fences for their access. An example here is
v4l. - Driver should use
dma_resv_usage_rwwhen retrieving fences as dependency for implicit synchronization.
π¦ DYNAMIC IMPORTER RULES: π¦
Dynamic importers β see dma_buf_attachment_is_dynamic β have additional constraints on how they set up fences:
- Dynamic importers must obey the write fences and wait for them to signal before allowing access to the buffer's underlying storage through the device.
- Dynamic importers should set fences for any access that they can't disable immediately from their
dma_buf_attach_ops.invalidate_mappingscallback.
π IMPORTANT: π
All drivers and memory management related functions must obey thestruct dma_resvrules β specifically the rules for updating and obeying fences. Seeenum dma_resv_usagefor further descriptions. This is not a suggestion, this is the law. π
And now, back to the members. We didn't forget about these three, they were just chillin' down here:
pollβ for userspace poll support.cb_inβ for userspace poll support.cb_outβ for userspace poll support.
πΈ Description πΈ
This represents a shared buffer, created by calling dma_buf_export. The userspace representation is a normal file descriptor, and you create that by calling dma_buf_fd. So the fancy kernel object has a totally normal everyday fd face for userspace. Main character energy with a relatable disguise. β¨
Shared dma buffers are reference counted using dma_buf_put and get_dma_buf. Keep those counts honest, or things get weird.
Device DMA access is handled by the separate struct dma_buf_attachment β not by this struct itself, okay? Different struct, different job. π
π§ SEE ALSO π§
Kernel file ./include/linux/dma-buf.h, plus the whole friend group:
struct dma_buf_ops(9)struct dma_buf_attach_ops(9)struct dma_buf_attachment(9)struct dma_buf_export_info(9)DEFINE_DMA_BUF_EXPORT_INFO(9)get_dma_buf(9)dma_buf_is_dynamic(9)
π And that's the page, bestie! This one lives over in ./include/linux, and the version stamp on it says October 2026, with the footer reading struct dma_buf(9). Go forth and share those buffers responsibly. Slay. π
π¦ 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