VirtualBox

Changeset 73327 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Jul 23, 2018 2:25:42 PM (7 years ago)
Author:
vboxsync
Message:

NEM/win: Do CR3 flush/update from ring-0 when we can (requires setjmp for VMMCALLRING3_PGM_MAP_CHUNK). bugref:9044

Location:
trunk/src/VBox/VMM
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/NEMAllNativeTemplate-win.cpp.h

    r73323 r73327  
    849849    /* Control registers. */
    850850    bool fMaybeChangedMode = false;
    851     bool fFlushTlb         = false;
    852     bool fFlushGlobalTlb   = false;
     851    bool fUpdateCr3        = false;
    853852    if (fWhat & CPUMCTX_EXTRN_CR_MASK)
    854853    {
     
    860859                CPUMSetGuestCR0(pVCpu, aValues[iReg].Reg64);
    861860                fMaybeChangedMode = true;
    862                 fFlushTlb = fFlushGlobalTlb = true; /// @todo fix this
    863861            }
    864862            iReg++;
     
    871869            {
    872870                CPUMSetGuestCR3(pVCpu, aValues[iReg].Reg64);
    873                 fFlushTlb = true;
     871                fUpdateCr3 = true;
    874872            }
    875873            iReg++;
     
    881879                CPUMSetGuestCR4(pVCpu, aValues[iReg].Reg64);
    882880                fMaybeChangedMode = true;
    883                 fFlushTlb = fFlushGlobalTlb = true; /// @todo fix this
    884881            }
    885882            iReg++;
     
    10991096
    11001097    /* Typical. */
    1101     if (!fMaybeChangedMode && !fFlushTlb)
     1098    if (!fMaybeChangedMode && !fUpdateCr3)
    11021099        return VINF_SUCCESS;
    11031100
     
    11081105    {
    11091106        int rc = PGMChangeMode(pVCpu, pVCpu->cpum.GstCtx.cr0, pVCpu->cpum.GstCtx.cr4, pVCpu->cpum.GstCtx.msrEFER);
    1110         AssertMsg(rc == VINF_SUCCESS, ("rc=%Rrc\n", rc)); NOREF(rc);
    1111     }
    1112 
    1113     if (fFlushTlb)
    1114     {
    1115         int rc = PGMFlushTLB(pVCpu, pVCpu->cpum.GstCtx.cr3, fFlushGlobalTlb);
    1116         AssertMsg(rc == VINF_SUCCESS, ("rc=%Rrc\n", rc)); NOREF(rc);
     1107        AssertMsgReturn(rc == VINF_SUCCESS, ("rc=%Rrc\n", rc), RT_FAILURE_NP(rc) ? rc : VERR_NEM_IPE_1);
     1108    }
     1109
     1110    if (fUpdateCr3)
     1111    {
     1112        int rc = PGMUpdateCR3(pVCpu, pVCpu->cpum.GstCtx.cr3);
     1113        AssertMsgReturn(rc == VINF_SUCCESS, ("rc=%Rrc\n", rc), RT_FAILURE_NP(rc) ? rc : VERR_NEM_IPE_2);
    11171114    }
    11181115
     
    11441141    AssertReturn(idCpu < pGVM->cCpus, VERR_INVALID_VMCPU_HANDLE);
    11451142
    1146     return nemR0WinImportState(pGVM, &pGVM->aCpus[idCpu], &pVCpu->cpum.GstCtx, fWhat);
     1143    return nemR0WinImportState(pGVM, &pGVM->aCpus[idCpu], &pVCpu->cpum.GstCtx, fWhat, true /*fCanUpdateCr3*/);
    11471144# else
    11481145    RT_NOREF(pVCpu, fWhat);
     
    18491846DECLINLINE(VBOXSTRICTRC) nemR0WinImportStateStrict(PGVM pGVM, PGVMCPU pGVCpu, PVMCPU pVCpu, uint64_t fWhat, const char *pszCaller)
    18501847{
    1851     int rc = nemR0WinImportState(pGVM, pGVCpu, &pVCpu->cpum.GstCtx, fWhat);
     1848    int rc = nemR0WinImportState(pGVM, pGVCpu, &pVCpu->cpum.GstCtx, fWhat, true /*fCanUpdateCr3*/);
    18521849    if (RT_SUCCESS(rc))
    18531850    {
     
    43634360        {
    43644361# ifdef IN_RING0
    4365             int rc2 = nemR0WinImportState(pGVM, pGVCpu, &pVCpu->cpum.GstCtx, fImport | CPUMCTX_EXTRN_NEM_WIN_EVENT_INJECT);
     4362            int rc2 = nemR0WinImportState(pGVM, pGVCpu, &pVCpu->cpum.GstCtx, fImport | CPUMCTX_EXTRN_NEM_WIN_EVENT_INJECT,
     4363                                          true /*fCanUpdateCr3*/);
    43664364            if (RT_SUCCESS(rc2))
    43674365                pVCpu->cpum.GstCtx.fExtrn &= ~fImport;
  • trunk/src/VBox/VMM/VMMAll/PGMAll.cpp

    r73324 r73327  
    14421442VMMDECL(int) PGMShwMakePageWritable(PVMCPU pVCpu, RTGCPTR GCPtr, uint32_t fOpFlags)
    14431443{
    1444     return pdmShwModifyPage(pVCpu, GCPtr, X86_PTE_RW, ~(uint64_t)0, fOpFlags);
     1444    if (pVCpu->pgm.s.enmShadowMode != PGMMODE_NONE) /* avoid assertions */
     1445        return pdmShwModifyPage(pVCpu, GCPtr, X86_PTE_RW, ~(uint64_t)0, fOpFlags);
     1446    return VINF_SUCCESS;
    14451447}
    14461448
  • trunk/src/VBox/VMM/VMMR0/NEMR0Native-win.cpp

    r73323 r73327  
    8585#if defined(NEM_WIN_WITH_RING0_RUNLOOP) || defined(NEM_WIN_USE_HYPERCALLS_FOR_REGISTERS)
    8686NEM_TMPL_STATIC int  nemR0WinExportState(PGVM pGVM, PGVMCPU pGVCpu, PCPUMCTX pCtx);
    87 NEM_TMPL_STATIC int  nemR0WinImportState(PGVM pGVM, PGVMCPU pGVCpu, PCPUMCTX pCtx, uint64_t fWhat);
     87NEM_TMPL_STATIC int  nemR0WinImportState(PGVM pGVM, PGVMCPU pGVCpu, PCPUMCTX pCtx, uint64_t fWhat, bool fCanUpdateCr3);
    8888NEM_TMPL_STATIC int  nemR0WinQueryCpuTick(PGVM pGVM, PGVMCPU pGVCpu, uint64_t *pcTicks, uint32_t *pcAux);
    8989NEM_TMPL_STATIC int  nemR0WinResumeCpuTickOnAll(PGVM pGVM, PGVMCPU pGVCpu, uint64_t uPausedTscValue);
     
    13161316 *
    13171317 * @returns VBox status code.
    1318  * @param   pGVM        The ring-0 VM handle.
    1319  * @param   pGVCpu      The ring-0 VCPU handle.
    1320  * @param   pCtx        The CPU context structure to import into.
    1321  * @param   fWhat       What to import, CPUMCTX_EXTRN_XXX.
     1318 * @param   pGVM            The ring-0 VM handle.
     1319 * @param   pGVCpu          The ring-0 VCPU handle.
     1320 * @param   pCtx            The CPU context structure to import into.
     1321 * @param   fWhat           What to import, CPUMCTX_EXTRN_XXX.
     1322 * @param   fCanUpdateCr3   Whether it's safe to update CR3 or not.
    13221323 */
    1323 NEM_TMPL_STATIC int nemR0WinImportState(PGVM pGVM, PGVMCPU pGVCpu, PCPUMCTX pCtx, uint64_t fWhat)
     1324NEM_TMPL_STATIC int nemR0WinImportState(PGVM pGVM, PGVMCPU pGVCpu, PCPUMCTX pCtx, uint64_t fWhat, bool fCanUpdateCr3)
    13241325{
    13251326    HV_INPUT_GET_VP_REGISTERS *pInput = (HV_INPUT_GET_VP_REGISTERS *)pGVCpu->nem.s.HypercallData.pbPage;
     
    17191720    /* Control registers. */
    17201721    bool fMaybeChangedMode = false;
    1721     bool fFlushTlb         = false;
    1722     bool fFlushGlobalTlb   = false;
     1722    bool fUpdateCr3        = false;
    17231723    if (fWhat & CPUMCTX_EXTRN_CR_MASK)
    17241724    {
     
    17301730                CPUMSetGuestCR0(pVCpu, paValues[iReg].Reg64);
    17311731                fMaybeChangedMode = true;
    1732                 fFlushTlb = fFlushGlobalTlb = true; /// @todo fix this
    17331732            }
    17341733            iReg++;
     
    17461745            {
    17471746                CPUMSetGuestCR3(pVCpu, paValues[iReg].Reg64);
    1748                 fFlushTlb = true;
     1747                fUpdateCr3 = true;
    17491748            }
    17501749            iReg++;
     
    17571756                CPUMSetGuestCR4(pVCpu, paValues[iReg].Reg64);
    17581757                fMaybeChangedMode = true;
    1759                 fFlushTlb = fFlushGlobalTlb = true; /// @todo fix this
    17601758            }
    17611759            iReg++;
     
    21612159
    21622160    /* Typical. */
    2163     if (!fMaybeChangedMode && !fFlushTlb)
     2161    if (!fMaybeChangedMode && !fUpdateCr3)
    21642162        return VINF_SUCCESS;
    21652163
     
    21712169    {
    21722170        rc = PGMChangeMode(pVCpu, pCtx->cr0, pCtx->cr4, pCtx->msrEFER);
    2173         AssertMsg(rc == VINF_SUCCESS, ("rc=%Rrc\n", rc));
    2174     }
    2175 
    2176     if (fFlushTlb)
    2177     {
    2178         LogFlow(("nemR0WinImportState: -> VERR_NEM_FLUSH_TLB!\n"));
    2179         /** @todo eliminate the VERR_NEM_FLUSH_TLB/VINF_NEM_FLUSH_TLB complication */
    2180         rc = VERR_NEM_FLUSH_TLB; /* Calling PGMFlushTLB w/o long jump setup doesn't work, ring-3 does it. */
     2171        AssertMsgReturn(rc == VINF_SUCCESS, ("rc=%Rrc\n", rc), RT_FAILURE_NP(rc) ? rc : VERR_NEM_IPE_1);
     2172    }
     2173
     2174    if (fUpdateCr3)
     2175    {
     2176        if (fCanUpdateCr3)
     2177        {
     2178            LogFlow(("nemR0WinImportState: -> PGMUpdateCR3!\n"));
     2179            rc = PGMUpdateCR3(pVCpu, pCtx->cr3);
     2180            AssertMsgReturn(rc == VINF_SUCCESS, ("rc=%Rrc\n", rc), RT_FAILURE_NP(rc) ? rc : VERR_NEM_IPE_2);
     2181        }
     2182        else
     2183        {
     2184            LogFlow(("nemR0WinImportState: -> VERR_NEM_FLUSH_TLB!\n"));
     2185            rc = VERR_NEM_FLUSH_TLB; /* Calling PGMFlushTLB w/o long jump setup doesn't work, ring-3 does it. */
     2186        }
    21812187    }
    21822188
     
    22132219         * Call worker.
    22142220         */
    2215         rc = nemR0WinImportState(pGVM, pGVCpu, &pVCpu->cpum.GstCtx, fWhat);
     2221        rc = nemR0WinImportState(pGVM, pGVCpu, &pVCpu->cpum.GstCtx, fWhat, false /*fCanUpdateCr3*/);
    22162222    }
    22172223    return rc;
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