VirtualBox

Changeset 96978 in vbox


Ignore:
Timestamp:
Oct 4, 2022 11:37:47 AM (2 years ago)
Author:
vboxsync
Message:

VMM/PGMAll.cpp: pgmGetCr3MaskForMode array optimization. bugref:10092

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/PGMAll.cpp

    r96900 r96978  
    6464DECLINLINE(int) pgmGstMapCr3(PVMCPUCC pVCpu, RTGCPHYS GCPhysCr3, PRTHCPTR pHCPtrGuestCr3);
    6565#ifdef VBOX_WITH_NESTED_HWVIRT_VMX_EPT
    66 static int pgmGstSlatWalk(PVMCPUCC pVCpu, RTGCPHYS GCPhysNested, bool fIsLinearAddrValid, RTGCPTR GCPtrNested, PPGMPTWALK pWalk,
    67                           PPGMPTWALKGST pGstWalk);
     66static int pgmGstSlatWalk(PVMCPUCC pVCpu, RTGCPHYS GCPhysNested, bool fIsLinearAddrValid, RTGCPTR GCPtrNested,
     67                          PPGMPTWALK pWalk, PPGMPTWALKGST pGstWalk);
    6868static int pgmGstSlatWalkPhys(PVMCPUCC pVCpu, PGMSLAT enmSlatMode, RTGCPHYS GCPhysNested, PPGMPTWALK pWalk,
    6969                              PPGMPTWALKGST pGstWalk);
     
    7676
    7777
     78/*
     79 * Second level transation - EPT.
     80 */
    7881#ifdef VBOX_WITH_NESTED_HWVIRT_VMX_EPT
    7982# define PGM_SLAT_TYPE               PGM_SLAT_TYPE_EPT
     
    902905
    903906
    904 /**
    905  * Gets the CR3 mask corresponding to the given paging mode.
     907/** Mask array used by pgmGetCr3MaskForMode.
     908 * X86_CR3_AMD64_PAGE_MASK is used for modes that doesn't have a CR3 or EPTP. */
     909static uint64_t const g_auCr3MaskForMode[PGMMODE_MAX] =
     910{
     911    /* [PGMMODE_INVALID] = */           X86_CR3_AMD64_PAGE_MASK,
     912    /* [PGMMODE_REAL] = */              X86_CR3_AMD64_PAGE_MASK,
     913    /* [PGMMODE_PROTECTED] = */         X86_CR3_AMD64_PAGE_MASK,
     914    /* [PGMMODE_32_BIT] = */            X86_CR3_PAGE_MASK,
     915    /* [PGMMODE_PAE] = */               X86_CR3_PAE_PAGE_MASK,
     916    /* [PGMMODE_PAE_NX] = */            X86_CR3_PAE_PAGE_MASK,
     917    /* [PGMMODE_AMD64] = */             X86_CR3_AMD64_PAGE_MASK,
     918    /* [PGMMODE_AMD64_NX] = */          X86_CR3_AMD64_PAGE_MASK,
     919    /* [PGMMODE_NESTED_32BIT = */       X86_CR3_PAGE_MASK,
     920    /* [PGMMODE_NESTED_PAE] = */        X86_CR3_PAE_PAGE_MASK,
     921    /* [PGMMODE_NESTED_AMD64] = */      X86_CR3_AMD64_PAGE_MASK,
     922    /* [PGMMODE_EPT] = */               X86_CR3_EPT_PAGE_MASK,
     923    /* [PGMMODE_NONE] = */              X86_CR3_AMD64_PAGE_MASK,
     924};
     925
     926
     927/**
     928 * Gets the physical address mask for CR3 in the given paging mode.
     929 *
     930 * The mask is for eliminating flags and other stuff in CR3/EPTP when
     931 * extracting the physical address.  It is not for validating whether there are
     932 * reserved bits set.  PGM ASSUMES that whoever loaded the CR3 value and passed
     933 * it to PGM checked for reserved bits, including reserved physical address
     934 * bits.
    906935 *
    907936 * @returns The CR3 mask.
     
    911940DECLINLINE(uint64_t) pgmGetCr3MaskForMode(PGMMODE enmMode, PGMSLAT enmSlatMode)
    912941{
    913     /** @todo This work can be optimized either by storing the masks in
    914      *        pVCpu->pgm.s.afGstCr3Masks[] for all PGMMODEs -or- just do this once and
    915      *        store the result when entering guest mode since we currently use it only
    916      *        for enmGuestMode. */
    917942    if (enmSlatMode == PGMSLAT_DIRECT)
    918943    {
    919944        Assert(enmMode != PGMMODE_EPT);
    920         switch (enmMode)
    921         {
    922             case PGMMODE_PAE:
    923             case PGMMODE_PAE_NX:
    924                 return X86_CR3_PAE_PAGE_MASK;
    925             case PGMMODE_AMD64:
    926             case PGMMODE_AMD64_NX:
    927                 return X86_CR3_AMD64_PAGE_MASK;
    928             default:
    929                 return X86_CR3_PAGE_MASK;
    930         }
    931     }
    932     else
    933     {
    934         Assert(enmSlatMode == PGMSLAT_EPT);
    935         return X86_CR3_EPT_PAGE_MASK;
    936     }
     945        return g_auCr3MaskForMode[(unsigned)enmMode < (unsigned)PGMMODE_MAX ? enmMode : 0];
     946    }
     947    Assert(enmSlatMode == PGMSLAT_EPT);
     948    return X86_CR3_EPT_PAGE_MASK;
    937949}
    938950
     
    940952/**
    941953 * Gets the masked CR3 value according to the current guest paging mode.
     954 *
     955 * See disclaimer in pgmGetCr3MaskForMode.
    942956 *
    943957 * @returns The masked PGM CR3 value.
     
    20082022}
    20092023
    2010 
    20112024#ifdef VBOX_WITH_NESTED_HWVIRT_VMX_EPT
     2025
    20122026/**
    20132027 * Performs a guest second-level address translation (SLAT).
     
    20882102    }
    20892103}
     2104
    20902105#endif /* VBOX_WITH_NESTED_HWVIRT_VMX_EPT */
    2091 
    20922106
    20932107/**
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette