VirtualBox

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


Ignore:
Timestamp:
Aug 17, 2018 4:34:25 PM (6 years ago)
Author:
vboxsync
Message:

VMM: Nested VMX: bugref:9180 Use GCPhysVmcs to keep track of whether the current VMCS is valid.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/IEMAllCImplVmxInstr.cpp.h

    r73732 r73739  
    452452DECLINLINE(void) iemVmxVmFailValid(PVMCPU pVCpu, VMXINSTRERR enmInsErr)
    453453{
    454     if (pVCpu->cpum.GstCtx.hwvirt.vmx.CTX_SUFF(pVmcs))
     454    if (pVCpu->cpum.GstCtx.hwvirt.vmx.GCPhysVmcs != NIL_RTGCPHYS)
    455455    {
    456456        pVCpu->cpum.GstCtx.eflags.u32 &= ~(X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF);
     
    470470DECLINLINE(void) iemVmxVmFail(PVMCPU pVCpu, VMXINSTRERR enmInsErr)
    471471{
    472     if (pVCpu->cpum.GstCtx.hwvirt.vmx.CTX_SUFF(pVmcs))
     472    if (pVCpu->cpum.GstCtx.hwvirt.vmx.GCPhysVmcs != NIL_RTGCPHYS)
    473473    {
    474474        iemVmxVmFailValid(pVCpu, enmInsErr);
     
    622622         */
    623623        pVCpu->cpum.GstCtx.hwvirt.vmx.GCPhysVmxon    = GCPhysVmxon;
     624        pVCpu->cpum.GstCtx.hwvirt.vmx.GCPhysVmcs     = NIL_RTGCPHYS;
    624625        pVCpu->cpum.GstCtx.hwvirt.vmx.fInVmxRootMode = true;
    625         pVCpu->cpum.GstCtx.hwvirt.vmx.GCPhysVmcs     = NIL_RTGCPHYS;
    626626        /** @todo NSTVMX: clear address-range monitoring. */
    627627        /** @todo NSTVMX: Intel PT. */
  • trunk/src/VBox/VMM/VMMR3/CPUM.cpp

    r73606 r73739  
    810810            SUPR3PageFreeEx(pVCpu->cpum.s.Guest.hwvirt.svm.pVmcbR3, SVM_VMCB_PAGES);
    811811            pVCpu->cpum.s.Guest.hwvirt.svm.pVmcbR3 = NULL;
     812            pVCpu->cpum.s.Guest.hwvirt.svm.pVmcbR0 = NULL;
    812813        }
    813814        pVCpu->cpum.s.Guest.hwvirt.svm.HCPhysVmcb = NIL_RTHCPHYS;
     
    817818            SUPR3PageFreeEx(pVCpu->cpum.s.Guest.hwvirt.svm.pvMsrBitmapR3, SVM_MSRPM_PAGES);
    818819            pVCpu->cpum.s.Guest.hwvirt.svm.pvMsrBitmapR3 = NULL;
     820            pVCpu->cpum.s.Guest.hwvirt.svm.pvMsrBitmapR0 = NULL;
    819821        }
    820822
     
    823825            SUPR3PageFreeEx(pVCpu->cpum.s.Guest.hwvirt.svm.pvIoBitmapR3, SVM_IOPM_PAGES);
    824826            pVCpu->cpum.s.Guest.hwvirt.svm.pvIoBitmapR3 = NULL;
     827            pVCpu->cpum.s.Guest.hwvirt.svm.pvIoBitmapR0 = NULL;
    825828        }
    826829    }
     
    895898    if (RT_FAILURE(rc))
    896899        cpumR3FreeSvmHwVirtState(pVM);
     900
     901    return rc;
     902}
     903
     904
     905/**
     906 * Frees memory allocated for the VMX hardware virtualization state.
     907 *
     908 * @param   pVM     The cross context VM structure.
     909 */
     910static void cpumR3FreeVmxHwVirtState(PVM pVM)
     911{
     912    Assert(pVM->cpum.ro.GuestFeatures.fVmx);
     913    for (VMCPUID i = 0; i < pVM->cCpus; i++)
     914    {
     915        PVMCPU pVCpu = &pVM->aCpus[i];
     916        if (pVCpu->cpum.s.Guest.hwvirt.vmx.pVmcsR3)
     917        {
     918            SUPR3PageFreeEx(pVCpu->cpum.s.Guest.hwvirt.vmx.pVmcsR3, VMX_V_VMCS_PAGES);
     919            pVCpu->cpum.s.Guest.hwvirt.vmx.pVmcsR3 = NULL;
     920            pVCpu->cpum.s.Guest.hwvirt.vmx.pVmcsR0 = NULL;
     921        }
     922    }
     923}
     924
     925
     926/**
     927 * Allocates memory for the VMX hardware virtualization state.
     928 *
     929 * @returns VBox status code.
     930 * @param   pVM     The cross context VM structure.
     931 */
     932static int cpumR3AllocVmxHwVirtState(PVM pVM)
     933{
     934    int rc = VINF_SUCCESS;
     935    LogRel(("CPUM: Allocating %u pages for the nested-guest VMCS\n", pVM->cCpus * VMX_V_VMCS_SIZE));
     936    for (VMCPUID i = 0; i < pVM->cCpus; i++)
     937    {
     938        PVMCPU pVCpu = &pVM->aCpus[i];
     939
     940        /*
     941         * Allocate the nested-guest current VMCS.
     942         */
     943        SUPPAGE SupNstGstVmcsPage;
     944        RT_ZERO(SupNstGstVmcsPage);
     945        SupNstGstVmcsPage.Phys = NIL_RTHCPHYS;
     946        Assert(VMX_V_VMCS_PAGES == 1);
     947        Assert(!pVCpu->cpum.s.Guest.hwvirt.vmx.pVmcsR3);
     948        rc = SUPR3PageAllocEx(VMX_V_VMCS_PAGES, 0 /* fFlags */, (void **)&pVCpu->cpum.s.Guest.hwvirt.vmx.pVmcsR3,
     949                              &pVCpu->cpum.s.Guest.hwvirt.vmx.pVmcsR0, &SupNstGstVmcsPage);
     950        if (RT_FAILURE(rc))
     951        {
     952            Assert(!pVCpu->cpum.s.Guest.hwvirt.vmx.pVmcsR3);
     953            LogRel(("CPUM%u: Failed to alloc %u pages for the nested-guest's VMCS\n", pVCpu->idCpu, VMX_V_VMCS_PAGES));
     954            break;
     955        }
     956    }
     957
     958    /* On any failure, cleanup. */
     959    if (RT_FAILURE(rc))
     960        cpumR3FreeVmxHwVirtState(pVM);
    897961
    898962    return rc;
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