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