VirtualBox

Changeset 106144 in vbox for trunk


Ignore:
Timestamp:
Sep 24, 2024 9:43:50 PM (2 months ago)
Author:
vboxsync
Message:

VMM/IEM: Relaxed iemNativeEmitGprByVCpuSignedDisp assertions to avoid trouble on Linux with supdrv; changed the range assertion in the caller (iemNativeRecompFunc_BltIn_CheckTimersAndIrqsCommon) to include a LogRelMax statement with details in the unlikely event it should ever trigger. bugref:10720

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

Legend:

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

    r106125 r106144  
    206206 */
    207207template<bool const a_fCheckTimers, bool const a_fCheckIrqs>
    208 DECL_FORCE_INLINE(uint32_t) iemNativeRecompFunc_BltIn_CheckTimersAndIrqsCommon(PIEMRECOMPILERSTATE pReNative, uint32_t off)
     208DECL_FORCE_INLINE_THROW(uint32_t) iemNativeRecompFunc_BltIn_CheckTimersAndIrqsCommon(PIEMRECOMPILERSTATE pReNative, uint32_t off)
    209209{
    210210    uint8_t const         idxEflReg  = !a_fCheckIrqs ? UINT8_MAX
     
    275275        /* OR in VM::fGlobalForcedActions.  We access the member via pVCpu.
    276276           No need to mask anything here.  Unfortunately, it's a 32-bit
    277            variable, so we can't OR it directly on x86. */
     277           variable, so we can't OR it directly on x86.
     278
     279           Note! We take a tiny liberty here and ASSUME that the VM and associated
     280                 VMCPU mappings are less than 2 GiB away from one another, so we
     281                 can access VM::fGlobalForcedActions via a 32-bit signed displacement.
     282
     283                 This is _only_ a potential issue with VMs using the _support_ _driver_
     284                 for manging the structure, as it maps the individual bits separately
     285                 and the mapping order differs between host platforms.  Linux may
     286                 map the VM structure higher than the VMCPU ones, whereas windows may
     287                 do put the VM structure in the lowest address.  On all hosts there
     288                 is a chance that virtual memory fragmentation could cause the bits to
     289                 end up at a greater distance from one another, but it is rather
     290                 doubtful and we just ASSUME it won't happen for now...
     291
     292                 When the VM structure is allocated in userland, there is one
     293                 allocation for it and all the associated VMCPU components, thus no
     294                 problems. */
    278295        AssertCompile(VM_FF_ALL_MASK == UINT32_MAX);
    279296        intptr_t const offGlobalForcedActions = (intptr_t)&pReNative->pVCpu->CTX_SUFF(pVM)->fGlobalForcedActions
    280297                                              - (intptr_t)pReNative->pVCpu;
    281         Assert((int32_t)offGlobalForcedActions == offGlobalForcedActions);
     298        if (RT_LIKELY((int32_t)offGlobalForcedActions == offGlobalForcedActions))
     299        { /* likely */ }
     300        else
     301        {
     302            LogRelMax(16, ("!!WARNING!! offGlobalForcedActions=%#zx pVM=%p pVCpu=%p - CheckTimersAndIrqsCommon\n",
     303                           offGlobalForcedActions, pReNative->pVCpu->CTX_SUFF(pVM), pReNative->pVCpu));
     304# ifdef IEM_WITH_THROW_CATCH
     305            AssertFailedStmt(IEMNATIVE_DO_LONGJMP(NULL, VERR_IEM_IPE_9));
     306# else
     307            AssertReleaseFailed();
     308# endif
     309        }
    282310
    283311# ifdef RT_ARCH_AMD64
     
    295323
    296324# elif defined(RT_ARCH_ARM64)
     325        Assert(offGlobalForcedActions < 0);
    297326        off = iemNativeEmitGprBySignedVCpuLdStEx(pCodeBuf, off, idxTmpReg2, (int32_t)offGlobalForcedActions,
    298327                                                 kArmv8A64InstrLdStType_Ld_Word, sizeof(uint32_t));
  • trunk/src/VBox/VMM/include/IEMN8veRecompilerEmit.h

    r106125 r106144  
    509509iemNativeEmitGprByVCpuSignedDisp(uint8_t *pbCodeBuf, uint32_t off, uint8_t iGprReg, int32_t offVCpu)
    510510{
    511     Assert(offVCpu < 0);
    512511    if (offVCpu < 128 && offVCpu >= -128)
    513512    {
     
    621620                                   ARMV8A64INSTRLDSTTYPE enmOperation, unsigned cbData, uint8_t iGprTmp = UINT8_MAX)
    622621{
    623     Assert(offVCpu < 0);
    624     Assert((uint32_t)-offVCpu < RT_BIT_32(28)); /* we should be way out of range for problematic sign extending issues. */
    625     Assert(!((uint32_t)-offVCpu & (cbData - 1)));
     622    Assert((uint32_t)RT_ABS(offVCpu) < RT_BIT_32(28)); /* we should be way out of range for problematic sign extending issues. */
     623    Assert(!((uint32_t)RT_ABS(offVCpu) & (cbData - 1)));
    626624
    627625   /*
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