drm_gem_prim...le_to_dmabuf(9)
π drm_gem_prim...le_to_dmabuf(9) β the Kernel API Manual, bestie edition β¨
okay so this is a page from the Kernel API Manual, and honestly it's giving "niche but iconic." Buckle up π
πΈ NAME πΈ
drm_gem_prime_handle_to_dmabuf β the PRIME export function for GEM drivers. yes, that's its whole job and it does it slayfully π
β¨ SYNOPSIS β¨
struct dma_buf * drm_gem_prime_handle_to_dmabuf (struct drm_device *dev
, struct drm_file *file_priv , uint32_t handle , uint32_t flags );
like, look at that signature. main character energy fr fr π
π«Ά ARGUMENTS π«Ά
devβ thedevyou're exporting the buffer from. the origin story, if you will π«file_privβ the drm file-private structure. it's giving "private but make it structural" πhandleβ the buffer handle you wanna export. this is the thing itself πΈflagsβ flags likeDRM_CLOEXEC. yes, like the one you know and love π
π¦ DESCRIPTION π¦
so this is the PRIME export function, and here's the tea: GEM drivers must use it β like, mandatorily, no cap β to make sure the underlying GEM object's lifetime gets managed correctly. it's not optional, it's a vibe check you have to pass π€
the actual exporting from the GEM object to a dma-buf? that's handled through the drm_gem_object_funcs.export callback. so this function is more like the manager, and the callback does the actual work π§
now, unlike drm_gem_prime_handle_to_fd, this one returns the struct dma_buf it created β without attaching it to any file descriptors. literally just hands you the object, no strings attached π
the difference between the two is similar to the difference between anon_inode_getfile and anon_inode_getfd. and the reason matters, bestie: insertion into the descriptor table is something you cannot revert if any cleanup is needed. so the descriptor-returning variants should only be used when you're past the last failure exit and the only thing left to do is pass the new file descriptor to userland. that's it, that's the finish line π
so when all you need is the object itself, or when you need to do something else that might fail β use that one instead. lowkey the safer choice, highkey the smarter one π
π₯ SEE ALSO π₯
the whole friend group, in order π:
- Kernel file
./drivers/gpu/drm/drm_prime.coverview and lifetime rules(9) drm_gem_dmabuf_export(9)drm_gem_dmabuf_release(9)drm_gem_prime_fd_to_handle(9)drm_gem_prime_handle_to_fd(9)- PRIME Helpers(9)
drm_gem_map_attach(9)drm_gem_map_detach(9)drm_gem_map_dma_buf(9)drm_gem_unmap_dma_buf(9)drm_gem_dmabuf_vmap(9)drm_gem_dmabuf_vunmap(9)drm_gem_prime_mmap(9)drm_gem_dmabuf_mmap(9)drm_prime_pages_to_sg(9)drm_prime_get_contiguous_size(9)drm_gem_prime_export(9)drm_gem_is_prime_exported_dma_buf(9)drm_gem_prime_import_dev(9)drm_gem_prime_import(9)drm_prime_sg_to_page_array(9)drm_prime_sg_to_dma_addr_array(9)drm_prime_gem_destroy(9)
and that's the whole page, bestie π«Ά this one lives under ./drivers/gpu/drm and it's dated October 2026 β so go forth, export those buffers responsibly, and remember: no reverting descriptor table insertions πβ¨ mwah π
π¦ 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