VirtualBox

Changeset 86465 in vbox for trunk/src/VBox/VMM/include


Ignore:
Timestamp:
Oct 7, 2020 10:58:48 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
140771
Message:

VMM/PGMInline.h: Working on eliminating page table bitfield use. bugref:9841 bugref:9746

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/include/PGMInline.h

    r82968 r86465  
    783783    {
    784784        const unsigned iPdpt = (uint32_t)GCPtr >> X86_PDPT_SHIFT;
    785         if (    pGuestPDPT->a[iPdpt].n.u1Present
    786             &&  !(pGuestPDPT->a[iPdpt].u & pVCpu->pgm.s.fGstPaeMbzPdpeMask) )
     785        if ((pGuestPDPT->a[iPdpt].u & (pVCpu->pgm.s.fGstPaeMbzPdpeMask | X86_PDPE_P)) == X86_PDPE_P)
    787786        {
    788787            const unsigned iPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
     
    828827
    829828    /* The PDPE. */
    830     PX86PDPT        pGuestPDPT = pgmGstGetPaePDPTPtr(pVCpu);
    831     if (RT_UNLIKELY(!pGuestPDPT))
    832         return NULL;
    833     const unsigned  iPdpt = (uint32_t)GCPtr >> X86_PDPT_SHIFT;
    834     if (pPdpe)
    835         *pPdpe = pGuestPDPT->a[iPdpt];
    836     if (!pGuestPDPT->a[iPdpt].n.u1Present)
    837         return NULL;
    838     if (RT_UNLIKELY(pVCpu->pgm.s.fGstPaeMbzPdpeMask & pGuestPDPT->a[iPdpt].u))
    839         return NULL;
    840 
    841     /* The PDE. */
     829    PX86PDPT pGuestPDPT = pgmGstGetPaePDPTPtr(pVCpu);
     830    if (pGuestPDPT)
     831    {
     832        const unsigned     iPdpt = (uint32_t)GCPtr >> X86_PDPT_SHIFT;
     833        X86PGPAEUINT const uPdpe = pGuestPDPT->a[iPdpt].u;
     834        if (pPdpe)
     835            pPdpe->u = uPdpe;
     836        if ((uPdpe & (pVCpu->pgm.s.fGstPaeMbzPdpeMask | X86_PDPE_P)) == X86_PDPE_P)
     837        {
     838
     839            /* The PDE. */
    842840#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
    843     PX86PDPAE   pGuestPD = NULL;
    844     int rc = pgmRZDynMapGCPageInlined(pVCpu,
    845                                       pGuestPDPT->a[iPdpt].u & X86_PDPE_PG_MASK,
    846                                       (void **)&pGuestPD
    847                                       RTLOG_COMMA_SRC_POS);
    848     if (RT_FAILURE(rc))
    849     {
    850         AssertMsg(rc == VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS, ("%Rrc\n", rc));
    851         return NULL;
    852     }
     841            PX86PDPAE   pGuestPD = NULL;
     842            int rc = pgmRZDynMapGCPageInlined(pVCpu,
     843                                              uPdpe & X86_PDPE_PG_MASK,
     844                                              (void **)&pGuestPD
     845                                              RTLOG_COMMA_SRC_POS);
     846            if (RT_FAILURE(rc))
     847            {
     848                AssertMsg(rc == VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS, ("%Rrc\n", rc));
     849                return NULL;
     850            }
    853851#else
    854     PX86PDPAE   pGuestPD = pVCpu->pgm.s.CTX_SUFF(apGstPaePDs)[iPdpt];
    855     if (    !pGuestPD
    856         ||  (pGuestPDPT->a[iPdpt].u & X86_PDPE_PG_MASK) != pVCpu->pgm.s.aGCPhysGstPaePDs[iPdpt])
    857         pgmGstLazyMapPaePD(pVCpu, iPdpt, &pGuestPD);
     852            PX86PDPAE   pGuestPD = pVCpu->pgm.s.CTX_SUFF(apGstPaePDs)[iPdpt];
     853            if (    !pGuestPD
     854                ||  (uPdpe & X86_PDPE_PG_MASK) != pVCpu->pgm.s.aGCPhysGstPaePDs[iPdpt])
     855                pgmGstLazyMapPaePD(pVCpu, iPdpt, &pGuestPD);
    858856#endif
    859 
    860     *piPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
    861     return pGuestPD;
     857            *piPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
     858            return pGuestPD;
     859        }
     860    }
     861    return NULL;
    862862}
    863863
     
    919919#else
    920920    PX86PML4 pGuestPml4 = pVCpu->pgm.s.CTX_SUFF(pGstAmd64Pml4);
    921     if (RT_UNLIKELY(!pGuestPml4))
     921    if (pGuestPml4)
     922    { /* likely */ }
     923    else
    922924    {
    923925         int rc = pgmGstLazyMapPml4(pVCpu, &pGuestPml4);
     
    944946     *       supporting 52-bit wide physical guest addresses.
    945947     */
    946     PCX86PML4       pGuestPml4 = pgmGstGetLongModePML4Ptr(pVCpu);
    947     const unsigned  iPml4      = (GCPtr >> X86_PML4_SHIFT) & X86_PML4_MASK;
    948     if (    RT_LIKELY(pGuestPml4)
    949         &&  pGuestPml4->a[iPml4].n.u1Present
    950         &&  !(pGuestPml4->a[iPml4].u & pVCpu->pgm.s.fGstAmd64MbzPml4eMask) )
    951     {
    952         PCX86PDPT   pPdptTemp;
    953         int rc = PGM_GCPHYS_2_PTR_BY_VMCPU(pVCpu, pGuestPml4->a[iPml4].u & X86_PML4E_PG_MASK, &pPdptTemp);
    954         if (RT_SUCCESS(rc))
     948    PCX86PML4 pGuestPml4 = pgmGstGetLongModePML4Ptr(pVCpu);
     949    if (RT_LIKELY(pGuestPml4))
     950    {
     951        const unsigned     iPml4  = (GCPtr >> X86_PML4_SHIFT) & X86_PML4_MASK;
     952        X86PGPAEUINT const uPml4e = pGuestPml4->a[iPml4].u;
     953        if ((uPml4e & (pVCpu->pgm.s.fGstAmd64MbzPml4eMask | X86_PML4E_P)) == X86_PML4E_P)
    955954        {
    956             const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_AMD64;
    957             if (    pPdptTemp->a[iPdpt].n.u1Present
    958                 &&  !(pPdptTemp->a[iPdpt].u & pVCpu->pgm.s.fGstAmd64MbzPdpeMask) )
     955            PCX86PDPT pPdptTemp;
     956            int rc = PGM_GCPHYS_2_PTR_BY_VMCPU(pVCpu, uPml4e & X86_PML4E_PG_MASK, &pPdptTemp);
     957            if (RT_SUCCESS(rc))
    959958            {
    960                 PCX86PDPAE pPD;
    961                 rc = PGM_GCPHYS_2_PTR_BY_VMCPU(pVCpu, pPdptTemp->a[iPdpt].u & X86_PDPE_PG_MASK, &pPD);
    962                 if (RT_SUCCESS(rc))
     959                const unsigned     iPdpt  = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_AMD64;
     960                X86PGPAEUINT const uPdpte = pPdptTemp->a[iPdpt].u;
     961                if ((uPdpte & (pVCpu->pgm.s.fGstAmd64MbzPdpeMask | X86_PDPE_P)) == X86_PDPE_P)
    963962                {
    964                     const unsigned iPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
    965                     return pPD->a[iPD];
     963                    PCX86PDPAE pPD;
     964                    rc = PGM_GCPHYS_2_PTR_BY_VMCPU(pVCpu, uPdpte & X86_PDPE_PG_MASK, &pPD);
     965                    if (RT_SUCCESS(rc))
     966                    {
     967                        const unsigned iPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
     968                        return pPD->a[iPD];
     969                    }
    966970                }
    967971            }
     972            AssertMsg(RT_SUCCESS(rc) || rc == VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS, ("%Rrc\n", rc));
    968973        }
    969         AssertMsg(RT_SUCCESS(rc) || rc == VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS, ("%Rrc\n", rc));
    970974    }
    971975
     
    989993{
    990994    /* The PMLE4. */
    991     PX86PML4        pGuestPml4 = pgmGstGetLongModePML4Ptr(pVCpu);
    992     if (RT_UNLIKELY(!pGuestPml4))
    993         return NULL;
    994     const unsigned  iPml4      = (GCPtr >> X86_PML4_SHIFT) & X86_PML4_MASK;
    995     PCX86PML4E      pPml4e     = *ppPml4e = &pGuestPml4->a[iPml4];
    996     if (!pPml4e->n.u1Present)
    997         return NULL;
    998     if (RT_UNLIKELY(pPml4e->u & pVCpu->pgm.s.fGstAmd64MbzPml4eMask))
    999         return NULL;
    1000 
    1001     /* The PDPE. */
    1002     PCX86PDPT       pPdptTemp;
    1003     int rc = PGM_GCPHYS_2_PTR_BY_VMCPU(pVCpu, pPml4e->u & X86_PML4E_PG_MASK, &pPdptTemp);
    1004     if (RT_FAILURE(rc))
    1005     {
    1006         AssertMsg(rc == VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS, ("%Rrc\n", rc));
    1007         return NULL;
    1008     }
    1009     const unsigned iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_AMD64;
    1010     *pPdpe = pPdptTemp->a[iPdpt];
    1011     if (!pPdpe->n.u1Present)
    1012         return NULL;
    1013     if (RT_UNLIKELY(pPdpe->u & pVCpu->pgm.s.fGstAmd64MbzPdpeMask))
    1014         return NULL;
    1015 
    1016     /* The PDE. */
    1017     PX86PDPAE pPD;
    1018     rc = PGM_GCPHYS_2_PTR_BY_VMCPU(pVCpu, pPdptTemp->a[iPdpt].u & X86_PDPE_PG_MASK, &pPD);
    1019     if (RT_FAILURE(rc))
    1020     {
    1021         AssertMsg(rc == VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS, ("%Rrc\n", rc));
    1022         return NULL;
    1023     }
    1024 
    1025     *piPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
    1026     return pPD;
     995    PX86PML4 pGuestPml4 = pgmGstGetLongModePML4Ptr(pVCpu);
     996    if (pGuestPml4)
     997    {
     998        const unsigned     iPml4  = (GCPtr >> X86_PML4_SHIFT) & X86_PML4_MASK;
     999        *ppPml4e = &pGuestPml4->a[iPml4];
     1000        X86PGPAEUINT const uPml4e = pGuestPml4->a[iPml4].u;
     1001        if ((uPml4e & (pVCpu->pgm.s.fGstAmd64MbzPml4eMask | X86_PML4E_P)) == X86_PML4E_P)
     1002        {
     1003            /* The PDPE. */
     1004            PCX86PDPT pPdptTemp;
     1005            int rc = PGM_GCPHYS_2_PTR_BY_VMCPU(pVCpu, uPml4e & X86_PML4E_PG_MASK, &pPdptTemp);
     1006            if (RT_SUCCESS(rc))
     1007            {
     1008                const unsigned     iPdpt = (GCPtr >> X86_PDPT_SHIFT) & X86_PDPT_MASK_AMD64;
     1009                X86PGPAEUINT const uPdpe = pPdptTemp->a[iPdpt].u;
     1010                pPdpe->u = uPdpe;
     1011                if ((uPdpe & (pVCpu->pgm.s.fGstAmd64MbzPdpeMask | X86_PDPE_P)) == X86_PDPE_P)
     1012                {
     1013                    /* The PDE. */
     1014                    PX86PDPAE pPD;
     1015                    rc = PGM_GCPHYS_2_PTR_BY_VMCPU(pVCpu, uPdpe & X86_PDPE_PG_MASK, &pPD);
     1016                    if (RT_SUCCESS(rc))
     1017                    {
     1018                        *piPD = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
     1019                        return pPD;
     1020                    }
     1021                    AssertMsg(rc == VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS, ("%Rrc\n", rc));
     1022                }
     1023            }
     1024            else
     1025                AssertMsg(rc == VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS, ("%Rrc\n", rc));
     1026        }
     1027    }
     1028    return NULL;
    10271029}
    10281030
     
    10921094 * @returns Pointer to the shadow PD.
    10931095 * @param   pVCpu       The cross context virtual CPU structure.
    1094  * @param   GCPtr       The address.
    1095  */
    1096 DECLINLINE(PX86PDPAE) pgmShwGetPaePDPtr(PVMCPUCC pVCpu, RTGCPTR GCPtr)
    1097 {
    1098     const unsigned  iPdpt = (uint32_t)GCPtr >> X86_PDPT_SHIFT;
    1099     PX86PDPT        pPdpt = pgmShwGetPaePDPTPtr(pVCpu);
    1100 
    1101     if (!pPdpt->a[iPdpt].n.u1Present)
    1102         return NULL;
    1103 
    1104     /* Fetch the pgm pool shadow descriptor. */
    1105     PVMCC pVM = pVCpu->CTX_SUFF(pVM);
    1106     PPGMPOOLPAGE pShwPde = pgmPoolGetPage(pVM->pgm.s.CTX_SUFF(pPool), pPdpt->a[iPdpt].u & X86_PDPE_PG_MASK);
    1107     AssertReturn(pShwPde, NULL);
    1108 
    1109     return (PX86PDPAE)PGMPOOL_PAGE_2_PTR_V2(pVM, pVCpu, pShwPde);
    1110 }
    1111 
    1112 
    1113 /**
    1114  * Gets the shadow page directory for the specified address, PAE.
    1115  *
    1116  * @returns Pointer to the shadow PD.
    1117  * @param   pVCpu       The cross context virtual CPU structure.
    11181096 * @param   pPdpt       Pointer to the page directory pointer table.
    11191097 * @param   GCPtr       The address.
     
    11221100{
    11231101    const unsigned  iPdpt = (uint32_t)GCPtr >> X86_PDPT_SHIFT;
    1124 
    1125     if (!pPdpt->a[iPdpt].n.u1Present)
    1126         return NULL;
    1127 
    1128     /* Fetch the pgm pool shadow descriptor. */
    1129     PVMCC             pVM     = pVCpu->CTX_SUFF(pVM);
    1130     PPGMPOOLPAGE    pShwPde = pgmPoolGetPage(pVM->pgm.s.CTX_SUFF(pPool), pPdpt->a[iPdpt].u & X86_PDPE_PG_MASK);
    1131     AssertReturn(pShwPde, NULL);
    1132 
    1133     return (PX86PDPAE)PGMPOOL_PAGE_2_PTR_V2(pVM, pVCpu, pShwPde);
     1102    if (pPdpt->a[iPdpt].u & X86_PDPE_P)
     1103    {
     1104        /* Fetch the pgm pool shadow descriptor. */
     1105        PVMCC           pVM     = pVCpu->CTX_SUFF(pVM);
     1106        PPGMPOOLPAGE    pShwPde = pgmPoolGetPage(pVM->pgm.s.CTX_SUFF(pPool), pPdpt->a[iPdpt].u & X86_PDPE_PG_MASK);
     1107        AssertReturn(pShwPde, NULL);
     1108
     1109        return (PX86PDPAE)PGMPOOL_PAGE_2_PTR_V2(pVM, pVCpu, pShwPde);
     1110    }
     1111    return NULL;
     1112}
     1113
     1114
     1115/**
     1116 * Gets the shadow page directory for the specified address, PAE.
     1117 *
     1118 * @returns Pointer to the shadow PD.
     1119 * @param   pVCpu       The cross context virtual CPU structure.
     1120 * @param   GCPtr       The address.
     1121 */
     1122DECLINLINE(PX86PDPAE) pgmShwGetPaePDPtr(PVMCPUCC pVCpu, RTGCPTR GCPtr)
     1123{
     1124    return pgmShwGetPaePDPtr(pVCpu, pgmShwGetPaePDPTPtr(pVCpu), GCPtr);
    11341125}
    11351126
     
    11441135DECLINLINE(X86PDEPAE) pgmShwGetPaePDE(PVMCPUCC pVCpu, RTGCPTR GCPtr)
    11451136{
    1146     const unsigned iPd = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
    1147 
    1148     PX86PDPAE pShwPde = pgmShwGetPaePDPtr(pVCpu, GCPtr);
    1149     if (!pShwPde)
    1150     {
    1151         X86PDEPAE ZeroPde = {0};
    1152         return ZeroPde;
    1153     }
    1154     return pShwPde->a[iPd];
     1137    const unsigned  iPd     = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
     1138    PX86PDPAE       pShwPde = pgmShwGetPaePDPtr(pVCpu, GCPtr);
     1139    if (pShwPde)
     1140        return pShwPde->a[iPd];
     1141
     1142    X86PDEPAE ZeroPde = {0};
     1143    return ZeroPde;
    11551144}
    11561145
     
    11661155DECLINLINE(PX86PDEPAE) pgmShwGetPaePDEPtr(PVMCPUCC pVCpu, RTGCPTR GCPtr)
    11671156{
    1168     const unsigned iPd = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
    1169 
    1170     PX86PDPAE pPde = pgmShwGetPaePDPtr(pVCpu, GCPtr);
    1171     AssertReturn(pPde, NULL);
    1172     return &pPde->a[iPd];
     1157    const unsigned iPd     = (GCPtr >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
     1158    PX86PDPAE      pShwPde = pgmShwGetPaePDPtr(pVCpu, GCPtr);
     1159    AssertReturn(pShwPde, NULL);
     1160    return &pShwPde->a[iPd];
    11731161}
    11741162
     
    11951183DECLINLINE(X86PML4E) pgmShwGetLongModePML4E(PVMCPUCC pVCpu, RTGCPTR GCPtr)
    11961184{
    1197     const unsigned  iPml4 = ((RTGCUINTPTR64)GCPtr >> X86_PML4_SHIFT) & X86_PML4_MASK;
     1185    const unsigned  iPml4    = ((RTGCUINTPTR64)GCPtr >> X86_PML4_SHIFT) & X86_PML4_MASK;
    11981186    PX86PML4        pShwPml4 = pgmShwGetLongModePML4Ptr(pVCpu);
    1199 
    1200     if (!pShwPml4)
    1201     {
    1202         X86PML4E ZeroPml4e = {0};
    1203         return ZeroPml4e;
    1204     }
    1205     return pShwPml4->a[iPml4];
     1187    if (pShwPml4)
     1188        return pShwPml4->a[iPml4];
     1189
     1190    X86PML4E ZeroPml4e = {0};
     1191    return ZeroPml4e;
    12061192}
    12071193
     
    12171203{
    12181204    PX86PML4 pShwPml4 = pgmShwGetLongModePML4Ptr(pVCpu);
    1219     if (!pShwPml4)
    1220         return NULL;
    1221     return &pShwPml4->a[iPml4];
     1205    if (pShwPml4)
     1206        return &pShwPml4->a[iPml4];
     1207    return NULL;
    12221208}
    12231209
Note: See TracChangeset for help on using the changeset viewer.

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