Index: trunk/src/VBox/VMM/VMMAll/IEMAllCImplSvmInstr.cpp.h
===================================================================
--- trunk/src/VBox/VMM/VMMAll/IEMAllCImplSvmInstr.cpp.h	(revision 68361)
+++ trunk/src/VBox/VMM/VMMAll/IEMAllCImplSvmInstr.cpp.h	(revision 68362)
@@ -96,9 +96,4 @@
 IEM_STATIC VBOXSTRICTRC iemSvmVmexit(PVMCPU pVCpu, PCPUMCTX pCtx, uint64_t uExitCode, uint64_t uExitInfo1, uint64_t uExitInfo2)
 {
-#ifndef IN_RING3
-    RT_NOREF(pVCpu, pCtx, uExitCode, uExitInfo1, uExitInfo2);
-    AssertMsgFailed(("iemSvmVmexit: Bad context\n"));
-    return VERR_INTERNAL_ERROR_5;
-#else
     if (   CPUMIsGuestInSvmNestedHwVirtMode(pCtx)
         || uExitCode == SVM_EXIT_INVALID)
@@ -261,5 +256,4 @@
     AssertMsgFailed(("iemSvmVmexit: Unexpected SVM-exit failure uExitCode=%#RX64\n", uExitCode));
     return VERR_SVM_IPE_5;
-#endif
 }
 
@@ -282,8 +276,4 @@
 IEM_STATIC VBOXSTRICTRC iemSvmVmrun(PVMCPU pVCpu, PCPUMCTX pCtx, uint8_t cbInstr, RTGCPHYS GCPhysVmcb)
 {
-#ifndef IN_RING3
-    RT_NOREF(pVCpu, pCtx, cbInstr, GCPhysVmcb);
-    return VINF_EM_RESCHEDULE_REM;
-#else
     PVM pVM = pVCpu->CTX_SUFF(pVM);
     LogFlow(("iemSvmVmrun\n"));
@@ -637,5 +627,4 @@
     Log(("iemSvmVmrun: Failed to read nested-guest VMCB at %#RGp (rc=%Rrc) -> #VMEXIT\n", GCPhysVmcb, rc));
     return rc;
-#endif
 }
 
@@ -934,5 +923,4 @@
     Log3(("iemSvmHandleIOIntercept: u16Port=%#x (%u)\n", u16Port, u16Port));
 
-#if 1
     SVMIOIOEXITINFO IoExitInfo;
     PCPUMCTX pCtx = IEM_GET_CTX(pVCpu);
@@ -945,50 +933,4 @@
         return iemSvmVmexit(pVCpu, pCtx, SVM_EXIT_IOIO, IoExitInfo.u, pCtx->rip + cbInstr);
     }
-#else
-    /*
-     * The IOPM layout:
-     * Each bit represents one 8-bit port. That makes a total of 0..65535 bits or
-     * two 4K pages.
-     *
-     * For IO instructions that access more than a single byte, the permission bits
-     * for all bytes are checked; if any bit is set to 1, the IO access is intercepted.
-     *
-     * Since it's possible to do a 32-bit IO access at port 65534 (accessing 4 bytes),
-     * we need 3 extra bits beyond the second 4K page.
-     */
-    PCPUMCTX pCtx = IEM_GET_CTX(pVCpu);
-    static const uint16_t s_auSizeMasks[] = { 0, 1, 3, 0, 0xf, 0, 0, 0 };
-
-    uint16_t const offIopm   = u16Port >> 3;
-    uint16_t const fSizeMask = s_auSizeMasks[(cAddrSizeBits >> SVM_IOIO_OP_SIZE_SHIFT) & 7];
-    uint8_t  const cShift    = u16Port - (offIopm << 3);
-    uint16_t const fIopmMask = (1 << cShift) | (fSizeMask << cShift);
-
-    uint8_t const *pbIopm = (uint8_t *)pCtx->hwvirt.svm.CTX_SUFF(pvIoBitmap);
-    Assert(pbIopm);
-    pbIopm += offIopm;
-    uint16_t const u16Iopm = *(uint16_t *)pbIopm;
-    if (u16Iopm & fIopmMask)
-    {
-        static const uint32_t s_auIoOpSize[] =
-        { SVM_IOIO_32_BIT_OP, SVM_IOIO_8_BIT_OP, SVM_IOIO_16_BIT_OP, 0, SVM_IOIO_32_BIT_OP, 0, 0, 0 };
-
-        static const uint32_t s_auIoAddrSize[] =
-        { 0, SVM_IOIO_16_BIT_ADDR, SVM_IOIO_32_BIT_ADDR, 0, SVM_IOIO_64_BIT_ADDR, 0, 0, 0 };
-
-        SVMIOIOEXITINFO IoExitInfo;
-        IoExitInfo.u         = s_auIoOpSize[cbReg & 7];
-        IoExitInfo.u        |= s_auIoAddrSize[(cAddrSizeBits >> 4) & 7];
-        IoExitInfo.n.u1STR   = iemSvmVmexitfStrIo;
-        IoExitInfo.n.u1REP   = fRep;
-        IoExitInfo.n.u3SEG   = iEffSeg & 7;
-        IoExitInfo.n.u1Type  = enmIoType;
-        IoExitInfo.n.u16Port = u16Port;
-
-        Log3(("iemSvmHandleIOIntercept: u16Port=%#x (%u) offIoPm=%u fSizeMask=%#x cShift=%u fIopmMask=%#x -> #VMEXIT\n",
-              u16Port, u16Port, offIopm, fSizeMask, cShift, fIopmMask));
-        return iemSvmVmexit(pVCpu, pCtx, SVM_EXIT_IOIO, IoExitInfo.u, pCtx->rip + cbInstr);
-    }
-#endif
 
     /** @todo remove later (for debugging as VirtualBox always traps all IO
@@ -1066,7 +1008,7 @@
 IEM_CIMPL_DEF_0(iemCImpl_vmrun)
 {
-#ifndef IN_RING3
+#if defined(VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM) && !defined(IN_RING3)
     RT_NOREF2(pVCpu, cbInstr);
-    return VINF_EM_RESCHEDULE_REM;
+    return VINF_EM_RAW_EMULATE_INSTR;
 #else
     LogFlow(("iemCImpl_vmrun\n"));
@@ -1129,5 +1071,5 @@
 IEM_CIMPL_DEF_0(iemCImpl_vmload)
 {
-#ifndef IN_RING3
+#if defined(VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM) && !defined(IN_RING3)
     RT_NOREF2(pVCpu, cbInstr);
     return VINF_EM_RAW_EMULATE_INSTR;
@@ -1184,5 +1126,5 @@
 IEM_CIMPL_DEF_0(iemCImpl_vmsave)
 {
-#ifndef IN_RING3
+#if defined(VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM) && !defined(IN_RING3)
     RT_NOREF2(pVCpu, cbInstr);
     return VINF_EM_RAW_EMULATE_INSTR;
@@ -1242,7 +1184,7 @@
 IEM_CIMPL_DEF_0(iemCImpl_clgi)
 {
-#ifndef IN_RING3
+#if defined(VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM) && !defined(IN_RING3)
     RT_NOREF2(pVCpu, cbInstr);
-    return VINF_EM_RESCHEDULE_REM;
+    return VINF_EM_RAW_EMULATE_INSTR;
 #else
     LogFlow(("iemCImpl_clgi\n"));
@@ -1257,5 +1199,6 @@
     pCtx->hwvirt.svm.fGif = 0;
     iemRegAddToRipAndClearRF(pVCpu, cbInstr);
-# if defined(VBOX_WITH_NESTED_HWVIRT) && defined(VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM) && defined(IN_RING3)
+
+# if defined(VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM) && defined(IN_RING3)
     return EMR3SetExecutionPolicy(pVCpu->CTX_SUFF(pVM)->pUVM, EMEXECPOLICY_IEM_ALL, true);
 # else
@@ -1271,7 +1214,7 @@
 IEM_CIMPL_DEF_0(iemCImpl_stgi)
 {
-#ifndef IN_RING3
+#if defined(VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM) && !defined(IN_RING3)
     RT_NOREF2(pVCpu, cbInstr);
-    return VINF_EM_RESCHEDULE_REM;
+    return VINF_EM_RAW_EMULATE_INSTR;
 #else
     LogFlow(("iemCImpl_stgi\n"));
@@ -1286,5 +1229,6 @@
     pCtx->hwvirt.svm.fGif = 1;
     iemRegAddToRipAndClearRF(pVCpu, cbInstr);
-# if defined(VBOX_WITH_NESTED_HWVIRT) && defined(VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM) && defined(IN_RING3)
+
+# if defined(VBOX_WITH_NESTED_HWVIRT_ONLY_IN_IEM) && defined(IN_RING3)
     return EMR3SetExecutionPolicy(pVCpu->CTX_SUFF(pVM)->pUVM, EMEXECPOLICY_IEM_ALL, false);
 # else
