VirtualBox

Changeset 76290 in vbox


Ignore:
Timestamp:
Dec 19, 2018 9:11:47 AM (6 years ago)
Author:
vboxsync
Message:

VMM/HM: Nested VMX: bugref:9180 Added a new pre-init VMM call, invoked from HMR3Init() to copy VMX features to the VM structures earlier than HMR0InitVM does. This way
the VMX features are available at the time of CPUMR3Init.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/hm.h

    r75440 r76290  
    218218VMMR0_INT_DECL(int)             HMR0Init(void);
    219219VMMR0_INT_DECL(int)             HMR0Term(void);
     220VMMR0_INT_DECL(int)             HMR0PreInitVM(PVM pVM);
    220221VMMR0_INT_DECL(int)             HMR0InitVM(PVM pVM);
    221222VMMR0_INT_DECL(int)             HMR0TermVM(PVM pVM);
  • trunk/include/VBox/vmm/vmm.h

    r75646 r76290  
    338338    VMMR0_DO_VMMR0_TERM,
    339339
    340     /** Setup the hardware accelerated raw-mode session. */
     340    /** Setup hardware-assisted VM session. */
    341341    VMMR0_DO_HM_SETUP_VM = 128,
    342     /** Attempt to enable or disable hardware accelerated raw-mode. */
     342    /** Attempt to enable or disable hardware-assisted mode. */
    343343    VMMR0_DO_HM_ENABLE,
     344    /** Pre-initialize hardware-assisted VM session. */
     345    VMMR0_DO_HM_PRE_INIT,
    344346
    345347    /** Call PGMR0PhysAllocateHandyPages(). */
  • trunk/src/VBox/VMM/VMMR0/HMR0.cpp

    r76232 r76290  
    2828#include <VBox/vmm/hm_vmx.h>
    2929#include <VBox/vmm/hm_svm.h>
    30 #include <VBox/vmm/gim.h>
    3130#include <VBox/err.h>
    3231#include <VBox/log.h>
     
    11981197
    11991198/**
    1200  * Does ring-0 per-VM HM initialization.
    1201  *
    1202  * This will copy HM global into the VM structure and call the CPU specific
    1203  * init routine which will allocate resources for each virtual CPU and such.
     1199 * Pre-initializes ring-0 HM per-VM structures.
     1200 *
     1201 * This is the first HM ring-0 function to be called when a VM is created. It is
     1202 * called after VT-x/AMD-V has been detected, and initialized and -after- HM's CFGM
     1203 * settings have been queried.
     1204 *
     1205 * This copies relevant, global HM structures into per-VM data and initializes some
     1206 * per-VCPU data.
    12041207 *
    12051208 * @returns VBox status code.
    12061209 * @param   pVM         The cross context VM structure.
    12071210 *
    1208  * @remarks This is called after HMR3Init(), see vmR3CreateU() and
    1209  *          vmR3InitRing3().
    1210  */
    1211 VMMR0_INT_DECL(int) HMR0InitVM(PVM pVM)
     1211 * @remarks This is called during HMR3Init(). Be really careful what we call here as
     1212 *          almost no VM machinery is up at this point (e.g. PGM, CPUM).
     1213 */
     1214VMMR0_INT_DECL(int) HMR0PreInitVM(PVM pVM)
    12121215{
    12131216    AssertReturn(pVM, VERR_INVALID_PARAMETER);
    1214 
    1215 #ifdef LOG_ENABLED
    1216     SUPR0Printf("HMR0InitVM: %p\n", pVM);
    1217 #endif
    1218 
    1219     /* Make sure we don't touch HM after we've disabled HM in preparation of a suspend. */
    1220     if (ASMAtomicReadBool(&g_HmR0.fSuspended))
    1221         return VERR_HM_SUSPEND_PENDING;
    12221217
    12231218    /*
     
    12641259        pVCpu->hm.s.idEnteredCpu   = NIL_RTCPUID;
    12651260        pVCpu->hm.s.idLastCpu      = NIL_RTCPUID;
    1266         pVCpu->hm.s.fGIMTrapXcptUD = GIMShouldTrapXcptUD(pVCpu);
    12671261
    12681262        /* We'll aways increment this the first time (host uses ASID 0). */
     
    12701264    }
    12711265
     1266    return VINF_SUCCESS;
     1267}
     1268
     1269
     1270/**
     1271 * Does ring-0 per-VM HM initialization.
     1272 *
     1273 * This will call the CPU specific init. routine which may initialize and allocate
     1274 * resources for virtual CPUs.
     1275 *
     1276 * @returns VBox status code.
     1277 * @param   pVM         The cross context VM structure.
     1278 *
     1279 * @remarks This is called after HMR3Init(), see vmR3CreateU() and
     1280 *          vmR3InitRing3().
     1281 */
     1282VMMR0_INT_DECL(int) HMR0InitVM(PVM pVM)
     1283{
     1284    AssertReturn(pVM, VERR_INVALID_PARAMETER);
     1285
     1286    /* Make sure we don't touch HM after we've disabled HM in preparation of a suspend. */
     1287    if (ASMAtomicReadBool(&g_HmR0.fSuspended))
     1288        return VERR_HM_SUSPEND_PENDING;
     1289
     1290    /*
     1291     * Get host kernel features that HM might need to know in order
     1292     * to co-operate and function properly with the host OS (e.g. SMAP).
     1293     *
     1294     * Technically, we could do this as part of the pre-init VM procedure
     1295     * but it shouldn't be done later than this point so we do it here.
     1296     */
    12721297    pVM->hm.s.fHostKernelFeatures = SUPR0GetKernelFeatures();
    12731298
  • trunk/src/VBox/VMM/VMMR0/VMMR0.cpp

    r75830 r76290  
    19301930
    19311931        /*
     1932         * Pre-initialize hardware-assisted mode per-VM data.
     1933         */
     1934        case VMMR0_DO_HM_PRE_INIT:
     1935            rc = HMR0PreInitVM(pVM);
     1936            VMM_CHECK_SMAP_CHECK2(pVM, RT_NOTHING);
     1937            break;
     1938
     1939        /*
    19321940         * Switch to RC to execute Hypervisor function.
    19331941         */
  • trunk/src/VBox/VMM/VMMR3/HM.cpp

    r76198 r76290  
    4646#include <VBox/vmm/pgm.h>
    4747#include <VBox/vmm/ssm.h>
     48#include <VBox/vmm/gim.h>
    4849#include <VBox/vmm/trpm.h>
    4950#include <VBox/vmm/dbgf.h>
     
    400401static DECLCALLBACK(void) hmR3Info(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
    401402static DECLCALLBACK(void) hmR3InfoEventPending(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
    402 static int                hmR3InitCPU(PVM pVM);
     403static int                hmR3InitFinalizeR3(PVM pVM);
    403404static int                hmR3InitFinalizeR0(PVM pVM);
    404405static int                hmR3InitFinalizeR0Intel(PVM pVM);
     
    702703            if (fCaps & SUPVTCAPS_AMD_V)
    703704            {
     705                rc = SUPR3CallVMMR0Ex(pVM->pVMR0, 0 /*idCpu*/, VMMR0_DO_HM_PRE_INIT, 0, NULL);
     706                AssertRCReturn(rc, rc);
     707                Assert(pVM->hm.s.svm.fSupported);
     708
    704709                LogRel(("HM: HMR3Init: AMD-V%s\n", fCaps & SUPVTCAPS_NESTED_PAGING ? " w/ nested paging" : ""));
    705                 pVM->hm.s.svm.fSupported = true;
    706710                VM_SET_MAIN_EXECUTION_ENGINE(pVM, VM_EXEC_ENGINE_HW_VIRT);
    707711            }
     
    712716                if (RT_SUCCESS(rc))
    713717                {
     718                    rc = SUPR3CallVMMR0Ex(pVM->pVMR0, 0 /*idCpu*/, VMMR0_DO_HM_PRE_INIT, 0, NULL);
     719                    AssertRCReturn(rc, rc);
     720                    Assert(pVM->hm.s.vmx.fSupported);
     721
    714722                    LogRel(("HM: HMR3Init: VT-x%s%s%s\n",
    715723                            fCaps & SUPVTCAPS_NESTED_PAGING ? " w/ nested paging" : "",
    716724                            fCaps & SUPVTCAPS_VTX_UNRESTRICTED_GUEST ? " and unrestricted guest execution" : "",
    717725                            (fCaps & (SUPVTCAPS_NESTED_PAGING | SUPVTCAPS_VTX_UNRESTRICTED_GUEST)) ? " hw support" : ""));
    718                     pVM->hm.s.vmx.fSupported = true;
    719726                    VM_SET_MAIN_EXECUTION_ENGINE(pVM, VM_EXEC_ENGINE_HW_VIRT);
    720727                }
     
    844851
    845852/**
    846  * Initializes the per-VCPU HM.
     853 * Initializes HM components after ring-3 phase has been fully initialized.
    847854 *
    848855 * @returns VBox status code.
    849856 * @param   pVM         The cross context VM structure.
    850857 */
    851 static int hmR3InitCPU(PVM pVM)
     858static int hmR3InitFinalizeR3(PVM pVM)
    852859{
    853860    LogFlow(("HMR3InitCPU\n"));
     
    860867        PVMCPU pVCpu = &pVM->aCpus[i];
    861868        pVCpu->hm.s.fActive = false;
     869        pVCpu->hm.s.fGIMTrapXcptUD = GIMShouldTrapXcptUD(pVCpu);    /* Is safe to call now since GIMR3Init() has completed. */
    862870    }
    863871
     
    11801188    {
    11811189        case VMINITCOMPLETED_RING3:
    1182             return hmR3InitCPU(pVM);
     1190            return hmR3InitFinalizeR3(pVM);
    11831191        case VMINITCOMPLETED_RING0:
    11841192            return hmR3InitFinalizeR0(pVM);
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