VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/VMMTests.cpp@ 80014

Last change on this file since 80014 was 80011, checked in by vboxsync, 6 years ago

VMM: Kicking out raw-mode (work in progress). ?bugref:9517

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 7.5 KB
Line 
1/* $Id: VMMTests.cpp 80011 2019-07-26 15:06:30Z vboxsync $ */
2/** @file
3 * VMM - The Virtual Machine Monitor Core, Tests.
4 */
5
6/*
7 * Copyright (C) 2006-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18//#define NO_SUPCALLR0VMM
19
20
21/*********************************************************************************************************************************
22* Header Files *
23*********************************************************************************************************************************/
24#define LOG_GROUP LOG_GROUP_VMM
25#include <iprt/asm-amd64-x86.h> /* for SUPGetCpuHzFromGIP */
26#include <VBox/vmm/vmm.h>
27#include <VBox/vmm/pdmapi.h>
28#include <VBox/vmm/cpum.h>
29#include <VBox/dbg.h>
30#include <VBox/vmm/hm.h>
31#include <VBox/vmm/mm.h>
32#include <VBox/vmm/trpm.h>
33#include <VBox/vmm/selm.h>
34#include "VMMInternal.h"
35#include <VBox/vmm/vm.h>
36#include <iprt/errcore.h>
37#include <VBox/param.h>
38
39#include <iprt/assert.h>
40#include <iprt/asm.h>
41#include <iprt/time.h>
42#include <iprt/stream.h>
43#include <iprt/string.h>
44#include <iprt/x86.h>
45
46
47#define SYNC_SEL(pHyperCtx, reg) \
48 if (pHyperCtx->reg.Sel) \
49 { \
50 DBGFSELINFO selInfo; \
51 int rc2 = SELMR3GetShadowSelectorInfo(pVM, pHyperCtx->reg.Sel, &selInfo); \
52 AssertRC(rc2); \
53 \
54 pHyperCtx->reg.u64Base = selInfo.GCPtrBase; \
55 pHyperCtx->reg.u32Limit = selInfo.cbLimit; \
56 pHyperCtx->reg.Attr.n.u1Present = selInfo.u.Raw.Gen.u1Present; \
57 pHyperCtx->reg.Attr.n.u1DefBig = selInfo.u.Raw.Gen.u1DefBig; \
58 pHyperCtx->reg.Attr.n.u1Granularity = selInfo.u.Raw.Gen.u1Granularity; \
59 pHyperCtx->reg.Attr.n.u4Type = selInfo.u.Raw.Gen.u4Type; \
60 pHyperCtx->reg.Attr.n.u2Dpl = selInfo.u.Raw.Gen.u2Dpl; \
61 pHyperCtx->reg.Attr.n.u1DescType = selInfo.u.Raw.Gen.u1DescType; \
62 pHyperCtx->reg.Attr.n.u1Long = selInfo.u.Raw.Gen.u1Long; \
63 }
64
65/* execute the switch. */
66VMMR3DECL(int) VMMDoHmTest(PVM pVM)
67{
68#if 1
69 RTPrintf("FIXME!\n");
70 RT_NOREF(pVM);
71 return 0;
72#else
73
74 uint32_t i;
75 int rc;
76 PCPUMCTX pHyperCtx, pGuestCtx;
77 RTGCPHYS CR3Phys = 0x0; /* fake address */
78 PVMCPU pVCpu = &pVM->aCpus[0];
79
80 if (!HMIsEnabled(pVM))
81 {
82 RTPrintf("VMM: Hardware accelerated test not available!\n");
83 return VERR_ACCESS_DENIED;
84 }
85
86#ifdef VBOX_WITH_RAW_MODE
87 /*
88 * These forced actions are not necessary for the test and trigger breakpoints too.
89 */
90 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_TRPM_SYNC_IDT);
91 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_SELM_SYNC_TSS);
92#endif
93
94 /* Enable mapping of the hypervisor into the shadow page table. */
95 uint32_t cb;
96 rc = PGMR3MappingsSize(pVM, &cb);
97 AssertRCReturn(rc, rc);
98
99 /* Pretend the mappings are now fixed; to force a refresh of the reserved PDEs. */
100 rc = PGMR3MappingsFix(pVM, MM_HYPER_AREA_ADDRESS, cb);
101 AssertRCReturn(rc, rc);
102
103 pHyperCtx = CPUMGetHyperCtxPtr(pVCpu);
104
105 pHyperCtx->cr0 = X86_CR0_PE | X86_CR0_WP | X86_CR0_PG | X86_CR0_TS | X86_CR0_ET | X86_CR0_NE | X86_CR0_MP;
106 pHyperCtx->cr4 = X86_CR4_PGE | X86_CR4_OSFXSR | X86_CR4_OSXMMEEXCPT;
107 PGMChangeMode(pVCpu, pHyperCtx->cr0, pHyperCtx->cr4, pHyperCtx->msrEFER);
108 PGMSyncCR3(pVCpu, pHyperCtx->cr0, CR3Phys, pHyperCtx->cr4, true);
109
110 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_TO_R3);
111 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_TIMER);
112 VM_FF_CLEAR(pVM, VM_FF_TM_VIRTUAL_SYNC);
113 VM_FF_CLEAR(pVM, VM_FF_REQUEST);
114
115 /*
116 * Setup stack for calling VMMRCEntry().
117 */
118 RTRCPTR RCPtrEP;
119 rc = PDMR3LdrGetSymbolRC(pVM, VMMRC_MAIN_MODULE_NAME, "VMMRCEntry", &RCPtrEP);
120 if (RT_SUCCESS(rc))
121 {
122 RTPrintf("VMM: VMMRCEntry=%RRv\n", RCPtrEP);
123
124 pHyperCtx = CPUMGetHyperCtxPtr(pVCpu);
125
126 /* Fill in hidden selector registers for the hypervisor state. */
127 SYNC_SEL(pHyperCtx, cs);
128 SYNC_SEL(pHyperCtx, ds);
129 SYNC_SEL(pHyperCtx, es);
130 SYNC_SEL(pHyperCtx, fs);
131 SYNC_SEL(pHyperCtx, gs);
132 SYNC_SEL(pHyperCtx, ss);
133 SYNC_SEL(pHyperCtx, tr);
134
135 /*
136 * Profile switching.
137 */
138 RTPrintf("VMM: profiling switcher...\n");
139 Log(("VMM: profiling switcher...\n"));
140 uint64_t TickMin = UINT64_MAX;
141 uint64_t tsBegin = RTTimeNanoTS();
142 uint64_t TickStart = ASMReadTSC();
143 for (i = 0; i < 1000000; i++)
144 {
145 CPUMSetHyperState(pVCpu, pVM->vmm.s.pfnCallTrampolineRC, pVCpu->vmm.s.pbEMTStackBottomRC, 0, 0);
146 CPUMPushHyper(pVCpu, 0);
147 CPUMPushHyper(pVCpu, VMMRC_DO_TESTCASE_HM_NOP);
148 CPUMPushHyper(pVCpu, pVM->pVMRC);
149 CPUMPushHyper(pVCpu, 3 * sizeof(RTRCPTR)); /* stack frame size */
150 CPUMPushHyper(pVCpu, RCPtrEP); /* what to call */
151
152 pHyperCtx = CPUMGetHyperCtxPtr(pVCpu);
153 pGuestCtx = CPUMQueryGuestCtxPtr(pVCpu);
154
155 /* Copy the hypervisor context to make sure we have a valid guest context. */
156 *pGuestCtx = *pHyperCtx;
157 pGuestCtx->cr3 = CR3Phys;
158
159 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_TO_R3);
160 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_TIMER);
161 VM_FF_CLEAR(pVM, VM_FF_TM_VIRTUAL_SYNC);
162
163 uint64_t TickThisStart = ASMReadTSC();
164 rc = SUPR3CallVMMR0Fast(pVM->pVMR0, VMMR0_DO_HM_RUN, 0);
165 uint64_t TickThisElapsed = ASMReadTSC() - TickThisStart;
166 if (RT_FAILURE(rc))
167 {
168 Log(("VMM: R0 returned fatal %Rrc in iteration %d\n", rc, i));
169 VMMR3FatalDump(pVM, pVCpu, rc);
170 return rc;
171 }
172 if (TickThisElapsed < TickMin)
173 TickMin = TickThisElapsed;
174 }
175 uint64_t TickEnd = ASMReadTSC();
176 uint64_t tsEnd = RTTimeNanoTS();
177
178 uint64_t Elapsed = tsEnd - tsBegin;
179 uint64_t PerIteration = Elapsed / (uint64_t)i;
180 uint64_t cTicksElapsed = TickEnd - TickStart;
181 uint64_t cTicksPerIteration = cTicksElapsed / (uint64_t)i;
182
183 RTPrintf("VMM: %8d cycles in %11llu ns (%11lld ticks), %10llu ns/iteration (%11lld ticks) Min %11lld ticks\n",
184 i, Elapsed, cTicksElapsed, PerIteration, cTicksPerIteration, TickMin);
185 Log(("VMM: %8d cycles in %11llu ns (%11lld ticks), %10llu ns/iteration (%11lld ticks) Min %11lld ticks\n",
186 i, Elapsed, cTicksElapsed, PerIteration, cTicksPerIteration, TickMin));
187
188 rc = VINF_SUCCESS;
189 }
190 else
191 AssertMsgFailed(("Failed to resolved VMMRC.rc::VMMRCEntry(), rc=%Rrc\n", rc));
192
193 return rc;
194#endif
195}
196
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette