struct svm_softc { int asid; long nptgen[MAXCPU]; }; ASID 0 is reserved for the host. ASID 1 is reserved for overflow allocation. ASIDs [2, max_asid) are free for normal guest allocations. svm_init() { asid_unr = alloc_unr(2, max_asid - 1, NULL); } svm_vminit() { asid = alloc_unr(asid_unr); if (asid == -1) asid = 1; /* overflow asid */ sc->asid = asid; } { disable_gintr(); /* nested pmap is now active on this 'hostcpu' */ pmap->pm_active |= (1 << hostcpu); flush_asid = 0; nptgen = pmap->nptgen; if (vcpustate->lastcpu != hostcpu) flush_asid = 1; if (sc->nptgen[hostcpu] != nptgen) { flush_asid = 1; sc->nptgen[hostcpu] = nptgen; } if (sc->asid == 1) flush_asid = 1; if (flush_asid) ctrl->tlb_ctrl = TLB_FLUSH_GUEST; else ctrl->tlb_ctrl = TLB_FLUSH_NOTHING; svm_launch(); /* nested pmap is no longer active on this 'hostcpu' */ pmap_pm_active &= ~(1 << hostcpu); }