Index: /trunk/include/VBox/vmm/em.h
===================================================================
--- /trunk/include/VBox/vmm/em.h	(revision 48369)
+++ /trunk/include/VBox/vmm/em.h	(revision 48370)
@@ -200,4 +200,5 @@
 VMM_INT_DECL(int)               EMInterpretWrmsr(PVM pVM, PVMCPU pVCpu, PCPUMCTXCORE pRegFrame);
 VMM_INT_DECL(bool)              EMShouldContinueAfterHalt(PVMCPU pVCpu, PCPUMCTX pCtx);
+VMM_INT_DECL(bool)              EMMonitorWaitShouldContinue(PVMCPU pVCpu, PCPUMCTX pCtx);
 VMM_INT_DECL(int)               EMMonitorWaitPrepare(PVMCPU pVCpu, uint64_t rax, uint64_t rcx, uint64_t rdx, RTGCPHYS GCPhys);
 VMM_INT_DECL(int)               EMMonitorWaitPerform(PVMCPU pVCpu, uint64_t rax, uint64_t rcx);
Index: /trunk/src/VBox/VMM/VMMAll/EMAll.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/EMAll.cpp	(revision 48369)
+++ /trunk/src/VBox/VMM/VMMAll/EMAll.cpp	(revision 48370)
@@ -219,14 +219,13 @@
 
 /**
- * Determine if we should continue after encountering a hlt or mwait
- * instruction.
+ * Determine if we should continue after encountering a mwait instruction.
  *
  * Clears MWAIT flags if returning @c true.
  *
- * @returns boolean
+ * @returns true if we should continue, false if we should halt.
  * @param   pVCpu           Pointer to the VMCPU.
  * @param   pCtx            Current CPU context.
  */
-VMM_INT_DECL(bool) EMShouldContinueAfterHalt(PVMCPU pVCpu, PCPUMCTX pCtx)
+VMM_INT_DECL(bool) EMMonitorWaitShouldContinue(PVMCPU pVCpu, PCPUMCTX pCtx)
 {
     if (   pCtx->eflags.Bits.u1IF
@@ -234,8 +233,26 @@
             ==                            (EMMWAIT_FLAG_ACTIVE | EMMWAIT_FLAG_BREAKIRQIF0)) )
     {
-        pVCpu->em.s.MWait.fWait &= ~(EMMWAIT_FLAG_ACTIVE | EMMWAIT_FLAG_BREAKIRQIF0);
+        if (VMCPU_FF_IS_PENDING(pVCpu, (VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_INTERRUPT_PIC)))
+        {
+            pVCpu->em.s.MWait.fWait &= ~(EMMWAIT_FLAG_ACTIVE | EMMWAIT_FLAG_BREAKIRQIF0);
+            return true;
+        }
+    }
+
+    return false;
+}
+
+
+/**
+ * Determine if we should continue after encountering a hlt instruction.
+ *
+ * @returns true if we should continue, false if we should halt.
+ * @param   pVCpu           Pointer to the VMCPU.
+ * @param   pCtx            Current CPU context.
+ */
+VMM_INT_DECL(bool) EMShouldContinueAfterHalt(PVMCPU pVCpu, PCPUMCTX pCtx)
+{
+    if (pCtx->eflags.Bits.u1IF)
         return !!VMCPU_FF_IS_PENDING(pVCpu, (VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_INTERRUPT_PIC));
-    }
-
     return false;
 }
Index: /trunk/src/VBox/VMM/VMMR0/HMSVMR0.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR0/HMSVMR0.cpp	(revision 48369)
+++ /trunk/src/VBox/VMM/VMMR0/HMSVMR0.cpp	(revision 48370)
@@ -4012,5 +4012,5 @@
 
         if (   rc == VINF_EM_HALT
-            && EMShouldContinueAfterHalt(pVCpu, pCtx))
+            && EMMonitorWaitShouldContinue(pVCpu, pCtx))
         {
             rc = VINF_SUCCESS;
Index: /trunk/src/VBox/VMM/VMMR0/HMVMXR0.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR0/HMVMXR0.cpp	(revision 48369)
+++ /trunk/src/VBox/VMM/VMMR0/HMVMXR0.cpp	(revision 48370)
@@ -8953,5 +8953,5 @@
 
         if (   rc == VINF_EM_HALT
-            && EMShouldContinueAfterHalt(pVCpu, pMixedCtx))
+            && EMMonitorWaitShouldContinue(pVCpu, pMixedCtx))
         {
             rc = VINF_SUCCESS;
Index: /trunk/src/VBox/VMM/VMMR3/EM.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR3/EM.cpp	(revision 48369)
+++ /trunk/src/VBox/VMM/VMMR3/EM.cpp	(revision 48370)
@@ -2514,8 +2514,14 @@
                 {
                     STAM_REL_PROFILE_START(&pVCpu->em.s.StatHalted, y);
+                    /* If HM (or someone else) store a pending interrupt in
+                       TRPM, it must be dispatched ASAP without any halting.
+                       Anything pending in TRPM has been accepted and the CPU
+                       should already be the right state to receive it. */
+                    if (TRPMHasTrap(pVCpu))
+                        rc = VINF_EM_RESCHEDULE;
                     /* MWAIT has a special extension where it's woken up when
                        an interrupt is pending even when IF=0. */
-                    if (   (pVCpu->em.s.MWait.fWait & (EMMWAIT_FLAG_ACTIVE | EMMWAIT_FLAG_BREAKIRQIF0))
-                        ==                            (EMMWAIT_FLAG_ACTIVE | EMMWAIT_FLAG_BREAKIRQIF0))
+                    else if (   (pVCpu->em.s.MWait.fWait & (EMMWAIT_FLAG_ACTIVE | EMMWAIT_FLAG_BREAKIRQIF0))
+                             ==                            (EMMWAIT_FLAG_ACTIVE | EMMWAIT_FLAG_BREAKIRQIF0))
                     {
                         rc = VMR3WaitHalted(pVM, pVCpu, false /*fIgnoreInterrupts*/);
@@ -2527,6 +2533,4 @@
                         }
                     }
-                    else if (TRPMHasTrap(pVCpu))
-                        rc = VINF_EM_RESCHEDULE;
                     else
                         rc = VMR3WaitHalted(pVM, pVCpu, !(CPUMGetGuestEFlags(pVCpu) & X86_EFL_IF));
