VirtualBox

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


Ignore:
Timestamp:
Mar 4, 2024 10:43:32 AM (12 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
162019
Message:

VMM/IEM: Flush the current program counter to CPUMCTX when in the TLB-miss branch but restore it after the function call to avoid unnecessarily writing CPUMCTX::rip in the TLB-hit path, bugref:10373

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

Legend:

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

    r103649 r103659  
    51355135 * RIP updates, since these are the most common ones.
    51365136 */
    5137 DECL_HIDDEN_THROW(uint32_t) iemNativeRegFlushPendingWrites(PIEMRECOMPILERSTATE pReNative, uint32_t off)
     5137DECL_HIDDEN_THROW(uint32_t) iemNativeRegFlushPendingWrites(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint64_t fGstShwExcept /*= 0*/)
    51385138{
    51395139#ifdef IEMNATIVE_WITH_DELAYED_PC_UPDATING
    5140     off = iemNativeEmitPcWriteback(pReNative, off);
    5141 #else
    5142     RT_NOREF(pReNative);
     5140    if (!(fGstShwExcept & kIemNativeGstReg_Pc))
     5141        off = iemNativeEmitPcWriteback(pReNative, off);
     5142#else
     5143    RT_NOREF(pReNative, fGstShwExcept);
    51435144#endif
    51445145
     
    1170311704     * registers after returning from the call. Not sure if that's sensible or
    1170411705     * not, though. */
     11706#ifndef IEMNATIVE_WITH_INSTRUCTION_COUNTING
    1170511707    off = iemNativeRegFlushPendingWrites(pReNative, off);
     11708#else
     11709    /* The program counter is treated differently for now. */
     11710    off = iemNativeRegFlushPendingWrites(pReNative, off, RT_BIT_64(kIemNativeGstReg_Pc));
     11711#endif
    1170611712
    1170711713#ifdef IEMNATIVE_WITH_FREE_AND_FLUSH_VOLATILE_REGS_AT_TLB_LOOKUP
     
    1175411760#endif
    1175511761
     11762#ifdef IEMNATIVE_WITH_DELAYED_PC_UPDATING
     11763    if (pReNative->Core.offPc)
     11764    {
     11765        /*
     11766         * Update the program counter but restore it at the end of the TlbMiss branch.
     11767         * This should allow delaying more program counter updates for the TlbLookup and hit paths
     11768         * which are hopefully much more frequent, reducing the amount of memory accesses.
     11769         */
     11770        /* Allocate a temporary PC register. */
     11771        uint8_t const idxPcReg = iemNativeRegAllocTmpForGuestReg(pReNative, &off, kIemNativeGstReg_Pc, kIemNativeGstRegUse_ForUpdate);
     11772
     11773        /* Perform the addition and store the result. */
     11774        off = iemNativeEmitAddGprImm(pReNative, off, idxPcReg, pReNative->Core.offPc);
     11775        off = iemNativeEmitStoreGprToVCpuU64(pReNative, off, idxPcReg, RT_UOFFSETOF(VMCPU, cpum.GstCtx.rip));
     11776
     11777        /* Free and flush the PC register. */
     11778        iemNativeRegFreeTmp(pReNative, idxPcReg);
     11779        iemNativeRegFlushGuestShadowsByHostMask(pReNative, RT_BIT_32(idxPcReg));
     11780    }
     11781#endif
     11782
    1175611783#ifndef IEMNATIVE_WITH_FREE_AND_FLUSH_VOLATILE_REGS_AT_TLB_LOOKUP
    1175711784    /* Save variables in volatile registers. */
     
    1181111838    off = iemNativeVarRestoreVolatileRegsPostHlpCall(pReNative, off, fHstRegsNotToSave);
    1181211839    off = iemNativeRegRestoreGuestShadowsInVolatileRegs(pReNative, off, TlbState.getActiveRegsWithShadows());
     11840#endif
     11841
     11842#ifdef IEMNATIVE_WITH_DELAYED_PC_UPDATING
     11843    if (pReNative->Core.offPc)
     11844    {
     11845        /*
     11846         * Time to restore the program counter to its original value.
     11847         */
     11848        /* Allocate a temporary PC register. */
     11849        uint8_t const idxPcReg = iemNativeRegAllocTmpForGuestReg(pReNative, &off, kIemNativeGstReg_Pc, kIemNativeGstRegUse_ForUpdate);
     11850
     11851        /* Restore the original value. */
     11852        off = iemNativeEmitSubGprImm(pReNative, off, idxPcReg, pReNative->Core.offPc);
     11853        off = iemNativeEmitStoreGprToVCpuU64(pReNative, off, idxPcReg, RT_UOFFSETOF(VMCPU, cpum.GstCtx.rip));
     11854
     11855        /* Free and flush the PC register. */
     11856        iemNativeRegFreeTmp(pReNative, idxPcReg);
     11857        iemNativeRegFlushGuestShadowsByHostMask(pReNative, RT_BIT_32(idxPcReg));
     11858    }
    1181311859#endif
    1181411860
  • trunk/src/VBox/VMM/include/IEMN8veRecompiler.h

    r103649 r103659  
    12321232DECLHIDDEN(void)            iemNativeRegFreeVar(PIEMRECOMPILERSTATE pReNative, uint8_t idxHstReg, bool fFlushShadows) RT_NOEXCEPT;
    12331233DECLHIDDEN(void)            iemNativeRegFreeAndFlushMask(PIEMRECOMPILERSTATE pReNative, uint32_t fHstRegMask) RT_NOEXCEPT;
    1234 DECL_HIDDEN_THROW(uint32_t) iemNativeRegFlushPendingWrites(PIEMRECOMPILERSTATE pReNative, uint32_t off);
     1234DECL_HIDDEN_THROW(uint32_t) iemNativeRegFlushPendingWrites(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint64_t fGstShwExept = 0);
    12351235DECL_HIDDEN_THROW(uint32_t) iemNativeRegMoveAndFreeAndFlushAtCall(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t cArgs,
    12361236                                                                  uint32_t fKeepVars = 0);
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