wrprotect_ptes(9)
π 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:
lazy_mmu_mode_enable(9)lazy_mmu_mode_disable(9)__task_lazy_mmu_mode_pause(9)lazy_mmu_mode_pause(9)__task_lazy_mmu_mode_resume(9)lazy_mmu_mode_resume(9)pte_batch_hint(9)set_ptes(9)clear_young_dirty_ptes(9)get_and_clear_full_ptes(9)get_and_clear_ptes(9)clear_full_ptes(9)clear_ptes(9)clear_nonpresent_ptes(9)ptep_try_set(9)flush_tlb_before_set(9)clear_flush_young_ptes(9)test_and_clear_young_ptes(9)modify_prot_start_ptes(9)modify_prot_commit_ptes(9)pfnmap_setup_cachemode(9)pfnmap_track(9)pfnmap_untrack(9)pfnmap_setup_cachemode_pfn(9)
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
- 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