FENCE CROSS-DRIVER CONTRACT(9)

๐Ÿ“ฆ version 7.3.1, in nixpkgs unstable

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_wait against other locks, drivers should annotate all code required to reach dma_fence_signal, which completes the fences, with dma_fence_begin_signalling and dma_fence_end_signalling. ๐Ÿ”’
  • Drivers are allowed to call dma_fence_wait while holding dma_resv_lock. This means any code required for fence completion cannot acquire a dma_resv lock. Note that this also pulls in the entire established locking hierarchy around dma_resv_lock and dma_resv_unlock. ๐Ÿ˜ฎโ€๐Ÿ’จ
  • Drivers are allowed to call dma_fence_wait from their shrinker callbacks. This means any code required for fence completion cannot allocate memory with GFP_KERNEL. ๐Ÿง 
  • Drivers are allowed to call dma_fence_wait from their mmu_notifier respectively mmu_interval_notifier callbacks. This means any code required for fence completion cannot allocate memory with GFP_NOFS or GFP_NOIO. Only GFP_ATOMIC is permissible, which might fail. โš ๏ธ
Note that only GPU drivers have a reasonable excuse for both requiring mmu_interval_notifier and shrinker callbacks at the same time as having to track asynchronous compute work using dma_fence. No driver outside of drivers/gpu should ever call dma_fence_wait in such contexts. ๐Ÿ‘€

๐Ÿ‘€ SEE ALSO ๐Ÿ‘€


xoxo, your kernel bestie ๐Ÿ’– source/version: ./drivers/dma-buf ยท date: October 2026. slay and ship it ๐Ÿซถ

๐Ÿ“ฆ where this page comes from