VirtualBox

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


Ignore:
Timestamp:
Jul 17, 2012 1:27:53 PM (12 years ago)
Author:
vboxsync
Message:

VMM/VMMR0: Store/restore TSC_AUX for AMD-V while not intercepting RDTSCPs and when supported on the host.

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

Legend:

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

    r42174 r42184  
    11781178    unsigned    cResume     = 0;
    11791179    uint8_t     u8LastTPR   = 0; /* Initialized for potentially stupid compilers. */
     1180    uint32_t    u32HostExtFeatures = 0;
    11801181    PHMGLOBLCPUINFO pCpu    = 0;
    11811182    RTCCUINTREG uOldEFlags  = ~(RTCCUINTREG)0;
     
    13961397#ifdef LOG_ENABLED
    13971398    pCpu = HWACCMR0GetCurrentCpu();
    1398     if (    pVCpu->hwaccm.s.idLastCpu   != pCpu->idCpu
    1399         ||  pVCpu->hwaccm.s.cTLBFlushes != pCpu->cTLBFlushes)
    1400     {
    1401         if (pVCpu->hwaccm.s.idLastCpu != pCpu->idCpu)
    1402         {
    1403             LogFlow(("Force TLB flush due to rescheduling to a different cpu (%d vs %d)\n", pVCpu->hwaccm.s.idLastCpu,
    1404                      pCpu->idCpu));
    1405         }
    1406         else
    1407         {
    1408             LogFlow(("Force TLB flush due to changed TLB flush count (%x vs %x)\n", pVCpu->hwaccm.s.cTLBFlushes,
    1409                      pCpu->cTLBFlushes));
    1410         }
    1411     }
     1399    if (pVCpu->hwaccm.s.idLastCpu != pCpu->idCpu)
     1400        LogFlow(("Force TLB flush due to rescheduling to a different cpu (%d vs %d)\n", pVCpu->hwaccm.s.idLastCpu, pCpu->idCpu));
     1401    else if (pVCpu->hwaccm.s.cTLBFlushes != pCpu->cTLBFlushes)
     1402        LogFlow(("Force TLB flush due to changed TLB flush count (%x vs %x)\n", pVCpu->hwaccm.s.cTLBFlushes, pCpu->cTLBFlushes));
    14121403    else if (VMCPU_FF_ISSET(pVCpu, VMCPU_FF_TLB_FLUSH))
    14131404        LogFlow(("Manual TLB flush\n"));
     
    14601451#endif
    14611452    TMNotifyStartOfExecution(pVCpu);
     1453
     1454    /*
     1455     * Save the current Host TSC_AUX and write the guest TSC_AUX to the host, so that
     1456     * RDTSCPs (that don't cause exits) reads the guest MSR. See @bugref{3324}.
     1457     */
     1458    u32HostExtFeatures = ASMCpuId_EDX(0x80000001);  /** @todo Move this elsewhere, not needed on every world switch */
     1459    if (    (u32HostExtFeatures & X86_CPUID_EXT_FEATURE_EDX_RDTSCP)
     1460        && !(pVMCB->ctrl.u32InterceptCtrl2 & SVM_CTRL2_INTERCEPT_RDTSCP))
     1461    {
     1462        pVCpu->hwaccm.s.u64HostTSCAux = ASMRdMsr(MSR_K8_TSC_AUX);
     1463        uint64_t u64GuestTSCAux = 0;
     1464        rc2 = CPUMQueryGuestMsr(pVCpu, MSR_K8_TSC_AUX, &u64GuestTSCAux);
     1465        AssertRC(rc2);
     1466        ASMWrMsr(MSR_K8_TSC_AUX, u64GuestTSCAux);
     1467    }
     1468
    14621469#ifdef VBOX_WITH_KERNEL_USING_XMM
    14631470    hwaccmR0SVMRunWrapXMM(pVCpu->hwaccm.s.svm.pVMCBHostPhys, pVCpu->hwaccm.s.svm.pVMCBPhys, pCtx, pVM, pVCpu,
     
    14711478    if (!(pVMCB->ctrl.u32InterceptCtrl1 & SVM_CTRL1_INTERCEPT_RDTSC))
    14721479    {
     1480        /* Restore host's TSC_AUX. */
     1481        if (u32HostExtFeatures & X86_CPUID_EXT_FEATURE_EDX_RDTSCP)
     1482            ASMWrMsr(MSR_K8_TSC_AUX, pVCpu->hwaccm.s.u64HostTSCAux);
     1483
    14731484        TMCpuTickSetLastSeen(pVCpu, ASMReadTSC() +
    14741485                             pVMCB->ctrl.u64TSCOffset - 0x400 /* guestimate of world switch overhead in clock ticks */);
  • trunk/src/VBox/VMM/VMMR0/HWVMXR0.cpp

    r42173 r42184  
    13721372# endif
    13731373
    1374         if (   (u32HostExtFeatures & X86_CPUID_EXT_FEATURE_EDX_RDTSCP)
    1375             && pVCpu->hwaccm.s.vmx.proc_ctls2 & VMX_VMCS_CTRL_PROC_EXEC2_RDTSCP)
     1374        if (pVCpu->hwaccm.s.vmx.proc_ctls2 & VMX_VMCS_CTRL_PROC_EXEC2_RDTSCP)
    13761375        {
    13771376            pMsr->u32IndexMSR = MSR_K8_TSC_AUX;
     
    31783177        && !(pVCpu->hwaccm.s.vmx.proc_ctls & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDTSC_EXIT))
    31793178    {
    3180         pVCpu->hwaccm.s.vmx.u64HostTSCAux = ASMRdMsr(MSR_K8_TSC_AUX);
     3179        pVCpu->hwaccm.s.u64HostTSCAux = ASMRdMsr(MSR_K8_TSC_AUX);
    31813180        uint64_t u64GuestTSCAux = 0;
    31823181        rc2 = CPUMQueryGuestMsr(pVCpu, MSR_K8_TSC_AUX, &u64GuestTSCAux);
     
    31943193    ASMAtomicIncU32(&pVCpu->hwaccm.s.cWorldSwitchExits);
    31953194
    3196 #ifndef VBOX_WITH_AUTO_MSR_LOAD_RESTORE
    3197     /*
    3198      * Restore host's TSC_AUX.
    3199      */
    3200     if (    (pVCpu->hwaccm.s.vmx.proc_ctls2 & VMX_VMCS_CTRL_PROC_EXEC2_RDTSCP)
    3201         && !(pVCpu->hwaccm.s.vmx.proc_ctls & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDTSC_EXIT))
    3202     {
    3203         ASMWrMsr(MSR_K8_TSC_AUX, pVCpu->hwaccm.s.vmx.u64HostTSCAux);
    3204     }
    3205 #endif
    3206 
    32073195    /* Possibly the last TSC value seen by the guest (too high) (only when we're in TSC offset mode). */
    32083196    if (!(pVCpu->hwaccm.s.vmx.proc_ctls & VMX_VMCS_CTRL_PROC_EXEC_CONTROLS_RDTSC_EXIT))
    32093197    {
     3198#ifndef VBOX_WITH_AUTO_MSR_LOAD_RESTORE
     3199        /* Restore host's TSC_AUX. */
     3200        if (pVCpu->hwaccm.s.vmx.proc_ctls2 & VMX_VMCS_CTRL_PROC_EXEC2_RDTSCP)
     3201            ASMWrMsr(MSR_K8_TSC_AUX, pVCpu->hwaccm.s.u64HostTSCAux);
     3202#endif
     3203
    32103204        TMCpuTickSetLastSeen(pVCpu,
    32113205                             ASMReadTSC() + pVCpu->hwaccm.s.vmx.u64TSCOffset - 0x400 /* guestimate of world switch overhead in clock ticks */);
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