VirtualBox

Changeset 104848 in vbox for trunk/src


Ignore:
Timestamp:
Jun 5, 2024 9:38:20 AM (8 months ago)
Author:
vboxsync
Message:

VMM/PGM,SUPDrv,IPRT: Added a RTR0MemObjZeroInitialize function to IPRT/SUPDrv for helping zero initializing MMIO2 backing memory. bugref:10687

Location:
trunk/src/VBox
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/SUPDrv.cpp

    r103684 r104848  
    474474    SUPEXP_STK_OKAY(    1,  RTR0MemObjSize),
    475475    SUPEXP_STK_OKAY(    1,  RTR0MemObjWasZeroInitialized),
     476    SUPEXP_STK_OKAY(    2,  RTR0MemObjZeroInitialize),
    476477    SUPEXP_STK_BACK(    3,  RTR0MemUserCopyFrom),
    477478    SUPEXP_STK_BACK(    3,  RTR0MemUserCopyTo),
  • trunk/src/VBox/HostDrivers/Support/SUPDrvIOC.h

    r104327 r104848  
    233233 *          - nothing
    234234 */
    235 #define SUPDRV_IOC_VERSION                              0x00340000
     235#define SUPDRV_IOC_VERSION                              0x00340001
    236236
    237237/** SUP_IOCTL_COOKIE. */
  • trunk/src/VBox/HostDrivers/Support/SUPLib.cpp

    r104328 r104848  
    298298        strcpy(CookieReq.u.In.szMagic, SUPCOOKIE_MAGIC);
    299299        CookieReq.u.In.u32ReqVersion = SUPDRV_IOC_VERSION;
    300         const uint32_t uMinVersion = /*(SUPDRV_IOC_VERSION & 0xffff0000) == 0x00340000
    301                                    ? 0x00340000
    302                                    : */ SUPDRV_IOC_VERSION & 0xffff0000;
     300        const uint32_t uMinVersion = (SUPDRV_IOC_VERSION & 0xffff0000) == 0x00340000
     301                                   ? 0x00340001
     302                                   : SUPDRV_IOC_VERSION & 0xffff0000;
    303303        CookieReq.u.In.u32MinVersion = uMinVersion;
    304304        rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_COOKIE, &CookieReq, SUP_IOCTL_COOKIE_SIZE);
  • trunk/src/VBox/Runtime/include/internal/memobj.h

    r100357 r104848  
    538538DECLHIDDEN(RTHCPHYS) rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage);
    539539
     540/**
     541 * Zero initialize an object without a ring-0 mapping.
     542 *
     543 * @returns IPRT status code.
     544 * @param   pMem            The ring-0 memory object handle.
     545 */
     546DECLHIDDEN(int) rtR0MemObjNativeZeroInitWithoutMapping(PRTR0MEMOBJINTERNAL pMem);
     547
    540548DECLHIDDEN(PRTR0MEMOBJINTERNAL) rtR0MemObjNew(size_t cbSelf, RTR0MEMOBJTYPE enmType, void *pv, size_t cb, const char *pszTag);
    541549DECLHIDDEN(void) rtR0MemObjDelete(PRTR0MEMOBJINTERNAL pMem);
  • trunk/src/VBox/Runtime/r0drv/darwin/memobj-r0drv-darwin.cpp

    r100357 r104848  
    15801580}
    15811581
     1582
     1583DECLHIDDEN(int) rtR0MemObjNativeZeroInitWithoutMapping(PRTR0MEMOBJINTERNAL pMem)
     1584{
     1585    RT_NOREF(pMem);
     1586    return VERR_NOT_IMPLEMENTED;
     1587}
     1588
  • trunk/src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c

    r100357 r104848  
    7777#include <iprt/param.h>
    7878#include <iprt/process.h>
     79#include <iprt/string.h>
    7980#include "internal/memobj.h"
    8081
     
    906907}
    907908
     909
     910DECLHIDDEN(int) rtR0MemObjNativeZeroInitWithoutMapping(PRTR0MEMOBJINTERNAL pMem)
     911{
     912    PRTR0MEMOBJFREEBSD const pMemFreeBsd = (PRTR0MEMOBJFREEBSD)pMem;
     913    size_t const             cPages      = pMemSolaris->Core.cb >> PAGE_SHIFT;
     914    size_t                   iPage;
     915    for (iPage = 0; iPage < cPages; iPage++)
     916    {
     917        void          *pvPage;
     918
     919        /* Get the physical address of the page. */
     920        RTHCPHYS const HCPhys = rtR0MemObjNativeGetPagePhysAddr(&pMemFreeBsd->Core, iPage);
     921        AssertReturn(HCPhys != NIL_RTHCPHYS, VERR_INTERNAL_ERROR_3);
     922        Assert(!(HCPhys & PAGE_OFFSET_MASK));
     923
     924        /* Map it. */
     925        pvPage = (void *)(uintptr_t)pmap_map(NULL, HCPhys, (HCPhys | PAGE_OFFSET_MASK) + 1, VM_PROT_WRITE | VM_PROT_READ);
     926        AssertPtrReturn(pvPage, VERR_INTERNAL_ERROR_3);
     927
     928        /* Zero it. */
     929        RT_BZERO(pvPage, PAGE_SIZE);
     930    }
     931    return VINF_SUCCESS;
     932}
     933
  • trunk/src/VBox/Runtime/r0drv/haiku/memobj-r0drv-haiku.c

    r100357 r104848  
    685685}
    686686
     687
     688DECLHIDDEN(int) rtR0MemObjNativeZeroInitWithoutMapping(PRTR0MEMOBJINTERNAL pMem)
     689{
     690    RT_NOREF(pMem);
     691    return VERR_NOT_IMPLEMENTED;
     692}
     693
  • trunk/src/VBox/Runtime/r0drv/linux/memobj-r0drv-linux.c

    r104096 r104848  
    21812181}
    21822182
     2183
     2184DECLHIDDEN(int) rtR0MemObjNativeZeroInitWithoutMapping(PRTR0MEMOBJINTERNAL pMem)
     2185{
     2186    PRTR0MEMOBJLNX const pMemLnx = (PRTR0MEMOBJLNX)pMem;
     2187    size_t const         cPages  = pMemLnx->Core.cb >> PAGE_SHIFT;
     2188    size_t               iPage;
     2189    /** @todo optimize this. */
     2190    for (iPage = 0; iPage < cPages; iPage++)
     2191    {
     2192        void          *pvPage;
     2193
     2194        /* Get the physical address of the page. */
     2195        RTHCPHYS const HCPhys = rtR0MemObjNativeGetPagePhysAddr(&pMemLnx->Core, iPage);
     2196        AssertReturn(HCPhys != NIL_RTHCPHYS, VERR_INTERNAL_ERROR_3);
     2197        Assert(!(HCPhys & PAGE_OFFSET_MASK));
     2198
     2199        /* Would've like to use valid_phys_addr_range for this test, but it isn't exported. */
     2200        AssertReturn((HCPhys | PAGE_OFFSET_MASK) < __pa(high_memory), VERR_INTERNAL_ERROR_3);
     2201
     2202        /* Map it. */
     2203        pvPage = phys_to_virt(HCPhys);
     2204        AssertPtrReturn(pvPage, VERR_INTERNAL_ERROR_3);
     2205
     2206        /* Zero it. */
     2207        RT_BZERO(pvPage, PAGE_SIZE);
     2208    }
     2209    return VINF_SUCCESS;
     2210}
     2211
  • trunk/src/VBox/Runtime/r0drv/memobj-r0drv.cpp

    r100357 r104848  
    5252#include <iprt/param.h>
    5353#include <iprt/process.h>
     54#include <iprt/string.h>
    5455#include <iprt/thread.h>
    5556
     
    296297
    297298
     299RTR0DECL(int) RTR0MemObjZeroInitialize(RTR0MEMOBJ hMemObj, bool fForce)
     300{
     301    PRTR0MEMOBJINTERNAL pMem;
     302
     303    /* Validate the object handle. */
     304    AssertReturn(hMemObj != NIL_RTR0MEMOBJ, VERR_INVALID_HANDLE);
     305    AssertPtrReturn(hMemObj, VERR_INVALID_HANDLE);
     306    pMem = (PRTR0MEMOBJINTERNAL)hMemObj;
     307    AssertMsgReturn(pMem->u32Magic == RTR0MEMOBJ_MAGIC, ("%p: %#x\n", pMem, pMem->u32Magic), VERR_INVALID_HANDLE);
     308    AssertMsgReturn(pMem->enmType > RTR0MEMOBJTYPE_INVALID && pMem->enmType < RTR0MEMOBJTYPE_END, ("%p: %d\n", pMem, pMem->enmType), VERR_INVALID_HANDLE);
     309    AssertReturn(   (pMem->enmType != RTR0MEMOBJTYPE_MAPPING || pMem->u.Mapping.R0Process == NIL_RTR0PROCESS)
     310                 && (pMem->enmType != RTR0MEMOBJTYPE_LOCK    || pMem->u.Lock.R0Process    == NIL_RTR0PROCESS)
     311                 && pMem->enmType != RTR0MEMOBJTYPE_RES_VIRT
     312                 , VERR_WRONG_TYPE);
     313    Assert(   (pMem->fFlags & (RTR0MEMOBJ_FLAGS_ZERO_AT_ALLOC | RTR0MEMOBJ_FLAGS_UNINITIALIZED_AT_ALLOC))
     314           !=                 (RTR0MEMOBJ_FLAGS_ZERO_AT_ALLOC | RTR0MEMOBJ_FLAGS_UNINITIALIZED_AT_ALLOC));
     315
     316    /*
     317     * Do we need to do anything?
     318     */
     319    if (   fForce
     320        ||    (pMem->fFlags & (RTR0MEMOBJ_FLAGS_ZERO_AT_ALLOC | RTR0MEMOBJ_FLAGS_UNINITIALIZED_AT_ALLOC))
     321           !=                  RTR0MEMOBJ_FLAGS_ZERO_AT_ALLOC)
     322    {
     323        /* This is easy if there is a ring-0 mapping: */
     324        if (pMem->pv)
     325            RT_BZERO(pMem->pv, pMem->cb);
     326        else
     327            return rtR0MemObjNativeZeroInitWithoutMapping(pMem);
     328    }
     329    return VINF_SUCCESS;
     330}
     331RT_EXPORT_SYMBOL(RTR0MemObjWasZeroInitialized);
     332
     333
    298334RTR0DECL(int) RTR0MemObjFree(RTR0MEMOBJ MemObj, bool fFreeMappings)
    299335{
  • trunk/src/VBox/Runtime/r0drv/netbsd/memobj-r0drv-netbsd.c

    r100357 r104848  
    586586}
    587587
     588
     589DECLHIDDEN(int) rtR0MemObjNativeZeroInitWithoutMapping(PRTR0MEMOBJINTERNAL pMem)
     590{
     591    RT_NOREF(pMem);
     592    return VERR_NOT_IMPLEMENTED;
     593}
     594
  • trunk/src/VBox/Runtime/r0drv/nt/memobj-r0drv-nt.cpp

    r104841 r104848  
    13011301}
    13021302
     1303
     1304DECLHIDDEN(int) rtR0MemObjNativeZeroInitWithoutMapping(PRTR0MEMOBJINTERNAL pMem)
     1305{
     1306    RT_NOREF(pMem);
     1307    return VERR_NOT_IMPLEMENTED;
     1308}
     1309
  • trunk/src/VBox/Runtime/r0drv/os2/memobj-r0drv-os2.cpp

    r100357 r104848  
    635635}
    636636
     637
     638DECLHIDDEN(int) rtR0MemObjNativeZeroInitWithoutMapping(PRTR0MEMOBJINTERNAL pMem)
     639{
     640    RT_NOREF(pMem);
     641    return VERR_NOT_IMPLEMENTED;
     642}
     643
  • trunk/src/VBox/Runtime/r0drv/solaris/memobj-r0drv-solaris.c

    r100359 r104848  
    5050#include <iprt/param.h>
    5151#include <iprt/process.h>
     52#include <iprt/string.h>
    5253#include "internal/memobj.h"
    5354#include "memobj-r0drv-solaris.h"
     
    12131214}
    12141215
     1216
     1217DECLHIDDEN(int) rtR0MemObjNativeZeroInitWithoutMapping(PRTR0MEMOBJINTERNAL pMem)
     1218{
     1219    PRTR0MEMOBJSOL const pMemSolaris = (PRTR0MEMOBJSOL)pMem;
     1220    size_t const         cPages      = pMemSolaris->Core.cb >> PAGE_SHIFT;
     1221    size_t               iPage;
     1222    for (iPage = 0; iPage < cPages; iPage++)
     1223    {
     1224        void          *pvPage;
     1225
     1226        /* Get the physical address of the page. */
     1227        RTHCPHYS const HCPhys = rtR0MemObjNativeGetPagePhysAddr(&pMemSolaris->Core, iPage);
     1228        AssertReturn(HCPhys != NIL_RTHCPHYS, VERR_INTERNAL_ERROR_3);
     1229        Assert(!(HCPhys & PAGE_OFFSET_MASK));
     1230
     1231        /* Map it. */
     1232        HCPhys >>= PAGE_SHIFT;
     1233        AssertReturn(HCPhys <= physmax, VERR_INTERNAL_ERROR_3);
     1234        pvPage = hat_kpm_pfn2va(HCPhys);
     1235        AssertPtrReturn(pvPage, VERR_INTERNAL_ERROR_3);
     1236
     1237        /* Zero it. */
     1238        RT_BZERO(pvPage, PAGE_SIZE);
     1239    }
     1240    return VINF_SUCCESS;
     1241}
     1242
  • trunk/src/VBox/VMM/VMMAll/PGMAllPhys.cpp

    r104840 r104848  
    11941194        AssertPtr(pbMmio2BackingR0);
    11951195# endif
    1196         if (!RTR0MemObjWasZeroInitialized(hMemObj))
    1197         {
    1198             void *pv = RTR0MemObjAddress(hMemObj);
    1199             AssertReturnStmt(pv, RTR0MemObjFree(hMemObj, true /*fFreeMappings*/),  VERR_INTERNAL_ERROR_4);
    1200             RT_BZERO(pv, cbMmio2Aligned);
    1201         }
     1196        rc = RTR0MemObjZeroInitialize(hMemObj, false /*fForce*/);
     1197        AssertRCReturnStmt(rc, RTR0MemObjFree(hMemObj, true /*fFreeMappings*/), rc);
    12021198#else
    12031199        RT_BZERO(pbMmio2BackingR3, cbMmio2Aligned);
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