Changeset 85016 in vbox for trunk/src/VBox/Devices/Storage
- Timestamp:
- Jul 1, 2020 5:28:16 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/DevVirtioSCSI.cpp
r84876 r85016 164 164 { 165 165 // Device-writable part 166 uint32_t uEvent; /**< event */166 uint32_t uEvent; /**< event */ 167 167 uint8_t abVirtioLun[8]; /**< lun */ 168 168 uint32_t uReason; /**< reason */ … … 216 216 uint8_t uCdb[1]; /**< cdb */ 217 217 218 REQ_CMD_PI_T piHdr; /**< T10 Pi block integrity (optional feature) 218 REQ_CMD_PI_T piHdr; /**< T10 Pi block integrity (optional feature) */ 219 219 uint8_t uPiOut[1]; /**< pi_out[] T10 pi block integrity */ 220 220 uint8_t uDataOut[1]; /**< dataout */ … … 1182 1182 { 1183 1183 size_t cbSeg = cbReqHdr - offReq; 1184 RTGCPHYS GCPhys = virtioCoreGCPhysChainGetNextSeg ment(pVirtqBuf->pSgPhysSend, &cbSeg);1184 RTGCPHYS GCPhys = virtioCoreGCPhysChainGetNextSeg(pVirtqBuf->pSgPhysSend, &cbSeg); 1185 1185 PDMDevHlpPCIPhysReadMeta(pDevIns, GCPhys, &VirtqReq.ab[offReq], cbSeg); 1186 1186 offReq += cbSeg; … … 1345 1345 virtioScsiR3FreeReq(pTarget, pReq); 1346 1346 } 1347 1348 1347 return VINF_SUCCESS; 1349 1348 } … … 1371 1370 RT_ZERO(ScsiCtrlUnion); 1372 1371 1373 size_t const cb Ctrl= RT_MIN(pVirtqBuf->cbPhysSend, sizeof(VIRTIO_SCSI_CTRL_UNION_T));1374 for (size_t offCtrl = 0; offCtrl < cbCtrl; )1375 { 1376 size_t cbSeg = cb Ctrl - offCtrl;1377 RTGCPHYS GCPhys = virtioCoreGCPhysChainGetNextSeg ment(pVirtqBuf->pSgPhysSend, &cbSeg);1378 PDMDevHlpPCIPhysReadMeta(pDevIns, GCPhys, &ScsiCtrlUnion.ab[ offCtrl], cbSeg);1379 offCtrl+= cbSeg;1372 size_t const cb = RT_MIN(pVirtqBuf->cbPhysSend, sizeof(VIRTIO_SCSI_CTRL_UNION_T)); 1373 for (size_t uOffset = 0; uOffset < cb; ) 1374 { 1375 size_t cbSeg = cb - uOffset; 1376 RTGCPHYS GCPhys = virtioCoreGCPhysChainGetNextSeg(pVirtqBuf->pSgPhysSend, &cbSeg); 1377 PDMDevHlpPCIPhysReadMeta(pDevIns, GCPhys, &ScsiCtrlUnion.ab[uOffset], cbSeg); 1378 uOffset += cbSeg; 1380 1379 } 1381 1380 … … 1591 1590 PVIRTQBUF pVirtqBuf; 1592 1591 int rc = virtioCoreR3VirtqAvailBufGet(pDevIns, &pThis->Virtio, uVirtqNbr, 1593 pWorkerR3->auRedoDescs[i], &pVirtqBuf);1592 pWorkerR3->auRedoDescs[i], &pVirtqBuf); 1594 1593 if (RT_FAILURE(rc)) 1595 1594 LogRel(("Error fetching desc chain to redo, %Rrc", rc)); … … 1780 1779 1781 1780 /** 1782 * Resolves to boolean true if uOffset matches a field offset and size exactly,1783 * (or if 64-bit field, if it accesses either 32-bit part as a 32-bit access)1784 * Assumption is this critereon is mandated by VirtIO 1.0, Section 4.1.3.1)1785 * (Easily re-written to allow unaligned bounded access to a field).1786 *1787 * @param member - Member of VIRTIO_PCI_COMMON_CFG_T1788 * @result - true or false1789 */1790 #define MATCH_SCSI_CONFIG(member) \1791 ( ( RT_SIZEOFMEMB(VIRTIOSCSI_CONFIG_T, member) == 8 \1792 && ( offConfig == RT_UOFFSETOF(VIRTIOSCSI_CONFIG_T, member) \1793 || offConfig == RT_UOFFSETOF(VIRTIOSCSI_CONFIG_T, member) + sizeof(uint32_t)) \1794 && cb == sizeof(uint32_t)) \1795 || ( offConfig == RT_UOFFSETOF(VIRTIOSCSI_CONFIG_T, member) \1796 && cb == RT_SIZEOFMEMB(VIRTIOSCSI_CONFIG_T, member)) )1797 1798 #ifdef LOG_ENABLED1799 # define LOG_SCSI_CONFIG_ACCESSOR(member) \1800 virtioCoreLogMappedIoValue(__FUNCTION__, #member, RT_SIZEOFMEMB(VIRTIOSCSI_CONFIG_T, member), \1801 pv, cb, offIntra, fWrite, false, 0);1802 #else1803 # define LOG_SCSI_CONFIG_ACCESSOR(member) do { } while (0)1804 #endif1805 1806 #define SCSI_CONFIG_ACCESSOR(member) \1807 do \1808 { \1809 uint32_t offIntra = offConfig - RT_UOFFSETOF(VIRTIOSCSI_CONFIG_T, member); \1810 if (fWrite) \1811 memcpy((char *)&pThis->virtioScsiConfig.member + offIntra, pv, cb); \1812 else \1813 memcpy(pv, (const char *)&pThis->virtioScsiConfig.member + offIntra, cb); \1814 LOG_SCSI_CONFIG_ACCESSOR(member); \1815 } while(0)1816 1817 #define SCSI_CONFIG_ACCESSOR_READONLY(member) \1818 do \1819 { \1820 uint32_t offIntra = offConfig - RT_UOFFSETOF(VIRTIOSCSI_CONFIG_T, member); \1821 if (fWrite) \1822 LogFunc(("Guest attempted to write readonly virtio_pci_common_cfg.%s\n", #member)); \1823 else \1824 { \1825 memcpy(pv, (const char *)&pThis->virtioScsiConfig.member + offIntra, cb); \1826 LOG_SCSI_CONFIG_ACCESSOR(member); \1827 } \1828 } while(0)1829 1830 /**1831 1781 * Worker for virtioScsiR3DevCapWrite and virtioScsiR3DevCapRead. 1832 1782 */ 1833 static int virtioScsiR3CfgAccessed(PVIRTIOSCSI pThis, uint32_t offConfig, void *pv, uint32_t cb, bool fWrite)1783 static int virtioScsiR3CfgAccessed(PVIRTIOSCSI pThis, uint32_t uOffsetOfAccess, void *pv, uint32_t cb, bool fWrite) 1834 1784 { 1835 1785 AssertReturn(pv && cb <= sizeof(uint32_t), fWrite ? VINF_SUCCESS : VINF_IOM_MMIO_UNUSED_00); 1836 1786 1837 if ( MATCH_SCSI_CONFIG(uNumVirtqs))1838 SCSI_CONFIG_ACCESSOR_READONLY(uNumVirtqs);1787 if (VIRTIO_DEV_CONFIG_MATCH_MEMBER( uNumVirtqs, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess)) 1788 VIRTIO_DEV_CONFIG_ACCESS_READONLY( uNumVirtqs, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig); 1839 1789 else 1840 if ( MATCH_SCSI_CONFIG(uSegMax))1841 SCSI_CONFIG_ACCESSOR_READONLY(uSegMax);1790 if (VIRTIO_DEV_CONFIG_MATCH_MEMBER( uSegMax, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess)) 1791 VIRTIO_DEV_CONFIG_ACCESS_READONLY( uSegMax, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig); 1842 1792 else 1843 if ( MATCH_SCSI_CONFIG(uMaxSectors))1844 SCSI_CONFIG_ACCESSOR_READONLY(uMaxSectors);1793 if (VIRTIO_DEV_CONFIG_MATCH_MEMBER( uMaxSectors, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess)) 1794 VIRTIO_DEV_CONFIG_ACCESS_READONLY( uMaxSectors, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig); 1845 1795 else 1846 if ( MATCH_SCSI_CONFIG(uCmdPerLun))1847 SCSI_CONFIG_ACCESSOR_READONLY(uCmdPerLun);1796 if (VIRTIO_DEV_CONFIG_MATCH_MEMBER( uCmdPerLun, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess)) 1797 VIRTIO_DEV_CONFIG_ACCESS_READONLY( uCmdPerLun, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig); 1848 1798 else 1849 if ( MATCH_SCSI_CONFIG(uEventInfoSize))1850 SCSI_CONFIG_ACCESSOR_READONLY(uEventInfoSize);1799 if (VIRTIO_DEV_CONFIG_MATCH_MEMBER( uEventInfoSize, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess)) 1800 VIRTIO_DEV_CONFIG_ACCESS_READONLY( uEventInfoSize, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig); 1851 1801 else 1852 if ( MATCH_SCSI_CONFIG(uSenseSize))1853 SCSI_CONFIG_ACCESSOR(uSenseSize);1802 if (VIRTIO_DEV_CONFIG_MATCH_MEMBER( uSenseSize, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess)) 1803 VIRTIO_DEV_CONFIG_ACCESS( uSenseSize, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig); 1854 1804 else 1855 if ( MATCH_SCSI_CONFIG(uCdbSize))1856 SCSI_CONFIG_ACCESSOR(uCdbSize);1805 if (VIRTIO_DEV_CONFIG_MATCH_MEMBER( uCdbSize, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess)) 1806 VIRTIO_DEV_CONFIG_ACCESS( uCdbSize, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig); 1857 1807 else 1858 if ( MATCH_SCSI_CONFIG(uMaxChannel))1859 SCSI_CONFIG_ACCESSOR_READONLY(uMaxChannel);1808 if (VIRTIO_DEV_CONFIG_MATCH_MEMBER( uMaxChannel, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess)) 1809 VIRTIO_DEV_CONFIG_ACCESS_READONLY( uMaxChannel, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig); 1860 1810 else 1861 if ( MATCH_SCSI_CONFIG(uMaxTarget))1862 SCSI_CONFIG_ACCESSOR_READONLY(uMaxTarget);1811 if (VIRTIO_DEV_CONFIG_MATCH_MEMBER( uMaxTarget, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess)) 1812 VIRTIO_DEV_CONFIG_ACCESS_READONLY( uMaxTarget, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig); 1863 1813 else 1864 if ( MATCH_SCSI_CONFIG(uMaxLun))1865 SCSI_CONFIG_ACCESSOR_READONLY(uMaxLun);1814 if (VIRTIO_DEV_CONFIG_MATCH_MEMBER( uMaxLun, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess)) 1815 VIRTIO_DEV_CONFIG_ACCESS_READONLY( uMaxLun, VIRTIOSCSI_CONFIG_T, uOffsetOfAccess, &pThis->virtioScsiConfig); 1866 1816 else 1867 1817 { 1868 LogFunc(("Bad access by guest to virtio_scsi_config: off=%u (%#x), cb=%u\n", offConfig, offConfig, cb));1818 LogFunc(("Bad access by guest to virtio_scsi_config: off=%u (%#x), cb=%u\n", uOffsetOfAccess, uOffsetOfAccess, cb)); 1869 1819 return fWrite ? VINF_SUCCESS : VINF_IOM_MMIO_UNUSED_00; 1870 1820 } 1871 1821 return VINF_SUCCESS; 1872 1822 } 1873 1874 #undef SCSI_CONFIG_ACCESSOR_READONLY1875 #undef SCSI_CONFIG_ACCESSOR1876 #undef LOG_ACCESSOR1877 #undef MATCH_SCSI_CONFIG1878 1823 1879 1824 /** … … 2528 2473 for (uint16_t uVirtqNbr = 0; uVirtqNbr < VIRTIOSCSI_VIRTQ_CNT; uVirtqNbr++) 2529 2474 { 2530 rc = virtioCore R3VirtqAttach(&pThis->Virtio, uVirtqNbr, VIRTQNAME(uVirtqNbr));2475 rc = virtioCoreVirtqAttach(&pThis->Virtio, uVirtqNbr, VIRTQNAME(uVirtqNbr)); 2531 2476 if (RT_FAILURE(rc)) 2532 2477 continue;
Note:
See TracChangeset
for help on using the changeset viewer.