Index: /trunk/src/VBox/VMM/PGM.cpp
===================================================================
--- /trunk/src/VBox/VMM/PGM.cpp	(revision 31065)
+++ /trunk/src/VBox/VMM/PGM.cpp	(revision 31066)
@@ -3118,5 +3118,6 @@
     }
     /* Override the shadow mode is nested paging is active. */
-    if (HWACCMIsNestedPagingActive(pVM))
+    pVM->pgm.s.fNestedPaging = HWACCMIsNestedPagingActive(pVM);
+    if (pVM->pgm.s.fNestedPaging)
         enmShadowMode = HWACCMGetShwPagingMode(pVM);
 
Index: /trunk/src/VBox/VMM/PGMBth.h
===================================================================
--- /trunk/src/VBox/VMM/PGMBth.h	(revision 31065)
+++ /trunk/src/VBox/VMM/PGMBth.h	(revision 31066)
@@ -136,7 +136,8 @@
           || PGM_GST_TYPE == PGM_TYPE_PROT))
 
-    PVM pVM   = pVCpu->pVMR3;
-
-    Assert(!HWACCMIsNestedPagingActive(pVM));
+    PVM pVM = pVCpu->pVMR3;
+
+    Assert(HWACCMIsNestedPagingActive(pVM) == pVM->pgm.s.fNestedPaging);
+    Assert(!pVM->pgm.s.fNestedPaging);
 
     pgmLock(pVM);
Index: /trunk/src/VBox/VMM/PGMGstDefs.h
===================================================================
--- /trunk/src/VBox/VMM/PGMGstDefs.h	(revision 31065)
+++ /trunk/src/VBox/VMM/PGMGstDefs.h	(revision 31066)
@@ -84,5 +84,5 @@
 #  define GST_IS_NX_ACTIVE(pVCpu)               (CPUMIsGuestNXEnabled(pVCpu)) /** @todo shadow this variable */
 #  if PGM_GST_TYPE == PGM_TYPE_PROT             /* (comment at top of PGMAllBth.h) */
-#   define BTH_IS_NP_ACTIVE(pVM)                HWACCMIsNestedPagingActive(pVM)
+#   define BTH_IS_NP_ACTIVE(pVM)                (pVM->pgm.s.fNestedPaging)
 #  else
 #   define BTH_IS_NP_ACTIVE(pVM)                (false)
Index: /trunk/src/VBox/VMM/PGMInternal.h
===================================================================
--- /trunk/src/VBox/VMM/PGMInternal.h	(revision 31065)
+++ /trunk/src/VBox/VMM/PGMInternal.h	(revision 31066)
@@ -2646,16 +2646,10 @@
      * This is used  */
     bool                            fLessThan52PhysicalAddressBits;
-    /** Alignment padding. */
-    bool                            afAlignment0[1];
-
-    /*
-     * This will be redefined at least two more times before we're done, I'm sure.
-     * The current code is only to get on with the coding.
-     *   - 2004-06-10: initial version, bird.
-     *   - 2004-07-02: 1st time, bird.
-     *   - 2004-10-18: 2nd time, bird.
-     *   - 2005-07-xx: 3rd time, bird.
-     */
-
+    /** Set when nested paging is active.
+     * This is meant to save calls to HWACCMIsNestedPagingActive and let the
+     * compilers optimize the code better.  Whether we use nested paging or
+     * not is something we find out during VMM initialization and we won't
+     * change this later on. */
+    bool                            fNestedPaging;
     /** The host paging mode. (This is what SUPLib reports.) */
     SUPPAGINGMODE                   enmHostMode;
@@ -3645,9 +3639,5 @@
 int             pgmMapDeactivateCR3(PVM pVM, PPGMPOOLPAGE pShwPageCR3);
 
-int             pgmShwSyncPaePDPtr(PVMCPU pVCpu, RTGCPTR GCPtr, PX86PDPE pGstPdpe, PX86PDPAE *ppPD);
-#ifndef IN_RC
-int             pgmShwSyncLongModePDPtr(PVMCPU pVCpu, RTGCPTR64 GCPtr, PX86PML4E pGstPml4e, PX86PDPE pGstPdpe, PX86PDPAE *ppPD);
-#endif
-int             pgmShwGetEPTPDPtr(PVMCPU pVCpu, RTGCPTR64 GCPtr, PEPTPDPT *ppPdpt, PEPTPD *ppPD);
+int             pgmShwSyncPaePDPtr(PVMCPU pVCpu, RTGCPTR GCPtr, PCX86PDPE pGstPdpe, PX86PDPAE *ppPD);
 
 int             pgmGstLazyMap32BitPD(PVMCPU pVCpu, PX86PD *ppPd);
Index: /trunk/src/VBox/VMM/PGMShw.h
===================================================================
--- /trunk/src/VBox/VMM/PGMShw.h	(revision 31065)
+++ /trunk/src/VBox/VMM/PGMShw.h	(revision 31066)
@@ -188,5 +188,6 @@
     PPGMPOOL     pPool     = pVM->pgm.s.CTX_SUFF(pPool);
 
-    Assert(HWACCMIsNestedPagingActive(pVM));
+    Assert(HWACCMIsNestedPagingActive(pVM) == pVM->pgm.s.fNestedPaging);
+    Assert(pVM->pgm.s.fNestedPaging);
     Assert(!pVCpu->pgm.s.pShwPageCR3R3);
 
Index: /trunk/src/VBox/VMM/VMMAll/PGMAll.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/PGMAll.cpp	(revision 31065)
+++ /trunk/src/VBox/VMM/VMMAll/PGMAll.cpp	(revision 31066)
@@ -70,4 +70,9 @@
 DECLINLINE(int) pgmShwGetLongModePDPtr(PVMCPU pVCpu, RTGCPTR64 GCPtr, PX86PML4E *ppPml4e, PX86PDPT *ppPdpt, PX86PDPAE *ppPD);
 DECLINLINE(int) pgmShwGetPaePoolPagePD(PPGMCPU pPGM, RTGCPTR GCPtr, PPGMPOOLPAGE *ppShwPde);
+#ifndef IN_RC
+static int      pgmShwSyncLongModePDPtr(PVMCPU pVCpu, RTGCPTR64 GCPtr, PCX86PML4E pGstPml4e, PCX86PDPE pGstPdpe, PX86PDPAE *ppPD);
+static int      pgmShwGetEPTPDPtr(PVMCPU pVCpu, RTGCPTR64 GCPtr, PEPTPDPT *ppPdpt, PEPTPD *ppPD);
+#endif
+
 
 /*
@@ -623,5 +628,6 @@
     }
 
-    if (!HWACCMIsNestedPagingActive(pVM))
+    Assert(HWACCMIsNestedPagingActive(pVM) == pVM->pgm.s.fNestedPaging);
+    if (!pVM->pgm.s.fNestedPaging)
     {
         /*
@@ -912,5 +918,5 @@
  * @param   ppPD        Receives address of page directory
  */
-int pgmShwSyncPaePDPtr(PVMCPU pVCpu, RTGCPTR GCPtr, PX86PDPE pGstPdpe, PX86PDPAE *ppPD)
+int pgmShwSyncPaePDPtr(PVMCPU pVCpu, RTGCPTR GCPtr, PCX86PDPE pGstPdpe, PX86PDPAE *ppPD)
 {
     const unsigned iPdPt    = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE;
@@ -930,4 +936,6 @@
         RTGCPTR64   GCPdPt;
         PGMPOOLKIND enmKind;
+        Assert(pGstPdpe);
+        X86PDPE     GstPdpe = *pGstPdpe;
 
 # if defined(IN_RC)
@@ -936,5 +944,6 @@
 # endif
 
-        if (HWACCMIsNestedPagingActive(pVM) || !CPUMIsGuestPagingEnabled(pVCpu))
+        Assert(HWACCMIsNestedPagingActive(pVM) == pVM->pgm.s.fNestedPaging);
+        if (pVM->pgm.s.fNestedPaging || !CPUMIsGuestPagingEnabled(pVCpu))
         {
             /* AMD-V nested paging or real/protected mode without paging. */
@@ -944,9 +953,7 @@
         else
         {
-            Assert(pGstPdpe);
-
             if (CPUMGetGuestCR4(pVCpu) & X86_CR4_PAE)
             {
-                if (!pGstPdpe->n.u1Present)
+                if (!GstPdpe.n.u1Present)
                 {
                     /* PD not present; guest must reload CR3 to change it.
@@ -955,11 +962,11 @@
                     Assert(!HWACCMIsEnabled(pVM));
 
-                    GCPdPt  = pGstPdpe->u & X86_PDPE_PG_MASK;
+                    GCPdPt  = GstPdpe.u & X86_PDPE_PG_MASK;
                     enmKind = PGMPOOLKIND_PAE_PD_PHYS;
-                    pGstPdpe->n.u1Present = 1;
+                    GstPdpe.n.u1Present = 1;
                 }
                 else
                 {
-                    GCPdPt  = pGstPdpe->u & X86_PDPE_PG_MASK;
+                    GCPdPt  = GstPdpe.u & X86_PDPE_PG_MASK;
                     enmKind = PGMPOOLKIND_PAE_PD_FOR_PAE_PD;
                 }
@@ -978,5 +985,5 @@
         /* The PD was cached or created; hook it up now. */
         pPdpe->u |= pShwPage->Core.Key
-                 | (pGstPdpe->u & ~(X86_PDPE_PG_MASK | X86_PDPE_AVL_MASK | X86_PDPE_PCD | X86_PDPE_PWT));
+                 | (GstPdpe.u & ~(X86_PDPE_PG_MASK | X86_PDPE_AVL_MASK | X86_PDPE_PCD | X86_PDPE_PWT));
 
 # if defined(IN_RC)
@@ -1051,5 +1058,5 @@
  * @param   ppPD        Receives address of page directory
  */
-int pgmShwSyncLongModePDPtr(PVMCPU pVCpu, RTGCPTR64 GCPtr, PX86PML4E pGstPml4e, PX86PDPE pGstPdpe, PX86PDPAE *ppPD)
+static int pgmShwSyncLongModePDPtr(PVMCPU pVCpu, RTGCPTR64 GCPtr, PCX86PML4E pGstPml4e, PCX86PDPE pGstPdpe, PX86PDPAE *ppPD)
 {
     PPGMCPU        pPGM          = &pVCpu->pgm.s;
@@ -1058,5 +1065,6 @@
     const unsigned iPml4         = (GCPtr >> X86_PML4_SHIFT) & X86_PML4_MASK;
     PX86PML4E      pPml4e        = pgmShwGetLongModePML4EPtr(pPGM, iPml4);
-    bool           fNestedPagingOrNoGstPaging = HWACCMIsNestedPagingActive(pVM) || !CPUMIsGuestPagingEnabled(pVCpu);
+    Assert(HWACCMIsNestedPagingActive(pVM) == pVM->pgm.s.fNestedPaging);
+    bool           fNestedPagingOrNoGstPaging = pVM->pgm.s.fNestedPaging || !CPUMIsGuestPagingEnabled(pVCpu);
     PPGMPOOLPAGE   pShwPage;
     int            rc;
@@ -1201,5 +1209,5 @@
  * @param   ppPD        Receives address of page directory
  */
-int pgmShwGetEPTPDPtr(PVMCPU pVCpu, RTGCPTR64 GCPtr, PEPTPDPT *ppPdpt, PEPTPD *ppPD)
+static int pgmShwGetEPTPDPtr(PVMCPU pVCpu, RTGCPTR64 GCPtr, PEPTPDPT *ppPdpt, PEPTPD *ppPD)
 {
     PPGMCPU        pPGM  = &pVCpu->pgm.s;
@@ -1212,5 +1220,6 @@
     int            rc;
 
-    Assert(HWACCMIsNestedPagingActive(pVM));
+    Assert(HWACCMIsNestedPagingActive(pVM) == pVM->pgm.s.fNestedPaging);
+    Assert(pVM->pgm.s.fNestedPaging);
     Assert(PGMIsLockOwner(pVM));
 
@@ -1829,5 +1838,6 @@
 
     /* We assume we're only called in nested paging mode. */
-    Assert(HWACCMIsNestedPagingActive(pVM) || pVCpu->pgm.s.enmShadowMode == PGMMODE_EPT);
+    Assert(HWACCMIsNestedPagingActive(pVM) == pVM->pgm.s.fNestedPaging);
+    Assert(pVM->pgm.s.fNestedPaging || pVCpu->pgm.s.enmShadowMode == PGMMODE_EPT);
     Assert(pVM->pgm.s.fMappingsDisabled);
     Assert(!(pVCpu->pgm.s.fSyncFlags & PGM_SYNC_MONITOR_CR3));
Index: /trunk/src/VBox/VMM/VMMAll/PGMAllBth.h
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/PGMAllBth.h	(revision 31065)
+++ /trunk/src/VBox/VMM/VMMAll/PGMAllBth.h	(revision 31066)
@@ -906,5 +906,6 @@
                         RTGCPHYS GCPhys2;
                         uint64_t fPageGst;
-                        if (!HWACCMIsNestedPagingActive(pVM))
+                        Assert(HWACCMIsNestedPagingActive(pVM) == pVM->pgm.s.fNestedPaging);
+                        if (!pVM->pgm.s.fNestedPaging)
                         {
                             rc = PGMGstGetPage(pVCpu, pvFault, &fPageGst, &GCPhys2);
@@ -1124,10 +1125,10 @@
     unsigned        iPDSrc = 0;
 #  if PGM_GST_TYPE == PGM_TYPE_PAE
-    X86PDPE         PdpeSrc;
-    PX86PDPAE       pPDSrc      = pgmGstGetPaePDPtr(pVCpu, GCPtrPage, &iPDSrc, &PdpeSrc);
+    X86PDPE         PdpeSrcIgn;
+    PX86PDPAE       pPDSrc      = pgmGstGetPaePDPtr(pVCpu, GCPtrPage, &iPDSrc, &PdpeSrcIgn);
 #  else /* AMD64 */
-    PX86PML4E       pPml4eSrc;
-    X86PDPE         PdpeSrc;
-    PX86PDPAE       pPDSrc      = pgmGstGetLongModePDPtr(pVCpu, GCPtrPage, &pPml4eSrc, &PdpeSrc, &iPDSrc);
+    PX86PML4E       pPml4eSrcIgn;
+    X86PDPE         PdpeSrcIgn;
+    PX86PDPAE       pPDSrc      = pgmGstGetLongModePDPtr(pVCpu, GCPtrPage, &pPml4eSrcIgn, &PdpeSrcIgn, &iPDSrc);
 #  endif
     GSTPDE          PdeSrc;
@@ -2079,5 +2080,6 @@
     if (PdeDst.n.u1Size)
     {
-        Assert(HWACCMIsNestedPagingActive(pVM));
+        Assert(HWACCMIsNestedPagingActive(pVM) == pVM->pgm.s.fNestedPaging);
+        Assert(pVM->pgm.s.fNestedPaging);
         Log(("CPU%d: SyncPage: Pde (big:%RX64) at %RGv changed behind our back!\n", pVCpu->idCpu, PdeDst.u, GCPtrPage));
         return VINF_SUCCESS;
@@ -3459,5 +3461,6 @@
     LogFlow(("VerifyAccessSyncPage: GCPtrPage=%RGv fPage=%#x uErr=%#x\n", GCPtrPage, fPage, uErr));
 
-    Assert(!HWACCMIsNestedPagingActive(pVM));
+    Assert(HWACCMIsNestedPagingActive(pVM) == pVM->pgm.s.fNestedPaging);
+    Assert(!pVM->pgm.s.fNestedPaging);
 #if   (   PGM_GST_TYPE == PGM_TYPE_32BIT \
        || PGM_GST_TYPE == PGM_TYPE_REAL \
@@ -4651,5 +4654,6 @@
            && PGM_GST_TYPE != PGM_TYPE_PROT))
 
-    Assert(!HWACCMIsNestedPagingActive(pVM));
+    Assert(HWACCMIsNestedPagingActive(pVM) == pVM->pgm.s.fNestedPaging);
+    Assert(!pVM->pgm.s.fNestedPaging);
 
     /*
@@ -4798,5 +4802,6 @@
 
 #  if PGM_GST_TYPE != PGM_TYPE_REAL
-    Assert(!HWACCMIsNestedPagingActive(pVM));
+    Assert(HWACCMIsNestedPagingActive(pVM) == pVM->pgm.s.fNestedPaging);
+    Assert(!pVM->pgm.s.fNestedPaging);
 #  endif
 
Index: /trunk/src/VBox/VMM/VMMAll/PGMAllPool.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMAll/PGMAllPool.cpp	(revision 31065)
+++ /trunk/src/VBox/VMM/VMMAll/PGMAllPool.cpp	(revision 31066)
@@ -3124,5 +3124,5 @@
         case PGMPOOLKIND_EPT_PD_FOR_PHYS:
         {
-            Assert(HWACCMIsNestedPagingActive(pVM));
+            Assert(pVM->pgm.s.fNestedPaging);
 
             const uint64_t  u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PDE4M_P | X86_PDE4M_PS;
@@ -3158,5 +3158,5 @@
         case PGMPOOLKIND_PAE_PD_PHYS:
         {
-            Assert(HWACCMIsNestedPagingActive(pVM));
+            Assert(pVM->pgm.s.fNestedPaging);
 
             const uint64_t  u64 = PGM_PAGE_GET_HCPHYS(pPhysPage) | X86_PDE4M_P | X86_PDE4M_PS;
