VirtualBox

Changeset 66276 in vbox for trunk/src/VBox/VMM/VMMR3


Ignore:
Timestamp:
Mar 28, 2017 7:14:16 AM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
114200
Message:

VMM: Nested Hw.virt: SVM MSRPM and IOPM allocations.

File:
1 edited

Legend:

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

    r65904 r66276  
    750750
    751751/**
     752 * Frees memory allocated by cpumR3AllocHwVirtState().
     753 *
     754 * @param   pVM     The cross context VM structure.
     755 */
     756static void cpumR3FreeHwVirtState(PVM pVM)
     757{
     758    if (pVM->cpum.ro.GuestFeatures.fSvm)
     759    {
     760        for (VMCPUID i = 0; i < pVM->cCpus; i++)
     761        {
     762            PVMCPU pVCpu = &pVM->aCpus[i];
     763            if (pVCpu->cpum.s.Guest.hwvirt.svm.pvMsrBitmapR3)
     764            {
     765                SUPR3PageFreeEx(pVCpu->cpum.s.Guest.hwvirt.svm.pvMsrBitmapR3, SVM_MSRPM_PAGES);
     766                pVCpu->cpum.s.Guest.hwvirt.svm.pvMsrBitmapR3 = NULL;
     767            }
     768
     769            if (pVCpu->cpum.s.Guest.hwvirt.svm.pvIoBitmapR3)
     770            {
     771                SUPR3PageFreeEx(pVCpu->cpum.s.Guest.hwvirt.svm.pvIoBitmapR3, SVM_IOPM_PAGES);
     772                pVCpu->cpum.s.Guest.hwvirt.svm.pvIoBitmapR3 = NULL;
     773            }
     774        }
     775    }
     776}
     777
     778
     779/**
     780 * Allocates memory required by the hardware virtualization state.
     781 *
     782 * @returns VBox status code.
     783 * @param   pVM     The cross context VM structure.
     784 */
     785static int cpumR3AllocHwVirtState(PVM pVM)
     786{
     787    int rc = VINF_SUCCESS;
     788    if (pVM->cpum.ro.GuestFeatures.fSvm)
     789    {
     790        for (VMCPUID i = 0; i < pVM->cCpus; i++)
     791        {
     792            PVMCPU pVCpu = &pVM->aCpus[i];
     793
     794            /*
     795             * Allocate the MSRPM (MSR Permission bitmap).
     796             */
     797            Assert(!pVCpu->cpum.s.Guest.hwvirt.svm.pvMsrBitmapR3);
     798            rc = SUPR3PageAllocEx(SVM_MSRPM_PAGES, 0 /* fFlags */, &pVCpu->cpum.s.Guest.hwvirt.svm.pvMsrBitmapR3,
     799                                  &pVCpu->cpum.s.Guest.hwvirt.svm.pvMsrBitmapR0, NULL /* paPages */);
     800            if (RT_FAILURE(rc))
     801            {
     802                Assert(!pVCpu->cpum.s.Guest.hwvirt.svm.pvMsrBitmapR3);
     803                LogRel(("CPUM%u: Failed to alloc %u pages for the nested-guest's MSR permission bitmap\n", pVCpu->idCpu,
     804                        SVM_MSRPM_PAGES));
     805                break;
     806            }
     807
     808            /*
     809             * Allocate the IOPM (IO Permission bitmap).
     810             */
     811            Assert(!pVCpu->cpum.s.Guest.hwvirt.svm.pvIoBitmapR3);
     812            rc = SUPR3PageAllocEx(SVM_IOPM_PAGES, 0 /* fFlags */, &pVCpu->cpum.s.Guest.hwvirt.svm.pvIoBitmapR3,
     813                                  &pVCpu->cpum.s.Guest.hwvirt.svm.pvIoBitmapR0, NULL /* paPages */);
     814            if (RT_FAILURE(rc))
     815            {
     816                Assert(!pVCpu->cpum.s.Guest.hwvirt.svm.pvIoBitmapR3);
     817                LogRel(("CPUM%u: Failed to alloc %u pages for the nested-guest's IO permission bitmap\n", pVCpu->idCpu,
     818                        SVM_IOPM_PAGES));
     819                break;
     820            }
     821        }
     822
     823        /* On any failure, cleanup. */
     824        if (RT_FAILURE(rc))
     825            cpumR3FreeHwVirtState(pVM);
     826    }
     827
     828    return rc;
     829}
     830
     831
     832/**
    752833 * Initializes the CPUM.
    753834 *
     
    883964
    884965    /*
    885      * Setup hypervisor startup values.
    886      */
     966     * Allocate memory required by the hardware virtualization state.
     967     */
     968    rc = cpumR3AllocHwVirtState(pVM);
     969    if (RT_FAILURE(rc))
     970        return rc;
    887971
    888972    /*
     
    10051089        pCtx->dr[5]              = 0;
    10061090    }
    1007 #else
    1008     NOREF(pVM);
    10091091#endif
     1092
     1093    cpumR3FreeHwVirtState(pVM);
    10101094    return VINF_SUCCESS;
    10111095}
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