__unmap_stage2_range(9)
π __unmap_stage2_range π
okay so bestie, welcome to the Kernel API Manual, section 9 β yes, the big-girl kernel-internals section, we love her π today's main character is __unmap_stage2_range, and she is literally the one who clears stage-2 page table entries to unmap a range. no cap. π₯
β¨ SYNOPSIS β¨
void __unmap_stage2_range (struct kvm_s2_mmu *mmu , phys_addr_t start ,
u64 size , bool may_block );
that's the whole signature, copy it exactly, don't be cute with it π«Ά
πΈ ARGUMENTS πΈ
mmuβ the KVM stage-2 MMU pointer. like, which MMU are we doing this to. the icon herself. πstartβ the intermediate physical base address of the range to unmap. where the range kicks off, address-wise.sizeβ the size of the area to unmap. how much we're clearing, in case that wasn't obvious bestie πmay_blockβ whether or not we are permitted to block. that's it, that's the whole vibe check: can we block, yes or no. π
π¦ DESCRIPTION π¦
so what she actually does: she clears a range of stage-2 mappings, and while she's at it she lowers the various ref-counts. lowkey efficient, highkey important. β¨
β οΈ okay this part is not a joke:__unmap_stage2_rangemust be called while holdingmmu_lockβ the only exception being when you're freeing the stage2 pgd before destroying the VM. otherwise another faulting VCPU may come in and mess with things behind our backs. and likeβ¦ not in a cute way. in a race-condition way. π
fr fr, hold the lock. unless you're in that one specific teardown case. that's the whole rule. periodt. π
π SEE ALSO π
kernel file ./arch/arm64/kvm/mmu.c, plus the whole friend group β go say hi:
kvm_arch_flush_remote_tlbs(9)stage2_flush_vm(9)free_hyp_pgds(9)create_hyp_mappings(9)hyp_alloc_private_va_range(9)create_hyp_io_mappings(9)create_hyp_exec_mappings(9)kvm_init_stage2_mmu(9)stage2_unmap_vm(9)kvm_phys_addr_ioremap(9)kvm_stage2_wp_range(9)kvm_mmu_wp_memory_region(9)kvm_mmu_split_memory_region(9)kvm_handle_guest_abort(9)
and that's the page, bestie π§π huge slay, go hold that mmu_lock.
sign-off: brought to you courtesy of./arch/arm64/kvm, dated October 2026, and filed under__unmap_stage2_range(9)β 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