Index: /trunk/include/VBox/vmm/cpum.h
===================================================================
--- /trunk/include/VBox/vmm/cpum.h	(revision 72487)
+++ /trunk/include/VBox/vmm/cpum.h	(revision 72488)
@@ -1259,4 +1259,68 @@
 /** @} */
 
+/** @name Externalized State Helpers.
+ * @{ */
+/** @def CPUM_ASSERT_NOT_EXTRN
+ * Macro for asserting that @a a_fNotExtrn are present.
+ *
+ * @param   a_pVCpu         The cross context virtual CPU structure of the calling EMT.
+ * @param   a_fNotExtrn     Mask of CPUMCTX_EXTRN_XXX bits to check.
+ *
+ * @remarks Requires VMCPU_INCL_CPUM_GST_CTX to be defined.
+ */
+#define CPUM_ASSERT_NOT_EXTRN(a_pVCpu, a_fNotExtrn) \
+    AssertMsg(!((a_pVCpu)->cpum.GstCtx.fExtrn & (a_fNotExtrn)), \
+              ("%#RX64; a_fNotExtrn=%#RX64\n", (a_pVCpu)->cpum.GstCtx.fExtrn, (a_fNotExtrn)))
+
+/** @def CPUM_IMPORT_EXTRN_RET
+ * Macro for making sure the state specified by @a fExtrnImport is present,
+ * calling CPUMImportGuestStateOnDemand() to get it if necessary.
+ *
+ * Will return if CPUMImportGuestStateOnDemand() fails.
+ *
+ * @param   a_pVCpu         The cross context virtual CPU structure of the calling EMT.
+ * @param   a_fExtrnImport  Mask of CPUMCTX_EXTRN_XXX bits to get.
+ * @thread  EMT(a_pVCpu)
+ *
+ * @remarks Requires VMCPU_INCL_CPUM_GST_CTX to be defined.
+ */
+#define CPUM_IMPORT_EXTRN_RET(a_pVCpu, a_fExtrnImport) \
+    do { \
+        if (!((a_pVCpu)->cpum.GstCtx.fExtrn & (a_fExtrnImport))) \
+        { /* already present, consider this likely */ } \
+        else \
+        { \
+            int rcCpumImport = CPUMImportGuestStateOnDemand(a_pVCpu, a_fExtrnImport); \
+            AssertRCReturn(rcCpumImport, rcCpumImport); \
+        } \
+    } while (0)
+
+/** @def CPUM_IMPORT_EXTRN_RC
+ * Macro for making sure the state specified by @a fExtrnImport is present,
+ * calling CPUMImportGuestStateOnDemand() to get it if necessary.
+ *
+ * Will update a_rcStrict if CPUMImportGuestStateOnDemand() fails.
+ *
+ * @param   a_pVCpu         The cross context virtual CPU structure of the calling EMT.
+ * @param   a_fExtrnImport  Mask of CPUMCTX_EXTRN_XXX bits to get.
+ * @param   a_rcStrict      Strict status code variable to update on failure.
+ * @thread  EMT(a_pVCpu)
+ *
+ * @remarks Requires VMCPU_INCL_CPUM_GST_CTX to be defined.
+ */
+#define CPUM_IMPORT_EXTRN_RCSTRICT(a_pVCpu, a_fExtrnImport, a_rcStrict) \
+    do { \
+        if (!((a_pVCpu)->cpum.GstCtx.fExtrn & (a_fExtrnImport))) \
+        { /* already present, consider this likely */ } \
+        else \
+        { \
+            int rcCpumImport = CPUMImportGuestStateOnDemand(a_pVCpu, a_fExtrnImport); \
+            AssertStmt(RT_SUCCESS(rcCpumImport) || RT_FAILURE_NP(a_rcStrict), a_rcStrict = rcCpumImport); \
+        } \
+    } while (0)
+
+VMM_INT_DECL(int) CPUMImportGuestStateOnDemand(PVMCPU pVCpu, uint64_t fExtrnImport);
+/** @} */
+
 #ifndef IPRT_WITHOUT_NAMED_UNIONS_AND_STRUCTS
 
Index: /trunk/src/VBox/VMM/VMMAll/CPUMAllRegs.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/CPUMAllRegs.cpp	(revision 72487)
+++ /trunk/src/VBox/VMM/VMMAll/CPUMAllRegs.cpp	(revision 72488)
@@ -28,4 +28,8 @@
 #include <VBox/vmm/mm.h>
 #include <VBox/vmm/em.h>
+#ifndef IN_RC
+# include <VBox/vmm/nem.h>
+# include <VBox/vmm/hm.h>
+#endif
 #if defined(VBOX_WITH_RAW_MODE) && !defined(IN_RING0)
 # include <VBox/vmm/selm.h>
@@ -42,5 +46,5 @@
 #include <iprt/asm-amd64-x86.h>
 #ifdef IN_RING3
-#include <iprt/thread.h>
+# include <iprt/thread.h>
 #endif
 
@@ -973,4 +977,5 @@
 VMMDECL(uint64_t) CPUMGetGuestCR0(PVMCPU pVCpu)
 {
+    Assert(!(pVCpu->cpum.s.Guest.fExtrn & CPUMCTX_EXTRN_CR0));
     return pVCpu->cpum.s.Guest.cr0;
 }
@@ -979,4 +984,5 @@
 VMMDECL(uint64_t) CPUMGetGuestCR2(PVMCPU pVCpu)
 {
+    Assert(!(pVCpu->cpum.s.Guest.fExtrn & CPUMCTX_EXTRN_CR2));
     return pVCpu->cpum.s.Guest.cr2;
 }
@@ -985,4 +991,5 @@
 VMMDECL(uint64_t) CPUMGetGuestCR3(PVMCPU pVCpu)
 {
+    Assert(!(pVCpu->cpum.s.Guest.fExtrn & CPUMCTX_EXTRN_CR3));
     return pVCpu->cpum.s.Guest.cr3;
 }
@@ -991,4 +998,5 @@
 VMMDECL(uint64_t) CPUMGetGuestCR4(PVMCPU pVCpu)
 {
+    Assert(!(pVCpu->cpum.s.Guest.fExtrn & CPUMCTX_EXTRN_CR4));
     return pVCpu->cpum.s.Guest.cr4;
 }
@@ -1013,4 +1021,5 @@
 VMMDECL(uint32_t) CPUMGetGuestEIP(PVMCPU pVCpu)
 {
+    Assert(!(pVCpu->cpum.s.Guest.fExtrn & CPUMCTX_EXTRN_RIP));
     return pVCpu->cpum.s.Guest.eip;
 }
@@ -1019,4 +1028,5 @@
 VMMDECL(uint64_t) CPUMGetGuestRIP(PVMCPU pVCpu)
 {
+    Assert(!(pVCpu->cpum.s.Guest.fExtrn & CPUMCTX_EXTRN_RIP));
     return pVCpu->cpum.s.Guest.rip;
 }
@@ -2771,2 +2781,39 @@
 }
 
+
+/**
+ * Used to dynamically imports state residing in NEM or HM.
+ *
+ * This is a worker for the CPUM_IMPORT_EXTRN_RET() macro and various IEM ones.
+ *
+ * @returns VBox status code.
+ * @param   pVCpu           The cross context virtual CPU structure of the calling thread.
+ * @param   fExtrnImport    The fields to import.
+ * @thread  EMT(pVCpu)
+ */
+VMM_INT_DECL(int) CPUMImportGuestStateOnDemand(PVMCPU pVCpu, uint64_t fExtrnImport)
+{
+    VMCPU_ASSERT_EMT(pVCpu);
+    if (pVCpu->cpum.s.Guest.fExtrn & fExtrnImport)
+    {
+#ifndef IN_RC
+        switch (pVCpu->cpum.s.Guest.fExtrn & CPUMCTX_EXTRN_KEEPER_MASK)
+        {
+            case CPUMCTX_EXTRN_KEEPER_NEM:
+            {
+                int rc = NEMImportStateOnDemand(pVCpu, &pVCpu->cpum.s.Guest, fExtrnImport);
+                Assert(rc == VINF_SUCCESS || RT_FAILURE_NP(rc));
+                return rc;
+            }
+
+            case CPUMCTX_EXTRN_KEEPER_HM: /** @todo make HM use CPUMCTX_EXTRN_XXX. */
+            default:
+                AssertLogRelMsgFailedReturn(("%#RX64 vs %#RX64\n", pVCpu->cpum.s.Guest.fExtrn, fExtrnImport), VERR_CPUM_IPE_2);
+        }
+#else
+        AssertLogRelMsgFailedReturn(("%#RX64 vs %#RX64\n", pVCpu->cpum.s.Guest.fExtrn, fExtrnImport), VERR_CPUM_IPE_2);
+#endif
+    }
+    return VINF_SUCCESS;
+}
+
Index: /trunk/src/VBox/VMM/VMMAll/IEMAll.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/IEMAll.cpp	(revision 72487)
+++ /trunk/src/VBox/VMM/VMMAll/IEMAll.cpp	(revision 72488)
@@ -13894,38 +13894,4 @@
 #endif /* IEM_WITH_SETJMP */
 
-
-/**
- * Used to dynamically imports state residing in NEM or HM.
- *
- * @returns VBox status code.
- * @param   pVCpu           The cross context virtual CPU structure of the calling thread.
- * @param   pCtx            The CPU context structure.
- * @param   fExtrnImport    The fields to import.
- */
-int iemCtxImport(PVMCPU pVCpu, PCPUMCTX pCtx, uint64_t fExtrnImport)
-{
-    switch (pCtx->fExtrn & CPUMCTX_EXTRN_KEEPER_MASK)
-    {
-#ifndef IN_RC
-        case CPUMCTX_EXTRN_KEEPER_NEM:
-        {
-            int rc = NEMImportStateOnDemand(pVCpu, pCtx, fExtrnImport);
-            Assert(rc == VINF_SUCCESS || RT_FAILURE_NP(rc));
-            return rc;
-        }
-
-        case CPUMCTX_EXTRN_KEEPER_HM: /** @todo make HM use CPUMCTX_EXTRN_XXX. */
-#endif
-
-        default:
-            AssertLogRelMsgFailed(("%RX64\n", fExtrnImport));
-#ifdef IN_RC
-            RT_NOREF_PV(pVCpu); RT_NOREF_PV(fExtrnImport);
-#endif
-            return VERR_IEM_IPE_9;
-    }
-}
-
-
 /** @}  */
 
Index: /trunk/src/VBox/VMM/VMMAll/NEMAllNativeTemplate-win.cpp.h
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/NEMAllNativeTemplate-win.cpp.h	(revision 72487)
+++ /trunk/src/VBox/VMM/VMMAll/NEMAllNativeTemplate-win.cpp.h	(revision 72488)
@@ -1039,4 +1039,6 @@
     /* Almost done, just update extrn flags and maybe change PGM mode. */
     pCtx->fExtrn &= ~fWhat;
+    if (!(pCtx->fExtrn & (CPUMCTX_EXTRN_ALL | (CPUMCTX_EXTRN_NEM_WIN_MASK & ~CPUMCTX_EXTRN_NEM_WIN_EVENT_INJECT))))
+        pCtx->fExtrn = 0;
 
     /* Typical. */
@@ -1050,5 +1052,5 @@
     {
         int rc = PGMChangeMode(pVCpu, pCtx->cr0, pCtx->cr4, pCtx->msrEFER);
-        AssertMsg(rc == VINF_SUCCESS, ("rc=%Rrc\n", rc));
+        AssertMsg(rc == VINF_SUCCESS, ("rc=%Rrc\n", rc)); NOREF(rc);
     }
 
@@ -1056,5 +1058,5 @@
     {
         int rc = PGMFlushTLB(pVCpu, pCtx->cr3, fFlushGlobalTlb);
-        AssertMsg(rc == VINF_SUCCESS, ("rc=%Rrc\n", rc));
+        AssertMsg(rc == VINF_SUCCESS, ("rc=%Rrc\n", rc)); NOREF(rc);
     }
 
@@ -1238,7 +1240,6 @@
 
 
-#ifdef LOG_ENABLED
 /** Macro used by nemHCWinExecStateToLogStr and nemR3WinExecStateToLogStr. */
-# define SWITCH_IT(a_szPrefix) \
+#define SWITCH_IT(a_szPrefix) \
     do \
         switch (u)\
@@ -1256,5 +1257,5 @@
     while (0)
 
-# ifdef NEM_WIN_USE_OUR_OWN_RUN_API
+#ifdef NEM_WIN_USE_OUR_OWN_RUN_API
 /**
  * Translates the execution stat bitfield into a short log string, VID version.
@@ -1275,5 +1276,5 @@
         SWITCH_IT("RM");
 }
-# elif defined(IN_RING3)
+#elif defined(IN_RING3)
 /**
  * Translates the execution stat bitfield into a short log string, WinHv version.
@@ -1294,7 +1295,6 @@
         SWITCH_IT("RM");
 }
-# endif /* IN_RING3 && !NEM_WIN_USE_OUR_OWN_RUN_API */
-# undef SWITCH_IT
-#endif /* LOG_ENABLED */
+#endif /* IN_RING3 && !NEM_WIN_USE_OUR_OWN_RUN_API */
+#undef SWITCH_IT
 
 
@@ -2802,5 +2802,5 @@
     nemR3WinCopyStateFromExceptionMessage(pVCpu, pExit, pCtx, true /*fClearXcpt*/);
     uint64_t fWhat = NEM_WIN_CPUMCTX_EXTRN_MASK_FOR_IEM;
-    if (pMsg->ExceptionVector == X86_XCPT_DB)
+    if (pExit->VpException.ExceptionType == X86_XCPT_DB)
         fWhat |= CPUMCTX_EXTRN_DR0_DR3 | CPUMCTX_EXTRN_DR7 | CPUMCTX_EXTRN_DR6;
     VBOXSTRICTRC rcStrict = nemHCWinImportStateIfNeededStrict(pVCpu, NULL, pCtx, fWhat, "Xcpt");
@@ -3670,5 +3670,5 @@
     /*
      * If the CPU is running, make sure to stop it before we try sync back the
-     * state and return to EM.
+     * state and return to EM.  We don't sync back the whole state if we can help it.
      */
 # ifdef NEM_WIN_USE_OUR_OWN_RUN_API
@@ -3685,29 +3685,51 @@
     if (pCtx->fExtrn & (CPUMCTX_EXTRN_ALL | (CPUMCTX_EXTRN_NEM_WIN_MASK & ~CPUMCTX_EXTRN_NEM_WIN_EVENT_INJECT)))
     {
-# ifdef IN_RING0
-        int rc2 = nemR0WinImportState(pGVM, pGVCpu, pCtx, CPUMCTX_EXTRN_ALL | CPUMCTX_EXTRN_NEM_WIN_MASK);
-        if (RT_SUCCESS(rc2))
-            pCtx->fExtrn = 0;
-        else if (rc2 == VERR_NEM_CHANGE_PGM_MODE || rc2 == VERR_NEM_FLUSH_TLB || rc2 == VERR_NEM_UPDATE_APIC_BASE)
-        {
-            pCtx->fExtrn = 0;
-            if (rcStrict == VINF_SUCCESS || rcStrict == -rc2)
-                rcStrict = -rc2;
-            else
+        /* Try anticipate what we might need. */
+        uint64_t fImport = IEM_CPUMCTX_EXTRN_MUST_MASK | CPUMCTX_EXTRN_NEM_WIN_INHIBIT_INT | CPUMCTX_EXTRN_NEM_WIN_INHIBIT_NMI;
+        if (   (rcStrict >= VINF_EM_FIRST && rcStrict <= VINF_EM_LAST)
+            || RT_FAILURE(rcStrict))
+            fImport = CPUMCTX_EXTRN_ALL | (CPUMCTX_EXTRN_NEM_WIN_MASK & ~CPUMCTX_EXTRN_NEM_WIN_EVENT_INJECT);
+        else if (VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_INTERRUPT_PIC | VMCPU_FF_INTERRUPT_APIC
+                                          | VMCPU_FF_INTERRUPT_NMI | VMCPU_FF_INTERRUPT_SMI))
+            fImport |= IEM_CPUMCTX_EXTRN_XCPT_MASK;
+        if (pCtx->fExtrn & fImport)
+        {
+#ifdef IN_RING0
+            int rc2 = nemR0WinImportState(pGVM, pGVCpu, pCtx, fImport | CPUMCTX_EXTRN_NEM_WIN_EVENT_INJECT);
+            if (RT_SUCCESS(rc2))
+                pCtx->fExtrn &= ~fImport;
+            else if (rc2 == VERR_NEM_CHANGE_PGM_MODE || rc2 == VERR_NEM_FLUSH_TLB || rc2 == VERR_NEM_UPDATE_APIC_BASE)
             {
-                pVCpu->nem.s.rcPending = -rc2;
-                LogFlow(("NEM/%u: rcPending=%Rrc (rcStrict=%Rrc)\n", pVCpu->idCpu, rc2, VBOXSTRICTRC_VAL(rcStrict) ));
+                pCtx->fExtrn &= ~fImport;
+                if (rcStrict == VINF_SUCCESS || rcStrict == -rc2)
+                    rcStrict = -rc2;
+                else
+                {
+                    pVCpu->nem.s.rcPending = -rc2;
+                    LogFlow(("NEM/%u: rcPending=%Rrc (rcStrict=%Rrc)\n", pVCpu->idCpu, rc2, VBOXSTRICTRC_VAL(rcStrict) ));
+                }
             }
-        }
 # else
-        int rc2 = nemHCWinCopyStateFromHyperV(pVM, pVCpu, pCtx, CPUMCTX_EXTRN_ALL | CPUMCTX_EXTRN_NEM_WIN_MASK);
-        if (RT_SUCCESS(rc2))
-            pCtx->fExtrn = 0;
+            int rc2 = nemHCWinCopyStateFromHyperV(pVM, pVCpu, pCtx, fImport | CPUMCTX_EXTRN_NEM_WIN_EVENT_INJECT);
+            if (RT_SUCCESS(rc2))
+                pCtx->fExtrn &= ~fImport;
 # endif
-        else if (RT_SUCCESS(rcStrict))
-            rcStrict = rc2;
+            else if (RT_SUCCESS(rcStrict))
+                rcStrict = rc2;
+            if (!(pCtx->fExtrn & (CPUMCTX_EXTRN_ALL | (CPUMCTX_EXTRN_NEM_WIN_MASK & ~CPUMCTX_EXTRN_NEM_WIN_EVENT_INJECT))))
+                pCtx->fExtrn = 0;
+            STAM_REL_COUNTER_INC(&pVCpu->nem.s.StatImportOnReturn);
+        }
+        else
+        {
+            STAM_REL_COUNTER_INC(&pVCpu->nem.s.StatImportOnReturnSkipped);
+            //pCtx->fExtrn &= ~CPUMCTX_EXTRN_NEM_WIN_EVENT_INJECT;
+        }
     }
     else
+    {
+        STAM_REL_COUNTER_INC(&pVCpu->nem.s.StatImportOnReturnSkipped);
         pCtx->fExtrn = 0;
+    }
 
     LogFlow(("NEM/%u: %04x:%08RX64 efl=%#08RX64 => %Rrc\n",
Index: /trunk/src/VBox/VMM/VMMR0/NEMR0Native-win.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR0/NEMR0Native-win.cpp	(revision 72487)
+++ /trunk/src/VBox/VMM/VMMR0/NEMR0Native-win.cpp	(revision 72488)
@@ -2135,4 +2135,6 @@
     /* Almost done, just update extrn flags and maybe change PGM mode. */
     pCtx->fExtrn &= ~fWhat;
+    if (!(pCtx->fExtrn & (CPUMCTX_EXTRN_ALL | (CPUMCTX_EXTRN_NEM_WIN_MASK & ~CPUMCTX_EXTRN_NEM_WIN_EVENT_INJECT))))
+        pCtx->fExtrn = 0;
 
     /* Typical. */
Index: /trunk/src/VBox/VMM/VMMR3/EM.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR3/EM.cpp	(revision 72487)
+++ /trunk/src/VBox/VMM/VMMR3/EM.cpp	(revision 72488)
@@ -37,4 +37,5 @@
 *********************************************************************************************************************************/
 #define LOG_GROUP LOG_GROUP_EM
+#define VMCPU_INCL_CPUM_GST_CTX /* for CPUM_IMPORT_GUEST_STATE_RET */
 #include <VBox/vmm/em.h>
 #include <VBox/vmm/vmm.h>
@@ -95,5 +96,4 @@
 #endif
 static int emR3RemExecute(PVM pVM, PVMCPU pVCpu, bool *pfFFDone);
-int emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
 
 
@@ -1198,5 +1198,5 @@
             fInREMState = emR3RemExecuteSyncBack(pVM, pVCpu);
 #endif
-            rc = emR3HighPriorityPostForcedActions(pVM, pVCpu, rc);
+            rc = VBOXSTRICTRC_TODO(emR3HighPriorityPostForcedActions(pVM, pVCpu, rc));
         }
 
@@ -1610,11 +1610,12 @@
  * Executes all high priority post execution force actions.
  *
- * @returns rc or a fatal status code.
+ * @returns Strict VBox status code.  Typically @a rc, but may be upgraded to
+ *          fatal error status code.
  *
  * @param   pVM         The cross context VM structure.
  * @param   pVCpu       The cross context virtual CPU structure.
- * @param   rc          The current rc.
+ * @param   rc          The current strict VBox status code rc.
  */
-int emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, int rc)
+VBOXSTRICTRC emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, VBOXSTRICTRC rc)
 {
     VBOXVMM_EM_FF_HIGH(pVCpu, pVM->fGlobalForcedActions, pVCpu->fLocalForcedActions, rc);
@@ -1626,4 +1627,5 @@
     if (VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_HM_UPDATE_CR3))
     {
+        CPUM_IMPORT_EXTRN_RCSTRICT(pVCpu, CPUMCTX_EXTRN_CR0 | CPUMCTX_EXTRN_CR3 | CPUMCTX_EXTRN_CR4 | CPUMCTX_EXTRN_EFER, rc);
         int rc2 = PGMUpdateCR3(pVCpu, CPUMGetGuestCR3(pVCpu));
         if (RT_FAILURE(rc2))
@@ -1635,4 +1637,5 @@
     if (VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_HM_UPDATE_PAE_PDPES))
     {
+        CPUM_IMPORT_EXTRN_RCSTRICT(pVCpu, CPUMCTX_EXTRN_CR0 | CPUMCTX_EXTRN_CR3 | CPUMCTX_EXTRN_CR4 | CPUMCTX_EXTRN_EFER, rc);
         if (CPUMIsGuestInPAEMode(pVCpu))
         {
@@ -1649,9 +1652,9 @@
     /* IEM has pending work (typically memory write after INS instruction). */
     if (VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_IEM))
-        rc = VBOXSTRICTRC_TODO(IEMR3ProcessForceFlag(pVM, pVCpu, rc));
+        rc = IEMR3ProcessForceFlag(pVM, pVCpu, rc);
 
     /* IOM has pending work (comitting an I/O or MMIO write). */
     if (VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_IOM))
-        rc = VBOXSTRICTRC_TODO(IOMR3ProcessForceFlag(pVM, pVCpu, rc));
+        rc = IOMR3ProcessForceFlag(pVM, pVCpu, rc);
 
 #ifdef VBOX_WITH_RAW_MODE
@@ -1829,4 +1832,5 @@
         if (VM_FF_IS_PENDING(pVM, VM_FF_EMT_RENDEZVOUS))
         {
+            CPUM_IMPORT_EXTRN_RCSTRICT(pVCpu, ~CPUMCTX_EXTRN_KEEPER_MASK, rc);
             rc2 = VMMR3EmtRendezvousFF(pVM, pVCpu);
             UPDATE_RC();
@@ -1876,4 +1880,5 @@
             || VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_DBGF) )
         {
+            CPUM_IMPORT_EXTRN_RCSTRICT(pVCpu, ~CPUMCTX_EXTRN_KEEPER_MASK, rc);
             rc2 = DBGFR3VMMForcedAction(pVM, pVCpu);
             UPDATE_RC();
@@ -1885,4 +1890,5 @@
         if (VM_FF_TEST_AND_CLEAR(pVM, VM_FF_RESET))
         {
+            CPUM_IMPORT_EXTRN_RCSTRICT(pVCpu, ~CPUMCTX_EXTRN_KEEPER_MASK, rc);
             rc2 = VBOXSTRICTRC_TODO(VMR3ResetFF(pVM));
             UPDATE_RC();
@@ -1896,9 +1902,8 @@
             &&  VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_CSAM_SCAN_PAGE))
         {
-            PCPUMCTX pCtx = pVCpu->em.s.pCtx;
-
             /** @todo check for 16 or 32 bits code! (D bit in the code selector) */
             Log(("Forced action VMCPU_FF_CSAM_SCAN_PAGE\n"));
-
+            CPUM_IMPORT_EXTRN_RCSTRICT(pVCpu, ~CPUMCTX_EXTRN_KEEPER_MASK, rc);
+            PCPUMCTX pCtx = pVCpu->em.s.pCtx;
             CSAMR3CheckCodeEx(pVM, pCtx, pCtx->eip);
             VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_CSAM_SCAN_PAGE);
@@ -1945,4 +1950,5 @@
         if (VM_FF_IS_PENDING(pVM, VM_FF_EMT_RENDEZVOUS))
         {
+            CPUM_IMPORT_EXTRN_RCSTRICT(pVCpu, ~CPUMCTX_EXTRN_KEEPER_MASK, rc);
             rc2 = VMMR3EmtRendezvousFF(pVM, pVCpu);
             UPDATE_RC();
@@ -1965,4 +1971,5 @@
         if (VM_FF_IS_PENDING_EXCEPT(pVM, VM_FF_REQUEST, VM_FF_PGM_NO_MEMORY))
         {
+            CPUM_IMPORT_EXTRN_RCSTRICT(pVCpu, ~CPUMCTX_EXTRN_KEEPER_MASK, rc);
             rc2 = VMR3ReqProcessU(pVM->pUVM, VMCPUID_ANY, false /*fPriorityOnly*/);
             if (rc2 == VINF_EM_OFF || rc2 == VINF_EM_TERMINATE) /** @todo this shouldn't be necessary */
@@ -2019,4 +2026,5 @@
         if (VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_REQUEST))
         {
+            CPUM_IMPORT_EXTRN_RCSTRICT(pVCpu, ~CPUMCTX_EXTRN_KEEPER_MASK, rc);
             rc2 = VMR3ReqProcessU(pVM->pUVM, pVCpu->idCpu, false /*fPriorityOnly*/);
             if (rc2 == VINF_EM_OFF || rc2 == VINF_EM_TERMINATE || rc2 == VINF_EM_RESET)
@@ -2079,4 +2087,5 @@
             &&  !VM_FF_IS_PENDING(pVM, VM_FF_PGM_NO_MEMORY))
         {
+            CPUM_ASSERT_NOT_EXTRN(pVCpu, CPUMCTX_EXTRN_RIP);
             if (CPUMGetGuestRIP(pVCpu) != EMGetInhibitInterruptsPC(pVCpu))
             {
@@ -2108,7 +2117,7 @@
                     {
                         fWakeupPending = true;
-#ifdef VBOX_STRICT
+# ifdef VBOX_STRICT
                         rcIrq = rc2;
-#endif
+# endif
                     }
                     if (fResched)
@@ -2118,4 +2127,5 @@
 #endif
                 {
+                    CPUM_ASSERT_NOT_EXTRN(pVCpu, CPUMCTX_EXTRN_RFLAGS);
                     if (   VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_INTERRUPT_PIC)
 #ifdef VBOX_WITH_NESTED_HWVIRT_SVM
@@ -2130,4 +2140,5 @@
                         /* Note: it's important to make sure the return code from TRPMR3InjectEvent isn't ignored! */
                         /** @todo this really isn't nice, should properly handle this */
+                        CPUM_IMPORT_EXTRN_RET(pVCpu, IEM_CPUMCTX_EXTRN_XCPT_MASK);
                         rc2 = TRPMR3InjectEvent(pVM, pVCpu, TRPM_HARDWARE_INT);
                         Log(("EM: TRPMR3InjectEvent -> %d\n", rc2));
@@ -2165,4 +2176,5 @@
             && !VM_FF_IS_PENDING(pVM, VM_FF_PGM_NO_MEMORY) )
         {
+            CPUM_IMPORT_EXTRN_RCSTRICT(pVCpu, ~CPUMCTX_EXTRN_KEEPER_MASK, rc);
             rc2 = DBGFR3VMMForcedAction(pVM, pVCpu);
             UPDATE_RC();
@@ -2175,4 +2187,5 @@
             && VM_FF_IS_PENDING(pVM, VM_FF_EMT_RENDEZVOUS))
         {
+            CPUM_IMPORT_EXTRN_RCSTRICT(pVCpu, ~CPUMCTX_EXTRN_KEEPER_MASK, rc);
             rc2 = VMMR3EmtRendezvousFF(pVM, pVCpu);
             UPDATE_RC();
Index: /trunk/src/VBox/VMM/VMMR3/EMHM.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR3/EMHM.cpp	(revision 72487)
+++ /trunk/src/VBox/VMM/VMMR3/EMHM.cpp	(revision 72488)
@@ -21,4 +21,5 @@
 *********************************************************************************************************************************/
 #define LOG_GROUP LOG_GROUP_EM
+#define VMCPU_INCL_CPUM_GST_CTX
 #include <VBox/vmm/em.h>
 #include <VBox/vmm/vmm.h>
@@ -129,5 +130,5 @@
             || VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_HIGH_PRIORITY_POST_MASK))
         {
-            rcStrict = emR3HighPriorityPostForcedActions(pVM, pVCpu, VBOXSTRICTRC_TODO(rcStrict));
+            rcStrict = emR3HighPriorityPostForcedActions(pVM, pVCpu, rcStrict);
             LogFlow(("EMR3HmSingleInstruction: FFs after -> %Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
         }
@@ -468,5 +469,5 @@
         if (    VM_FF_IS_PENDING(pVM, VM_FF_HIGH_PRIORITY_POST_MASK)
             ||  VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_HIGH_PRIORITY_POST_MASK))
-            rc = emR3HighPriorityPostForcedActions(pVM, pVCpu, rc);
+            rc = VBOXSTRICTRC_TODO(emR3HighPriorityPostForcedActions(pVM, pVCpu, rc));
 
         /*
Index: /trunk/src/VBox/VMM/VMMR3/EMR3Nem.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR3/EMR3Nem.cpp	(revision 72487)
+++ /trunk/src/VBox/VMM/VMMR3/EMR3Nem.cpp	(revision 72488)
@@ -21,4 +21,5 @@
 *********************************************************************************************************************************/
 #define LOG_GROUP LOG_GROUP_EM
+#define VMCPU_INCL_CPUM_GST_CTX
 #include <VBox/vmm/em.h>
 #include <VBox/vmm/vmm.h>
@@ -74,5 +75,5 @@
 
 /**
- * Executes instruction in HM mode if we can.
+ * Executes instruction in NEM mode if we can.
  *
  * This is somewhat comparable to REMR3EmulateInstruction.
@@ -90,11 +91,11 @@
 VBOXSTRICTRC emR3NemSingleInstruction(PVM pVM, PVMCPU pVCpu, uint32_t fFlags)
 {
-    PCPUMCTX pCtx = pVCpu->em.s.pCtx;
+    Assert(pVCpu->em.s.pCtx == &pVCpu->cpum.GstCtx);
     Assert(!(fFlags & ~EM_ONE_INS_FLAGS_MASK));
 
-    if (!NEMR3CanExecuteGuest(pVM, pVCpu, pCtx))
+    if (!NEMR3CanExecuteGuest(pVM, pVCpu, &pVCpu->cpum.GstCtx))
         return VINF_EM_RESCHEDULE;
 
-    uint64_t const uOldRip = pCtx->rip;
+    uint64_t const uOldRip = pVCpu->cpum.GstCtx.rip;
     for (;;)
     {
@@ -105,5 +106,5 @@
             || VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_HIGH_PRIORITY_PRE_RAW_MASK))
         {
-            VBOXSTRICTRC rcStrict = emR3NemForcedActions(pVM, pVCpu, pCtx);
+            VBOXSTRICTRC rcStrict = emR3NemForcedActions(pVM, pVCpu, &pVCpu->cpum.GstCtx);
             if (rcStrict != VINF_SUCCESS)
             {
@@ -129,5 +130,5 @@
             || VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_HIGH_PRIORITY_POST_MASK))
         {
-            rcStrict = emR3HighPriorityPostForcedActions(pVM, pVCpu, VBOXSTRICTRC_TODO(rcStrict));
+            rcStrict = emR3HighPriorityPostForcedActions(pVM, pVCpu, rcStrict);
             LogFlow(("emR3NemSingleInstruction: FFs after -> %Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
         }
@@ -135,5 +136,5 @@
         if (rcStrict != VINF_SUCCESS && (rcStrict < VINF_EM_FIRST || rcStrict > VINF_EM_LAST))
         {
-            rcStrict = emR3NemHandleRC(pVM, pVCpu, pCtx, VBOXSTRICTRC_TODO(rcStrict));
+            rcStrict = emR3NemHandleRC(pVM, pVCpu, &pVCpu->cpum.GstCtx, VBOXSTRICTRC_TODO(rcStrict));
             Log(("emR3NemSingleInstruction: emR3NemHandleRC -> %Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
         }
@@ -142,11 +143,14 @@
          * Done?
          */
+        CPUM_ASSERT_NOT_EXTRN(pVCpu, CPUMCTX_EXTRN_RIP);
         if (   (rcStrict != VINF_SUCCESS && rcStrict != VINF_EM_DBG_STEPPED)
             || !(fFlags & EM_ONE_INS_FLAGS_RIP_CHANGE)
-            || pCtx->rip != uOldRip)
-        {
-            if (rcStrict == VINF_SUCCESS && pCtx->rip != uOldRip)
+            || pVCpu->cpum.GstCtx.rip != uOldRip)
+        {
+            if (rcStrict == VINF_SUCCESS && pVCpu->cpum.GstCtx.rip != uOldRip)
                 rcStrict = VINF_EM_DBG_STEPPED;
-            Log(("emR3NemSingleInstruction: returns %Rrc (rip %llx -> %llx)\n", VBOXSTRICTRC_VAL(rcStrict), uOldRip, pCtx->rip));
+            Log(("emR3NemSingleInstruction: returns %Rrc (rip %llx -> %llx)\n",
+                 VBOXSTRICTRC_VAL(rcStrict), uOldRip, pVCpu->cpum.GstCtx.rip));
+            CPUM_IMPORT_EXTRN_RET(pVCpu, ~CPUMCTX_EXTRN_KEEPER_MASK);
             return rcStrict;
         }
@@ -172,5 +176,5 @@
 #endif
 {
-#ifdef LOG_ENABLED
+#if defined(LOG_ENABLED)
     PCPUMCTX pCtx = pVCpu->em.s.pCtx;
 #endif
@@ -195,4 +199,5 @@
      */
     STAM_PROFILE_START(&pVCpu->em.s.StatIEMEmu, a);
+    CPUM_IMPORT_EXTRN_RET(pVCpu, IEM_CPUMCTX_EXTRN_MUST_MASK);
     rc = VBOXSTRICTRC_TODO(IEMExecOne(pVCpu));
     STAM_PROFILE_STOP(&pVCpu->em.s.StatIEMEmu, a);
@@ -203,4 +208,5 @@
 #ifdef VBOX_WITH_REM
         STAM_PROFILE_START(&pVCpu->em.s.StatREMEmu, b);
+        CPUM_IMPORT_EXTRN_RET(pVCpu, ~CPUMCTX_EXTRN_KEEPER_MASK);
         EMRemLock(pVM);
         /* Flush the recompiler TLB if the VCPU has changed. */
@@ -216,9 +222,4 @@
 #endif /* !VBOX_WITH_REM */
     }
-
-#ifdef EM_NOTIFY_HM
-    if (pVCpu->em.s.enmState == EMSTATE_DEBUG_GUEST_HM)
-        HMR3NotifyEmulated(pVCpu);
-#endif
     return rc;
 }
@@ -278,4 +279,5 @@
      * Hand it over to the interpreter.
      */
+    CPUM_IMPORT_EXTRN_RET(pVCpu, IEM_CPUMCTX_EXTRN_MUST_MASK);
     VBOXSTRICTRC rcStrict = IEMExecOne(pVCpu);
     LogFlow(("emR3NemExecuteIOInstruction: %Rrc\n", VBOXSTRICTRC_VAL(rcStrict)));
@@ -443,7 +445,7 @@
          */
         VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_RESUME_GUEST_MASK);
-        if (    VM_FF_IS_PENDING(pVM, VM_FF_HIGH_PRIORITY_POST_MASK)
-            ||  VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_HIGH_PRIORITY_POST_MASK))
-            rcStrict = emR3HighPriorityPostForcedActions(pVM, pVCpu, VBOXSTRICTRC_TODO(rcStrict));
+        if (   VM_FF_IS_PENDING(pVM, VM_FF_HIGH_PRIORITY_POST_MASK)
+            || VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_HIGH_PRIORITY_POST_MASK))
+            rcStrict = emR3HighPriorityPostForcedActions(pVM, pVCpu, rcStrict);
 
         /*
@@ -478,6 +480,14 @@
 
     /*
-     * Return to outer loop.
-     */
+     * Return to outer loop, making sure the fetch all state as we leave.
+     *
+     * Note! Not using CPUM_IMPORT_EXTRN_RET here, to prioritize an rcStrict error
+     *       status over import errors.
+     */
+    if (pCtx->fExtrn)
+    {
+        int rcImport = NEMImportStateOnDemand(pVCpu, pCtx, pCtx->fExtrn);
+        AssertReturn(RT_SUCCESS(rcImport) || RT_FAILURE_NP(rcStrict), rcImport);
+    }
 #if defined(LOG_ENABLED) && defined(DEBUG)
     RTLogFlush(NULL);
Index: /trunk/src/VBox/VMM/VMMR3/EMRaw.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR3/EMRaw.cpp	(revision 72487)
+++ /trunk/src/VBox/VMM/VMMR3/EMRaw.cpp	(revision 72488)
@@ -21,4 +21,5 @@
 *********************************************************************************************************************************/
 #define LOG_GROUP LOG_GROUP_EM
+#define VMCPU_INCL_CPUM_GST_CTX
 #include <VBox/vmm/em.h>
 #include <VBox/vmm/vmm.h>
@@ -140,5 +141,5 @@
      * Deal with the return code.
      */
-    rc = emR3HighPriorityPostForcedActions(pVM, pVCpu, rc);
+    rc = VBOXSTRICTRC_TODO(emR3HighPriorityPostForcedActions(pVM, pVCpu, rc));
     rc = emR3RawHandleRC(pVM, pVCpu, pCtx, rc);
     rc = emR3RawUpdateForceFlag(pVM, pVCpu, pCtx, rc);
@@ -220,5 +221,5 @@
      * Deal with the return codes.
      */
-    rc = emR3HighPriorityPostForcedActions(pVM, pVCpu, rc);
+    rc = VBOXSTRICTRC_TODO(emR3HighPriorityPostForcedActions(pVM, pVCpu, rc));
     rc = emR3RawHandleRC(pVM, pVCpu, pCtx, rc);
     rc = emR3RawUpdateForceFlag(pVM, pVCpu, pCtx, rc);
@@ -1426,5 +1427,5 @@
         if (    VM_FF_IS_PENDING(pVM, VM_FF_HIGH_PRIORITY_POST_MASK)
             ||  VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_HIGH_PRIORITY_POST_MASK))
-            rc = emR3HighPriorityPostForcedActions(pVM, pVCpu, rc);
+            rc = VBOXSTRICTRC_TODO(emR3HighPriorityPostForcedActions(pVM, pVCpu, rc));
 
 #ifdef VBOX_STRICT
Index: /trunk/src/VBox/VMM/VMMR3/NEMR3Native-win.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR3/NEMR3Native-win.cpp	(revision 72487)
+++ /trunk/src/VBox/VMM/VMMR3/NEMR3Native-win.cpp	(revision 72488)
@@ -1235,4 +1235,6 @@
                             STAMR3RegisterF(pVM, &pNemCpu->StatBreakOnStatus,       STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Number of status code breaks",           "/NEM/CPU%u/BreakOnStatus", iCpu);
                             STAMR3RegisterF(pVM, &pNemCpu->StatImportOnDemand,      STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Number of on-demand state imports",      "/NEM/CPU%u/ImportOnDemand", iCpu);
+                            STAMR3RegisterF(pVM, &pNemCpu->StatImportOnReturn,      STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Number of state imports on loop return", "/NEM/CPU%u/ImportOnReturn", iCpu);
+                            STAMR3RegisterF(pVM, &pNemCpu->StatImportOnReturnSkipped, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Number of skipped state imports on loop return", "/NEM/CPU%u/ImportOnReturnSkipped", iCpu);
                         }
 
Index: /trunk/src/VBox/VMM/include/EMHandleRCTmpl.h
===================================================================
--- /trunk/src/VBox/VMM/include/EMHandleRCTmpl.h	(revision 72487)
+++ /trunk/src/VBox/VMM/include/EMHandleRCTmpl.h	(revision 72488)
@@ -46,4 +46,6 @@
 #endif
 {
+    NOREF(pCtx);
+
     switch (rc)
     {
@@ -111,7 +113,5 @@
             AssertReleaseMsgFailed(("%Rrc handling is not yet implemented\n", rc));
             break;
-#endif /* EMHANDLERC_WITH_PATM */
-
-#ifdef EMHANDLERC_WITH_PATM
+
         /*
          * Memory mapped I/O access - attempt to patch the instruction
@@ -166,4 +166,5 @@
          */
         case VINF_PGM_CHANGE_MODE:
+            CPUM_ASSERT_NOT_EXTRN(pVCpu, CPUMCTX_EXTRN_CR0 | CPUMCTX_EXTRN_CR3 | CPUMCTX_EXTRN_CR4 | CPUMCTX_EXTRN_EFER);
             rc = PGMChangeMode(pVCpu, pCtx->cr0, pCtx->cr4, pCtx->msrEFER);
             if (rc == VINF_SUCCESS)
@@ -240,42 +241,6 @@
          */
         case VINF_GIM_R3_HYPERCALL:
-        {
-            /*
-             * Currently hypercall instruction (vmmcall) emulation is compiled and
-             * implemented only when nested hw. virt feature is enabled in IEM.
-             *
-             * On Intel or when nested hardware virtualization support isn't compiled
-             * we still need to implement hypercalls rather than throw a #UD.
-             */
-#ifdef VBOX_WITH_NESTED_HWVIRT_SVM
-            if (pVM->cpum.ro.GuestFeatures.fSvm)
-            {
-                rc = emR3ExecuteInstruction(pVM, pVCpu, "Hypercall");
-                break;
-            }
-#endif
-            /** @todo IEM/REM need to handle VMCALL/VMMCALL, see
-             *        @bugref{7270#c168}. */
-            uint8_t cbInstr = 0;
-            VBOXSTRICTRC rcStrict = GIMExecHypercallInstr(pVCpu, pCtx, &cbInstr);
-            if (rcStrict == VINF_SUCCESS)
-            {
-                Assert(cbInstr);
-                pCtx->rip += cbInstr;
-                /* Update interrupt inhibition. */
-                if (   VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_INHIBIT_INTERRUPTS)
-                    && pCtx->rip != EMGetInhibitInterruptsPC(pVCpu))
-                    VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INHIBIT_INTERRUPTS);
-                rc = VINF_SUCCESS;
-            }
-            else if (rcStrict == VINF_GIM_HYPERCALL_CONTINUING)
-                rc = VINF_SUCCESS;
-            else
-            {
-                Assert(rcStrict != VINF_GIM_R3_HYPERCALL);
-                rc = VBOXSTRICTRC_VAL(rcStrict);
-            }
-            break;
-        }
+            rc = emR3ExecuteInstruction(pVM, pVCpu, "Hypercall");
+            break;
 
 #ifdef EMHANDLERC_WITH_HM
@@ -308,7 +273,5 @@
             rc = emR3ExecuteInstruction(pVM, pVCpu, "TSS FAULT: ");
             break;
-#endif
-
-#ifdef EMHANDLERC_WITH_PATM
+
         case VINF_PATM_PENDING_IRQ_AFTER_IRET:
             rc = emR3ExecuteInstruction(pVM, pVCpu, "EMUL: ", VINF_PATM_PENDING_IRQ_AFTER_IRET);
@@ -324,4 +287,5 @@
 
         case VINF_EM_RAW_INJECT_TRPM_EVENT:
+            CPUM_IMPORT_EXTRN_RET(pVCpu, IEM_CPUMCTX_EXTRN_XCPT_MASK);
             rc = VBOXSTRICTRC_VAL(IEMInjectTrpmEvent(pVCpu));
             /* The following condition should be removed when IEM_IMPLEMENTS_TASKSWITCH becomes true. */
Index: /trunk/src/VBox/VMM/include/EMInternal.h
===================================================================
--- /trunk/src/VBox/VMM/include/EMInternal.h	(revision 72487)
+++ /trunk/src/VBox/VMM/include/EMInternal.h	(revision 72488)
@@ -474,5 +474,5 @@
 EMSTATE emR3Reschedule(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
 int     emR3ForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
-int     emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, int rc);
+VBOXSTRICTRC emR3HighPriorityPostForcedActions(PVM pVM, PVMCPU pVCpu, VBOXSTRICTRC rc);
 
 int     emR3RawUpdateForceFlag(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, int rc);
Index: /trunk/src/VBox/VMM/include/IEMInternal.h
===================================================================
--- /trunk/src/VBox/VMM/include/IEMInternal.h	(revision 72487)
+++ /trunk/src/VBox/VMM/include/IEMInternal.h	(revision 72488)
@@ -813,5 +813,5 @@
         else \
         { \
-            int rcCtxImport = iemCtxImport(a_pVCpu, a_pCtx, a_fExtrnImport); \
+            int rcCtxImport = CPUMImportGuestStateOnDemand(a_pVCpu, a_fExtrnImport); \
             AssertRCReturn(rcCtxImport, rcCtxImport); \
         } \
@@ -833,5 +833,5 @@
         else \
         { \
-            int rcCtxImport = iemCtxImport(a_pVCpu, a_pCtx, a_fExtrnImport); \
+            int rcCtxImport = CPUMImportGuestStateOnDemand(a_pVCpu, a_fExtrnImport); \
             AssertLogRelRC(rcCtxImport); \
         } \
@@ -855,10 +855,9 @@
         else \
         { \
-            int rcCtxImport = iemCtxImport(a_pVCpu, a_pCtx, a_fExtrnImport); \
+            int rcCtxImport = CPUMImportGuestStateOnDemand(a_pVCpu, a_fExtrnImport); \
             AssertRCStmt(rcCtxImport, longjmp(*pVCpu->iem.s.CTX_SUFF(pJmpBuf), rcCtxImport)); \
         } \
     } while (0)
 
-int iemCtxImport(PVMCPU pVCpu, PCPUMCTX pCtx, uint64_t fExtrnImport);
 
 
Index: /trunk/src/VBox/VMM/include/NEMInternal.h
===================================================================
--- /trunk/src/VBox/VMM/include/NEMInternal.h	(revision 72487)
+++ /trunk/src/VBox/VMM/include/NEMInternal.h	(revision 72488)
@@ -272,4 +272,6 @@
     STAMCOUNTER                 StatBreakOnStatus;
     STAMCOUNTER                 StatImportOnDemand;
+    STAMCOUNTER                 StatImportOnReturn;
+    STAMCOUNTER                 StatImportOnReturnSkipped;
     /** @} */
 #endif /* RT_OS_WINDOWS */
