VirtualBox

Changeset 82876 in vbox


Ignore:
Timestamp:
Jan 27, 2020 1:38:45 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
135853
Message:

VMM/GMMR0: Working on eliminating legacy-mode (locking user memory rather than allocating it directly). bugref:9627

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/VBox/VMM/VMMR0/GMMR0.cpp

    r82866 r82876  
    107107 * by the VM that locked it. We will make no attempt at implementing
    108108 * 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.
    109115 *
    110116 *
     
    186192# define VBOX_USE_CRIT_SECT_FOR_GIANT
    187193#endif
     194
     195/** Enable the legacy mode code (will be dropped soon). */
     196#define GMM_WITH_LEGACY_MODE
    188197
    189198
     
    450459/** Indicates that the chunk is a large page (2MB). */
    451460#define GMM_CHUNK_FLAGS_LARGE_PAGE  UINT16_C(0x0001)
     461#ifdef GMM_WITH_LEGACY_MODE
    452462/** 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
    454465/** @}  */
    455466
     
    550561    uint64_t            cBalloonedPages;
    551562
     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
    552571    /** The legacy allocation mode indicator.
    553572     * This is determined at initialization time. */
    554573    bool                fLegacyAllocationMode;
     574#endif
    555575    /** The bound memory mode indicator.
    556576     * When set, the memory will be bound to a specific VM and never
     
    799819        if (RT_SUCCESS(rc))
    800820        {
     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 */
    801842            /*
    802843             * Check and see if RTR0MemObjAllocPhysNC works.
    803844             */
    804 #if 0 /* later, see @bufref{3170}. */
     845# if 0 /* later, see @bufref{3170}. */
    805846            RTR0MEMOBJ MemObj;
    806847            rc = RTR0MemObjAllocPhysNC(&MemObj, _64K, NIL_RTHCPHYS);
     
    814855            else
    815856                SUPR0Printf("GMMR0Init: RTR0MemObjAllocPhysNC(,64K,Any) -> %d!\n", rc);
    816 #else
    817 # 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)
    818859            pGMM->fLegacyAllocationMode = false;
    819 if ARCH_BITS == 32
     860 if ARCH_BITS == 32
    820861            /* Don't reuse possibly partial chunks because of the virtual
    821862               address space limitation. */
    822863            pGMM->fBoundMemoryMode      = true;
     864#   else
     865            pGMM->fBoundMemoryMode      = false;
     866#   endif
    823867#  else
    824             pGMM->fBoundMemoryMode      = false;
    825 #  endif
    826 # else
    827868            pGMM->fLegacyAllocationMode = true;
    828869            pGMM->fBoundMemoryMode      = true;
     870#  endif
    829871# endif
    830 #endif
     872#endif /* GMM_WITH_LEGACY_MODE */
    831873
    832874            /*
     
    836878
    837879            g_pGMM = pGMM;
     880#ifdef GMM_WITH_LEGACY_MODE
    838881            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
    839887            return VINF_SUCCESS;
    840888        }
     
    21332181    Assert(pGMM->hMtxOwner != RTThreadNativeSelf());
    21342182    Assert(hGVM != NIL_GVM_HANDLE || pGMM->fBoundMemoryMode);
     2183#ifdef GMM_WITH_LEGACY_MODE
    21352184    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
    21362188
    21372189#if defined(VBOX_WITH_RAM_IN_KERNEL) && !defined(VBOX_WITH_LINEAR_HOST_PHYS_MEM)
     
    21392191     * Get a ring-0 mapping of the object.
    21402192     */
     2193# ifdef GMM_WITH_LEGACY_MODE
    21412194    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
    21422198    if (!pbMapping)
    21432199    {
     
    22422298
    22432299    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
    22442309    int rc = RTR0MemObjAllocPhysNC(&hMemObj, GMM_CHUNK_SIZE, NIL_RTHCPHYS);
     2310#endif
    22452311    if (RT_SUCCESS(rc))
    22462312    {
     
    25742640    }
    25752641
     2642#ifdef GMM_WITH_LEGACY_MODE
    25762643    /*
    25772644     * If we're in legacy memory mode, it's easy to figure if we have
     
    25842651        return VERR_GMM_SEED_ME;
    25852652    }
     2653#endif
    25862654
    25872655    /*
     
    26002668    pGMM->cAllocatedPages           += cPages;
    26012669
     2670#ifdef GMM_WITH_LEGACY_MODE
    26022671    /*
    26032672     * Part two of it's-easy-in-legacy-memory-mode.
    26042673     */
    2605     uint32_t iPage = 0;
    26062674    if (pGMM->fLegacyAllocationMode)
    26072675    {
    2608         iPage = gmmR0AllocatePagesInBoundMode(pGVM, iPage, cPages, paPages);
     2676        uint32_t iPage = gmmR0AllocatePagesInBoundMode(pGVM, 0, cPages, paPages);
    26092677        AssertReleaseReturn(iPage == cPages, VERR_GMM_ALLOC_PAGES_IPE);
    26102678        return VINF_SUCCESS;
    26112679    }
     2680#endif
    26122681
    26132682    /*
    26142683     * Bound mode is also relatively straightforward.
    26152684     */
     2685    uint32_t iPage = 0;
    26162686    int rc = VINF_SUCCESS;
    26172687    if (pGMM->fBoundMemoryMode)
     
    30693139        return rc;
    30703140
     3141#ifdef GMM_WITH_LEGACY_MODE
    30713142    // /* Not supported in legacy mode where we allocate the memory in ring 3 and lock it in ring 0. */
    30723143    // if (pGMM->fLegacyAllocationMode)
    30733144    //     return VERR_NOT_SUPPORTED;
     3145#endif
    30743146
    30753147    *pHCPhys = NIL_RTHCPHYS;
     
    31703242        return rc;
    31713243
     3244#ifdef GMM_WITH_LEGACY_MODE
    31723245    // /* Not supported in legacy mode where we allocate the memory in ring 3 and lock it in ring 0. */
    31733246    // if (pGMM->fLegacyAllocationMode)
    31743247    //     return VERR_NOT_SUPPORTED;
     3248#endif
    31753249
    31763250    gmmR0MutexAcquire(pGMM);
     
    32593333     */
    32603334    if (    pChunk->cMappingsX
     3335#ifdef GMM_WITH_LEGACY_MODE
    32613336        &&  (!pGMM->fLegacyAllocationMode || (pChunk->fFlags & GMM_CHUNK_FLAGS_LARGE_PAGE))
     3337#endif
    32623338        &&  pGVM)
    32633339        gmmR0UnmapChunkLocked(pGMM, pGVM, pChunk);
     
    33873463     */
    33883464    /** @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
    33933474        gmmR0FreeChunk(pGMM, NULL, pChunk, false);
    33943475
     
    39133994static int gmmR0UnmapChunkLocked(PGMM pGMM, PGVM pGVM, PGMMCHUNK pChunk)
    39143995{
    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
    39164000
    39174001    /*
     
    39594043static int gmmR0UnmapChunk(PGMM pGMM, PGVM pGVM, PGMMCHUNK pChunk, bool fRelaxedSem)
    39604044{
     4045#ifdef GMM_WITH_LEGACY_MODE
    39614046    if (!pGMM->fLegacyAllocationMode || (pChunk->fFlags & GMM_CHUNK_FLAGS_LARGE_PAGE))
    39624047    {
     4048#endif
    39634049        /*
    39644050         * Lock the chunk and if possible leave the giant GMM lock.
     
    39734059        }
    39744060        return rc;
     4061#ifdef GMM_WITH_LEGACY_MODE
    39754062    }
    39764063
     
    39804067    Log(("gmmR0UnmapChunk: Chunk %#x is not mapped into pGVM=%p/%#x (legacy)\n", pChunk->Core.Key, pGVM, pGVM->hSelf));
    39814068    return VERR_GMM_CHUNK_NOT_MAPPED;
     4069#endif
    39824070}
    39834071
     
    39964084static int gmmR0MapChunkLocked(PGMM pGMM, PGVM pGVM, PGMMCHUNK pChunk, PRTR3PTR ppvR3)
    39974085{
     4086#ifdef GMM_WITH_LEGACY_MODE
    39984087    /*
    39994088     * If we're in legacy mode this is simple.
     
    40104099        return VINF_SUCCESS;
    40114100    }
     4101#else
     4102    RT_NOREF(pGMM);
     4103#endif
    40124104
    40134105    /*
     
    42664358GMMR0DECL(int) GMMR0SeedChunk(PGVM pGVM, VMCPUID idCpu, RTR3PTR pvR3)
    42674359{
     4360#ifdef GMM_WITH_LEGACY_MODE
    42684361    /*
    42694362     * Validate input and get the basics.
     
    43014394    LogFlow(("GMMR0SeedChunk: rc=%d (pvR3=%p)\n", rc, pvR3));
    43024395    return rc;
     4396#else
     4397    RT_NOREF(pGVM, idCpu, pvR3);
     4398    return VERR_NOT_SUPPORTED;
     4399#endif
    43034400}
    43044401
Note: See TracChangeset for help on using the changeset viewer.

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