Index: /trunk/include/VBox/vm.h
===================================================================
--- /trunk/include/VBox/vm.h	(revision 31358)
+++ /trunk/include/VBox/vm.h	(revision 31359)
@@ -102,4 +102,6 @@
     /** The native thread handle. */
     RTNATIVETHREAD          hNativeThread;
+    /** The native R0 thread handle. (different from the R3 handle!) */
+    RTNATIVETHREAD          hNativeThreadR0;
     /** Which host CPU ID is this EMT running on.
      * Only valid when in RC or HWACCMR0 with scheduling disabled. */
@@ -114,5 +116,5 @@
      *          following it (to grow into and align the struct size).
      *   */
-    uint8_t                 abAlignment1[HC_ARCH_BITS == 32 ? 28 : 12];
+    uint8_t                 abAlignment1[HC_ARCH_BITS == 32 ? 24 : 4];
 
     /** CPUM part. */
Index: /trunk/include/VBox/vm.mac
===================================================================
--- /trunk/include/VBox/vm.mac	(revision 31358)
+++ /trunk/include/VBox/vm.mac	(revision 31359)
@@ -120,4 +120,5 @@
 
     .hNativeThread          RTR0PTR_RES 1
+    .hNativeThreadR0        RTR0PTR_RES 1
     .idHostCpu              resd 1
 
Index: /trunk/src/VBox/VMM/VMMAll/VMMAll.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/VMMAll.cpp	(revision 31358)
+++ /trunk/src/VBox/VMM/VMMAll/VMMAll.cpp	(revision 31359)
@@ -61,19 +61,4 @@
         return 0;
 
-    /* Search first by host cpu id (most common case)
-     * and then by native thread id (page fusion case).
-     */
-    /* RTMpCpuId had better be cheap. */ 
-    RTCPUID idHostCpu = RTMpCpuId(); 
-
-    /** @todo optimize for large number of VCPUs when that becomes more common. */
-    for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
-    {
-        PVMCPU pVCpu = &pVM->aCpus[idCpu];
-
-        if (pVCpu->idHostCpu == idHostCpu)
-            return pVCpu->idCpu;
-    }
-
     /* RTThreadGetNativeSelf had better be cheap. */
     RTNATIVETHREAD hThread = RTThreadNativeSelf();
@@ -84,5 +69,5 @@
         PVMCPU pVCpu = &pVM->aCpus[idCpu];
 
-        if (pVCpu->hNativeThread == hThread)
+        if (pVCpu->hNativeThreadR0 == hThread)
             return pVCpu->idCpu;
     }
@@ -115,20 +100,4 @@
         return &pVM->aCpus[0];
 
-    /* Search first by host cpu id (most common case)
-     * and then by native thread id (page fusion case).
-     */
-
-    /* RTMpCpuId had better be cheap. */ 
-    RTCPUID idHostCpu = RTMpCpuId(); 
-
-    /** @todo optimize for large number of VCPUs when that becomes more common. */
-    for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
-    {
-        PVMCPU pVCpu = &pVM->aCpus[idCpu];
-
-        if (pVCpu->idHostCpu == idHostCpu)
-            return pVCpu;
-    }
-
     /* RTThreadGetNativeSelf had better be cheap. */
     RTNATIVETHREAD hThread = RTThreadNativeSelf();
@@ -139,5 +108,5 @@
         PVMCPU pVCpu = &pVM->aCpus[idCpu];
 
-        if (pVCpu->hNativeThread == hThread)
+        if (pVCpu->hNativeThreadR0 == hThread)
             return pVCpu;
     }
Index: /trunk/src/VBox/VMM/VMMR0/VMMR0.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR0/VMMR0.cpp	(revision 31358)
+++ /trunk/src/VBox/VMM/VMMR0/VMMR0.cpp	(revision 31359)
@@ -965,4 +965,7 @@
             PVMCPU pVCpu = &pVM->aCpus[idCpu];
 
+            if (pVCpu->hNativeThreadR0 == NIL_RTNATIVETHREAD)
+                pVCpu->hNativeThreadR0 = RTThreadNativeSelf();
+
             /* Make sure that log flushes can jump back to ring-3; annoying to get an incomplete log (this is risky though as the code doesn't take this into account). */
             int rc = GMMR0CheckSharedModulesStart(pVM);
