VirtualBox

Changeset 101091 in vbox


Ignore:
Timestamp:
Sep 12, 2023 12:42:45 PM (20 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
159060
Message:

VMM/IEM: Fixed collision list issue when removing. Added length assertions when changing it. bugref:10369

File:
1 edited

Legend:

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

    r101088 r101091  
    460460}
    461461
     462#ifdef VBOX_STRICT
     463/**
     464 * Assertion helper that checks a collisions list count.
     465 */
     466static void iemTbCacheAssertCorrectCount(PIEMTBCACHE pTbCache, uint32_t idxHash, const char *pszOperation)
     467{
     468    PIEMTB pTb   = IEMTBCACHE_PTR_GET_TB(pTbCache->apHash[idxHash]);
     469    int    cLeft = IEMTBCACHE_PTR_GET_COUNT(pTbCache->apHash[idxHash]);
     470    while (pTb)
     471    {
     472        pTb = pTb->pNext;
     473        cLeft--;
     474    }
     475    AssertMsg(cLeft == 0,
     476              ("idxHash=%#x cLeft=%d; entry count=%d; %s\n",
     477               idxHash, cLeft, IEMTBCACHE_PTR_GET_COUNT(pTbCache->apHash[idxHash]), pszOperation));
     478}
     479#endif
     480
    462481
    463482DECL_NO_INLINE(static, void) iemTbCacheAddWithPruning(PVMCPUCC pVCpu, PIEMTBCACHE pTbCache, PIEMTB pTb, uint32_t idxHash)
     
    471490    uintptr_t cInserted    = 0;
    472491    PIEMTB    pTbCollision = IEMTBCACHE_PTR_GET_TB(pTbCache->apHash[idxHash]);
     492
    473493    pTbCache->apHash[idxHash] = NULL; /* Must NULL the entry before trying to free anything. */
    474494
     
    504524        iemTbAllocatorFree(pVCpu, apSortedTbs[idx]);
    505525
    506     /* Chain the new TB together with the ones we like to keep of the existing
    507        ones and insert this list into the hash table. */
     526    /* Then chain the new TB together with the ones we like to keep of the
     527       existing ones and insert this list into the hash table. */
    508528    pTbCollision = pTb;
    509529    for (uintptr_t idx = 0; idx < cKeep; idx++)
     
    512532
    513533    pTbCache->apHash[idxHash] = IEMTBCACHE_PTR_MAKE(pTb, cKeep + 1);
     534#ifdef VBOX_STRICT
     535    iemTbCacheAssertCorrectCount(pTbCache, idxHash, "add w/ pruning");
     536#endif
    514537
    515538    STAM_PROFILE_STOP(&pTbCache->StatPrune, a);
     
    534557            pTb->pNext = IEMTBCACHE_PTR_GET_TB(pTbOldHead);
    535558            pTbCache->apHash[idxHash] = IEMTBCACHE_PTR_MAKE(pTb, cCollisions + 1);
     559#ifdef VBOX_STRICT
     560            iemTbCacheAssertCorrectCount(pTbCache, idxHash, "add");
     561#endif
    536562        }
    537563        else
     
    552578    uint32_t const idxHash = IEMTBCACHE_HASH(pTbCache, pTb->fFlags, pTb->GCPhysPc);
    553579    PIEMTB         pTbHash = IEMTBCACHE_PTR_GET_TB(pTbCache->apHash[idxHash]);
    554 
    555     /* At the head of the collision list? */
     580    uint32_t volatile cLength = IEMTBCACHE_PTR_GET_COUNT(pTbCache->apHash[idxHash]); RT_NOREF(cLength);
     581
     582    /*
     583     * At the head of the collision list?
     584     */
    556585    if (pTbHash == pTb)
    557586    {
     
    559588            pTbCache->apHash[idxHash] = NULL;
    560589        else
     590        {
    561591            pTbCache->apHash[idxHash] = IEMTBCACHE_PTR_MAKE(pTb->pNext,
    562592                                                            IEMTBCACHE_PTR_GET_COUNT(pTbCache->apHash[idxHash]) - 1);
     593#ifdef VBOX_STRICT
     594            iemTbCacheAssertCorrectCount(pTbCache, idxHash, "remove #1");
     595#endif
     596        }
    563597        return true;
    564598    }
    565599
    566     /* Search the collision list. */
     600    /*
     601     * Search the collision list.
     602     */
     603    PIEMTB const pTbHead = pTbHash;
    567604    while (pTbHash)
    568605    {
     
    571608        {
    572609            pTbHash->pNext = pTb->pNext;
    573             pTbCache->apHash[idxHash] = IEMTBCACHE_PTR_MAKE(pTbCache->apHash[idxHash],
    574                                                             IEMTBCACHE_PTR_GET_COUNT(pTbCache->apHash[idxHash]) - 1);
     610            pTbCache->apHash[idxHash] = IEMTBCACHE_PTR_MAKE(pTbHead, IEMTBCACHE_PTR_GET_COUNT(pTbCache->apHash[idxHash]) - 1);
     611#ifdef VBOX_STRICT
     612            iemTbCacheAssertCorrectCount(pTbCache, idxHash, "remove #2");
     613#endif
    575614            return true;
    576615        }
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