wrprotect_ptes(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… wrprotect_ptes β€” the kernel API manual, but make it make sense

okay bestie, so this is wrprotect_ptes(9) from the Kernel API Manual, and no cap, it's lowkey one of the more chill functions you'll meet. it write-protects PTEs that map consecutive pages of the same folio. tiny job, does it well. let's get into it πŸŽ€


✨ SYNOPSIS ✨

void wrprotect_ptes (struct mm_struct *mm , unsigned long addr , pte_t
*ptep , unsigned int nr );

that's it. that's the whole vibe. four args, no return value, she just does the thing and leaves. main character energy fr πŸ’…


🌸 ARGUMENTS 🌸

here's who's who at the function party:

  • mm β€” the address space where the pages are mapped. like, which world are we living in.
  • addr β€” the address where the first page lives. the starting point, the origin story ⭐
  • ptep β€” the page table pointer for the first entry. your little handle onto the action.
  • nr β€” how many entries you want write-protected. the count. the guest list, if you will 🫢

πŸ’– DESCRIPTION πŸ’–

so the way this works: this function may be overridden by the architecture. so like, your arch could swoop in and do its own special thing (iykyk). otherwise? it's literally just implemented as a simple loop over ptep_set_wrprotect. simple. iconic. efficient. 🧚

and hmm, one thing to clock: the PTE bits in the PTE range besides the PFN can differ. for example β€” plot twist β€” some PTEs might already be write-protected. so don't assume they're all identical, bestie. πŸ™ˆ


πŸ”₯ CONTEXT πŸ”₯

okay so the ground rules for calling this thing:

  • the caller holds the page table lock β€” non-negotiable, periodt πŸ”’
  • the PTEs map consecutive pages that all belong to the same folio
  • the PTEs are all in the same PMD
break any of these and you're not just wrong, you're messy about being wrong. and we don't do messy. πŸ’€

πŸ‘‘ SEE ALSO πŸ‘‘

the whole friend group, gathered in the kernel file ./include/linux/pgtable.h:

like, the entire squad. go read them too, they're all serving πŸ’œ


anyway bestie, that's the page ✨ huge shoutout to ./include/linux for holding it down, and this edition is stamped October 2026 β€” so like, future-proofed AND cute. go forth and write-protect responsibly, mwah πŸ’‹πŸ¦‹

πŸ“¦ where this page comes from