__unmap_stage2_range(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… __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_range must be called while holding mmu_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:


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