VirtualBox

Ignore:
Timestamp:
Dec 4, 2015 9:46:44 PM (9 years ago)
Author:
vboxsync
Message:

HM: Fixes for the VT-x trace points and debug events.

File:
1 edited

Legend:

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

    r58999 r59003  
    55075507    }
    55085508
    5509     if (fOffsettedTsc)
     5509    if (fOffsettedTsc && RT_LIKELY(!pVCpu->hm.s.fDebugWantRdTscExit))
    55105510    {
    55115511        /* Note: VMX_VMCS_CTRL_PROC_EXEC_RDTSC_EXIT takes precedence over TSC_OFFSET, applies to RDTSCP too. */
     
    88778877    uint32_t    uDtraceSettingsSeqNo;
    88788878    /** Exits to check (one bit per exit). */
    8879     uint32_t    bmExitsToCheck[2];
     8879    uint32_t    bmExitsToCheck[3];
    88808880
    88818881    /** The initial VMX_VMCS32_CTRL_PROC_EXEC value (helps with restore). */
     
    88878887
    88888888} VMXRUNDBGSTATE;
    8889 AssertCompileMemberSize(VMXRUNDBGSTATE, bmExitsToCheck, (VMX_EXIT_MAX + 31) / 32 * 4);
     8889AssertCompileMemberSize(VMXRUNDBGSTATE, bmExitsToCheck, (VMX_EXIT_MAX + 1 + 31) / 32 * 4);
    88908890typedef VMXRUNDBGSTATE *PVMXRUNDBGSTATE;
    88918891
     
    89458945        pVCpu->hm.s.vmx.u32ProcCtls   &= ~pDbgState->fCpe1Unwanted;
    89468946        VMXWriteVmcs32(VMX_VMCS32_CTRL_PROC_EXEC, pVCpu->hm.s.vmx.u32ProcCtls);
     8947        Log6(("hmR0VmxRunDebugStateRevert: VMX_VMCS32_CTRL_PROC_EXEC: %#RX32\n", pVCpu->hm.s.vmx.u32ProcCtls));
    89478948        pDbgState->fModifiedProcCtls   = true;
    89488949    }
     
    89518952    {
    89528953        pVCpu->hm.s.vmx.u32ProcCtls2  |= pDbgState->fCpe2Extra;
    8953         VMXWriteVmcs32(VMX_VMCS32_CTRL_PROC_EXEC, pVCpu->hm.s.vmx.u32ProcCtls2);
     8954        VMXWriteVmcs32(VMX_VMCS32_CTRL_PROC_EXEC2, pVCpu->hm.s.vmx.u32ProcCtls2);
     8955        Log6(("hmR0VmxRunDebugStateRevert: VMX_VMCS32_CTRL_PROC_EXEC2: %#RX32\n", pVCpu->hm.s.vmx.u32ProcCtls2));
    89548956        pDbgState->fModifiedProcCtls2  = true;
    89558957    }
     
    89598961        pVCpu->hm.s.vmx.u32XcptBitmap |= pDbgState->bmXcptExtra;
    89608962        VMXWriteVmcs32(VMX_VMCS32_CTRL_EXCEPTION_BITMAP, pVCpu->hm.s.vmx.u32XcptBitmap);
     8963        Log6(("hmR0VmxRunDebugStateRevert: VMX_VMCS32_CTRL_EXCEPTION_BITMAP: %#RX32\n", pVCpu->hm.s.vmx.u32XcptBitmap));
    89618964        pDbgState->fModifiedXcptBitmap = true;
    89628965    }
     
    89668969        pVCpu->hm.s.vmx.u32CR0Mask = 0;
    89678970        VMXWriteVmcs32(VMX_VMCS_CTRL_CR0_MASK, 0);
     8971        Log6(("hmR0VmxRunDebugStateRevert: VMX_VMCS_CTRL_CR0_MASK: 0\n"));
    89688972    }
    89698973
     
    89728976        pVCpu->hm.s.vmx.u32CR4Mask = 0;
    89738977        VMXWriteVmcs32(VMX_VMCS_CTRL_CR4_MASK, 0);
     8978        Log6(("hmR0VmxRunDebugStateRevert: VMX_VMCS_CTRL_CR4_MASK: 0\n"));
    89748979    }
    89758980}
     
    89979002       cached value and reload the field. */
    89989003    if (   pDbgState->fModifiedProcCtls2
    8999         && pVCpu->hm.s.vmx.u32ProcCtls2 != pDbgState->fProcCtlsInitial)
     9004        && pVCpu->hm.s.vmx.u32ProcCtls2 != pDbgState->fProcCtls2Initial)
    90009005    {
    90019006        int rc2 = VMXWriteVmcs32(VMX_VMCS32_CTRL_PROC_EXEC2, pDbgState->fProcCtls2Initial);
     
    90309035 * the necessary exits demanded by DBGF and DTrace.
    90319036 *
    9032  * @param   pVM         The cross context VM structure.
    9033  * @param   pVCpu       The cross context virtual CPU structure.
    9034  * @param   pCtx        Pointer to the guest-CPU context.
    9035  * @param   pDbgState   The debug state.
    9036  */
    9037 static void hmR0VmxPreRunGuestDebugStateUpdate(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, PVMXRUNDBGSTATE pDbgState)
     9037 * @param   pVM             The cross context VM structure.
     9038 * @param   pVCpu           The cross context virtual CPU structure.
     9039 * @param   pCtx            Pointer to the guest-CPU context.
     9040 * @param   pDbgState       The debug state.
     9041 * @param   pVmxTransient   Pointer to the VMX transient structure.  May update
     9042 *                          fUpdateTscOffsettingAndPreemptTimer.
     9043 */
     9044static void hmR0VmxPreRunGuestDebugStateUpdate(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx,
     9045                                               PVMXRUNDBGSTATE pDbgState, PVMXTRANSIENT pVmxTransient)
    90389046{
    90399047    /*
     
    91059113         ||  RT_CONCAT3(VBOXVMM_, a_EventSubName, _ENABLED)() )
    91069114#define SET_ONLY_XBM_IF_EITHER_EN(a_EventSubName, a_uExit) \
    9107         if (IS_EITHER_ENABLED(pVM, a_EventSubName)) ASMBitSet((pDbgState)->bmExitsToCheck, a_uExit); else do { } while (0)
     9115        if (IS_EITHER_ENABLED(pVM, a_EventSubName)) \
     9116        {   AssertCompile((unsigned)(a_uExit) < sizeof(pDbgState->bmExitsToCheck) * 8); \
     9117            ASMBitSet((pDbgState)->bmExitsToCheck, a_uExit); \
     9118        } else do { } while (0)
    91089119#define SET_CPE1_XBM_IF_EITHER_EN(a_EventSubName, a_uExit, a_fCtrlProcExec) \
    91099120        if (IS_EITHER_ENABLED(pVM, a_EventSubName)) \
    91109121        { \
    91119122            (pDbgState)->fCpe1Extra |= (a_fCtrlProcExec); \
     9123            AssertCompile((unsigned)(a_uExit) < sizeof(pDbgState->bmExitsToCheck) * 8); \
    91129124            ASMBitSet((pDbgState)->bmExitsToCheck, a_uExit); \
    91139125        } else do { } while (0)
     
    91169128        { \
    91179129            (pDbgState)->fCpe1Unwanted |= (a_fUnwantedCtrlProcExec); \
     9130            AssertCompile((unsigned)(a_uExit) < sizeof(pDbgState->bmExitsToCheck) * 8); \
    91189131            ASMBitSet((pDbgState)->bmExitsToCheck, a_uExit); \
    91199132        } else do { } while (0)
     
    91229135        { \
    91239136            (pDbgState)->fCpe2Extra |= (a_fCtrlProcExec2); \
     9137            AssertCompile((unsigned)(a_uExit) < sizeof(pDbgState->bmExitsToCheck) * 8); \
    91249138            ASMBitSet((pDbgState)->bmExitsToCheck, a_uExit); \
    91259139        } else do { } while (0)
     
    91369150    SET_ONLY_XBM_IF_EITHER_EN(EXIT_INVD,                VMX_EXIT_INVD);             /* unconditional */
    91379151    SET_CPE1_XBM_IF_EITHER_EN(EXIT_INVLPG,              VMX_EXIT_INVLPG,   VMX_VMCS_CTRL_PROC_EXEC_INVLPG_EXIT);
    9138 #if 0
    91399152    SET_CPE1_XBM_IF_EITHER_EN(EXIT_RDPMC,               VMX_EXIT_RDPMC,    VMX_VMCS_CTRL_PROC_EXEC_RDPMC_EXIT);
    91409153    SET_CPE1_XBM_IF_EITHER_EN(EXIT_RDTSC,               VMX_EXIT_RDTSC,    VMX_VMCS_CTRL_PROC_EXEC_RDTSC_EXIT);
     
    91599172        AssertRC(rc2);
    91609173
     9174#if 0 /** @todo fix me */
    91619175        pDbgState->fClearCr0Mask = true;
    91629176        pDbgState->fClearCr4Mask = true;
     9177#endif
    91639178        if (IS_EITHER_ENABLED(pVM, EXIT_CRX_READ))
    91649179            pDbgState->fCpe1Extra |= VMX_VMCS_CTRL_PROC_EXEC_CR3_STORE_EXIT | VMX_VMCS_CTRL_PROC_EXEC_CR8_STORE_EXIT;
     
    91959210    SET_CPE1_XBM_IF_EITHER_EN(EXIT_MWAIT,               VMX_EXIT_MWAIT,     VMX_VMCS_CTRL_PROC_EXEC_MWAIT_EXIT);   /* parnoia */
    91969211    SET_CPE1_XBM_IF_EITHER_EN(EXIT_MONITOR,             VMX_EXIT_MONITOR,   VMX_VMCS_CTRL_PROC_EXEC_MONITOR_EXIT); /* parnoia */
     9212#if 0 /** @todo too slow, fix handler. */
    91979213    SET_CPE1_XBM_IF_EITHER_EN(EXIT_PAUSE,               VMX_EXIT_PAUSE,     VMX_VMCS_CTRL_PROC_EXEC_PAUSE_EXIT);
     9214#endif
    91989215
    91999216    if (   IS_EITHER_ENABLED(pVM, EXIT_SGDT)
     
    92269243    SET_ONLY_XBM_IF_EITHER_EN(EXIT_XSAVES,              VMX_EXIT_XSAVES);           /* unconditional (enabled by host, guest cfg) */
    92279244    SET_ONLY_XBM_IF_EITHER_EN(EXIT_XRSTORS,             VMX_EXIT_XRSTORS);          /* unconditional (enabled by host, guest cfg) */
    9228 #endif
     9245
    92299246#undef IS_EITHER_ENABLED
    92309247#undef SET_ONLY_XBM_IF_EITHER_EN
     
    92369253     * Sanitize the control stuff.
    92379254     */
     9255    pDbgState->fCpe2Extra       &= pVM->hm.s.vmx.Msrs.VmxProcCtls2.n.allowed1;
     9256    if (pDbgState->fCpe2Extra)
     9257        pDbgState->fCpe1Extra   |= VMX_VMCS_CTRL_PROC_EXEC_USE_SECONDARY_EXEC_CTRL;
    92389258    pDbgState->fCpe1Extra       &= pVM->hm.s.vmx.Msrs.VmxProcCtls.n.allowed1;
    92399259    pDbgState->fCpe1Unwanted    &= ~pVM->hm.s.vmx.Msrs.VmxProcCtls.n.disallowed0;
    9240     pDbgState->fCpe2Extra       &= pVM->hm.s.vmx.Msrs.VmxProcCtls2.n.allowed1;
     9260    if (pVCpu->hm.s.fDebugWantRdTscExit != RT_BOOL(pDbgState->fCpe1Extra & VMX_VMCS_CTRL_PROC_EXEC_RDTSC_EXIT))
     9261    {
     9262        pVCpu->hm.s.fDebugWantRdTscExit ^= true;
     9263        pVmxTransient->fUpdateTscOffsettingAndPreemptTimer = true;
     9264    }
     9265
    92419266    Log6(("HM: debug state: cpe1=%#RX32 cpeu=%#RX32 cpe2=%#RX32%s%s\n",
    92429267          pDbgState->fCpe1Extra, pDbgState->fCpe1Unwanted, pDbgState->fCpe2Extra,
     
    92549279 *
    92559280 * @returns Strict VBox status code (i.e. informational status codes too).
    9256  * @param   pVM         The cross context VM structure.
    9257  * @param   pVCpu       The cross context virtual CPU structure.
    9258  * @param   pMixedCtx   Pointer to the guest-CPU context.
    9259  * @param   pDbgState   The debug state.
     9281 * @param   pVM             The cross context VM structure.
     9282 * @param   pVCpu           The cross context virtual CPU structure.
     9283 * @param   pMixedCtx       Pointer to the guest-CPU context.
     9284 * @param   pVmxTransient   Pointer to the VMX-transient structure.
     9285 * @param   uExitReason     The VM-exit reason.
    92609286 *
    92619287 * @remarks The name of this function is displayed by dtrace, so keep it short
     
    97329758
    97339759    /* Set HMCPU indicators.  */
    9734     bool const fSavedSingleInstruction = pVCpu->hm.s.fSingleInstruction;
    9735     pVCpu->hm.s.fSingleInstruction = pVCpu->hm.s.fSingleInstruction || DBGFIsStepping(pVCpu);
    9736     pVCpu->hm.s.fUsingDebugLoop = true;
     9760    bool const fSavedSingleInstruction  = pVCpu->hm.s.fSingleInstruction;
     9761    pVCpu->hm.s.fSingleInstruction      = pVCpu->hm.s.fSingleInstruction || DBGFIsStepping(pVCpu);
     9762    pVCpu->hm.s.fDebugWantRdTscExit     = false;
     9763    pVCpu->hm.s.fUsingDebugLoop         = true;
    97379764
    97389765    /* State we keep to help modify and later restore the VMCS fields we alter, and for detecting steps.  */
    97399766    VMXRUNDBGSTATE DbgState;
    97409767    hmR0VmxRunDebugStateInit(pVCpu, pCtx, &DbgState);
    9741     hmR0VmxPreRunGuestDebugStateUpdate(pVM, pVCpu, pCtx, &DbgState);
     9768    hmR0VmxPreRunGuestDebugStateUpdate(pVM, pVCpu, pCtx, &DbgState, &VmxTransient);
    97429769
    97439770    /*
     
    98329859         */
    98339860        if (VBOXVMM_GET_SETTINGS_SEQ_NO() != DbgState.uDtraceSettingsSeqNo)
    9834             hmR0VmxPreRunGuestDebugStateUpdate(pVM, pVCpu, pCtx, &DbgState);
     9861            hmR0VmxPreRunGuestDebugStateUpdate(pVM, pVCpu, pCtx, &DbgState, &VmxTransient);
    98359862    }
    98369863
     
    98569883
    98579884    /* Restore HMCPU indicators. */
    9858     pVCpu->hm.s.fUsingDebugLoop = false;
    9859     pVCpu->hm.s.fSingleInstruction = fSavedSingleInstruction;
     9885    pVCpu->hm.s.fUsingDebugLoop     = false;
     9886    pVCpu->hm.s.fDebugWantRdTscExit = false;
     9887    pVCpu->hm.s.fSingleInstruction  = fSavedSingleInstruction;
    98609888
    98619889    STAM_PROFILE_ADV_STOP(&pVCpu->hm.s.StatEntry, x);
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