FENCE CROSS-DRIVER CONTRACT(9)
fence cross-driver contract(9) ๐
okay so this is from the Kernel API Manual, and itโs the whole dma_fence cross-driver contract situation, bestie ๐
. Since dma_fence provides a cross-driver contract, literally every driver has to follow the same rules, no cap:
- Fences must complete in a reasonable time. Fences which represent kernels and shaders submitted by userspace could run forever, so they must be backed up by timeout and gpu hang recovery code. Minimally that code must prevent further command submission and force complete all in-flight fences, e.g. when the driver or hardware do not support gpu reset, or if the gpu reset failed for some reason. Ideally the driver supports gpu recovery which only affects the offending userspace context, and no other userspace submissions. โจ
- Drivers may have different ideas of what completion within a reasonable time means. Some hang recovery code uses a fixed timeout, others a mix between observing forward progress and increasingly strict timeouts. Drivers should not try to second guess timeout handling of fences from other drivers. ๐ โโ๏ธ
- Deadlock prevention era. To ensure thereโs no deadlocks of
dma_fence_waitagainst other locks, drivers should annotate all code required to reachdma_fence_signal, which completes the fences, withdma_fence_begin_signallinganddma_fence_end_signalling. ๐ - Drivers are allowed to call
dma_fence_waitwhile holdingdma_resv_lock. This means any code required for fence completion cannot acquire adma_resvlock. Note that this also pulls in the entire established locking hierarchy arounddma_resv_lockanddma_resv_unlock. ๐ฎโ๐จ - Drivers are allowed to call
dma_fence_waitfrom their shrinker callbacks. This means any code required for fence completion cannot allocate memory withGFP_KERNEL. ๐ง - Drivers are allowed to call
dma_fence_waitfrom theirmmu_notifierrespectivelymmu_interval_notifiercallbacks. This means any code required for fence completion cannot allocate memory withGFP_NOFSorGFP_NOIO. OnlyGFP_ATOMICis permissible, which might fail. โ ๏ธ
Note that only GPU drivers have a reasonable excuse for both requiringmmu_interval_notifierand shrinker callbacks at the same time as having to track asynchronous compute work usingdma_fence. No driver outside ofdrivers/gpushould ever calldma_fence_waitin such contexts. ๐
๐ SEE ALSO ๐
Kernel file ./drivers/dma-buf/dma-fence.c DMA fences overview(9)dma_fence_get_stub(9)dma_fence_allocate_private_stub(9)dma_fence_context_alloc(9)fence signalling annotation(9)dma_fence_begin_signalling(9)dma_fence_end_signalling(9)dma_fence_signal_timestamp_locked(9)dma_fence_signal_timestamp(9)dma_fence_signal_locked(9)dma_fence_check_and_signal_locked(9)dma_fence_check_and_signal(9)dma_fence_signal(9)dma_fence_wait_timeout(9)dma_fence_release(9)dma_fence_free(9)dma_fence_enable_signaling(9)dma_fence_add_callback(9)dma_fence_get_status(9)dma_fence_remove_callback(9)dma_fence_default_wait(9)dma_fence_wait_any_timeout(9)deadline hints(9)dma_fence_set_deadline(9)dma_fence_describe(9)dma_fence_init(9)dma_fence_init64(9)dma_fence_driver_name(9)dma_fence_timeline_name(9)
xoxo, your kernel bestie ๐ source/version: ./drivers/dma-buf ยท date: October 2026. slay and ship it ๐ซถ
๐ฆ 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