VirtualBox

Changeset 74488 in vbox


Ignore:
Timestamp:
Sep 27, 2018 6:04:58 AM (6 years ago)
Author:
vboxsync
Message:

VMM/CPUM: Nested SVM, VMX: bugref:7243 bugref:9180 Initialize and re-initialize VMX and SVM hwvirt state. Esp. important for VMX
where the guest-physical addresses need to be NIL_RTGCPHYS as VMX instruction rely on it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/CPUM.cpp

    r74486 r74488  
    902902
    903903/**
     904 * Initializes (or re-initializes) per-VCPU SVM hardware virtualization state.
     905 *
     906 * @param   pVCpu   The cross context virtual CPU structure.
     907 */
     908DECLINLINE(void) cpumR3InitSvmHwVirtState(PVMCPU pVCpu)
     909{
     910    PCPUMCTX pCtx = &pVCpu->cpum.s.Guest;
     911    Assert(pCtx->hwvirt.enmHwvirt == CPUMHWVIRT_SVM);
     912    Assert(pCtx->hwvirt.svm.CTX_SUFF(pVmcb));
     913
     914    memset(pCtx->hwvirt.svm.CTX_SUFF(pVmcb), 0, SVM_VMCB_PAGES << PAGE_SHIFT);
     915    pCtx->hwvirt.svm.uMsrHSavePa    = 0;
     916    pCtx->hwvirt.svm.uPrevPauseTick = 0;
     917}
     918
     919
     920/**
    904921 * Frees memory allocated for the VMX hardware virtualization state.
    905922 *
     
    10361053
    10371054    return rc;
     1055}
     1056
     1057
     1058/**
     1059 * Initializes (or re-initializes) per-VCPU VMX hardware virtualization state.
     1060 *
     1061 * @param   pVCpu   The cross context virtual CPU structure.
     1062 */
     1063DECLINLINE(void) cpumR3InitVmxHwVirtState(PVMCPU pVCpu)
     1064{
     1065    PCPUMCTX pCtx = &pVCpu->cpum.s.Guest;
     1066    Assert(pCtx->hwvirt.enmHwvirt == CPUMHWVIRT_VMX);
     1067    Assert(pCtx->hwvirt.vmx.CTX_SUFF(pVmcs));
     1068    Assert(pCtx->hwvirt.vmx.CTX_SUFF(pShadowVmcs));
     1069
     1070    memset(pCtx->hwvirt.vmx.CTX_SUFF(pVmcs),       0, VMX_V_VMCS_SIZE);
     1071    memset(pCtx->hwvirt.vmx.CTX_SUFF(pShadowVmcs), 0, VMX_V_VMCS_SIZE);
     1072    pCtx->hwvirt.vmx.GCPhysVmxon       = NIL_RTGCPHYS;
     1073    pCtx->hwvirt.vmx.GCPhysShadowVmcs  = NIL_RTGCPHYS;
     1074    pCtx->hwvirt.vmx.GCPhysVmxon       = NIL_RTGCPHYS;
     1075    pCtx->hwvirt.vmx.fInVmxRootMode    = false;
     1076    pCtx->hwvirt.vmx.fInVmxNonRootMode = false;
     1077    /* Don't reset diagnostics here. */
    10381078}
    10391079
     
    15781618    else if (pVM->cpum.ro.GuestFeatures.fSvm)
    15791619        rc = cpumR3AllocSvmHwVirtState(pVM);
     1620    else
     1621        Assert(pVM->aCpus[0].cpum.s.Guest.hwvirt.enmHwvirt == CPUMHWVIRT_NONE);
    15801622    if (RT_FAILURE(rc))
    15811623        return rc;
     1624
     1625    /*
     1626     * Initialize guest hardware virtualization state.
     1627     */
     1628    CPUMHWVIRT const enmHwvirt = pVM->aCpus[0].cpum.s.Guest.hwvirt.enmHwvirt;
     1629    if (enmHwvirt == CPUMHWVIRT_VMX)
     1630    {
     1631        for (VMCPUID i = 0; i < pVM->cCpus; i++)
     1632            cpumR3InitVmxHwVirtState(&pVM->aCpus[i]);
     1633    }
     1634    else if (enmHwvirt == CPUMHWVIRT_SVM)
     1635    {
     1636        for (VMCPUID i = 0; i < pVM->cCpus; i++)
     1637            cpumR3InitSvmHwVirtState(&pVM->aCpus[i]);
     1638    }
    15821639
    15831640    /*
     
    18161873     */
    18171874    pCtx->hwvirt.fGif = true;
    1818 
    1819     /* SVM. */
    1820     if (pCtx->hwvirt.svm.CTX_SUFF(pVmcb))
    1821     {
    1822         memset(pCtx->hwvirt.svm.CTX_SUFF(pVmcb), 0, SVM_VMCB_PAGES << PAGE_SHIFT);
    1823         pCtx->hwvirt.svm.uMsrHSavePa    = 0;
    1824         pCtx->hwvirt.svm.uPrevPauseTick = 0;
    1825     }
     1875    Assert(!pVM->cpum.ro.GuestFeatures.fVmx || !pVM->cpum.ro.GuestFeatures.fSvm);   /* Paranoia. */
     1876    if (pVM->cpum.ro.GuestFeatures.fVmx)
     1877        cpumR3InitVmxHwVirtState(pVCpu);
     1878    else if (pVM->cpum.ro.GuestFeatures.fSvm)
     1879        cpumR3InitSvmHwVirtState(pVCpu);
    18261880}
    18271881
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