VirtualBox

Changeset 93650 in vbox for trunk/src/VBox/VMM/VMMAll


Ignore:
Timestamp:
Feb 8, 2022 10:43:53 AM (3 years ago)
Author:
vboxsync
Message:

VMM/PGM,*: Split the physical access handler type registration into separate ring-0 and ring-3 steps, expanding the type to 64-bit. bugref:10094

Location:
trunk/src/VBox/VMM/VMMAll
Files:
6 edited

Legend:

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

    r93635 r93650  
    68516851        if (!PGMHandlerPhysicalIsRegistered(pVCpu->CTX_SUFF(pVM), GCPhysApicAccess))
    68526852        {
    6853             PVMCC pVM       = pVCpu->CTX_SUFF(pVM);
    6854             PVMCPUCC pVCpu0 = VMCC_GET_CPU_0(pVM);
     6853            PVMCC pVM = pVCpu->CTX_SUFF(pVM);
    68556854            int rc = PGMHandlerPhysicalRegister(pVM, GCPhysApicAccess, GCPhysApicAccess + X86_PAGE_4K_SIZE - 1,
    6856                                                 pVCpu0->iem.s.hVmxApicAccessPage, 0 /*uUser*/, NULL /*pszDesc*/);
     6855                                                pVM->iem.s.hVmxApicAccessPage, 0 /*uUser*/, NULL /*pszDesc*/);
    68576856            if (RT_SUCCESS(rc))
    68586857            { /* likely */ }
  • trunk/src/VBox/VMM/VMMAll/IOMAllMmioNew.cpp

    r93635 r93650  
    728728 * @remarks The @a uUser argument is the MMIO handle.
    729729 */
    730 DECLEXPORT(VBOXSTRICTRC) iomMmioPfHandlerNew(PVMCC pVM, PVMCPUCC pVCpu, RTGCUINT uErrorCode, PCPUMCTXCORE pCtxCore,
    731                                              RTGCPTR pvFault, RTGCPHYS GCPhysFault, uint64_t uUser)
     730DECLCALLBACK(VBOXSTRICTRC) iomMmioPfHandlerNew(PVMCC pVM, PVMCPUCC pVCpu, RTGCUINT uErrorCode, PCPUMCTXCORE pCtxCore,
     731                                               RTGCPTR pvFault, RTGCPHYS GCPhysFault, uint64_t uUser)
    732732{
    733733    STAM_PROFILE_START(&pVM->iom.s.StatMmioPfHandler, Prf);
     
    797797 * @remarks The @a uUser argument is the MMIO handle.
    798798 */
    799 PGM_ALL_CB2_DECL(VBOXSTRICTRC) iomMmioHandlerNew(PVMCC pVM, PVMCPUCC pVCpu, RTGCPHYS GCPhysFault, void *pvPhys, void *pvBuf,
    800                                                  size_t cbBuf, PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, uint64_t uUser)
     799DECLCALLBACK(VBOXSTRICTRC) iomMmioHandlerNew(PVMCC pVM, PVMCPUCC pVCpu, RTGCPHYS GCPhysFault, void *pvPhys, void *pvBuf,
     800                                             size_t cbBuf, PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, uint64_t uUser)
    801801{
    802802    STAM_PROFILE_START(UnusedMacroArg, Prf);
  • trunk/src/VBox/VMM/VMMAll/MMAllHyper.cpp

    r93592 r93650  
    12601260
    12611261/**
    1262  * Converts a context neutral heap offset into a pointer.
    1263  *
    1264  * @returns Pointer to hyper heap data.
    1265  * @param   pVM         The cross context VM structure.
    1266  * @param   offHeap     The hyper heap offset.
    1267  */
    1268 VMMDECL(void *) MMHyperHeapOffsetToPtr(PVM pVM, uint32_t offHeap)
    1269 {
    1270     Assert(offHeap - MMYPERHEAP_HDR_SIZE <= pVM->mm.s.CTX_SUFF(pHyperHeap)->cbHeap);
    1271     return (uint8_t *)pVM->mm.s.CTX_SUFF(pHyperHeap) + offHeap;
    1272 }
    1273 
    1274 
    1275 /**
    1276  * Converts a context specific heap pointer into a neutral heap offset.
    1277  *
    1278  * @returns Heap offset.
    1279  * @param   pVM         The cross context VM structure.
    1280  * @param   pv          Pointer to the heap data.
    1281  */
    1282 VMMDECL(uint32_t) MMHyperHeapPtrToOffset(PVM pVM, void *pv)
    1283 {
    1284     size_t offHeap = (uint8_t *)pv - (uint8_t *)pVM->mm.s.CTX_SUFF(pHyperHeap);
    1285     Assert(offHeap - MMYPERHEAP_HDR_SIZE <= pVM->mm.s.CTX_SUFF(pHyperHeap)->cbHeap);
    1286     return (uint32_t)offHeap;
    1287 }
    1288 
    1289 
    1290 /**
    12911262 * Checks if an address is within the hypervisor memory area.
    12921263 *
  • trunk/src/VBox/VMM/VMMAll/PGMAllBth.h

    r93635 r93650  
    243243        if (pCur)
    244244        {
    245             PPGMPHYSHANDLERTYPEINT pCurType = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
     245            PCPGMPHYSHANDLERTYPEINT const pCurType = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
    246246
    247247#  ifdef PGM_SYNC_N_PAGES
     
    312312            }
    313313
    314             if (pCurType->CTX_SUFF(pfnPfHandler))
     314            if (pCurType->pfnPfHandler)
    315315            {
    316316                STAM_PROFILE_START(&pCur->Stat, h);
     
    318318                if (pCurType->fKeepPgmLock)
    319319                {
    320                     rcStrict = pCurType->CTX_SUFF(pfnPfHandler)(pVM, pVCpu, uErr, pRegFrame, pvFault, GCPhysFault,
    321                                                                 !pCurType->fRing0DevInsIdx ? pCur->uUser
    322                                                                 : (uintptr_t)PDMDeviceRing0IdxToInstance(pVM, pCur->uUser));
     320                    rcStrict = pCurType->pfnPfHandler(pVM, pVCpu, uErr, pRegFrame, pvFault, GCPhysFault,
     321                                                      !pCurType->fRing0DevInsIdx ? pCur->uUser
     322                                                      : (uintptr_t)PDMDeviceRing0IdxToInstance(pVM, pCur->uUser));
    323323
    324324#  ifdef VBOX_WITH_STATISTICS
     
    335335                    *pfLockTaken = false;
    336336
    337                     rcStrict = pCurType->CTX_SUFF(pfnPfHandler)(pVM, pVCpu, uErr, pRegFrame, pvFault, GCPhysFault, uUser);
     337                    rcStrict = pCurType->pfnPfHandler(pVM, pVCpu, uErr, pRegFrame, pvFault, GCPhysFault, uUser);
    338338
    339339#  ifdef VBOX_WITH_STATISTICS
  • trunk/src/VBox/VMM/VMMAll/PGMAllHandler.cpp

    r93635 r93650  
    4747
    4848/*********************************************************************************************************************************
     49*   Global Variables                                                                                                             *
     50*********************************************************************************************************************************/
     51/** Dummy physical access handler type record. */
     52CTX_SUFF(PGMPHYSHANDLERTYPEINT) const g_pgmHandlerPhysicalDummyType =
     53{
     54    /* .hType = */              UINT64_C(0x93b7557e1937aaff),
     55    /* .enmKind = */            PGMPHYSHANDLERKIND_INVALID,
     56    /* .uState = */             PGM_PAGE_HNDL_PHYS_STATE_ALL,
     57    /* .fKeepPgmLock = */       true,
     58    /* .fRing0DevInsIdx = */    false,
     59#ifdef IN_RING0
     60    /* .afPadding = */          {false},
     61    /* .pfnHandler = */         pgmR0HandlerPhysicalHandlerToRing3,
     62    /* .pfnPfHandler = */       pgmR0HandlerPhysicalPfHandlerToRing3,
     63#elif defined(IN_RING3)
     64    /* .fRing0Enabled = */      false,
     65    /* .pfnHandler = */         pgmR3HandlerPhysicalHandlerInvalid,
     66#else
     67# error "unsupported context"
     68#endif
     69    /* .pszDesc = */            "dummy"
     70};
     71
     72
     73/*********************************************************************************************************************************
    4974*   Internal Functions                                                                                                           *
    5075*********************************************************************************************************************************/
     
    5580
    5681
    57 /**
    58  * Internal worker for releasing a physical handler type registration reference.
    59  *
    60  * @returns New reference count. UINT32_MAX if invalid input (asserted).
    61  * @param   pVM         The cross context VM structure.
    62  * @param   pType       Pointer to the type registration.
    63  */
    64 DECLINLINE(uint32_t) pgmHandlerPhysicalTypeRelease(PVMCC pVM, PPGMPHYSHANDLERTYPEINT pType)
    65 {
    66     AssertMsgReturn(pType->u32Magic == PGMPHYSHANDLERTYPEINT_MAGIC, ("%#x\n", pType->u32Magic), UINT32_MAX);
    67     uint32_t cRefs = ASMAtomicDecU32(&pType->cRefs);
    68     if (cRefs == 0)
    69     {
    70         PGM_LOCK_VOID(pVM);
    71         pType->u32Magic = PGMPHYSHANDLERTYPEINT_MAGIC_DEAD;
    72         RTListOff32NodeRemove(&pType->ListNode);
    73         PGM_UNLOCK(pVM);
    74         MMHyperFree(pVM, pType);
    75     }
    76     return cRefs;
    77 }
    78 
    79 
    80 /**
    81  * Internal worker for retaining a physical handler type registration reference.
    82  *
    83  * @returns New reference count. UINT32_MAX if invalid input (asserted).
    84  * @param   pVM         The cross context VM structure.
    85  * @param   pType       Pointer to the type registration.
    86  */
    87 DECLINLINE(uint32_t) pgmHandlerPhysicalTypeRetain(PVM pVM, PPGMPHYSHANDLERTYPEINT pType)
    88 {
    89     NOREF(pVM);
    90     AssertMsgReturn(pType->u32Magic == PGMPHYSHANDLERTYPEINT_MAGIC, ("%#x\n", pType->u32Magic), UINT32_MAX);
    91     uint32_t cRefs = ASMAtomicIncU32(&pType->cRefs);
    92     Assert(cRefs < _1M && cRefs > 0);
    93     return cRefs;
    94 }
    95 
    96 
    97 /**
    98  * Releases a reference to a physical handler type registration.
    99  *
    100  * @returns New reference count. UINT32_MAX if invalid input (asserted).
    101  * @param   pVM         The cross context VM structure.
    102  * @param   hType       The type regiration handle.
    103  */
    104 VMMDECL(uint32_t) PGMHandlerPhysicalTypeRelease(PVMCC pVM, PGMPHYSHANDLERTYPE hType)
    105 {
    106     if (hType != NIL_PGMPHYSHANDLERTYPE)
    107         return pgmHandlerPhysicalTypeRelease(pVM, PGMPHYSHANDLERTYPEINT_FROM_HANDLE(pVM, hType));
    108     return 0;
    109 }
    110 
    111 
    112 /**
    113  * Retains a reference to a physical handler type registration.
    114  *
    115  * @returns New reference count. UINT32_MAX if invalid input (asserted).
    116  * @param   pVM         The cross context VM structure.
    117  * @param   hType       The type regiration handle.
    118  */
    119 VMMDECL(uint32_t) PGMHandlerPhysicalTypeRetain(PVM pVM, PGMPHYSHANDLERTYPE hType)
    120 {
    121     return pgmHandlerPhysicalTypeRetain(pVM, PGMPHYSHANDLERTYPEINT_FROM_HANDLE(pVM, hType));
    122 }
     82#ifndef IN_RING3
     83
     84/**
     85 * @callback_method_impl{FNPGMPHYSHANDLER,
     86 *      Dummy for forcing ring-3 handling of the access.}
     87 */
     88DECLCALLBACK(VBOXSTRICTRC)
     89pgmR0HandlerPhysicalHandlerToRing3(PVMCC pVM, PVMCPUCC pVCpu, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf,
     90                                   PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, uint64_t uUser)
     91{
     92    RT_NOREF(pVM, pVCpu, GCPhys, pvPhys, pvBuf, cbBuf, enmAccessType, enmOrigin, uUser);
     93    return VINF_EM_RAW_EMULATE_INSTR;
     94}
     95
     96
     97/**
     98 * @callback_method_impl{FNPGMRZPHYSPFHANDLER,
     99 *      Dummy for forcing ring-3 handling of the access.}
     100 */
     101DECLCALLBACK(VBOXSTRICTRC)
     102pgmR0HandlerPhysicalPfHandlerToRing3(PVMCC pVM, PVMCPUCC pVCpu, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame,
     103                                     RTGCPTR pvFault, RTGCPHYS GCPhysFault, uint64_t uUser)
     104{
     105    RT_NOREF(pVM, pVCpu, uErrorCode, pRegFrame, pvFault, GCPhysFault, uUser);
     106    return VINF_EM_RAW_EMULATE_INSTR;
     107}
     108
     109#endif /* !IN_RING3 */
    123110
    124111
     
    145132                               R3PTRTYPE(const char *) pszDesc, PPGMPHYSHANDLER *ppPhysHandler)
    146133{
    147     PPGMPHYSHANDLERTYPEINT pType = PGMPHYSHANDLERTYPEINT_FROM_HANDLE(pVM, hType);
     134    /*
     135     * Validate input.
     136     */
     137    PCPGMPHYSHANDLERTYPEINT const pType = pgmHandlerPhysicalTypeHandleToPtr(pVM, hType);
     138    AssertReturn(pType, VERR_INVALID_HANDLE);
     139    AssertReturn(pType->enmKind > PGMPHYSHANDLERKIND_INVALID && pType->enmKind < PGMPHYSHANDLERKIND_END, VERR_INVALID_HANDLE);
     140    AssertPtr(ppPhysHandler);
     141
    148142    Log(("pgmHandlerPhysicalExCreate: uUser=%#RX64 hType=%#x (%d, %s) pszDesc=%RHv:%s\n",
    149          uUser, hType, pType->enmKind, R3STRING(pType->pszDesc), pszDesc, R3STRING(pszDesc)));
    150 
    151     /*
    152      * Validate input.
    153      */
    154     AssertPtr(ppPhysHandler);
    155     AssertReturn(pType->u32Magic == PGMPHYSHANDLERTYPEINT_MAGIC, VERR_INVALID_HANDLE);
     143         uUser, hType, pType->enmKind, pType->pszDesc, pszDesc, R3STRING(pszDesc)));
    156144
    157145    /*
     
    169157        pNew->uUser         = uUser;
    170158        pNew->hType         = hType;
    171         pNew->pszDesc       = pszDesc != NIL_RTR3PTR ? pszDesc : pType->pszDesc;
    172         pgmHandlerPhysicalTypeRetain(pVM, pType);
     159        pNew->pszDesc       = pszDesc != NIL_RTR3PTR ? pszDesc
     160#ifdef IN_RING3
     161                            : pType->pszDesc;
     162#else
     163                            : pVM->pgm.s.aPhysHandlerTypes[hType].pszDesc;
     164#endif
    173165        *ppPhysHandler = pNew;
    174166        return VINF_SUCCESS;
     
    213205     * Validate input.
    214206     */
     207    PGMPHYSHANDLERTYPE const      hType = pPhysHandler->hType;
     208    PCPGMPHYSHANDLERTYPEINT const pType = pgmHandlerPhysicalTypeHandleToPtr(pVM, hType);
     209    AssertReturn(pType, VERR_INVALID_HANDLE);
     210    AssertReturn(pType->enmKind > PGMPHYSHANDLERKIND_INVALID && pType->enmKind < PGMPHYSHANDLERKIND_END, VERR_INVALID_HANDLE);
     211
    215212    AssertPtr(pPhysHandler);
    216     PPGMPHYSHANDLERTYPEINT pType = PGMPHYSHANDLERTYPEINT_FROM_HANDLE(pVM, pPhysHandler->hType);
    217     Assert(pType->u32Magic == PGMPHYSHANDLERTYPEINT_MAGIC);
    218     Log(("pgmHandlerPhysicalExRegister: GCPhys=%RGp GCPhysLast=%RGp hType=%#x (%d, %s) pszDesc=%RHv:%s\n",
    219          GCPhys, GCPhysLast, pPhysHandler->hType, pType->enmKind, R3STRING(pType->pszDesc), pPhysHandler->pszDesc, R3STRING(pPhysHandler->pszDesc)));
     213
     214    Log(("pgmHandlerPhysicalExRegister: GCPhys=%RGp GCPhysLast=%RGp hType=%#x (%d, %s) pszDesc=%RHv:%s\n", GCPhys, GCPhysLast,
     215         hType, pType->enmKind, pType->pszDesc, pPhysHandler->pszDesc, R3STRING(pPhysHandler->pszDesc)));
    220216    AssertReturn(pPhysHandler->Core.Key == NIL_RTGCPHYS, VERR_WRONG_ORDER);
    221217
     
    313309{
    314310#ifdef LOG_ENABLED
    315     PPGMPHYSHANDLERTYPEINT pType = PGMPHYSHANDLERTYPEINT_FROM_HANDLE(pVM, hType);
     311    PCPGMPHYSHANDLERTYPEINT pType = pgmHandlerPhysicalTypeHandleToPtr(pVM, hType);
    316312    Log(("PGMHandlerPhysicalRegister: GCPhys=%RGp GCPhysLast=%RGp uUser=%#RX64 hType=%#x (%d, %s) pszDesc=%RHv:%s\n",
    317313         GCPhys, GCPhysLast, uUser, hType, pType->enmKind, R3STRING(pType->pszDesc), pszDesc, R3STRING(pszDesc)));
     
    353349    bool                    fFlushTLBs = false;
    354350    int                     rc         = VINF_SUCCESS;
    355     PPGMPHYSHANDLERTYPEINT  pCurType   = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
     351    PCPGMPHYSHANDLERTYPEINT pCurType   = PGMPHYSHANDLER_GET_TYPE_NO_NULL(pVM, pCur);
    356352    const unsigned          uState     = pCurType->uState;
    357353    uint32_t                cPages     = pCur->cPages;
     
    483479        AssertPtr(pHandler);
    484480        AssertReturn(pHandler->Core.Key == NIL_RTGCPHYS, VERR_WRONG_ORDER);
    485         PGMHandlerPhysicalTypeRelease(pVM, pHandler->hType);
    486481        MMHyperFree(pVM, pHandler);
    487482    }
     
    539534{
    540535#ifdef VBOX_WITH_NATIVE_NEM
    541     PPGMPHYSHANDLERTYPEINT  pCurType    = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
     536    PCPGMPHYSHANDLERTYPEINT pCurType    = PGMPHYSHANDLER_GET_TYPE_NO_NULL(pVM, pCur);
    542537    RTGCPHYS                GCPhysStart = pCur->Core.Key;
    543538    RTGCPHYS                GCPhysLast  = pCur->Core.KeyLast;
     
    623618            || ((fAbove ? pCur->Core.Key : pCur->Core.KeyLast) >> GUEST_PAGE_SHIFT) != (GCPhys >> GUEST_PAGE_SHIFT))
    624619            break;
    625         PPGMPHYSHANDLERTYPEINT pCurType = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
     620        PCPGMPHYSHANDLERTYPEINT pCurType = PGMPHYSHANDLER_GET_TYPE_NO_NULL(pVM, pCur);
    626621        uState = RT_MAX(uState, pCurType->uState);
    627622
     
    636631
    637632    /*
    638      * Update if we found something that is a higher priority
    639      * state than the current.
     633     * Update if we found something that is a higher priority state than the current.
    640634     */
    641635    if (uState != PGM_PAGE_HNDL_PHYS_STATE_NONE)
     
    786780            }
    787781#ifdef VBOX_STRICT
    788             PPGMPHYSHANDLERTYPEINT pCurType = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
    789             AssertMsg(pCurType->enmKind != PGMPHYSHANDLERKIND_MMIO || PGM_PAGE_IS_MMIO(pPage), ("%RGp %R[pgmpage]\n", GCPhys, pPage));
     782            PCPGMPHYSHANDLERTYPEINT const pCurType = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
     783            AssertMsg(pCurType && (pCurType->enmKind != PGMPHYSHANDLERKIND_MMIO || PGM_PAGE_IS_MMIO(pPage)),
     784                      ("%RGp %R[pgmpage]\n", GCPhys, pPage));
    790785#endif
    791786            PGM_PAGE_SET_HNDL_PHYS_STATE(pPage, PGM_PAGE_HNDL_PHYS_STATE_NONE);
     
    855850         */
    856851        pgmHandlerPhysicalResetRamFlags(pVM, pCur);
    857         PPGMPHYSHANDLERTYPEINT const pCurType      = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
     852        PCPGMPHYSHANDLERTYPEINT const pCurType     = PGMPHYSHANDLER_GET_TYPE_NO_NULL(pVM, pCur);
     853        @todo pCurType validation
    858854        bool const                   fRestoreAsRAM = pCurType->pfnHandlerR3 /** @todo this isn't entirely correct. */
    859855                                                  && pCurType->enmKind != PGMPHYSHANDLERKIND_MMIO;
     
    11411137         * Validate kind.
    11421138         */
    1143         PPGMPHYSHANDLERTYPEINT pCurType = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
     1139        PCPGMPHYSHANDLERTYPEINT pCurType = PGMPHYSHANDLER_GET_TYPE_NO_NULL(pVM, pCur);
    11441140        switch (pCurType->enmKind)
    11451141        {
     
    12051201             */
    12061202            default:
    1207                 AssertMsgFailed(("Invalid type %d! Corruption!\n",  pCurType->enmKind));
     1203                AssertMsgFailed(("Invalid type %d/%#x! Corruption!\n",  pCurType->enmKind, pCur->hType));
    12081204                rc = VERR_PGM_PHYS_HANDLER_IPE;
    12091205                break;
     
    12491245         * Validate kind.
    12501246         */
    1251         PPGMPHYSHANDLERTYPEINT pCurType = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
    1252         if (pCurType->enmKind == PGMPHYSHANDLERKIND_WRITE)
     1247        PCPGMPHYSHANDLERTYPEINT pCurType = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
     1248        if (   pCurType
     1249            && pCurType->enmKind == PGMPHYSHANDLERKIND_WRITE)
    12531250        {
    12541251            STAM_COUNTER_INC(&pVM->pgm.s.Stats.CTX_MID_Z(Stat,PhysHandlerReset));
     
    13161313    if (RT_LIKELY(pCur))
    13171314    {
    1318         if (RT_LIKELY(    GCPhysPage >= pCur->Core.Key
    1319                       &&  GCPhysPage <= pCur->Core.KeyLast))
     1315        if (RT_LIKELY(   GCPhysPage >= pCur->Core.Key
     1316                      && GCPhysPage <= pCur->Core.KeyLast))
    13201317        {
    13211318            Assert(!(pCur->Core.Key & GUEST_PAGE_OFFSET_MASK));
    13221319            Assert((pCur->Core.KeyLast & GUEST_PAGE_OFFSET_MASK) == GUEST_PAGE_OFFSET_MASK);
    13231320
    1324             PPGMPHYSHANDLERTYPEINT pCurType = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
    1325             AssertReturnStmt(   pCurType->enmKind == PGMPHYSHANDLERKIND_WRITE
    1326                              || pCurType->enmKind == PGMPHYSHANDLERKIND_ALL,
     1321            PCPGMPHYSHANDLERTYPEINT const pCurType = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
     1322            AssertReturnStmt(   pCurType
     1323                             && (   pCurType->enmKind == PGMPHYSHANDLERKIND_WRITE
     1324                                 || pCurType->enmKind == PGMPHYSHANDLERKIND_ALL),
    13271325                             PGM_UNLOCK(pVM), VERR_ACCESS_DENIED);
    13281326
     
    14881486                      && GCPhysPage <= pCur->Core.KeyLast))
    14891487        {
    1490             PPGMPHYSHANDLERTYPEINT pCurType = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
     1488            PCPGMPHYSHANDLERTYPEINT const pCurType = PGMPHYSHANDLER_GET_TYPE_NO_NULL(pVM, pCur);
    14911489            AssertReturnStmt(pCurType->enmKind == PGMPHYSHANDLERKIND_MMIO, PGM_UNLOCK(pVM), VERR_ACCESS_DENIED);
    14921490            AssertReturnStmt(!(pCur->Core.Key & GUEST_PAGE_OFFSET_MASK), PGM_UNLOCK(pVM), VERR_INVALID_PARAMETER);
     
    16171615                      &&  GCPhysPage <= pCur->Core.KeyLast))
    16181616        {
    1619             PPGMPHYSHANDLERTYPEINT pCurType = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
     1617            PCPGMPHYSHANDLERTYPEINT const pCurType = PGMPHYSHANDLER_GET_TYPE_NO_NULL(pVM, pCur);
    16201618            AssertReturnStmt(pCurType->enmKind == PGMPHYSHANDLERKIND_MMIO, PGM_UNLOCK(pVM), VERR_ACCESS_DENIED);
    16211619            AssertReturnStmt(!(pCur->Core.Key & GUEST_PAGE_OFFSET_MASK), PGM_UNLOCK(pVM), VERR_INVALID_PARAMETER);
     
    17061704#ifdef VBOX_STRICT
    17071705        Assert(GCPhys >= pCur->Core.Key && GCPhys <= pCur->Core.KeyLast);
    1708         PPGMPHYSHANDLERTYPEINT pCurType = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
     1706        PCPGMPHYSHANDLERTYPEINT const pCurType = PGMPHYSHANDLER_GET_TYPE_NO_NULL(pVM, pCur);
    17091707        Assert(   pCurType->enmKind == PGMPHYSHANDLERKIND_WRITE
    17101708               || pCurType->enmKind == PGMPHYSHANDLERKIND_ALL
     
    17401738        return true;
    17411739    }
    1742     PPGMPHYSHANDLERTYPEINT pCurType = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
     1740
     1741    /* Only whole pages can be disabled. */
     1742    Assert(   pCur->Core.Key     <= (GCPhys & ~(RTGCPHYS)GUEST_PAGE_OFFSET_MASK)
     1743           && pCur->Core.KeyLast >= (GCPhys | GUEST_PAGE_OFFSET_MASK));
     1744
     1745    PCPGMPHYSHANDLERTYPEINT const pCurType = PGMPHYSHANDLER_GET_TYPE_NO_NULL(pVM, pCur);
    17431746    Assert(   pCurType->enmKind == PGMPHYSHANDLERKIND_WRITE
    17441747           || pCurType->enmKind == PGMPHYSHANDLERKIND_ALL
    17451748           || pCurType->enmKind == PGMPHYSHANDLERKIND_MMIO); /* sanity */
    1746     /* Only whole pages can be disabled. */
    1747     Assert(   pCur->Core.Key     <= (GCPhys & ~(RTGCPHYS)GUEST_PAGE_OFFSET_MASK)
    1748            && pCur->Core.KeyLast >= (GCPhys | GUEST_PAGE_OFFSET_MASK));
    1749 
    1750     bool bRet = pCurType->enmKind != PGMPHYSHANDLERKIND_WRITE;
     1749    bool const fRet = pCurType->enmKind != PGMPHYSHANDLERKIND_WRITE;
    17511750    PGM_UNLOCK(pVM);
    1752     return bRet;
     1751    return fRet;
    17531752}
    17541753
     
    18181817                    if (pPhys)
    18191818                    {
    1820                         PPGMPHYSHANDLERTYPEINT pPhysType = (PPGMPHYSHANDLERTYPEINT)MMHyperHeapOffsetToPtr(pVM, pPhys->hType);
     1819                        PCPGMPHYSHANDLERTYPEINT pPhysType = pgmHandlerPhysicalTypeHandleToPtr(pVM, pPhys->hType);
    18211820                        unsigned uState = pPhysType->uState;
    18221821
     
    18291828                                ||  pPhys2->Core.Key > (State.GCPhys | GUEST_PAGE_OFFSET_MASK))
    18301829                                break;
    1831                             PPGMPHYSHANDLERTYPEINT pPhysType2 = (PPGMPHYSHANDLERTYPEINT)MMHyperHeapOffsetToPtr(pVM, pPhys2->hType);
     1830                            PCPGMPHYSHANDLERTYPEINT pPhysType2 = pgmHandlerPhysicalTypeHandleToPtr(pVM, pPhys2->hType);
    18321831                            uState = RT_MAX(uState, pPhysType2->uState);
    18331832                            pPhys = pPhys2;
  • trunk/src/VBox/VMM/VMMAll/PGMAllPhys.cpp

    r93635 r93650  
    114114
    115115
    116 #ifndef IN_RING3
    117 
    118 /**
    119  * @callback_method_impl{FNPGMPHYSHANDLER,
    120  *      Dummy for forcing ring-3 handling of the access.}
    121  */
    122 DECLEXPORT(VBOXSTRICTRC)
    123 pgmPhysHandlerRedirectToHC(PVMCC pVM, PVMCPUCC pVCpu, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf,
    124                            PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, uint64_t uUser)
    125 {
    126     RT_NOREF(pVM, pVCpu, GCPhys, pvPhys, pvBuf, cbBuf, enmAccessType, enmOrigin, uUser);
    127     return VINF_EM_RAW_EMULATE_INSTR;
    128 }
    129 
    130 
    131 /**
    132  * @callback_method_impl{FNPGMRZPHYSPFHANDLER,
    133  *      Dummy for forcing ring-3 handling of the access.}
    134  */
    135 VMMDECL(VBOXSTRICTRC) pgmPhysPfHandlerRedirectToHC(PVMCC pVM, PVMCPUCC pVCpu, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame,
    136                                                    RTGCPTR pvFault, RTGCPHYS GCPhysFault, uint64_t uUser)
    137 {
    138     RT_NOREF(pVM, pVCpu, uErrorCode, pRegFrame, pvFault, GCPhysFault, uUser);
    139     return VINF_EM_RAW_EMULATE_INSTR;
    140 }
    141 
    142 #endif /* !IN_RING3 */
    143 
    144116/**
    145117 * Looks up a ROM range by its PGMROMRANGE::GCPhys value.
     
    161133 * @remarks The @a uUser argument is the PGMROMRANGE::GCPhys value.
    162134 */
    163 DECLEXPORT(VBOXSTRICTRC) pgmPhysRomWritePfHandler(PVMCC pVM, PVMCPUCC pVCpu, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame,
    164                                                   RTGCPTR pvFault, RTGCPHYS GCPhysFault, uint64_t uUser)
     135DECLCALLBACK(VBOXSTRICTRC) pgmPhysRomWritePfHandler(PVMCC pVM, PVMCPUCC pVCpu, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame,
     136                                                    RTGCPTR pvFault, RTGCPHYS GCPhysFault, uint64_t uUser)
    165137
    166138{
     
    233205 * @remarks The @a uUser argument is the PGMROMRANGE::GCPhys value.
    234206 */
    235 PGM_ALL_CB2_DECL(VBOXSTRICTRC)
     207DECLCALLBACK(VBOXSTRICTRC)
    236208pgmPhysRomWriteHandler(PVMCC pVM, PVMCPUCC pVCpu, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf,
    237209                       PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, uint64_t uUser)
     
    396368 * @remarks The @a uUser is the MMIO2 index.
    397369 */
    398 DECLEXPORT(VBOXSTRICTRC) pgmPhysMmio2WritePfHandler(PVMCC pVM, PVMCPUCC pVCpu, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame,
    399                                                     RTGCPTR pvFault, RTGCPHYS GCPhysFault, uint64_t uUser)
     370DECLCALLBACK(VBOXSTRICTRC) pgmPhysMmio2WritePfHandler(PVMCC pVM, PVMCPUCC pVCpu, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame,
     371                                                      RTGCPTR pvFault, RTGCPHYS GCPhysFault, uint64_t uUser)
    400372{
    401373    RT_NOREF(pVCpu, uErrorCode, pRegFrame);
     
    417389 * @remarks The @a uUser is the MMIO2 index.
    418390 */
    419 PGM_ALL_CB2_DECL(VBOXSTRICTRC)
     391DECLCALLBACK(VBOXSTRICTRC)
    420392pgmPhysMmio2WriteHandler(PVMCC pVM, PVMCPUCC pVCpu, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf,
    421393                         PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, uint64_t uUser)
     
    24362408    {
    24372409        PPGMPHYSHANDLER pCur = pgmHandlerPhysicalLookup(pVM, GCPhys);
    2438         AssertReleaseMsg(pCur, ("GCPhys=%RGp cb=%#x\n", GCPhys, cb));
    2439         Assert(GCPhys >= pCur->Core.Key && GCPhys <= pCur->Core.KeyLast);
    2440         Assert((pCur->Core.Key     & GUEST_PAGE_OFFSET_MASK) == 0);
    2441         Assert((pCur->Core.KeyLast & GUEST_PAGE_OFFSET_MASK) == GUEST_PAGE_OFFSET_MASK);
     2410        if (pCur)
     2411        {
     2412            Assert(pCur && GCPhys >= pCur->Core.Key && GCPhys <= pCur->Core.KeyLast);
     2413            Assert((pCur->Core.Key     & GUEST_PAGE_OFFSET_MASK) == 0);
     2414            Assert((pCur->Core.KeyLast & GUEST_PAGE_OFFSET_MASK) == GUEST_PAGE_OFFSET_MASK);
    24422415#ifndef IN_RING3
    2443         if (enmOrigin != PGMACCESSORIGIN_IEM)
    2444         {
    2445             /* Cannot reliably handle informational status codes in this context */
    2446             pgmPhysReleaseInternalPageMappingLock(pVM, &PgMpLck);
    2447             return VERR_PGM_PHYS_WR_HIT_HANDLER;
    2448         }
     2416            if (enmOrigin != PGMACCESSORIGIN_IEM)
     2417            {
     2418                /* Cannot reliably handle informational status codes in this context */
     2419                pgmPhysReleaseInternalPageMappingLock(pVM, &PgMpLck);
     2420                return VERR_PGM_PHYS_WR_HIT_HANDLER;
     2421            }
    24492422#endif
    2450         PPGMPHYSHANDLERTYPEINT const pCurType   = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
    2451         PFNPGMPHYSHANDLER const      pfnHandler = pCurType->CTX_SUFF(pfnHandler); Assert(pfnHandler);
    2452         uint64_t const               uUser      = !pCurType->fRing0DevInsIdx ? pCur->uUser
    2453                                                 : (uintptr_t)PDMDeviceRing0IdxToInstance(pVM, pCur->uUser);
    2454 
    2455         Log5(("pgmPhysReadHandler: GCPhys=%RGp cb=%#x pPage=%R[pgmpage] phys %s\n", GCPhys, cb, pPage, R3STRING(pCur->pszDesc) ));
    2456         STAM_PROFILE_START(&pCur->Stat, h);
    2457         PGM_LOCK_ASSERT_OWNER(pVM);
    2458 
    2459         /* Release the PGM lock as MMIO handlers take the IOM lock. (deadlock prevention) */
    2460         PGM_UNLOCK(pVM);
    2461         rcStrict = pfnHandler(pVM, pVCpu, GCPhys, (void *)pvSrc, pvBuf, cb, PGMACCESSTYPE_READ, enmOrigin, uUser);
    2462         PGM_LOCK_VOID(pVM);
     2423            PCPGMPHYSHANDLERTYPEINT const pCurType   = PGMPHYSHANDLER_GET_TYPE_NO_NULL(pVM, pCur);
     2424            PFNPGMPHYSHANDLER const       pfnHandler = pCurType->pfnHandler; Assert(pfnHandler);
     2425            uint64_t const                uUser      = !pCurType->fRing0DevInsIdx ? pCur->uUser
     2426                                                     : (uintptr_t)PDMDeviceRing0IdxToInstance(pVM, pCur->uUser);
     2427
     2428            Log5(("pgmPhysReadHandler: GCPhys=%RGp cb=%#x pPage=%R[pgmpage] phys %s\n", GCPhys, cb, pPage, R3STRING(pCur->pszDesc) ));
     2429            STAM_PROFILE_START(&pCur->Stat, h);
     2430            PGM_LOCK_ASSERT_OWNER(pVM);
     2431
     2432            /* Release the PGM lock as MMIO handlers take the IOM lock. (deadlock prevention) */
     2433            PGM_UNLOCK(pVM);
     2434            rcStrict = pfnHandler(pVM, pVCpu, GCPhys, (void *)pvSrc, pvBuf, cb, PGMACCESSTYPE_READ, enmOrigin, uUser);
     2435            PGM_LOCK_VOID(pVM);
    24632436
    24642437#ifdef VBOX_WITH_STATISTICS
    2465         pCur = pgmHandlerPhysicalLookup(pVM, GCPhys);
    2466         if (pCur)
    2467             STAM_PROFILE_STOP(&pCur->Stat, h);
     2438            pCur = pgmHandlerPhysicalLookup(pVM, GCPhys);
     2439            if (pCur)
     2440                STAM_PROFILE_STOP(&pCur->Stat, h);
    24682441#else
    2469         pCur = NULL; /* might not be valid anymore. */
     2442            pCur = NULL; /* might not be valid anymore. */
    24702443#endif
    2471         AssertLogRelMsg(PGM_HANDLER_PHYS_IS_VALID_STATUS(rcStrict, false),
    2472                         ("rcStrict=%Rrc GCPhys=%RGp\n", VBOXSTRICTRC_VAL(rcStrict), GCPhys));
    2473         if (   rcStrict != VINF_PGM_HANDLER_DO_DEFAULT
    2474             && !PGM_PHYS_RW_IS_SUCCESS(rcStrict))
    2475         {
    2476             pgmPhysReleaseInternalPageMappingLock(pVM, &PgMpLck);
    2477             return rcStrict;
    2478         }
     2444            AssertLogRelMsg(PGM_HANDLER_PHYS_IS_VALID_STATUS(rcStrict, false),
     2445                            ("rcStrict=%Rrc GCPhys=%RGp\n", VBOXSTRICTRC_VAL(rcStrict), GCPhys));
     2446            if (   rcStrict != VINF_PGM_HANDLER_DO_DEFAULT
     2447                && !PGM_PHYS_RW_IS_SUCCESS(rcStrict))
     2448            {
     2449                pgmPhysReleaseInternalPageMappingLock(pVM, &PgMpLck);
     2450                return rcStrict;
     2451            }
     2452        }
     2453        else
     2454            AssertLogRelMsgFailed(("GCPhys=%RGp cb=%#x\n", GCPhys, cb));
    24792455    }
    24802456
     
    26652641     * Give priority to physical handlers (like #PF does).
    26662642     *
    2667      * Hope for a lonely physical handler first that covers the whole
    2668      * write area. This should be a pretty frequent case with MMIO and
    2669      * the heavy usage of full page handlers in the page pool.
     2643     * Hope for a lonely physical handler first that covers the whole write
     2644     * area.  This should be a pretty frequent case with MMIO and the heavy
     2645     * usage of full page handlers in the page pool.
    26702646     */
    26712647    PVMCPUCC pVCpu = VMMGetCpu(pVM);
     
    26832659            cbRange = cbWrite;
    26842660
    2685         Assert(PGMPHYSHANDLER_GET_TYPE(pVM, pCur)->CTX_SUFF(pfnHandler));
     2661        Assert(PGMPHYSHANDLER_GET_TYPE(pVM, pCur)->pfnHandler);
    26862662        Log5(("pgmPhysWriteHandler: GCPhys=%RGp cbRange=%#x pPage=%R[pgmpage] phys %s\n",
    26872663              GCPhys, cbRange, pPage, R3STRING(pCur->pszDesc) ));
     
    26922668        if (RT_SUCCESS(rcStrict))
    26932669        {
    2694             PPGMPHYSHANDLERTYPEINT const pCurType   = PGMPHYSHANDLER_GET_TYPE(pVM, pCur);
    2695             PFNPGMPHYSHANDLER const      pfnHandler = pCurType->CTX_SUFF(pfnHandler);
    2696             uint64_t const               uUser      = !pCurType->fRing0DevInsIdx ? pCur->uUser
    2697                                                     : (uintptr_t)PDMDeviceRing0IdxToInstance(pVM, pCur->uUser);
     2670            PCPGMPHYSHANDLERTYPEINT const pCurType   = PGMPHYSHANDLER_GET_TYPE_NO_NULL(pVM, pCur);
     2671            PFNPGMPHYSHANDLER const       pfnHandler = pCurType->pfnHandler;
     2672            uint64_t const                uUser      = !pCurType->fRing0DevInsIdx ? pCur->uUser
     2673                                                     : (uintptr_t)PDMDeviceRing0IdxToInstance(pVM, pCur->uUser);
    26982674            STAM_PROFILE_START(&pCur->Stat, h);
    26992675
     
    27472723    else /* The handler is somewhere else in the page, deal with it below. */
    27482724        rcStrict = VINF_SUCCESS;
    2749     Assert(!PGM_PAGE_IS_MMIO_OR_ALIAS(pPage)); /* MMIO handlers are all PAGE_SIZEed! */
     2725    Assert(!PGM_PAGE_IS_MMIO_OR_ALIAS(pPage)); /* MMIO handlers are all GUEST_PAGE_SIZEed! */
    27502726
    27512727    /*
     
    27632739    }
    27642740
     2741    /** @todo clean up this code some more now there are no virtual handlers any
     2742     *        more. */
    27652743    /* The loop state (big + ugly). */
    27662744    PPGMPHYSHANDLER pPhys       = NULL;
     
    28042782        VBOXSTRICTRC rcStrict2 = VINF_PGM_HANDLER_DO_DEFAULT;
    28052783        uint32_t cbRange = (uint32_t)cbWrite;
     2784        Assert(cbRange == cbWrite);
    28062785
    28072786        /*
     
    28182797                cbRange = offPhysLast + 1;
    28192798
    2820             PPGMPHYSHANDLERTYPEINT const pCurType   = PGMPHYSHANDLER_GET_TYPE(pVM, pPhys);
    2821             PFNPGMPHYSHANDLER const      pfnHandler = pCurType->CTX_SUFF(pfnHandler);
    2822             uint64_t const               uUser      = !pCurType->fRing0DevInsIdx ? pPhys->uUser
    2823                                                     : (uintptr_t)PDMDeviceRing0IdxToInstance(pVM, pPhys->uUser);
     2799            PCPGMPHYSHANDLERTYPEINT const pCurType   = PGMPHYSHANDLER_GET_TYPE_NO_NULL(pVM, pPhys);
     2800            PFNPGMPHYSHANDLER const       pfnHandler = pCurType->pfnHandler;
     2801            uint64_t const                uUser      = !pCurType->fRing0DevInsIdx ? pPhys->uUser
     2802                                                     : (uintptr_t)PDMDeviceRing0IdxToInstance(pVM, pPhys->uUser);
    28242803
    28252804            Log5(("pgmPhysWriteHandler: GCPhys=%RGp cbRange=%#x pPage=%R[pgmpage] phys %s\n", GCPhys, cbRange, pPage, R3STRING(pPhys->pszDesc) ));
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