VirtualBox

Changeset 80928 in vbox for trunk/src/VBox/Devices/VirtIO


Ignore:
Timestamp:
Sep 21, 2019 5:29:54 AM (5 years ago)
Author:
vboxsync
Message:

Storage/DevVirtioSCSI.cpp: Fixed/improved attach target count/allocation and processing, converted size_t to uint32_t where possible and added mapping on uint32_t <-> size_t conversions between VirtIO and the VSCSI layer. Other clean-up

Location:
trunk/src/VBox/Devices/VirtIO
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/VirtIO/Virtio_1_0.cpp

    r80762 r80928  
    3939 * See API comments in header file for description
    4040 */
    41 void virtioVirtToSgPhys(VIRTIOHANDLE hVirtio, PRTSGBUF pSgDst, void *pvSrc, size_t cb)
    42 {
    43     while (cb)
    44     {
    45         size_t cbSeg = cb;
    46         RTGCPHYS GCPhys = (RTGCPHYS)RTSgBufGetNextSegment(pSgDst, &cbSeg);
    47         PDMDevHlpPhysWrite(((PVIRTIOSTATE)hVirtio)->CTX_SUFF(pDevIns), GCPhys, pvSrc, cbSeg);
    48         pvSrc = ((uint8_t *)pvSrc) + cbSeg;
    49         cb -= cbSeg;
    50     }
    51 }
    52 
    53 /**
    54  * See API comments in header file for description
    55  */
    56 void virtioSgPhysToVirt(VIRTIOHANDLE hVirtio, PRTSGBUF pSgSrc, void *pvDst, size_t cb)
    57 {
    58     while (cb)
    59     {
    60         size_t cbSeg = cb;
    61         RTGCPHYS GCPhys = (RTGCPHYS)RTSgBufGetNextSegment(pSgSrc, &cbSeg);
    62         PDMDevHlpPhysRead(((PVIRTIOSTATE)hVirtio)->CTX_SUFF(pDevIns), GCPhys, pvDst, cbSeg);
    63         pvDst = ((uint8_t *)pvDst) + cbSeg;
    64         cb -= cbSeg;
    65     }
    66 }
    67 
    68 /**
    69  * See API comments in header file for description
    70  */
    7141int virtioQueueAttach(VIRTIOHANDLE hVirtio, uint16_t qIdx, const char *pcszName)
    7242{
     
    7949    RTStrCopy((char *)pVirtq->szVirtqName, sizeof(pVirtq->szVirtqName), pcszName);
    8050    return VINF_SUCCESS;
    81 
    8251}
    8352
     
    157126    uint16_t uDescIdx = uHeadIdx;
    158127
    159     Log6Func(("%s DESC CHAIN: (head) desc_idx=%u [avail_idx=%u]\n",
     128    Log3Func(("%s DESC CHAIN: (head) desc_idx=%u [avail_idx=%u]\n",
    160129            pVirtq->szVirtqName, uHeadIdx, pVirtq->uAvailIdx));
    161130
     
    198167        if (desc.fFlags & VIRTQ_DESC_F_WRITE)
    199168        {
    200             Log6Func(("%s IN  desc_idx=%u seg=%u addr=%RGp cb=%u\n",
     169            Log3Func(("%s IN  desc_idx=%u seg=%u addr=%RGp cb=%u\n",
    201170                QUEUENAME(qIdx), uDescIdx, cSegsIn, desc.pGcPhysBuf, desc.cb));
    202171            cbIn += desc.cb;
     
    205174        else
    206175        {
    207             Log6Func(("%s OUT desc_idx=%u seg=%u addr=%RGp cb=%u\n",
     176            Log3Func(("%s OUT desc_idx=%u seg=%u addr=%RGp cb=%u\n",
    208177                QUEUENAME(qIdx), uDescIdx, cSegsOut, desc.pGcPhysBuf, desc.cb));
    209178            cbOut += desc.cb;
     
    223192    RTSgBufInit(pSgPhysIn, (PCRTSGSEG)paSegsIn, cSegsIn);
    224193
    225     void *pSgVirtOut = RTMemAlloc(cbOut);
    226     AssertReturn(pSgVirtOut, VERR_NO_MEMORY);
     194    void *pVirtOut = RTMemAlloc(cbOut);
     195    AssertReturn(pVirtOut, VERR_NO_MEMORY);
     196
     197    /* If there's any guest → device data in phys. memory pulled
     198     * from queue, copy it into virtual memory to return to caller */
    227199
    228200    if (cSegsOut)
    229201    {
     202        uint8_t *outSgVirt = (uint8_t *)pVirtOut;
    230203        RTSGBUF outSgPhys;
    231204        RTSgBufInit(&outSgPhys, (PCRTSGSEG)paSegsOut, cSegsOut);
    232         virtioSgPhysToVirt((PVIRTIOSTATE)hVirtio, &outSgPhys, pSgVirtOut, cbOut);
     205        for (size_t cb = cbOut; cb;)
     206        {
     207            size_t cbSeg = cb;
     208            RTGCPHYS GCPhys = (RTGCPHYS)RTSgBufGetNextSegment(&outSgPhys, &cbSeg);
     209            PDMDevHlpPhysRead(((PVIRTIOSTATE)hVirtio)->CTX_SUFF(pDevIns), GCPhys, outSgVirt, cbSeg);
     210            outSgVirt = ((uint8_t *)outSgVirt) + cbSeg;
     211            cb -= cbSeg;
     212        }
    233213        RTMemFree(paSegsOut);
    234214    }
     
    239219    pDescChain->uHeadIdx   = uHeadIdx;
    240220    pDescChain->cbVirtSrc  = cbOut;
    241     pDescChain->pVirtSrc   = pSgVirtOut;
     221    pDescChain->pVirtSrc   = pVirtOut;
    242222    pDescChain->cbPhysDst  = cbIn;
    243223    pDescChain->pSgPhysDst = pSgPhysIn;
    244224    *ppDescChain = pDescChain;
    245225
    246     Log6Func(("%s -- segs OUT: %u (%u bytes)   IN: %u (%u bytes) --\n",
     226    Log3Func(("%s -- segs OUT: %u (%u bytes)   IN: %u (%u bytes) --\n",
    247227              pVirtq->szVirtqName, cSegsOut, cbOut, cSegsIn, cbIn));
    248228
     
    264244
    265245    uint16_t uUsedIdx = virtioReadUsedRingIdx(pVirtio, qIdx);
    266     Log6Func(("Copying client data to %s, desc chain (head desc_idx %d)\n",
     246    Log3Func(("Copying client data to %s, desc chain (head desc_idx %d)\n",
    267247               QUEUENAME(qIdx), uUsedIdx));
    268248
     
    270250     * Copy virtual memory s/g buffer containing data to return to the guest
    271251     * to phys. memory described by (IN direction ) s/g buffer of the descriptor chain
    272      * original pulled from the queue, to 'send back' to the guest driver.
     252     * (pulled from avail ring of queue), essentially giving result back to the guest driver.
    273253     */
    274     size_t cbRemain = RTSgBufCalcTotalLength(pSgVirtReturn);
    275     size_t cbCopy = 0;
     254    uint32_t cbRemain = RTSgBufCalcTotalLength(pSgVirtReturn);
     255    uint32_t cbCopy = 0;
    276256    while (cbRemain)
    277257    {
     
    288268    }
    289269
    290 
    291270    if (fFence)
    292271        RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
     
    302281    virtioWriteUsedElem(pVirtio, qIdx, pVirtq->uUsedIdx++, pDescChain->uHeadIdx, cbCopy);
    303282
    304 
    305     if (LogIs2Enabled())
    306     {
    307         Log2Func((".... Copied %u bytes to %u byte buffer, residual=%d\n",
    308              cbCopy, pDescChain->cbPhysDst, pDescChain->cbPhysDst - cbCopy));
    309     }
     283    Log2Func((".... Copied %u bytes to %u byte buffer, residual=%d\n",
     284         cbCopy, pDescChain->cbPhysDst, pDescChain->cbPhysDst - cbCopy));
     285
    310286    Log6Func(("Write ahead used_idx=%d, %s used_idx=%d\n",
    311287         pVirtq->uUsedIdx,  QUEUENAME(qIdx), uUsedIdx));
     
    14771453  *
    14781454  */
    1479  void virtioHexDump(uint8_t *pv, size_t cb, uint32_t uBase, const char *pszTitle)
     1455 void virtioHexDump(uint8_t *pv, uint32_t cb, uint32_t uBase, const char *pszTitle)
    14801456 {
    14811457     if (pszTitle)
     
    15121488 * @param   idx         - The index, if fHasIndex is true
    15131489 */
    1514 void virtioLogMappedIoValue(const char *pszFunc, const char *pszMember, size_t uMemberSize,
     1490void virtioLogMappedIoValue(const char *pszFunc, const char *pszMember, uint32_t uMemberSize,
    15151491                        const void *pv, uint32_t cb, uint32_t uOffset, bool fWrite,
    15161492                        bool fHasIndex, uint32_t idx)
  • trunk/src/VBox/Devices/VirtIO/Virtio_1_0.h

    r80762 r80928  
    6565{
    6666    uint32_t  uHeadIdx;                                    /**< Head idx of associated desc chain        */
    67     size_t    cbVirtSrc;                                   /**< Size of virt source buffer               */
     67    uint32_t    cbVirtSrc;                                   /**< Size of virt source buffer               */
    6868    void     *pVirtSrc;                                    /**< Virt mem buf holding out data from guest */
    69     size_t    cbPhysDst;                                   /**< Total size of dst buffer                 */
     69    uint32_t    cbPhysDst;                                   /**< Total size of dst buffer                 */
    7070    PRTSGBUF  pSgPhysDst;                                  /**< Phys S/G buf to store result for guest   */
    7171} VIRTIO_DESC_CHAIN_T, *PVIRTIO_DESC_CHAIN_T, **PPVIRTIO_DESC_CHAIN_T;
     
    119119 * @param   cbWrite     Number of bytes to write
    120120 */
    121 typedef DECLCALLBACK(int)   FNVIRTIODEVCAPWRITE(PPDMDEVINS pDevIns, uint32_t uOffset, const void *pvBuf, size_t cbWrite);
     121typedef DECLCALLBACK(int)   FNVIRTIODEVCAPWRITE(PPDMDEVINS pDevIns, uint32_t uOffset, const void *pvBuf, uint32_t cbWrite);
    122122typedef FNVIRTIODEVCAPWRITE *PFNVIRTIODEVCAPWRITE;
    123123
     
    131131 * @param   cbRead      Number of bytes to read
    132132 */
    133 typedef DECLCALLBACK(int)   FNVIRTIODEVCAPREAD(PPDMDEVINS pDevIns, uint32_t uOffset, const void *pvBuf, size_t cbRead);
     133typedef DECLCALLBACK(int)   FNVIRTIODEVCAPREAD(PPDMDEVINS pDevIns, uint32_t uOffset, const void *pvBuf, uint32_t cbRead);
    134134typedef FNVIRTIODEVCAPREAD *PFNVIRTIODEVCAPREAD;
    135135
     
    144144                                  (VIRTIOHANDLE hVirtio, void *pClient, uint16_t qIdx);
    145145     DECLCALLBACKMEMBER(int,  pfnVirtioDevCapRead)
    146                                   (PPDMDEVINS pDevIns, uint32_t uOffset, const void *pvBuf, size_t cbRead);
     146                                  (PPDMDEVINS pDevIns, uint32_t uOffset, const void *pvBuf, uint32_t cbRead);
    147147     DECLCALLBACKMEMBER(int,  pfnVirtioDevCapWrite)
    148                                   (PPDMDEVINS pDevIns, uint32_t uOffset, const void *pvBuf, size_t cbWrite);
     148                                  (PPDMDEVINS pDevIns, uint32_t uOffset, const void *pvBuf, uint32_t cbWrite);
    149149     DECLCALLBACKMEMBER(int,  pfnSSMDevLiveExec)
    150150                                  (PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass);
     
    381381 * @param   idx         - The index if fHasIndex
    382382 */
    383 void virtioLogMappedIoValue(const char *pszFunc, const char *pszMember, size_t uMemberSize,
     383void virtioLogMappedIoValue(const char *pszFunc, const char *pszMember, uint32_t uMemberSize,
    384384                            const void *pv, uint32_t cb, uint32_t uOffset,
    385385                            bool fWrite, bool fHasIndex, uint32_t idx);
     
    395395 *                        provided text with value of cb to indicate size next to it.
    396396 */
    397 void virtioHexDump(uint8_t *pv, size_t cb, uint32_t uBase, const char *pszTitle);
     397void virtioHexDump(uint8_t *pv, uint32_t cb, uint32_t uBase, const char *pszTitle);
    398398
    399399#endif /* !VBOX_INCLUDED_SRC_VirtIO_Virtio_1_0_h */
  • trunk/src/VBox/Devices/VirtIO/Virtio_1_0_impl.h

    r80762 r80928  
    517517        if (status & VIRTIO_STATUS_DEVICE_NEEDS_RESET)
    518518            Log6(("%sNEEDS_RESET", primed++ ? " | " : ""));
     519        (void)primed;
    519520    }
    520521}
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