STRUCT DMA_BUF_SYNC(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

hiii bestie πŸ’… welcome to struct dma_buf_sync(9) from the Kernel API Manual β€” we're literally about to make CPU access and DMA buffers get along ✨

🌸 NAME 🌸

struct dma_buf_sync β€” Synchronize with CPU access. no cap, that's the whole vibe check 🫢

✨ SYNOPSIS ✨

struct dma_buf_sync {
    __u64 flags;
 };

🧩 Members 🧩

  • flags β€” the set of access flags πŸ‘‘
  • DMA_BUF_SYNC_START β€” Indicates the start of a map access session. 🎬
  • DMA_BUF_SYNC_END β€” Indicates the end of a map access session. πŸŽ€
  • DMA_BUF_SYNC_READ β€” Indicates that the mapped DMA buffer will be read by the client via the CPU map. πŸ“–
  • DMA_BUF_SYNC_WRITE β€” Indicates that the mapped DMA buffer will be written by the client via the CPU map. ✍️
  • DMA_BUF_SYNC_RW β€” An alias for DMA_BUF_SYNC_READ | DMA_BUF_SYNC_WRITE. πŸ’…

πŸ’« Description πŸ’«

Okay so picture this: when a DMA buffer is accessed from the CPU via mmap, it is not always possible to guarantee coherency between the CPU-visible map and underlying memory. 😭 To manage coherency, DMA_BUF_IOCTL_SYNC must be used to bracket any CPU access to give the kernel the chance to shuffle memory around if needed. ✨

Prior to accessing the map, the client must call DMA_BUF_IOCTL_SYNC with DMA_BUF_SYNC_START and the appropriate read/write flags. Once the access is complete, the client should call DMA_BUF_IOCTL_SYNC with DMA_BUF_SYNC_END and the same read/write flags. 🫢

The synchronization provided via DMA_BUF_IOCTL_SYNC only provides cache coherency. It does not prevent other processes or devices from accessing the memory at the same time. ⚠️ If synchronization with a GPU or other device driver is required, it is the client's responsibility to wait for buffer to be ready for reading or writing before calling this ioctl with DMA_BUF_SYNC_START. Likewise, the client must ensure that follow-up work is not submitted to GPU or other device driver until after this ioctl has been called with DMA_BUF_SYNC_END? (yes bestie, that question mark is part of the sentence energy 😭)

If the driver or API with which the client is interacting uses implicit synchronization, waiting for prior work to complete can be done via poll on the DMA buffer file descriptor. πŸ¦‹ If the driver or API requires explicit synchronization, the client may have to wait on a sync_file or other synchronization primitive outside the scope of the DMA buffer API. πŸ‘‘

πŸ‘€ SEE ALSO πŸ‘€

  • Kernel file ./include/uapi/linux/dma-buf.h
  • struct dma_buf_export_sync_file(9)
  • struct dma_buf_import_sync_file(9)

okay that's the page bestie πŸŽ€ source/version: ./include/uapi/linux; date: October 2026; page: struct dma_buf_sync(9). mwah πŸ’‹

πŸ“¦ where this page comes from