STRUCT DMA_FENCE(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… struct dma_fence(9) β€” Kernel API Manual energy ✨

okay bestie, so we're in the struct dma_fence(9) manpage, and honestly? it's giving software synchronization primitive and it eats. let's get into it 🫢


🌸 NAME 🌸

struct dma_fence β€” a software synchronization primitive. yes that's the whole name section, she's concise, we respect it πŸ’…


✨ SYNOPSIS ✨

struct dma_fence {
    union {
      spinlock_t *extern_lock;
      spinlock_t inline_lock;
    };
    const struct dma_fence_ops *ops;
    union {
      struct list_head cb_list;
      ktime_t timestamp;
      struct rcu_head rcu;
    };
    u64 context;
    u64 seqno;
    unsigned long flags;
    struct kref refcount;
    int error;
 };

that's the whole struct, character for character, no cap πŸ”₯


πŸŽ€ Members πŸŽ€

  • {unnamed_union} β€” anonymous. she has no name, she's mysterious, we don't ask questions πŸ™ˆ
  • extern_lock β€” an external spin_lock_irqsave used for locking. deprecated babes, so maybe don't πŸ’€
  • inline_lock β€” the alternative: an internal spin_lock_irqsave used for locking. this is the one ✨
  • ops β€” the dma_fence_ops assocciated with this fence. her whole personality comes from ops fr fr
  • {unnamed_union} β€” anonymous again. another mystery icon πŸ‘‘
  • cb_list β€” list of all callbacks to call πŸ“ž
  • timestamp β€” Timestamp for when the fence was signaled. ⭐
  • rcu β€” used for releasing the fence with kfree_rcu
  • context β€” the execution context this fence belongs to, returned by dma_fence_context_alloc
  • seqno β€” the sequence number of this fence inside the execution context. you can compare it to decide which fence would be signaled later πŸ‘€
  • flags β€” A mask of DMA_FENCE_FLAG_*, defined below ⬇️
  • refcount β€” refcount for this fence, keeping her alive 🫢
  • error β€” Optional! only valid if < 0, and it must be set before calling dma_fence_signal. it means the fence has completed with an error 😭

πŸ’– Description πŸ’–

so like, the flags member must be manipulated and read using the appropriate atomic ops (bit_*), which means taking the spinlock will not be needed most of the time. iconic behavior honestly ✨

here's the flag lore:

  • DMA_FENCE_FLAG_INITIALIZED_BIT β€” fence was initialized
  • DMA_FENCE_FLAG_INLINE_LOCK_BIT β€” use the inline spinlock instead of the external one
  • DMA_FENCE_FLAG_SIGNALED_BIT β€” fence is already signaled
  • DMA_FENCE_FLAG_TIMESTAMP_BIT β€” timestamp recorded for fence signaling
  • DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT β€” enable_signaling might have been called
  • DMA_FENCE_FLAG_USER_BITS β€” start of the unused bits, can be used by the implementer of the fence for its own purposes. can be used in different ways by different fence implementers, so do not rely on this 🚨
⚠️ okay this part is important, bestie, pay attention: since atomic bitops are used, this is not guaranteed to be the case. particularly, if the bit was set, but dma_fence_signal was called right before this bit was set, it would have been able to set the DMA_FENCE_FLAG_SIGNALED_BIT, before enable_signaling was called. adding a check for DMA_FENCE_FLAG_SIGNALED_BIT after setting DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT closes this race, and makes sure that after dma_fence_signal was called, any enable_signaling call will have either been completed, or never called at all. race condition: handled πŸ’…πŸ”₯

πŸ¦‹ SEE ALSO πŸ¦‹

Kernel file ./include/linux/dma-fence.h


and that's the whole page bestie, go forth and fence responsibly 🌈

this masterpiece lives in ./include/linux, dated October 2026 β€” shoutout to the source and version, mwah πŸ’œπŸŽ€

πŸ“¦ where this page comes from