VirtualBox

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


Ignore:
Timestamp:
Jan 13, 2010 9:05:35 PM (15 years ago)
Author:
vboxsync
Message:

CPU hotplug: Merge the first patch. Resets a CPU state if a CPU was removed from the VM

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/EM.cpp

    r25732 r25816  
    437437}
    438438
     439VMMR3DECL(void) EMR3ResetCpu(PVMCPU pVCpu)
     440{
     441    pVCpu->em.s.fForceRAW = false;
     442
     443    /* VMR3Reset may return VINF_EM_RESET or VINF_EM_SUSPEND, so transition
     444        out of the HALTED state here so that enmPrevState doesn't end up as
     445        HALTED when EMR3Execute returns. */
     446    if (pVCpu->em.s.enmState == EMSTATE_HALTED)
     447    {
     448        Log(("EMR3ResetCpu: Cpu#%u %s -> %s\n", pVCpu->idCpu, emR3GetStateName(pVCpu->em.s.enmState), pVCpu->idCpu == 0 ? "EMSTATE_NONE" : "EMSTATE_WAIT_SIPI"));
     449        pVCpu->em.s.enmState = pVCpu->idCpu == 0 ? EMSTATE_NONE : EMSTATE_WAIT_SIPI;
     450    }
     451}
    439452
    440453/**
     
    449462    {
    450463        PVMCPU pVCpu = &pVM->aCpus[i];
    451         pVCpu->em.s.fForceRAW = false;
    452 
    453         /* VMR3Reset may return VINF_EM_RESET or VINF_EM_SUSPEND, so transition
    454            out of the HALTED state here so that enmPrevState doesn't end up as
    455            HALTED when EMR3Execute returns. */
    456         if (pVCpu->em.s.enmState == EMSTATE_HALTED)
    457         {
    458             Log(("EMR3Reset: Cpu#%u %s -> %s\n", i, emR3GetStateName(pVCpu->em.s.enmState), i == 0 ? "EMSTATE_NONE" : "EMSTATE_WAIT_SIPI"));
    459             pVCpu->em.s.enmState = i == 0 ? EMSTATE_NONE : EMSTATE_WAIT_SIPI;
    460         }
     464        EMR3ResetCpu(pVCpu);
    461465    }
    462466}
  • trunk/src/VBox/VMM/HWACCM.cpp

    r25386 r25816  
    14581458
    14591459/**
     1460 * Resets a virtual CPU.
     1461 *
     1462 * @param pVCpu    The CPu to reset.
     1463 */
     1464VMMR3DECL(void) HWACCMR3ResetCPU(PVMCPU pVCpu)
     1465{
     1466    /* On first entry we'll sync everything. */
     1467    pVCpu->hwaccm.s.fContextUseFlags = HWACCM_CHANGED_ALL;
     1468
     1469    pVCpu->hwaccm.s.vmx.cr0_mask = 0;
     1470    pVCpu->hwaccm.s.vmx.cr4_mask = 0;
     1471
     1472    pVCpu->hwaccm.s.fActive        = false;
     1473    pVCpu->hwaccm.s.Event.fPending = false;
     1474
     1475    /* Reset state information for real-mode emulation in VT-x. */
     1476    pVCpu->hwaccm.s.vmx.enmLastSeenGuestMode = PGMMODE_REAL;
     1477    pVCpu->hwaccm.s.vmx.enmPrevGuestMode     = PGMMODE_REAL;
     1478    pVCpu->hwaccm.s.vmx.enmCurrGuestMode     = PGMMODE_REAL;
     1479
     1480    /* Reset the contents of the read cache. */
     1481    PVMCSCACHE pCache = &pVCpu->hwaccm.s.vmx.VMCSCache;
     1482    for (unsigned j=0;j<pCache->Read.cValidEntries;j++)
     1483        pCache->Read.aFieldVal[j] = 0;
     1484
     1485#ifdef VBOX_WITH_CRASHDUMP_MAGIC
     1486    /* Magic marker for searching in crash dumps. */
     1487    strcpy((char *)pCache->aMagic, "VMCSCACHE Magic");
     1488    pCache->uMagic = UINT64_C(0xDEADBEEFDEADBEEF);
     1489#endif
     1490}
     1491
     1492/**
    14601493 * The VM is being reset.
    14611494 *
     
    14761509        PVMCPU pVCpu = &pVM->aCpus[i];
    14771510
    1478         /* On first entry we'll sync everything. */
    1479         pVCpu->hwaccm.s.fContextUseFlags = HWACCM_CHANGED_ALL;
    1480 
    1481         pVCpu->hwaccm.s.vmx.cr0_mask = 0;
    1482         pVCpu->hwaccm.s.vmx.cr4_mask = 0;
    1483 
    1484         pVCpu->hwaccm.s.fActive        = false;
    1485         pVCpu->hwaccm.s.Event.fPending = false;
    1486 
    1487         /* Reset state information for real-mode emulation in VT-x. */
    1488         pVCpu->hwaccm.s.vmx.enmLastSeenGuestMode = PGMMODE_REAL;
    1489         pVCpu->hwaccm.s.vmx.enmPrevGuestMode     = PGMMODE_REAL;
    1490         pVCpu->hwaccm.s.vmx.enmCurrGuestMode     = PGMMODE_REAL;
    1491 
    1492         /* Reset the contents of the read cache. */
    1493         PVMCSCACHE pCache = &pVCpu->hwaccm.s.vmx.VMCSCache;
    1494         for (unsigned j=0;j<pCache->Read.cValidEntries;j++)
    1495             pCache->Read.aFieldVal[j] = 0;
    1496 
    1497 #ifdef VBOX_WITH_CRASHDUMP_MAGIC
    1498         /* Magic marker for searching in crash dumps. */
    1499         strcpy((char *)pCache->aMagic, "VMCSCACHE Magic");
    1500         pCache->uMagic = UINT64_C(0xDEADBEEFDEADBEEF);
    1501 #endif
     1511        HWACCMR3ResetCPU(pVCpu);
    15021512    }
    15031513
  • trunk/src/VBox/VMM/PDM.cpp

    r25732 r25816  
    11531153}
    11541154
     1155VMMR3DECL(void) PDMR3ResetCpu(PVMCPU pVCpu)
     1156{
     1157    VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_APIC);
     1158    VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_PIC);
     1159    VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_NMI);
     1160    VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_SMI);
     1161}
    11551162
    11561163/**
     
    12451252    {
    12461253        PVMCPU pVCpu = &pVM->aCpus[idCpu];
    1247         VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_APIC);
    1248         VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_PIC);
    1249         VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_NMI);
    1250         VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_INTERRUPT_SMI);
     1254        PDMR3ResetCpu(pVCpu);
    12511255    }
    12521256    VM_FF_CLEAR(pVM, VM_FF_PDM_DMA);
  • trunk/src/VBox/VMM/PGM.cpp

    r25732 r25816  
    21722172}
    21732173
     2174VMMR3DECL(void) PGMR3ResetCpu(PVM pVM, PVMCPU pVCpu)
     2175{
     2176    int rc = PGM_GST_PFN(Exit, pVCpu)(pVCpu);
     2177    AssertRC(rc);
     2178
     2179    rc = PGMR3ChangeMode(pVM, pVCpu, PGMMODE_REAL);
     2180    AssertRC(rc);
     2181
     2182    STAM_REL_COUNTER_RESET(&pVCpu->pgm.s.cGuestModeChanges);
     2183
     2184    pgmR3PoolResetCpu(pVM, pVCpu);
     2185
     2186    /*
     2187     * Re-init other members.
     2188     */
     2189    pVCpu->pgm.s.fA20Enabled = true;
     2190
     2191    /*
     2192     * Clear the FFs PGM owns.
     2193     */
     2194    VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
     2195    VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL);
     2196}
    21742197
    21752198/**
  • trunk/src/VBox/VMM/PGMInternal.h

    r25647 r25816  
    32853285void            pgmR3PoolRelocate(PVM pVM);
    32863286void            pgmR3PoolReset(PVM pVM);
     3287void            pgmR3PoolResetCpu(PVM pVM, PVMCPU pVCpu);
    32873288void            pgmR3PoolClearAll(PVM pVM);
    32883289
  • trunk/src/VBox/VMM/TRPM.cpp

    r25647 r25816  
    713713}
    714714
     715VMMR3DECL(void) TRPMR3ResetCpu(PVMCPU pVCpu)
     716{
     717    pVCpu->trpm.s.uActiveVector = ~0;
     718}
    715719
    716720/**
     
    746750    {
    747751        PVMCPU pVCpu = &pVM->aCpus[i];
    748         pVCpu->trpm.s.uActiveVector = ~0;
     752        TRPMR3ResetCpu(pVCpu);
    749753    }
    750754    memcpy(&pVM->trpm.s.aIdt[0], &g_aIdt[0], sizeof(pVM->trpm.s.aIdt));
  • trunk/src/VBox/VMM/VM.cpp

    r25238 r25816  
    40424042}
    40434043
     4044DECLCALLBACK(int) vmR3HotunplugCPU(PVM pVM, VMCPUID idCpu)
     4045{
     4046    PVMCPU pVCpu = VMMGetCpuById(pVM, idCpu);
     4047    VMCPU_ASSERT_EMT(pVCpu);
     4048
     4049    /*
     4050     * Reset per CPU resources.
     4051     * Actually only needed for VT-x because the CPU
     4052     * seems to be still in some paged mode and startup
     4053     * fails after a new hotplug event.
     4054     * SVM works fine even without this.
     4055     */
     4056    Log(("vmR3HotunplugCPU for VCPU %d\n", idCpu));
     4057    PGMR3ResetCpu(pVM, pVCpu);
     4058    PDMR3ResetCpu(pVCpu);
     4059    TRPMR3ResetCpu(pVCpu);
     4060    CPUMR3ResetCpu(pVCpu);
     4061    EMR3ResetCpu(pVCpu);
     4062    HWACCMR3ResetCPU(pVCpu);
     4063    return VINF_EM_WAIT_SIPI;
     4064}
     4065
     4066/**
     4067 * Return the package and core id of a CPU.
     4068 *
     4069 * @returns VBOX status code.
     4070 * @param   pVM              The VM to operate on.
     4071 * @param   idCpu            Virtual CPU to get the ID from.
     4072 * @param   pidCpuCore       Where to store the core ID of the virtual CPU.
     4073 * @param   pidCpuPackage    Where to store the package ID of the virtual CPU.
     4074 */
     4075VMMR3DECL(int) VMR3GetCPUCoreAndPackageIdFromCPUId(PVM pVM, VMCPUID idCpu, uint32_t *pidCpuCore, uint32_t *pidCpuPackage)
     4076{
     4077    if (idCpu >= pVM->cCpus)
     4078        return VERR_INVALID_CPU_ID;
     4079
     4080#ifdef VBOX_WITH_MULTI_CORE
     4081    *pidCpuCore    = idCpu;
     4082    *pidCpuPackage = 0;
     4083#else
     4084    *pidCpuCore    = 0;
     4085    *pidCpuPackage = idCpu;
     4086#endif
     4087
     4088    return VINF_SUCCESS;
     4089}
     4090
     4091/**
     4092 * Unplugs a CPU from the guest.
     4093 *
     4094 * @returns VBox status code.
     4095 * @param   pVM     The VM to operate on.
     4096 * @param   idCpu   Virtual CPU to perform the unplug operation on.
     4097 */
     4098VMMR3DECL(int) VMR3HotunplugCPU(PVM pVM, VMCPUID idCpu)
     4099{
     4100    AssertReturn(idCpu < pVM->cCpus, VERR_INVALID_CPU_ID);
     4101
     4102    /** @todo Destroy EMT and not needed resources. */
     4103    return VMR3ReqCallNoWaitU(pVM->pUVM, idCpu, (PFNRT)vmR3HotunplugCPU, 2, pVM, idCpu);
     4104}
     4105
     4106/**
     4107 * Hotplugs a CPU on the guest.
     4108 *
     4109 * @returns VBox status code.
     4110 * @param   pVM     The VM to operate on.
     4111 * @param   idCpu   Virtual CPU to perform the hotplug operation on.
     4112 */
     4113VMMR3DECL(int) VMR3HotplugCPU(PVM pVM, VMCPUID idCpu)
     4114{
     4115    AssertReturn(idCpu < pVM->cCpus, VERR_INVALID_CPU_ID);
     4116
     4117    /** @todo start EMT and allocate needed resources. */
     4118    return VINF_SUCCESS;
     4119}
     4120
  • trunk/src/VBox/VMM/VMMAll/PGMAllPool.cpp

    r25577 r25816  
    47674767
    47684768#ifdef IN_RING3
     4769
     4770void pgmR3PoolResetCpu(PVM pVM, PVMCPU pVCpu)
     4771{
     4772    pgmR3ExitShadowModeBeforePoolFlush(pVM, pVCpu);
     4773
     4774    pgmR3ReEnterShadowModeAfterPoolFlush(pVM, pVCpu);
     4775    VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
     4776    VMCPU_FF_SET(pVCpu, VMCPU_FF_TLB_FLUSH);
     4777}
     4778
    47694779/**
    47704780 * Flushes the entire cache.
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