Changeset 82876 in vbox
- Timestamp:
- Jan 27, 2020 1:38:45 PM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 135853
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/VBox/VMM/VMMR0/GMMR0.cpp ¶
r82866 r82876 107 107 * by the VM that locked it. We will make no attempt at implementing 108 108 * page sharing on these systems, just do enough to make it all work. 109 * 110 * @note With 6.1 really dropping 32-bit support, the legacy mode is obsoleted 111 * under the assumption that there is sufficient kernel virtual address 112 * space to map all of the guest memory allocations. So, we'll be using 113 * #RTR0MemObjAllocPage on some platforms as an alternative to 114 * #RTR0MemObjAllocPhysNC. 109 115 * 110 116 * … … 186 192 # define VBOX_USE_CRIT_SECT_FOR_GIANT 187 193 #endif 194 195 /** Enable the legacy mode code (will be dropped soon). */ 196 #define GMM_WITH_LEGACY_MODE 188 197 189 198 … … 450 459 /** Indicates that the chunk is a large page (2MB). */ 451 460 #define GMM_CHUNK_FLAGS_LARGE_PAGE UINT16_C(0x0001) 461 #ifdef GMM_WITH_LEGACY_MODE 452 462 /** Indicates that the chunk was locked rather than allocated directly. */ 453 #define GMM_CHUNK_FLAGS_SEEDED UINT16_C(0x0002) 463 # define GMM_CHUNK_FLAGS_SEEDED UINT16_C(0x0002) 464 #endif 454 465 /** @} */ 455 466 … … 550 561 uint64_t cBalloonedPages; 551 562 563 #ifndef GMM_WITH_LEGACY_MODE 564 # ifdef VBOX_WITH_LINEAR_HOST_PHYS_MEM 565 /** Whether #RTR0MemObjAllocPhysNC works. */ 566 bool fHasWorkingAllocPhysNC; 567 # else 568 bool fPadding; 569 # endif 570 #else 552 571 /** The legacy allocation mode indicator. 553 572 * This is determined at initialization time. */ 554 573 bool fLegacyAllocationMode; 574 #endif 555 575 /** The bound memory mode indicator. 556 576 * When set, the memory will be bound to a specific VM and never … … 799 819 if (RT_SUCCESS(rc)) 800 820 { 821 #ifndef GMM_WITH_LEGACY_MODE 822 /* 823 * Figure out how we're going to allocate stuff (only applicable to 824 * host with linear physical memory mappings). 825 */ 826 pGMM->fBoundMemoryMode = false; 827 # ifdef VBOX_WITH_LINEAR_HOST_PHYS_MEM 828 pGMM->fHasWorkingAllocPhysNC = false; 829 830 RTR0MEMOBJ hMemObj; 831 rc = RTR0MemObjAllocPhysNC(&hMemObj, GMM_CHUNK_SIZE, NIL_RTHCPHYS); 832 if (RT_SUCCESS(rc)) 833 { 834 rc = RTR0MemObjFree(hMemObj, true); 835 AssertRC(rc); 836 pGMM->fHasWorkingAllocPhysNC = true; 837 } 838 else if (rc != VERR_NOT_SUPPORTED) 839 SUPR0Printf("GMMR0Init: Warning! RTR0MemObjAllocPhysNC(, %u, NIL_RTHCPHYS) -> %d!\n", GMM_CHUNK_SIZE, rc); 840 # endif 841 #else /* GMM_WITH_LEGACY_MODE */ 801 842 /* 802 843 * Check and see if RTR0MemObjAllocPhysNC works. 803 844 */ 804 # if 0 /* later, see @bufref{3170}. */845 # if 0 /* later, see @bufref{3170}. */ 805 846 RTR0MEMOBJ MemObj; 806 847 rc = RTR0MemObjAllocPhysNC(&MemObj, _64K, NIL_RTHCPHYS); … … 814 855 else 815 856 SUPR0Printf("GMMR0Init: RTR0MemObjAllocPhysNC(,64K,Any) -> %d!\n", rc); 816 # else817 # if defined(RT_OS_WINDOWS) || (defined(RT_OS_SOLARIS) && ARCH_BITS == 64) || defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)857 # else 858 # if defined(RT_OS_WINDOWS) || (defined(RT_OS_SOLARIS) && ARCH_BITS == 64) || defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) 818 859 pGMM->fLegacyAllocationMode = false; 819 # if ARCH_BITS == 32860 # if ARCH_BITS == 32 820 861 /* Don't reuse possibly partial chunks because of the virtual 821 862 address space limitation. */ 822 863 pGMM->fBoundMemoryMode = true; 864 # else 865 pGMM->fBoundMemoryMode = false; 866 # endif 823 867 # else 824 pGMM->fBoundMemoryMode = false;825 # endif826 # else827 868 pGMM->fLegacyAllocationMode = true; 828 869 pGMM->fBoundMemoryMode = true; 870 # endif 829 871 # endif 830 #endif 872 #endif /* GMM_WITH_LEGACY_MODE */ 831 873 832 874 /* … … 836 878 837 879 g_pGMM = pGMM; 880 #ifdef GMM_WITH_LEGACY_MODE 838 881 LogFlow(("GMMInit: pGMM=%p fLegacyAllocationMode=%RTbool fBoundMemoryMode=%RTbool\n", pGMM, pGMM->fLegacyAllocationMode, pGMM->fBoundMemoryMode)); 882 #elif defined(VBOX_WITH_LINEAR_HOST_PHYS_MEM) 883 LogFlow(("GMMInit: pGMM=%p fBoundMemoryMode=%RTbool fHasWorkingAllocPhysNC=%RTbool\n", pGMM, pGMM->fBoundMemoryMode, pGMM->fHasWorkingAllocPhysNC)); 884 #else 885 LogFlow(("GMMInit: pGMM=%p fBoundMemoryMode=%RTbool\n", pGMM, pGMM->fBoundMemoryMode)); 886 #endif 839 887 return VINF_SUCCESS; 840 888 } … … 2133 2181 Assert(pGMM->hMtxOwner != RTThreadNativeSelf()); 2134 2182 Assert(hGVM != NIL_GVM_HANDLE || pGMM->fBoundMemoryMode); 2183 #ifdef GMM_WITH_LEGACY_MODE 2135 2184 Assert(fChunkFlags == 0 || fChunkFlags == GMM_CHUNK_FLAGS_LARGE_PAGE || fChunkFlags == GMM_CHUNK_FLAGS_SEEDED); 2185 #else 2186 Assert(fChunkFlags == 0 || fChunkFlags == GMM_CHUNK_FLAGS_LARGE_PAGE); 2187 #endif 2136 2188 2137 2189 #if defined(VBOX_WITH_RAM_IN_KERNEL) && !defined(VBOX_WITH_LINEAR_HOST_PHYS_MEM) … … 2139 2191 * Get a ring-0 mapping of the object. 2140 2192 */ 2193 # ifdef GMM_WITH_LEGACY_MODE 2141 2194 uint8_t *pbMapping = !(fChunkFlags & GMM_CHUNK_FLAGS_SEEDED) ? (uint8_t *)RTR0MemObjAddress(hMemObj) : NULL; 2195 # else 2196 uint8_t *pbMapping = (uint8_t *)RTR0MemObjAddress(hMemObj); 2197 # endif 2142 2198 if (!pbMapping) 2143 2199 { … … 2242 2298 2243 2299 RTR0MEMOBJ hMemObj; 2300 #ifndef GMM_WITH_LEGACY_MODE 2301 int rc; 2302 # ifdef VBOX_WITH_LINEAR_HOST_PHYS_MEM 2303 if (pGMM->fHasWorkingAllocPhysNC) 2304 rc = RTR0MemObjAllocPhysNC(&hMemObj, GMM_CHUNK_SIZE, NIL_RTHCPHYS); 2305 else 2306 # endif 2307 rc = RTR0MemObjAllocPage(&hMemObj, GMM_CHUNK_SIZE, false /*fExecutable*/); 2308 #else 2244 2309 int rc = RTR0MemObjAllocPhysNC(&hMemObj, GMM_CHUNK_SIZE, NIL_RTHCPHYS); 2310 #endif 2245 2311 if (RT_SUCCESS(rc)) 2246 2312 { … … 2574 2640 } 2575 2641 2642 #ifdef GMM_WITH_LEGACY_MODE 2576 2643 /* 2577 2644 * If we're in legacy memory mode, it's easy to figure if we have … … 2584 2651 return VERR_GMM_SEED_ME; 2585 2652 } 2653 #endif 2586 2654 2587 2655 /* … … 2600 2668 pGMM->cAllocatedPages += cPages; 2601 2669 2670 #ifdef GMM_WITH_LEGACY_MODE 2602 2671 /* 2603 2672 * Part two of it's-easy-in-legacy-memory-mode. 2604 2673 */ 2605 uint32_t iPage = 0;2606 2674 if (pGMM->fLegacyAllocationMode) 2607 2675 { 2608 iPage = gmmR0AllocatePagesInBoundMode(pGVM, iPage, cPages, paPages);2676 uint32_t iPage = gmmR0AllocatePagesInBoundMode(pGVM, 0, cPages, paPages); 2609 2677 AssertReleaseReturn(iPage == cPages, VERR_GMM_ALLOC_PAGES_IPE); 2610 2678 return VINF_SUCCESS; 2611 2679 } 2680 #endif 2612 2681 2613 2682 /* 2614 2683 * Bound mode is also relatively straightforward. 2615 2684 */ 2685 uint32_t iPage = 0; 2616 2686 int rc = VINF_SUCCESS; 2617 2687 if (pGMM->fBoundMemoryMode) … … 3069 3139 return rc; 3070 3140 3141 #ifdef GMM_WITH_LEGACY_MODE 3071 3142 // /* Not supported in legacy mode where we allocate the memory in ring 3 and lock it in ring 0. */ 3072 3143 // if (pGMM->fLegacyAllocationMode) 3073 3144 // return VERR_NOT_SUPPORTED; 3145 #endif 3074 3146 3075 3147 *pHCPhys = NIL_RTHCPHYS; … … 3170 3242 return rc; 3171 3243 3244 #ifdef GMM_WITH_LEGACY_MODE 3172 3245 // /* Not supported in legacy mode where we allocate the memory in ring 3 and lock it in ring 0. */ 3173 3246 // if (pGMM->fLegacyAllocationMode) 3174 3247 // return VERR_NOT_SUPPORTED; 3248 #endif 3175 3249 3176 3250 gmmR0MutexAcquire(pGMM); … … 3259 3333 */ 3260 3334 if ( pChunk->cMappingsX 3335 #ifdef GMM_WITH_LEGACY_MODE 3261 3336 && (!pGMM->fLegacyAllocationMode || (pChunk->fFlags & GMM_CHUNK_FLAGS_LARGE_PAGE)) 3337 #endif 3262 3338 && pGVM) 3263 3339 gmmR0UnmapChunkLocked(pGMM, pGVM, pChunk); … … 3387 3463 */ 3388 3464 /** @todo Do this on the way out. */ 3389 if (RT_UNLIKELY( pChunk->cFree == GMM_CHUNK_NUM_PAGES 3390 && pChunk->pFreeNext 3391 && pChunk->pFreePrev /** @todo this is probably misfiring, see reset... */ 3392 && (!pGMM->fLegacyAllocationMode || (pChunk->fFlags & GMM_CHUNK_FLAGS_LARGE_PAGE)))) 3465 if (RT_LIKELY( pChunk->cFree != GMM_CHUNK_NUM_PAGES 3466 || pChunk->pFreeNext == NULL 3467 || pChunk->pFreePrev == NULL /** @todo this is probably misfiring, see reset... */)) 3468 { /* likely */ } 3469 #ifdef GMM_WITH_LEGACY_MODE 3470 else if (RT_LIKELY(pGMM->fLegacyAllocationMode && !(pChunk->fFlags & GMM_CHUNK_FLAGS_LARGE_PAGE))) 3471 { /* likely */ } 3472 #endif 3473 else 3393 3474 gmmR0FreeChunk(pGMM, NULL, pChunk, false); 3394 3475 … … 3913 3994 static int gmmR0UnmapChunkLocked(PGMM pGMM, PGVM pGVM, PGMMCHUNK pChunk) 3914 3995 { 3915 Assert(!pGMM->fLegacyAllocationMode || (pChunk->fFlags & GMM_CHUNK_FLAGS_LARGE_PAGE)); NOREF(pGMM); 3996 RT_NOREF_PV(pGMM); 3997 #ifdef GMM_WITH_LEGACY_MODE 3998 Assert(!pGMM->fLegacyAllocationMode || (pChunk->fFlags & GMM_CHUNK_FLAGS_LARGE_PAGE)); 3999 #endif 3916 4000 3917 4001 /* … … 3959 4043 static int gmmR0UnmapChunk(PGMM pGMM, PGVM pGVM, PGMMCHUNK pChunk, bool fRelaxedSem) 3960 4044 { 4045 #ifdef GMM_WITH_LEGACY_MODE 3961 4046 if (!pGMM->fLegacyAllocationMode || (pChunk->fFlags & GMM_CHUNK_FLAGS_LARGE_PAGE)) 3962 4047 { 4048 #endif 3963 4049 /* 3964 4050 * Lock the chunk and if possible leave the giant GMM lock. … … 3973 4059 } 3974 4060 return rc; 4061 #ifdef GMM_WITH_LEGACY_MODE 3975 4062 } 3976 4063 … … 3980 4067 Log(("gmmR0UnmapChunk: Chunk %#x is not mapped into pGVM=%p/%#x (legacy)\n", pChunk->Core.Key, pGVM, pGVM->hSelf)); 3981 4068 return VERR_GMM_CHUNK_NOT_MAPPED; 4069 #endif 3982 4070 } 3983 4071 … … 3996 4084 static int gmmR0MapChunkLocked(PGMM pGMM, PGVM pGVM, PGMMCHUNK pChunk, PRTR3PTR ppvR3) 3997 4085 { 4086 #ifdef GMM_WITH_LEGACY_MODE 3998 4087 /* 3999 4088 * If we're in legacy mode this is simple. … … 4010 4099 return VINF_SUCCESS; 4011 4100 } 4101 #else 4102 RT_NOREF(pGMM); 4103 #endif 4012 4104 4013 4105 /* … … 4266 4358 GMMR0DECL(int) GMMR0SeedChunk(PGVM pGVM, VMCPUID idCpu, RTR3PTR pvR3) 4267 4359 { 4360 #ifdef GMM_WITH_LEGACY_MODE 4268 4361 /* 4269 4362 * Validate input and get the basics. … … 4301 4394 LogFlow(("GMMR0SeedChunk: rc=%d (pvR3=%p)\n", rc, pvR3)); 4302 4395 return rc; 4396 #else 4397 RT_NOREF(pGVM, idCpu, pvR3); 4398 return VERR_NOT_SUPPORTED; 4399 #endif 4303 4400 } 4304 4401
Note:
See TracChangeset
for help on using the changeset viewer.