compat_vma_mmap(9)
π compat_vma_mmap(9) β Kernel API Manual β¨
Okay so bestie, buckle up, because we're talking about compat_vma_mmap, a little compatibility shim living its best life in the kernel API manual. No cap, it's doing important bridge work while everybody else migrates. π«Ά
πΈ NAME πΈ
compat_vma_mmap β apply the file's .mmap_prepare() hook to an existing VMA and execute any requested actions. That's it, that's the whole vibe. π
β¨ SYNOPSIS β¨
int compat_vma_mmap (struct file *file , struct vm_area_struct *vma );
π¦ ARGUMENTS π¦
fileβ the file which possesss anf_op->mmap_preparehook. (And yes, "possesss" has three s's β that's literally how it's written in the source, I'm not fixing it, it's iconic now. π)vmaβ the VMA you're applying the.mmap_preparehook to. That's the main character right there. π
π DESCRIPTION π
So normally? .mmap_prepare gets invoked directly upon mmap. Simple. Clean. Beautiful. π
But. Certain stacked drivers invoke a nested mmap hook of an underlying file. And that's where things get spicy. π₯
Until all drivers are converted to use .mmap_prepare, we have to be conservative β we literally must keep invoking these stacked drivers using the deprecated .mmap hook. Lowkey tragic, but that's the situation.
However β and this is the plot twist β we have a problem if the underlying file system possesses an .mmap_prepare hook, because we're in a different context when we invoke the .mmap hook, already having a VMA to deal with. π Different context, different rules, same VMA.
So compat_vma_mmap is the compatibility function that fixes all of this. What it does:
- Takes VMA state π«Ά
- Establishes a
struct vm_area_descdescriptor π - Passes it to the underlying
.mmap_preparehook π― - Applies any changes performed by it β
Heads up bestie: once the conversion of drivers is complete, this function will no longer be required and will be removed. So don't get too attached. π It's giving limited-edition.
β RETURN β
0 on success, or error. That's the whole story. Slay. π
π SEE ALSO π
Kernel file ./mm/util.c, plus the whole friend group:
kfree_const(9)__kmemdup_nul(9)kstrdup(9)kstrdup_const(9)kstrndup(9)kmemdup(9)kmemdup_array(9)kvmemdup(9)kmemdup_nul(9)memdup_user(9)vmemdup_user(9)strndup_user(9)memdup_user_nul(9)randomize_page(9)__account_locked_vm(9)account_locked_vm(9)__vmalloc_array(9)vmalloc_array(9)__vcalloc(9)vcalloc(9)folio_mapping(9)folio_copy(9)get_cmdline(9)mem_dump_obj(9)compat_set_desc_from_vma(9)__compat_vma_mmap(9)snapshot_page(9)mmap_action_prepare(9)mmap_action_complete(9)folio_pte_batch(9)page_range_contiguous(9)
And that's the page!! π Big kiss from the ./mm directory, dated October 2026 β go forth and call compat_vma_mmap, bestie, while it still exists. π§ππΈ
π¦ 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