VirtualBox

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


Ignore:
Timestamp:
Feb 19, 2014 3:13:19 PM (11 years ago)
Author:
vboxsync
Message:

VMM/HMVMXR0: Fix for workaround done in r92215.

File:
1 edited

Legend:

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

    r50426 r50506  
    12361236 * auto-load/store MSR area in the VMCS.
    12371237 *
    1238  * @returns VBox status code.
     1238 * @returns true if the MSR was added -and- its value was updated, false
     1239 *          otherwise.
    12391240 * @param   pVCpu           Pointer to the VMCPU.
    12401241 * @param   uMsr            The MSR.
     
    12431244 *                          necessary.
    12441245 */
    1245 static int hmR0VmxAddAutoLoadStoreMsr(PVMCPU pVCpu, uint32_t uMsr, uint64_t uGuestMsrValue, bool fUpdateHostMsr)
     1246static bool hmR0VmxAddAutoLoadStoreMsr(PVMCPU pVCpu, uint32_t uMsr, uint64_t uGuestMsrValue, bool fUpdateHostMsr)
    12461247{
    12471248    PVMXAUTOMSR pGuestMsr = (PVMXAUTOMSR)pVCpu->hm.s.vmx.pvGuestMsr;
     
    12831284     * updated by hmR0VmxSaveHostMsrs(). We do this for performance reasons.
    12841285     */
     1286    bool fUpdatedMsrValue = false;
    12851287    if (   fAdded
    12861288        && fUpdateHostMsr)
     
    12891291        Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
    12901292        pHostMsr->u64Value = ASMRdMsr(pHostMsr->u32Msr);
    1291     }
    1292 
    1293     return VINF_SUCCESS;
     1293        fUpdatedMsrValue = true;
     1294    }
     1295
     1296    return fUpdatedMsrValue;
    12941297}
    12951298
     
    27752778    int rc = VERR_INTERNAL_ERROR_5;
    27762779
     2780#if HC_ARCH_BITS == 64
    27772781    /*
    2778      * Quick fix for regression #7240.  Restore the host state if we've messed
    2779      * it up already, otherwise all we'll get it all wrong below!
     2782     * If we've executed guest code using VT-x, the host-state bits will be messed up. We
     2783     * should -not- save the messed up state without restoring the original host-state. See @bugref{7240}.
    27802784     */
    2781     if (   (pVCpu->hm.s.vmx.fRestoreHostFlags & VMX_RESTORE_HOST_REQUIRED)
    2782         && (pVCpu->hm.s.vmx.fRestoreHostFlags & ~VMX_RESTORE_HOST_REQUIRED))
    2783         VMXRestoreHostState(pVCpu->hm.s.vmx.fRestoreHostFlags, &pVCpu->hm.s.vmx.RestoreHost);
     2785    AssertMsgReturn(!(pVCpu->hm.s.vmx.fRestoreHostFlags & VMX_RESTORE_HOST_REQUIRED),
     2786                    ("Re-saving host-state after executing guest code without leaving VT-x!\n"), VERR_WRONG_ORDER);
     2787#endif
    27842788
    27852789    /*
     
    30253029        hmR0VmxLazySaveHostMsrs(pVCpu);
    30263030#endif
    3027 
    3028     if (pVCpu->hm.s.vmx.cMsrs > 0)
    3029         hmR0VmxUpdateAutoLoadStoreHostMsrs(pVCpu);
    30303031
    30313032    /*
     
    45634564        {
    45644565            pVCpu->hm.s.vmx.pfnStartVM = VMXR0SwitcherStartVM64;
    4565             HMCPU_CF_SET(pVCpu, HM_CHANGED_HOST_CONTEXT | HM_CHANGED_VMX_EXIT_CTLS | HM_CHANGED_VMX_ENTRY_CTLS);
     4566            /* Currently, all mode changes sends us back to ring-3, so these should be set. See @bugref{6944}. */
     4567            Assert(HMCPU_CF_IS_SET(pVCpu, HM_CHANGED_HOST_CONTEXT | HM_CHANGED_VMX_EXIT_CTLS | HM_CHANGED_VMX_ENTRY_CTLS));
    45664568        }
    45674569#else
     
    45774579        {
    45784580            pVCpu->hm.s.vmx.pfnStartVM = VMXR0StartVM32;
    4579             HMCPU_CF_SET(pVCpu, HM_CHANGED_HOST_CONTEXT | HM_CHANGED_VMX_EXIT_CTLS | HM_CHANGED_VMX_ENTRY_CTLS);
     4581            /* Currently, all mode changes sends us back to ring-3, so these should be set. See @bugref{6944}. */
     4582            Assert(HMCPU_CF_IS_SET(pVCpu, HM_CHANGED_HOST_CONTEXT | HM_CHANGED_VMX_EXIT_CTLS | HM_CHANGED_VMX_ENTRY_CTLS));
    45804583        }
    45814584#else
     
    66746677#endif
    66756678
     6679    /* Update auto-load/store host MSRs values when we re-enter VT-x (as we could be on a different CPU). */
     6680    pVCpu->hm.s.vmx.fUpdatedHostMsrs = false;
     6681
    66766682    STAM_PROFILE_ADV_SET_STOPPED(&pVCpu->hm.s.StatEntry);
    66776683    STAM_PROFILE_ADV_SET_STOPPED(&pVCpu->hm.s.StatLoadGuestState);
     
    68946900        }
    68956901#endif
     6902        pVCpu->hm.s.vmx.fUpdatedHostMsrs = false;
    68966903        VMCPU_CMPXCHG_STATE(pVCpu, VMCPUSTATE_STARTED_HM, VMCPUSTATE_STARTED_EXEC);
    68976904        if (pVCpu->hm.s.vmx.uVmcsState & HMVMX_VMCS_STATE_ACTIVE)
     
    70777084    if (pVCpu->hm.s.Event.fPending)
    70787085    {
     7086#if defined(DEBUG) || defined(VBOX_STRICT) || defined(VBOX_WITH_STATISTICS)
     7087        uint32_t uIntType = VMX_EXIT_INTERRUPTION_INFO_TYPE(pVCpu->hm.s.Event.u64IntInfo);
     7088#endif
    70797089#if defined(VBOX_STRICT) || defined(VBOX_WITH_STATISTICS)
    7080         uint32_t uIntType = VMX_EXIT_INTERRUPTION_INFO_TYPE(pVCpu->hm.s.Event.u64IntInfo);
    70817090        if (uIntType == VMX_EXIT_INTERRUPTION_INFO_TYPE_EXT_INT)
    70827091        {
     
    70947103        }
    70957104#endif
    7096         Log4(("Injecting pending event vcpu[%RU32] u64IntInfo=%#RX64\n", pVCpu->idCpu, pVCpu->hm.s.Event.u64IntInfo));
     7105        Log4(("Injecting pending event vcpu[%RU32] u64IntInfo=%#RX64 Type=%#x\n", pVCpu->idCpu, pVCpu->hm.s.Event.u64IntInfo,
     7106              (uint8_t)uIntType));
    70977107        rc = hmR0VmxInjectEventVmcs(pVCpu, pMixedCtx, pVCpu->hm.s.Event.u64IntInfo, pVCpu->hm.s.Event.cbInstr,
    70987108                                    pVCpu->hm.s.Event.u32ErrCode, pVCpu->hm.s.Event.GCPtrFaultAddress, &uIntrState);
     
    81028112
    81038113    /*
    8104      * The host MSR values the very first time around won't be updated, so we need to
    8105      * fill those values in. Subsequently, it's updated as part of the host state.
     8114     * Lazy-update of the host MSRs values in the auto-load/store MSR area.
    81068115     */
    81078116    if (   !pVCpu->hm.s.vmx.fUpdatedHostMsrs
    81088117        && pVCpu->hm.s.vmx.cMsrs > 0)
    81098118    {
    8110         HMCPU_CF_SET(pVCpu, HM_CHANGED_HOST_CONTEXT);
     8119        hmR0VmxUpdateAutoLoadStoreHostMsrs(pVCpu);
    81118120    }
    81128121
     
    81818190            AssertRC(rc2);
    81828191            Assert(HMVMXCPU_GST_IS_UPDATED(pVCpu, HMVMX_UPDATED_GUEST_AUTO_LOAD_STORE_MSRS));
    8183             hmR0VmxAddAutoLoadStoreMsr(pVCpu, MSR_K8_TSC_AUX, CPUMR0GetGuestTscAux(pVCpu), true /* fUpdateHostMsr */);
     8192            bool fMsrUpdated = hmR0VmxAddAutoLoadStoreMsr(pVCpu, MSR_K8_TSC_AUX, CPUMR0GetGuestTscAux(pVCpu),
     8193                                                          true /* fUpdateHostMsr */);
     8194            Assert(fMsrUpdated || pVCpu->hm.s.vmx.fUpdatedHostMsrs);
     8195            /* Finally, mark that all host MSR values are updated so we don't redo it without leaving VT-x. See @bugref{6956}. */
     8196            pVCpu->hm.s.vmx.fUpdatedHostMsrs = true;
    81848197        }
    81858198        else
     8199        {
    81868200            hmR0VmxRemoveAutoLoadStoreMsr(pVCpu, MSR_K8_TSC_AUX);
     8201            Assert(!pVCpu->hm.s.vmx.cMsrs || pVCpu->hm.s.vmx.fUpdatedHostMsrs);
     8202        }
    81878203    }
    81888204#ifdef VBOX_STRICT
     
    82428258#endif
    82438259
     8260#if HC_ARCH_BITS == 64
    82448261    pVCpu->hm.s.vmx.fRestoreHostFlags |= VMX_RESTORE_HOST_REQUIRED;   /* Host state messed up by VT-x, we must restore. */
     8262#endif
    82458263    pVCpu->hm.s.vmx.uVmcsState |= HMVMX_VMCS_STATE_LAUNCHED;          /* Use VMRESUME instead of VMLAUNCH in the next run. */
    82468264    ASMSetFlags(pVmxTransient->uEflags);                              /* Enable interrupts. */
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