mapping_wrprotect_range(9)
๐ mapping_wrprotect_range(9) โจ
okay so this is a page from the Kernel API Manual, and bestie, we are about to become intimately familiar with mapping_wrprotect_range. it's giving "niche kernel internals" and honestly? we're obsessed. ๐ซถ
๐ธ NAME ๐ธ
mapping_wrprotect_range โ write-protect all mappings in a specified range. that's it, that's the whole vibe. ๐
โจ SYNOPSIS โจ
int mapping_wrprotect_range (struct address_space *mapping , pgoff_t
pgoff , unsigned long pfn , unsigned long nr_pages );
like, copy that exactly, no cap. every asterisk and comma matters, this is C, we don't freestyle. ๐ญ
๐ ARGUMENTS ๐
so here's the cast of characters, and yes they all have main character energy:
mappingโ thestruct address_spacewhose reverse mapping should be traversed. this is the map we're walking, iykyk. ๐บ๏ธpgoffโ the page offset at whichpfnis mapped withinmapping. basically "where in the mapping does this page live". ๐pfnโ the PFN of the page mapped inmappingatpgoff. PFN = page frame number, the physical-address bestie. ๐ฅnr_pagesโ the number of physically contiguous base pages spanned. so like, how many pages we're doing here. count 'em. ๐งฎ
๐ฆ DESCRIPTION ๐ฆ
okay so what does this actually do, you ask? it traverses the reverse mapping, finding all VMAs which contain a shared mapping of the pages in the specified range in mapping, and write-protects them. and "write-protects" here literally means it updates the page tables to mark the mappings read-only โ such that a write protection fault arises when the mappings are written to. so like, the moment someone tries to write, boom, fault. that's the whole point. ๐
and now the important bit, pay attention bestie: the pfn value need not refer to a folio, but rather can reference a kernel allocation which is mapped into userland. so we therefore do not require that the page maps to a folio with a valid mapping or index field โ instead, the caller specifies these in mapping and pgoff. the caller does the work. respect. ๐
ngl this is the part people get wrong โ the folio assumption is not safe here, the caller has to hand youmappingandpgoffthemselves. no guessing, no vibes-based lookups. ๐
โญ RETURN โญ
the number of write-protected PTEs, or an error. short and sweet, love that for us. ๐
๐ SEE ALSO ๐
the whole friend group, in Kernel file ./mm/rmap.c:
__anon_vma_prepare(9), anon_vma_clone(9), unlink_anon_vmas(9), page_address_in_vma(9), folio_referenced(9), pfn_mkclean_range(9), folio_move_anon_rmap(9), __folio_set_anon(9), __page_check_anon_rmap(9), folio_add_anon_rmap_ptes(9), folio_add_anon_rmap_pmd(9), folio_add_new_anon_rmap(9), folio_add_file_rmap_ptes(9), folio_add_file_rmap_pmd(9), folio_add_file_rmap_pud(9), folio_remove_rmap_ptes(9), folio_remove_rmap_pmd(9), folio_remove_rmap_pud(9), try_to_unmap(9), try_to_migrate(9), make_device_exclusive(9), __rmap_walk_file(9).
like, that's the entire rmap.c cinematic universe and we stan. ๐
and that's the page, bestie!! sourced from ./mm, dated October 2026, and it's mapping_wrprotect_range(9) all the way down. go forth and write-protect responsibly ๐โจ
๐ฆ 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