VirtualBox

Changeset 96957 in vbox


Ignore:
Timestamp:
Sep 30, 2022 8:33:19 PM (2 years ago)
Author:
vboxsync
Message:

VMM/PGMPool: Extended the .pgmpoolcheck command to cover the other shadow guest EPT structures too. bugref:10092

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/PGMPool.cpp

    r96949 r96957  
    10501050        State.fFirstMsg = true;
    10511051
     1052        if (pPage->idx != i)
     1053            pgmR3PoolCheckError(&State, "Invalid idx value: %#x, expected %#x", pPage->idx, i);
     1054
    10521055        if (pPage->enmKind == PGMPOOLKIND_FREE)
    10531056            continue;
    10541057        if (pPage->enmKind > PGMPOOLKIND_LAST || pPage->enmKind <= PGMPOOLKIND_INVALID)
    10551058        {
    1056             pgmR3PoolCheckError(&State, "Invalid enmKind value: %#x\n", pPage->enmKind);
     1059            if (pPage->enmKind != PGMPOOLKIND_INVALID || pPage->idx != 0)
     1060                pgmR3PoolCheckError(&State, "Invalid enmKind value: %#x\n", pPage->enmKind);
    10571061            continue;
    10581062        }
     
    10721076            }
    10731077        }
     1078# define HCPHYS_TO_POOL_PAGE(a_HCPhys) (PPGMPOOLPAGE)RTAvloHCPhysGet(&pPool->HCPhysTree, (a_HCPhys))
    10741079
    10751080        /*
     
    11041109                PCEPTPT const pGstPT = (PCEPTPT)pvGuestPage;
    11051110                for (unsigned j = 0; j < RT_ELEMENTS(pShwPT->a); j++)
    1106                     if (pShwPT->a[j].u & EPT_PRESENT_MASK)
     1111                {
     1112                    uint64_t const uShw = pShwPT->a[j].u;
     1113                    if (uShw & EPT_PRESENT_MASK)
    11071114                    {
    1108                         RTHCPHYS HCPhys = NIL_RTHCPHYS;
    1109                         int rc = PGMPhysGCPhys2HCPhys(pPool->CTX_SUFF(pVM), pGstPT->a[j].u & X86_PTE_PAE_PG_MASK, &HCPhys);
     1115                        uint64_t const uGst   = pGstPT->a[j].u;
     1116                        RTHCPHYS       HCPhys = NIL_RTHCPHYS;
     1117                        int rc = PGMPhysGCPhys2HCPhys(pPool->CTX_SUFF(pVM), uGst & EPT_E_PG_MASK, &HCPhys);
    11101118                        if (   rc != VINF_SUCCESS
    1111                             || (pShwPT->a[j].u & EPT_E_PG_MASK) != HCPhys)
     1119                            || (uShw & EPT_E_PG_MASK) != HCPhys)
    11121120                            pgmR3PoolCheckError(&State, "Mismatch HCPhys: rc=%Rrc idx=%#x guest %RX64 shw=%RX64 vs %RHp\n",
    1113                                                 rc, j, pGstPT->a[j].u, pShwPT->a[j].u, HCPhys);
    1114                         else if (      (pShwPT->a[j].u & (EPT_E_READ | EPT_E_WRITE | EPT_E_EXECUTE))
    1115                                     != (EPT_E_READ | EPT_E_WRITE | EPT_E_EXECUTE)
    1116                                  && (   ((pShwPT->a[j].u & EPT_E_READ)    && !(pGstPT->a[j].u & EPT_E_READ))
    1117                                      || ((pShwPT->a[j].u & EPT_E_WRITE)   && !(pGstPT->a[j].u & EPT_E_WRITE))
    1118                                      || ((pShwPT->a[j].u & EPT_E_EXECUTE) && !(pGstPT->a[j].u & EPT_E_EXECUTE)) ) )
     1121                                                rc, j, uGst, uShw, HCPhys);
     1122                        if (      (uShw & (EPT_E_READ | EPT_E_WRITE | EPT_E_EXECUTE))
     1123                               != (EPT_E_READ | EPT_E_WRITE | EPT_E_EXECUTE)
     1124                            && (   ((uShw & EPT_E_READ)    && !(uGst & EPT_E_READ))
     1125                                || ((uShw & EPT_E_WRITE)   && !(uGst & EPT_E_WRITE))
     1126                                || ((uShw & EPT_E_EXECUTE) && !(uGst & EPT_E_EXECUTE)) ) )
     1127                            pgmR3PoolCheckError(&State, "Mismatch r/w/x: idx=%#x guest %RX64 shw=%RX64\n", j, uGst, uShw);
     1128                    }
     1129                }
     1130                break;
     1131            }
     1132
     1133            case PGMPOOLKIND_EPT_PD_FOR_EPT_PD:
     1134            {
     1135                PCEPTPD const pShwPD = (PCEPTPD)PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
     1136                PCEPTPD const pGstPD = (PCEPTPD)pvGuestPage;
     1137                for (unsigned j = 0; j < RT_ELEMENTS(pShwPD->a); j++)
     1138                {
     1139                    uint64_t const uShw = pShwPD->a[j].u;
     1140                    if (uShw & EPT_PRESENT_MASK)
     1141                    {
     1142                        uint64_t const uGst = pGstPD->a[j].u;
     1143                        if (uShw & EPT_E_LEAF)
     1144                        {
     1145                            if (!(uGst & EPT_E_LEAF))
     1146                                pgmR3PoolCheckError(&State, "Leafness-mismatch: idx=%#x guest %RX64 shw=%RX64\n", j, uGst, uShw);
     1147                            else
     1148                            {
     1149                                RTHCPHYS HCPhys = NIL_RTHCPHYS;
     1150                                int rc = PGMPhysGCPhys2HCPhys(pPool->CTX_SUFF(pVM), uGst & EPT_PDE2M_PG_MASK, &HCPhys);
     1151                                if (   rc != VINF_SUCCESS
     1152                                    || (uShw & EPT_E_PG_MASK) != HCPhys)
     1153                                    pgmR3PoolCheckError(&State, "Mismatch HCPhys: rc=%Rrc idx=%#x guest %RX64 shw=%RX64 vs %RHp (2MB)\n",
     1154                                                        rc, j, uGst, uShw, HCPhys);
     1155                            }
     1156                        }
     1157                        else
     1158                        {
     1159                            PPGMPOOLPAGE pSubPage = HCPHYS_TO_POOL_PAGE(uShw & EPT_E_PG_MASK);
     1160                            if (pSubPage)
     1161                            {
     1162                                /** @todo adjust for 2M page to shadow PT mapping.   */
     1163                                if (pSubPage->enmKind != PGMPOOLKIND_EPT_PT_FOR_EPT_PT)
     1164                                    pgmR3PoolCheckError(&State, "Wrong sub-table type: idx=%#x guest %RX64 shw=%RX64: idxSub=%#x %s\n",
     1165                                                        j, uGst, uShw, pSubPage->idx, pgmPoolPoolKindToStr(pSubPage->enmKind));
     1166                                if (pSubPage->fA20Enabled != pPage->fA20Enabled)
     1167                                    pgmR3PoolCheckError(&State, "Wrong sub-table A20: idx=%#x guest %RX64 shw=%RX64: idxSub=%#x A20=%d, expected %d\n",
     1168                                                        j, uGst, uShw, pSubPage->idx, pSubPage->fA20Enabled, pPage->fA20Enabled);
     1169                                if (pSubPage->GCPhys != (uGst & EPT_E_PG_MASK))
     1170                                    pgmR3PoolCheckError(&State, "Wrong sub-table GCPhys: idx=%#x guest %RX64 shw=%RX64: GCPhys=%#RGp idxSub=%#x\n",
     1171                                                        j, uGst, uShw, pSubPage->GCPhys, pSubPage->idx);
     1172                            }
     1173                            else
     1174                                pgmR3PoolCheckError(&State, "sub table not found: idx=%#x shw=%RX64\n", j, uShw);
     1175
     1176                        }
     1177                        if (      (uShw & (EPT_E_READ | EPT_E_WRITE | EPT_E_EXECUTE))
     1178                               != (EPT_E_READ | EPT_E_WRITE | EPT_E_EXECUTE)
     1179                            && (   ((uShw & EPT_E_READ)    && !(uGst & EPT_E_READ))
     1180                                || ((uShw & EPT_E_WRITE)   && !(uGst & EPT_E_WRITE))
     1181                                || ((uShw & EPT_E_EXECUTE) && !(uGst & EPT_E_EXECUTE)) ) )
    11191182                            pgmR3PoolCheckError(&State, "Mismatch r/w/x: idx=%#x guest %RX64 shw=%RX64\n",
    1120                                                 j, pGstPT->a[j].u, pShwPT->a[j].u);
     1183                                                j, uGst, uShw);
    11211184                    }
     1185                }
     1186                break;
     1187            }
     1188
     1189            case PGMPOOLKIND_EPT_PDPT_FOR_EPT_PDPT:
     1190            {
     1191                PCEPTPDPT const pShwPDPT = (PCEPTPDPT)PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
     1192                PCEPTPDPT const pGstPDPT = (PCEPTPDPT)pvGuestPage;
     1193                for (unsigned j = 0; j < RT_ELEMENTS(pShwPDPT->a); j++)
     1194                {
     1195                    uint64_t const uShw = pShwPDPT->a[j].u;
     1196                    if (uShw & EPT_PRESENT_MASK)
     1197                    {
     1198                        uint64_t const uGst = pGstPDPT->a[j].u;
     1199                        if (uShw & EPT_E_LEAF)
     1200                            pgmR3PoolCheckError(&State, "No 1GiB shadow pages: idx=%#x guest %RX64 shw=%RX64\n", j, uGst, uShw);
     1201                        else
     1202                        {
     1203                            PPGMPOOLPAGE pSubPage = HCPHYS_TO_POOL_PAGE(uShw & EPT_E_PG_MASK);
     1204                            if (pSubPage)
     1205                            {
     1206                                if (pSubPage->enmKind != PGMPOOLKIND_EPT_PD_FOR_EPT_PD)
     1207                                    pgmR3PoolCheckError(&State, "Wrong sub-table type: idx=%#x guest %RX64 shw=%RX64: idxSub=%#x %s\n",
     1208                                                        j, uGst, uShw, pSubPage->idx, pgmPoolPoolKindToStr(pSubPage->enmKind));
     1209                                if (pSubPage->fA20Enabled != pPage->fA20Enabled)
     1210                                    pgmR3PoolCheckError(&State, "Wrong sub-table A20: idx=%#x guest %RX64 shw=%RX64: idxSub=%#x A20=%d, expected %d\n",
     1211                                                        j, uGst, uShw, pSubPage->idx, pSubPage->fA20Enabled, pPage->fA20Enabled);
     1212                                if (pSubPage->GCPhys != (uGst & EPT_E_PG_MASK))
     1213                                    pgmR3PoolCheckError(&State, "Wrong sub-table GCPhys: idx=%#x guest %RX64 shw=%RX64: GCPhys=%#RGp idxSub=%#x\n",
     1214                                                        j, uGst, uShw, pSubPage->GCPhys, pSubPage->idx);
     1215                            }
     1216                            else
     1217                                pgmR3PoolCheckError(&State, "sub table not found: idx=%#x shw=%RX64\n", j, uShw);
     1218
     1219                        }
     1220                        if (      (uShw & (EPT_E_READ | EPT_E_WRITE | EPT_E_EXECUTE))
     1221                               != (EPT_E_READ | EPT_E_WRITE | EPT_E_EXECUTE)
     1222                            && (   ((uShw & EPT_E_READ)    && !(uGst & EPT_E_READ))
     1223                                || ((uShw & EPT_E_WRITE)   && !(uGst & EPT_E_WRITE))
     1224                                || ((uShw & EPT_E_EXECUTE) && !(uGst & EPT_E_EXECUTE)) ) )
     1225                            pgmR3PoolCheckError(&State, "Mismatch r/w/x: idx=%#x guest %RX64 shw=%RX64\n",
     1226                                                j, uGst, uShw);
     1227                    }
     1228                }
     1229                break;
     1230            }
     1231
     1232            case PGMPOOLKIND_EPT_PML4_FOR_EPT_PML4:
     1233            {
     1234                PCEPTPML4 const pShwPML4 = (PCEPTPML4)PGMPOOL_PAGE_2_PTR(pPool->CTX_SUFF(pVM), pPage);
     1235                PCEPTPML4 const pGstPML4 = (PCEPTPML4)pvGuestPage;
     1236                for (unsigned j = 0; j < RT_ELEMENTS(pShwPML4->a); j++)
     1237                {
     1238                    uint64_t const uShw = pShwPML4->a[j].u;
     1239                    if (uShw & EPT_PRESENT_MASK)
     1240                    {
     1241                        uint64_t const uGst = pGstPML4->a[j].u;
     1242                        if (uShw & EPT_E_LEAF)
     1243                            pgmR3PoolCheckError(&State, "No 0.5TiB shadow pages: idx=%#x guest %RX64 shw=%RX64\n", j, uGst, uShw);
     1244                        else
     1245                        {
     1246                            PPGMPOOLPAGE pSubPage = HCPHYS_TO_POOL_PAGE(uShw & EPT_E_PG_MASK);
     1247                            if (pSubPage)
     1248                            {
     1249                                if (pSubPage->enmKind != PGMPOOLKIND_EPT_PDPT_FOR_EPT_PDPT)
     1250                                    pgmR3PoolCheckError(&State, "Wrong sub-table type: idx=%#x guest %RX64 shw=%RX64: idxSub=%#x %s\n",
     1251                                                        j, uGst, uShw, pSubPage->idx, pgmPoolPoolKindToStr(pSubPage->enmKind));
     1252                                if (pSubPage->fA20Enabled != pPage->fA20Enabled)
     1253                                    pgmR3PoolCheckError(&State, "Wrong sub-table A20: idx=%#x guest %RX64 shw=%RX64: idxSub=%#x A20=%d, expected %d\n",
     1254                                                        j, uGst, uShw, pSubPage->idx, pSubPage->fA20Enabled, pPage->fA20Enabled);
     1255                                if (pSubPage->GCPhys != (uGst & EPT_E_PG_MASK))
     1256                                    pgmR3PoolCheckError(&State, "Wrong sub-table GCPhys: idx=%#x guest %RX64 shw=%RX64: GCPhys=%#RGp idxSub=%#x\n",
     1257                                                        j, uGst, uShw, pSubPage->GCPhys, pSubPage->idx);
     1258                            }
     1259                            else
     1260                                pgmR3PoolCheckError(&State, "sub table not found: idx=%#x shw=%RX64\n", j, uShw);
     1261
     1262                        }
     1263                        if (      (uShw & (EPT_E_READ | EPT_E_WRITE | EPT_E_EXECUTE))
     1264                               != (EPT_E_READ | EPT_E_WRITE | EPT_E_EXECUTE)
     1265                            && (   ((uShw & EPT_E_READ)    && !(uGst & EPT_E_READ))
     1266                                || ((uShw & EPT_E_WRITE)   && !(uGst & EPT_E_WRITE))
     1267                                || ((uShw & EPT_E_EXECUTE) && !(uGst & EPT_E_EXECUTE)) ) )
     1268                            pgmR3PoolCheckError(&State, "Mismatch r/w/x: idx=%#x guest %RX64 shw=%RX64\n",
     1269                                                j, uGst, uShw);
     1270                    }
     1271                }
    11221272                break;
    11231273            }
    11241274        }
    11251275
     1276#undef HCPHYS_TO_POOL_PAGE
    11261277        if (pvGuestPage)
    11271278            PGMPhysReleasePageMappingLock(pVM, &LockPage);
     
    11311282    if (State.cErrors > 0)
    11321283        return DBGCCmdHlpFail(pCmdHlp, pCmd, "Found %#x errors", State.cErrors);
     1284    DBGCCmdHlpPrintf(pCmdHlp, "no errors found\n");
    11331285    return VINF_SUCCESS;
    11341286}
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