VMMR0.cpp revision 321de479bc1f555103582dbf308df2ec9d271d62
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * VMM - Host Context Ring 0.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Copyright (C) 2006-2007 Oracle Corporation
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * available from http://www.virtualbox.org. This file is free software;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * you can redistribute it and/or modify it under the terms of the GNU
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * General Public License (GPL) as published by the Free Software
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/*******************************************************************************
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync* Header Files *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync*******************************************************************************/
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#if defined(_MSC_VER) && defined(RT_ARCH_AMD64) /** @todo check this with with VC7! */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/*******************************************************************************
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync* Internal Functions *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync*******************************************************************************/
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/*******************************************************************************
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync* Global Variables *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync*******************************************************************************/
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/** Drag in necessary library bits.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * The runtime lives here (in VMMR0.r0) and VBoxDD*R0.r0 links against us. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Initialize the module.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * This is called when we're first loaded.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns 0 on success.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBox status on failure.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Initialize the GVMM, GMM, HWACCM, PGM (Darwin) and INTNET.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* bail out */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Terminate the module.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * This is called when we're finally unloaded.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Terminate the internal network service.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * PGM (Darwin) and HWACCM global cleanup.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Destroy the GMM and GVMM instances.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Initaties the R0 driver for a particular VM instance.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBox status code.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVM The VM instance in question.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param uSvnRev The SVN revision of the ring-3 part.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @thread EMT.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Match the SVN revisions.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogRel(("VMMR0InitVM: Revision mismatch, r3=%d r0=%d\n", uSvnRev, VMMGetSvnRev()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync SUPR0Printf("VMMR0InitVM: Revision mismatch, r3=%d r0=%d\n", uSvnRev, VMMGetSvnRev());
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Register the EMT R0 logger instance for VCPU 0.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync# if 0 /* testing of the logger. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: before %p\n", RTLogDefaultInstance()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: pfnFlush=%p actual=%p\n", pR0Logger->Logger.pfnFlush, vmmR0LoggerFlush));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: pfnLogger=%p actual=%p\n", pR0Logger->Logger.pfnLogger, vmmR0LoggerWrapper));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: offScratch=%d fFlags=%#x fDestFlags=%#x\n", pR0Logger->Logger.offScratch, pR0Logger->Logger.fFlags, pR0Logger->Logger.fDestFlags));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: after %p reg\n", RTLogDefaultInstance()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogSetDefaultInstanceThread(NULL, pVM->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: after %p dereg\n", RTLogDefaultInstance()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pR0Logger->Logger.pfnLogger("hello ring-0 logger\n");
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: returned succesfully from direct logger call.\n"));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: returned succesfully from direct flush call.\n"));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: after %p reg2\n", RTLogDefaultInstance()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pR0Logger->Logger.pfnLogger("hello ring-0 logger\n");
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: returned succesfully from direct logger call (2). offScratch=%d\n", pR0Logger->Logger.offScratch));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogSetDefaultInstanceThread(NULL, pVM->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: after %p dereg2\n", RTLogDefaultInstance()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogLoggerEx(&pR0Logger->Logger, 0, ~0U, "hello ring-0 logger (RTLogLoggerEx)\n");
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: RTLogLoggerEx returned fine offScratch=%d\n", pR0Logger->Logger.offScratch));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogPrintf("hello ring-0 logger (RTLogPrintf)\n");
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: RTLogPrintf returned fine offScratch=%d\n", pR0Logger->Logger.offScratch));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Log(("Switching to per-thread logging instance %p (key=%p)\n", &pR0Logger->Logger, pVM->pSession));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif /* LOG_ENABLED */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Initialize the per VM data for GVMM and GMM.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync// if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync// rc = GMMR0InitPerVMData(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Init HWACCM, CPUM and PGM (Darwin only).
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = CPUMR0Init(pVM); /** @todo rename to CPUMR0InitVM */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* bail out */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogSetDefaultInstanceThread(NULL, (uintptr_t)pVM->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Terminates the R0 driver for a particular VM instance.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * This is normally called by ring-3 as part of the VM termination process, but
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * may alternatively be called during the support driver session cleanup when
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * the VM object is destroyed (see GVMM).
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBox status code.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVM The VM instance in question.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pGVM Pointer to the global VM structure. Optional.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @thread EMT or session clean up thread.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Tell GVMM what we're up to and check that we only do this once.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Deregister the logger.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogSetDefaultInstanceThread(NULL, (uintptr_t)pVM->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Record return code statistics
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVM The VM handle.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVCpu The VMCPU handle.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param rc The status code.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic void vmmR0RecordRC(PVM pVM, PVMCPU pVCpu, int rc)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Collect statistics.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetInterruptHyper);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetRingSwitchInt);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetStaleSelector);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOReadWrite);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOPatchRead);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOPatchWrite);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIOBlockEmulate);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchEmulate);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchIretIRQ);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetRescheduleREM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetTimerPending);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetInterruptPending);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPDMQueueFlush);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMPoolGrow);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMMapChunk);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMAllocHandy);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMCALLRING3_REM_REPLAY_HANDLER_NOTIFICATIONS:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallVMSetError);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallVMSetRuntimeError);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPATMDuplicateFn);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPGMChangeMode);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPGMFlushPending);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPendingRequest);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif /* VBOX_WITH_STATISTICS */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Unused ring-0 entry point that used to be called from the interrupt gate.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Will be removed one of the next times we do a major SUPDrv version bump.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBox status code.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVM The VM to operate on.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param enmOperation Which operation to execute.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pvArg Argument to the operation.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @remarks Assume called with interrupts disabled.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncVMMR0DECL(int) VMMR0EntryInt(PVM pVM, VMMR0OPERATION enmOperation, void *pvArg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * We're returning VERR_NOT_SUPPORT here so we've got something else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * than -1 which the interrupt gate glue code might return.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Log(("operation %#x is not supported\n", enmOperation));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * The Ring 0 entry point, called by the fast-ioctl path.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVM The VM to operate on.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * The return code is stored in pVM->vmm.s.iLastGZRc.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param idCpu The Virtual CPU ID of the calling EMT.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param enmOperation Which operation to execute.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @remarks Assume called with interrupts _enabled_.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncVMMR0DECL(void) VMMR0EntryFast(PVM pVM, VMCPUID idCpu, VMMR0OPERATION enmOperation)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Switch to GC and run guest raw mode code.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Disable interrupts before doing the world switch.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Safety precaution as hwaccm disables the switcher. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pVCpu->vmm.s.iLastGZRc = VERR_RAW_MODE_INVALID_SMP;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pVCpu->vmm.s.iLastGZRc = VERR_PGM_NO_CR3_SHADOW_ROOT;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* We might need to disable VT-x if the active switcher turns off paging. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Re-enable VT-x if previously turned off. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Run guest code using the available hardware acceleration technology.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Disable interrupts before we do anything interesting. On Windows we avoid
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * this by having the support driver raise the IRQL before calling us, this way
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * we hope to get away with page faults and later calling into the kernel.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTTHREADPREEMPTSTATE PreemptState = RTTHREADPREEMPTSTATE_INITIALIZER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Lazy registration of ring 0 loggers. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = vmmR0CallRing3SetJmp(&pVCpu->vmm.s.CallRing3JmpBufR0, HWACCMR0RunGuestCode, pVM, pVCpu); /* this may resume code. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* System is about to go into suspend mode; go back to ring 3. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* No special action required for external interrupts, just return. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * For profiling.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Impossible.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Validates a session or VM session argument.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns true / false accordingly.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVM The VM argument.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pSession The session argument.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncDECLINLINE(bool) vmmR0IsValidSession(PVM pVM, PSUPDRVSESSION pClaimedSession, PSUPDRVSESSION pSession)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* This must be set! */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return false;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Only one out of the two. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return false;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * VMMR0EntryEx worker function, either called directly or when ever possible
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * called thru a longjmp so we can exit safely on failure.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBox status code.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVM The VM to operate on.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param idCpu Virtual CPU ID argument. Must be NIL_VMCPUID if pVM
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * is NIL_RTR0PTR, and may be NIL_VMCPUID if it isn't
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param enmOperation Which operation to execute.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pReqHdr This points to a SUPVMMR0REQHDR packet. Optional.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * The support driver validates this if it's present.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param u64Arg Some simple constant argument.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pSession The session of the caller.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @remarks Assume called with interrupts _enabled_.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic int vmmR0EntryExWorker(PVM pVM, VMCPUID idCpu, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReqHdr, uint64_t u64Arg, PSUPDRVSESSION pSession)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Common VM pointer validation.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync SUPR0Printf("vmmR0EntryExWorker: Invalid pVM=%p! (op=%d)\n", pVM, enmOperation);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_UNLIKELY( pVM->enmVMState < VMSTATE_CREATING
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync SUPR0Printf("vmmR0EntryExWorker: Invalid pVM=%p:{enmVMState=%d, .pVMR0=%p}! (op=%d)\n",
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_UNLIKELY(idCpu >= pVM->cCpus && idCpu != NIL_VMCPUID))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync SUPR0Printf("vmmR0EntryExWorker: Invalid idCpu (%u vs cCpus=%u)\n", idCpu, pVM->cCpus);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync SUPR0Printf("vmmR0EntryExWorker: Invalid idCpu=%u\n", idCpu);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * GVM requests
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GVMMR0CreateVMReq((PGVMMCREATEVMREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GVMMR0SchedWakeUpAndPokeCpusReq(pVM, (PGVMMSCHEDWAKEUPANDPOKECPUSREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GVMMR0QueryStatisticsReq(pVM, (PGVMMQUERYSTATISTICSSREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GVMMR0ResetStatisticsReq(pVM, (PGVMMRESETSTATISTICSSREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Initialize the R0 part of a VM instance.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Terminate the R0 part of a VM instance.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Attempt to enable hwacc mode and check the current setting.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Setup the hardware accelerated session.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Switch to RC to execute Hypervisor function.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Safety precaution as HWACCM can disable the switcher. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* We might need to disable VT-x if the active switcher turns off paging. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Re-enable VT-x if previously turned off. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /** @todo dispatch interrupts? */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * PGM wrappers.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return PGMR0PhysAllocateHandyPages(pVM, &pVM->aCpus[idCpu]);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return PGMR0PhysAllocateLargeHandyPage(pVM, &pVM->aCpus[idCpu]);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * GMM wrappers.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0InitialReservationReq(pVM, idCpu, (PGMMINITIALRESERVATIONREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0UpdateReservationReq(pVM, idCpu, (PGMMUPDATERESERVATIONREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0AllocatePagesReq(pVM, idCpu, (PGMMALLOCATEPAGESREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0FreePagesReq(pVM, idCpu, (PGMMFREEPAGESREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0FreeLargePageReq(pVM, idCpu, (PGMMFREELARGEPAGEREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0QueryHypervisorMemoryStatsReq(pVM, (PGMMMEMSTATSREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0QueryMemoryStatsReq(pVM, idCpu, (PGMMMEMSTATSREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0BalloonedPagesReq(pVM, idCpu, (PGMMBALLOONEDPAGESREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0MapUnmapChunkReq(pVM, idCpu, (PGMMMAPUNMAPCHUNKREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0SeedChunk(pVM, idCpu, (RTR3PTR)u64Arg);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0RegisterSharedModuleReq(pVM, idCpu, (PGMMREGISTERSHAREDMODULEREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0UnregisterSharedModuleReq(pVM, idCpu, (PGMMUNREGISTERSHAREDMODULEREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Select a valid VCPU context. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc = vmmR0CallRing3SetJmp(&pVCpu->vmm.s.CallRing3JmpBufR0, GMMR0CheckSharedModules, pVM, pVCpu); /* this may resume code. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Clear the VCPU context. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * A quick GCFGM mock-up.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /** @todo GCFGM with proper access control, ring-3 management interface and all that. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (pVM || !pReqHdr || u64Arg || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = GVMMR0SetConfig(pReq->pSession, &pReq->szName[0], pReq->u64Value);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync //if (rc == VERR_CFGM_VALUE_NOT_FOUND)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync // rc = GMMR0SetConfig(pReq->pSession, &pReq->szName[0], pReq->u64Value);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = GVMMR0QueryConfig(pReq->pSession, &pReq->szName[0], &pReq->u64Value);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync //if (rc == VERR_CFGM_VALUE_NOT_FOUND)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync // rc = GMMR0QueryConfig(pReq->pSession, &pReq->szName[0], &pReq->u64Value);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * PDM Wrappers.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (!pVM || !pReqHdr || u64Arg || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return PDMR0DriverCallReqHandler(pVM, (PPDMDRIVERCALLREQHANDLERREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Requests to the internal networking service.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg || !pReq || !vmmR0IsValidSession(pVM, pReq->pSession, pSession) || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFCLOSEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return IntNetR0IfCloseReq(pSession, (PINTNETIFCLOSEREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFGETBUFFERPTRSREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return IntNetR0IfGetBufferPtrsReq(pSession, (PINTNETIFGETBUFFERPTRSREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return IntNetR0IfSetPromiscuousModeReq(pSession, (PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETMACADDRESSREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return IntNetR0IfSetMacAddressReq(pSession, (PINTNETIFSETMACADDRESSREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETACTIVEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return IntNetR0IfSetActiveReq(pSession, (PINTNETIFSETACTIVEREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSENDREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return IntNetR0IfSendReq(pSession, (PINTNETIFSENDREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFWAITREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return IntNetR0IfWaitReq(pSession, (PINTNETIFWAITREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * For profiling.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * For testing Ring-0 APIs invoked in this environment.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /** @todo make new test */
return VINF_SUCCESS;
#if HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
return VERR_INVALID_CPU_ID;
return VERR_NOT_SUPPORTED;
typedef struct VMMR0ENTRYEXARGS
VMMR0DECL(int) VMMR0EntryEx(PVM pVM, VMCPUID idCpu, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession)
switch (enmOperation)
case VMMR0_DO_GMM_FREE_PAGES:
case VMMR0_DO_VMMR0_INIT:
case VMMR0_DO_VMMR0_TERM:
#ifdef LOG_ENABLED
# ifdef DEBUG
# ifdef DEBUG
# ifdef RT_ARCH_X86
# ifdef DEBUG
#ifdef LOG_ENABLED
#ifdef LOG_ENABLED
if (pVM)
if (pVCpu)
#ifdef RT_ARCH_X86
#ifdef RT_OS_LINUX
DECLEXPORT(void) RTCALL RTAssertMsg1Weak(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
if (pVM)
return cbChars;
if (pLog)
if (pVM)
RTStrPrintfV(pVM->vmm.s.szRing0AssertMsg2, sizeof(pVM->vmm.s.szRing0AssertMsg2), pszFormat, vaCopy);