VirtualBox

Changeset 53196 in vbox for trunk/src/VBox/VMM/VMMR0


Ignore:
Timestamp:
Nov 4, 2014 12:52:21 PM (10 years ago)
Author:
vboxsync
Message:

VMM/HMVMXR0: Fix incorrect sign and calculation on guest TSC offset in VMCS.

File:
1 edited

Legend:

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

    r53193 r53196  
    56205620        fOffsettedTsc = TMCpuTickCanUseRealTSC(pVCpu, &pVCpu->hm.s.vmx.u64TSCOffset, &fParavirtTsc);
    56215621
    5622 #if 1
    56235622    if (fParavirtTsc)
    56245623    {
    5625 #if 1
     5624        /** @todo this is a hack until TM switches to pure-offsetting mode. */
    56265625        uint64_t const u64CurTsc   = ASMReadTSC();
    56275626        uint64_t const u64LastTick = TMCpuTickGetLastSeen(pVCpu);
    5628         if (u64CurTsc + pVCpu->hm.s.vmx.u64TSCOffset < u64LastTick)
    5629         {
    5630             pVCpu->hm.s.vmx.u64TSCOffset = (u64LastTick - u64CurTsc);
     5627        if (u64CurTsc - pVCpu->hm.s.vmx.u64TSCOffset < u64LastTick)
     5628        {
     5629            pVCpu->hm.s.vmx.u64TSCOffset = u64CurTsc - u64LastTick;
    56315630            STAM_COUNTER_INC(&pVCpu->hm.s.StatTscOffsetAdjusted);
    56325631        }
    56335632
    5634         Assert(u64CurTsc + pVCpu->hm.s.vmx.u64TSCOffset >= u64LastTick);
    5635 #endif
     5633        Assert(u64CurTsc - pVCpu->hm.s.vmx.u64TSCOffset >= u64LastTick);
    56365634        rc = GIMR0UpdateParavirtTsc(pVM, pVCpu->hm.s.vmx.u64TSCOffset);
    56375635        AssertRC(rc);
     
    56435641        STAM_COUNTER_INC(&pVCpu->hm.s.StatTscParavirt);
    56445642    }
    5645     else
    5646 #else
    5647     if (fParavirtTsc)
    5648         STAM_COUNTER_INC(&pVCpu->hm.s.StatTscParavirt);
    5649 #endif
    5650     if (fOffsettedTsc)
     5643    else if (fOffsettedTsc)
    56515644    {
    56525645        uint64_t u64CurTSC = ASMReadTSC();
    5653         if (u64CurTSC + pVCpu->hm.s.vmx.u64TSCOffset >= TMCpuTickGetLastSeen(pVCpu))
     5646        if (u64CurTSC - pVCpu->hm.s.vmx.u64TSCOffset >= TMCpuTickGetLastSeen(pVCpu))
    56545647        {
    56555648            /* Note: VMX_VMCS_CTRL_PROC_EXEC_RDTSC_EXIT takes precedence over TSC_OFFSET, applies to RDTSCP too. */
    5656             rc = VMXWriteVmcs64(VMX_VMCS64_CTRL_TSC_OFFSET_FULL, pVCpu->hm.s.vmx.u64TSCOffset);   AssertRC(rc);
     5649            rc = VMXWriteVmcs64(VMX_VMCS64_CTRL_TSC_OFFSET_FULL, -pVCpu->hm.s.vmx.u64TSCOffset);  AssertRC(rc);
    56575650
    56585651            pVCpu->hm.s.vmx.u32ProcCtls &= ~VMX_VMCS_CTRL_PROC_EXEC_RDTSC_EXIT;
     
    87318724    {
    87328725        /** @todo Find a way to fix hardcoding a guestimate.  */
    8733         TMCpuTickSetLastSeen(pVCpu, ASMReadTSC()
    8734                              + pVCpu->hm.s.vmx.u64TSCOffset - 0x400   /* guestimate of world switch overhead in clock ticks */);
     8726        TMCpuTickSetLastSeen(pVCpu, ASMReadTSC() - pVCpu->hm.s.vmx.u64TSCOffset
     8727                             - 0x400  /* guestimate of world switch overhead in clock ticks */);
    87358728    }
    87368729
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