VirtualBox

Changeset 41205 in vbox for trunk/src


Ignore:
Timestamp:
May 8, 2012 1:01:09 PM (13 years ago)
Author:
vboxsync
Message:

VMM/VMMR0/HWVMXR0: VPID optimization+fix: use VPIDs without flushing whenever possible (VPID, VPID+EPT). Fixes incorrect flushing of old VPID (VPID-only).

Location:
trunk/src/VBox/VMM
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR0/HWVMXR0.cpp

    r41193 r41205  
    137137        return VERR_VMX_VMXON_FAILED;
    138138    }
     139
     140    /*
     141     * Flush all VPIDs (in case we or anyother hypervisor have been using VPIDs) so that
     142     * we can avoid an explicit flush while using new VPIDs.
     143     */
     144    if (   pVM
     145        && pVM->hwaccm.s.vmx.fVPID
     146        && (pVM->hwaccm.s.vmx.msr.vmx_eptcaps & MSR_IA32_VMX_EPT_CAPS_INVVPID_CAPS_ALL_CONTEXTS))
     147    {
     148        hmR0VmxFlushVPID(pVM, NULL /* pvCpu */, VMX_FLUSH_VPID_ALL_CONTEXTS, 0 /* GCPtr */);
     149        pCpu->fFlushASIDBeforeUse = false;
     150    }
     151    else
     152        pCpu->fFlushASIDBeforeUse = true;
     153
    139154    return VINF_SUCCESS;
    140155}
     
    22072222                pCpu->uCurrentASID = 1;       /* start at 1; host uses 0 */
    22082223                pCpu->cTLBFlushes++;
     2224                pCpu->fFlushASIDBeforeUse = true;
    22092225            }
    22102226
    22112227            pVCpu->hwaccm.s.uCurrentASID = pCpu->uCurrentASID;
    2212             hmR0VmxFlushVPID(pVM, pVCpu, pVM->hwaccm.s.vmx.enmFlushVPID, 0 /* GCPtr */);
     2228            if (pCpu->fFlushASIDBeforeUse)
     2229                hmR0VmxFlushVPID(pVM, pVCpu, pVM->hwaccm.s.vmx.enmFlushVPID, 0 /* GCPtr */);
    22132230        }
    22142231        else
     2232        {
     2233            /** @todo is it better to flush by EPT or VPID here? find out which is less
     2234             *        expensive. */
    22152235            hmR0VmxFlushEPT(pVM, pVCpu, pVM->hwaccm.s.vmx.enmFlushEPT);
     2236        }
    22162237
    22172238        pVCpu->hwaccm.s.cTLBFlushes    = pCpu->cTLBFlushes;
     
    23632384    if (pVCpu->hwaccm.s.fForceTLBFlush)
    23642385    {
    2365         if (    ++pCpu->uCurrentASID >= pVM->hwaccm.s.uMaxASID
     2386        ++pCpu->uCurrentASID;
     2387        if (    pCpu->uCurrentASID >= pVM->hwaccm.s.uMaxASID
    23662388            ||  pCpu->fFlushTLB)
    23672389        {
     
    23692391            pCpu->uCurrentASID               = 1;       /* start at 1; host uses 0 */
    23702392            pCpu->cTLBFlushes++;
    2371             hmR0VmxFlushVPID(pVM, pVCpu, pVM->hwaccm.s.vmx.enmFlushVPID, 0 /* GCPtr */);
     2393            pCpu->fFlushASIDBeforeUse        = true;
    23722394        }
    23732395        else
     
    23772399        pVCpu->hwaccm.s.cTLBFlushes    = pCpu->cTLBFlushes;
    23782400        pVCpu->hwaccm.s.uCurrentASID   = pCpu->uCurrentASID;
     2401        if (pCpu->fFlushASIDBeforeUse)
     2402            hmR0VmxFlushVPID(pVM, pVCpu, pVM->hwaccm.s.vmx.enmFlushVPID, 0 /* GCPtr */);
    23792403    }
    23802404    else
     
    24102434    int rc  = VMXWriteVMCS(VMX_VMCS16_GUEST_FIELD_VPID, pVCpu->hwaccm.s.uCurrentASID);
    24112435    AssertRC(rc);
    2412 
    2413     if (pVCpu->hwaccm.s.fForceTLBFlush)
    2414         hmR0VmxFlushVPID(pVM, pVCpu, pVM->hwaccm.s.vmx.enmFlushVPID, 0 /* GCPtr */);
    24152436
    24162437# ifdef VBOX_WITH_STATISTICS
  • trunk/src/VBox/VMM/include/HWACCMInternal.h

    r41190 r41205  
    165165    /** TLB flush count. */
    166166    uint32_t            cTLBFlushes;
     167
     168    /** Whether to flush each new ASID/VPID before use. */
     169    bool                fFlushASIDBeforeUse;
    167170
    168171    /** Set the first time a cpu is used to make sure we start with a clean TLB. */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette