VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/EMR3Nem.cpp@ 78254

Last change on this file since 78254 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

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