VirtualBox

Changeset 44785 in vbox


Ignore:
Timestamp:
Feb 21, 2013 3:24:21 PM (12 years ago)
Author:
vboxsync
Message:

VMMDev.cpp: Delay critsect exit for HGCM requests to avoid race between EMT writing back and HGCM read+writing back the request.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/VMMDev/VMMDev.cpp

    r44782 r44785  
    21872187
    21882188
    2189 static int vmmdevReqDispatcher(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr, RTGCPHYS GCPhysReqHdr)
     2189/**
     2190 * Dispatch the request to the appropriate handler function.
     2191 *
     2192 * @returns Port I/O handler exit code.
     2193 * @param   pThis           The VMM device instance data.
     2194 * @param   pReqHdr         The request header (cached in host memory).
     2195 * @param   GCPhysReqHdr    The guest physical address of the request (for
     2196 *                          HGCM).
     2197 * @param   pfDelayedUnlock Where to indicate whether the critical section exit
     2198 *                          needs to be delayed till after the request has been
     2199 *                          written back. This is a HGCM kludge, see critsect
     2200 *                          work in hgcmCompletedWorker for more details.
     2201 */
     2202static int vmmdevReqDispatcher(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr, RTGCPHYS GCPhysReqHdr, bool *pfDelayedUnlock)
    21902203{
    21912204    int rcRet = VINF_SUCCESS;
     2205    *pfDelayedUnlock = false;
    21922206
    21932207    switch (pReqHdr->requestType)
     
    22922306        case VMMDevReq_HGCMConnect:
    22932307            pReqHdr->rc = vmmdevReqHandler_HGCMConnect(pThis, pReqHdr, GCPhysReqHdr);
     2308            *pfDelayedUnlock = true;
    22942309            break;
    22952310
    22962311        case VMMDevReq_HGCMDisconnect:
    22972312            pReqHdr->rc = vmmdevReqHandler_HGCMDisconnect(pThis, pReqHdr, GCPhysReqHdr);
     2313            *pfDelayedUnlock = true;
    22982314            break;
    22992315
     
    23052321# endif /* VBOX_WITH_64_BITS_GUESTS */
    23062322            pReqHdr->rc = vmmdevReqHandler_HGCMCall(pThis, pReqHdr, GCPhysReqHdr);
     2323            *pfDelayedUnlock = true;
    23072324            break;
    23082325#endif /* VBOX_WITH_HGCM */
     
    23102327        case VMMDevReq_HGCMCancel:
    23112328            pReqHdr->rc = vmmdevReqHandler_HGCMCancel(pThis, pReqHdr, GCPhysReqHdr);
     2329            *pfDelayedUnlock = true;
    23122330            break;
    23132331
     
    24602478    Log2(("VMMDev request issued: %d\n", requestHeader.requestType));
    24612479
     2480    bool                 fDelayedUnlock = false;
    24622481    int                  rcRet          = VINF_SUCCESS;
    24632482    VMMDevRequestHeader *pRequestHeader = NULL;
     
    24832502                PDMDevHlpPhysRead(pDevIns, (RTGCPHYS)u32, pRequestHeader, requestHeader.size);
    24842503
    2485                 rcRet = vmmdevReqDispatcher(pThis, pRequestHeader, u32);
     2504                rcRet = vmmdevReqDispatcher(pThis, pRequestHeader, u32, &fDelayedUnlock);
    24862505            }
    24872506            else
     
    25032522        }
    25042523
    2505         PDMCritSectLeave(&pThis->CritSect);
     2524        if (!fDelayedUnlock)
     2525            PDMCritSectLeave(&pThis->CritSect);
    25062526    }
    25072527    else
     
    25222542    {
    25232543        PDMDevHlpPhysWrite(pDevIns, u32, pRequestHeader, pRequestHeader->size);
     2544        if (fDelayedUnlock)
     2545            PDMCritSectLeave(&pThis->CritSect);
    25242546        RTMemFree(pRequestHeader);
    25252547    }
     
    25282550        /* early error case; write back header only */
    25292551        PDMDevHlpPhysWrite(pDevIns, u32, &requestHeader, sizeof(requestHeader));
     2552        Assert(!fDelayedUnlock);
    25302553    }
    25312554
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