drivers/dma-buf/dma-fence.c
Source file repositories/reference/linux-study-clean/drivers/dma-buf/dma-fence.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/dma-buf/dma-fence.c- Extension
.c- Size
- 39871 bytes
- Lines
- 1210
- Domain
- Driver Families
- Bucket
- drivers/dma-buf
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/slab.hlinux/export.hlinux/atomic.hlinux/dma-fence.hlinux/sched/signal.hlinux/seq_file.htrace/events/dma_fence.h
Detected Declarations
struct default_wait_cbfunction dma_fence_initfunction dma_fence_init_stubfunction dma_fence_initfunction dma_fence_end_signallingfunction dma_fence_begin_signallingfunction __dma_fence_might_waitfunction dma_fence_waitfunction list_for_each_entry_safefunction dma_fence_waitfunction dma_fence_waitfunction dma_fence_check_and_signalfunction dma_fence_check_and_signalfunction dma_fence_waitfunction indirectlyfunction dma_fence_releasefunction kfree_rcufunction __dma_fence_enable_signalingfunction dma_fence_enable_sw_signalingfunction dma_fence_add_callbackfunction dma_fence_get_status_lockedfunction dma_fence_add_callbackfunction dma_fence_default_wait_cbfunction dma_fence_default_waitfunction dma_fence_test_signaled_anyfunction dma_fence_waitfunction ktimefunction dma_fence_describefunction __dma_fence_initfunction dma_fence_laterfunction dma_fence_latermodule init dma_fence_init_stubexport dma_fence_get_stubexport dma_fence_allocate_private_stubexport dma_fence_context_allocexport dma_fence_begin_signallingexport dma_fence_end_signallingexport dma_fence_signal_timestamp_lockedexport dma_fence_signal_timestampexport dma_fence_signal_lockedexport dma_fence_check_and_signal_lockedexport dma_fence_check_and_signalexport dma_fence_signalexport dma_fence_wait_timeoutexport dma_fence_releaseexport dma_fence_freeexport dma_fence_enable_sw_signalingexport dma_fence_add_callback
Annotated Snippet
subsys_initcall(dma_fence_init_stub);
/**
* dma_fence_get_stub - return a signaled fence
*
* Return a stub fence which is already signaled. The fence's timestamp
* corresponds to the initialisation time of the linux kernel.
*/
struct dma_fence *dma_fence_get_stub(void)
{
return dma_fence_get(&dma_fence_stub);
}
EXPORT_SYMBOL(dma_fence_get_stub);
/**
* dma_fence_allocate_private_stub - return a private, signaled fence
* @timestamp: timestamp when the fence was signaled
*
* Return a newly allocated and signaled stub fence.
*/
struct dma_fence *dma_fence_allocate_private_stub(ktime_t timestamp)
{
struct dma_fence *fence;
fence = kzalloc_obj(*fence);
if (fence == NULL)
return NULL;
dma_fence_init(fence, &dma_fence_stub_ops, NULL, 0, 0);
set_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
&fence->flags);
dma_fence_signal_timestamp(fence, timestamp);
return fence;
}
EXPORT_SYMBOL(dma_fence_allocate_private_stub);
/**
* dma_fence_context_alloc - allocate an array of fence contexts
* @num: amount of contexts to allocate
*
* This function will return the first index of the number of fence contexts
* allocated. The fence context is used for setting &dma_fence.context to a
* unique number by passing the context to dma_fence_init().
*/
u64 dma_fence_context_alloc(unsigned num)
{
WARN_ON(!num);
return atomic64_fetch_add(num, &dma_fence_context_counter);
}
EXPORT_SYMBOL(dma_fence_context_alloc);
/**
* DOC: fence signalling annotation
*
* Proving correctness of all the kernel code around &dma_fence through code
* review and testing is tricky for a few reasons:
*
* * It is a cross-driver contract, and therefore all drivers must follow the
* same rules for lock nesting order, calling contexts for various functions
* and anything else significant for in-kernel interfaces. But it is also
* impossible to test all drivers in a single machine, hence brute-force N vs.
* N testing of all combinations is impossible. Even just limiting to the
* possible combinations is infeasible.
*
* * There is an enormous amount of driver code involved. For render drivers
* there's the tail of command submission, after fences are published,
* scheduler code, interrupt and workers to process job completion,
* and timeout, gpu reset and gpu hang recovery code. Plus for integration
* with core mm with have &mmu_notifier, respectively &mmu_interval_notifier,
* and &shrinker. For modesetting drivers there's the commit tail functions
* between when fences for an atomic modeset are published, and when the
* corresponding vblank completes, including any interrupt processing and
* related workers. Auditing all that code, across all drivers, is not
* feasible.
*
* * Due to how many other subsystems are involved and the locking hierarchies
* this pulls in there is extremely thin wiggle-room for driver-specific
* differences. &dma_fence interacts with almost all of the core memory
* handling through page fault handlers via &dma_resv, dma_resv_lock() and
* dma_resv_unlock(). On the other side it also interacts through all
* allocation sites through &mmu_notifier and &shrinker.
*
* Furthermore lockdep does not handle cross-release dependencies, which means
* any deadlocks between dma_fence_wait() and dma_fence_signal() can't be caught
* at runtime with some quick testing. The simplest example is one thread
* waiting on a &dma_fence while holding a lock::
*
* lock(A);
Annotation
- Immediate include surface: `linux/slab.h`, `linux/export.h`, `linux/atomic.h`, `linux/dma-fence.h`, `linux/sched/signal.h`, `linux/seq_file.h`, `trace/events/dma_fence.h`.
- Detected declarations: `struct default_wait_cb`, `function dma_fence_init`, `function dma_fence_init_stub`, `function dma_fence_init`, `function dma_fence_end_signalling`, `function dma_fence_begin_signalling`, `function __dma_fence_might_wait`, `function dma_fence_wait`, `function list_for_each_entry_safe`, `function dma_fence_wait`.
- Atlas domain: Driver Families / drivers/dma-buf.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.