Changeset 18291 in vbox for trunk/src/VBox/VMM/VMMAll
- Timestamp:
- Mar 26, 2009 5:11:07 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMAll/PGMAllMap.cpp
r17667 r18291 268 268 case PGMMODE_PAE_NX: 269 269 { 270 PX86PDPT pShwPdpt; 271 PX86PDPAE pShwPaePd; 272 const unsigned iPdPt = iNewPDE / 256; 273 unsigned iPDE = iNewPDE * 2 % 512; 274 275 pShwPdpt = pgmShwGetPaePDPTPtr(&pVM->pgm.s); 270 const unsigned iPdPt = iNewPDE / 256; 271 unsigned iPDE = iNewPDE * 2 % 512; 272 PX86PDPT pShwPdpt = pgmShwGetPaePDPTPtr(&pVM->pgm.s); 276 273 Assert(pShwPdpt); 277 274 #ifdef IN_RC /* Lock mapping to prevent it from being reused during pgmShwSyncPaePDPtr. */ 278 275 PGMDynLockHCPage(pVM, (uint8_t *)pShwPdpt); 279 276 #endif 280 pShwPaePd = pgmShwGetPaePDPtr(&pVM->pgm.s, (iPdPt << X86_PDPT_SHIFT));277 PX86PDPAE pShwPaePd = pgmShwGetPaePDPtr(&pVM->pgm.s, (iPdPt << X86_PDPT_SHIFT)); 281 278 if (!pShwPaePd) 282 279 { … … 312 309 pgmPoolLockPage(pVM->pgm.s.CTX_SUFF(pPool), pPoolPagePd); 313 310 } 314 # 315 else 311 #ifdef VBOX_STRICT 312 else 316 313 if (pShwPaePd->a[iPDE].u & PGM_PDFLAGS_MAPPING) 317 314 { … … 321 318 AssertFatalMsg((pShwPaePd->a[iPDE+1].u & X86_PDE_PG_MASK) == pMap->aPTs[i].HCPhysPaePT1, ("%RX64 vs %RX64\n", pShwPaePd->a[iPDE+1].u & X86_PDE_PG_MASK, pMap->aPTs[i].HCPhysPaePT1)); 322 319 } 323 # 320 #endif 324 321 if ( pShwPaePd->a[iPDE].n.u1Present 325 322 && !(pShwPaePd->a[iPDE].u & PGM_PDFLAGS_MAPPING)) … … 364 361 } 365 362 363 366 364 /** 367 365 * Clears all PDEs involved with the mapping in the shadow page table. 368 366 * 369 * @param pVM The VM handle. 370 * @param pShwPageCR3 CR3 root page 371 * @param pMap Pointer to the mapping in question. 372 * @param iOldPDE The index of the 32-bit PDE corresponding to the base of the mapping. 373 */ 374 void pgmMapClearShadowPDEs(PVM pVM, PPGMPOOLPAGE pShwPageCR3, PPGMMAPPING pMap, unsigned iOldPDE) 375 { 376 Log(("pgmMapClearShadowPDEs old pde %x (cPTs=%x) (mappings enabled %d)\n", iOldPDE, pMap->cPTs, pgmMapAreMappingsEnabled(&pVM->pgm.s))); 367 * @param pVM The VM handle. 368 * @param pShwPageCR3 CR3 root page 369 * @param pMap Pointer to the mapping in question. 370 * @param iOldPDE The index of the 32-bit PDE corresponding to the base of the mapping. 371 * @param fDeactivateCR3 Set if it's pgmMapDeactivateCR3 calling. 372 */ 373 void pgmMapClearShadowPDEs(PVM pVM, PPGMPOOLPAGE pShwPageCR3, PPGMMAPPING pMap, unsigned iOldPDE, bool fDeactivateCR3) 374 { 375 Log(("pgmMapClearShadowPDEs: old pde %x (cPTs=%x) (mappings enabled %d) fDeactivateCR3=%RTbool\n", iOldPDE, pMap->cPTs, pgmMapAreMappingsEnabled(&pVM->pgm.s), fDeactivateCR3)); 377 376 378 377 if (!pgmMapAreMappingsEnabled(&pVM->pgm.s)) … … 415 414 case PGMMODE_PAE_NX: 416 415 { 417 PX86PDPT pShwPdpt = NULL; 418 PX86PDPAE pShwPaePd = NULL; 419 420 const unsigned iPdpt = iOldPDE / 256; /* iOldPDE * 2 / 512; iOldPDE is in 4 MB pages */ 421 unsigned iPDE = iOldPDE * 2 % 512; 422 pShwPdpt = (PX86PDPT)PGMPOOL_PAGE_2_PTR_BY_PGM(&pVM->pgm.s, pShwPageCR3); 423 pShwPaePd = pgmShwGetPaePDPtr(&pVM->pgm.s, pShwPdpt, (iPdpt << X86_PDPT_SHIFT)); 416 const unsigned iPdpt = iOldPDE / 256; /* iOldPDE * 2 / 512; iOldPDE is in 4 MB pages */ 417 unsigned iPDE = iOldPDE * 2 % 512; 418 PX86PDPT pShwPdpt = (PX86PDPT)PGMPOOL_PAGE_2_PTR_BY_PGM(&pVM->pgm.s, pShwPageCR3); 419 PX86PDPAE pShwPaePd = pgmShwGetPaePDPtr(&pVM->pgm.s, pShwPdpt, (iPdpt << X86_PDPT_SHIFT)); 424 420 425 421 /* Clear the PGM_PDFLAGS_MAPPING flag for the page directory pointer entry. (legacy PAE guest mode) */ 426 pShwPdpt->a[iPdpt].u &= ~PGM_PLXFLAGS_MAPPING; 427 422 if (fDeactivateCR3) 423 pShwPdpt->a[iPdpt].u &= ~PGM_PLXFLAGS_MAPPING; 424 else if (pShwPdpt->a[iPdpt].u & PGM_PLXFLAGS_MAPPING) 425 { 426 /* See if there are any other mappings here. This is suboptimal code. */ 427 pShwPdpt->a[iPdpt].u &= ~PGM_PLXFLAGS_MAPPING; 428 for (PPGMMAPPING pCur = pVM->pgm.s.CTX_SUFF(pMappings); pCur; pCur = pCur->CTX_SUFF(pNext)) 429 if ( pCur != pMap 430 && ( (pCur->GCPtr >> X86_PDPT_SHIFT) == iPdpt 431 || (pCur->GCPtrLast >> X86_PDPT_SHIFT) == iPdpt)) 432 { 433 pShwPdpt->a[iPdpt].u |= PGM_PLXFLAGS_MAPPING; 434 break; 435 } 436 } 428 437 if (pCurrentShwPdpt) 429 438 { … … 474 483 * @param iPDE The index of the 32-bit PDE corresponding to the base of the mapping. 475 484 */ 476 void pgmMapCheckShadowPDEs(PVM pVM, PPGMPOOLPAGE pShwPageCR3, PPGMMAPPING pMap, unsigned iPDE)485 static void pgmMapCheckShadowPDEs(PVM pVM, PPGMPOOLPAGE pShwPageCR3, PPGMMAPPING pMap, unsigned iPDE) 477 486 { 478 487 Assert(pShwPageCR3); 479 488 480 u nsignedi = pMap->cPTs;489 uint32_t i = pMap->cPTs; 481 490 PGMMODE enmShadowMode = PGMGetShadowMode(pVM); 482 491 … … 486 495 iPDE--; 487 496 488 switch (enmShadowMode)497 switch (enmShadowMode) 489 498 { 490 499 case PGMMODE_32_BIT: … … 494 503 495 504 AssertMsg(pShw32BitPd->a[iPDE].u == (PGM_PDFLAGS_MAPPING | X86_PDE_P | X86_PDE_A | X86_PDE_RW | X86_PDE_US | (uint32_t)pMap->aPTs[i].HCPhysPT), 496 ("Expected %x vs %x\n", pShw32BitPd->a[iPDE].u, (PGM_PDFLAGS_MAPPING | X86_PDE_P | X86_PDE_A | X86_PDE_RW | X86_PDE_US | (uint32_t)pMap->aPTs[i].HCPhysPT))); 505 ("Expected %x vs %x; iPDE=%#x %RGv %s\n", 506 pShw32BitPd->a[iPDE].u, (PGM_PDFLAGS_MAPPING | X86_PDE_P | X86_PDE_A | X86_PDE_RW | X86_PDE_US | (uint32_t)pMap->aPTs[i].HCPhysPT), 507 iPDE, pMap->GCPtr, R3STRING(pMap->pszDesc) )); 497 508 break; 498 509 } … … 501 512 case PGMMODE_PAE_NX: 502 513 { 503 PX86PDPT pPdpt = NULL; 504 PX86PDPAE pShwPaePd = NULL; 505 506 const unsigned iPD = iPDE / 256; /* iPDE * 2 / 512; iPDE is in 4 MB pages */ 507 unsigned iPaePDE = iPDE * 2 % 512; 508 pPdpt = (PX86PDPT)PGMPOOL_PAGE_2_PTR_BY_PGM(&pVM->pgm.s, pShwPageCR3); 509 pShwPaePd = pgmShwGetPaePDPtr(&pVM->pgm.s, pPdpt, (iPD << X86_PDPT_SHIFT)); 514 const unsigned iPD = iPDE / 256; /* iPDE * 2 / 512; iPDE is in 4 MB pages */ 515 unsigned iPaePDE = iPDE * 2 % 512; 516 PX86PDPT pPdpt = (PX86PDPT)PGMPOOL_PAGE_2_PTR_BY_PGM(&pVM->pgm.s, pShwPageCR3); 517 PX86PDPAE pShwPaePd = pgmShwGetPaePDPtr(&pVM->pgm.s, pPdpt, (iPD << X86_PDPT_SHIFT)); 510 518 AssertFatal(pShwPaePd); 511 519 512 520 AssertMsg(pShwPaePd->a[iPaePDE].u == (PGM_PDFLAGS_MAPPING | X86_PDE_P | X86_PDE_A | X86_PDE_RW | X86_PDE_US | pMap->aPTs[i].HCPhysPaePT0), 513 ("Expected %RX64 vs %RX64\n", pShwPaePd->a[iPDE].u, (PGM_PDFLAGS_MAPPING | X86_PDE_P | X86_PDE_A | X86_PDE_RW | X86_PDE_US | (uint32_t)pMap->aPTs[i].HCPhysPaePT0))); 521 ("Expected %RX64 vs %RX64; iPDE=%#x iPD=%#x iPaePDE=%#x %RGv %s\n", 522 pShwPaePd->a[iPDE].u, (PGM_PDFLAGS_MAPPING | X86_PDE_P | X86_PDE_A | X86_PDE_RW | X86_PDE_US | pMap->aPTs[i].HCPhysPaePT0), 523 iPDE, iPD, iPaePDE, pMap->GCPtr, R3STRING(pMap->pszDesc) )); 514 524 515 525 iPaePDE++; … … 517 527 518 528 AssertMsg(pShwPaePd->a[iPaePDE].u == (PGM_PDFLAGS_MAPPING | X86_PDE_P | X86_PDE_A | X86_PDE_RW | X86_PDE_US | pMap->aPTs[i].HCPhysPaePT1), 519 ("Expected %RX64 vs %RX64\n", pShwPaePd->a[iPDE].u, (PGM_PDFLAGS_MAPPING | X86_PDE_P | X86_PDE_A | X86_PDE_RW | X86_PDE_US | (uint32_t)pMap->aPTs[i].HCPhysPaePT1))); 520 521 Assert(pPdpt->a[iPD].u & PGM_PLXFLAGS_MAPPING); 529 ("Expected %RX64 vs %RX64; iPDE=%#x iPD=%#x iPaePDE=%#x %RGv %s\n", 530 pShwPaePd->a[iPDE].u, (PGM_PDFLAGS_MAPPING | X86_PDE_P | X86_PDE_A | X86_PDE_RW | X86_PDE_US | pMap->aPTs[i].HCPhysPaePT1), 531 iPDE, iPD, iPaePDE, pMap->GCPtr, R3STRING(pMap->pszDesc) )); 532 533 AssertMsg(pPdpt->a[iPD].u & PGM_PLXFLAGS_MAPPING, 534 ("%RX64; iPD=%#x iPDE=%#x iPaePDE=%#x %RGv %s\n", 535 pPdpt->a[iPD].u, 536 iPDE, iPD, iPaePDE, pMap->GCPtr, R3STRING(pMap->pszDesc) )); 522 537 break; 523 538 } … … 530 545 } 531 546 547 532 548 /** 533 549 * Check the hypervisor mappings in the active CR3. … … 558 574 559 575 #ifndef IN_RING0 576 560 577 /** 561 578 * Apply the hypervisor mappings to the active CR3. … … 573 590 return VINF_SUCCESS; 574 591 575 /* @noteA log flush (in RC) can cause problems when called from MapCR3 (inconsistent state will trigger assertions). */576 Log4((" PGMMapActivateAll fixed mappings=%d\n", pVM->pgm.s.fMappingsFixed));592 /* Note. A log flush (in RC) can cause problems when called from MapCR3 (inconsistent state will trigger assertions). */ 593 Log4(("pgmMapActivateCR3: fixed mappings=%d idxShwPageCR3=%#x\n", pVM->pgm.s.fMappingsFixed, pShwPageCR3 ? pShwPageCR3->idx : NIL_PGMPOOL_IDX)); 577 594 578 595 Assert(pShwPageCR3 && pShwPageCR3 == pVM->pgm.s.CTX_SUFF(pShwPageCR3)); … … 584 601 { 585 602 unsigned iPDE = pCur->GCPtr >> X86_PD_SHIFT; 586 587 603 pgmMapSetShadowPDEs(pVM, pCur, iPDE); 588 604 } … … 607 623 608 624 Assert(pShwPageCR3); 625 Log4(("pgmMapDeactivateCR3: fixed mappings=%d idxShwPageCR3=%#x\n", pVM->pgm.s.fMappingsFixed, pShwPageCR3 ? pShwPageCR3->idx : NIL_PGMPOOL_IDX)); 609 626 610 627 /* … … 614 631 { 615 632 unsigned iPDE = pCur->GCPtr >> X86_PD_SHIFT; 616 617 pgmMapClearShadowPDEs(pVM, pShwPageCR3, pCur, iPDE); 633 pgmMapClearShadowPDEs(pVM, pShwPageCR3, pCur, iPDE, true /*fDeactivateCR3*/); 618 634 } 619 635 return VINF_SUCCESS; 620 636 } 637 621 638 622 639 /** … … 711 728 } 712 729 730 713 731 /** 714 732 * Checks and resolves (ring 3 only) guest conflicts with VMM GC mappings. … … 728 746 Assert(enmGuestMode <= PGMMODE_PAE_NX); 729 747 730 /*731 * Iterate mappings.732 */733 748 if (enmGuestMode == PGMMODE_32_BIT) 734 749 { … … 739 754 Assert(pPD); 740 755 741 for (PPGMMAPPING pCur = pVM->pgm.s.CTX_SUFF(pMappings); pCur; pCur = pCur->CTX_SUFF(pNext)) 756 /* 757 * Iterate mappings. 758 */ 759 for (PPGMMAPPING pCur = pVM->pgm.s.CTX_SUFF(pMappings); pCur; ) 742 760 { 743 unsigned iPDE = pCur->GCPtr >> X86_PD_SHIFT; 744 unsigned iPT = pCur->cPTs; 761 PPGMMAPPING pNext = pCur->CTX_SUFF(pNext); 762 unsigned iPDE = pCur->GCPtr >> X86_PD_SHIFT; 763 unsigned iPT = pCur->cPTs; 745 764 while (iPT-- > 0) 746 765 { 747 766 if ( pPD->a[iPDE + iPT].n.u1Present /** @todo PGMGstGetPDE. */ 748 && (pVM->fRawR0Enabled || pPD->a[iPDE + iPT].n.u1User)) 767 && ( pVM->fRawR0Enabled 768 || pPD->a[iPDE + iPT].n.u1User)) 749 769 { 750 770 STAM_COUNTER_INC(&pVM->pgm.s.StatR3DetectedConflicts); … … 753 773 Log(("PGMHasMappingConflicts: Conflict was detected at %08RX32 for mapping %s (32 bits)\n" 754 774 " iPDE=%#x iPT=%#x PDE=%RGp.\n", 755 (iPT + iPDE) << X86_PD_SHIFT, pCur->pszDesc,756 iPDE, iPT, pPD->a[iPDE + iPT].au32[0]));775 (iPT + iPDE) << X86_PD_SHIFT, pCur->pszDesc, 776 iPDE, iPT, pPD->a[iPDE + iPT].au32[0])); 757 777 int rc = pgmR3SyncPTResolveConflict(pVM, pCur, pPD, iPDE << X86_PD_SHIFT); 758 778 AssertRCReturn(rc, rc); 759 760 /*761 * Update pCur.762 */763 pCur = pVM->pgm.s.CTX_SUFF(pMappings);764 while (pCur && pCur->GCPtr < (iPDE << X86_PD_SHIFT))765 pCur = pCur->CTX_SUFF(pNext);766 779 break; 767 780 #else 768 781 Log(("PGMHasMappingConflicts: Conflict was detected at %08RX32 for mapping (32 bits)\n" 769 782 " iPDE=%#x iPT=%#x PDE=%RGp.\n", 770 (iPT + iPDE) << X86_PD_SHIFT,771 iPDE, iPT, pPD->a[iPDE + iPT].au32[0]));783 (iPT + iPDE) << X86_PD_SHIFT, 784 iPDE, iPT, pPD->a[iPDE + iPT].au32[0])); 772 785 return VINF_PGM_SYNC_CR3; 773 786 #endif 774 787 } 775 788 } 776 if (!pCur) 777 break; 789 pCur = pNext; 778 790 } 779 791 } … … 781 793 || enmGuestMode == PGMMODE_PAE_NX) 782 794 { 783 for (PPGMMAPPING pCur = pVM->pgm.s.CTX_SUFF(pMappings); pCur; pCur = pCur->CTX_SUFF(pNext)) 795 /* 796 * Iterate mappings. 797 */ 798 for (PPGMMAPPING pCur = pVM->pgm.s.CTX_SUFF(pMappings); pCur;) 784 799 { 785 RTGCPTR GCPtr = pCur->GCPtr;786 787 unsigned iPT= pCur->cb >> X86_PD_PAE_SHIFT;800 PPGMMAPPING pNext = pCur->CTX_SUFF(pNext); 801 RTGCPTR GCPtr = pCur->GCPtr; 802 unsigned iPT = pCur->cb >> X86_PD_PAE_SHIFT; 788 803 while (iPT-- > 0) 789 804 { … … 797 812 Log(("PGMHasMappingConflicts: Conflict was detected at %RGv for mapping %s (PAE)\n" 798 813 " PDE=%016RX64.\n", 799 GCPtr, pCur->pszDesc, Pde.u));814 GCPtr, pCur->pszDesc, Pde.u)); 800 815 int rc = pgmR3SyncPTResolveConflictPAE(pVM, pCur, pCur->GCPtr); 801 816 AssertRCReturn(rc, rc); 802 803 /*804 * Update pCur.805 */806 pCur = pVM->pgm.s.CTX_SUFF(pMappings);807 while (pCur && pCur->GCPtr < GCPtr)808 pCur = pCur->CTX_SUFF(pNext);809 817 break; 810 818 #else 811 819 Log(("PGMHasMappingConflicts: Conflict was detected at %RGv for mapping (PAE)\n" 812 820 " PDE=%016RX64.\n", 813 GCPtr, Pde.u));821 GCPtr, Pde.u)); 814 822 return VINF_PGM_SYNC_CR3; 815 823 #endif … … 817 825 GCPtr += (1 << X86_PD_PAE_SHIFT); 818 826 } 819 if (!pCur) 820 break; 827 pCur = pNext; 821 828 } 822 829 } … … 824 831 AssertFailed(); 825 832 833 Assert(!PGMMapHasConflicts(pVM)); 826 834 return VINF_SUCCESS; 827 835 }
Note:
See TracChangeset
for help on using the changeset viewer.