STRUCT DMA_FENCE(9)
π 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 externalspin_lock_irqsaveused for locking. deprecated babes, so maybe don't πinline_lockβ the alternative: an internalspin_lock_irqsaveused for locking. this is the one β¨opsβ thedma_fence_opsassocciated with this fence. her whole personality comes fromopsfr 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 withkfree_rcucontextβ the execution context this fence belongs to, returned bydma_fence_context_allocseqnoβ 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 ofDMA_FENCE_FLAG_*, defined below β¬οΈrefcountβ refcount for this fence, keeping her alive π«Άerrorβ Optional! only valid if< 0, and it must be set before callingdma_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 initializedDMA_FENCE_FLAG_INLINE_LOCK_BITβ use the inline spinlock instead of the external oneDMA_FENCE_FLAG_SIGNALED_BITβ fence is already signaledDMA_FENCE_FLAG_TIMESTAMP_BITβ timestamp recorded for fence signalingDMA_FENCE_FLAG_ENABLE_SIGNAL_BITβenable_signalingmight have been calledDMA_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, butdma_fence_signalwas called right before this bit was set, it would have been able to set theDMA_FENCE_FLAG_SIGNALED_BIT, beforeenable_signalingwas called. adding a check forDMA_FENCE_FLAG_SIGNALED_BITafter settingDMA_FENCE_FLAG_ENABLE_SIGNAL_BITcloses this race, and makes sure that afterdma_fence_signalwas called, anyenable_signalingcall will have either been completed, or never called at all. race condition: handled π π₯
π¦ SEE ALSO π¦
Kernel file ./include/linux/dma-fence.h
struct dma_fence_cb(9)struct dma_fence_ops(9)dma_fence_was_initialized(9)dma_fence_put(9)dma_fence_get(9)dma_fence_get_rcu(9)dma_fence_get_rcu_safe(9)dma_fence_spinlock(9)dma_fence_lock_irqsave(9)dma_fence_unlock_irqrestore(9)dma_fence_assert_held(9)- Safe external access to driver provided object members(9)
dma_fence_is_signaled_locked(9)dma_fence_is_signaled(9)__dma_fence_is_later(9)dma_fence_is_later(9)dma_fence_is_later_or_same(9)dma_fence_later(9)dma_fence_get_status_locked(9)dma_fence_set_error(9)dma_fence_timestamp(9)dma_fence_wait(9)dma_fence_is_array(9)dma_fence_is_chain(9)dma_fence_is_container(9)
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
- 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