VirtualBox

Changeset 80928 in vbox for trunk


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
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/DevVirtioSCSI.cpp

    r80762 r80928  
    4747#include "VBoxDD.h"
    4848
     49
     50/*
     51 * RT log-levels used:
     52 *
     53 *    Level 1:   The most important (but usually rare) things to note
     54 *    Level 2:   SCSI command logging
     55 *    Level 3:   Vector and I/O transfer summary (shows what client sent an expects and fulfillment)
     56 *    Level 6:   Device ⟷ Guest Driver negotation, traffic, notifications and state handling
     57 *    Level 12:  Brief formatted hex dumps of I/O data
     58 */
     59
    4960#define LUN0    0
    5061/**
     
    6980 * TEMPORARY NOTE: following parameter is set to 1 for early development. Will be increased later
    7081 */
    71 #define VIRTIOSCSI_REQ_QUEUE_CNT                    1            /**< Number of req queues exposed by dev.            */
     82#define VIRTIOSCSI_REQ_QUEUE_CNT                    2            /**< Number of req queues exposed by dev.            */
    7283#define VIRTIOSCSI_QUEUE_CNT                        VIRTIOSCSI_REQ_QUEUE_CNT + 2
    73 #define VIRTIOSCSI_MAX_TARGETS                      256          /**< Default value                                   */
    7484#define VIRTIOSCSI_MAX_LUN                          256          /* < VirtIO specification, section 5.6.4             */
    7585#define VIRTIOSCSI_MAX_COMMANDS_PER_LUN             1            /* < T.B.D. What is a good value for this?           */
     
    110120
    111121/**
    112  * This macro resolves to boolean true if uOffset matches a field offset and size exactly,
    113  * (or if it is a 64-bit field, if it accesses either 32-bit part as a 32-bit access)
    114  * ASSUMED this critereon is mandated by section 4.1.3.1 of the VirtIO 1.0 specification)
    115  * This MACRO can be re-written to allow unaligned access to a field (within bounds).
     122 * Resolves to boolean true if uOffset matches a field offset and size exactly,
     123 * (or if 64-bit field, if it accesses either 32-bit part as a 32-bit access)
     124 * It is *assumed* this critereon is mandated by section 4.1.3.1 of the VirtIO 1.0 spec)
     125 * This macro can be re-written to allow unaligned access to a field (within bounds).
    116126 *
    117127 * @param   member   - Member of VIRTIO_PCI_COMMON_CFG_T
     
    160170            pMediaExTxDirEnumValue == PDMMEDIAEXIOREQSCSITXDIR_TO_DEVICE
    161171/**
    162  * The following struct is the VirtIO SCSI Host Device  device-specific configuration described in section 5.6.4
    163  * of the VirtIO 1.0 specification. This layout maps an MMIO area shared VirtIO guest driver. The VBox VirtIO
    164  * this virtual controller device implementation is a client of. The frame work calls back whenever the guest driver
    165  * accesses any part of field in this struct
     172 * Following struct is the VirtIO SCSI Host Device device-specific configuration described in section 5.6.4
     173 * of the VirtIO 1.0 spec. Layout maps an MMIO area shared VirtIO guest driver. The VBox VirtIO
     174 * this virtual controller device implementation is a client of. Framework does a callback whenever
     175 * guest driver accesses any part of field in this struct
    166176 */
    167177typedef struct virtio_scsi_config
     
    312322    uint32_t uType;                                            /** type                                              */
    313323    uint32_t uSubtype;                                         /** subtype                                           */
    314     uint8_t  uScsiLun[8];                                    /** lun                                               */
     324    uint8_t  uScsiLun[8];                                      /** lun                                               */
    315325    uint64_t uId;                                              /** id                                                */
    316326    // Device-writable part
     
    335345    // Device-readable part
    336346    uint32_t  uType;                                          /** type                                               */
    337     uint8_t   uScsiLun[8];                                  /** lun                                                */
     347    uint8_t   uScsiLun[8];                                    /** lun                                                */
    338348    uint32_t  uEventsRequested;                               /** event_requested                                    */
    339349    // Device-writable part
     
    429439    VIRTIOHANDLE                    hVirtio;
    430440
    431     /** SCSI target instances data */
    432     VIRTIOSCSITARGET                aTargetInstances[VIRTIOSCSI_MAX_TARGETS];
     441    /** Number of targets detected */
     442    uint64_t                        cTargets;
     443
     444    R3PTRTYPE(PVIRTIOSCSITARGET)    paTargetInstances;
     445#if HC_ARCH_BITS == 32
     446      RTR3PTR                 R3PtrPadding0;
     447#endif
    433448
    434449    /** Per device-bound virtq worker-thread contexts (eventq slot unused) */
     
    482497    /** The event semaphore the processing thread waits on. */
    483498
    484     /** Number of targets detected */
    485     uint64_t                        cTargets;
    486499
    487500    /** Total number of requests active across all targets */
     
    532545    PVIRTIOSCSITARGET              pTarget;                  /**< Target                                            */
    533546    uint16_t                       qIdx;                     /**< Index of queue this request arrived on            */
    534     size_t                         cbPiOut;                  /**< Size of T10 pi in buffer                          */
     547    uint32_t                       cbPiOut;                  /**< Size of T10 pi in buffer                          */
    535548    uint8_t                       *pbPiOut;                  /**< Address of pi out buffer                          */
    536549    uint8_t                       *pbDataOut;                /**< dataout                                           */
    537     size_t                         cbDataOut;                /**< size of dataout buffer                            */
    538     size_t                         cbPiIn;                   /**< Size of T10 pi buffer                             */
     550    uint32_t                       cbDataOut;                /**< size of dataout buffer                            */
     551    uint32_t                       cbPiIn;                   /**< Size of T10 pi buffer                             */
    539552    uint8_t                       *pbPiIn;                   /**< Address of pi in buffer                           */
    540     size_t                         cbDataIn;                 /**< Size of datain buffer                             */
     553    uint32_t                       cbDataIn;                 /**< Size of datain buffer                             */
    541554    uint8_t                       *pbDataIn;                 /**< datain                                            */
    542     size_t                         cbSense;                  /**< Size of sense buffer                              */
     555    uint32_t                       cbSense;                  /**< Size of sense buffer                              */
    543556    size_t                         uSenseLen;                /**< Receives # bytes written into sense buffer        */
    544557    uint8_t                       *pbSense;                  /**< Pointer to R3 sense buffer                        */
     
    548561} VIRTIOSCSIREQ;
    549562
    550 DECLINLINE(bool) isBufZero(uint8_t *pv, size_t cb)
     563DECLINLINE(bool) isBufZero(uint8_t *pv, uint32_t cb)
    551564{
    552565    for (uint32_t i = 0; i < cb; i++)
     
    619632}
    620633
    621 DECLINLINE(void) virtioGetControlAsyncMaskText(char *pszOutput, size_t cbOutput, uint32_t uAsyncTypesMask)
     634DECLINLINE(void) virtioGetControlAsyncMaskText(char *pszOutput, uint32_t cbOutput, uint32_t uAsyncTypesMask)
    622635{
    623636    RTStrPrintf(pszOutput, cbOutput, "%s%s%s%s%s%s",
     
    713726        case VIRTIOSCSI_T_NO_EVENT:
    714727            if (uEventType & VIRTIOSCSI_T_EVENTS_MISSED)
    715                 LogFunc(("(target=%d, LUN=%d) Warning driver that events were missed\n", uTarget, LUN0));
     728                Log6Func(("(target=%d, LUN=%d) Warning driver that events were missed\n", uTarget, LUN0));
    716729            else
    717                 LogFunc(("(target=%d, LUN=%d): Warning event info guest queued is shorter than configured\n",
     730                Log6Func(("(target=%d, LUN=%d): Warning event info guest queued is shorter than configured\n",
    718731                          uTarget, LUN0));
    719732            break;
     
    722735            {
    723736                case VIRTIOSCSI_EVT_RESET_REMOVED:
    724                     LogFunc(("(target=%d, LUN=%d): Target or LUN removed\n", uTarget, LUN0));
     737                    Log6Func(("(target=%d, LUN=%d): Target or LUN removed\n", uTarget, LUN0));
    725738                    break;
    726739                case VIRTIOSCSI_EVT_RESET_RESCAN:
    727                     LogFunc(("(target=%d, LUN=%d): Target or LUN added\n", uTarget, LUN0));
     740                    Log6Func(("(target=%d, LUN=%d): Target or LUN added\n", uTarget, LUN0));
    728741                    break;
    729742                case VIRTIOSCSI_EVT_RESET_HARD:
    730                     LogFunc(("(target=%d, LUN=%d): Target was reset\n", uTarget, LUN0));
     743                    Log6Func(("(target=%d, LUN=%d): Target was reset\n", uTarget, LUN0));
    731744                    break;
    732745            }
     
    735748            char szTypeText[128];
    736749            virtioGetControlAsyncMaskText(szTypeText, sizeof(szTypeText), uReason);
    737             LogFunc(("(target=%d, LUN=%d): Delivering subscribed async notification %s\n", uTarget, LUN0));
     750            Log6Func(("(target=%d, LUN=%d): Delivering subscribed async notification %s\n", uTarget, LUN0));
    738751            break;
    739752        case VIRTIOSCSI_T_PARAM_CHANGE:
     
    742755            break;
    743756        default:
    744             LogFunc(("(target=%d, LUN=%d): Unknown event type: %d, ignoring\n", uTarget, LUN0));
     757            Log6Func(("(target=%d, LUN=%d): Unknown event type: %d, ignoring\n", uTarget, LUN0));
    745758            return VINF_SUCCESS;
    746759    }
     
    837850    PPDMIMEDIAEX      pIMediaEx = pTarget->pDrvMediaEx;
    838851
    839     size_t cbResidual = 0, cbXfer = 0;
     852    size_t cbResidual = 0;
     853    size_t cbXfer = 0;
    840854    int rc = pIMediaEx->pfnIoReqQueryResidual(pIMediaEx, hIoReq, &cbResidual);
    841855    AssertRC(rc);
     
    845859
    846860    struct REQ_RESP_HDR respHdr = { 0 };
    847     respHdr.uSenseLen = pReq->pbSense[2] == SCSI_SENSE_NONE ? 0 : pReq->uSenseLen;
    848     respHdr.uResidual = cbResidual;
     861    respHdr.uSenseLen = pReq->pbSense[2] == SCSI_SENSE_NONE ? 0 : (uint32_t)pReq->uSenseLen;
     862    AssertMsg(!(cbResidual & 0xffffffff00000000),
     863            ("WARNING: Residual size larger than uint32_t holds, truncating"));
     864    respHdr.uResidual = (uint32_t)(cbResidual & 0xffffffff);
    849865    respHdr.uStatus   = pReq->uStatus;
    850866
     
    909925        LogFunc(("cbDataIn = %u, cbDataOut = %u (cbIn = %u, cbOut = %u)\n",
    910926                  pReq->cbDataIn, pReq->cbDataOut, pReq->pDescChain->cbPhysDst, pReq->pDescChain->cbVirtSrc));
    911         LogFunc(("xfer = %d, residual = %u\n", cbXfer, cbResidual));
     927        LogFunc(("xfer = %lu, residual = %u\n", cbXfer, cbResidual));
    912928        LogFunc(("xfer direction: %s, sense written = %d, sense size = %d\n",
    913929             virtioGetTxDirText(pReq->enmTxDir), respHdr.uSenseLen, pThis->virtioScsiConfig.uSenseSize));
     
    920936    }
    921937
    922     if (LogIsItEnabled(RTLOGGRPFLAGS_LEVEL_12, LOG_GROUP))
    923     {
    924         size_t cb = RT_MIN(cbXfer, 256);
     938    if (LogIs12Enabled())
     939    {
     940        uint32_t cb = RT_MIN(cbXfer, 256);
    925941        if (VIRTIO_IN_DIRECTION(pReq->enmTxDir))
    926942        {
    927             Log(("datain[256 of %d total bytes xferred]:\n", cbXfer));
     943            Log(("datain[%d of %d total bytes xferred]:\n", cb, cbXfer));
    928944            if (!isBufZero(pReq->pbDataIn, cb))
    929945                VIRTIO_HEX_DUMP(RTLOGGRPFLAGS_LEVEL_12, pReq->pbDataIn,  cb,  0, 0);
     
    934950        if (VIRTIO_OUT_DIRECTION(pReq->enmTxDir))
    935951        {
    936             Log(("dataout[256 of %d total bytes xferred]:\n", cbXfer));
     952            Log(("dataout[%d of %d total bytes xferred]:\n", cb, cbXfer));
    937953            if (!isBufZero(pReq->pbDataOut, cb))
    938954                VIRTIO_HEX_DUMP(RTLOGGRPFLAGS_LEVEL_12, pReq->pbDataOut, cb, 0, 0);
     
    9871003         * (phys. memory) with the Req response data in virtual memory.
    9881004         */
    989         size_t cbReqSgBuf = RTSgBufCalcTotalLength(&reqSegBuf);
     1005        uint32_t cbReqSgBuf = RTSgBufCalcTotalLength(&reqSegBuf);
    9901006        AssertMsgReturn(cbReqSgBuf <= pReq->pDescChain->cbPhysDst,
    9911007                       ("Guest expected less req data (space needed: %d, avail: %d)\n",
     
    10161032    uint8_t  uTarget  = pVirtqReq->cmdHdr.uVirtioLun[1];
    10171033    uint32_t uScsiLun = (pVirtqReq->cmdHdr.uVirtioLun[2] << 8 | pVirtqReq->cmdHdr.uVirtioLun[3]) & 0x3fff;
    1018     PVIRTIOSCSITARGET pTarget = &pThis->aTargetInstances[uTarget];
     1034    PVIRTIOSCSITARGET pTarget = &pThis->paTargetInstances[uTarget];
    10191035
    10201036    LogFunc(("[%s] (Target: %d LUN: %d)  CDB: %.*Rhxs\n",
     
    10291045     * Calculate request offsets
    10301046     */
    1031     size_t  cbPiIn = 0, cbPiOut = 0, cbPiHdr = 0;
     1047    uint32_t  cbPiIn = 0, cbPiOut = 0, cbPiHdr = 0;
    10321048    off_t   piOutOff = 0;
    10331049
     
    10431059    off_t   uDataInOff  = sizeof(REQ_RESP_HDR) + pThis->virtioScsiConfig.uSenseSize + cbPiIn;
    10441060    uint8_t *pbDataOut = (uint8_t *)((uint64_t)pVirtqReq + uDataOutOff);
    1045     size_t  cbDataOut = pDescChain->cbVirtSrc - uDataOutOff;
    1046     size_t  cbDataIn  = pDescChain->cbPhysDst - uDataInOff;
     1061    uint32_t  cbDataOut = pDescChain->cbVirtSrc - uDataOutOff;
     1062    uint32_t  cbDataIn  = pDescChain->cbPhysDst - uDataInOff;
    10471063
    10481064    /**
     
    11321148
    11331149    rc = pIMediaEx->pfnIoReqSendScsiCmd(pIMediaEx, pReq->hIoReq, uScsiLun,
    1134                                         pVirtqReq->uCdb, pThis->virtioScsiConfig.uCdbSize,
     1150                                        pVirtqReq->uCdb, (size_t)pThis->virtioScsiConfig.uCdbSize,
    11351151                                        PDMMEDIAEXIOREQSCSITXDIR_UNKNOWN, &pReq->enmTxDir,
    1136                                         RT_MAX(cbDataIn, cbDataOut),
    1137                                         pReq->pbSense, pReq->cbSense, &pReq->uSenseLen,
     1152                                        (size_t)RT_MAX(cbDataIn, cbDataOut),
     1153                                        pReq->pbSense, (size_t)pReq->cbSense, &pReq->uSenseLen,
    11381154                                        &pReq->uStatus, 30 * RT_MS_1SEC);
    11391155
     
    11451161         */
    11461162        Log2Func(("Request submission error from lower-level driver\n"));
    1147         size_t cbResidual;
    1148         pIMediaEx->pfnIoReqQueryResidual(pIMediaEx, pReq->hIoReq, &cbResidual);
    11491163        uint8_t uASC, uASCQ = 0;
    11501164        switch (rc)
     
    13431357        if (virtioQueueIsEmpty(pThis->hVirtio, qIdx))
    13441358        {
    1345             /* Interlocks avoid missing alarm while going to sleep & notifier doesn't wake the awoken */
     1359            /* Atomic interlocks avoid missing alarm while going to sleep & notifier waking the awoken */
    13461360            ASMAtomicWriteBool(&pWorker->fSleeping, true);
    13471361            bool fNotificationSent = ASMAtomicXchgBool(&pWorker->fNotified, false);
     
    13711385        if (qIdx == CONTROLQ_IDX)
    13721386            virtioScsiCtrl(pThis, qIdx, pDescChain);
    1373         else
     1387        else /* request queue index */
    13741388        {
    13751389            rc = virtioScsiReqSubmit(pThis, qIdx, pDescChain);
     
    14721486    PVIRTIOSCSI pThis = (PVIRTIOSCSI)pClient;
    14731487    PWORKER pWorker = &pThis->aWorker[qIdx];
    1474 
    14751488
    14761489    RTLogFlush(RTLogDefaultInstanceEx(RT_MAKE_U32(0, UINT16_MAX)));
     
    17361749    for (uint32_t i = 0; i < pThis->cTargets; i++)
    17371750    {
    1738         PVIRTIOSCSITARGET pTarget = &pThis->aTargetInstances[i];
     1751        PVIRTIOSCSITARGET pTarget = &pThis->paTargetInstances[i];
    17391752        if (pTarget->pDrvBase)
    17401753            if (pTarget->pDrvMediaEx)
     
    17781791 * @returns VBox status code.
    17791792 * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1780  * @param   iTarget            The unit which status LED we desire.
     1793 * @param   iTarget         The unit which status LED we desire.
    17811794 * @param   ppLed           Where to store the LED pointer.
    17821795 */
     
    17981811 * @returns VBox status code.
    17991812 * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1800  * @param   iTarget            The unit which status LED we desire.
     1813 * @param   iTarget         The unit which status LED we desire.
    18011814 * @param   ppLed           Where to store the LED pointer.
    18021815 */
     
    18061819    if (iTarget < pThis->cTargets)
    18071820    {
    1808         *ppLed = &pThis->aTargetInstances[iTarget].led;
     1821        *ppLed = &pThis->paTargetInstances[iTarget].led;
    18091822        Assert((*ppLed)->u32Magic == PDMLED_MAGIC);
    18101823        return VINF_SUCCESS;
     
    18141827
    18151828static int virtioScsiCfgAccessed(PVIRTIOSCSI pThis, uint32_t uOffset,
    1816                                     const void *pv, size_t cb, uint8_t fWrite)
     1829                                    const void *pv, uint32_t cb, uint8_t fWrite)
    18171830{
    18181831    int rc = VINF_SUCCESS;
     
    18631876 * @param   cb          Number of bytes to read
    18641877 */
    1865 static DECLCALLBACK(int) virtioScsiDevCapRead(PPDMDEVINS pDevIns, uint32_t uOffset, const void *pv, size_t cb)
     1878static DECLCALLBACK(int) virtioScsiDevCapRead(PPDMDEVINS pDevIns, uint32_t uOffset, const void *pv, uint32_t cb)
    18661879{
    18671880    int rc = VINF_SUCCESS;
     
    18821895 * @param   cb          Number of bytes to write
    18831896 */
    1884 static DECLCALLBACK(int) virtioScsiDevCapWrite(PPDMDEVINS pDevIns, uint32_t uOffset, const void *pv, size_t cb)
     1897static DECLCALLBACK(int) virtioScsiDevCapWrite(PPDMDEVINS pDevIns, uint32_t uOffset, const void *pv, uint32_t cb)
    18851898{
    18861899    int rc = VINF_SUCCESS;
     
    19161929    pThis->pDevInsR3 = pDevIns;
    19171930
    1918     for (uint32_t i = 0; i < VIRTIOSCSI_MAX_TARGETS; i++)
    1919     {
    1920         PVIRTIOSCSITARGET pTarget = &pThis->aTargetInstances[i];
     1931    for (uint32_t i = 0; i < pThis->cTargets; i++)
     1932    {
     1933        PVIRTIOSCSITARGET pTarget = &pThis->paTargetInstances[i];
    19211934        pTarget->pVirtioScsi = pThis;
    19221935    }
     
    19861999    RT_NOREF(fFlags);
    19872000    PVIRTIOSCSI       pThis = PDMINS_2_DATA(pDevIns, PVIRTIOSCSI);
    1988     PVIRTIOSCSITARGET pTarget = &pThis->aTargetInstances[iTarget];
     2001    PVIRTIOSCSITARGET pTarget = &pThis->paTargetInstances[iTarget];
    19892002
    19902003    LogFunc((""));
     
    20132026{
    20142027    PVIRTIOSCSI       pThis   = PDMINS_2_DATA(pDevIns, PVIRTIOSCSI);
    2015     PVIRTIOSCSITARGET pTarget = &pThis->aTargetInstances[iTarget];
     2028    PVIRTIOSCSITARGET pTarget = &pThis->paTargetInstances[iTarget];
    20162029    int rc;
    20172030
     
    20572070    PVIRTIOSCSI  pThis = PDMINS_2_DATA(pDevIns, PVIRTIOSCSI);
    20582071
     2072    RTMemFree(pThis->paTargetInstances);
     2073    pThis->paTargetInstances = NULL;
    20592074    for (int qIdx = 0; qIdx < VIRTIOSCSI_QUEUE_CNT; qIdx++)
    20602075    {
     
    20852100
    20862101    /* Usable defaults */
    2087     pThis->cTargets = VIRTIOSCSI_MAX_TARGETS;
     2102    pThis->cTargets = 1;
    20882103
    20892104    /*
     
    22062221    Log2Func(("Found %d targets attached to controller\n", pThis->cTargets));
    22072222
     2223     pThis->paTargetInstances = (PVIRTIOSCSITARGET)RTMemAllocZ(sizeof(VIRTIOSCSITARGET) * pThis->cTargets);
     2224     if (!pThis->paTargetInstances)
     2225          return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to allocate memory for target states"));
     2226
    22082227    for (RTUINT iTarget = 0; iTarget < pThis->cTargets; iTarget++)
    22092228    {
    2210         PVIRTIOSCSITARGET pTarget = &pThis->aTargetInstances[iTarget];
     2229        PVIRTIOSCSITARGET pTarget = &pThis->paTargetInstances[iTarget];
    22112230
    22122231        if (RTStrAPrintf(&pTarget->pszTargetName, "VSCSI%u", iTarget) < 0)
     
    22382257        LogFunc(("Attaching LUN: %s\n", pTarget->pszTargetName));
    22392258
    2240         AssertReturn(iTarget < RT_ELEMENTS(pThis->aTargetInstances), VERR_PDM_NO_SUCH_LUN);
    2241         rc = PDMDevHlpDriverAttach(pDevIns, iTarget, &pTarget->IBase, &pTarget->pDrvBase, (const char *)&pTarget->pszTargetName);
     2259        AssertReturn(iTarget < pThis->cTargets, VERR_PDM_NO_SUCH_LUN);
     2260        rc = PDMDevHlpDriverAttach(pDevIns, iTarget, &pTarget->IBase, &pTarget->pDrvBase, pTarget->pszTargetName);
    22422261        if (RT_SUCCESS(rc))
    22432262        {
     
    22462265            pTarget->pDrvMedia = PDMIBASE_QUERY_INTERFACE(pTarget->pDrvBase, PDMIMEDIA);
    22472266            AssertMsgReturn(VALID_PTR(pTarget->pDrvMedia),
    2248                          ("virtio-scsi configuration error: LUN#%d missing basic media interface!\n", pTarget->iTarget),
     2267                         ("virtio-scsi configuration error: LUN#%d missing basic media interface!\n", iTarget),
    22492268                         VERR_PDM_MISSING_INTERFACE);
    22502269
     
    22522271            pTarget->pDrvMediaEx = PDMIBASE_QUERY_INTERFACE(pTarget->pDrvBase, PDMIMEDIAEX);
    22532272            AssertMsgReturn(VALID_PTR(pTarget->pDrvMediaEx),
    2254                          ("virtio-scsi configuration error: LUN#%d missing extended media interface!\n", pTarget->iTarget),
     2273                         ("virtio-scsi configuration error: LUN#%d missing extended media interface!\n", iTarget),
    22552274                         VERR_PDM_MISSING_INTERFACE);
    22562275
    22572276            rc = pTarget->pDrvMediaEx->pfnIoReqAllocSizeSet(pTarget->pDrvMediaEx, sizeof(VIRTIOSCSIREQ));
    22582277            AssertMsgReturn(VALID_PTR(pTarget->pDrvMediaEx),
    2259                          ("virtio-scsi configuration error: LUN#%u: Failed to set I/O request size!\n", pTarget->iTarget),
     2278                         ("virtio-scsi configuration error: LUN#%u: Failed to set I/O request size!\n", iTarget),
    22602279                         rc);
    22612280
     
    22632282            AssertMsgReturn(VALID_PTR(pTarget->pDrvMediaEx),
    22642283                         ("virtio-scsi configuration error: LUN#%u: Failed to get set Media notify obj!\n",
    2265                           pTarget->iTarget), rc);
     2284                          iTarget), rc);
    22662285
    22672286        }
     
    22752294        else
    22762295        {
    2277             AssertLogRelMsgFailed(("virtio-scsi: Failed to attach %s: %Rrc\n", pTarget->pszTargetName));
     2296            AssertLogRelMsgFailed(("virtio-scsi: Failed to attach %s: %Rrc\n", pTarget->pszTargetName, rc));
    22782297            return rc;
    22792298        }
  • 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