Changeset 88818 in vbox for trunk/src/VBox/Devices/Bus
- Timestamp:
- May 3, 2021 10:19:31 AM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 144152
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Bus/DevIommuAmd.cpp
r88668 r88818 173 173 174 174 /** Acquires the cache lock. */ 175 #define IOMMU_ LOCK_CACHE(a_pDevIns, a_pThis) \175 #define IOMMU_CACHE_LOCK(a_pDevIns, a_pThis) \ 176 176 do { \ 177 int const rcLock = PDMDevHlpCritSectEnter((a_pDevIns), &(a_pThis)->CritSectCache, VERR_SEM_BUSY); \ 178 if (rcLock == VINF_SUCCESS) \ 179 { /* likely */ } \ 180 else \ 181 { \ 182 AssertRC(rcLock); \ 183 return rcLock; \ 184 } \ 185 } while (0) 186 187 /** Acquires the cache lock (asserts on failure). */ 188 # define IOMMU_LOCK_CACHE_NORET(a_pDevIns, a_pThis) \ 189 do { \ 190 int const rcLock = PDMDevHlpCritSectEnter((a_pDevIns), &(a_pThis)->CritSectCache, VERR_SEM_BUSY); \ 177 int const rcLock = PDMDevHlpCritSectEnter((a_pDevIns), &(a_pThis)->CritSectCache, VINF_SUCCESS); \ 191 178 AssertRC(rcLock); \ 192 179 } while (0) 193 180 194 181 /** Releases the cache lock. */ 195 # define IOMMU_ UNLOCK_CACHE(a_pDevIns, a_pThis) PDMDevHlpCritSectLeave((a_pDevIns), &(a_pThis)->CritSectCache)182 # define IOMMU_CACHE_UNLOCK(a_pDevIns, a_pThis) PDMDevHlpCritSectLeave((a_pDevIns), &(a_pThis)->CritSectCache) 196 183 #endif /* IOMMU_WITH_DTE_CACHE */ 197 184 … … 199 186 #define IOMMU_GET_PAGE_OFF_MASK(a_cShift) (~(UINT64_C(0xffffffffffffffff) << (a_cShift))) 200 187 201 /** Acquires the PDM lock . */202 #define IOMMU_LOCK (a_pDevIns, a_pThisCC, a_rcBusy) \188 /** Acquires the PDM lock (returns a_rcBusy on contention). */ 189 #define IOMMU_LOCK_RET(a_pDevIns, a_pThisCC, a_rcBusy) \ 203 190 do { \ 204 191 int const rcLock = (a_pThisCC)->CTX_SUFF(pIommuHlp)->pfnLock((a_pDevIns), (a_rcBusy)); \ … … 209 196 } while (0) 210 197 198 /** Acquires the PDM lock (shouldn't really fail). */ 199 #ifdef IN_RING3 200 # define IOMMU_LOCK(a_pDevIns, a_pThisCC) (a_pThisCC)->CTX_SUFF(pIommuHlp)->pfnLock((a_pDevIns), VERR_IGNORED) 201 #else 202 # define IOMMU_LOCK(a_pDevIns, a_pThisCC) \ 203 do { \ 204 int const rcLock = (a_pThisCC)->CTX_SUFF(pIommuHlp)->pfnLock((a_pDevIns), VINF_SUCCESS); \ 205 AssertRC(rcLock); \ 206 } while (0) 207 #endif 208 211 209 /** Checks if the current thread owns the PDM lock. */ 212 210 # define IOMMU_ASSERT_LOCK_IS_OWNER(a_pDevIns, a_pThisCC) \ … … 215 213 Assert((a_pThisCC)->CTX_SUFF(pIommuHlp)->pfnLockIsOwner((a_pDevIns))); \ 216 214 NOREF(a_pThisCC); \ 217 } while (0)218 219 /** Acquires the PDM lock (asserts on failure). */220 #define IOMMU_LOCK_NORET(a_pDevIns, a_pThisCC) \221 do { \222 int const rcLock = (a_pThisCC)->CTX_SUFF(pIommuHlp)->pfnLock((a_pDevIns), VERR_SEM_BUSY); \223 AssertRC(rcLock); \224 215 } while (0) 225 216 … … 954 945 955 946 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU); 956 IOMMU_ LOCK_CACHE_NORET(pDevIns, pThis);947 IOMMU_CACHE_LOCK(pDevIns, pThis); 957 948 958 949 uint16_t const cDteCache = RT_ELEMENTS(pThis->aDteCache); … … 972 963 rc = VERR_OUT_OF_RESOURCES; 973 964 974 IOMMU_ UNLOCK_CACHE(pDevIns, pThis);965 IOMMU_CACHE_UNLOCK(pDevIns, pThis); 975 966 return rc; 976 967 } … … 988 979 { 989 980 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU); 990 IOMMU_ LOCK_CACHE_NORET(pDevIns, pThis);981 IOMMU_CACHE_LOCK(pDevIns, pThis); 991 982 992 983 uint16_t const cDteCache = RT_ELEMENTS(pThis->aDteCache); … … 996 987 pThis->aDteCache[idxDte].fFlags |= fFlags; 997 988 998 IOMMU_ UNLOCK_CACHE(pDevIns, pThis);989 IOMMU_CACHE_UNLOCK(pDevIns, pThis); 999 990 } 1000 991 … … 1010 1001 { 1011 1002 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU); 1012 IOMMU_ LOCK_CACHE_NORET(pDevIns, pThis);1003 IOMMU_CACHE_LOCK(pDevIns, pThis); 1013 1004 1014 1005 uint16_t const cDteCache = RT_ELEMENTS(pThis->aDteCache); … … 1020 1011 } 1021 1012 1022 IOMMU_ UNLOCK_CACHE(pDevIns, pThis);1013 IOMMU_CACHE_UNLOCK(pDevIns, pThis); 1023 1014 } 1024 1015 … … 1032 1023 { 1033 1024 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU); 1034 IOMMU_ LOCK_CACHE_NORET(pDevIns, pThis);1025 IOMMU_CACHE_LOCK(pDevIns, pThis); 1035 1026 RT_ZERO(pThis->aDeviceIds); 1036 1027 RT_ZERO(pThis->aDteCache); 1037 IOMMU_ UNLOCK_CACHE(pDevIns, pThis);1028 IOMMU_CACHE_UNLOCK(pDevIns, pThis); 1038 1029 } 1039 1030 # endif /* IN_RING3 */ … … 1310 1301 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU); 1311 1302 PIOMMUR3 pThisR3 = PDMDEVINS_2_DATA_CC(pDevIns, PIOMMUR3); 1312 IOMMU_ LOCK_CACHE_NORET(pDevIns, pThis);1303 IOMMU_CACHE_LOCK(pDevIns, pThis); 1313 1304 1314 1305 if (pThisR3->cCachedIotlbes > 0) … … 1322 1313 } 1323 1314 1324 IOMMU_ UNLOCK_CACHE(pDevIns, pThis);1315 IOMMU_CACHE_UNLOCK(pDevIns, pThis); 1325 1316 } 1326 1317 … … 1344 1335 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU); 1345 1336 PIOMMUR3 pThisR3 = PDMDEVINS_2_DATA_CC(pDevIns, PIOMMUR3); 1346 IOMMU_ LOCK_CACHE_NORET(pDevIns, pThis);1337 IOMMU_CACHE_LOCK(pDevIns, pThis); 1347 1338 1348 1339 do … … 1356 1347 } while (cbInvalidate > 0); 1357 1348 1358 IOMMU_ UNLOCK_CACHE(pDevIns, pThis);1349 IOMMU_CACHE_UNLOCK(pDevIns, pThis); 1359 1350 } 1360 1351 … … 1376 1367 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU); 1377 1368 PIOMMUR3 pThisR3 = PDMDEVINS_2_DATA_CC(pDevIns, PIOMMUR3); 1378 IOMMU_ LOCK_CACHE_NORET(pDevIns, pThis);1369 IOMMU_CACHE_LOCK(pDevIns, pThis); 1379 1370 1380 1371 IOTLBEFLUSHARG Args; … … 1383 1374 RTAvlU64DoWithAll(&pThisR3->TreeIotlbe, true /* fFromLeft */, iommuAmdIotlbEntryRemoveDomainId, &Args); 1384 1375 1385 IOMMU_ UNLOCK_CACHE(pDevIns, pThis);1376 IOMMU_CACHE_UNLOCK(pDevIns, pThis); 1386 1377 } 1387 1378 … … 1418 1409 cPages = RT_MIN(cPages, IOMMU_IOTLBE_MAX); 1419 1410 1420 IOMMU_ LOCK_CACHE_NORET(pDevIns, pThis);1411 IOMMU_CACHE_LOCK(pDevIns, pThis); 1421 1412 /** @todo Re-check DTE cache? */ 1422 1413 do … … 1427 1418 --cPages; 1428 1419 } while (cPages > 0); 1429 IOMMU_ UNLOCK_CACHE(pDevIns, pThis);1420 IOMMU_CACHE_UNLOCK(pDevIns, pThis); 1430 1421 } 1431 1422 #endif /* IOMMU_WITH_IOTLBE_CACHE */ … … 1497 1488 1498 1489 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU); 1499 IOMMU_ LOCK_CACHE_NORET(pDevIns, pThis);1490 IOMMU_CACHE_LOCK(pDevIns, pThis); 1500 1491 1501 1492 uint16_t const idxDteCache = iommuAmdDteCacheEntryLookup(pThis, idDevice); … … 1542 1533 } 1543 1534 1544 IOMMU_ UNLOCK_CACHE(pDevIns, pThis);1535 IOMMU_CACHE_UNLOCK(pDevIns, pThis); 1545 1536 return rc; 1546 1537 } … … 1564 1555 int rc = VINF_SUCCESS; 1565 1556 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU); 1566 IOMMU_ LOCK_CACHE_NORET(pDevIns, pThis);1557 IOMMU_CACHE_LOCK(pDevIns, pThis); 1567 1558 1568 1559 /* Find an existing entry or get an unused slot. */ … … 1578 1569 rc = VERR_OUT_OF_RESOURCES; 1579 1570 1580 IOMMU_ UNLOCK_CACHE(pDevIns, pThis);1571 IOMMU_CACHE_UNLOCK(pDevIns, pThis); 1581 1572 return rc; 1582 1573 } … … 1593 1584 { 1594 1585 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU); 1595 IOMMU_ LOCK_CACHE_NORET(pDevIns, pThis);1586 IOMMU_CACHE_LOCK(pDevIns, pThis); 1596 1587 uint16_t const cIrteCache = RT_ELEMENTS(pThis->aIrteCache); 1597 1588 for (uint16_t i = 0; i < cIrteCache; i++) … … 1605 1596 } 1606 1597 } 1607 IOMMU_ UNLOCK_CACHE(pDevIns, pThis);1598 IOMMU_CACHE_UNLOCK(pDevIns, pThis); 1608 1599 } 1609 1600 … … 1617 1608 { 1618 1609 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU); 1619 IOMMU_ LOCK_CACHE_NORET(pDevIns, pThis);1610 IOMMU_CACHE_LOCK(pDevIns, pThis); 1620 1611 uint16_t const cIrteCache = RT_ELEMENTS(pThis->aIrteCache); 1621 1612 for (uint16_t i = 0; i < cIrteCache; i++) … … 1624 1615 pThis->aIrteCache[i].Irte.u32 = 0; 1625 1616 } 1626 IOMMU_ UNLOCK_CACHE(pDevIns, pThis);1617 IOMMU_CACHE_UNLOCK(pDevIns, pThis); 1627 1618 } 1628 1619 # endif /* IN_RING3 */ … … 2745 2736 if (!(off & 7)) 2746 2737 { 2747 IOMMU_LOCK (pDevIns, pThisCC, VINF_IOM_R3_MMIO_WRITE);2738 IOMMU_LOCK_RET(pDevIns, pThisCC, VINF_IOM_R3_MMIO_WRITE); 2748 2739 VBOXSTRICTRC rcStrict = pReg->pfnWrite(pDevIns, pThis, off, uValue); 2749 2740 IOMMU_UNLOCK(pDevIns, pThisCC); … … 2760 2751 { 2761 2752 VBOXSTRICTRC rcStrict; 2762 IOMMU_LOCK (pDevIns, pThisCC, VINF_IOM_R3_MMIO_WRITE);2753 IOMMU_LOCK_RET(pDevIns, pThisCC, VINF_IOM_R3_MMIO_WRITE); 2763 2754 2764 2755 /* … … 2871 2862 if (!(off & 7)) 2872 2863 { 2873 IOMMU_LOCK (pDevIns, pThisCC, VINF_IOM_R3_MMIO_READ);2864 IOMMU_LOCK_RET(pDevIns, pThisCC, VINF_IOM_R3_MMIO_READ); 2874 2865 VBOXSTRICTRC rcStrict = pReg->pfnRead(pDevIns, pThis, off, puResult); 2875 2866 IOMMU_UNLOCK(pDevIns, pThisCC); … … 2884 2875 Assert(off & 7); 2885 2876 Assert(off >= 4); 2886 IOMMU_LOCK (pDevIns, pThisCC, VINF_IOM_R3_MMIO_READ);2877 IOMMU_LOCK_RET(pDevIns, pThisCC, VINF_IOM_R3_MMIO_READ); 2887 2878 VBOXSTRICTRC rcStrict = pReg->pfnRead(pDevIns, pThis, off - 4, puResult); 2888 2879 IOMMU_UNLOCK(pDevIns, pThisCC); … … 2948 2939 PIOMMUCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PIOMMUCC); 2949 2940 2950 IOMMU_LOCK _NORET(pDevIns, pThisCC);2941 IOMMU_LOCK(pDevIns, pThisCC); 2951 2942 2952 2943 /* Check if event logging is active and the log has not overflowed. */ … … 3067 3058 3068 3059 PIOMMUCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PIOMMUCC); 3069 IOMMU_LOCK _NORET(pDevIns, pThisCC);3060 IOMMU_LOCK(pDevIns, pThisCC); 3070 3061 3071 3062 iommuAmdHwErrorSet(pDevIns, (PCEVT_GENERIC_T)pEvent); … … 3113 3104 3114 3105 PIOMMUCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PIOMMUCC); 3115 IOMMU_LOCK _NORET(pDevIns, pThisCC);3106 IOMMU_LOCK(pDevIns, pThisCC); 3116 3107 3117 3108 iommuAmdHwErrorSet(pDevIns, (PCEVT_GENERIC_T)pEvent); … … 3165 3156 3166 3157 PIOMMUCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PIOMMUCC); 3167 IOMMU_LOCK _NORET(pDevIns, pThisCC);3158 IOMMU_LOCK(pDevIns, pThisCC); 3168 3159 3169 3160 iommuAmdHwErrorSet(pDevIns, (PCEVT_GENERIC_T)pEvent); … … 3484 3475 PIOMMUCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PIOMMUCC); 3485 3476 3486 IOMMU_LOCK(pDevIns, pThisCC , VERR_SEM_BUSY);3477 IOMMU_LOCK(pDevIns, pThisCC); 3487 3478 3488 3479 /* Figure out which device table segment is being accessed. */ … … 4168 4159 * we don't want the DTE cache to be invalidate while we perform IOTBL lookups. 4169 4160 */ 4170 IOMMU_ LOCK_CACHE(pDevIns, pThis);4161 IOMMU_CACHE_LOCK(pDevIns, pThis); 4171 4162 4172 4163 /* Lookup the DTE cache entry. */ … … 4224 4215 IOMMU_IOTLB_LOOKUP_FAILED(VERR_NOT_FOUND); 4225 4216 4226 IOMMU_ UNLOCK_CACHE(pDevIns, pThis);4217 IOMMU_CACHE_UNLOCK(pDevIns, pThis); 4227 4218 4228 4219 return rc; … … 4878 4869 if (pCmdComWait->n.u1Interrupt) 4879 4870 { 4880 IOMMU_LOCK(pDevIns, pThisR3 , VERR_IGNORED);4871 IOMMU_LOCK(pDevIns, pThisR3); 4881 4872 ASMAtomicOrU64(&pThis->Status.u64, IOMMU_STATUS_COMPLETION_WAIT_INTR); 4882 4873 bool const fRaiseInt = pThis->Ctrl.n.u1CompWaitIntrEn; … … 5108 5099 * save on host memory a bit, we could (once PGM has the necessary APIs) 5109 5100 * lock the page mappings page mappings and access them directly. */ 5110 IOMMU_LOCK(pDevIns, pThisR3 , VERR_IGNORED);5101 IOMMU_LOCK(pDevIns, pThisR3); 5111 5102 5112 5103 if (pThis->Status.n.u1CmdBufRunning) … … 5129 5120 IOMMU_UNLOCK(pDevIns, pThisR3); 5130 5121 int rc = PDMDevHlpPCIPhysRead(pDevIns, GCPhysCmdBufBase, pvCmds, cbCmdBuf); 5131 IOMMU_LOCK(pDevIns, pThisR3 , VERR_IGNORED);5122 IOMMU_LOCK(pDevIns, pThisR3); 5132 5123 5133 5124 if (RT_SUCCESS(rc)) … … 5292 5283 5293 5284 PIOMMUR3 pThisR3 = PDMDEVINS_2_DATA_CC(pDevIns, PIOMMUR3); 5294 IOMMU_LOCK(pDevIns, pThisR3 , VERR_IGNORED);5285 IOMMU_LOCK(pDevIns, pThisR3); 5295 5286 5296 5287 VBOXSTRICTRC rcStrict; … … 6024 6015 RT_NOREF(pszArgs); 6025 6016 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU); 6026 IOMMU_ LOCK_CACHE_NORET(pDevIns, pThis);6017 IOMMU_CACHE_LOCK(pDevIns, pThis); 6027 6018 6028 6019 uint16_t const cDteCache = RT_ELEMENTS(pThis->aDeviceIds); … … 6044 6035 } 6045 6036 } 6046 IOMMU_ UNLOCK_CACHE(pDevIns, pThis);6037 IOMMU_CACHE_UNLOCK(pDevIns, pThis); 6047 6038 } 6048 6039 # endif /* IOMMU_WITH_DTE_CACHE */ … … 6069 6060 Args.idDomain = idDomain; 6070 6061 6071 IOMMU_ LOCK_CACHE_NORET(pDevIns, pThis);6062 IOMMU_CACHE_LOCK(pDevIns, pThis); 6072 6063 RTAvlU64DoWithAll(&pThisR3->TreeIotlbe, true /* fFromLeft */, iommuAmdR3IotlbEntryInfo, &Args); 6073 IOMMU_ UNLOCK_CACHE(pDevIns, pThis);6064 IOMMU_CACHE_UNLOCK(pDevIns, pThis); 6074 6065 } 6075 6066 else … … 6108 6099 6109 6100 PIOMMU pThis = PDMDEVINS_2_DATA(pDevIns, PIOMMU); 6110 IOMMU_ LOCK_CACHE_NORET(pDevIns, pThis);6101 IOMMU_CACHE_LOCK(pDevIns, pThis); 6111 6102 6112 6103 uint16_t const cIrteCache = RT_ELEMENTS(pThis->aIrteCache); … … 6138 6129 } 6139 6130 } 6140 IOMMU_ UNLOCK_CACHE(pDevIns, pThis);6131 IOMMU_CACHE_UNLOCK(pDevIns, pThis); 6141 6132 } 6142 6133 # endif /* IOMMU_WITH_IRTE_CACHE */ … … 6636 6627 6637 6628 int rc; 6638 IOMMU_LOCK(pDevIns, pThisR3 , VERR_IGNORED);6629 IOMMU_LOCK(pDevIns, pThisR3); 6639 6630 6640 6631 /* Map MMIO regions if the IOMMU BAR is enabled. */ … … 6675 6666 LogFlowFunc(("\n")); 6676 6667 6677 IOMMU_LOCK _NORET(pDevIns, pThisR3);6668 IOMMU_LOCK(pDevIns, pThisR3); 6678 6669 6679 6670 RT_ZERO(pThis->aDevTabBaseAddrs); … … 6770 6761 LogFlowFunc(("\n")); 6771 6762 6772 IOMMU_LOCK _NORET(pDevIns, pThisR3);6763 IOMMU_LOCK(pDevIns, pThisR3); 6773 6764 6774 6765 if (pThis->hEvtCmdThread != NIL_SUPSEMEVENT)
Note:
See TracChangeset
for help on using the changeset viewer.