VirtualBox

Changeset 46664 in vbox


Ignore:
Timestamp:
Jun 19, 2013 3:12:48 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
86555
Message:

VMM/HMSVMR0: Build fixes, makefile conditionals.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/Makefile.kmk

    r46560 r46664  
    5656ifdef VBOX_WITH_OLD_VTX_CODE
    5757 VMM_COMMON_DEFS += VBOX_WITH_OLD_VTX_CODE
     58endif
     59ifdef VBOX_WITH_OLD_AMDV_CODE
     60 VMM_COMMON_DEFS += VBOX_WITH_OLD_AMDV_CODE
    5861endif
    5962ifdef VBOX_WITH_SAFE_STR
     
    529532        VMMR0/HMR0.cpp \
    530533        VMMR0/HMR0A.asm \
    531         VMMR0/HWSVMR0.cpp \
    532534        VMMR0/PDMR0Device.cpp \
    533535        VMMR0/PDMR0Driver.cpp \
     
    595597  VMMR0_SOURCES += VMMR0/HMVMXR0.cpp
    596598 endif
     599 ifdef VBOX_WITH_OLD_AMDV_CODE
     600  VMMR0_SOURCES += VMMR0/HWSVMR0.cpp
     601 else
     602  VMMR0_SOURCES += VMMR0/HMSVMR0.cpp
     603 endif
    597604 VMMR0_SOURCES.amd64 = \
    598605        VMMR0/VMMR0JmpA-amd64.asm
  • trunk/src/VBox/VMM/VMMR0/HMSVMR0.cpp

    r46659 r46664  
    1919*   Header Files                                                               *
    2020*******************************************************************************/
     21#define LOG_GROUP LOG_GROUP_HM
     22#include <iprt/asm-amd64-x86.h>
     23#include <iprt/thread.h>
     24
     25#include "HMInternal.h"
     26#include <VBox/vmm/vm.h>
     27#include "HWSVMR0.h"
     28#include <VBox/vmm/pdmapi.h>
     29#include <VBox/vmm/dbgf.h>
     30#include <VBox/vmm/iom.h>
     31#include <VBox/vmm/tm.h>
    2132
    2233#ifdef DEBUG_ramshankar
     
    7586    do \
    7687    { \
    77         pCtx->reg.Sel       = pVmcb->guest.REG.u16Sel; \
    78         pCtx->reg.ValidSel  = pVmcb->guest.REG.u16Sel; \
    79         pCtx->reg.fFlags    = CPUMSELREG_FLAGS_VALID; \
    80         pCtx->reg.u32Limit  = pVmcb->guest.REG.u32Limit; \
    81         pCtx->reg.u64Base   = pVmcb->guest.REG.u64Base; \
    82         pCtx->reg.Attr.u    = HMSVM_VMCB_2_CPU_SEG_ATTR(pVmcb->guest.REG.u16Attr); \
     88        pMixedCtx->reg.Sel       = pVmcb->guest.REG.u16Sel; \
     89        pMixedCtx->reg.ValidSel  = pVmcb->guest.REG.u16Sel; \
     90        pMixedCtx->reg.fFlags    = CPUMSELREG_FLAGS_VALID; \
     91        pMixedCtx->reg.u32Limit  = pVmcb->guest.REG.u32Limit; \
     92        pMixedCtx->reg.u64Base   = pVmcb->guest.REG.u64Base; \
     93        pMixedCtx->reg.Attr.u    = HMSVM_VMCB_2_CPU_SEG_ATTR(pVmcb->guest.REG.u16Attr); \
    8394    } while (0)
    8495/** @} */
     
    145156#define HMSVM_VMCB_CLEAN_AVIC                   RT_BIT(11)
    146157/** Mask of all valid VMCB Clean bits. */
    147 #define HMSVM_VMCB_CLEAN_ALL                    (  HMSVM_VMCB_CLEAN_INTERCEPTS
    148                                                  | HMSVM_VMCB_CLEAN_IOPM_MSRPM
    149                                                  | HMSVM_VMCB_CLEAN_ASID
    150                                                  | HMSVM_VMCB_CLEAN_TPR
    151                                                  | HMSVM_VMCB_CLEAN_NP
    152                                                  | HMSVM_VMCB_CLEAN_CRX
    153                                                  | HMSVM_VMCB_CLEAN_DRX
    154                                                  | HMSVM_VMCB_CLEAN_DT
    155                                                  | HMSVM_VMCB_CLEAN_SEG
    156                                                  | HMSVM_VMCB_CLEAN_CR2
    157                                                  | HMSVM_VMCB_CLEAN_LBR
     158#define HMSVM_VMCB_CLEAN_ALL                    (  HMSVM_VMCB_CLEAN_INTERCEPTS  \
     159                                                 | HMSVM_VMCB_CLEAN_IOPM_MSRPM  \
     160                                                 | HMSVM_VMCB_CLEAN_ASID        \
     161                                                 | HMSVM_VMCB_CLEAN_TPR         \
     162                                                 | HMSVM_VMCB_CLEAN_NP          \
     163                                                 | HMSVM_VMCB_CLEAN_CRX_EFER    \
     164                                                 | HMSVM_VMCB_CLEAN_DRX         \
     165                                                 | HMSVM_VMCB_CLEAN_DT          \
     166                                                 | HMSVM_VMCB_CLEAN_SEG         \
     167                                                 | HMSVM_VMCB_CLEAN_CR2         \
     168                                                 | HMSVM_VMCB_CLEAN_LBR         \
    158169                                                 | HMSVM_VMCB_CLEAN_AVIC)
    159170/** @} */
     
    212223*******************************************************************************/
    213224static void hmR0SvmSetMsrPermission(PVMCPU pVCpu, unsigned uMsr, SVMMSREXITREAD enmRead, SVMMSREXITWRITE enmWrite);
     225static void hmR0SvmPendingEventToTrpmTrap(PVMCPU pVCpu);
     226
     227HMSVM_EXIT_DECL hmR0SvmExitIntr(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     228HMSVM_EXIT_DECL hmR0SvmExitWbinvd(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     229HMSVM_EXIT_DECL hmR0SvmExitInvd(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     230HMSVM_EXIT_DECL hmR0SvmExitCpuid(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     231HMSVM_EXIT_DECL hmR0SvmExitRdtsc(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     232HMSVM_EXIT_DECL hmR0SvmExitRdtscp(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     233HMSVM_EXIT_DECL hmR0SvmExitRdpmc(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     234HMSVM_EXIT_DECL hmR0SvmExitInvlpg(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     235HMSVM_EXIT_DECL hmR0SvmExitHlt(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     236HMSVM_EXIT_DECL hmR0SvmExitMonitor(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     237HMSVM_EXIT_DECL hmR0SvmExitMwait(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     238HMSVM_EXIT_DECL hmR0SvmExitShutdown(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     239HMSVM_EXIT_DECL hmR0SvmExitReadCRx(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     240HMSVM_EXIT_DECL hmR0SvmExitWriteCRx(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     241HMSVM_EXIT_DECL hmR0SvmExitSetPendingXcptUD(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     242HMSVM_EXIT_DECL hmR0SvmExitMsr(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     243HMSVM_EXIT_DECL hmR0SvmExitReadDRx(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     244HMSVM_EXIT_DECL hmR0SvmExitWriteDRx(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     245HMSVM_EXIT_DECL hmR0SvmExitIOInstr(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     246HMSVM_EXIT_DECL hmR0SvmExitNestedPF(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     247HMSVM_EXIT_DECL hmR0SvmExitVIntr(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     248HMSVM_EXIT_DECL hmR0SvmExitTaskSwitch(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     249HMSVM_EXIT_DECL hmR0SvmExitVmmCall(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     250HMSVM_EXIT_DECL hmR0SvmExitXcptPF(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     251HMSVM_EXIT_DECL hmR0SvmExitXcptNM(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     252HMSVM_EXIT_DECL hmR0SvmExitXcptMF(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
     253HMSVM_EXIT_DECL hmR0SvmExitXcptDB(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient);
    214254
    215255DECLINLINE(int) hmR0SvmHandleExit(PVMCPU pVCpu, PCPUMCTX pMixedCtx, PSVMTRANSIENT pSvmTransient);
     
    331371
    332372    /* Set all bits to intercept all IO accesses. */
    333     ASMMemFill32(pVM->hm.s.svm.pvIOBitmap, 3 << PAGE_SHIFT, UINT32_C(0xffffffff));
     373    ASMMemFill32(g_pvIOBitmap, 3 << PAGE_SHIFT, UINT32_C(0xffffffff));
     374    return VINF_SUCCESS;
    334375}
    335376
     
    342383    if (g_hMemObjIOBitmap != NIL_RTR0MEMOBJ)
    343384    {
    344         RTR0MemObjFree(pVM->hm.s.svm.hMemObjIOBitmap, false /* fFreeMappings */);
     385        RTR0MemObjFree(g_hMemObjIOBitmap, false /* fFreeMappings */);
    345386        g_pvIOBitmap      = NULL;
    346387        g_HCPhysIOBitmap  = 0;
     
    424465    for (VMCPUID i = 0; i < pVM->cCpus; i++)
    425466    {
     467        PVMCPU pVCpu = &pVM->aCpus[i];
     468
    426469        /*
    427470         * Allocate one page for the host-context VM control block (VMCB). This is used for additional host-state (such as
     
    455498        rc = RTR0MemObjAllocCont(&pVCpu->hm.s.svm.hMemObjMsrBitmap, 2 << PAGE_SHIFT, false /* fExecutable */);
    456499        if (RT_FAILURE(rc))
    457             failure_cleanup;
     500            goto failure_cleanup;
    458501
    459502        pVCpu->hm.s.svm.pvMsrBitmap     = RTR0MemObjAddress(pVCpu->hm.s.svm.hMemObjMsrBitmap);
     
    466509
    467510failure_cleanup:
    468     hmR0SvmFreeVMStructs(pVM);
     511    hmR0SvmFreeStructs(pVM);
    469512    return rc;
    470513}
     
    479522VMMR0DECL(int) SVMR0TermVM(PVM pVM)
    480523{
    481     hmR0SvmFreeVMStructs(pVM);
     524    hmR0SvmFreeStructs(pVM);
    482525    return VINF_SUCCESS;
    483526}
     
    492535 * @param   enmWrite    MSR write permissions.
    493536 */
    494 static void hmR0SvmSetMsrPermission(PVMCPU pVCpu, uint32_t uMsr, SVMMSREXITREAD enmRead, SVMMSREXITWRITE enmWrite)
     537static void hmR0SvmSetMsrPermission(PVMCPU pVCpu, unsigned uMsr, SVMMSREXITREAD enmRead, SVMMSREXITWRITE enmWrite)
    495538{
    496539    unsigned ulBit;
     
    541584        ASMBitClear(pbMsrBitmap, ulBit + 1);
    542585
     586    PSVMVMCB pVmcb = (PSVMVMCB)pVCpu->hm.s.svm.pvVmcb;
    543587    pVmcb->ctrl.u64VmcbCleanBits &= ~HMSVM_VMCB_CLEAN_IOPM_MSRPM;
    544588}
     
    821865    }
    822866    else
    823         Assert(pVmcb->ctrl.TLBCtrl.n.u8TLBFlush == SVM_TLB_FLUSH_ENTIRE)
     867        Assert(pVmcb->ctrl.TLBCtrl.n.u8TLBFlush == SVM_TLB_FLUSH_ENTIRE);
    824868#endif
    825869}
     
    900944
    901945
    902 DECLINLINE(void) hmR0SvmAddXcptIntercept(uint32_t u32Xcpt)
    903 {
    904     if (!(pVmcb->ctrl.u32InterceptException & RT_BIT(u32Xcpt))
     946/**
     947 * Adds an exception to the intercept exception bitmap in the VMCB and updates
     948 * the corresponding VMCB Clean Bit.
     949 *
     950 * @param   pVmcb       Pointer to the VMCB.
     951 * @param   u32Xcpt     The value of the exception (X86_XCPT_*).
     952 */
     953DECLINLINE(void) hmR0SvmAddXcptIntercept(PSVMVMCB pVmcb, uint32_t u32Xcpt)
     954{
     955    if (!(pVmcb->ctrl.u32InterceptException & RT_BIT(u32Xcpt)))
    905956    {
    906957        pVmcb->ctrl.u32InterceptException |= RT_BIT(u32Xcpt);
     
    909960}
    910961
    911 DECLINLINE(void) hmR0SvmRemoveXcptIntercept(uint32_t u32Xcpt)
     962
     963/**
     964 * Removes an exception from the intercept-exception bitmap in the VMCB and
     965 * updates the corresponding VMCB Clean Bit.
     966 *
     967 * @param   pVmcb       Pointer to the VMCB.
     968 * @param   u32Xcpt     The value of the exception (X86_XCPT_*).
     969 */
     970DECLINLINE(void) hmR0SvmRemoveXcptIntercept(PSVMVMCB pVmcb, uint32_t u32Xcpt)
    912971{
    913972#ifndef HMSVM_ALWAYS_TRAP_ALL_XCPTS
     
    936995     * Guest CR0.
    937996     */
     997    PVM pVM = pVCpu->CTX_SUFF(pVM);
    938998    if (pVCpu->hm.s.fContextUseFlags & HM_CHANGED_GUEST_CR0)
    939999    {
     
    9711031        {
    9721032            fInterceptNM = true;           /* Guest FPU inactive, VM-exit on #NM for lazy FPU loading. */
    973             u32GuestCR0 |=  X86_CR0_TS     /* Guest can task switch quickly and do lazy FPU syncing. */
     1033            u64GuestCR0 |=  X86_CR0_TS     /* Guest can task switch quickly and do lazy FPU syncing. */
    9741034                          | X86_CR0_MP;    /* FWAIT/WAIT should not ignore CR0.TS and should generate #NM. */
    9751035        }
     
    9791039         */
    9801040        if (fInterceptNM)
    981             hmR0SvmAddXcptIntercept(X86_XCPT_NM);
     1041            hmR0SvmAddXcptIntercept(pVmcb, X86_XCPT_NM);
    9821042        else
    983             hmR0SvmRemoveXcptIntercept(X86_XCPT_NM);
     1043            hmR0SvmRemoveXcptIntercept(pVmcb, X86_XCPT_NM);
    9841044
    9851045        if (fInterceptMF)
    986             hmR0SvmAddXcptIntercept(X86_XCPT_MF);
     1046            hmR0SvmAddXcptIntercept(pVmcb, X86_XCPT_MF);
    9871047        else
    988             hmR0SvmRemoveXcptIntercept(X86_XCPT_MF);
     1048            hmR0SvmRemoveXcptIntercept(pVmcb, X86_XCPT_MF);
    9891049
    9901050        pVmcb->guest.u64CR0 = u64GuestCR0;
     
    11601220     * See AMD spec. 15.5.1 "Basic Operation" | "Canonicalization and Consistency Checks".
    11611221     */
    1162     if (pVCpu->hm.s.fContextUseFlags & HM_CHANGED_SVM_GUEST_EFER_MSR
     1222    if (pVCpu->hm.s.fContextUseFlags & HM_CHANGED_SVM_GUEST_EFER_MSR)
    11631223    {
    11641224        pVmcb->guest.u64EFER = pCtx->msrEFER | MSR_K6_EFER_SVME;
     
    11981258 *
    11991259 * @param   pVCpu       Pointer to the VMCPU.
     1260 * @param   pVmcb       Pointer to the VMCB.
    12001261 * @param   pCtx        Pointer to the guest-CPU context.
    12011262 *
     
    12031264 * @remarks Requires EFLAGS to be up-to-date in the VMCB!
    12041265 */
    1205 DECLINLINE(void) hmR0SvmLoadGuestDebugRegs(PVMCPU pVCpu, PCPUMCTX pCtx)
     1266DECLINLINE(void) hmR0SvmLoadGuestDebugRegs(PVMCPU pVCpu, PSVMVMCB pVmcb, PCPUMCTX pCtx)
    12061267{
    12071268    if (!(pVCpu->hm.s.fContextUseFlags & HM_CHANGED_GUEST_DEBUG))
     
    12301291    }
    12311292
     1293    PVM pVM = pVCpu->CTX_SUFF(pVM);
    12321294    if (CPUMGetHyperDR7(pVCpu) & (X86_DR7_ENABLED_MASK | X86_DR7_GD))
    12331295    {
    12341296        if (!CPUMIsHyperDebugStateActive(pVCpu))
    12351297        {
    1236             rc = CPUMR0LoadHyperDebugState(pVM, pVCpu, pCtx, true /* include DR6 */);
     1298            int rc = CPUMR0LoadHyperDebugState(pVM, pVCpu, pCtx, true /* include DR6 */);
    12371299            AssertRC(rc);
    12381300
     
    12491311        if (!CPUMIsGuestDebugStateActive(pVCpu))
    12501312        {
    1251             rc = CPUMR0LoadGuestDebugState(pVM, pVCpu, pCtx, true /* include DR6 */);
     1313            int rc = CPUMR0LoadGuestDebugState(pVM, pVCpu, pCtx, true /* include DR6 */);
    12521314            AssertRC(rc);
    12531315            STAM_COUNTER_INC(&pVCpu->hm.s.StatDRxArmed);
     
    12631325
    12641326    if (fInterceptDB)
    1265         hmR0SvmAddXcptIntercept(X86_XCPT_DB);
     1327        hmR0SvmAddXcptIntercept(pVmcb, X86_XCPT_DB);
    12661328    else
    1267         hmR0SvmRemoveXcptIntercept(X86_XCPT_DB);
     1329        hmR0SvmRemoveXcptIntercept(pVmcb, X86_XCPT_DB);
    12681330
    12691331    if (fInterceptMovDRx)
     
    13181380    if (pVCpu->CTX_SUFF(pVM)->hm.s.fTPRPatchingActive)
    13191381    {
    1320         pCtx->msrLSTAR = u8LastTPR;
     1382        pCtx->msrLSTAR = u8Tpr;
    13211383
    13221384        /* If there are interrupts pending, intercept LSTAR writes, otherwise don't intercept reads or writes. */
     
    13371399
    13381400        /* If there are interrupts pending, intercept CR8 writes to evaluate ASAP if we can deliver the interrupt to the guest. */
    1339         if (fPending)
     1401        if (fPendingIntr)
    13401402            pVmcb->ctrl.u16InterceptWrCRx |= RT_BIT(8);
    13411403        else
     
    15701632    /** @todo Verify this. */
    15711633    if (   !pMixedCtx->cs.Attr.n.u1Granularity
    1572         &&  pMixedCtx->cs.Attr.n.u1Present
    1573         &&  pMixedCtx->cs.u32Limit > UINT32_C(0xfffff))
     1634        && pMixedCtx->cs.Attr.n.u1Present
     1635        && pMixedCtx->cs.u32Limit > UINT32_C(0xfffff))
    15741636    {
    15751637        Assert((pMixedCtx->cs.u32Limit & 0xfff) == 0xfff);
     
    15771639    }
    15781640#ifdef VBOX_STRICT
    1579 # define HMSVM_ASSERT_SEL_GRANULARITY(reg) \
     1641# define HMSVM_ASSERT_SEG_GRANULARITY(reg) \
    15801642    AssertMsg(   !pMixedCtx->reg.Attr.n.u1Present \
    15811643              || (   pMixedCtx->reg.Attr.n.u1Granularity \
    15821644                  ? (pMixedCtx->reg.u32Limit & 0xfff) == 0xfff \
    15831645                  :  pMixedCtx->reg.u32Limit <= UINT32_C(0xfffff)), \
    1584               ("Invalid Segment Attributes %#x %#x %#llx\n", pMixedCtx->reg.u32Limit,
     1646              ("Invalid Segment Attributes %#x %#x %#llx\n", pMixedCtx->reg.u32Limit, \
    15851647              pMixedCtx->reg.Attr.u, pMixedCtx->reg.u64Base))
    15861648
     
    16251687     * This is done as the very last step of syncing the guest state, as PGMUpdateCR3() may cause longjmp's to ring-3.
    16261688     */
    1627     if (   pVM->hm.s.fNestedPaging
     1689    if (   pVCpu->CTX_SUFF(pVM)->hm.s.fNestedPaging
    16281690        && pMixedCtx->cr3 != pVmcb->guest.u64CR3)
    16291691    {
     
    16691731        CPUMR0LoadHostDebugState(pVM, pVCpu);
    16701732        Assert(!CPUMIsHyperDebugStateActive(pVCpu));
     1733#ifdef VBOX_STRICT
     1734        PSVMVMCB pVmcb = (PSVMVMCB)pVCpu->hm.s.svm.pvVmcb;
    16711735        Assert(pVmcb->ctrl.u16InterceptRdDRx == 0xffff);
    16721736        Assert(pVmcb->ctrl.u16InterceptWrDRx == 0xffff);
     1737#endif
    16731738    }
    16741739
     
    18541919
    18551920
    1856 /**
    1857  * Converts any TRPM trap into a pending SVM event. This is typically used when
     1921
     1922/**
     1923 * Converts any TRPM trap into a pending HM event. This is typically used when
    18581924 * entering from ring-3 (not longjmp returns).
    18591925 *
     
    18741940    AssertRC(rc);
    18751941
    1876     PSVMEVENT pEvent = &pVCpu->hm.s.Event;
    1877     pEvent->u         = 0;
    1878     pEvent->n.u1Valid = 1;
     1942    SVMEVENT Event;
     1943    Event.u         = 0;
     1944    Event.n.u1Valid = 1;
    18791945
    18801946    /* Refer AMD spec. 15.20 "Event Injection" for the format. */
    18811947    if (enmTrpmEvent == TRPM_TRAP)
    18821948    {
    1883         pEvent->n.u3Type = SVM_EVENT_EXCEPTION;
     1949        Event.n.u3Type = SVM_EVENT_EXCEPTION;
    18841950        switch (uVector)
    18851951        {
     
    18921958            case X86_XCPT_AC:
    18931959            {
    1894                 pEvent->n.u32ErrorCode     = uErrCode;
    1895                 pEvent->n.u1ErrorCodeValid = 1;
     1960                Event.n.u32ErrorCode     = uErrCode;
     1961                Event.n.u1ErrorCodeValid = 1;
    18961962                break;
    18971963            }
     
    19011967    {
    19021968        if (uVector == X86_XCPT_NMI)
    1903             pEvent->n.u3Type = SVM_EVENT_NMI;
     1969            Event.n.u3Type = SVM_EVENT_NMI;
    19041970        else
    1905             pEvent->n.u3Type = SVM_EVENT_EXTERNAL_IRQ;
     1971            Event.n.u3Type = SVM_EVENT_EXTERNAL_IRQ;
    19061972    }
    19071973    else if (enmTrpmEvent == TRPM_SOFTWARE_INT)
    1908         pEvent->n.u3Type = SVM_EVENT_SOFTWARE_INT;
     1974        Event.n.u3Type = SVM_EVENT_SOFTWARE_INT;
    19091975    else
    19101976        AssertMsgFailed(("Invalid TRPM event type %d\n", enmTrpmEvent));
     
    19131979    AssertRC(rc);
    19141980
    1915     Log4(("TRPM->HM event: u=%#RX64 u8Vector=%#x uErrorCodeValid=%#x uErrorCode=%#RX32\n", pEvent->u, pEvent->n.u8Vector,
    1916           pEvent->n.u1ErrorCodeValid, pEvent->n.u32ErrorCode));
     1981    Log4(("TRPM->HM event: u=%#RX64 u8Vector=%#x uErrorCodeValid=%RTbool uErrorCode=%#RX32\n", Event.u, Event.n.u8Vector,
     1982          !!Event.n.u1ErrorCodeValid, Event.n.u32ErrorCode));
     1983    hmR0SvmSetPendingEvent(pVCpu, &Event, GCPtrFaultAddress);
    19171984}
    19181985
     
    19291996    Assert(TRPMQueryTrap(pVCpu, NULL /* pu8TrapNo */, NULL /* pEnmType */) == VERR_TRPM_NO_ACTIVE_TRAP);
    19301997
    1931     PSVMEVENT pEvent    = &pVCpu->hm.s.Event;
    1932     uint8_t uVector     = pEvent->n.u8Vector;
    1933     uint8_t uVectorType = pEvent->n.u3Type;
     1998    SVMEVENT Event;
     1999    Event.u = pVCpu->hm.s.Event.u64IntrInfo;
     2000
     2001    uint8_t uVector     = Event.n.u8Vector;
     2002    uint8_t uVectorType = Event.n.u3Type;
    19342003
    19352004    TRPMEVENT enmTrapType;
    19362005    switch (uVectorType)
    19372006    {
    1938         case SVM_EVENT_EXTERNAL_IRQ
     2007        case SVM_EVENT_EXTERNAL_IRQ:
    19392008        case SVM_EVENT_NMI:
    19402009           enmTrapType = TRPM_HARDWARE_INT;
     
    19572026    AssertRC(rc);
    19582027
    1959     if (pEvent->n.u1ErrorCodeValid)
    1960         TRPMSetErrorCode(pVCpu, pEvent->n.u32ErrorCode);
     2028    if (Event.n.u1ErrorCodeValid)
     2029        TRPMSetErrorCode(pVCpu, Event.n.u32ErrorCode);
    19612030
    19622031    if (   uVectorType == SVM_EVENT_EXCEPTION
     
    20612130        {
    20622131            pVCpu->hm.s.Event.fPending = false;
    2063             hmR0SvmInjectEvent(pVCpu, pVmcb, pCtx, &Event);
     2132            hmR0SvmInjectEventVmcb(pVCpu, pVmcb, pCtx, &Event);
    20642133        }
    20652134        else
     
    20762145            Event.n.u3Type   = SVM_EVENT_NMI;
    20772146
    2078             hmR0SvmInjectEvent(pVCpu, pVmcb, pCtx, &Event);
     2147            hmR0SvmInjectEventVmcb(pVCpu, pVmcb, pCtx, &Event);
    20792148            VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_NMI);
    20802149        }
     
    20902159        {
    20912160            uint8_t u8Interrupt;
    2092             rc = PDMGetInterrupt(pVCpu, &u8Interrupt);
     2161            int rc = PDMGetInterrupt(pVCpu, &u8Interrupt);
    20932162            if (RT_SUCCESS(rc))
    20942163            {
     
    20992168                Event.n.u3Type   = SVM_EVENT_EXTERNAL_IRQ;
    21002169
    2101                 hmR0SvmInjectEvent(pVCpu, pVmcb, pCtx, &Event);
     2170                hmR0SvmInjectEventVmcb(pVCpu, pVmcb, pCtx, &Event);
    21022171                STAM_COUNTER_INC(&pVCpu->hm.s.StatIntInject);
    21032172            }
     
    22892358        if (VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_HM_UPDATE_CR3))
    22902359        {
    2291             rc = PGMUpdateCR3(pVCpu, pCtx->cr3);
     2360            int rc = PGMUpdateCR3(pVCpu, pCtx->cr3);
    22922361            Assert(rc == VINF_SUCCESS || rc == VINF_PGM_SYNC_CR3);
    22932362            Assert(!VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_HM_UPDATE_CR3));
     
    22972366        if (VMCPU_FF_IS_PENDING(pVCpu,VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL))
    22982367        {
    2299             rc = PGMSyncCR3(pVCpu, pCtx->cr0, pCtx->cr3, pCtx->cr4, VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3));
     2368            int rc = PGMSyncCR3(pVCpu, pCtx->cr0, pCtx->cr3, pCtx->cr4, VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3));
    23002369            if (rc != VINF_SUCCESS)
    23012370            {
    2302                 AssertRC(rc);
    23032371                Log4(("hmR0SvmCheckForceFlags: PGMSyncCR3 forcing us back to ring-3. rc=%d\n", rc));
    23042372                return rc;
     
    23122380        {
    23132381            STAM_COUNTER_INC(&pVCpu->hm.s.StatSwitchHmToR3FF);
    2314             rc = RT_UNLIKELY(VM_FF_IS_PENDING(pVM, VM_FF_PGM_NO_MEMORY)) ? VINF_EM_NO_MEMORY : VINF_EM_RAW_TO_R3;
     2382            int rc = RT_UNLIKELY(VM_FF_IS_PENDING(pVM, VM_FF_PGM_NO_MEMORY)) ? VINF_EM_NO_MEMORY : VINF_EM_RAW_TO_R3;
    23152383            Log4(("hmR0SvmCheckForceFlags: HM_TO_R3 forcing us back to ring-3. rc=%d\n", rc));
    23162384            return rc;
     
    23402408    }
    23412409
    2342     /* Paranoia. */
    2343     Assert(rc != VERR_EM_INTERPRETER);
    23442410    return VINF_SUCCESS;
    23452411}
     
    23622428 * @retval VINF_* scheduling changes, we have to go back to ring-3.
    23632429 *
     2430 * @param   pVM             Pointer to the VM.
    23642431 * @param   pVCpu           Pointer to the VMCPU.
    23652432 * @param   pCtx            Pointer to the guest-CPU context.
    23662433 * @param   pSvmTransient   Pointer to the SVM transient structure.
    23672434 */
    2368 DECLINE(int) hmR0SvmPreRunGuest(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient)
     2435DECLINLINE(int) hmR0SvmPreRunGuest(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient)
    23692436{
    23702437    /* Check force flag actions that might require us to go back to ring-3. */
     
    24302497     *        should be done wrt to the VMCB Clean Bit, but we'll find out the
    24312498     *        hard way. */
     2499    PSVMVMCB pVmcb = (PSVMVMCB)pVCpu->hm.s.svm.pvVmcb;
    24322500    pVmcb->ctrl.NestedPaging.n.u1NestedPaging = pVM->hm.s.fNestedPaging;
    24332501
     
    24692537        pVCpu->hm.s.u64HostTscAux = ASMRdMsr(MSR_K8_TSC_AUX);
    24702538        uint64_t u64GuestTscAux = 0;
    2471         rc2 = CPUMQueryGuestMsr(pVCpu, MSR_K8_TSC_AUX, &u64GuestTscAux);
     2539        int rc2 = CPUMQueryGuestMsr(pVCpu, MSR_K8_TSC_AUX, &u64GuestTscAux);
    24722540        AssertRC(rc2);
    24732541        ASMWrMsr(MSR_K8_TSC_AUX, u64GuestTscAux);
     
    25182586 *          unconditionally when it is safe to do so.
    25192587 */
    2520 DECLINLINE(void) hmR0SvmPostRunGuest(PVM pVM, PVMCPU pVCpu, PCPUMCTX pMixedCtx, PSVMTRANSIENT pSvmTransient, rcVMRun)
     2588DECLINLINE(void) hmR0SvmPostRunGuest(PVM pVM, PVMCPU pVCpu, PCPUMCTX pMixedCtx, PSVMTRANSIENT pSvmTransient, int rcVMRun)
    25212589{
    25222590    Assert(!VMMRZCallRing3IsEnabled(pVCpu));
     
    25652633            /* TPR patching (for 32-bit guests) uses LSTAR MSR for holding the TPR value, otherwise uses the VTPR. */
    25662634            if (   pVM->hm.s.fTPRPatchingActive
    2567                 && (pCtx->msrLSTAR & 0xff) != pSvmTransient->u8GuestTpr)
     2635                && (pMixedCtx->msrLSTAR & 0xff) != pSvmTransient->u8GuestTpr)
    25682636            {
    2569                 int rc = PDMApicSetTPR(pVCpu, pCtx->msrLSTAR & 0xff);
     2637                int rc = PDMApicSetTPR(pVCpu, (pMixedCtx->msrLSTAR & 0xff));
    25702638                AssertRC(rc);
    25712639            }
     
    26302698                        || SvmTransient.u64ExitCode == (uint64_t)SVM_EXIT_INVALID))   /* Check for invalid guest-state errors. */
    26312699        {
    2632             if (rc == VINF_SUCCESS);
     2700            if (rc == VINF_SUCCESS)
    26332701                rc = VERR_SVM_INVALID_GUEST_STATE;
    2634             hmR0SvmReportWorldSwitchError(pVM, pVCpu, rc, pCtx, &SvmTransient);
     2702            hmR0SvmReportWorldSwitchError(pVM, pVCpu, rc, pCtx);
    26352703            return rc;
    26362704        }
     
    27492817        default:
    27502818        {
    2751             case SVM_EXIT_READ_DR0:     case SVM_EXIT_READ_DR1:     case SVM_EXIT_READ_DR2:     case SVM_EXIT_READ_DR3:
    2752             case SVM_EXIT_READ_DR6:     case SVM_EXIT_READ_DR7:     case SVM_EXIT_READ_DR8:     case SVM_EXIT_READ_DR9:
    2753             case SVM_EXIT_READ_DR10:    case SVM_EXIT_READ_DR11:    case SVM_EXIT_READ_DR12:    case SVM_EXIT_READ_DR13:
    2754             case SVM_EXIT_READ_DR14:    case SVM_EXIT_READ_DR15:
    2755                 return hmR0SvmExitReadDRx(pVCpu, pCtx, pSvmTransient);
    2756 
    2757             case SVM_EXIT_WRITE_DR0:    case SVM_EXIT_WRITE_DR1:    case SVM_EXIT_WRITE_DR2:    case SVM_EXIT_WRITE_DR3:
    2758             case SVM_EXIT_WRITE_DR6:    case SVM_EXIT_WRITE_DR7:    case SVM_EXIT_WRITE_DR8:    case SVM_EXIT_WRITE_DR9:
    2759             case SVM_EXIT_WRITE_DR10:   case SVM_EXIT_WRITE_DR11:   case SVM_EXIT_WRITE_DR12:   case SVM_EXIT_WRITE_DR13:
    2760             case SVM_EXIT_WRITE_DR14:   case SVM_EXIT_WRITE_DR15:
    2761                 return hmR0SvmExitWriteDRx(pVCpu, pCtx, pSvmTransient);
    2762 
    2763             case SVM_EXIT_TASK_SWITCH:
    2764                 return hmR0SvmExitTaskSwitch(pVCpu, pCtx, pSvmTransient);
    2765 
    2766             case SVM_EXIT_VMMCALL:
    2767                 return hmR0SvmExitVmmCall(pVCpu, pCtx, pSvmTransient);
    2768 
    2769             case SVM_EXIT_INVLPGA:
    2770             case SVM_EXIT_RSM:
    2771             case SVM_EXIT_VMRUN:
    2772             case SVM_EXIT_VMLOAD:
    2773             case SVM_EXIT_VMSAVE:
    2774             case SVM_EXIT_STGI:
    2775             case SVM_EXIT_CLGI:
    2776             case SVM_EXIT_SKINIT:
    2777                 return hmR0SvmExitSetPendingXcptUD(pVCpu, pCtx, pSvmTransient);
     2819            switch (pSvmTransient->u64ExitCode)
     2820            {
     2821                case SVM_EXIT_READ_DR0:     case SVM_EXIT_READ_DR1:     case SVM_EXIT_READ_DR2:     case SVM_EXIT_READ_DR3:
     2822                case SVM_EXIT_READ_DR6:     case SVM_EXIT_READ_DR7:     case SVM_EXIT_READ_DR8:     case SVM_EXIT_READ_DR9:
     2823                case SVM_EXIT_READ_DR10:    case SVM_EXIT_READ_DR11:    case SVM_EXIT_READ_DR12:    case SVM_EXIT_READ_DR13:
     2824                case SVM_EXIT_READ_DR14:    case SVM_EXIT_READ_DR15:
     2825                    return hmR0SvmExitReadDRx(pVCpu, pCtx, pSvmTransient);
     2826
     2827                case SVM_EXIT_WRITE_DR0:    case SVM_EXIT_WRITE_DR1:    case SVM_EXIT_WRITE_DR2:    case SVM_EXIT_WRITE_DR3:
     2828                case SVM_EXIT_WRITE_DR6:    case SVM_EXIT_WRITE_DR7:    case SVM_EXIT_WRITE_DR8:    case SVM_EXIT_WRITE_DR9:
     2829                case SVM_EXIT_WRITE_DR10:   case SVM_EXIT_WRITE_DR11:   case SVM_EXIT_WRITE_DR12:   case SVM_EXIT_WRITE_DR13:
     2830                case SVM_EXIT_WRITE_DR14:   case SVM_EXIT_WRITE_DR15:
     2831                    return hmR0SvmExitWriteDRx(pVCpu, pCtx, pSvmTransient);
     2832
     2833                case SVM_EXIT_TASK_SWITCH:
     2834                    return hmR0SvmExitTaskSwitch(pVCpu, pCtx, pSvmTransient);
     2835
     2836                case SVM_EXIT_VMMCALL:
     2837                    return hmR0SvmExitVmmCall(pVCpu, pCtx, pSvmTransient);
     2838
     2839                case SVM_EXIT_INVLPGA:
     2840                case SVM_EXIT_RSM:
     2841                case SVM_EXIT_VMRUN:
     2842                case SVM_EXIT_VMLOAD:
     2843                case SVM_EXIT_VMSAVE:
     2844                case SVM_EXIT_STGI:
     2845                case SVM_EXIT_CLGI:
     2846                case SVM_EXIT_SKINIT:
     2847                    return hmR0SvmExitSetPendingXcptUD(pVCpu, pCtx, pSvmTransient);
    27782848
    27792849#ifdef HMSVM_ALWAYS_TRAP_ALL_XCPTS
    2780             case SVM_EXIT_EXCEPTION_0:      /* X86_XCPT_DE */
    2781             case SVM_EXIT_EXCEPTION_3:      /* X86_XCPT_BP */
    2782             case SVM_EXIT_EXCEPTION_6:      /* X86_XCPT_UD */
    2783             case SVM_EXIT_EXCEPTION_B:      /* X86_XCPT_NP */
    2784             case SVM_EXIT_EXCEPTION_C:      /* X86_XCPT_SS */
    2785             case SVM_EXIT_EXCEPTION_D:      /* X86_XCPT_GP */
    2786             {
    2787                 SVMEVENT Event;
    2788                 Event.u          = 0;
    2789                 Event.n.u1Valid  = 1;
    2790                 Event.n.u3Type   = SVM_EVENT_EXCEPTION;
    2791                 Event.n.u8Vector = pSvmTransient->u64ExitCode - SVM_EXIT_EXCEPTION_0;
    2792 
    2793                 switch (Event.n.u8Vector)
     2850                case SVM_EXIT_EXCEPTION_0:      /* X86_XCPT_DE */
     2851                case SVM_EXIT_EXCEPTION_3:      /* X86_XCPT_BP */
     2852                case SVM_EXIT_EXCEPTION_6:      /* X86_XCPT_UD */
     2853                case SVM_EXIT_EXCEPTION_B:      /* X86_XCPT_NP */
     2854                case SVM_EXIT_EXCEPTION_C:      /* X86_XCPT_SS */
     2855                case SVM_EXIT_EXCEPTION_D:      /* X86_XCPT_GP */
    27942856                {
    2795                     case X86_XCPT_GP:
    2796                         Event.n.u1ErrorCodeValid    = 1;
    2797                         Event.n.u32ErrorCode        = pVmcb->ctrl.u64ExitInfo1;
    2798                         STAM_COUNTER_INC(&pVCpu->hm.s.StatExitGuestGP);
    2799                         break;
    2800                     case X86_XCPT_BP:
    2801                         /** Saves the wrong EIP on the stack (pointing to the int3) instead of the
    2802                          *  next instruction. */
    2803                         /** @todo Investigate this later. */
    2804                         break;
    2805                     case X86_XCPT_DE:
    2806                         STAM_COUNTER_INC(&pVCpu->hm.s.StatExitGuestDE);
    2807                         break;
    2808                     case X86_XCPT_UD:
    2809                         STAM_COUNTER_INC(&pVCpu->hm.s.StatExitGuestUD);
    2810                         break;
    2811                     case X86_XCPT_SS:
    2812                         Event.n.u1ErrorCodeValid    = 1;
    2813                         Event.n.u32ErrorCode        = pVmcb->ctrl.u64ExitInfo1;
    2814                         STAM_COUNTER_INC(&pVCpu->hm.s.StatExitGuestSS);
    2815                         break;
    2816                     case X86_XCPT_NP:
    2817                         Event.n.u1ErrorCodeValid    = 1;
    2818                         Event.n.u32ErrorCode        = pVmcb->ctrl.u64ExitInfo1;
    2819                         STAM_COUNTER_INC(&pVCpu->hm.s.StatExitGuestNP);
    2820                         break;
     2857                    SVMEVENT Event;
     2858                    Event.u          = 0;
     2859                    Event.n.u1Valid  = 1;
     2860                    Event.n.u3Type   = SVM_EVENT_EXCEPTION;
     2861                    Event.n.u8Vector = pSvmTransient->u64ExitCode - SVM_EXIT_EXCEPTION_0;
     2862
     2863                    switch (Event.n.u8Vector)
     2864                    {
     2865                        case X86_XCPT_GP:
     2866                            Event.n.u1ErrorCodeValid    = 1;
     2867                            Event.n.u32ErrorCode        = pVmcb->ctrl.u64ExitInfo1;
     2868                            STAM_COUNTER_INC(&pVCpu->hm.s.StatExitGuestGP);
     2869                            break;
     2870                        case X86_XCPT_BP:
     2871                            /** Saves the wrong EIP on the stack (pointing to the int3) instead of the
     2872                             *  next instruction. */
     2873                            /** @todo Investigate this later. */
     2874                            break;
     2875                        case X86_XCPT_DE:
     2876                            STAM_COUNTER_INC(&pVCpu->hm.s.StatExitGuestDE);
     2877                            break;
     2878                        case X86_XCPT_UD:
     2879                            STAM_COUNTER_INC(&pVCpu->hm.s.StatExitGuestUD);
     2880                            break;
     2881                        case X86_XCPT_SS:
     2882                            Event.n.u1ErrorCodeValid    = 1;
     2883                            Event.n.u32ErrorCode        = pVmcb->ctrl.u64ExitInfo1;
     2884                            STAM_COUNTER_INC(&pVCpu->hm.s.StatExitGuestSS);
     2885                            break;
     2886                        case X86_XCPT_NP:
     2887                            Event.n.u1ErrorCodeValid    = 1;
     2888                            Event.n.u32ErrorCode        = pVmcb->ctrl.u64ExitInfo1;
     2889                            STAM_COUNTER_INC(&pVCpu->hm.s.StatExitGuestNP);
     2890                            break;
     2891                    }
     2892                    Log4(("#Xcpt: Vector=%#x at CS:RIP=%04x:%RGv\n", Event.n.u8Vector, pCtx->cs.Sel, (RTGCPTR)pCtx->rip));
     2893                    hmR0SvmSetPendingEvent(pVCpu, &Event, 0 /* GCPtrFaultAddress */);
     2894                    return VINF_SUCCESS;
    28212895                }
    2822                 Log4(("#Xcpt: Vector=%#x at CS:RIP=%04x:%RGv\n", Event.n.u8Vector, pCtx->cs.Sel, (RTGCPTR)pCtx->rip));
    2823                 hmR0SvmSetPendingEvent(pVCpu, &Event, 0 /* GCPtrFaultAddress */);
    2824                 return VINF_SUCCESS;
    2825             }
    2826 #endif
    2827 
    2828             default:
    2829             {
    2830                 AssertMsgFailed(("hmR0SvmHandleExit: Unexpected exit code %#x\n", u32ExitCode));
    2831                 return VERR_SVM_UNEXPECTED_EXIT;
     2896#endif  /* HMSVM_ALWAYS_TRAP_ALL_XCPTS */
     2897
     2898                default:
     2899                {
     2900                    AssertMsgFailed(("hmR0SvmHandleExit: Unexpected exit code %#x\n", u32ExitCode));
     2901                    return VERR_SVM_UNEXPECTED_EXIT;
     2902                }
    28322903            }
    28332904        }
     
    28612932                if (VMMR0IsLogFlushDisabled(pVCpu)) \
    28622933                    HMSVM_ASSERT_PREEMPT_CPUID(); \
    2863                 HMSVM_STOP_EXIT_DISPATCH_PROF(); \
    28642934            } while (0)
    28652935#else   /* Release builds */
     
    28922962
    28932963        GCPtrPage = Param1.val.val64;
    2894         rc = EMInterpretInvlpg(pVCpu->CTX_SUFF(pVM), pVCpu,  pRegFrame, GCPtrPage);
     2964        VBOXSTRICTRC rc2 = EMInterpretInvlpg(pVCpu->CTX_SUFF(pVM), pVCpu,  pRegFrame, GCPtrPage);
     2965        rc = VBOXSTRICTRC_VAL(rc2);
    28952966    }
    28962967    else
     
    29513022    Event.n.u3Type   = SVM_EVENT_EXCEPTION;
    29523023    Event.n.u8Vector = X86_XCPT_UD;
    2953     hmR0SvmSetPendingEvent(pVCpu, &Event);
     3024    hmR0SvmSetPendingEvent(pVCpu, &Event, 0 /* GCPtrFaultAddress */);
    29543025}
    29553026
     
    29673038    Event.n.u3Type   = SVM_EVENT_EXCEPTION;
    29683039    Event.n.u8Vector = X86_XCPT_DB;
    2969     hmR0SvmSetPendingEvent(pVCpu, &Event);
     3040    hmR0SvmSetPendingEvent(pVCpu, &Event, 0 /* GCPtrFaultAddress */);
    29703041}
    29713042
     
    29943065    pCtx->cr2 = uFaultAddress;
    29953066
    2996     hmR0SvmSetPendingEvent(pVCpu, &Event);
     3067    hmR0SvmSetPendingEvent(pVCpu, &Event, uFaultAddress);
    29973068}
    29983069
     
    30113082    Event.n.u3Type   = SVM_EVENT_EXCEPTION;
    30123083    Event.n.u8Vector = X86_XCPT_NM;
    3013     hmR0SvmSetPendingEvent(pVCpu, &Event);
     3084    hmR0SvmSetPendingEvent(pVCpu, &Event, 0 /* GCPtrFaultAddress */);
    30143085}
    30153086
     
    30273098    Event.n.u3Type   = SVM_EVENT_EXCEPTION;
    30283099    Event.n.u8Vector = X86_XCPT_MF;
    3029     hmR0SvmSetPendingEvent(pVCpu, &Event);
     3100    hmR0SvmSetPendingEvent(pVCpu, &Event, 0 /* GCPtrFaultAddress */);
    30303101}
    30313102
     
    30453116    Event.n.u1ErrorCodeValid = 1;
    30463117    Event.n.u32ErrorCode     = 0;
    3047     hmR0SvmSetPendingEvent(pVCpu, &Event);
     3118    hmR0SvmSetPendingEvent(pVCpu, &Event, 0 /* GCPtrFaultAddress */);
    30483119}
    30493120
     
    31653236    if (pVmcb->ctrl.ExitIntInfo.n.u1Valid)
    31663237    {
     3238        uint8_t uIdtVector  = pVmcb->ctrl.ExitIntInfo.n.u8Vector;
     3239        uint8_t uExitVector = UINT8_MAX;       /* Start off with an invalid vector, updated when it's valid. See below. */
     3240
     3241        typedef enum
     3242        {
     3243            SVMREFLECTXCPT_XCPT,    /* Reflect the exception to the guest or for further evaluation by VMM. */
     3244            SVMREFLECTXCPT_DF,      /* Reflect the exception as a double-fault to the guest. */
     3245            SVMREFLECTXCPT_TF,      /* Indicate a triple faulted state to the VMM. */
     3246            SVMREFLECTXCPT_NONE     /* Nothing to reflect. */
     3247        } SVMREFLECTXCPT;
     3248
     3249        SVMREFLECTXCPT enmReflect = SVMREFLECTXCPT_NONE;
    31673250        if (pVmcb->ctrl.ExitIntInfo.n.u3Type == SVM_EVENT_EXCEPTION)
    31683251        {
    3169             typedef enum
    3170             {
    3171                 SVMREFLECTXCPT_XCPT,    /* Reflect the exception to the guest or for further evaluation by VMM. */
    3172                 SVMREFLECTXCPT_DF,      /* Reflect the exception as a double-fault to the guest. */
    3173                 SVMREFLECTXCPT_TF,      /* Indicate a triple faulted state to the VMM. */
    3174                 SVMREFLECTXCPT_NONE     /* Nothing to reflect. */
    3175             } SVMREFLECTXCPT;
    3176 
    3177             SVMREFLECTXCPT enmReflect = SVMREFLECTXCPT_NONE;
    3178 
    31793252            if (pSvmTransient->u64ExitCode - SVM_EXIT_EXCEPTION_0 <= SVM_EXIT_EXCEPTION_1F)
    31803253            {
    3181                 uint8_t uExitVector = (uint8_t)(pSvmTransient->u64ExitCode - SVM_EXIT_EXCEPTION_0);
    3182                 uint8_t uIdtVector  = pVmcb->ctrl.ExitIntInfo.n.u8Vector;
    3183 
     3254                uExitVector = (uint8_t)(pSvmTransient->u64ExitCode - SVM_EXIT_EXCEPTION_0);
    31843255                if (   uExitVector == X86_XCPT_PF
    31853256                    && uIdtVector  == X86_XCPT_PF)
     
    31943265               {
    31953266                   enmReflect = SVMREFLECTXCPT_DF;
    3196                }
     3267                   Log4(("IDT: Pending vectoring #DF %#RX64 uExitVector=%#x\n", pVCpu->hm.s.Event.u64IntrInfo, uExitVector));
     3268                }
    31973269               else if (uIdtVector == X86_XCPT_DF)
    31983270                   enmReflect = SVMREFLECTXCPT_TF;
     
    33283400    HMSVM_VALIDATE_EXIT_HANDLER_PARAMS();
    33293401    PVM pVM = pVCpu->CTX_SUFF(pVM);
    3330     rc = EMInterpretRdtsc(pVM, pVCpu, CPUMCTX2CORE(pCtx));
     3402    int rc = EMInterpretRdtsc(pVM, pVCpu, CPUMCTX2CORE(pCtx));
    33313403    if (RT_LIKELY(rc == VINF_SUCCESS))
    33323404        pCtx->rip += 2;     /* Hardcoded opcode, AMD-V doesn't give us this information. */
     
    33473419{
    33483420    HMSVM_VALIDATE_EXIT_HANDLER_PARAMS();
    3349     int rc = EMInterpretRdtscp(pVM, pVCpu, pCtx);
     3421    int rc = EMInterpretRdtscp(pVCpu->CTX_SUFF(pVM), pVCpu, pCtx);
    33503422    if (RT_LIKELY(rc == VINF_SUCCESS))
    33513423        pCtx->rip += 3;     /* Hardcoded opcode, AMD-V doesn't give us this information. */
     
    33663438{
    33673439    HMSVM_VALIDATE_EXIT_HANDLER_PARAMS();
    3368     int rc = EMInterpretRdpmc(pVM, pVCpu, CPUMCTX2CORE(pCtx));
     3440    int rc = EMInterpretRdpmc(pVCpu->CTX_SUFF(pVM), pVCpu, CPUMCTX2CORE(pCtx));
    33693441    if (RT_LIKELY(rc == VINF_SUCCESS))
    33703442        pCtx->rip += 2;     /* Hardcoded opcode, AMD-V doesn't give us this information. */
     
    33853457{
    33863458    HMSVM_VALIDATE_EXIT_HANDLER_PARAMS();
     3459    PVM pVM = pVCpu->CTX_SUFF(pVM);
    33873460    Assert(!pVM->hm.s.fNestedPaging);
    33883461
     
    34143487{
    34153488    HMSVM_VALIDATE_EXIT_HANDLER_PARAMS();
    3416     int rc = EMInterpretMonitor(pVM, pVCpu, CPUMCTX2CORE(pCtx));
     3489    int rc = EMInterpretMonitor(pVCpu->CTX_SUFF(pVM), pVCpu, CPUMCTX2CORE(pCtx));
    34173490    if (RT_LIKELY(rc == VINF_SUCCESS))
    34183491        pCtx->rip += 3;     /* Hardcoded opcode, AMD-V doesn't give us this information. */
     
    34333506{
    34343507    HMSVM_VALIDATE_EXIT_HANDLER_PARAMS();
    3435     int rc = EMInterpretMWait(pVM, pVCpu, CPUMCTX2CORE(pCtx));
     3508    VBOXSTRICTRC rc2 = EMInterpretMWait(pVCpu->CTX_SUFF(pVM), pVCpu, CPUMCTX2CORE(pCtx));
     3509    int rc = VBOXSTRICTRC_VAL(rc2);
    34363510    if (    rc == VINF_EM_HALT
    34373511        ||  rc == VINF_SUCCESS)
     
    34753549    HMSVM_VALIDATE_EXIT_HANDLER_PARAMS();
    34763550    /** @todo Decode Assist. */
    3477     int rc = EMInterpretInstruction(pVCpu, CPUMCTX2CORE(pCtx), 0 /* pvFault */);
     3551    VBOXSTRICTRC rc2 = EMInterpretInstruction(pVCpu, CPUMCTX2CORE(pCtx), 0 /* pvFault */);
     3552    int rc = VBOXSTRICTRC_VAL(rc2);
    34783553    Assert(rc == VERR_EM_INTERPRETER || rc == VINF_PGM_CHANGE_MODE || rc == VINF_PGM_SYNC_CR3);
    34793554    Assert((pSvmTransient->u64ExitCode - SVM_EXIT_READ_CR0) <= 15);
     
    34903565    HMSVM_VALIDATE_EXIT_HANDLER_PARAMS();
    34913566    /** @todo Decode Assist. */
    3492     int rc = EMInterpretInstruction(pVCpu, CPUMCTX2CORE(pCtx), 0 /* pvFault */);
    3493     if (rc == VINF_SUCCCES)
     3567    VBOXSTRICTRC rc2 = EMInterpretInstruction(pVCpu, CPUMCTX2CORE(pCtx), 0 /* pvFault */);
     3568    int rc = VBOXSTRICTRC_VAL(rc2);
     3569    if (rc == VINF_SUCCESS)
    34943570    {
    34953571        /* RIP has been updated by EMInterpretInstruction(). */
     
    35023578
    35033579            case 3:     /* CR3. */
    3504                 Assert(!pVM->hm.s.fNestedPaging);
     3580                Assert(!pVCpu->CTX_SUFF(pVM)->hm.s.fNestedPaging);
    35053581                pVCpu->hm.s.fContextUseFlags |= HM_CHANGED_GUEST_CR3;
    35063582                break;
     
    35153591
    35163592            default:
    3517                 AsserMsgFailed(("hmR0SvmExitWriteCRx: Invalid/Unexpected Write-CRx exit. u64ExitCode=%#RX64 %#x CRx=%#RX64\n",
     3593                AssertMsgFailed(("hmR0SvmExitWriteCRx: Invalid/Unexpected Write-CRx exit. u64ExitCode=%#RX64 %#x CRx=%#RX64\n",
    35183594                                pSvmTransient->u64ExitCode, pSvmTransient->u64ExitCode - SVM_EXIT_WRITE_CR0));
    35193595                break;
     
    35333609{
    35343610    HMSVM_VALIDATE_EXIT_HANDLER_PARAMS();
    3535     return hmR0SvmSetPendingXcptUD(pVCpu);
     3611    hmR0SvmSetPendingXcptUD(pVCpu);
     3612    return VINF_SUCCESS;
    35363613}
    35373614
     
    35443621    HMSVM_VALIDATE_EXIT_HANDLER_PARAMS();
    35453622    PSVMVMCB pVmcb = (PSVMVMCB)pVCpu->hm.s.svm.pvVmcb;
     3623    PVM      pVM   = pVCpu->CTX_SUFF(pVM);
    35463624
    35473625    int rc;
     
    35643642        }
    35653643
    3566         rc = EMInterpretWrmsr(pVCpu->CTX_SUFF(pVM), pVCpu, CPUMCTX2CORE(pCtx));
     3644        rc = EMInterpretWrmsr(pVM, pVCpu, CPUMCTX2CORE(pCtx));
    35673645        AssertMsg(rc == VINF_SUCCESS || rc == VERR_EM_INTERPRETER, ("hmR0SvmExitMsr: EMInterpretWrmsr failed rc=%Rrc\n", rc));
    35683646
     
    35743652        /* MSR Read access. */
    35753653        STAM_COUNTER_INC(&pVCpu->hm.s.StatExitRdmsr);
    3576         int rc = EMInterpretRdmsr(pVCpu->CTX_SUFF(pVM), pVCpu, CPUMCTX2CORE(pCtx));
     3654        rc = EMInterpretRdmsr(pVM, pVCpu, CPUMCTX2CORE(pCtx));
    35773655        AssertMsg(rc == VINF_SUCCESS || rc == VERR_EM_INTERPRETER, ("hmR0SvmExitMsr: EMInterpretRdmsr failed rc=%Rrc\n", rc));
    35783656    }
     
    36093687        /* Save the host & load the guest debug state, restart execution of the MOV DRx instruction. */
    36103688        PVM pVM = pVCpu->CTX_SUFF(pVM);
    3611         rc = CPUMR0LoadGuestDebugState(pVM, pVCpu, pCtx, true /* include DR6 */);
     3689        int rc = CPUMR0LoadGuestDebugState(pVM, pVCpu, pCtx, true /* include DR6 */);
    36123690        AssertRC(rc);
    36133691        Assert(CPUMIsGuestDebugStateActive(pVCpu));
    36143692
    36153693        STAM_COUNTER_INC(&pVCpu->hm.s.StatDRxContextSwitch);
    3616         return VINF_SUCCESS;
     3694        return rc;
    36173695    }
    36183696
    36193697    /** @todo Decode assist.  */
    3620     int rc = EMInterpretInstruction(pVCpu, CPUMCTX2CORE(pCtx), 0 /* pvFault */);
     3698    VBOXSTRICTRC rc2 = EMInterpretInstruction(pVCpu, CPUMCTX2CORE(pCtx), 0 /* pvFault */);
     3699    int rc = VBOXSTRICTRC_VAL(rc2);
    36213700    if (RT_LIKELY(rc == VINF_SUCCESS))
    36223701    {
     
    36253704    }
    36263705    else
    3627         Assert(c == VERR_EM_INTERPRETER);
     3706        Assert(rc == VERR_EM_INTERPRETER);
    36283707    return rc;
    36293708}
     
    36563735                                                                                            the result (in AL/AX/EAX). */
    36573736
     3737    PSVMVMCB pVmcb = (PSVMVMCB)pVCpu->hm.s.svm.pvVmcb;
     3738    PVM      pVM   = pVCpu->CTX_SUFF(pVM);
     3739
    36583740    /* Refer AMD spec. 15.10.2 "IN and OUT Behaviour" and Figure 15-2. "EXITINFO1 for IOIO Intercept" for the format. */
    36593741    SVMIOIOEXIT IoExitInfo;
     
    36833765            if (IoExitInfo.n.u1Type == 0)   /* OUT */
    36843766            {
    3685                 rc = IOMInterpretOUTSEx(pVM, pVCpu, CPUMCTX2CORE(pCtx), IoExitInfo.n.u16Port, pDis->fPrefix,
    3686                                         (DISCPUMODE)pDis->uAddrMode, uIOSize);
     3767                VBOXSTRICTRC rc2 = IOMInterpretOUTSEx(pVM, pVCpu, CPUMCTX2CORE(pCtx), IoExitInfo.n.u16Port, pDis->fPrefix,
     3768                                                      (DISCPUMODE)pDis->uAddrMode, uIOSize);
     3769                rc = VBOXSTRICTRC_VAL(rc2);
    36873770                STAM_COUNTER_INC(&pVCpu->hm.s.StatExitIOStringWrite);
    36883771            }
    36893772            else
    36903773            {
    3691                 rc = IOMInterpretINSEx(pVM, pVCpu, CPUMCTX2CORE(pCtx), IoExitInfo.n.u16Port, pDis->fPrefix,
    3692                                        (DISCPUMODE)pDis->uAddrMode, uIOSize);
     3774                VBOXSTRICTRC rc2 = IOMInterpretINSEx(pVM, pVCpu, CPUMCTX2CORE(pCtx), IoExitInfo.n.u16Port, pDis->fPrefix,
     3775                                                     (DISCPUMODE)pDis->uAddrMode, uIOSize);
     3776                rc = VBOXSTRICTRC_VAL(rc2);
    36933777                STAM_COUNTER_INC(&pVCpu->hm.s.StatExitIOStringRead);
    36943778            }
     
    37043788        if (IoExitInfo.n.u1Type == 0)   /* OUT */
    37053789        {
    3706             rc = IOMIOPortWrite(pVM, pVCpu, IoExitInfo.n.u16Port, pCtx->eax & uAndVal, uIOSize);
     3790            VBOXSTRICTRC rc2 = IOMIOPortWrite(pVM, pVCpu, IoExitInfo.n.u16Port, pCtx->eax & uAndVal, uIOSize);
     3791            rc = VBOXSTRICTRC_VAL(rc2);
    37073792            if (rc == VINF_IOM_R3_IOPORT_WRITE)
    37083793                HMR0SavePendingIOPortWrite(pVCpu, pCtx->rip, pVmcb->ctrl.u64ExitInfo2, IoExitInfo.n.u16Port, uAndVal, uIOSize);
     
    37143799            uint32_t u32Val = 0;
    37153800
    3716             rc = IOMIOPortRead(pVM, pVCpu, IoExitInfo.n.u16Port, &u32Val, uIOSize);
     3801            VBOXSTRICTRC rc2 = IOMIOPortRead(pVM, pVCpu, IoExitInfo.n.u16Port, &u32Val, uIOSize);
     3802            rc = VBOXSTRICTRC_VAL(rc2);
    37173803            if (IOM_SUCCESS(rc))
    37183804            {
     
    38383924            PHMTPRPATCH pPatch = (PHMTPRPATCH)RTAvloU32Get(&pVM->hm.s.PatchTree, (AVLOU32KEY)pCtx->eip);
    38393925            if (!pPatch)
    3840             {
    3841                 rc = VINF_EM_HM_PATCH_TPR_INSTR;
    3842                 return rc;
    3843             }
     3926                return VINF_EM_HM_PATCH_TPR_INSTR;
    38443927        }
    38453928    }
     
    38643947    if ((u32ErrCode & (X86_TRAP_PF_RSVD | X86_TRAP_PF_P)) == (X86_TRAP_PF_RSVD | X86_TRAP_PF_P))
    38653948    {
    3866         rc = PGMR0Trap0eHandlerNPMisconfig(pVM, pVCpu, enmNestedPagingMode, CPUMCTX2CORE(pCtx), GCPhysFaultAddr, u32ErrCode);
     3949        VBOXSTRICTRC rc2 = PGMR0Trap0eHandlerNPMisconfig(pVM, pVCpu, enmNestedPagingMode, CPUMCTX2CORE(pCtx), GCPhysFaultAddr,
     3950                                                         u32ErrCode);
     3951        rc = VBOXSTRICTRC_VAL(rc2);
    38673952
    38683953        /*
     
    39133998    HMSVM_VALIDATE_EXIT_HANDLER_PARAMS();
    39143999
     4000    PSVMVMCB pVmcb = (PSVMVMCB)pVCpu->hm.s.svm.pvVmcb;
    39154001    pVmcb->ctrl.IntCtrl.n.u1VIrqValid  = 0;  /* No virtual interrupts pending, we'll inject the current one before reentry. */
    39164002    pVmcb->ctrl.IntCtrl.n.u8VIrqVector = 0;
     
    39204006    pVmcb->ctrl.u64VmcbCleanBits &= ~(HMSVM_VMCB_CLEAN_INTERCEPTS | HMSVM_VMCB_CLEAN_TPR);
    39214007
    3922     /* Deliver the pending interrupt via hmR0SvmPreRunGuest()->hmR0SvmInjectEvent() and resume guest execution. */
     4008    /* Deliver the pending interrupt via hmR0SvmPreRunGuest()->hmR0SvmInjectEventVmcb() and resume guest execution. */
    39234009    STAM_COUNTER_INC(&pVCpu->hm.s.StatExitIntWindow);
    39244010    return VINF_SUCCESS;
     
    39684054    HMSVM_VALIDATE_EXIT_HANDLER_PARAMS();
    39694055
    3970     int rc = hmR0SvmEmulateMovTpr(pVM, pVCpu, pCtx);
     4056    int rc = hmR0SvmEmulateMovTpr(pVCpu->CTX_SUFF(pVM), pVCpu, pCtx);
    39714057    if (RT_UNLIKELY(rc != VINF_SUCCESS))
    39724058        hmR0SvmSetPendingXcptUD(pVCpu);
     
    40114097#endif
    40124098
     4099    PVM pVM = pVCpu->CTX_SUFF(pVM);
    40134100    Assert(!pVM->hm.s.fNestedPaging);
    40144101
     
    40284115        /* Check if the page at the fault-address is the APIC base. */
    40294116        RTGCPHYS GCPhysPage;
    4030         rc = PGMGstGetPage(pVCpu, (RTGCPTR)uFaultAddress, NULL /* pfFlags */, &GCPhysPage);
    4031         if (   rc == VINF_SUCCESS
    4032             && GCPhys == GCPhysApicBase)
     4117        int rc2 = PGMGstGetPage(pVCpu, (RTGCPTR)uFaultAddress, NULL /* pfFlags */, &GCPhysPage);
     4118        if (   rc2 == VINF_SUCCESS
     4119            && GCPhysPage == GCPhysApicBase)
    40334120        {
    40344121            /* Only attempt to patch the instruction once. */
     
    40444131
    40454132    TRPMAssertXcptPF(pVCpu, uFaultAddress, u32ErrCode);
    4046     rc = PGMTrap0eHandler(pVCpu, errCode, CPUMCTX2CORE(pCtx), (RTGCPTR)uFaultAddress);
     4133    int rc = PGMTrap0eHandler(pVCpu, u32ErrCode, CPUMCTX2CORE(pCtx), (RTGCPTR)uFaultAddress);
    40474134
    40484135    Log2(("#PF rc=%Rrc\n", rc));
     
    40984185
    40994186    /* Lazy FPU loading; load the guest-FPU state transparently and continue execution of the guest. */
    4100     PVM pVM = pVCpu->CTX_SUFF(pVM);
    4101     rc = CPUMR0LoadGuestFPU(pVM, pVCpu, pCtx);
     4187    int rc = CPUMR0LoadGuestFPU(pVCpu->CTX_SUFF(pVM), pVCpu, pCtx);
    41024188    if (rc == VINF_SUCCESS)
    41034189    {
     
    41254211    HMSVM_CHECK_EXIT_DUE_TO_EVENT_DELIVERY();
    41264212
     4213    int rc;
    41274214    if (!(pCtx->cr0 & X86_CR0_NE))
    41284215    {
     
    41404227}
    41414228
     4229
     4230/**
     4231 * #VMEXIT handler for debug exception (SVM_EXIT_DB). Conditional #VMEXIT.
     4232 */
     4233HMSVM_EXIT_DECL hmR0SvmExitXcptDB(PVMCPU pVCpu, PCPUMCTX pCtx, PSVMTRANSIENT pSvmTransient)
     4234{
     4235    HMSVM_VALIDATE_EXIT_HANDLER_PARAMS();
     4236
     4237    HMSVM_CHECK_EXIT_DUE_TO_EVENT_DELIVERY();
     4238
     4239    /* -XXX- todo!!*/
     4240    return VERR_NOT_IMPLEMENTED;
     4241}
     4242
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette