VirtualBox

Changeset 49464 in vbox for trunk/src/VBox/VMM/VMMR3


Ignore:
Timestamp:
Nov 13, 2013 1:02:43 PM (11 years ago)
Author:
vboxsync
Message:

PATM: Fixed saved state regression introduced with r86139, bumping up the saved state version. The change was assuming the structures was saved using the field descriptors, not just restored. Changed the state saving do the right thing. Bumping the version and saving the structures with markers and everything. New version number also helps detecting the affected range of SVN revisions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/PATMSSM.cpp

    r49247 r49464  
    249249
    250250/**
     251 * SSM descriptor table for the PATM structure starting with r86139.
     252 */
     253static SSMFIELD const g_aPatmFields86139[] =
     254{
     255    /** @todo there are a bunch more fields here which can be marked as ignored. */
     256    SSMFIELD_ENTRY_IGNORE(          PATM, offVM),
     257    SSMFIELD_ENTRY_RCPTR(           PATM, pPatchMemGC),
     258    SSMFIELD_ENTRY_IGN_HCPTR(       PATM, pPatchMemHC),
     259    SSMFIELD_ENTRY(                 PATM, cbPatchMem),
     260    SSMFIELD_ENTRY(                 PATM, offPatchMem),
     261    SSMFIELD_ENTRY(                 PATM, fOutOfMemory),
     262    SSMFIELD_ENTRY_PAD_HC_AUTO(     3, 3),
     263    SSMFIELD_ENTRY(                 PATM, deltaReloc),
     264    SSMFIELD_ENTRY_IGN_HCPTR(       PATM, pGCStateHC),
     265    SSMFIELD_ENTRY_RCPTR(           PATM, pGCStateGC),
     266    SSMFIELD_ENTRY_RCPTR(           PATM, pGCStackGC),
     267    SSMFIELD_ENTRY_IGN_HCPTR(       PATM, pGCStackHC),
     268    SSMFIELD_ENTRY_RCPTR(           PATM, pCPUMCtxGC),
     269    SSMFIELD_ENTRY_RCPTR(           PATM, pStatsGC),
     270    SSMFIELD_ENTRY_IGN_HCPTR(       PATM, pStatsHC),
     271    SSMFIELD_ENTRY(                 PATM, uCurrentPatchIdx),
     272    SSMFIELD_ENTRY(                 PATM, ulCallDepth),
     273    SSMFIELD_ENTRY(                 PATM, cPageRecords),
     274    SSMFIELD_ENTRY_RCPTR(           PATM, pPatchedInstrGCLowest),
     275    SSMFIELD_ENTRY_RCPTR(           PATM, pPatchedInstrGCHighest),
     276    SSMFIELD_ENTRY_RCPTR(           PATM, PatchLookupTreeGC),
     277    SSMFIELD_ENTRY_IGN_HCPTR(       PATM, PatchLookupTreeHC),
     278    SSMFIELD_ENTRY_RCPTR(           PATM, pfnHelperCallGC),
     279    SSMFIELD_ENTRY_RCPTR(           PATM, pfnHelperRetGC),
     280    SSMFIELD_ENTRY_RCPTR(           PATM, pfnHelperJumpGC),
     281    SSMFIELD_ENTRY_RCPTR(           PATM, pfnHelperIretGC),
     282    SSMFIELD_ENTRY_IGN_HCPTR(       PATM, pGlobalPatchRec),
     283    SSMFIELD_ENTRY_RCPTR(           PATM, pfnSysEnterGC),
     284    SSMFIELD_ENTRY_RCPTR(           PATM, pfnSysEnterPatchGC),
     285    SSMFIELD_ENTRY(                 PATM, uSysEnterPatchIdx),
     286    SSMFIELD_ENTRY_RCPTR(           PATM, pvFaultMonitor),
     287    SSMFIELD_ENTRY_GCPHYS(          PATM, mmio.GCPhys),
     288    SSMFIELD_ENTRY_RCPTR(           PATM, mmio.pCachedData),
     289    SSMFIELD_ENTRY_IGN_RCPTR(       PATM, mmio.Alignment0),
     290    SSMFIELD_ENTRY_IGN_HCPTR(       PATM, savedstate.pSSM),
     291    SSMFIELD_ENTRY(                 PATM, savedstate.cPatches),
     292    SSMFIELD_ENTRY_PAD_HC64(        PATM, savedstate.Alignment0, sizeof(uint32_t)),
     293    SSMFIELD_ENTRY_IGN_HCPTR(       PATM, hDbgModPatchMem),
     294    SSMFIELD_ENTRY_PAD_HC32(        PATM, Alignment0, sizeof(uint32_t)),
     295    SSMFIELD_ENTRY_IGNORE(          PATM, StatNrOpcodeRead),
     296    SSMFIELD_ENTRY_IGNORE(          PATM, StatDisabled),
     297    SSMFIELD_ENTRY_IGNORE(          PATM, StatUnusable),
     298    SSMFIELD_ENTRY_IGNORE(          PATM, StatEnabled),
     299    SSMFIELD_ENTRY_IGNORE(          PATM, StatInstalled),
     300    SSMFIELD_ENTRY_IGNORE(          PATM, StatInstalledFunctionPatches),
     301    SSMFIELD_ENTRY_IGNORE(          PATM, StatInstalledTrampoline),
     302    SSMFIELD_ENTRY_IGNORE(          PATM, StatInstalledJump),
     303    SSMFIELD_ENTRY_IGNORE(          PATM, StatInt3Callable),
     304    SSMFIELD_ENTRY_IGNORE(          PATM, StatInt3BlockRun),
     305    SSMFIELD_ENTRY_IGNORE(          PATM, StatOverwritten),
     306    SSMFIELD_ENTRY_IGNORE(          PATM, StatFixedConflicts),
     307    SSMFIELD_ENTRY_IGNORE(          PATM, StatFlushed),
     308    SSMFIELD_ENTRY_IGNORE(          PATM, StatPageBoundaryCrossed),
     309    SSMFIELD_ENTRY_IGNORE(          PATM, StatMonitored),
     310    SSMFIELD_ENTRY_IGNORE(          PATM, StatHandleTrap),
     311    SSMFIELD_ENTRY_IGNORE(          PATM, StatSwitchBack),
     312    SSMFIELD_ENTRY_IGNORE(          PATM, StatSwitchBackFail),
     313    SSMFIELD_ENTRY_IGNORE(          PATM, StatPATMMemoryUsed),
     314    SSMFIELD_ENTRY_IGNORE(          PATM, StatDuplicateREQSuccess),
     315    SSMFIELD_ENTRY_IGNORE(          PATM, StatDuplicateREQFailed),
     316    SSMFIELD_ENTRY_IGNORE(          PATM, StatDuplicateUseExisting),
     317    SSMFIELD_ENTRY_IGNORE(          PATM, StatFunctionFound),
     318    SSMFIELD_ENTRY_IGNORE(          PATM, StatFunctionNotFound),
     319    SSMFIELD_ENTRY_IGNORE(          PATM, StatPatchWrite),
     320    SSMFIELD_ENTRY_IGNORE(          PATM, StatPatchWriteDetect),
     321    SSMFIELD_ENTRY_IGNORE(          PATM, StatDirty),
     322    SSMFIELD_ENTRY_IGNORE(          PATM, StatPushTrap),
     323    SSMFIELD_ENTRY_IGNORE(          PATM, StatPatchWriteInterpreted),
     324    SSMFIELD_ENTRY_IGNORE(          PATM, StatPatchWriteInterpretedFailed),
     325    SSMFIELD_ENTRY_IGNORE(          PATM, StatSysEnter),
     326    SSMFIELD_ENTRY_IGNORE(          PATM, StatSysExit),
     327    SSMFIELD_ENTRY_IGNORE(          PATM, StatEmulIret),
     328    SSMFIELD_ENTRY_IGNORE(          PATM, StatEmulIretFailed),
     329    SSMFIELD_ENTRY_IGNORE(          PATM, StatInstrDirty),
     330    SSMFIELD_ENTRY_IGNORE(          PATM, StatInstrDirtyGood),
     331    SSMFIELD_ENTRY_IGNORE(          PATM, StatInstrDirtyBad),
     332    SSMFIELD_ENTRY_IGNORE(          PATM, StatPatchPageInserted),
     333    SSMFIELD_ENTRY_IGNORE(          PATM, StatPatchPageRemoved),
     334    SSMFIELD_ENTRY_IGNORE(          PATM, StatPatchRefreshSuccess),
     335    SSMFIELD_ENTRY_IGNORE(          PATM, StatPatchRefreshFailed),
     336    SSMFIELD_ENTRY_IGNORE(          PATM, StatGenRet),
     337    SSMFIELD_ENTRY_IGNORE(          PATM, StatGenRetReused),
     338    SSMFIELD_ENTRY_IGNORE(          PATM, StatGenJump),
     339    SSMFIELD_ENTRY_IGNORE(          PATM, StatGenCall),
     340    SSMFIELD_ENTRY_IGNORE(          PATM, StatGenPopf),
     341    SSMFIELD_ENTRY_IGNORE(          PATM, StatCheckPendingIRQ),
     342    SSMFIELD_ENTRY_IGNORE(          PATM, StatFunctionLookupReplace),
     343    SSMFIELD_ENTRY_IGNORE(          PATM, StatFunctionLookupInsert),
     344    SSMFIELD_ENTRY_IGNORE(          PATM, StatU32FunctionMaxSlotsUsed),
     345    SSMFIELD_ENTRY_IGNORE(          PATM, Alignment0),
     346    SSMFIELD_ENTRY_TERM()
     347};
     348
     349/**
    251350 * SSM descriptor table for the PATMGCSTATE structure.
    252351 */
     
    433532
    434533    /* Save the lookup record. */
    435     int rc = SSMR3PutMem(pSSM, pPatchToGuestRec, sizeof(RECPATCHTOGUEST));
     534    int rc = SSMR3PutStructEx(pSSM, pPatchToGuestRec, sizeof(RECPATCHTOGUEST), 0 /*fFlags*/, &g_aPatmRecPatchToGuest[0], NULL);
    436535    AssertRCReturn(rc, rc);
    437536
     
    479578
    480579    /* Save the lookup record. */
    481     int rc = SSMR3PutMem(pSSM, &rec, sizeof(rec));
     580    int rc = SSMR3PutStructEx(pSSM, &rec, sizeof(rec), 0 /*fFlags*/, &g_aPatmRelocRec[0], NULL);
    482581    AssertRCReturn(rc, rc);
    483582
     
    595694
    596695    patmR3PatchConvertMem2SSM(&patch, pPatch);
     696    Log4(("patmSavePatchState: cbPatchJump=%u uCurPathOffset=%#x pInstrGCLowest/Higest=%#x/%#x nrFixups=%#x nrJumpRecs=%#x\n",
     697          patch.patch.cbPatchJump, patch.patch.uCurPatchOffset, patch.patch.pInstrGCLowest, patch.patch.pInstrGCHighest,
     698          patch.patch.nrFixups, patch.patch.nrJumpRecs));
    597699
    598700    /*
     
    606708
    607709    /* Save the patch record itself */
    608     rc = SSMR3PutMem(pSSM, &patch, sizeof(patch));
     710    rc = SSMR3PutStructEx(pSSM, &patch, sizeof(patch), 0 /*fFlags*/, &g_aPatmPatchRecFields[0], NULL);
    609711    AssertRCReturn(rc, rc);
    610712
     
    661763     * Save PATM structure
    662764     */
    663     rc = SSMR3PutMem(pSSM, &patmInfo, sizeof(patmInfo));
     765    rc = SSMR3PutStructEx(pSSM, &patmInfo, sizeof(patmInfo), 0 /*fFlags*/, &g_aPatmFields[0], NULL);
    664766    AssertRCReturn(rc, rc);
    665767
     
    673775     * Save GC state memory
    674776     */
    675     rc = SSMR3PutMem(pSSM, pVM->patm.s.pGCStateHC, sizeof(PATMGCSTATE));
     777    rc = SSMR3PutStructEx(pSSM, pVM->patm.s.pGCStateHC, sizeof(PATMGCSTATE), 0 /*fFlags*/, &g_aPatmGCStateFields[0], NULL);
    676778    AssertRCReturn(rc, rc);
    677779
     
    679781     * Save PATM stack page
    680782     */
     783    SSMR3PutU32(pSSM, PATM_STACK_TOTAL_SIZE);
    681784    rc = SSMR3PutMem(pSSM, pVM->patm.s.pGCStackHC, PATM_STACK_TOTAL_SIZE);
    682785    AssertRCReturn(rc, rc);
     
    718821
    719822    if (    uVersion != PATM_SSM_VERSION
     823        &&  uVersion != PATM_SSM_VERSION_MEM
    720824        &&  uVersion != PATM_SSM_VERSION_FIXUP_HACK
    721825        &&  uVersion != PATM_SSM_VERSION_VER16
     
    725829        return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
    726830    }
     831    uint32_t const fStructRestoreFlags = uVersion <= PATM_SSM_VERSION_MEM ? SSMSTRUCT_FLAGS_MEM_BAND_AID_RELAXED : 0;
    727832    Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
    728833
     
    733838     */
    734839    RT_ZERO(patmInfo);
    735     rc = SSMR3GetStructEx(pSSM, &patmInfo, sizeof(patmInfo), SSMSTRUCT_FLAGS_MEM_BAND_AID_RELAXED, &g_aPatmFields[0], NULL);
     840    if (   uVersion == PATM_SSM_VERSION_MEM
     841        && SSMR3HandleRevision(pSSM) >= 86139)
     842        rc = SSMR3GetStructEx(pSSM, &patmInfo, sizeof(patmInfo), SSMSTRUCT_FLAGS_MEM_BAND_AID_RELAXED,
     843                              &g_aPatmFields86139[0], NULL);
     844    else
     845        rc = SSMR3GetStructEx(pSSM, &patmInfo, sizeof(patmInfo), fStructRestoreFlags, &g_aPatmFields[0], NULL);
    736846    AssertRCReturn(rc, rc);
    737847
    738848    /* Relative calls are made to the helper functions. Therefor their relative location must not change! */
    739849    /* Note: we reuse the saved global helpers and assume they are identical, which is kind of dangerous. */
    740     if (    (pVM->patm.s.pfnHelperCallGC - pVM->patm.s.pPatchMemGC) != (patmInfo.pfnHelperCallGC  - patmInfo.pPatchMemGC)
    741         ||  (pVM->patm.s.pfnHelperRetGC  - pVM->patm.s.pPatchMemGC) != (patmInfo.pfnHelperRetGC   - patmInfo.pPatchMemGC)
    742         ||  (pVM->patm.s.pfnHelperJumpGC - pVM->patm.s.pPatchMemGC) != (patmInfo.pfnHelperJumpGC  - patmInfo.pPatchMemGC)
    743         ||  (pVM->patm.s.pfnHelperIretGC - pVM->patm.s.pPatchMemGC) != (patmInfo.pfnHelperIretGC  - patmInfo.pPatchMemGC))
    744     {
    745         AssertMsgFailed(("Helper function ptrs don't match!!!\n"));
    746         return VERR_SSM_INVALID_STATE;
    747     }
    748 
    749     if (pVM->patm.s.cbPatchMem != patmInfo.cbPatchMem)
    750     {
    751         AssertMsgFailed(("Patch memory ptrs and/or sizes don't match!!!\n"));
    752         return VERR_SSM_INVALID_STATE;
    753     }
     850    AssertLogRelReturn((pVM->patm.s.pfnHelperCallGC - pVM->patm.s.pPatchMemGC) == (patmInfo.pfnHelperCallGC  - patmInfo.pPatchMemGC),
     851                       VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
     852    AssertLogRelReturn((pVM->patm.s.pfnHelperRetGC  - pVM->patm.s.pPatchMemGC) == (patmInfo.pfnHelperRetGC   - patmInfo.pPatchMemGC),
     853                       VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
     854    AssertLogRelReturn((pVM->patm.s.pfnHelperJumpGC - pVM->patm.s.pPatchMemGC) == (patmInfo.pfnHelperJumpGC  - patmInfo.pPatchMemGC),
     855                       VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
     856    AssertLogRelReturn((pVM->patm.s.pfnHelperIretGC - pVM->patm.s.pPatchMemGC) == (patmInfo.pfnHelperIretGC  - patmInfo.pPatchMemGC),
     857                       VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
     858    AssertLogRelReturn(pVM->patm.s.cbPatchMem == patmInfo.cbPatchMem, VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
     859
    754860    pVM->patm.s.offPatchMem         = patmInfo.offPatchMem;
    755861    pVM->patm.s.deltaReloc          = patmInfo.deltaReloc;
     
    787893     */
    788894    RT_BZERO(pVM->patm.s.pGCStateHC, sizeof(PATMGCSTATE));
    789     rc = SSMR3GetStructEx(pSSM, pVM->patm.s.pGCStateHC, sizeof(PATMGCSTATE), SSMSTRUCT_FLAGS_MEM_BAND_AID_RELAXED, &g_aPatmGCStateFields[0], NULL);
     895    rc = SSMR3GetStructEx(pSSM, pVM->patm.s.pGCStateHC, sizeof(PATMGCSTATE), fStructRestoreFlags, &g_aPatmGCStateFields[0], NULL);
    790896    AssertRCReturn(rc, rc);
    791897
     
    793899     * Restore PATM stack page
    794900     */
    795     rc = SSMR3GetMem(pSSM, pVM->patm.s.pGCStackHC, PATM_STACK_TOTAL_SIZE);
     901    uint32_t cbStack = PATM_STACK_TOTAL_SIZE;
     902    if (uVersion > PATM_SSM_VERSION_MEM)
     903    {
     904        rc = SSMR3GetU32(pSSM, &cbStack);
     905        AssertRCReturn(rc, rc);
     906    }
     907    AssertCompile(!(PATM_STACK_TOTAL_SIZE & 31));
     908    AssertLogRelMsgReturn(cbStack > 0 && cbStack <= PATM_STACK_TOTAL_SIZE && !(cbStack & 31),
     909                          ("cbStack=%#x vs %#x", cbStack, PATM_STACK_TOTAL_SIZE),
     910                          VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
     911    rc = SSMR3GetMem(pSSM, pVM->patm.s.pGCStackHC, cbStack);
    796912    AssertRCReturn(rc, rc);
     913    if (cbStack < PATM_STACK_TOTAL_SIZE)
     914        memset((uint8_t *)pVM->patm.s.pGCStackHC + cbStack, 0, PATM_STACK_TOTAL_SIZE - cbStack);
    797915
    798916    /*
     
    805923
    806924        RT_ZERO(patch);
    807         rc = SSMR3GetStructEx(pSSM, &patch, sizeof(patch), SSMSTRUCT_FLAGS_MEM_BAND_AID_RELAXED, &g_aPatmPatchRecFields[0], NULL);
     925        rc = SSMR3GetStructEx(pSSM, &patch, sizeof(patch), fStructRestoreFlags, &g_aPatmPatchRecFields[0], NULL);
    808926        AssertRCReturn(rc, rc);
     927        Log4(("patmR3Load: cbPatchJump=%u uCurPathOffset=%#x pInstrGCLowest/Higest=%#x/%#x nrFixups=%#x nrJumpRecs=%#x\n",
     928              patch.patch.cbPatchJump, patch.patch.uCurPatchOffset, patch.patch.pInstrGCLowest, patch.patch.pInstrGCHighest,
     929              patch.patch.nrFixups, patch.patch.nrJumpRecs));
    809930
    810931        Assert(!(patch.patch.flags & PATMFL_GLOBAL_FUNCTIONS));
     
    854975
    855976            RT_ZERO(rec);
    856             rc = SSMR3GetStructEx(pSSM, &rec, sizeof(rec), SSMSTRUCT_FLAGS_MEM_BAND_AID_RELAXED, &g_aPatmRelocRec[0], NULL);
     977            rc = SSMR3GetStructEx(pSSM, &rec, sizeof(rec), fStructRestoreFlags, &g_aPatmRelocRec[0], NULL);
    857978            AssertRCReturn(rc, rc);
    858979
     
    9021023            {
    9031024                RT_ZERO(rec);
    904                 rc = SSMR3GetStructEx(pSSM, &rec, sizeof(rec), SSMSTRUCT_FLAGS_MEM_BAND_AID_RELAXED, &g_aPatmRecPatchToGuest[0], NULL);
     1025                rc = SSMR3GetStructEx(pSSM, &rec, sizeof(rec), fStructRestoreFlags, &g_aPatmRecPatchToGuest[0], NULL);
    9051026                AssertRCReturn(rc, rc);
    9061027
     
    11801301        }
    11811302        else
    1182         if (ulSSMVersion >= PATM_SSM_VERSION)
     1303        if (ulSSMVersion >= PATM_SSM_VERSION_MEM)
    11831304        {
    11841305#ifdef LOG_ENABLED
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