VirtualBox

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


Ignore:
Timestamp:
Apr 13, 2016 11:12:36 AM (9 years ago)
Author:
vboxsync
Message:

VMM/APIC: Added extra assertions for debugging.

File:
1 edited

Legend:

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

    r60464 r60468  
    912912            pXApicPage->timer_ccr.u32CurrentCount = uInitialCount;
    913913            if (uInitialCount)
     914            {
     915                Log4(("APIC%u: apicR3TimerCallback: Re-arming timer. uInitialCount=%#RX32\n", pVCpu->idCpu, uInitialCount));
    914916                APICStartTimer(pApicCpu, uInitialCount);
     917            }
    915918            break;
    916919        }
     
    10021005    LogFlow(("APIC: apicR3TermState: pVM=%p\n", pVM));
    10031006
    1004     if (pApic->pvApicPibR3)
     1007    /* Unmap and free the PIB. */
     1008    if (pApic->pvApicPibR3 != NIL_RTR3PTR)
    10051009    {
    10061010        size_t const cPages = pApic->cbApicPib >> PAGE_SHIFT;
     
    10091013        else
    10101014            SUPR3ContFree((void *)pApic->pvApicPibR3, cPages);
    1011         pApic->pvApicPibR3 = NULL;
    1012     }
    1013 
     1015        pApic->pvApicPibR3 = NIL_RTR3PTR;
     1016        pApic->pvApicPibR0 = NIL_RTR0PTR;
     1017        pApic->pvApicPibRC = NIL_RTRCPTR;
     1018    }
     1019
     1020    /* Unmap and free the virtual-APIC pages. */
    10141021    for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
    10151022    {
    1016         PVMCPU   pVCpu      = &pVM->aCpus[idCpu];
    1017         PAPICCPU pApicCpu   = VMCPU_TO_APICCPU(pVCpu);
    1018         if (pApicCpu->pvApicPageR3)
     1023        PVMCPU   pVCpu    = &pVM->aCpus[idCpu];
     1024        PAPICCPU pApicCpu = VMCPU_TO_APICCPU(pVCpu);
     1025
     1026        pApicCpu->pvApicPibR3 = NIL_RTR3PTR;
     1027        pApicCpu->pvApicPibR0 = NIL_RTR0PTR;
     1028        pApicCpu->pvApicPibRC = NIL_RTRCPTR;
     1029
     1030        if (pApicCpu->pvApicPageR3 != NIL_RTR3PTR)
    10191031        {
    10201032            SUPR3PageFreeEx((void *)pApicCpu->pvApicPageR3, 1 /* cPages */);
    1021             pApicCpu->pvApicPageR3 = NULL;
    1022             pApicCpu->pvApicPibR3  = NULL;
     1033            pApicCpu->pvApicPageR3 = NIL_RTR3PTR;
     1034            pApicCpu->pvApicPageR0 = NIL_RTR0PTR;
     1035            pApicCpu->pvApicPageRC = NIL_RTRCPTR;
    10231036        }
    10241037    }
     
    10351048{
    10361049    PAPIC pApic = VM_TO_APIC(pVM);
    1037     bool const fNeedGCMapping = !HMIsEnabled(pVM);
    10381050    LogFlow(("APIC: apicR3InitState: pVM=%p\n", pVM));
     1051
     1052    /* With hardware virtualization, we don't need to map the APIC in GC. */
     1053    bool const fNeedsGCMapping = !HMIsEnabled(pVM);
    10391054
    10401055    /*
     
    10441059     * physically contiguous allocations are rounded to a multiple of page size.
    10451060     */
     1061    Assert(pApic->pvApicPibR3 == NIL_RTR3PTR);
     1062    Assert(pApic->pvApicPibR0 == NIL_RTR0PTR);
     1063    Assert(pApic->pvApicPibRC == NIL_RTRCPTR);
    10461064    pApic->cbApicPib    = RT_ALIGN_Z(pVM->cCpus * sizeof(APICPIB), PAGE_SIZE);
    10471065    size_t const cPages = pApic->cbApicPib >> PAGE_SHIFT;
    1048     Assert(!pApic->pvApicPibR3);
    10491066    if (cPages == 1)
    10501067    {
     
    10521069        RT_ZERO(SupApicPib);
    10531070        SupApicPib.Phys = NIL_RTHCPHYS;
    1054         int rc = SUPR3PageAllocEx(cPages, 0 /* fFlags */, (void **)&pApic->pvApicPibR3, &pApic->pvApicPibR0, &SupApicPib);
     1071        int rc = SUPR3PageAllocEx(1 /* cPages */, 0 /* fFlags */, (void **)&pApic->pvApicPibR3, &pApic->pvApicPibR0, &SupApicPib);
    10551072        if (RT_SUCCESS(rc))
    10561073        {
    10571074            pApic->HCPhysApicPib = SupApicPib.Phys;
    1058             AssertReturn(pApic->pvApicPibR3, VERR_INVALID_POINTER);
    1059             memset((void *)pApic->pvApicPibR3, 0, pApic->cbApicPib);
     1075            AssertLogRelReturn(pApic->pvApicPibR3, VERR_INTERNAL_ERROR);
    10601076        }
    10611077        else
     
    10701086    if (pApic->pvApicPibR3)
    10711087    {
    1072         Assert(pApic->pvApicPibR0 != NIL_RTR0PTR);
    1073         Assert(pApic->HCPhysApicPib != NIL_RTHCPHYS);
    1074 
    1075         /* Map the pending-interrupt bitmap (PIB) into GC.  */
    1076         if (fNeedGCMapping)
     1088        AssertLogRelReturn(pApic->pvApicPibR0   != NIL_RTR0PTR,  VERR_INTERNAL_ERROR);
     1089        AssertLogRelReturn(pApic->HCPhysApicPib != NIL_RTHCPHYS, VERR_INTERNAL_ERROR);
     1090
     1091        /* Initialize the PIB. */
     1092        memset((void *)pApic->pvApicPibR3, 0, pApic->cbApicPib);
     1093
     1094        /* Map the PIB into GC.  */
     1095        if (fNeedsGCMapping)
    10771096        {
     1097            pApic->pvApicPibRC == NIL_RTRCPTR;
    10781098            int rc = MMR3HyperMapHCPhys(pVM, (void *)pApic->pvApicPibR3, NIL_RTR0PTR, pApic->HCPhysApicPib, pApic->cbApicPib,
    10791099                                        "APIC PIB", (PRTGCPTR)&pApic->pvApicPibRC);
    10801100            if (RT_FAILURE(rc))
    10811101            {
    1082                 LogRel(("APIC: Failed to map %u bytes for the pending-interrupt bitmap to GC, rc=%Rrc\n", pApic->cbApicPib, rc));
     1102                LogRel(("APIC: Failed to map %u bytes for the pending-interrupt bitmap into GC, rc=%Rrc\n", pApic->cbApicPib,
     1103                        rc));
    10831104                apicR3TermState(pVM);
    10841105                return rc;
    10851106            }
     1107
     1108            AssertLogRelReturn(pApic->pvApicPibRC != NIL_RTRCPTR, VERR_INTERNAL_ERROR);
    10861109        }
    10871110
     1111        /*
     1112         * Allocate the map the virtual-APIC pages.
     1113         */
    10881114        for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
    10891115        {
     
    10911117            PAPICCPU pApicCpu = VMCPU_TO_APICCPU(pVCpu);
    10921118
    1093             /* Allocate and map the virtual-APIC page. */
    10941119            SUPPAGE SupApicPage;
    10951120            RT_ZERO(SupApicPage);
    10961121            SupApicPage.Phys = NIL_RTHCPHYS;
    10971122
     1123            Assert(pApicCpu->pvApicPageR3 == NIL_RTR0PTR);
     1124            Assert(pApicCpu->pvApicPageR0 == NIL_RTR0PTR);
     1125            Assert(pApicCpu->pvApicPageRC == NIL_RTRCPTR);
     1126            AssertCompile(sizeof(XAPICPAGE) == PAGE_SIZE);
    10981127            pApicCpu->cbApicPage = sizeof(XAPICPAGE);
    1099             AssertCompile(sizeof(XAPICPAGE) == PAGE_SIZE);
    1100 
    1101             Assert(!pApicCpu->pvApicPageR3);
    11021128            int rc = SUPR3PageAllocEx(1 /* cPages */, 0 /* fFlags */, (void **)&pApicCpu->pvApicPageR3, &pApicCpu->pvApicPageR0,
    11031129                                      &SupApicPage);
    11041130            if (RT_SUCCESS(rc))
    11051131            {
     1132                AssertLogRelReturn(pApicCpu->pvApicPageR3   != NIL_RTR3PTR,  VERR_INTERNAL_ERROR);
     1133                AssertLogRelReturn(pApicCpu->HCPhysApicPage != NIL_RTHCPHYS, VERR_INTERNAL_ERROR);
    11061134                pApicCpu->HCPhysApicPage = SupApicPage.Phys;
    1107                 Assert(pApicCpu->HCPhysApicPage != NIL_RTHCPHYS);
    1108                 Assert(pApicCpu->pvApicPageR3);
    11091135
    11101136                /* Map the virtual-APIC page into GC. */
    1111                 if (fNeedGCMapping)
     1137                if (fNeedsGCMapping)
    11121138                {
    11131139                    rc = MMR3HyperMapHCPhys(pVM, (void *)pApicCpu->pvApicPageR3, NIL_RTR0PTR, pApicCpu->HCPhysApicPage,
     
    11151141                    if (RT_FAILURE(rc))
    11161142                    {
    1117                         LogRel(("APIC%u: Failed to map %u bytes for the virtual-APIC page to GC, rc=%Rrc", idCpu,
     1143                        LogRel(("APIC%u: Failed to map %u bytes for the virtual-APIC page into GC, rc=%Rrc", idCpu,
    11181144                                pApicCpu->cbApicPage, rc));
    11191145                        apicR3TermState(pVM);
    11201146                        return rc;
    11211147                    }
     1148
     1149                    AssertLogRelReturn(pApicCpu->pvApicPageRC != NIL_RTRCPTR, VERR_INTERNAL_ERROR);
    11221150                }
    11231151
     
    11261154                pApicCpu->pvApicPibR0      = (RTR0PTR)((RTR0UINTPTR)pApic->pvApicPibR0 + offApicPib);
    11271155                pApicCpu->pvApicPibR3      = (RTR3PTR)((RTR3UINTPTR)pApic->pvApicPibR3 + offApicPib);
    1128                 if (fNeedGCMapping)
     1156                if (fNeedsGCMapping)
    11291157                    pApicCpu->pvApicPibRC += offApicPib;
    11301158
     
    11331161                APICR3Reset(pVCpu);
    11341162
    1135 #ifdef VBOX_STRICT
    1136                 Assert(pApicCpu->pvApicPageR3);
    1137                 Assert(pApicCpu->pvApicPageR0);
    1138                 Assert(!fNeedGCMapping || pApicCpu->pvApicPageRC);
    1139                 Assert(pApicCpu->pvApicPibR3);
    1140                 Assert(pApicCpu->pvApicPibR0);
    1141                 Assert(!fNeedGCMapping || pApicCpu->pvApicPibRC);
     1163#ifdef DEBUG_ramshankar
     1164                Assert(pApicCpu->pvApicPibR3 != NIL_RTR3PTR);
     1165                Assert(pApicCpu->pvApicPibR0 != NIL_RTR0PTR);
     1166                Assert(!fNeedsGCMapping || pApicCpu->pvApicPibRC != NIL_RTRCPTR);
     1167                Assert(pApicCpu->pvApicPageR3 != NIL_RTR3PTR);
     1168                Assert(pApicCpu->pvApicPageR0 != NIL_RTR0PTR);
     1169                Assert(!fNeedsGCMapping || pApicCpu->pvApicPageRC != NIL_RTRCPTR);
    11421170#endif
    11431171            }
    11441172            else
    11451173            {
    1146                 LogRel(("APIC%u: Failed to allocate %u bytes for the virtual-APIC page\n", pApicCpu->cbApicPage));
     1174                LogRel(("APIC%u: Failed to allocate %u bytes for the virtual-APIC page, rc=%Rrc\n", pApicCpu->cbApicPage, rc));
    11471175                apicR3TermState(pVM);
    1148                 return VERR_NO_MEMORY;
     1176                return rc;
    11491177            }
    11501178        }
    11511179
    1152 #ifdef VBOX_STRICT
    1153         Assert(pApic->pvApicPibR0);
    1154         Assert(pApic->pvApicPibR3);
    1155         Assert(!fNeedGCMapping || pApic->pvApicPibRC);
     1180#ifdef DEBUG_ramshankar
     1181        Assert(pApic->pvApicPibR3 != NIL_RTR3PTR);
     1182        Assert(pApic->pvApicPibR0 != NIL_RTR0PTR);
     1183        Assert(!fNeedsGCMapping || pApic->pvApicPibRC != NIL_RTRCPTR);
    11561184#endif
    11571185        return VINF_SUCCESS;
    11581186    }
    11591187
    1160     LogRel(("APIC: Failed to allocate %u bytes of contiguous low-memory for the pending-interrupt bitmap\n", pApic->cbApicPib));
     1188    LogRel(("APIC: Failed to allocate %u bytes of physically contiguous memory for the pending-interrupt bitmap\n",
     1189            pApic->cbApicPib));
    11611190    return VERR_NO_MEMORY;
    11621191}
     
    11691198{
    11701199    PVM pVM = PDMDevHlpGetVM(pDevIns);
     1200    LogFlow(("APIC: apicR3Destruct: pVM=%p\n", pVM));
     1201
    11711202    apicR3TermState(pVM);
    11721203    return VINF_SUCCESS;
     
    11821213    PAPIC pApic = VM_TO_APIC(pVM);
    11831214
     1215    /*
     1216     * Init APIC settings that rely on HM and CPUM configurations.
     1217     */
    11841218    CPUMCPUIDLEAF CpuLeaf;
    11851219    int rc = CPUMR3CpuIdGetLeaf(pVM, &CpuLeaf, 1, 0);
    11861220    AssertRCReturn(rc, rc);
     1221
    11871222    pApic->fSupportsTscDeadline = RT_BOOL(CpuLeaf.uEcx & X86_CPUID_FEATURE_ECX_TSCDEADL);
    1188 
    11891223    pApic->fPostedIntrsEnabled  = HMR3IsPostedIntrsEnabled(pVM->pUVM);
    11901224    pApic->fVirtApicRegsEnabled = HMR3IsVirtApicRegsEnabled(pVM->pUVM);
     
    11991233    /** @todo Figure out why doing this from apicR3Construct() it doesn't work. See @bugref{8245#c48} */
    12001234#define APIC_REG_COUNTER(a_Reg, a_Desc, a_Key) \
    1201     rc = STAMR3RegisterF(pVM, a_Reg, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, a_Desc, a_Key, idCpu)
     1235    do { \
     1236        rc = STAMR3RegisterF(pVM, a_Reg, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, a_Desc, a_Key, idCpu); \
     1237        AssertRCReturn(rc, rc); \
     1238    } while(0)
    12021239
    12031240    bool const fHasRC = !HMIsEnabled(pVM);
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