drm_gem_mmap_obj(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… drm_gem_mmap_obj(9) πŸ’…

okay bestie, buckle up β€” this is a page from the Kernel API Manual and we're about to make memory-mapping a GEM object make sense, no cap ✨


🌸 NAME 🌸

drm_gem_mmap_obj β€” memory map a GEM object 🫢


✨ SYNOPSIS ✨

int drm_gem_mmap_obj (struct drm_gem_object *obj , unsigned long
obj_size , struct vm_area_struct *vma );

πŸŽ€ ARGUMENTS πŸŽ€

  • obj β€” the GEM object you're trying to map, aka the main character of this whole operation πŸ‘‘
  • obj_size β€” the object size that's getting mapped, counted in bytes (yes, bytes, we're being precise here πŸ’…)
  • vma β€” the VMA for the area that's about to be mapped πŸ¦‹

πŸ’– DESCRIPTION πŸ’–

So what this does is: it sets up the VMA so the GEM object can be mapped, using the GEM object's own vm_ops. That's the whole vibe.

And because GEM objects have different requirements depending on who they are, they've got two paths, and honestly both are valid:

  • they can ship a fault handler inside their vm_ops β€” and in that case any access to the object gets trapped, so somebody can go do migration, GTT binding, surface register allocation, or performance monitoring 😀
  • or they can just mmap the buffer memory synchronously after calling drm_gem_mmap_obj, and honestly? also iconic.

This function is mainly intended to implement the DMABUF mmap operation, specifically for when the GEM object isn't looked up based on its fake offset. And if you're trying to implement the DRM mmap operation instead? Drivers should be using the drm_gem_mmap function for that, not this one. Noted. πŸ“

⚠️ okay this part is important, like actually important: drm_gem_mmap_obj assumes the user has already been granted access to the buffer, whereas drm_gem_mmap is the one that prevents unprivileged users from mapping random objects. So callers must verify access restrictions before calling this helper. No skipping that step, bestie, fr fr πŸ”₯

Return value: it returns 0 or success, or -EINVAL if the object size is smaller than the VMA size, or if no vm_ops are provided. Like, that's the deal πŸ’€


🌈 SEE ALSO 🌈

Kernel file ./drivers/gpu/drm/drm_gem.c β€” and here's the whole friend group, everybody say hi πŸ‘‹


and that's the whole page, bestie πŸ§šπŸ’œ go map something responsibly

k bye, this was brought to you by the Kernel API Manual, living at ./drivers/gpu/drm, dated October 2026 β€” mwah, slay, periodt πŸ’…πŸŽ€πŸ“

πŸ“¦ where this page comes from