remap_pfn_range(9)
π remap_pfn_range β like, the kernel-memory-to-userspace glow-up
Okay bestie, welcome to the Kernel API Manual β¨ β this one's called remap_pfn_range(9) and it's literally the function that hands kernel memory over to userspace. Main character energy fr fr π«Ά
πΈ NAME
remap_pfn_range β remap kernel memory to userspace π«
β¨ SYNOPSIS
int remap_pfn_range (struct vm_area_struct *vma , unsigned long addr ,
unsigned long pfn , unsigned long size , pgprot_t prot );
That's the whole vibe check right there π five args, no notes.
π ARGUMENTS
vmaβ the uservmayou're mapping into, i.e. the userspace side of the situationship π¦addrβ the target, page-aligned user address where the mapping starts. Page-aligned, bestie, don't play with me πpfnβ page frame number of the kernel physical memory address πsizeβ how big the mapping area is πprotβ page protection flags for this mapping, aka the outfit it wears π
π NOTE
This is only safe if the mm semaphore is held when it's called. Not "probably fine", not "we'll see" β held. Do not come for me if you skip this, I warned you π
β RETURN
0on success π- a negative error code otherwise π
π₯ SEE ALSO
Kernel file ./mm/memory.c β and honestly the whole extended friend group:
free_pgd_range(9)free_pgtables(9)__vm_normal_page(9)vm_normal_page(9)vm_normal_folio(9)vm_normal_page_pmd(9)vm_normal_folio_pmd(9)vm_normal_page_pud(9)restore_exclusive_pte(9)cond_install_uffd_wp_ptes(9)zap_vma_for_reaping(9)unmap_vmas(9)zap_vma_range_batched(9)zap_vma_range(9)zap_special_vma_range(9)vm_insert_pages(9)vm_insert_page(9)vm_map_pages(9)vm_map_pages_zero(9)vmf_insert_pfn_prot(9)vmf_insert_pfn(9)vm_iomap_memory(9)__vmf_anon_prepare(9)finish_mkwrite_fault(9)unmap_mapping_folio(9)unmap_mapping_pages(9)unmap_mapping_range(9)set_pte_range(9)finish_fault(9)mm_account_fault(9)follow_pfnmap_start(9)follow_pfnmap_end(9)generic_access_phys(9)access_remote_vm(9)copy_remote_vm_str(9)folio_zero_user(9)
okayyy that's the whole page, you ate that π This one ships out of ./mm and is dated October 2026 β so go forth, remap responsibly, and keep that mm semaphore held, iykyk π§π
π¦ 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