VirtualBox

Changeset 47260 in vbox


Ignore:
Timestamp:
Jul 19, 2013 1:58:55 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
87389
Message:

VMM/HMSVMR0: Implement NRIP for instruction intercepts and MSRs. IOIO exits still a todo.

File:
1 edited

Legend:

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

    r47239 r47260  
    35233523
    35243524
     3525/**
     3526 * Advances the guest RIP in the if the NRIP_SAVE feature is supported by the
     3527 * CPU, otherwise advances the RIP by @a cb bytes.
     3528 *
     3529 * @param   pVCpu       Pointer to the VMCPU.
     3530 * @param   pCtx        Pointer to the guest-CPU context.
     3531 * @param   cb          RIP increment value in bytes.
     3532 *
     3533 * @remarks Use this function only from #VMEXIT's where the NRIP value is valid
     3534 *          when NRIP_SAVE is supported by the CPU!
     3535 */
     3536DECLINLINE(void) hmR0SvmUpdateRip(PVMCPU pVCpu, PCPUMCTX pCtx, uint32_t cb)
     3537{
     3538    if (pVCpu->CTX_SUFF(pVM)->hm.s.svm.u32Features & AMD_CPUID_SVM_FEATURE_EDX_NRIP_SAVE)
     3539    {
     3540        PSVMVMCB pVmcb = (PSVMVMCB)pVCpu->hm.s.svm.pvVmcb;
     3541        pCtx->rip = pVmcb->ctrl.u64NextRIP;
     3542    }
     3543    else
     3544        pCtx->rip += cb;
     3545}
     3546
     3547
    35253548/* -=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
    35263549/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #VMEXIT handlers -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
     
    35643587{
    35653588    HMSVM_VALIDATE_EXIT_HANDLER_PARAMS();
    3566     pCtx->rip += 2;         /* Hardcoded opcode, AMD-V doesn't give us this information. */
     3589
     3590    hmR0SvmUpdateRip(pVCpu, pCtx, 2);
    35673591    STAM_COUNTER_INC(&pVCpu->hm.s.StatExitWbinvd);
    35683592    return VINF_SUCCESS;
     
    35763600{
    35773601    HMSVM_VALIDATE_EXIT_HANDLER_PARAMS();
    3578     pCtx->rip += 2;         /* Hardcoded opcode, AMD-V doesn't give us this information. */
     3602
     3603    hmR0SvmUpdateRip(pVCpu, pCtx, 2);
    35793604    STAM_COUNTER_INC(&pVCpu->hm.s.StatExitInvd);
    35803605    return VINF_SUCCESS;
     
    35913616    int rc = EMInterpretCpuId(pVM, pVCpu, CPUMCTX2CORE(pCtx));
    35923617    if (RT_LIKELY(rc == VINF_SUCCESS))
    3593         pCtx->rip += 2;     /* Hardcoded opcode, AMD-V doesn't give us this information. */
     3618        hmR0SvmUpdateRip(pVCpu, pCtx, 2);
    35943619    else
    35953620    {
     
    36123637    if (RT_LIKELY(rc == VINF_SUCCESS))
    36133638    {
    3614         pCtx->rip += 2;     /* Hardcoded opcode, AMD-V doesn't give us this information. */
     3639        hmR0SvmUpdateRip(pVCpu, pCtx, 2);
    36153640        pSvmTransient->fUpdateTscOffsetting = true;
    36163641    }
     
    36343659    if (RT_LIKELY(rc == VINF_SUCCESS))
    36353660    {
    3636         pCtx->rip += 3;     /* Hardcoded opcode, AMD-V doesn't give us this information. */
     3661        hmR0SvmUpdateRip(pVCpu, pCtx, 3);
    36373662        pSvmTransient->fUpdateTscOffsetting = true;
    36383663    }
     
    36553680    int rc = EMInterpretRdpmc(pVCpu->CTX_SUFF(pVM), pVCpu, CPUMCTX2CORE(pCtx));
    36563681    if (RT_LIKELY(rc == VINF_SUCCESS))
    3657         pCtx->rip += 2;     /* Hardcoded opcode, AMD-V doesn't give us this information. */
     3682        hmR0SvmUpdateRip(pVCpu, pCtx, 2);
    36583683    else
    36593684    {
     
    36893714{
    36903715    HMSVM_VALIDATE_EXIT_HANDLER_PARAMS();
    3691     pCtx->rip++;        /* Hardcoded opcode, AMD-V doesn't give us this information. */
     3716    hmR0SvmUpdateRip(pVCpu, pCtx, 1);
    36923717    int rc = EMShouldContinueAfterHalt(pVCpu, pCtx) ? VINF_SUCCESS : VINF_EM_HALT;
    36933718    STAM_COUNTER_INC(&pVCpu->hm.s.StatExitHlt);
     
    37043729    int rc = EMInterpretMonitor(pVCpu->CTX_SUFF(pVM), pVCpu, CPUMCTX2CORE(pCtx));
    37053730    if (RT_LIKELY(rc == VINF_SUCCESS))
    3706         pCtx->rip += 3;     /* Hardcoded opcode, AMD-V doesn't give us this information. */
     3731        hmR0SvmUpdateRip(pVCpu, pCtx, 3);
    37073732    else
    37083733    {
     
    37263751        ||  rc == VINF_SUCCESS)
    37273752    {
    3728         pCtx->rip += 3;     /* Hardcoded opcode, AMD-V doesn't give us this information. */
     3753        hmR0SvmUpdateRip(pVCpu, pCtx, 3);
    37293754
    37303755        if (   rc == VINF_EM_HALT
     
    38423867    PVM      pVM   = pVCpu->CTX_SUFF(pVM);
    38433868
    3844     /** @todo r=ramshankar: This cannot be right if prefixes are involved. When
    3845      *        NRIP_SAVE isn't available we have to disassemble the instruction. */
    38463869    int rc;
    38473870    if (pVmcb->ctrl.u64ExitInfo1 == SVM_EXIT1_MSR_WRITE)
     
    38603883                pVCpu->hm.s.fContextUseFlags |= HM_CHANGED_SVM_GUEST_APIC_STATE;
    38613884            }
    3862             pCtx->rip += 2;     /* Hardcoded opcode, AMD-V doesn't give us this information. */
     3885            hmR0SvmUpdateRip(pVCpu, pCtx, 2);
    38633886            return VINF_SUCCESS;
    38643887        }
    38653888
    3866         rc = EMInterpretWrmsr(pVM, pVCpu, CPUMCTX2CORE(pCtx));
    3867         if (RT_LIKELY(rc == VINF_SUCCESS))
    3868             pCtx->rip += 2;     /* Hardcoded opcode, AMD-V doesn't give us this information. */
     3889        if (pVM->hm.s.svm.u32Features & AMD_CPUID_SVM_FEATURE_EDX_NRIP_SAVE)
     3890        {
     3891            rc = EMInterpretWrmsr(pVM, pVCpu, CPUMCTX2CORE(pCtx));
     3892            if (RT_LIKELY(rc == VINF_SUCCESS))
     3893                pCtx->rip = pVmcb->ctrl.u64NextRIP;
     3894            else
     3895                AssertMsg(rc == VERR_EM_INTERPRETER, ("hmR0SvmExitMsr: EMInterpretWrmsr failed rc=%Rrc\n", rc));
     3896        }
    38693897        else
    3870             AssertMsg(rc == VERR_EM_INTERPRETER, ("hmR0SvmExitMsr: EMInterpretWrmsr failed rc=%Rrc\n", rc));
     3898        {
     3899            VBOXSTRICTRC rcStrict = EMInterpretInstruction(pVCpu, CPUMCTX2CORE(pCtx), 0 /* pvFault */);
     3900            rc = VBOXSTRICTRC_VAL(rcStrict);
     3901            if (RT_UNLIKELY(rc != VINF_SUCCESS))
     3902                AssertMsg(rc == VERR_EM_INTERPRETER, ("hmR0SvmExitMsr: WrMsr. EMInterpretInstruction failed rc=%Rrc\n", rc));
     3903            /* RIP updated by EMInterpretInstruction(). */
     3904        }
    38713905
    38723906        /* If this is an X2APIC WRMSR access, update the APIC state as well. */
     
    38883922        /* MSR Read access. */
    38893923        STAM_COUNTER_INC(&pVCpu->hm.s.StatExitRdmsr);
    3890         rc = EMInterpretRdmsr(pVM, pVCpu, CPUMCTX2CORE(pCtx));
    3891         if (RT_LIKELY(rc == VINF_SUCCESS))
    3892             pCtx->rip += 2;     /* Hardcoded opcode, AMD-V doesn't give us this information. */
     3924        Assert(pVmcb->ctrl.u64ExitInfo1 == SVM_EXIT1_MSR_READ);
     3925
     3926        if (pVM->hm.s.svm.u32Features & AMD_CPUID_SVM_FEATURE_EDX_NRIP_SAVE)
     3927        {
     3928            rc = EMInterpretRdmsr(pVM, pVCpu, CPUMCTX2CORE(pCtx));
     3929            if (RT_LIKELY(rc == VINF_SUCCESS))
     3930                pCtx->rip = pVmcb->ctrl.u64NextRIP;
     3931            else
     3932                AssertMsg(rc == VERR_EM_INTERPRETER, ("hmR0SvmExitMsr: EMInterpretRdmsr failed rc=%Rrc\n", rc));
     3933        }
    38933934        else
    3894             AssertMsg(rc == VERR_EM_INTERPRETER, ("hmR0SvmExitMsr: EMInterpretRdmsr failed rc=%Rrc\n", rc));
     3935        {
     3936            VBOXSTRICTRC rcStrict = EMInterpretInstruction(pVCpu, CPUMCTX2CORE(pCtx), 0);
     3937            rc = VBOXSTRICTRC_VAL(rcStrict);
     3938            if (RT_UNLIKELY(rc != VINF_SUCCESS))
     3939                AssertMsg(rc == VERR_EM_INTERPRETER, ("hmR0SvmExitMsr: RdMsr. EMInterpretInstruction failed rc=%Rrc\n", rc));
     3940            /* RIP updated by EMInterpretInstruction(). */
     3941        }
    38953942    }
    38963943
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