Index: trunk/src/VBox/VMM/VMMAll/PGMAllBth.h
===================================================================
--- trunk/src/VBox/VMM/VMMAll/PGMAllBth.h	(revision 26711)
+++ trunk/src/VBox/VMM/VMMAll/PGMAllBth.h	(revision 26717)
@@ -2939,4 +2939,5 @@
     if (rc != VINF_SUCCESS)
     {
+        STAM_PROFILE_STOP(&pVCpu->pgm.s.CTX_MID_Z(Stat,SyncPT), a);
         AssertRC(rc);
         return rc;
@@ -2955,26 +2956,48 @@
 
 # if (PGM_SHW_TYPE == PGM_TYPE_EPT) && (HC_ARCH_BITS == 64) && defined(RT_OS_WINDOWS)
-    if (PGMIsUsingLargePages(pVM))
-    {
-        RTHCPHYS HCPhys;
-        rc = pgmPhysAllocLargePage(pVM, GCPtrPage & SHW_PDE_PG_MASK, &HCPhys);
+    {
+        PPGMPAGE pPage;
+
+        /* Check if we allocated a big page before for this 2 MB range. */
+        int rc = pgmPhysGetPageEx(&pVM->pgm.s, GCPtrPage & X86_PDE2M_PAE_PG_MASK, &pPage);
         if (RT_SUCCESS(rc))
         {
-            PdeDst.u &= X86_PDE_AVL_MASK;
-            PdeDst.u |= HCPhys;
-            PdeDst.n.u1Present   = 1;
-            PdeDst.n.u1Write     = 1;
-            PdeDst.n.u1Execute   = 1;
-            PdeDst.b.u1Size      = 1;
-            PdeDst.b.u1IgnorePAT = 1;
-            PdeDst.b.u3EMT       = VMX_EPT_MEMTYPE_WB;
-            ASMAtomicWriteSize(pPdeDst, PdeDst.u);
-
-            STAM_PROFILE_STOP(&pVCpu->pgm.s.CTX_MID_Z(Stat,SyncPT), a);
-            return VINF_SUCCESS;
-
+            RTHCPHYS HCPhys = NIL_RTHCPHYS;
+
+            if (PGM_PAGE_GET_PDE_TYPE(pPage) == PGM_PAGE_PDE_TYPE_PDE)
+            {
+                AssertRelease(PGM_PAGE_GET_STATE(pPage) == PGM_PAGE_STATE_ALLOCATED);
+                HCPhys = PGM_PAGE_GET_HCPHYS(pPage);
+            }
+            else
+            if (PGMIsUsingLargePages(pVM))
+            {
+                rc = pgmPhysAllocLargePage(pVM, GCPtrPage);
+                if (RT_SUCCESS(rc))
+                {
+                    Assert(PGM_PAGE_GET_STATE(pPage) == PGM_PAGE_STATE_ALLOCATED);
+                    Assert(PGM_PAGE_GET_PDE_TYPE(pPage) == PGM_PAGE_PDE_TYPE_PDE);
+                    HCPhys = PGM_PAGE_GET_HCPHYS(pPage);
+                }
+                else
+                    LogFlow(("pgmPhysAllocLargePage failed with %Rrc\n", rc));
+            }
+
+            if (HCPhys != NIL_RTHCPHYS)
+            {
+                PdeDst.u &= X86_PDE_AVL_MASK;
+                PdeDst.u |= HCPhys;
+                PdeDst.n.u1Present   = 1;
+                PdeDst.n.u1Write     = 1;
+                PdeDst.n.u1Execute   = 1;
+                PdeDst.b.u1Size      = 1;
+                PdeDst.b.u1IgnorePAT = 1;
+                PdeDst.b.u3EMT       = VMX_EPT_MEMTYPE_WB;
+                ASMAtomicWriteSize(pPdeDst, PdeDst.u);
+
+                STAM_PROFILE_STOP(&pVCpu->pgm.s.CTX_MID_Z(Stat,SyncPT), a);
+                return VINF_SUCCESS;
+            }
         }
-        else
-            LogFlow(("pgmPhysAllocLargePage failed with %Rrc\n", rc));
     }
 # endif
Index: trunk/src/VBox/VMM/VMMAll/PGMAllPhys.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMAll/PGMAllPhys.cpp	(revision 26711)
+++ trunk/src/VBox/VMM/VMMAll/PGMAllPhys.cpp	(revision 26717)
@@ -371,7 +371,5 @@
         &&  PGM_PAGE_GET_TYPE(pPage) == PGMPAGETYPE_RAM)
     {
-        RTHCPHYS HCPhysDummy;
-
-        int rc = pgmPhysAllocLargePage(pVM, GCPhys, &HCPhysDummy);
+        int rc = pgmPhysAllocLargePage(pVM, GCPhys);
         if (rc == VINF_SUCCESS)
             return rc;
@@ -468,10 +466,9 @@
  * @param   pVM         The VM address.
  * @param   GCPhys      The address of the page.
- * @param   pHCPhys     Pointer to HC physical address (out)
  *
  * @remarks Must be called from within the PGM critical section. It may
  *          nip back to ring-3/0 in some cases.
  */
-int pgmPhysAllocLargePage(PVM pVM, RTGCPHYS GCPhys, RTHCPHYS *pHCPhys)
+int pgmPhysAllocLargePage(PVM pVM, RTGCPHYS GCPhys)
 {
     RTGCPHYS GCPhysBase = GCPhys & X86_PDE2M_PAE_PG_MASK;
@@ -483,6 +480,4 @@
     Assert(PGMIsLocked(pVM));
     Assert(PGMIsUsingLargePages(pVM));
-    Assert((GCPhys & X86_PD_PAE_MASK) == 0);
-    AssertPtr(pHCPhys);
 
     PPGMPAGE pPage;
@@ -491,16 +486,9 @@
         &&  PGM_PAGE_GET_TYPE(pPage) == PGMPAGETYPE_RAM)
     {
-        RTHCPHYS HCPhys = NIL_RTHCPHYS;
         unsigned uPDEType = PGM_PAGE_GET_PDE_TYPE(pPage);
 
-        if  (uPDEType == PGM_PAGE_PDE_TYPE_PDE)
-        {
-            /* Previously allocated 2 MB range can be reused. */
-            Assert(PGM_PAGE_GET_STATE(pPage) == PGM_PAGE_STATE_ALLOCATED);
-
-            *pHCPhys = PGM_PAGE_GET_HCPHYS(pPage);
-            return VINF_SUCCESS;
-        }
-        else
+        /* Don't call this function for already allocated pages. */
+        Assert(uPDEType != PGM_PAGE_PDE_TYPE_PDE); 
+
         if  (   uPDEType == PGM_PAGE_PDE_TYPE_DONTCARE
              && PGM_PAGE_GET_STATE(pPage) == PGM_PAGE_STATE_ZERO)
@@ -547,5 +535,4 @@
                 {   
                     Assert(PGM_PAGE_GET_STATE(pPage) == PGM_PAGE_STATE_ALLOCATED);
-                    *pHCPhys = PGM_PAGE_GET_HCPHYS(pPage);
                     STAM_COUNTER_INC(&pVM->pgm.s.StatLargePageUsed);
                     return VINF_SUCCESS;
