VMA OFFSET MANAGER(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… vma offset manager πŸ’…

okay so welcome to the vma offset manager, bestie β€” this is the kernel API manual page for it, and honestly? it's kind of a vibe. let's get into it 🫢


🌸 DESCRIPTION 🌸

so the vma-manager's whole job? it's responsible to map arbitrary driver-dependent memory regions into the linear user address-space. that's it, that's the gig ✨ it provides offsets to the caller which can then be used on the address_space of the drm-device. and it takes care to not overlap regions, to size them appropriately, and to not confuse mm-core by inconsistent fake vm_pgoff fields. no cap, it's very considerate πŸ’…

🚨 real talk though: drivers shouldn't use this for object placement in VMEM. this manager should only be used to manage mappings into linear user-space VMs. periodt.

🧚 the backend situation

we use drm_mm as backend to manage object allocations. but β€” and this is the important part β€” it is highly optimized for alloc/free calls, not lookups. hence, we use an rb-tree to speed up offset lookups. iykyk, different data structure for different problems πŸ’–

πŸ’€ the big no-no

you must not use multiple offset managers on a single address_space. otherwise, mm-core will be unable to tear down memory mappings as the VM will no longer be linear. like... don't do it. it's giving chaos. 😭

πŸŽ€ pages, not bytes (please remember this)

this offset manager works on page-based addresses. that is, every argument and return code (with the exception of drm_vma_node_offset_addr) is given in number of pages, not number of bytes. so object sizes and offsets must always be page-aligned (as usual). if you want to get a valid byte-based user-space address for a given offset, please see drm_vma_node_offset_addr. it's literally right there bestie πŸ¦‹

πŸ”₯ bonus round: access management

additionally to offset management, the vma offset manager also handles access management. for every open-file context that is allowed to access a given node, you must call drm_vma_node_allow. otherwise, an mmap call on this open-file with the offset of the node will fail with -EACCES. 😀 to revoke access again, use drm_vma_node_revoke. however β€” important β€” the caller is responsible for destroying already existing mappings, if required. that part's on you, queen πŸ‘‘


πŸ’œ SEE ALSO πŸ’œ


and that's the whole page, bestie!! 🌈 this little icon lives in ./drivers/gpu/drm, it's stamped October 2026, and it goes by the name vma offset manager(9) β€” go forth and map those regions responsibly πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from