- Timestamp:
- Sep 22, 2019 9:56:37 AM (5 years ago)
- Location:
- trunk/src/VBox/Devices
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/DevVirtioSCSI.cpp
r80928 r80931 47 47 #include "VBoxDD.h" 48 48 49 50 49 /* 51 50 * RT log-levels used: … … 327 326 uint8_t uResponse; /** response */ 328 327 } VIRTIOSCSI_CTRL_TMF_T, *PVIRTIOSCSI_CTRL_TMF_T; 329 #pragma pack( 0)328 #pragma pack() 330 329 331 330 /** … … 514 513 515 514 /** True if the guest/driver and VirtIO framework are in the ready state */ 516 boolfVirtioReady;515 unsigned fVirtioReady; 517 516 518 517 /** True if VIRTIO_SCSI_F_T10_PI was negotiated */ 519 boolfHasT10pi;518 unsigned fHasT10pi; 520 519 521 520 /** True if VIRTIO_SCSI_F_T10_PI was negotiated */ 522 boolfHasHotplug;521 unsigned fHasHotplug; 523 522 524 523 /** True if VIRTIO_SCSI_F_T10_PI was negotiated */ 525 boolfHasInOutBufs;524 unsigned fHasInOutBufs; 526 525 527 526 /** True if VIRTIO_SCSI_F_T10_PI was negotiated */ 528 boolfHasLunChange;527 unsigned fHasLunChange; 529 528 530 529 /** True if in the process of resetting */ 531 boolfResetting;530 unsigned fResetting; 532 531 533 532 /** True if in the process of quiescing I/O */ 534 boolfQuiescing;533 unsigned fQuiescing; 535 534 536 535 } VIRTIOSCSI, *PVIRTIOSCSI; … … 861 860 respHdr.uSenseLen = pReq->pbSense[2] == SCSI_SENSE_NONE ? 0 : (uint32_t)pReq->uSenseLen; 862 861 AssertMsg(!(cbResidual & 0xffffffff00000000), 863 ("WARNING: Residual size larger than uint32_t holds, truncating"));862 ("WARNING: Residual size larger than sizeof(uint32_t), truncating")); 864 863 respHdr.uResidual = (uint32_t)(cbResidual & 0xffffffff); 865 864 respHdr.uStatus = pReq->uStatus; … … 938 937 if (LogIs12Enabled()) 939 938 { 940 uint32_t cb = RT_MIN(cbXfer, 256); 939 Assert(!(cbXfer & 0xffffffff00000000)); 940 uint32_t cbXfer32 = cbXfer & 0xffffffff; 941 uint32_t cb = RT_MIN(cbXfer32, 256); 941 942 if (VIRTIO_IN_DIRECTION(pReq->enmTxDir)) 942 943 { … … 1003 1004 * (phys. memory) with the Req response data in virtual memory. 1004 1005 */ 1005 uint32_t cbReqSgBuf = RTSgBufCalcTotalLength(&reqSegBuf);1006 size_t cbReqSgBuf = RTSgBufCalcTotalLength(&reqSegBuf); 1006 1007 AssertMsgReturn(cbReqSgBuf <= pReq->pDescChain->cbPhysDst, 1007 ("Guest expected less req data (space needed: % d, avail: %d)\n",1008 ("Guest expected less req data (space needed: %ld, avail: %d)\n", 1008 1009 cbReqSgBuf, pReq->pDescChain->cbPhysDst), 1009 1010 VERR_BUFFER_OVERFLOW); … … 1349 1350 while (pThread->enmState == PDMTHREADSTATE_RUNNING) 1350 1351 { 1351 if (pThis->fQuiescing || !pThis->fQueueAttached[qIdx])1352 {1353 Log6Func(("Skipping wakeup (quiescing or reset)\n"));1354 continue;1355 }1356 1357 1352 if (virtioQueueIsEmpty(pThis->hVirtio, qIdx)) 1358 1353 { … … 1373 1368 ASMAtomicWriteBool(&pWorker->fSleeping, false); 1374 1369 } 1375 Log6Func(("fetching next descriptor chain from %s\n", QUEUENAME(qIdx))); 1376 PVIRTIO_DESC_CHAIN_T pDescChain; 1377 rc = virtioQueueGet(pThis->hVirtio, qIdx, &pDescChain, true); 1378 if (rc == VERR_NOT_AVAILABLE) 1370 1371 if (!pThis->fQueueAttached[qIdx]) 1379 1372 { 1380 Log6Func(("Nothing found in %s\n", QUEUENAME(qIdx))); 1381 continue; 1373 LogFunc(("%s queue not attached, worker aborting...\n", QUEUENAME(qIdx))); 1374 break; 1375 } else { 1376 LogFunc(("%s queue is still attached!\n", QUEUENAME(qIdx))); 1382 1377 } 1383 1378 1384 AssertRC(rc); 1385 if (qIdx == CONTROLQ_IDX) 1386 virtioScsiCtrl(pThis, qIdx, pDescChain); 1387 else /* request queue index */ 1379 if (!pThis->fQuiescing) 1388 1380 { 1389 rc = virtioScsiReqSubmit(pThis, qIdx, pDescChain); 1390 if (RT_FAILURE(rc)) 1391 { 1392 LogRel(("Error submitting req packet, resetting %Rrc", rc)); 1393 } 1381 Log6Func(("fetching next descriptor chain from %s\n", QUEUENAME(qIdx))); 1382 PVIRTIO_DESC_CHAIN_T pDescChain; 1383 rc = virtioQueueGet(pThis->hVirtio, qIdx, &pDescChain, true); 1384 if (rc == VERR_NOT_AVAILABLE) 1385 { 1386 Log6Func(("Nothing found in %s\n", QUEUENAME(qIdx))); 1387 continue; 1388 } 1389 1390 AssertRC(rc); 1391 if (qIdx == CONTROLQ_IDX) 1392 virtioScsiCtrl(pThis, qIdx, pDescChain); 1393 else /* request queue index */ 1394 { 1395 rc = virtioScsiReqSubmit(pThis, qIdx, pDescChain); 1396 if (RT_FAILURE(rc)) 1397 { 1398 LogRel(("Error submitting req packet, resetting %Rrc", rc)); 1399 } 1400 } 1394 1401 } 1395 1402 } … … 1513 1520 } 1514 1521 1515 static DECLCALLBACK(void) virtioScsiStatusChanged(VIRTIOHANDLE hVirtio, void *pClient, boolfVirtioReady)1522 static DECLCALLBACK(void) virtioScsiStatusChanged(VIRTIOHANDLE hVirtio, void *pClient, uint32_t fVirtioReady) 1516 1523 { 1517 1524 RT_NOREF(hVirtio); … … 1827 1834 1828 1835 static int virtioScsiCfgAccessed(PVIRTIOSCSI pThis, uint32_t uOffset, 1829 const void *pv, uint32_t cb, uint8_tfWrite)1836 const void *pv, uint32_t cb, bool fWrite) 1830 1837 { 1831 1838 int rc = VINF_SUCCESS; -
trunk/src/VBox/Devices/VirtIO/Virtio_1_0.cpp
r80928 r80931 35 35 #define INSTANCE(pVirtio) pVirtio->szInstance 36 36 #define QUEUENAME(qIdx) (pVirtio->virtqState[qIdx].szVirtqName) 37 37 38 38 39 /** … … 246 247 Log3Func(("Copying client data to %s, desc chain (head desc_idx %d)\n", 247 248 QUEUENAME(qIdx), uUsedIdx)); 249 (void)uUsedIdx; 248 250 249 251 /* … … 252 254 * (pulled from avail ring of queue), essentially giving result back to the guest driver. 253 255 */ 254 uint32_t cbRemain = RTSgBufCalcTotalLength(pSgVirtReturn);255 uint32_t cbCopy = 0;256 size_t cbCopy = 0; 257 size_t cbRemain = RTSgBufCalcTotalLength(pSgVirtReturn); 256 258 while (cbRemain) 257 259 { … … 260 262 uint64_t dstSgLen = (uint64_t)paSeg->cbSeg; 261 263 uint64_t dstSgCur = (uint64_t)pSgPhysReturn->pvSegCur; 262 cbCopy = RT_MIN( pSgVirtReturn->cbSegLeft, dstSgLen - (dstSgCur - dstSgStart));264 cbCopy = RT_MIN((uint64_t)pSgVirtReturn->cbSegLeft, dstSgLen - (dstSgCur - dstSgStart)); 263 265 PDMDevHlpPhysWrite(pVirtio->CTX_SUFF(pDevIns), 264 266 (RTGCPHYS)pSgPhysReturn->pvSegCur, pSgVirtReturn->pvSegCur, cbCopy); … … 276 278 pVirtq->fEventThresholdReached = true; 277 279 280 Assert(!(cbCopy & 0xffffffff00000000)); 278 281 /** 279 282 * Place used buffer's descriptor in used ring but don't update used ring's slot index. 280 283 * That will be done with a subsequent client call to virtioQueueSync() */ 281 virtioWriteUsedElem(pVirtio, qIdx, pVirtq->uUsedIdx++, pDescChain->uHeadIdx, cbCopy); 282 283 Log2Func((".... Copied %u bytes to %u byte buffer, residual=%d\n", 284 virtioWriteUsedElem(pVirtio, qIdx, pVirtq->uUsedIdx++, pDescChain->uHeadIdx, 285 (uint32_t)(cbCopy & 0xffffffff)); 286 287 Log2Func((".... Copied %ul bytes to %ul byte buffer, residual=%ul\n", 284 288 cbCopy, pDescChain->cbPhysDst, pDescChain->cbPhysDst - cbCopy)); 285 289 … … 310 314 Log6Func(("Updating %s used_idx from %u to %u\n", 311 315 QUEUENAME(qIdx), uIdx, pVirtq->uUsedIdx)); 316 (void)uIdx; 312 317 313 318 virtioWriteUsedRingIdx(pVirtio, qIdx, pVirtq->uUsedIdx); … … 323 328 { 324 329 Assert(uNotifyIdx == qIdx); 330 (void)uNotifyIdx; 325 331 326 332 PVIRTQSTATE pVirtq = &pVirtio->virtqState[qIdx]; 327 333 Log6Func(("%s\n", pVirtq->szVirtqName)); 334 (void)pVirtq; 328 335 329 336 /** Inform client */ … … 488 495 { 489 496 PVIRTIOSTATE pVirtio = (PVIRTIOSTATE)hVirtio; 490 return pVirtio->uQueueEnable[qIdx] ;497 return pVirtio->uQueueEnable[qIdx] != 0; 491 498 } 492 499 … … 528 535 529 536 /** Let the client know */ 530 pVirtio->virtioCallbacks.pfnVirtioStatusChanged((VIRTIOHANDLE)pVirtio, pVirtio->pClientContext, false);537 pVirtio->virtioCallbacks.pfnVirtioStatusChanged((VIRTIOHANDLE)pVirtio, pVirtio->pClientContext, 0); 531 538 virtioResetDevice(pVirtio); 532 539 } … … 645 652 * Notify client only if status actually changed from last time. 646 653 */ 647 bool fOkayNow = pVirtio->uDeviceStatus & VIRTIO_STATUS_DRIVER_OK; 648 bool fWasOkay = pVirtio->uPrevDeviceStatus & VIRTIO_STATUS_DRIVER_OK; 654 uint32_t fOkayNow = pVirtio->uDeviceStatus & VIRTIO_STATUS_DRIVER_OK; 655 uint32_t fWasOkay = pVirtio->uPrevDeviceStatus & VIRTIO_STATUS_DRIVER_OK; 656 uint32_t fDrvOk = pVirtio->uDeviceStatus & VIRTIO_STATUS_DRIVER_OK; 649 657 if ((fOkayNow && !fWasOkay) || (!fOkayNow && fWasOkay)) 650 pVirtio->virtioCallbacks.pfnVirtioStatusChanged((VIRTIOHANDLE)pVirtio, pVirtio->pClientContext, 651 pVirtio->uDeviceStatus & VIRTIO_STATUS_DRIVER_OK); 658 pVirtio->virtioCallbacks.pfnVirtioStatusChanged((VIRTIOHANDLE)pVirtio, pVirtio->pClientContext, fDrvOk); 652 659 pVirtio->uPrevDeviceStatus = pVirtio->uDeviceStatus; 653 660 } … … 758 765 { 759 766 uint32_t uOffset = GCPhysAddr - pVirtio->pGcPhysCommonCfg; 760 virtioCommonCfgAccessed(pVirtio, 0 /* fWrite */, uOffset, cb, pv);767 virtioCommonCfgAccessed(pVirtio, 0 /* fWrite */, uOffset, cb, (void const *)pv); 761 768 } 762 769 else … … 1072 1079 pVirtio->virtioCallbacks.pfnSSMDevLoadExec = ssmLoadExecCallback; 1073 1080 pVirtio->virtioCallbacks.pfnSSMDevLoadDone = ssmLoadDoneCallback; 1074 1075 1081 1076 1082 /* Set PCI config registers (assume 32-bit mode) */ … … 1308 1314 1309 1315 int rc = VINF_SUCCESS; 1310 virtioDumpState(pVirtio, "virtioSaveExec"); 1311 1316 1317 #ifdef DEBUG 1318 virtioDumpState(pVirtio, (const char *)"virtioSaveExec"); 1319 #endif 1312 1320 rc = SSMR3PutBool(pSSM, pVirtio->fGenUpdatePending); 1313 1321 rc = SSMR3PutU8(pSSM, pVirtio->uDeviceStatus); … … 1365 1373 1366 1374 int rc = VINF_SUCCESS; 1375 1376 #ifdef DEBUG 1367 1377 virtioDumpState(pVirtio, "virtioLoadExec"); 1378 #endif 1368 1379 1369 1380 if (uPass == SSM_PASS_FINAL) … … 1424 1435 1425 1436 int rc = VINF_SUCCESS; 1437 #ifdef DEBUG 1426 1438 virtioDumpState(pVirtio, "virtioLoadDone"); 1427 1439 #endif 1428 1440 rc = pVirtio->virtioCallbacks.pfnSSMDevLoadDone(pDevIns, pSSM); 1429 1441 … … 1437 1449 1438 1450 int rc = VINF_SUCCESS; 1451 1452 #ifdef DEBUG 1439 1453 virtioDumpState(pVirtio, "virtioLiveExec"); 1440 1454 #endif 1441 1455 rc = pVirtio->virtioCallbacks.pfnSSMDevLiveExec(pDevIns, pSSM, uPass); 1442 1456 … … 1473 1487 } 1474 1488 Log(("\n")); 1489 RT_NOREF2(uBase, pv); 1475 1490 } 1476 1491 … … 1489 1504 */ 1490 1505 void virtioLogMappedIoValue(const char *pszFunc, const char *pszMember, uint32_t uMemberSize, 1491 const void *pv, uint32_t cb, uint32_t uOffset, boolfWrite,1492 boolfHasIndex, uint32_t idx)1506 const void *pv, uint32_t cb, uint32_t uOffset, int fWrite, 1507 int fHasIndex, uint32_t idx) 1493 1508 { 1494 1509 … … 1529 1544 pszIdx, uOffset, uOffset + cb, cb, pv)); 1530 1545 } 1546 RT_NOREF2(fWrite, pszFunc); 1531 1547 } 1532 1548 -
trunk/src/VBox/Devices/VirtIO/Virtio_1_0.h
r80928 r80931 65 65 { 66 66 uint32_t uHeadIdx; /**< Head idx of associated desc chain */ 67 uint32_t 67 uint32_t cbVirtSrc; /**< Size of virt source buffer */ 68 68 void *pVirtSrc; /**< Virt mem buf holding out data from guest */ 69 uint32_t 69 uint32_t cbPhysDst; /**< Total size of dst buffer */ 70 70 PRTSGBUF pSgPhysDst; /**< Phys S/G buf to store result for guest */ 71 71 } VIRTIO_DESC_CHAIN_T, *PVIRTIO_DESC_CHAIN_T, **PPVIRTIO_DESC_CHAIN_T; … … 96 96 * @param pClient Pointer to opaque client data (state) 97 97 */ 98 typedef DECLCALLBACK(void) FNVIRTIOSTATUSCHANGED(VIRTIOHANDLE hVirtio, void *pClient, boolfDriverOk);98 typedef DECLCALLBACK(void) FNVIRTIOSTATUSCHANGED(VIRTIOHANDLE hVirtio, void *pClient, uint32_t fDriverOk); 99 99 typedef FNVIRTIOSTATUSCHANGED *PFNVIRTIOSTATUSCHANGED; 100 100 … … 140 140 { 141 141 DECLCALLBACKMEMBER(void, pfnVirtioStatusChanged) 142 (VIRTIOHANDLE hVirtio, void *pClient, boolfDriverOk);142 (VIRTIOHANDLE hVirtio, void *pClient, uint32_t fDriverOk); 143 143 DECLCALLBACKMEMBER(void, pfnVirtioQueueNotified) 144 144 (VIRTIOHANDLE hVirtio, void *pClient, uint16_t qIdx); … … 320 320 */ 321 321 uint64_t virtioGetNegotiatedFeatures(VIRTIOHANDLE hVirtio); 322 323 322 324 323 /** CLIENT MUST CALL ON RELOCATE CALLBACK! */ … … 383 382 void virtioLogMappedIoValue(const char *pszFunc, const char *pszMember, uint32_t uMemberSize, 384 383 const void *pv, uint32_t cb, uint32_t uOffset, 385 bool fWrite, bool fHasIndex, uint32_t idx); 386 384 int fWrite, int fHasIndex, uint32_t idx); 387 385 /** 388 386 * Does a formatted hex dump using Log(()), recommend using VIRTIO_HEX_DUMP() macro to -
trunk/src/VBox/Devices/VirtIO/Virtio_1_0_impl.h
r80928 r80931 240 240 /** 241 241 * This macro returns true if the implied parameter GCPhysAddr address and access length are 242 * within mapped capability struct specified with the explicit parameters.242 * within the range of the mapped capability struct specified with the explicit parameters. 243 243 * 244 244 * Actual Parameters: … … 283 283 #define LOG_COMMON_CFG_ACCESS_INDEXED(member, idx) \ 284 284 virtioLogMappedIoValue(__FUNCTION__, #member, RT_SIZEOFMEMB(VIRTIO_PCI_COMMON_CFG_T, member), \ 285 pv, cb, uIntraOff, fWrite, true, idx);285 pv, cb, uIntraOff, fWrite, true, idx); 286 286 287 287 #define COMMON_CFG_ACCESSOR(member) \ … … 521 521 } 522 522 523 static int virtioCommonCfgAccessed (PVIRTIOSTATE pVirtio, int fWrite, off_t uOffset, unsigned cb, void const *pv); 523 524 static void virtioResetQueue (PVIRTIOSTATE pVirtio, uint16_t qIdx); 524 525 static void virtioNotifyGuestDriver (PVIRTIOSTATE pVirtio, uint16_t qIdx, bool fForce); … … 526 527 static void virtioLowerInterrupt (PVIRTIOSTATE pVirtio); 527 528 static void virtioQueueNotified (PVIRTIOSTATE pVirtio, uint16_t qidx, uint16_t uDescIdx); 528 static int virtioCommonCfgAccessed (PVIRTIOSTATE pVirtio, int fWrite, off_t uOffset, unsigned cb, void const *pv);529 529 static void virtioGuestResetted (PVIRTIOSTATE pVirtio); 530 530
Note:
See TracChangeset
for help on using the changeset viewer.