compat_vma_mmap(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 an f_op->mmap_prepare hook. (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_prepare hook 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:

  1. Takes VMA state 🫢
  2. Establishes a struct vm_area_desc descriptor πŸ“
  3. Passes it to the underlying .mmap_prepare hook 🎯
  4. 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:


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