VirtualBox

Changeset 22243 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Aug 13, 2009 3:43:06 PM (15 years ago)
Author:
vboxsync
Message:

Apply the same tsc underflow check to AMD-V.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/HWACCMInternal.h

    r22242 r22243  
    557557    RTUINT                      uCurrentASID;
    558558
    559     /* Last use TSC offset value. (cached) */
    560     uint64_t                    u64TSCOffset;
    561 
    562559    struct
    563560    {
     
    619616        uint32_t                    cCachedMSRs;
    620617        uint32_t                    uAlignement;
     618
     619        /* Last use TSC offset value. (cached) */
     620        uint64_t                    u64TSCOffset;
    621621
    622622        /** VMCS cache. */
  • trunk/src/VBox/VMM/VMMR0/HWSVMR0.cpp

    r22018 r22243  
    899899    if (TMCpuTickCanUseRealTSC(pVCpu, &pVMCB->ctrl.u64TSCOffset))
    900900    {
    901         pVMCB->ctrl.u32InterceptCtrl1 &= ~SVM_CTRL1_INTERCEPT_RDTSC;
    902         pVMCB->ctrl.u32InterceptCtrl2 &= ~SVM_CTRL2_INTERCEPT_RDTSCP;
    903         STAM_COUNTER_INC(&pVCpu->hwaccm.s.StatTSCOffset);
     901        uint64_t u64CurTSC = ASMReadTSC();
     902        if (u64CurTSC + pVMCB->ctrl.u64TSCOffset >= TMCpuTickGetLastSeen(pVCpu))
     903        {
     904            pVMCB->ctrl.u32InterceptCtrl1 &= ~SVM_CTRL1_INTERCEPT_RDTSC;
     905            pVMCB->ctrl.u32InterceptCtrl2 &= ~SVM_CTRL2_INTERCEPT_RDTSCP;
     906            STAM_COUNTER_INC(&pVCpu->hwaccm.s.StatTSCOffset);
     907        }
     908        else
     909        {
     910            /* Fall back to rdtsc emulation as we would otherwise pass decreasing tsc values to the guest. */
     911            Log(("TSC %RX64 offset %RX64 time=%RX64 last=%RX64 (diff=%RX64, virt_tsc=%RX64)\n", u64CurTSC, pVMCB->ctrl.u64TSCOffset, u64CurTSC + pVMCB->ctrl.u64TSCOffset, TMCpuTickGetLastSeen(pVCpu), TMCpuTickGetLastSeen(pVCpu) - u64CurTSC - pVMCB->ctrl.u64TSCOffset, TMCpuTickGet(pVCpu)));
     912        }
    904913    }
    905914    else
     
    12501259    pVCpu->hwaccm.s.svm.pfnVMRun(pVCpu->hwaccm.s.svm.pVMCBHostPhys, pVCpu->hwaccm.s.svm.pVMCBPhys, pCtx, pVM, pVCpu);
    12511260#endif
     1261    /* Possibly the last TSC value seen by the guest (too high) (only when we're in tsc offset mode). */
     1262    if (!(pVMCB->ctrl.u32InterceptCtrl1 & SVM_CTRL1_INTERCEPT_RDTSC))
     1263        TMCpuTickSetLastSeen(pVCpu, ASMReadTSC() + pVMCB->ctrl.u64TSCOffset - 0x1000 /* guestimate of world switch overhead in clock ticks */);
    12521264    TMNotifyEndOfExecution(pVCpu);
    12531265    VMCPU_SET_STATE(pVCpu, VMCPUSTATE_STARTED);
  • trunk/src/VBox/VMM/VMMR0/HWVMXR0.cpp

    r22242 r22243  
    18031803    AssertRC(rc);
    18041804
    1805     if (TMCpuTickCanUseRealTSC(pVCpu, &pVCpu->hwaccm.s.u64TSCOffset))
     1805    if (TMCpuTickCanUseRealTSC(pVCpu, &pVCpu->hwaccm.s.vmx.u64TSCOffset))
    18061806    {
    18071807        uint64_t u64CurTSC = ASMReadTSC();
    1808         if (u64CurTSC + pVCpu->hwaccm.s.u64TSCOffset >= TMCpuTickGetLastSeen(pVCpu))
     1808        if (u64CurTSC + pVCpu->hwaccm.s.vmx.u64TSCOffset >= TMCpuTickGetLastSeen(pVCpu))
    18091809        {
    18101810            /* Note: VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDTSC_EXIT takes precedence over TSC_OFFSET */
    1811             rc = VMXWriteVMCS64(VMX_VMCS_CTRL_TSC_OFFSET_FULL, pVCpu->hwaccm.s.u64TSCOffset);
     1811            rc = VMXWriteVMCS64(VMX_VMCS_CTRL_TSC_OFFSET_FULL, pVCpu->hwaccm.s.vmx.u64TSCOffset);
    18121812            AssertRC(rc);
    18131813
     
    18201820        {
    18211821            /* Fall back to rdtsc emulation as we would otherwise pass decreasing tsc values to the guest. */
    1822             Log(("TSC %RX64 offset %RX64 time=%RX64 last=%RX64 (diff=%RX64, virt_tsc=%RX64)\n", u64CurTSC, pVCpu->hwaccm.s.u64TSCOffset, u64CurTSC + pVCpu->hwaccm.s.u64TSCOffset, TMCpuTickGetLastSeen(pVCpu), TMCpuTickGetLastSeen(pVCpu) - u64CurTSC - pVCpu->hwaccm.s.u64TSCOffset, TMCpuTickGet(pVCpu)));
     1822            Log(("TSC %RX64 offset %RX64 time=%RX64 last=%RX64 (diff=%RX64, virt_tsc=%RX64)\n", u64CurTSC, pVCpu->hwaccm.s.vmx.u64TSCOffset, u64CurTSC + pVCpu->hwaccm.s.vmx.u64TSCOffset, TMCpuTickGetLastSeen(pVCpu), TMCpuTickGetLastSeen(pVCpu) - u64CurTSC - pVCpu->hwaccm.s.vmx.u64TSCOffset, TMCpuTickGet(pVCpu)));
    18231823            pVCpu->hwaccm.s.vmx.proc_ctls |= VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDTSC_EXIT;
    18241824            rc = VMXWriteVMCS(VMX_VMCS_CTRL_PROC_EXEC_CONTROLS, pVCpu->hwaccm.s.vmx.proc_ctls);
     
    25922592    /* Possibly the last TSC value seen by the guest (too high) (only when we're in tsc offset mode). */
    25932593    if (!(pVCpu->hwaccm.s.vmx.proc_ctls & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDTSC_EXIT))
    2594         TMCpuTickSetLastSeen(pVCpu, ASMReadTSC() + pVCpu->hwaccm.s.u64TSCOffset - 0x1000 /* guestimate of world switch overhead in clock ticks */);
     2594        TMCpuTickSetLastSeen(pVCpu, ASMReadTSC() + pVCpu->hwaccm.s.vmx.u64TSCOffset - 0x1000 /* guestimate of world switch overhead in clock ticks */);
    25952595
    25962596    TMNotifyEndOfExecution(pVCpu);
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