Locking(9)
π Locking π
ok so bestie, welcome to Locking(9) from the Kernel API Manual β grab a lil snack, this one's about who's holding the lock (spoiler: not DRM GPUVM) π«Ά
π the whole vibe
so in terms of managing drm_gpuva entries, DRM GPUVM does not take care of locking itself β nope, that's literally the driver's responsibility, no cap. the driver is the one who has to worry about locking, and the ops it probably wants to protect are: inserting, removing and iterating drm_gpuva objects, plus generating all kinds of operations, such as split / merge or prefetch. β¨
DRM GPUVM also does not take care of the locking of the backing drm_gem_object buffers GPU VA lists and drm_gpuvm_bo abstractions by itself either β drivers are responsible to enforce mutual exclusion using either the GEMs dma_resv lock or the GEMs gpuva.lock mutex. pick your fighter π
π΅οΈ the lockdep checks (yes there are checks)
ok but here's the part that's giving accountability: DRM GPUVM does contain lockdep checks to ensure callers of its API hold the corresponding lock whenever the drm_gem_objects GPU VA list is accessed by functions such as drm_gpuva_link or drm_gpuva_unlink β but also drm_gpuvm_bo_obtain and drm_gpuvm_bo_put. π₯
and the latter is required since on creation and destruction of a drm_gpuvm_bo the drm_gpuvm_bo is attached / removed from the drm_gem_objects gpuva list. subsequent calls to drm_gpuvm_bo_obtain for the same drm_gpuvm and drm_gem_object must be able to observe previous creations and destructions of drm_gpuvm_bos in order to keep instances unique. iykyk π
π the internal lists
the drm_gpuvm's lists for keeping track of external and evicted objects are protected against concurrent insertion / removal and iteration internally. slay, one less thing.
however β and yes there's a however, there's always a however π β drivers still need ensure to protect concurrent calls to functions iterating those lists, namely drm_gpuvm_prepare_objects and drm_gpuvm_validate.
π© the DRM_GPUVM_RESV_PROTECTED option-ish thing
alternatively, drivers can set the DRM_GPUVM_RESV_PROTECTED flag to indicate that the corresponding dma_resv locks are held in order to protect the lists. if DRM_GPUVM_RESV_PROTECTED is set, internal locking is disabled and the corresponding lockdep checks are enabled.
bestie this is an optimization for drivers which are capable of taking the corresponding dma_resv locks and hence do not require internal locking. so like, only if you can actually do the thing, okay? π
β¨ SEE ALSO β¨
here's the whole friend group, fr fr β kernel file ./drivers/gpu/drm/drm_gpuvm.c:
Overview(9)Split and Merge(9)Madvise Logic - Splitting and Traversal(9)Examples(9)get_next_vm_bo_from_list(9)for_each_vm_bo_in_list(9)restore_vm_bo_list(9)drm_gpuvm_bo_is_zombie(9)drm_gpuvm_bo_list_add(9)drm_gpuvm_bo_list_del_init(9)drm_gpuvm_bo_list_del(9)drm_gpuvm_range_valid(9)drm_gpuvm_resv_object_alloc(9)drm_gpuvm_init(9)drm_gpuvm_put(9)drm_gpuvm_prepare_vm(9)drm_gpuvm_prepare_objects(9)drm_gpuvm_prepare_range(9)drm_gpuvm_exec_lock(9)drm_gpuvm_exec_lock_array(9)drm_gpuvm_exec_lock_range(9)drm_gpuvm_validate(9)drm_gpuvm_resv_add_fence(9)drm_gpuvm_bo_create(9)drm_gpuvm_bo_put(9)drm_gpuvm_bo_put_deferred(9)drm_gpuvm_bo_deferred_cleanup(9)drm_gpuvm_bo_find(9)drm_gpuvm_bo_obtain_locked(9)drm_gpuvm_bo_obtain_prealloc(9)drm_gpuvm_bo_extobj_add(9)drm_gpuvm_bo_evict(9)drm_gpuva_insert(9)drm_gpuva_remove(9)drm_gpuva_link(9)drm_gpuva_unlink(9)drm_gpuva_unlink_defer(9)drm_gpuva_find_first(9)drm_gpuva_find(9)drm_gpuvm_interval_empty(9)drm_gpuva_map(9)drm_gpuva_remap(9)drm_gpuva_unmap(9)drm_gpuvm_sm_map(9)drm_gpuvm_sm_unmap(9)drm_gpuvm_sm_map_exec_lock(9)drm_gpuvm_sm_unmap_exec_lock(9)drm_gpuvm_sm_map_ops_create(9)drm_gpuvm_madvise_ops_create(9)drm_gpuvm_sm_unmap_ops_create(9)drm_gpuvm_prefetch_ops_create(9)drm_gpuvm_bo_unmap_ops_create(9)drm_gpuva_ops_free(9)
πΈ that's the whole page, bestie β shipped from ./drivers/gpu/drm, dated October 2026, and it's Locking(9) if you need to cite it in the group chat π π¦
π¦ 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