drm_gpuvm_sm_map_exec_lock(9)
π drm_gpuvm_sm_map_exec_lock(9)
okay so bestie, buckle up β this is from the Kernel API Manual, and it's literally the function that does the locking homework before your driver starts messing with the VM. no cap, it's giving "responsible older sibling energy" π«Ά
β¨ NAME β¨
drm_gpuvm_sm_map_exec_lock β locks the objects touched by a drm_gpuvm_sm_map()
πΈ SYNOPSIS πΈ
int drm_gpuvm_sm_map_exec_lock (struct drm_gpuvm *gpuvm , struct drm_exec *exec , unsigned int num_fences , struct drm_gpuvm_map_req *req );
π ARGUMENTS π
gpuvmβ thedrm_gpuvmthat represents the GPU VA space πexecβ thedrm_execlocking contextnum_fencesβ for newly mapped objects, the # of fences to reservereqβ ptr todrm_gpuvm_map_reqstruct
π¦ DESCRIPTION π¦
so what this function actually does: it locks (drm_exec_lock_obj) the objects that are gonna get unmapped/remapped, and it locks and prepares (drm_exec_prepare_object) the objects that are gonna be newly mapped. two-for-one, we love to see it β¨
the expected usage is, and I quote:
vm_bind {
struct drm_exec exec;
// IGNORE_DUPLICATES is required, INTERRUPTIBLE_WAIT is recommended:
drm_exec_init(exec, IGNORE_DUPLICATES | INTERRUPTIBLE_WAIT, 0);
drm_exec_until_all_locked (exec) {
for_each_vm_bind_operation {
switch (op->op) {
case DRIVER_OP_UNMAP:
ret = drm_gpuvm_sm_unmap_exec_lock(gpuvm, exec, op->addr, op->range);
break;
case DRIVER_OP_MAP:
ret = drm_gpuvm_sm_map_exec_lock(gpuvm, exec, num_fences, req);
break;
}
drm_exec_retry_on_contention(exec);
if (ret)
return ret;
}
}
}
the whole point, bestie: this enables all the locking to be performed before the driver even begins modifying the VM. main character scheduling behavior, honestly π
and it's safe to do this even in the case of overlapping DRIVER_VM_BIND_OPs, where an earlier op can alter the sequence of steps generated for a later op β because that later altered step will involve the same GEM object(s) you already saw in the earlier locking step. which is, like, the whole flex. for example:
- An earlier driver
DRIVER_OP_UNMAPop removes the need for aDRM_GPUVA_OP_REMAP/UNMAPstep. This is safe because we've already locked the GEM object in the earlierDRIVER_OP_UNMAPop. - An earlier
DRIVER_OP_MAPop overlaps with a laterDRIVER_OP_MAP/UNMAPop, introducing aDRM_GPUVA_OP_REMAP/UNMAPthat wouldn't have been required without the earlierDRIVER_OP_MAP. This is safe because we've already locked the GEM object in the earlierDRIVER_OP_MAPstep.
likeβ¦ it just works. no notes. π₯
β RETURN β
0 on success, or a negative error code π
π SEE ALSO π
grab a snack, this list is long but every single one of them made it π
- Kernel file
./drivers/gpu/drm/drm_gpuvm.c,Overview(9),Split and Merge(9),Madvise Logic - Splitting and Traversal(9),Locking(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_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)
and that's the page, bestie π§ this little baddie lives in ./drivers/gpu/drm and it was dated October 2026 β so go forth, lock responsibly, and slay ππ
π¦ 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