Locking(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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:


🌸 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