VirtualBox

Changeset 100356 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Jul 4, 2023 6:41:38 AM (17 months ago)
Author:
vboxsync
Message:

Runtime/RTR0MemObj*: Add PhysHighest parameter to RTR0MemObjAllocCont to indicate the maximum allowed physical address for an allocation, bugref:10457 [revert due to build failures]

Location:
trunk/src/VBox/Runtime
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/include/internal/memobj.h

    r100355 r100356  
    361361 * @param   ppMem           Where to store the ring-0 memory object handle.
    362362 * @param   cb              Number of bytes to allocate, page aligned.
    363  * @param   PhysHighest     The highest permitable address (inclusive).
    364  *                          Pass NIL_RTHCPHYS if any address is acceptable.
    365363 * @param   fExecutable     Flag indicating whether it should be permitted to executed code in the memory object.
    366364 * @param   pszTag          Allocation tag used for statistics and such.
    367365 */
    368 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest,
    369                                           bool fExecutable, const char *pszTag);
     366DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag);
    370367
    371368/**
  • trunk/src/VBox/Runtime/r0drv/darwin/memobj-r0drv-darwin.cpp

    r100355 r100356  
    885885
    886886
    887 /**
    888  * Translates the PhysHighest address into a mask.
    889  */
    890 static mach_vm_address_t rtR0MemObjDarwinCalcPhysMask(RTHCPHYS PhysHighest, size_t uAlignment)
    891 {
    892     if (PhysHighest == NIL_RTHCPHYS)
    893         return uAlignment <= PAGE_SIZE ? 0 : ~(mach_vm_address_t)(uAlignment - 1);
    894 
    895     mach_vm_address_t PhysMask = ~(mach_vm_address_t)0;
    896     while (PhysMask > (PhysHighest | PAGE_OFFSET_MASK))
    897         PhysMask >>= 1;
    898     PhysMask &= ~(mach_vm_address_t)(uAlignment - 1);
    899 
    900     return PhysMask;
    901 }
    902 
    903 
    904 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest,
    905                                           bool fExecutable, const char *pszTag)
    906 {
    907     mach_vm_address_t const PhysMask = rtR0MemObjDarwinCalcPhysMask(PhysHighest, PAGE_SIZE);
     887DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag)
     888{
    908889    IPRT_DARWIN_SAVE_EFL_AC();
    909890
    910     int rc = rtR0MemObjNativeAllocWorker(ppMem, cb, fExecutable, true /* fContiguous */, PhysMask, PhysHighest,
     891    int rc = rtR0MemObjNativeAllocWorker(ppMem, cb, fExecutable, true /* fContiguous */,
     892                                         ~(uint32_t)PAGE_OFFSET_MASK, _4G - PAGE_SIZE,
    911893                                         RTR0MEMOBJTYPE_CONT, PAGE_SIZE, pszTag, false /*fOnKernelThread*/);
    912894
     
    916898     */
    917899    if (RT_FAILURE(rc) && cb <= PAGE_SIZE)
    918         rc = rtR0MemObjNativeAllocWorker(ppMem, cb + PAGE_SIZE, fExecutable, true /* fContiguous */, PhysMask, PhysHighest,
     900        rc = rtR0MemObjNativeAllocWorker(ppMem, cb + PAGE_SIZE, fExecutable, true /* fContiguous */,
     901                                         ~(uint32_t)PAGE_OFFSET_MASK, _4G - PAGE_SIZE,
    919902                                         RTR0MEMOBJTYPE_CONT, PAGE_SIZE, pszTag, false /*fOnKernelThread*/);
    920903    IPRT_DARWIN_RESTORE_EFL_AC();
     
    932915            return VERR_NOT_SUPPORTED;
    933916    }
    934     mach_vm_address_t const PhysMask = rtR0MemObjDarwinCalcPhysMask(PhysHighest, uAlignment);
    935917
    936918    IPRT_DARWIN_SAVE_EFL_AC();
     
    941923    int rc;
    942924    if (PhysHighest == NIL_RTHCPHYS)
    943         rc = rtR0MemObjNativeAllocWorker(ppMem, cb, false /* fExecutable */, true /* fContiguous */, PhysMask, UINT64_MAX,
    944                                          RTR0MEMOBJTYPE_PHYS, uAlignment, pszTag, false /*fOnKernelThread*/);
     925        rc = rtR0MemObjNativeAllocWorker(ppMem, cb, false /* fExecutable */, true /* fContiguous */,
     926                                         uAlignment <= PAGE_SIZE ? 0 : ~(mach_vm_address_t)(uAlignment - 1) /* PhysMask*/,
     927                                         UINT64_MAX, RTR0MEMOBJTYPE_PHYS, uAlignment, pszTag, false /*fOnKernelThread*/);
    945928    else
    946929    {
     930        mach_vm_address_t PhysMask = 0;
     931        PhysMask = ~(mach_vm_address_t)0;
     932        while (PhysMask > (PhysHighest | PAGE_OFFSET_MASK))
     933            PhysMask >>= 1;
    947934        AssertReturn(PhysMask + 1 <= cb, VERR_INVALID_PARAMETER);
    948         rc = rtR0MemObjNativeAllocWorker(ppMem, cb, false /* fExecutable */, true /* fContiguous */, PhysMask, PhysHighest,
     935        PhysMask &= ~(mach_vm_address_t)(uAlignment - 1);
     936
     937        rc = rtR0MemObjNativeAllocWorker(ppMem, cb, false /* fExecutable */, true /* fContiguous */,
     938                                         PhysMask, PhysHighest,
    949939                                         RTR0MEMOBJTYPE_PHYS, uAlignment, pszTag, false /*fOnKernelThread*/);
    950940    }
  • trunk/src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c

    r100355 r100356  
    410410
    411411
    412 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHigest,
    413                                           bool fExecutable, const char *pszTag)
     412DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag)
    414413{
    415414    PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_CONT,
     
    417416    if (pMemFreeBSD)
    418417    {
    419         int rc = rtR0MemObjFreeBSDAllocHelper(pMemFreeBSD, fExecutable, PhysHigest, true /*fContiguous*/, VERR_NO_CONT_MEMORY);
     418        int rc = rtR0MemObjFreeBSDAllocHelper(pMemFreeBSD, fExecutable, _4G - 1, true /*fContiguous*/, VERR_NO_CONT_MEMORY);
    420419        if (RT_SUCCESS(rc))
    421420        {
  • trunk/src/VBox/Runtime/r0drv/haiku/memobj-r0drv-haiku.c

    r100355 r100356  
    277277
    278278
    279 int rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest, bool fExecutable, const char *pszTag)
    280 {
    281     return rtR0MemObjNativeAllocArea(ppMem, cb, fExecutable, RTR0MEMOBJTYPE_CONT, PhysHighest, 0 /* uAlignment */, pszTag);
     279int rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag)
     280{
     281    return rtR0MemObjNativeAllocArea(ppMem, cb, fExecutable, RTR0MEMOBJTYPE_CONT, 0 /* PhysHighest */, 0 /* uAlignment */, pszTag);
    282282}
    283283
  • trunk/src/VBox/Runtime/r0drv/linux/memobj-r0drv-linux.c

    r100355 r100356  
    149149/** Pointer to the linux memory object. */
    150150typedef RTR0MEMOBJLNX *PRTR0MEMOBJLNX;
    151 
    152 
    153 /*********************************************************************************************************************************
    154 *   Global Variables                                                                                                             *
    155 *********************************************************************************************************************************/
    156 /*
    157  * Linux allows only a coarse selection of zones for
    158  * allocations matching a particular maximum physical address.
    159  *
    160  * Sorted from high to low physical address!
    161  */
    162 static const struct
    163 {
    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 #endif
    174 #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 #endif
    179 };
    180151
    181152
     
    1001972
    1002973
    1003 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest,
    1004                                           bool fExecutable, const char *pszTag)
     974DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag)
    1005975{
    1006976    IPRT_LINUX_SAVE_EFL_AC();
    1007977    PRTR0MEMOBJLNX pMemLnx;
    1008978    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,
    1035989                                       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
    1040995    if (RT_SUCCESS(rc))
    1041996    {
     
    1043998        if (RT_SUCCESS(rc))
    1044999        {
    1045 #if defined(RT_STRICT)
     1000#if defined(RT_STRICT) && (defined(RT_ARCH_AMD64) || defined(CONFIG_HIGHMEM64G))
    10461001            size_t iPage = pMemLnx->cPages;
    10471002            while (iPage-- > 0)
    1048                 Assert(page_to_phys(pMemLnx->apPages[iPage]) < PhysHighest);
     1003                Assert(page_to_phys(pMemLnx->apPages[iPage]) < _4G);
    10491004#endif
    10501005            pMemLnx->Core.u.Cont.Phys = page_to_phys(pMemLnx->apPages[0]);
  • trunk/src/VBox/Runtime/r0drv/memobj-r0drv.cpp

    r100355 r100356  
    474474
    475475
    476 RTR0DECL(int) RTR0MemObjAllocContTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, bool fExecutable, const char *pszTag)
     476RTR0DECL(int) RTR0MemObjAllocContTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag)
    477477{
    478478    /* sanity checks. */
     
    482482    AssertReturn(cb > 0, VERR_INVALID_PARAMETER);
    483483    AssertReturn(cb <= cbAligned, VERR_INVALID_PARAMETER);
    484     AssertReturn(PhysHighest >= cb, VERR_INVALID_PARAMETER);
    485484    RT_ASSERT_PREEMPTIBLE();
    486485
    487486    /* do the allocation. */
    488     return rtR0MemObjNativeAllocCont(pMemObj, cbAligned, PhysHighest, fExecutable, pszTag);
     487    return rtR0MemObjNativeAllocCont(pMemObj, cbAligned, fExecutable, pszTag);
    489488}
    490489RT_EXPORT_SYMBOL(RTR0MemObjAllocContTag);
  • trunk/src/VBox/Runtime/r0drv/netbsd/memobj-r0drv-netbsd.c

    r100355 r100356  
    288288
    289289
    290 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest,
    291                                           bool fExecutable, const char *pszTag)
     290DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag)
    292291{
    293292    PRTR0MEMOBJNETBSD pMemNetBSD = (PRTR0MEMOBJNETBSD)rtR0MemObjNew(sizeof(*pMemNetBSD), RTR0MEMOBJTYPE_CONT, NULL, cb, pszTag);
    294293    if (pMemNetBSD)
    295294    {
    296         int rc = rtR0MemObjNetBSDAllocHelper(pMemNetBSD, cb, fExecutable, PhysHighest, true /*fContiguous*/);
     295        int rc = rtR0MemObjNetBSDAllocHelper(pMemNetBSD, cb, fExecutable, _4G - 1, true /*fContiguous*/);
    297296        if (RT_SUCCESS(rc))
    298297        {
  • trunk/src/VBox/Runtime/r0drv/nt/memobj-r0drv-nt.cpp

    r100355 r100356  
    565565     * Fall back on contiguous memory...
    566566     */
    567     return rtR0MemObjNativeAllocCont(ppMem, cb, _4G - 1, fExecutable, pszTag);
     567    return rtR0MemObjNativeAllocCont(ppMem, cb, fExecutable, pszTag);
    568568}
    569569
     
    636636
    637637
    638 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest,
    639                                           bool fExecutable, const char *pszTag)
    640 {
    641     return rtR0MemObjNativeAllocContEx(ppMem, cb, fExecutable, PhysHighest, PAGE_SIZE /* alignment */, pszTag);
     638DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag)
     639{
     640    return rtR0MemObjNativeAllocContEx(ppMem, cb, fExecutable, _4G-1, PAGE_SIZE /* alignment */, pszTag);
    642641}
    643642
  • trunk/src/VBox/Runtime/r0drv/os2/memobj-r0drv-os2.cpp

    r100355 r100356  
    218218
    219219
    220 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest,
    221                                           bool fExecutable, const char *pszTag)
     220DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag)
    222221{
    223222    NOREF(fExecutable);
    224     AssertMsgReturn(PhysHighest >= _16M - 1, ("PhysHigest=%RHp\n", PhysHighest), VERR_NOT_SUPPORTED);
    225223
    226224    /* create the object. */
     
    231229        /* do the allocation. */
    232230        ULONG ulPhys = ~0UL;
    233         int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG | (PhysHighest < _4G - 1 ? VMDHA_16M : 0),
    234                              &pMemOs2->Core.pv, (PPVOID)&ulPhys, NULL);
     231        int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG, &pMemOs2->Core.pv, (PPVOID)&ulPhys, NULL);
    235232        if (!rc)
    236233        {
     
    251248                                          const char *pszTag)
    252249{
    253     AssertMsgReturn(PhysHighest >= _16M - 1, ("PhysHigest=%RHp\n", PhysHighest), VERR_NOT_SUPPORTED);
     250    AssertMsgReturn(PhysHighest >= 16 *_1M, ("PhysHigest=%RHp\n", PhysHighest), VERR_NOT_SUPPORTED);
    254251
    255252    /** @todo alignment  */
     
    264261        /* do the allocation. */
    265262        ULONG ulPhys = ~0UL;
    266         int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG | (PhysHighest < _4G - 1 ? VMDHA_16M : 0),
     263        int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG | (PhysHighest < _4G ? VMDHA_16M : 0),
    267264                             &pMemOs2->Core.pv, (PPVOID)&ulPhys, NULL);
    268265        if (!rc)
  • trunk/src/VBox/Runtime/r0drv/solaris/memobj-r0drv-solaris.c

    r100355 r100356  
    727727
    728728
    729 DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest,
    730                                           bool fExecutable, const char *pszTag)
     729DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag)
    731730{
    732731    AssertReturn(!fExecutable, VERR_NOT_SUPPORTED);
    733     return rtR0MemObjNativeAllocPhys(ppMem, cb, PhysHigest, PAGE_SIZE /* alignment */, pszTag);
     732    return rtR0MemObjNativeAllocPhys(ppMem, cb, _4G - 1, PAGE_SIZE /* alignment */, pszTag);
    734733}
    735734
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette