VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/EMHM.cpp@ 81150

Last change on this file since 81150 was 81150, checked in by vboxsync, 5 years ago

VMM,/Makefile.kmk: Kicked out more recompiler related code. bugref:9576

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 19.0 KB
Line 
1/* $Id: EMHM.cpp 81150 2019-10-08 12:53:47Z vboxsync $ */
2/** @file
3 * EM - Execution Monitor / Manager - hardware virtualization
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
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_EM
23#define VMCPU_INCL_CPUM_GST_CTX
24#include <VBox/vmm/em.h>
25#include <VBox/vmm/vmm.h>
26#include <VBox/vmm/selm.h>
27#include <VBox/vmm/trpm.h>
28#include <VBox/vmm/iem.h>
29#include <VBox/vmm/iom.h>
30#include <VBox/vmm/dbgf.h>
31#include <VBox/vmm/pgm.h>
32#include <VBox/vmm/tm.h>
33#include <VBox/vmm/mm.h>
34#include <VBox/vmm/ssm.h>
35#include <VBox/vmm/pdmapi.h>
36#include <VBox/vmm/pdmcritsect.h>
37#include <VBox/vmm/pdmqueue.h>
38#include <VBox/vmm/hm.h>
39#include "EMInternal.h"
40#include <VBox/vmm/vm.h>
41#include <VBox/vmm/gim.h>
42#include <VBox/vmm/cpumdis.h>
43#include <VBox/dis.h>
44#include <VBox/disopcode.h>
45#include <VBox/err.h>
46#include <VBox/vmm/dbgf.h>
47#include "VMMTracing.h"
48
49#include <iprt/asm.h>
50
51
52/*********************************************************************************************************************************
53* Internal Functions *
54*********************************************************************************************************************************/
55static int emR3HmHandleRC(PVM pVM, PVMCPU pVCpu, int rc);
56DECLINLINE(int) emR3HmExecuteInstruction(PVM pVM, PVMCPU pVCpu, const char *pszPrefix, int rcGC = VINF_SUCCESS);
57static int emR3HmExecuteIOInstruction(PVM pVM, PVMCPU pVCpu);
58static int emR3HmForcedActions(PVM pVM, PVMCPU pVCpu);
59
60#define EMHANDLERC_WITH_HM
61#define emR3ExecuteInstruction emR3HmExecuteInstruction
62#define emR3ExecuteIOInstruction emR3HmExecuteIOInstruction
63#include "EMHandleRCTmpl.h"
64
65
66/**
67 * Executes instruction in HM mode if we can.
68 *
69 * This is somewhat comparable to REMR3EmulateInstruction.
70 *
71 * @returns VBox strict status code.
72 * @retval VINF_EM_DBG_STEPPED on success.
73 * @retval VERR_EM_CANNOT_EXEC_GUEST if we cannot execute guest instructions in
74 * HM right now.
75 *
76 * @param pVM The cross context VM structure.
77 * @param pVCpu The cross context virtual CPU structure for the calling EMT.
78 * @param fFlags Combinations of EM_ONE_INS_FLAGS_XXX.
79 * @thread EMT.
80 */
81VMMR3_INT_DECL(VBOXSTRICTRC) EMR3HmSingleInstruction(PVM pVM, PVMCPU pVCpu, uint32_t fFlags)
82{
83 Assert(!(fFlags & ~EM_ONE_INS_FLAGS_MASK));
84
85 if (!HMCanExecuteGuest(pVM, pVCpu, &pVCpu->cpum.GstCtx))
86 return VINF_EM_RESCHEDULE;
87
88 uint64_t const uOldRip = pVCpu->cpum.GstCtx.rip;
89 for (;;)
90 {
91 /*
92 * Service necessary FFs before going into HM.
93 */
94 if ( VM_FF_IS_ANY_SET(pVM, VM_FF_HIGH_PRIORITY_PRE_RAW_MASK)
95 || VMCPU_FF_IS_ANY_SET(pVCpu, VMCPU_FF_HIGH_PRIORITY_PRE_RAW_MASK))
96 {
97 VBOXSTRICTRC rcStrict = emR3HmForcedActions(pVM, pVCpu);
98 if (rcStrict != VINF_SUCCESS)
99 {
100 Log(("EMR3HmSingleInstruction: FFs before -> %Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
101 return rcStrict;
102 }
103 }
104
105 /*
106 * Go execute it.
107 */
108 bool fOld = HMSetSingleInstruction(pVM, pVCpu, true);
109 VBOXSTRICTRC rcStrict = VMMR3HmRunGC(pVM, pVCpu);
110 HMSetSingleInstruction(pVM, pVCpu, fOld);
111 LogFlow(("EMR3HmSingleInstruction: %Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
112
113 /*
114 * Handle high priority FFs and informational status codes. We don't do
115 * normal FF processing the caller or the next call can deal with them.
116 */
117 VMCPU_FF_CLEAR_MASK(pVCpu, VMCPU_FF_RESUME_GUEST_MASK);
118 if ( VM_FF_IS_ANY_SET(pVM, VM_FF_HIGH_PRIORITY_POST_MASK)
119 || VMCPU_FF_IS_ANY_SET(pVCpu, VMCPU_FF_HIGH_PRIORITY_POST_MASK))
120 {
121 rcStrict = emR3HighPriorityPostForcedActions(pVM, pVCpu, rcStrict);
122 LogFlow(("EMR3HmSingleInstruction: FFs after -> %Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
123 }
124
125 if (rcStrict != VINF_SUCCESS && (rcStrict < VINF_EM_FIRST || rcStrict > VINF_EM_LAST))
126 {
127 rcStrict = emR3HmHandleRC(pVM, pVCpu, VBOXSTRICTRC_TODO(rcStrict));
128 Log(("EMR3HmSingleInstruction: emR3HmHandleRC -> %Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
129 }
130
131 /*
132 * Done?
133 */
134 if ( (rcStrict != VINF_SUCCESS && rcStrict != VINF_EM_DBG_STEPPED)
135 || !(fFlags & EM_ONE_INS_FLAGS_RIP_CHANGE)
136 || pVCpu->cpum.GstCtx.rip != uOldRip)
137 {
138 if (rcStrict == VINF_SUCCESS && pVCpu->cpum.GstCtx.rip != uOldRip)
139 rcStrict = VINF_EM_DBG_STEPPED;
140 Log(("EMR3HmSingleInstruction: returns %Rrc (rip %llx -> %llx)\n", VBOXSTRICTRC_VAL(rcStrict), uOldRip, pVCpu->cpum.GstCtx.rip));
141 CPUM_IMPORT_EXTRN_RET(pVCpu, ~CPUMCTX_EXTRN_KEEPER_MASK);
142 return rcStrict;
143 }
144 }
145}
146
147
148/**
149 * Executes one (or perhaps a few more) instruction(s).
150 *
151 * @returns VBox status code suitable for EM.
152 *
153 * @param pVM The cross context VM structure.
154 * @param pVCpu The cross context virtual CPU structure.
155 * @param rcRC Return code from RC.
156 * @param pszPrefix Disassembly prefix. If not NULL we'll disassemble the
157 * instruction and prefix the log output with this text.
158 */
159#if defined(LOG_ENABLED) || defined(DOXYGEN_RUNNING)
160static int emR3HmExecuteInstructionWorker(PVM pVM, PVMCPU pVCpu, int rcRC, const char *pszPrefix)
161#else
162static int emR3HmExecuteInstructionWorker(PVM pVM, PVMCPU pVCpu, int rcRC)
163#endif
164{
165 NOREF(rcRC);
166
167#ifdef LOG_ENABLED
168 /*
169 * Log it.
170 */
171 Log(("EMINS: %04x:%RGv RSP=%RGv\n", pVCpu->cpum.GstCtx.cs.Sel, (RTGCPTR)pVCpu->cpum.GstCtx.rip, (RTGCPTR)pVCpu->cpum.GstCtx.rsp));
172 if (pszPrefix)
173 {
174 DBGFR3_INFO_LOG(pVM, pVCpu, "cpumguest", pszPrefix);
175 DBGFR3_DISAS_INSTR_CUR_LOG(pVCpu, pszPrefix);
176 }
177#endif
178
179 /*
180 * Use IEM and fallback on REM if the functionality is missing.
181 * Once IEM gets mature enough, nothing should ever fall back.
182 */
183 STAM_PROFILE_START(&pVCpu->em.s.StatIEMEmu, a);
184 VBOXSTRICTRC rcStrict;
185 uint32_t idxContinueExitRec = pVCpu->em.s.idxContinueExitRec;
186 RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
187 if (idxContinueExitRec >= RT_ELEMENTS(pVCpu->em.s.aExitRecords))
188 {
189 CPUM_IMPORT_EXTRN_RET(pVCpu, IEM_CPUMCTX_EXTRN_MUST_MASK);
190 rcStrict = VBOXSTRICTRC_TODO(IEMExecOne(pVCpu));
191 }
192 else
193 {
194 RT_UNTRUSTED_VALIDATED_FENCE();
195 rcStrict = EMHistoryExec(pVCpu, &pVCpu->em.s.aExitRecords[idxContinueExitRec], 0);
196 LogFlow(("emR3HmExecuteInstruction: %Rrc (EMHistoryExec)\n", VBOXSTRICTRC_VAL(rcStrict)));
197 }
198 STAM_PROFILE_STOP(&pVCpu->em.s.StatIEMEmu, a);
199
200 if ( rcStrict == VERR_IEM_ASPECT_NOT_IMPLEMENTED
201 || rcStrict == VERR_IEM_INSTR_NOT_IMPLEMENTED)
202 {
203#ifdef VBOX_WITH_REM
204 STAM_PROFILE_START(&pVCpu->em.s.StatREMEmu, b);
205 EMRemLock(pVM);
206 /* Flush the recompiler TLB if the VCPU has changed. */
207 if (pVM->em.s.idLastRemCpu != pVCpu->idCpu)
208 CPUMSetChangedFlags(pVCpu, CPUM_CHANGED_ALL);
209 pVM->em.s.idLastRemCpu = pVCpu->idCpu;
210
211 rcStrict = REMR3EmulateInstruction(pVM, pVCpu);
212 EMRemUnlock(pVM);
213 STAM_PROFILE_STOP(&pVCpu->em.s.StatREMEmu, b);
214#else /* !VBOX_WITH_REM */
215 NOREF(pVM);
216#endif /* !VBOX_WITH_REM */
217 }
218
219 return VBOXSTRICTRC_TODO(rcStrict);
220}
221
222
223/**
224 * Executes one (or perhaps a few more) instruction(s).
225 * This is just a wrapper for discarding pszPrefix in non-logging builds.
226 *
227 * @returns VBox status code suitable for EM.
228 * @param pVM The cross context VM structure.
229 * @param pVCpu The cross context virtual CPU structure.
230 * @param pszPrefix Disassembly prefix. If not NULL we'll disassemble the
231 * instruction and prefix the log output with this text.
232 * @param rcGC GC return code
233 */
234DECLINLINE(int) emR3HmExecuteInstruction(PVM pVM, PVMCPU pVCpu, const char *pszPrefix, int rcGC)
235{
236#ifdef LOG_ENABLED
237 return emR3HmExecuteInstructionWorker(pVM, pVCpu, rcGC, pszPrefix);
238#else
239 RT_NOREF_PV(pszPrefix);
240 return emR3HmExecuteInstructionWorker(pVM, pVCpu, rcGC);
241#endif
242}
243
244
245/**
246 * Executes one (or perhaps a few more) IO instruction(s).
247 *
248 * @returns VBox status code suitable for EM.
249 * @param pVM The cross context VM structure.
250 * @param pVCpu The cross context virtual CPU structure.
251 */
252static int emR3HmExecuteIOInstruction(PVM pVM, PVMCPU pVCpu)
253{
254 RT_NOREF(pVM);
255 STAM_PROFILE_START(&pVCpu->em.s.StatIOEmu, a);
256
257 VBOXSTRICTRC rcStrict;
258 uint32_t idxContinueExitRec = pVCpu->em.s.idxContinueExitRec;
259 RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
260 if (idxContinueExitRec >= RT_ELEMENTS(pVCpu->em.s.aExitRecords))
261 {
262 /*
263 * Hand it over to the interpreter.
264 */
265 CPUM_IMPORT_EXTRN_RET(pVCpu, IEM_CPUMCTX_EXTRN_MUST_MASK);
266 rcStrict = IEMExecOne(pVCpu);
267 LogFlow(("emR3HmExecuteIOInstruction: %Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
268 }
269 else
270 {
271 RT_UNTRUSTED_VALIDATED_FENCE();
272 CPUM_IMPORT_EXTRN_RET(pVCpu, IEM_CPUMCTX_EXTRN_MUST_MASK);
273 rcStrict = EMHistoryExec(pVCpu, &pVCpu->em.s.aExitRecords[idxContinueExitRec], 0);
274 LogFlow(("emR3HmExecuteIOInstruction: %Rrc (EMHistoryExec)\n", VBOXSTRICTRC_VAL(rcStrict)));
275 STAM_COUNTER_INC(&pVCpu->em.s.CTX_SUFF(pStats)->StatIoRestarted);
276 }
277
278 STAM_COUNTER_INC(&pVCpu->em.s.CTX_SUFF(pStats)->StatIoIem);
279 STAM_PROFILE_STOP(&pVCpu->em.s.StatIOEmu, a);
280 return VBOXSTRICTRC_TODO(rcStrict);
281}
282
283
284/**
285 * Process HM specific forced actions.
286 *
287 * This function is called when any FFs in the VM_FF_HIGH_PRIORITY_PRE_RAW_MASK
288 * or/and VMCPU_FF_HIGH_PRIORITY_PRE_RAW_MASK are pending.
289 *
290 * @returns VBox status code. May return VINF_EM_NO_MEMORY but none of the other
291 * EM statuses.
292 * @param pVM The cross context VM structure.
293 * @param pVCpu The cross context virtual CPU structure.
294 */
295static int emR3HmForcedActions(PVM pVM, PVMCPU pVCpu)
296{
297 /*
298 * Sync page directory.
299 */
300 if (VMCPU_FF_IS_ANY_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL))
301 {
302 CPUM_IMPORT_EXTRN_RET(pVCpu, CPUMCTX_EXTRN_CR0 | CPUMCTX_EXTRN_CR3 | CPUMCTX_EXTRN_CR4);
303 Assert(pVCpu->em.s.enmState != EMSTATE_WAIT_SIPI);
304 int rc = PGMSyncCR3(pVCpu, pVCpu->cpum.GstCtx.cr0, pVCpu->cpum.GstCtx.cr3, pVCpu->cpum.GstCtx.cr4, VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3));
305 if (RT_FAILURE(rc))
306 return rc;
307
308 /* Prefetch pages for EIP and ESP. */
309 /** @todo This is rather expensive. Should investigate if it really helps at all. */
310 /** @todo this should be skipped! */
311 CPUM_IMPORT_EXTRN_RET(pVCpu, CPUMCTX_EXTRN_CS | CPUMCTX_EXTRN_SS);
312 rc = PGMPrefetchPage(pVCpu, SELMToFlat(pVM, DISSELREG_CS, CPUMCTX2CORE(&pVCpu->cpum.GstCtx), pVCpu->cpum.GstCtx.rip));
313 if (rc == VINF_SUCCESS)
314 rc = PGMPrefetchPage(pVCpu, SELMToFlat(pVM, DISSELREG_SS, CPUMCTX2CORE(&pVCpu->cpum.GstCtx), pVCpu->cpum.GstCtx.rsp));
315 if (rc != VINF_SUCCESS)
316 {
317 if (rc != VINF_PGM_SYNC_CR3)
318 {
319 AssertLogRelMsgReturn(RT_FAILURE(rc), ("%Rrc\n", rc), VERR_IPE_UNEXPECTED_INFO_STATUS);
320 return rc;
321 }
322 rc = PGMSyncCR3(pVCpu, pVCpu->cpum.GstCtx.cr0, pVCpu->cpum.GstCtx.cr3, pVCpu->cpum.GstCtx.cr4, VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3));
323 if (RT_FAILURE(rc))
324 return rc;
325 }
326 /** @todo maybe prefetch the supervisor stack page as well */
327 }
328
329 /*
330 * Allocate handy pages (just in case the above actions have consumed some pages).
331 */
332 if (VM_FF_IS_PENDING_EXCEPT(pVM, VM_FF_PGM_NEED_HANDY_PAGES, VM_FF_PGM_NO_MEMORY))
333 {
334 int rc = PGMR3PhysAllocateHandyPages(pVM);
335 if (RT_FAILURE(rc))
336 return rc;
337 }
338
339 /*
340 * Check whether we're out of memory now.
341 *
342 * This may stem from some of the above actions or operations that has been executed
343 * since we ran FFs. The allocate handy pages must for instance always be followed by
344 * this check.
345 */
346 if (VM_FF_IS_SET(pVM, VM_FF_PGM_NO_MEMORY))
347 return VINF_EM_NO_MEMORY;
348
349 return VINF_SUCCESS;
350}
351
352
353/**
354 * Executes hardware accelerated raw code. (Intel VT-x & AMD-V)
355 *
356 * This function contains the raw-mode version of the inner
357 * execution loop (the outer loop being in EMR3ExecuteVM()).
358 *
359 * @returns VBox status code. The most important ones are: VINF_EM_RESCHEDULE, VINF_EM_RESCHEDULE_RAW,
360 * VINF_EM_RESCHEDULE_REM, VINF_EM_SUSPEND, VINF_EM_RESET and VINF_EM_TERMINATE.
361 *
362 * @param pVM The cross context VM structure.
363 * @param pVCpu The cross context virtual CPU structure.
364 * @param pfFFDone Where to store an indicator telling whether or not
365 * FFs were done before returning.
366 */
367int emR3HmExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone)
368{
369 int rc = VERR_IPE_UNINITIALIZED_STATUS;
370
371 LogFlow(("emR3HmExecute%d: (cs:eip=%04x:%RGv)\n", pVCpu->idCpu, pVCpu->cpum.GstCtx.cs.Sel, (RTGCPTR)pVCpu->cpum.GstCtx.rip));
372 *pfFFDone = false;
373
374 STAM_COUNTER_INC(&pVCpu->em.s.StatHMExecuteCalled);
375
376 /*
377 * Spin till we get a forced action which returns anything but VINF_SUCCESS.
378 */
379 for (;;)
380 {
381 STAM_PROFILE_ADV_START(&pVCpu->em.s.StatHMEntry, a);
382
383 /* Check if a forced reschedule is pending. */
384 if (HMR3IsRescheduleRequired(pVM, &pVCpu->cpum.GstCtx))
385 {
386 rc = VINF_EM_RESCHEDULE;
387 break;
388 }
389
390 /*
391 * Process high priority pre-execution raw-mode FFs.
392 */
393 if ( VM_FF_IS_ANY_SET(pVM, VM_FF_HIGH_PRIORITY_PRE_RAW_MASK)
394 || VMCPU_FF_IS_ANY_SET(pVCpu, VMCPU_FF_HIGH_PRIORITY_PRE_RAW_MASK))
395 {
396 rc = emR3HmForcedActions(pVM, pVCpu);
397 if (rc != VINF_SUCCESS)
398 break;
399 }
400
401#ifdef LOG_ENABLED
402 /*
403 * Log important stuff before entering GC.
404 */
405 if (TRPMHasTrap(pVCpu))
406 Log(("CPU%d: Pending hardware interrupt=0x%x cs:rip=%04X:%RGv\n", pVCpu->idCpu, TRPMGetTrapNo(pVCpu), pVCpu->cpum.GstCtx.cs.Sel, (RTGCPTR)pVCpu->cpum.GstCtx.rip));
407
408 uint32_t cpl = CPUMGetGuestCPL(pVCpu);
409 if (pVM->cCpus == 1)
410 {
411 if (pVCpu->cpum.GstCtx.eflags.Bits.u1VM)
412 Log(("HWV86: %08X IF=%d\n", pVCpu->cpum.GstCtx.eip, pVCpu->cpum.GstCtx.eflags.Bits.u1IF));
413 else if (CPUMIsGuestIn64BitCodeEx(&pVCpu->cpum.GstCtx))
414 Log(("HWR%d: %04X:%RGv ESP=%RGv IF=%d IOPL=%d CR0=%x CR4=%x EFER=%x\n", cpl, pVCpu->cpum.GstCtx.cs.Sel, (RTGCPTR)pVCpu->cpum.GstCtx.rip, pVCpu->cpum.GstCtx.rsp, pVCpu->cpum.GstCtx.eflags.Bits.u1IF, pVCpu->cpum.GstCtx.eflags.Bits.u2IOPL, (uint32_t)pVCpu->cpum.GstCtx.cr0, (uint32_t)pVCpu->cpum.GstCtx.cr4, (uint32_t)pVCpu->cpum.GstCtx.msrEFER));
415 else
416 Log(("HWR%d: %04X:%08X ESP=%08X IF=%d IOPL=%d CR0=%x CR4=%x EFER=%x\n", cpl, pVCpu->cpum.GstCtx.cs.Sel, pVCpu->cpum.GstCtx.eip, pVCpu->cpum.GstCtx.esp, pVCpu->cpum.GstCtx.eflags.Bits.u1IF, pVCpu->cpum.GstCtx.eflags.Bits.u2IOPL, (uint32_t)pVCpu->cpum.GstCtx.cr0, (uint32_t)pVCpu->cpum.GstCtx.cr4, (uint32_t)pVCpu->cpum.GstCtx.msrEFER));
417 }
418 else
419 {
420 if (pVCpu->cpum.GstCtx.eflags.Bits.u1VM)
421 Log(("HWV86-CPU%d: %08X IF=%d\n", pVCpu->idCpu, pVCpu->cpum.GstCtx.eip, pVCpu->cpum.GstCtx.eflags.Bits.u1IF));
422 else if (CPUMIsGuestIn64BitCodeEx(&pVCpu->cpum.GstCtx))
423 Log(("HWR%d-CPU%d: %04X:%RGv ESP=%RGv IF=%d IOPL=%d CR0=%x CR4=%x EFER=%x\n", cpl, pVCpu->idCpu, pVCpu->cpum.GstCtx.cs.Sel, (RTGCPTR)pVCpu->cpum.GstCtx.rip, pVCpu->cpum.GstCtx.rsp, pVCpu->cpum.GstCtx.eflags.Bits.u1IF, pVCpu->cpum.GstCtx.eflags.Bits.u2IOPL, (uint32_t)pVCpu->cpum.GstCtx.cr0, (uint32_t)pVCpu->cpum.GstCtx.cr4, (uint32_t)pVCpu->cpum.GstCtx.msrEFER));
424 else
425 Log(("HWR%d-CPU%d: %04X:%08X ESP=%08X IF=%d IOPL=%d CR0=%x CR4=%x EFER=%x\n", cpl, pVCpu->idCpu, pVCpu->cpum.GstCtx.cs.Sel, pVCpu->cpum.GstCtx.eip, pVCpu->cpum.GstCtx.esp, pVCpu->cpum.GstCtx.eflags.Bits.u1IF, pVCpu->cpum.GstCtx.eflags.Bits.u2IOPL, (uint32_t)pVCpu->cpum.GstCtx.cr0, (uint32_t)pVCpu->cpum.GstCtx.cr4, (uint32_t)pVCpu->cpum.GstCtx.msrEFER));
426 }
427#endif /* LOG_ENABLED */
428
429 /*
430 * Execute the code.
431 */
432 STAM_PROFILE_ADV_STOP(&pVCpu->em.s.StatHMEntry, a);
433
434 if (RT_LIKELY(emR3IsExecutionAllowed(pVM, pVCpu)))
435 {
436 STAM_PROFILE_START(&pVCpu->em.s.StatHMExec, x);
437 rc = VMMR3HmRunGC(pVM, pVCpu);
438 STAM_PROFILE_STOP(&pVCpu->em.s.StatHMExec, x);
439 }
440 else
441 {
442 /* Give up this time slice; virtual time continues */
443 STAM_REL_PROFILE_ADV_START(&pVCpu->em.s.StatCapped, u);
444 RTThreadSleep(5);
445 STAM_REL_PROFILE_ADV_STOP(&pVCpu->em.s.StatCapped, u);
446 rc = VINF_SUCCESS;
447 }
448
449
450 /*
451 * Deal with high priority post execution FFs before doing anything else.
452 */
453 VMCPU_FF_CLEAR_MASK(pVCpu, VMCPU_FF_RESUME_GUEST_MASK);
454 if ( VM_FF_IS_ANY_SET(pVM, VM_FF_HIGH_PRIORITY_POST_MASK)
455 || VMCPU_FF_IS_ANY_SET(pVCpu, VMCPU_FF_HIGH_PRIORITY_POST_MASK))
456 rc = VBOXSTRICTRC_TODO(emR3HighPriorityPostForcedActions(pVM, pVCpu, rc));
457
458 /*
459 * Process the returned status code.
460 */
461 if (rc >= VINF_EM_FIRST && rc <= VINF_EM_LAST)
462 break;
463
464 rc = emR3HmHandleRC(pVM, pVCpu, rc);
465 if (rc != VINF_SUCCESS)
466 break;
467
468 /*
469 * Check and execute forced actions.
470 */
471#ifdef VBOX_HIGH_RES_TIMERS_HACK
472 TMTimerPollVoid(pVM, pVCpu);
473#endif
474 if ( VM_FF_IS_ANY_SET(pVM, VM_FF_ALL_MASK)
475 || VMCPU_FF_IS_ANY_SET(pVCpu, VMCPU_FF_ALL_MASK))
476 {
477 rc = emR3ForcedActions(pVM, pVCpu, rc);
478 VBOXVMM_EM_FF_ALL_RET(pVCpu, rc);
479 if ( rc != VINF_SUCCESS
480 && rc != VINF_EM_RESCHEDULE_HM)
481 {
482 *pfFFDone = true;
483 break;
484 }
485 }
486 }
487
488 /*
489 * Return to outer loop.
490 */
491#if defined(LOG_ENABLED) && defined(DEBUG)
492 RTLogFlush(NULL);
493#endif
494 return rc;
495}
496
Note: See TracBrowser for help on using the repository browser.

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