Changeset 100356 in vbox for trunk/src/VBox/Runtime/r0drv/linux
- Timestamp:
- Jul 4, 2023 6:41:38 AM (23 months ago)
- svn:sync-xref-src-repo-rev:
- 158086
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/linux/memobj-r0drv-linux.c
r100355 r100356 149 149 /** Pointer to the linux memory object. */ 150 150 typedef RTR0MEMOBJLNX *PRTR0MEMOBJLNX; 151 152 153 /*********************************************************************************************************************************154 * Global Variables *155 *********************************************************************************************************************************/156 /*157 * Linux allows only a coarse selection of zones for158 * allocations matching a particular maximum physical address.159 *160 * Sorted from high to low physical address!161 */162 static const struct163 {164 RTHCPHYS PhysHighest;165 gfp_t fGfp;166 } g_aZones[] =167 {168 { NIL_RTHCPHYS, GFP_KERNEL },169 #if (defined(RT_ARCH_AMD64) || defined(CONFIG_X86_PAE)) && defined(GFP_DMA32)170 { _4G - 1, GFP_DMA32 }, /* ZONE_DMA32: 0-4GB */171 #elif defined(RT_ARCH_ARM32) || defined(RT_ARCH_ARM64)172 { _4G - 1, GFP_DMA }, /* ZONE_DMA: 0-4GB */173 #endif174 #if defined(RT_ARCH_AMD64)175 { _16M - 1, GFP_DMA }, /* ZONE_DMA: 0-16MB */176 #elif defined(RT_ARCH_X86)177 { 896 * _1M - 1, GFP_USER }, /* ZONE_NORMAL (32-bit hosts): 0-896MB */178 #endif179 };180 151 181 152 … … 1001 972 1002 973 1003 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest, 1004 bool fExecutable, const char *pszTag) 974 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag) 1005 975 { 1006 976 IPRT_LINUX_SAVE_EFL_AC(); 1007 977 PRTR0MEMOBJLNX pMemLnx; 1008 978 int rc; 1009 uint32_t idxZone; 1010 1011 /* 1012 * The last zone must be able to satisfy the PhysHighest requirement or there 1013 * will be no zone at all. 1014 */ 1015 if (g_aZones[RT_ELEMENTS(g_aZones) - 1].PhysHighest > PhysHighest) 1016 { 1017 IPRT_LINUX_RESTORE_EFL_AC(); 1018 AssertMsgFailedReturn(("No zone can satisfy PhysHighest=%RHp!\n", PhysHighest), 1019 VERR_NO_CONT_MEMORY); 1020 } 1021 1022 /* Find the first zone matching our PhysHighest requirement. */ 1023 idxZone = 0; 1024 for (;;) 1025 { 1026 if (g_aZones[idxZone].PhysHighest <= PhysHighest) 1027 break; /* We found a zone satisfying the requirement. */ 1028 idxZone++; 1029 } 1030 1031 /* Now try to allocate pages from all the left zones until one succeeds. */ 1032 for (;;) 1033 { 1034 rc = rtR0MemObjLinuxAllocPages(&pMemLnx, RTR0MEMOBJTYPE_CONT, cb, PAGE_SIZE, g_aZones[idxZone].fGfp, 979 980 #if (defined(RT_ARCH_AMD64) || defined(RT_ARCH_ARM64) || defined(CONFIG_X86_PAE)) && defined(GFP_DMA32) 981 /* ZONE_DMA32: 0-4GB */ 982 rc = rtR0MemObjLinuxAllocPages(&pMemLnx, RTR0MEMOBJTYPE_CONT, cb, PAGE_SIZE, GFP_DMA32, 983 true /* contiguous */, fExecutable, VERR_NO_CONT_MEMORY, pszTag); 984 if (RT_FAILURE(rc)) 985 #endif 986 #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_ARM64) 987 /* ZONE_DMA: 0-16MB */ 988 rc = rtR0MemObjLinuxAllocPages(&pMemLnx, RTR0MEMOBJTYPE_CONT, cb, PAGE_SIZE, GFP_DMA, 1035 989 true /* contiguous */, fExecutable, VERR_NO_CONT_MEMORY, pszTag); 1036 idxZone++; 1037 if (RT_SUCCESS(rc) || idxZone == RT_ELEMENTS(g_aZones)) 1038 break; 1039 } 990 #else 991 /* ZONE_NORMAL (32-bit hosts): 0-896MB */ 992 rc = rtR0MemObjLinuxAllocPages(&pMemLnx, RTR0MEMOBJTYPE_CONT, cb, PAGE_SIZE, GFP_USER, 993 true /* contiguous */, fExecutable, VERR_NO_CONT_MEMORY, pszTag); 994 #endif 1040 995 if (RT_SUCCESS(rc)) 1041 996 { … … 1043 998 if (RT_SUCCESS(rc)) 1044 999 { 1045 #if defined(RT_STRICT) 1000 #if defined(RT_STRICT) && (defined(RT_ARCH_AMD64) || defined(CONFIG_HIGHMEM64G)) 1046 1001 size_t iPage = pMemLnx->cPages; 1047 1002 while (iPage-- > 0) 1048 Assert(page_to_phys(pMemLnx->apPages[iPage]) < PhysHighest);1003 Assert(page_to_phys(pMemLnx->apPages[iPage]) < _4G); 1049 1004 #endif 1050 1005 pMemLnx->Core.u.Cont.Phys = page_to_phys(pMemLnx->apPages[0]);
Note:
See TracChangeset
for help on using the changeset viewer.