VirtualBox

Changeset 52761 in vbox


Ignore:
Timestamp:
Sep 16, 2014 3:49:57 PM (10 years ago)
Author:
vboxsync
Message:

GIM nits: Must check version and config when loading saved state. Saved state version macros shouldn't be called guest-interface-manager-saved-state-manager-version, but rather guest-interface-manager-saved-state-version. SSM failures are sticky, so no need for AssertRCReturn for every SSM call, only when we want to use the data. First sentence of function documentation provide a brief description of the function and for readability purposes stand alone (also, keep it short when possible).

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

Legend:

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

    r52699 r52761  
    8989     * Register the saved state data unit.
    9090     */
    91     int rc;
    92     rc = SSMR3RegisterInternal(pVM, "GIM", 0 /* uInstance */, GIM_SSM_VERSION, sizeof(GIM),
    93                                     NULL /* pfnLivePrep */, NULL /* pfnLiveExec */, NULL /* pfnLiveVote*/,
    94                                     NULL /* pfnSavePrep */, gimR3Save,              NULL /* pfnSaveDone */,
    95                                     NULL /* pfnLoadPrep */, gimR3Load,              NULL /* pfnLoadDone */);
     91    int rc = SSMR3RegisterInternal(pVM, "GIM", 0 /* uInstance */, GIM_SAVED_STATE_VERSION, sizeof(GIM),
     92                                   NULL /* pfnLivePrep */, NULL /* pfnLiveExec */, NULL /* pfnLiveVote*/,
     93                                   NULL /* pfnSavePrep */, gimR3Save,              NULL /* pfnSaveDone */,
     94                                   NULL /* pfnLoadPrep */, gimR3Load,              NULL /* pfnLoadDone */);
    9695    if (RT_FAILURE(rc))
    9796        return rc;
     
    128127        pVM->gim.s.fEnabled = true;
    129128        pVM->gim.s.u32Version = uVersion;
     129        /** @todo r=bird: Because u32Version is saved, it should be translated to the
     130         *        'most up-to-date implementation' version number when 0. Otherwise,
     131         *        we'll have abiguities when loading the state of older VMs. */
    130132        if (!RTStrCmp(szProvider, "Minimal"))
    131133        {
     
    140142        /** @todo KVM and others. */
    141143        else
    142         {
    143             LogRel(("GIM: Provider \"%s\" unknown.\n", szProvider));
    144             rc = VERR_GIM_INVALID_PROVIDER;
    145         }
     144            rc = VMR3SetError(pVM->pUVM, VERR_GIM_INVALID_PROVIDER, RT_SRC_POS, "Provider \"%s\" unknown.", szProvider);
    146145    }
    147146    return rc;
     
    151150/**
    152151 * Initializes the remaining bits of the GIM provider.
     152 *
    153153 * This is called after initializing HM and most other VMM components.
    154154 *
     
    179179
    180180/**
    181  * Applies relocations to data and code managed by this component. This function
    182  * will be called at init and whenever the VMM need to relocate itself inside
    183  * the GC.
     181 * Applies relocations to data and code managed by this component.
     182 *
     183 * This function will be called at init and whenever the VMM need to relocate
     184 * itself inside the GC.
    184185 *
    185186 * @param   pVM         Pointer to the VM.
     
    235236    int rc;
    236237#if 0
     238    SSMR3PutU32(pSSM, pVM->cCpus);
    237239    for (VMCPUID i = 0; i < pVM->cCpus; i++)
    238240    {
     
    244246     * Save per-VM data.
    245247     */
    246     rc = SSMR3PutBool(pSSM, pVM->gim.s.fEnabled);
    247     AssertRCReturn(rc, rc);
    248     rc = SSMR3PutU32(pSSM, pVM->gim.s.enmProviderId);
    249     AssertRCReturn(rc, rc);
     248    SSMR3PutBool(pSSM, pVM->gim.s.fEnabled);
     249    SSMR3PutU32(pSSM, pVM->gim.s.enmProviderId);
    250250    rc = SSMR3PutU32(pSSM, pVM->gim.s.u32Version);
    251251    AssertRCReturn(rc, rc);
     
    285285    if (uPass != SSM_PASS_FINAL)
    286286        return VINF_SUCCESS;
     287    if (uVersion != GIM_SAVED_STATE_VERSION)
     288        return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
     289
    287290
    288291    /** @todo Load per-CPU data. */
     
    298301     * Load per-VM data.
    299302     */
    300     rc = SSMR3GetBool(pSSM, &pVM->gim.s.fEnabled);
     303    bool fEnabled;
     304    SSMR3GetBool(pSSM, &fEnabled);
     305    uint32_t uProviderId;
     306    SSMR3GetU32(pSSM, &uProviderId);
     307    uint32_t uProviderVersion;
     308    rc = SSMR3GetU32(pSSM, &uProviderVersion);
    301309    AssertRCReturn(rc, rc);
    302     rc = SSMR3GetU32(pSSM, (uint32_t *)&pVM->gim.s.enmProviderId);
    303     AssertRCReturn(rc, rc);
    304     rc = SSMR3GetU32(pSSM, &pVM->gim.s.u32Version);
    305     AssertRCReturn(rc, rc);
     310
     311    if ((GIMPROVIDERID)uProviderId != pVM->gim.s.enmProviderId)
     312        return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Saved GIM provider %u differs from the configured one (%u)."),
     313                                uProviderId, pVM->gim.s.enmProviderId);
     314#if 0 /** @todo r=bird: Figure out what you mean to do here with the version. */
     315    if (uProviderVersion != pVM->gim.s.u32Version)
     316        return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Saved GIM provider version %u differs from the configured one (%u)."),
     317                                uProviderVersion, pVM->gim.s.u32Version);
     318#else
     319    pVM->gim.s.u32Version = uProviderVersion;
     320#endif
    306321
    307322    /*
  • trunk/src/VBox/VMM/VMMR3/GIMHv.cpp

    r52699 r52761  
    3535#include <VBox/version.h>
    3636
     37
    3738/*******************************************************************************
    3839*   Defined Constants And Macros                                               *
    3940*******************************************************************************/
    4041//#define GIMHV_HYPERCALL                 "GIMHvHypercall"
     42
     43/**
     44 * GIM Hyper-V saved-state version.
     45 */
     46#define GIM_HV_SAVED_STATE_VERSION          UINT32_C(1)
     47
     48
     49/*******************************************************************************
     50*   Global Variables                                                           *
     51*******************************************************************************/
    4152#ifdef VBOX_WITH_STATISTICS
    4253# define GIMHV_MSRRANGE(a_uFirst, a_uLast, a_szName) \
     
    360371     * Save the Hyper-V SSM version.
    361372     */
    362     int rc = SSMR3PutU32(pSSM, GIM_HV_SSM_VERSION);         AssertRCReturn(rc, rc);
     373    SSMR3PutU32(pSSM, GIM_HV_SAVED_STATE_VERSION);
    363374
    364375    /** @todo Save per-VCPU data. */
     
    367378     * Save per-VM MSRs.
    368379     */
    369     rc = SSMR3PutU64(pSSM, pcHv->u64GuestOsIdMsr);          AssertRCReturn(rc, rc);
    370     rc = SSMR3PutU64(pSSM, pcHv->u64HypercallMsr);          AssertRCReturn(rc, rc);
    371     rc = SSMR3PutU64(pSSM, pcHv->u64TscPageMsr);            AssertRCReturn(rc, rc);
     380    SSMR3PutU64(pSSM, pcHv->u64GuestOsIdMsr);
     381    SSMR3PutU64(pSSM, pcHv->u64HypercallMsr);
     382    SSMR3PutU64(pSSM, pcHv->u64TscPageMsr);
    372383
    373384    /*
    374385     * Save Hyper-V features / capabilities.
    375386     */
    376     rc = SSMR3PutU32(pSSM, pcHv->uBaseFeat);                AssertRCReturn(rc, rc);
    377     rc = SSMR3PutU32(pSSM, pcHv->uPartFlags);               AssertRCReturn(rc, rc);
    378     rc = SSMR3PutU32(pSSM, pcHv->uPowMgmtFeat);             AssertRCReturn(rc, rc);
    379     rc = SSMR3PutU32(pSSM, pcHv->uMiscFeat);                AssertRCReturn(rc, rc);
    380     rc = SSMR3PutU32(pSSM, pcHv->uHyperHints);              AssertRCReturn(rc, rc);
    381     rc = SSMR3PutU32(pSSM, pcHv->uHyperCaps);               AssertRCReturn(rc, rc);
     387    SSMR3PutU32(pSSM, pcHv->uBaseFeat);
     388    SSMR3PutU32(pSSM, pcHv->uPartFlags);
     389    SSMR3PutU32(pSSM, pcHv->uPowMgmtFeat);
     390    SSMR3PutU32(pSSM, pcHv->uMiscFeat);
     391    SSMR3PutU32(pSSM, pcHv->uHyperHints);
     392    SSMR3PutU32(pSSM, pcHv->uHyperCaps);
    382393
    383394    /*
     
    385396     */
    386397    PCGIMMMIO2REGION pcRegion = &pcHv->aMmio2Regions[GIM_HV_HYPERCALL_PAGE_REGION_IDX];
    387     rc = SSMR3PutU8(pSSM,     pcRegion->iRegion);           AssertRCReturn(rc, rc);
    388     rc = SSMR3PutBool(pSSM,   pcRegion->fRCMapping);        AssertRCReturn(rc, rc);
    389     rc = SSMR3PutU32(pSSM,    pcRegion->cbRegion);          AssertRCReturn(rc, rc);
    390     rc = SSMR3PutGCPhys(pSSM, pcRegion->GCPhysPage);        AssertRCReturn(rc, rc);
    391     rc = SSMR3PutStrZ(pSSM,   pcRegion->szDescription);     AssertRCReturn(rc, rc);
     398    SSMR3PutU8(pSSM,     pcRegion->iRegion);
     399    SSMR3PutBool(pSSM,   pcRegion->fRCMapping);
     400    SSMR3PutU32(pSSM,    pcRegion->cbRegion);
     401    SSMR3PutGCPhys(pSSM, pcRegion->GCPhysPage);
     402    SSMR3PutStrZ(pSSM,   pcRegion->szDescription);
    392403
    393404    /*
     
    395406     */
    396407    pcRegion = &pcHv->aMmio2Regions[GIM_HV_REF_TSC_PAGE_REGION_IDX];
    397     rc = SSMR3PutU8(pSSM,     pcRegion->iRegion);           AssertRCReturn(rc, rc);
    398     rc = SSMR3PutBool(pSSM,   pcRegion->fRCMapping);        AssertRCReturn(rc, rc);
    399     rc = SSMR3PutU32(pSSM,    pcRegion->cbRegion);          AssertRCReturn(rc, rc);
    400     rc = SSMR3PutGCPhys(pSSM, pcRegion->GCPhysPage);        AssertRCReturn(rc, rc);
    401     rc = SSMR3PutStrZ(pSSM,   pcRegion->szDescription);     AssertRCReturn(rc, rc);
     408    SSMR3PutU8(pSSM,     pcRegion->iRegion);
     409    SSMR3PutBool(pSSM,   pcRegion->fRCMapping);
     410    SSMR3PutU32(pSSM,    pcRegion->cbRegion);
     411    SSMR3PutGCPhys(pSSM, pcRegion->GCPhysPage);
     412    SSMR3PutStrZ(pSSM,   pcRegion->szDescription);
    402413    /* Save the TSC sequence so we can bump it on restore (as the CPU frequency/offset may change). */
    403414    uint32_t uTscSequence = 0;
     
    408419        uTscSequence = pcRefTsc->u32TscSequence;
    409420    }
    410     rc = SSMR3PutU32(pSSM,    uTscSequence);                AssertRCReturn(rc, rc);
    411 
    412     return VINF_SUCCESS;
     421
     422    return SSMR3PutU32(pSSM, uTscSequence);
    413423}
    414424
     
    429439     * Load the Hyper-V SSM version first.
    430440     */
    431     uint32_t uHvSSMVersion;
    432     int rc = SSMR3GetU32(pSSM, &uHvSSMVersion);             AssertRCReturn(rc, rc);
     441    uint32_t uHvSavedStatVersion;
     442    int rc = SSMR3GetU32(pSSM, &uHvSavedStatVersion);
     443    AssertRCReturn(rc, rc);
     444    if (uHvSavedStatVersion != GIM_HV_SAVED_STATE_VERSION)
     445        return SSMR3SetLoadError(pSSM, VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION, RT_SRC_POS,
     446                                 N_("Unsupported Hyper-V saved state version %u (expected %u)."),
     447                                 uHvSavedStatVersion, GIM_HV_SAVED_STATE_VERSION);
     448
    433449
    434450    /** @todo Load per-VCPU data. */
     
    437453     * Load per-VM MSRs.
    438454     */
    439     rc = SSMR3GetU64(pSSM, &pHv->u64GuestOsIdMsr);          AssertRCReturn(rc, rc);
    440     rc = SSMR3GetU64(pSSM, &pHv->u64HypercallMsr);          AssertRCReturn(rc, rc);
    441     rc = SSMR3GetU64(pSSM, &pHv->u64TscPageMsr);            AssertRCReturn(rc, rc);
     455    SSMR3GetU64(pSSM, &pHv->u64GuestOsIdMsr);
     456    SSMR3GetU64(pSSM, &pHv->u64HypercallMsr);
     457    SSMR3GetU64(pSSM, &pHv->u64TscPageMsr);
    442458
    443459    /*
    444460     * Load Hyper-V features / capabilities.
    445461     */
    446     rc = SSMR3GetU32(pSSM, &pHv->uBaseFeat);                AssertRCReturn(rc, rc);
    447     rc = SSMR3GetU32(pSSM, &pHv->uPartFlags);               AssertRCReturn(rc, rc);
    448     rc = SSMR3GetU32(pSSM, &pHv->uPowMgmtFeat);             AssertRCReturn(rc, rc);
    449     rc = SSMR3GetU32(pSSM, &pHv->uMiscFeat);                AssertRCReturn(rc, rc);
    450     rc = SSMR3GetU32(pSSM, &pHv->uHyperHints);              AssertRCReturn(rc, rc);
    451     rc = SSMR3GetU32(pSSM, &pHv->uHyperCaps);               AssertRCReturn(rc, rc);
     462    SSMR3GetU32(pSSM, &pHv->uBaseFeat);
     463    SSMR3GetU32(pSSM, &pHv->uPartFlags);
     464    SSMR3GetU32(pSSM, &pHv->uPowMgmtFeat);
     465    SSMR3GetU32(pSSM, &pHv->uMiscFeat);
     466    SSMR3GetU32(pSSM, &pHv->uHyperHints);
     467    SSMR3GetU32(pSSM, &pHv->uHyperCaps);
    452468
    453469    /*
     
    455471     */
    456472    PGIMMMIO2REGION pRegion = &pHv->aMmio2Regions[GIM_HV_HYPERCALL_PAGE_REGION_IDX];
    457     rc = SSMR3GetU8(pSSM,     &pRegion->iRegion);           AssertRCReturn(rc, rc);
    458     rc = SSMR3GetBool(pSSM,   &pRegion->fRCMapping);        AssertRCReturn(rc, rc);
    459     rc = SSMR3GetU32(pSSM,    &pRegion->cbRegion);          AssertRCReturn(rc, rc);
    460     rc = SSMR3GetGCPhys(pSSM, &pRegion->GCPhysPage);        AssertRCReturn(rc, rc);
    461     rc = SSMR3GetStrZ(pSSM,    pRegion->szDescription, sizeof(pRegion->szDescription));
     473    SSMR3GetU8(pSSM,     &pRegion->iRegion);
     474    SSMR3GetBool(pSSM,   &pRegion->fRCMapping);
     475    SSMR3GetU32(pSSM,    &pRegion->cbRegion);
     476    SSMR3GetGCPhys(pSSM, &pRegion->GCPhysPage);
     477    rc = SSMR3GetStrZ(pSSM, pRegion->szDescription, sizeof(pRegion->szDescription));
    462478    AssertRCReturn(rc, rc);
    463479    if (MSR_GIM_HV_HYPERCALL_IS_ENABLED(pHv->u64HypercallMsr))
     
    480496    uint32_t uTscSequence;
    481497    pRegion = &pHv->aMmio2Regions[GIM_HV_REF_TSC_PAGE_REGION_IDX];
    482     rc = SSMR3GetU8(pSSM,     &pRegion->iRegion);           AssertRCReturn(rc, rc);
    483     rc = SSMR3GetBool(pSSM,   &pRegion->fRCMapping);        AssertRCReturn(rc, rc);
    484     rc = SSMR3GetU32(pSSM,    &pRegion->cbRegion);          AssertRCReturn(rc, rc);
    485     rc = SSMR3GetGCPhys(pSSM, &pRegion->GCPhysPage);        AssertRCReturn(rc, rc);
    486     rc = SSMR3GetStrZ(pSSM,    pRegion->szDescription, sizeof(pRegion->szDescription));
    487     rc = SSMR3GetU32(pSSM,    &uTscSequence);               AssertRCReturn(rc, rc);
     498    SSMR3GetU8(pSSM,     &pRegion->iRegion);
     499    SSMR3GetBool(pSSM,   &pRegion->fRCMapping);
     500    SSMR3GetU32(pSSM,    &pRegion->cbRegion);
     501    SSMR3GetGCPhys(pSSM, &pRegion->GCPhysPage);
     502    SSMR3GetStrZ(pSSM,    pRegion->szDescription, sizeof(pRegion->szDescription));
     503    rc = SSMR3GetU32(pSSM, &uTscSequence);
    488504    AssertRCReturn(rc, rc);
    489505    if (MSR_GIM_HV_REF_TSC_IS_ENABLED(pHv->u64TscPageMsr))
  • trunk/src/VBox/VMM/include/GIMInternal.h

    r52247 r52761  
    3232
    3333/** The saved state version. */
    34 #define GIM_SSM_VERSION                          1
     34#define GIM_SAVED_STATE_VERSION         1
    3535
    3636/**
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