VMMTests.cpp revision e0b9d3c357adf9b7d05f55540e86f22943fc4b23
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * VMM - The Virtual Machine Monitor Core, Tests.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * available from http://www.virtualbox.org. This file is free software;
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * you can redistribute it and/or modify it under the terms of the GNU
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * General Public License (GPL) as published by the Free Software
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * additional information or have any questions.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync//#define NO_SUPCALLR0VMM
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync/*******************************************************************************
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync* Header Files *
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync*******************************************************************************/
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * Performs a testcase.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * @returns return value from the test.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * @param pVM The VM handle.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * @param enmTestcase The testcase operation to perform.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * @param uVariation The testcase variation id.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsyncstatic int vmmR3DoGCTest(PVM pVM, VMMGCOPERATION enmTestcase, unsigned uVariation)
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync int rc = PDMR3LdrGetSymbolRC(pVM, VMMGC_MAIN_MODULE_NAME, "VMMGCEntry", &RCPtrEP);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync memset(pVM->vmm.s.pbEMTStackR3, 0xaa, VMM_STACK_SIZE);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync CPUMSetHyperESP(pVCpu, pVM->vmm.s.pbEMTStackBottomRC); /* Clear the stack. */
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync CPUMPushHyper(pVCpu, 3 * sizeof(RTRCPTR)); /* stack frame size */
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync CPUMSetHyperEIP(pVCpu, pVM->vmm.s.pfnCallTrampolineRC);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync Assert(CPUMGetHyperCR3(pVCpu) && CPUMGetHyperCR3(pVCpu) == PGMGetHyperCR3(pVCpu));
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync rc = SUPCallVMMR0Fast(pVM->pVMR0, VMMR0_DO_RAW_RUN, 0);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * Performs a trap test.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * @returns Return value from the trap test.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * @param pVM The VM handle.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * @param u8Trap The trap number to test.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * @param uVariation The testcase variation.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * @param rcExpect The expected result.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * @param u32Eax The expected eax value.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * @param pszFaultEIP The fault address. Pass NULL if this isn't available or doesn't apply.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * @param pszDesc The test description.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsyncstatic int vmmR3DoTrapTest(PVM pVM, uint8_t u8Trap, unsigned uVariation, int rcExpect, uint32_t u32Eax, const char *pszFaultEIP, const char *pszDesc)
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync RTPrintf("VMM: testing 0%x / %d - %s\n", u8Trap, uVariation, pszDesc);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync int rc = PDMR3LdrGetSymbolRC(pVM, VMMGC_MAIN_MODULE_NAME, "VMMGCEntry", &RCPtrEP);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync memset(pVM->vmm.s.pbEMTStackR3, 0xaa, VMM_STACK_SIZE);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync CPUMSetHyperESP(pVCpu, pVM->vmm.s.pbEMTStackBottomRC); /* Clear the stack. */
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync CPUMPushHyper(pVCpu, u8Trap + VMMGC_DO_TESTCASE_TRAP_FIRST);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync CPUMPushHyper(pVCpu, 3 * sizeof(RTRCPTR)); /* stack frame size */
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync CPUMSetHyperEIP(pVCpu, pVM->vmm.s.pfnCallTrampolineRC);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync Assert(CPUMGetHyperCR3(pVCpu) && CPUMGetHyperCR3(pVCpu) == PGMGetHyperCR3(pVCpu));
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync rc = SUPCallVMMR0Fast(pVM->pVMR0, VMMR0_DO_RAW_RUN, 0);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync bool fDump = false;
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync RTPrintf("VMM: FAILURE - rc=%Rrc expected %Rrc\n", rc, rcExpect);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync && u8Trap != 8 /* double fault doesn't dare set TrapNo. */
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync && u8Trap != 3 /* guest only, we're not in guest. */
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync && u8Trap != 1 /* guest only, we're not in guest. */
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync RTPrintf("VMM: FAILURE - Trap %#x expected %#x\n", TRPMGetTrapNo(pVCpu), u8Trap);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync int rc2 = PDMR3LdrGetSymbolRC(pVM, VMMGC_MAIN_MODULE_NAME, pszFaultEIP, &RCPtrFault);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync RTPrintf("VMM: FAILURE - Failed to resolve symbol '%s', %Rrc!\n", pszFaultEIP, rc);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync RTPrintf("VMM: FAILURE - EIP=%08RX32 expected %RRv (%s)\n", CPUMGetHyperEIP(pVCpu), RCPtrFault, pszFaultEIP);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync RTPrintf("VMM: FAILURE - ss=%x expected %x\n", CPUMGetHyperSS(pVCpu), SELMGetHyperDS(pVM));
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync RTPrintf("VMM: FAILURE - es=%x expected %x\n", CPUMGetHyperES(pVCpu), SELMGetHyperDS(pVM));
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync RTPrintf("VMM: FAILURE - ds=%x expected %x\n", CPUMGetHyperDS(pVCpu), SELMGetHyperDS(pVM));
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync RTPrintf("VMM: FAILURE - fs=%x expected %x\n", CPUMGetHyperFS(pVCpu), SELMGetHyperDS(pVM));
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync RTPrintf("VMM: FAILURE - gs=%x expected %x\n", CPUMGetHyperGS(pVCpu), SELMGetHyperDS(pVM));
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync RTPrintf("VMM: FAILURE - edi=%x expected %x\n", CPUMGetHyperEDI(pVCpu), 0x01234567);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync RTPrintf("VMM: FAILURE - esi=%x expected %x\n", CPUMGetHyperESI(pVCpu), 0x42000042);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync RTPrintf("VMM: FAILURE - ebp=%x expected %x\n", CPUMGetHyperEBP(pVCpu), 0xffeeddcc);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync RTPrintf("VMM: FAILURE - ebx=%x expected %x\n", CPUMGetHyperEBX(pVCpu), 0x89abcdef);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync RTPrintf("VMM: FAILURE - ecx=%x expected %x\n", CPUMGetHyperECX(pVCpu), 0xffffaaaa);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync RTPrintf("VMM: FAILURE - edx=%x expected %x\n", CPUMGetHyperEDX(pVCpu), 0x77778888);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync RTPrintf("VMM: FAILURE - eax=%x expected %x\n", CPUMGetHyperEAX(pVCpu), u32Eax);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync/* execute the switch. */
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * Setup stack for calling VMMGCEntry().
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync int rc = PDMR3LdrGetSymbolRC(pVM, VMMGC_MAIN_MODULE_NAME, "VMMGCEntry", &RCPtrEP);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync * Test various crashes which we must be able to recover from.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync vmmR3DoTrapTest(pVM, 0x3, 0, VINF_EM_DBG_HYPER_ASSERTION, 0xf0f0f0f0, "vmmGCTestTrap3_FaultEIP", "int3");
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync vmmR3DoTrapTest(pVM, 0x3, 1, VINF_EM_DBG_HYPER_ASSERTION, 0xf0f0f0f0, "vmmGCTestTrap3_FaultEIP", "int3 WP");
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync#if defined(DEBUG_bird) /* guess most people would like to skip these since they write to com1. */
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync vmmR3DoTrapTest(pVM, 0x8, 0, VERR_TRPM_PANIC, 0x00000000, "vmmGCTestTrap8_FaultEIP", "#DF [#PG]");
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync SELMR3Relocate(pVM); /* this resets the busy flag of the Trap 08 TSS */
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync rc = CFGMR3QueryBool(CFGMR3GetRoot(pVM), "DoubleFault", &f);
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync /* see tripple fault warnings in SELM and VMMGC.cpp. */
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync vmmR3DoTrapTest(pVM, 0x8, 1, VERR_TRPM_PANIC, 0x00000000, "vmmGCTestTrap8_FaultEIP", "#DF [#PG] WP");
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync SELMR3Relocate(pVM); /* this resets the busy flag of the Trap 08 TSS */
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync vmmR3DoTrapTest(pVM, 0xd, 0, VERR_TRPM_DONT_PANIC, 0xf0f0f0f0, "vmmGCTestTrap0d_FaultEIP", "ltr #GP");
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync ///@todo find a better \#GP case, on intel ltr will \#PF (busy update?) and not \#GP.
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync //vmmR3DoTrapTest(pVM, 0xd, 1, VERR_TRPM_DONT_PANIC, 0xf0f0f0f0, "vmmGCTestTrap0d_FaultEIP", "ltr #GP WP");
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync vmmR3DoTrapTest(pVM, 0xe, 0, VERR_TRPM_DONT_PANIC, 0x00000000, "vmmGCTestTrap0e_FaultEIP", "#PF (NULL)");
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync vmmR3DoTrapTest(pVM, 0xe, 1, VERR_TRPM_DONT_PANIC, 0x00000000, "vmmGCTestTrap0e_FaultEIP", "#PF (NULL) WP");
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync vmmR3DoTrapTest(pVM, 0xe, 2, VINF_SUCCESS, 0x00000000, NULL, "#PF w/Tmp Handler");
0df8f2889273aee65079da0f4b5727a4ac6d3e7bvboxsync vmmR3DoTrapTest(pVM, 0xe, 4, VINF_SUCCESS, 0x00000000, NULL, "#PF w/Tmp Handler and bad fs");
return rc;
return rc;
RTPrintf("VMM: DR1=VMMGCEntry test failed with rc=%Rrc! expected VINF_EM_RAW_BREAKPOINT_HYPER\n", rc);
return rc;
return rc;
RTPrintf("VMM: DR1=VMMGCEntry test failed with rc=%Rrc! expected VINF_EM_RAW_BREAKPOINT_HYPER\n", rc);
return rc;
return rc;
return VERR_GENERAL_FAILURE;
return VERR_GENERAL_FAILURE;
return rc;
return rc;
RTPrintf("Warning: Ticks=%RU64 (< %RU64)\n", Ticks, SUPGetCpuHzFromGIP(g_pSUPGlobalInfoPage) / 10000);
return rc;
return rc;
RTPrintf("VMM: %8d cycles in %11llu ns (%11lld ticks), %10llu ns/iteration (%11lld ticks) Min %11lld ticks\n",
Log(("VMM: %8d cycles in %11llu ns (%11lld ticks), %10llu ns/iteration (%11lld ticks) Min %11lld ticks\n",
return rc;
uint32_t i;
int rc;
return VERR_ACCESS_DENIED;
pHyperCtx->cr0 = X86_CR0_PE | X86_CR0_WP | X86_CR0_PG | X86_CR0_TS | X86_CR0_ET | X86_CR0_NE | X86_CR0_MP;
return rc;
RTPrintf("VMM: %8d cycles in %11llu ns (%11lld ticks), %10llu ns/iteration (%11lld ticks) Min %11lld ticks\n",
Log(("VMM: %8d cycles in %11llu ns (%11lld ticks), %10llu ns/iteration (%11lld ticks) Min %11lld ticks\n",
return rc;