VirtualBox

Changeset 80177 in vbox


Ignore:
Timestamp:
Aug 7, 2019 9:55:21 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
132618
Message:

VMM: Kicking out raw-mode - PGMPool. bugref:9517

File:
1 edited

Legend:

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

    r80007 r80177  
    264264                    for (unsigned i = 0; i < 2; i++)
    265265                    {
    266 #  ifdef VBOX_WITH_RAW_MODE_NOT_R0
    267                         if ((uShw.pPDPae->a[iShw + i].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
    268                         {
    269                             Assert(pgmMapAreMappingsEnabled(pVM));
    270                             VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
    271                             LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShwPdpt=%#x iShw=%#x!\n", iShwPdpt, iShw+i));
    272                             break;
    273                         }
    274 #  endif /* VBOX_WITH_RAW_MODE_NOT_R0 */
    275266                        if (uShw.pPDPae->a[iShw+i].n.u1Present)
    276267                        {
     
    290281                            if (iShw2 < RT_ELEMENTS(uShw.pPDPae->a))
    291282                            {
    292 #  ifdef VBOX_WITH_RAW_MODE_NOT_R0
    293                                 if ((uShw.pPDPae->a[iShw2].u & (PGM_PDFLAGS_MAPPING | X86_PDE_P)) == (PGM_PDFLAGS_MAPPING | X86_PDE_P))
    294                                 {
    295                                     Assert(pgmMapAreMappingsEnabled(pVM));
    296                                     VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
    297                                     LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShwPdpt=%#x iShw2=%#x!\n", iShwPdpt, iShw2));
    298                                     break;
    299                                 }
    300 #  endif /* VBOX_WITH_RAW_MODE_NOT_R0 */
    301283                                if (uShw.pPDPae->a[iShw2].n.u1Present)
    302284                                {
     
    366348                LogFlow(("pgmPoolMonitorChainChanging: PGMPOOLKIND_32BIT_PD %x\n", iShw));
    367349                STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPD));
    368 #  ifdef VBOX_WITH_RAW_MODE_NOT_R0
    369                 if (uShw.pPD->a[iShw].u & PGM_PDFLAGS_MAPPING)
     350                if (uShw.pPD->a[iShw].n.u1Present)
    370351                {
    371                     Assert(pgmMapAreMappingsEnabled(pVM));
    372                     VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
    373                     STAM_COUNTER_INC(&(pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZGuestCR3WriteConflict));
    374                     LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
    375                     break;
    376                 }
    377                 else
    378 #  endif /* VBOX_WITH_RAW_MODE_NOT_R0 */
    379                 {
    380                     if (uShw.pPD->a[iShw].n.u1Present)
    381                     {
    382                         LogFlow(("pgmPoolMonitorChainChanging: 32 bit pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPD->a[iShw].u));
    383                         pgmPoolFree(pVM,
    384                                     uShw.pPD->a[iShw].u & X86_PDE_PAE_PG_MASK,
    385                                     pPage->idx,
    386                                     iShw);
    387                         ASMAtomicWriteU32(&uShw.pPD->a[iShw].u, 0);
    388                     }
     352                    LogFlow(("pgmPoolMonitorChainChanging: 32 bit pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPD->a[iShw].u));
     353                    pgmPoolFree(pVM,
     354                                uShw.pPD->a[iShw].u & X86_PDE_PAE_PG_MASK,
     355                                pPage->idx,
     356                                iShw);
     357                    ASMAtomicWriteU32(&uShw.pPD->a[iShw].u, 0);
    389358                }
    390359                /* paranoia / a bit assumptive. */
     
    396365                        &&  iShw2 < RT_ELEMENTS(uShw.pPD->a))
    397366                    {
    398 #   ifdef VBOX_WITH_RAW_MODE_NOT_R0
    399                         if (uShw.pPD->a[iShw2].u & PGM_PDFLAGS_MAPPING)
    400                         {
    401                             Assert(pgmMapAreMappingsEnabled(pVM));
    402                             STAM_COUNTER_INC(&(pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZGuestCR3WriteConflict));
    403                             VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
    404                             LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
    405                             break;
    406                         }
    407 #   endif /* VBOX_WITH_RAW_MODE_NOT_R0 */
    408367                        if (uShw.pPD->a[iShw2].n.u1Present)
    409368                        {
     
    422381                {
    423382                    LogFlow(("pgmPoolMonitorChainChanging: iShw=%#x: %RX32 -> freeing it!\n", iShw, uShw.pPD->a[iShw].u));
    424 # ifdef IN_RC       /* TLB load - we're pushing things a bit... */
    425                     ASMProbeReadByte(pvAddress);
    426 # endif
    427383                    pgmPoolFree(pVM, uShw.pPD->a[iShw].u & X86_PDE_PG_MASK, pPage->idx, iShw);
    428384                    ASMAtomicWriteU32(&uShw.pPD->a[iShw].u, 0);
     
    437393                const unsigned iShw = off / sizeof(X86PDEPAE);
    438394                STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitor,FaultPD));
    439 #ifdef VBOX_WITH_RAW_MODE_NOT_R0
    440                 if (uShw.pPDPae->a[iShw].u & PGM_PDFLAGS_MAPPING)
    441                 {
    442                     Assert(pgmMapAreMappingsEnabled(pVM));
    443                     VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
    444                     STAM_COUNTER_INC(&(pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZGuestCR3WriteConflict));
    445                     LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw=%#x!\n", iShw));
    446                     break;
    447                 }
    448 #endif /* VBOX_WITH_RAW_MODE_NOT_R0 */
     395
    449396                /*
    450397                 * Causes trouble when the guest uses a PDE to refer to the whole page table level
     
    452399                 * table entries -> recheck; probably only applies to the RC case.)
    453400                 */
    454 #ifdef VBOX_WITH_RAW_MODE_NOT_R0
    455                 else
    456 #endif
     401                if (uShw.pPDPae->a[iShw].n.u1Present)
    457402                {
    458                     if (uShw.pPDPae->a[iShw].n.u1Present)
    459                     {
    460                         LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPae->a[iShw].u));
    461                         pgmPoolFree(pVM,
    462                                     uShw.pPDPae->a[iShw].u & X86_PDE_PAE_PG_MASK,
    463                                     pPage->idx,
    464                                     iShw);
    465                         ASMAtomicWriteU64(&uShw.pPDPae->a[iShw].u, 0);
    466                     }
     403                    LogFlow(("pgmPoolMonitorChainChanging: pae pd iShw=%#x: %RX64 -> freeing it!\n", iShw, uShw.pPDPae->a[iShw].u));
     404                    pgmPoolFree(pVM,
     405                                uShw.pPDPae->a[iShw].u & X86_PDE_PAE_PG_MASK,
     406                                pPage->idx,
     407                                iShw);
     408                    ASMAtomicWriteU64(&uShw.pPDPae->a[iShw].u, 0);
    467409                }
     410
    468411                /* paranoia / a bit assumptive. */
    469412                if (    (off & 7)
     
    473416                    AssertBreak(iShw2 < RT_ELEMENTS(uShw.pPDPae->a));
    474417
    475 #ifdef VBOX_WITH_RAW_MODE_NOT_R0
    476                     if (    iShw2 != iShw
    477                         &&  uShw.pPDPae->a[iShw2].u & PGM_PDFLAGS_MAPPING)
    478                     {
    479                         Assert(pgmMapAreMappingsEnabled(pVM));
    480                         VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
    481                         STAM_COUNTER_INC(&(pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZGuestCR3WriteConflict));
    482                         LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
    483                         break;
    484                     }
    485                     else
    486 #endif /* VBOX_WITH_RAW_MODE_NOT_R0 */
    487418                    if (uShw.pPDPae->a[iShw2].n.u1Present)
    488419                    {
     
    513444                if (iShw < X86_PG_PAE_PDPE_ENTRIES)          /* don't use RT_ELEMENTS(uShw.pPDPT->a), because that's for long mode only */
    514445                {
    515 # ifdef VBOX_WITH_RAW_MODE_NOT_R0
    516                     if (uShw.pPDPT->a[iShw].u & PGM_PLXFLAGS_MAPPING)
    517                     {
    518                         Assert(pgmMapAreMappingsEnabled(pVM));
    519                         STAM_COUNTER_INC(&(pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZGuestCR3WriteConflict));
    520                         VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
    521                         LogFlow(("pgmPoolMonitorChainChanging: Detected pdpt conflict at iShw=%#x!\n", iShw));
    522                         break;
    523                     }
    524                     else
    525 # endif /* VBOX_WITH_RAW_MODE_NOT_R0 */
    526446                    if (uShw.pPDPT->a[iShw].n.u1Present)
    527447                    {
     
    542462                            &&  iShw2 < X86_PG_PAE_PDPE_ENTRIES)
    543463                        {
    544 # ifdef VBOX_WITH_RAW_MODE_NOT_R0
    545                             if (uShw.pPDPT->a[iShw2].u & PGM_PLXFLAGS_MAPPING)
    546                             {
    547                                 Assert(pgmMapAreMappingsEnabled(pVM));
    548                                 STAM_COUNTER_INC(&(pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZGuestCR3WriteConflict));
    549                                 VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
    550                                 LogFlow(("pgmPoolMonitorChainChanging: Detected conflict at iShw2=%#x!\n", iShw2));
    551                                 break;
    552                             }
    553                             else
    554 # endif /* VBOX_WITH_RAW_MODE_NOT_R0 */
    555464                            if (uShw.pPDPT->a[iShw2].n.u1Present)
    556465                            {
     
    568477            }
    569478
    570 #ifndef IN_RC
    571479            case PGMPOOLKIND_64BIT_PD_FOR_64BIT_PD:
    572480            {
     
    664572                break;
    665573            }
    666 #endif /* IN_RING0 */
    667574
    668575            default:
     
    745652    }
    746653
    747 # ifndef IN_RC
    748654    /** @todo could make this general, faulting close to rsp should be a safe reuse heuristic. */
    749655    if (   HMHasPendingIrq(pVM)
    750         && (pRegFrame->rsp - pvFault) < 32)
     656        && pRegFrame->rsp - pvFault < 32)
    751657    {
    752658        /* Fault caused by stack writes while trying to inject an interrupt event. */
     
    754660        return true;
    755661    }
    756 # else
    757     NOREF(pVM); NOREF(pvFault);
    758 # endif
    759662
    760663    LogFlow(("Reused instr %RGv %d at %RGv param1.fUse=%llx param1.reg=%d\n", pRegFrame->rip, pDis->pCurInstr->uOpcode, pvFault, pDis->Param1.fUse,  pDis->Param1.Base.idxGenReg));
     
    880783    else if (rc2 == VERR_EM_INTERPRETER)
    881784    {
    882 # ifdef IN_RC
    883         if (PATMIsPatchGCAddr(pVM, pRegFrame->eip))
    884         {
    885             LogFlow(("pgmRZPoolAccessPfHandlerFlush: Interpretation failed for patch code %04x:%RGv, ignoring.\n",
    886                      pRegFrame->cs.Sel, (RTGCPTR)pRegFrame->eip));
    887             rc = VINF_SUCCESS;
    888             STAM_COUNTER_INC(&pPool->StatMonitorPfRZIntrFailPatch2);
    889         }
    890         else
    891 # endif
    892         {
    893             rc = VINF_EM_RAW_EMULATE_INSTR;
    894             STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitorPf,EmulateInstr));
    895         }
     785        rc = VINF_EM_RAW_EMULATE_INSTR;
     786        STAM_COUNTER_INC(&pPool->CTX_MID_Z(StatMonitorPf,EmulateInstr));
    896787    }
    897788    else if (RT_FAILURE_NP(rc2))
     
    952843    while (pRegFrame->rcx)
    953844    {
    954 # if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
     845# ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
    955846        uint32_t iPrevSubset = PGMRZDynMapPushAutoSubset(pVCpu);
    956847        pgmPoolMonitorChainChanging(pVCpu, pPool, pPage, GCPhysFault, NULL, uIncrement);
     
    959850        pgmPoolMonitorChainChanging(pVCpu, pPool, pPage, GCPhysFault, NULL, uIncrement);
    960851# endif
    961 # ifdef IN_RC
    962         *(uint32_t *)(uintptr_t)pu32 = pRegFrame->eax;
    963 # else
    964852        PGMPhysSimpleWriteGCPhys(pVM, GCPhysFault, &pRegFrame->rax, uIncrement);
    965 # endif
    966853        pu32           += uIncrement;
    967854        GCPhysFault    += uIncrement;
     
    1007894     * Clear all the pages. ASSUMES that pvFault is readable.
    1008895     */
    1009 # if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
     896# ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
    1010897    uint32_t iPrevSubset = PGMRZDynMapPushAutoSubset(pVCpu);
    1011898# endif
     
    1026913    }
    1027914
    1028 # if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
     915# ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
    1029916    PGMRZDynMapPopAutoSubset(pVCpu, iPrevSubset);
    1030917# endif
     
    13551242        }
    13561243    }
    1357 # endif /* PGMPOOL_WITH_OPTIMIZED_DIRTY_PT */
     1244# endif /* PGMPOOL_WITH_OPTIMIZED_DIRTY_PT && IN_RING0 */
    13581245
    13591246    STAM_COUNTER_INC(&pPool->StatMonitorPfRZFlushModOverflow);
     
    14521339        else
    14531340            cMaxModifications = 24;
    1454 # ifdef IN_RC
    1455         cMaxModifications *= 2; /* traps are cheaper than exists. */
    1456 # endif
    14571341#endif
    14581342
     
    17871671    Log(("Flush dirty page %RGp cMods=%d\n", pPage->GCPhys, pPage->cModifications));
    17881672
    1789 # if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
     1673# ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
    17901674    PVMCPU   pVCpu = VMMGetCpu(pVM);
    17911675    uint32_t iPrevSubset = PGMRZDynMapPushAutoSubset(pVCpu);
     
    18531737        Log(("Removed dirty page %RGp cMods=%d cChanges=%d\n", pPage->GCPhys, pPage->cModifications, cChanges));
    18541738
    1855 # if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
     1739# ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
    18561740    PGMRZDynMapPopAutoSubset(pVCpu, iPrevSubset);
    18571741# endif
     
    21452029static int pgmPoolCacheFreeOne(PPGMPOOL pPool, uint16_t iUser)
    21462030{
    2147 #ifndef IN_RC
    21482031    const PVM pVM = pPool->CTX_SUFF(pVM);
    2149 #endif
    21502032    Assert(pPool->iAgeHead != pPool->iAgeTail); /* We shouldn't be here if there < 2 cached entries! */
    21512033    STAM_COUNTER_INC(&pPool->StatCacheFreeUpOne);
     
    36663548        else
    36673549        {
    3668 # if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC) /** @todo we can drop this now. */
     3550# ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 /** @todo we can drop this now. */
    36693551            /* Start a subset here because pgmPoolTrackFlushGCPhysPTsSlow and
    36703552               pgmPoolTrackFlushGCPhysPTs will/may kill the pool otherwise. */
     
    36863568            *pfFlushTLBs = true;
    36873569
    3688 # if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
     3570# ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
    36893571            PGMRZDynMapPopAutoSubset(pVCpu, iPrevSubset);
    36903572# endif
     
    38093691                    break;
    38103692                }
    3811 #ifndef IN_RC
     3693
    38123694                case PGMPOOLKIND_EPT_PT_FOR_PHYS:
    38133695                {
     
    38343716                    break;
    38353717                }
    3836 #endif
    3837             }
     3718            }
     3719
    38383720            if (!--cLeft)
    38393721                break;
     
    39623844        case PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD:
    39633845        case PGMPOOLKIND_PAE_PD_FOR_PAE_PD:
    3964 #ifdef IN_RC
    3965             /*
    3966              * In 32 bits PAE mode we *must* invalidate the TLB when changing a
    3967              * PDPT entry; the CPU fetches them only during cr3 load, so any
    3968              * non-present PDPT will continue to cause page faults.
    3969              */
    3970             ASMReloadCR3();
    3971 #endif
    3972             RT_FALL_THRU();
    39733846        case PGMPOOLKIND_PAE_PD_PHYS:
    39743847        case PGMPOOLKIND_PAE_PDPT_PHYS:
     
    49764849    }
    49774850
    4978 #if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
     4851#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
    49794852    /* Start a subset so we won't run out of mapping space. */
    49804853    PVMCPU pVCpu = VMMGetCpu(pVM);
     
    50094882    pgmPoolCacheFlushPage(pPool, pPage);
    50104883
    5011 #if defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) || defined(IN_RC)
     4884#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
    50124885    /* Heavy stuff done. */
    50134886    PGMRZDynMapPopAutoSubset(pVCpu, iPrevSubset);
     
    50974970     * If the pool isn't full grown yet, expand it.
    50984971     */
    5099     if (    pPool->cCurPages < pPool->cMaxPages
    5100 #if defined(IN_RC)
    5101         /* Hack alert: we can't deal with jumps to ring 3 when called from MapCR3 and allocating pages for PAE PDs. */
    5102         &&  enmKind != PGMPOOLKIND_PAE_PD_FOR_PAE_PD
    5103         &&  (enmKind < PGMPOOLKIND_PAE_PD0_FOR_32BIT_PD || enmKind > PGMPOOLKIND_PAE_PD3_FOR_32BIT_PD)
    5104 #endif
    5105         )
     4972    if (pPool->cCurPages < pPool->cMaxPages)
    51064973    {
    51074974        STAM_PROFILE_ADV_SUSPEND(&pPool->StatAlloc, a);
     
    53685235                {
    53695236                    Log(("PGMPoolFlushPage: found pgm pool pages for %RGp\n", GCPhys));
    5370 #ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
     5237# ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
    53715238                    if (pPage->fDirty)
    53725239                        STAM_COUNTER_INC(&pPool->StatForceFlushDirtyPage);
    53735240                    else
    5374 #endif
     5241# endif
    53755242                        STAM_COUNTER_INC(&pPool->StatForceFlushPage);
    53765243                    Assert(!pgmPoolIsPageLocked(pPage));
     
    54085275}
    54095276
    5410 #endif /* IN_RING3 */
    5411 #ifdef IN_RING3
    54125277
    54135278/**
     
    54965361        pPage->cLastAccessHandler = 0;
    54975362        pPage->cLocked    = 0;
    5498 #ifdef VBOX_STRICT
     5363# ifdef VBOX_STRICT
    54995364        pPage->GCPtrDirtyFault = NIL_RTGCPTR;
    5500 #endif
     5365# endif
    55015366    }
    55025367    pPool->aPages[pPool->cCurPages - 1].iNext = NIL_PGMPOOL_IDX;
     
    55605425    pPool->iAgeTail = NIL_PGMPOOL_IDX;
    55615426
    5562 #ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
     5427# ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
    55635428    /* Clear all dirty pages. */
    55645429    pPool->idxFreeDirtyPage = 0;
     
    55665431    for (unsigned i = 0; i < RT_ELEMENTS(pPool->aidxDirtyPages); i++)
    55675432        pPool->aidxDirtyPages[i] = NIL_PGMPOOL_IDX;
    5568 #endif
     5433# endif
    55695434
    55705435    /*
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