VirtualBox

Ignore:
Timestamp:
Dec 9, 2020 6:59:04 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
141850
Message:

Runtime/memobj-r0drv-linux.c: Changes to support the upcoming 5.10 kernel, bugref:9879

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/linux/memobj-r0drv-linux.c

    r86542 r87074  
    5757 * This is a must for 5.8+, but we enable it all the way back to 3.2.x for
    5858 * better W^R compliance (fExecutable flag). */
    59 #if RTLNX_VER_MIN(3,2,0) || defined(DOXYGEN_RUNNING)
     59#if RTLNX_VER_RANGE(3,2,0, 5,10,0) || defined(DOXYGEN_RUNNING)
    6060# define IPRT_USE_ALLOC_VM_AREA_FOR_EXEC
     61#endif
     62/** @def IPRT_USE_APPLY_TO_PAGE_RANGE_FOR_EXEC
     63 * alloc_vm_area was removed with 5.10 so we have to resort to a different way
     64 * to allocate executable memory.
     65 * It would be possible to remove IPRT_USE_ALLOC_VM_AREA_FOR_EXEC and use
     66 * this path execlusively for 3.2+ but no time to test it really works on every
     67 * supported kernel, so better play safe for now.
     68 */
     69#if RTLNX_VER_MIN(5,10,0) || defined(DOXYGEN_RUNNING)
     70# define IPRT_USE_APPLY_TO_PAGE_RANGE_FOR_EXEC
    6171#endif
    6272
     
    501511    }
    502512}
     513
     514
     515#ifdef IPRT_USE_APPLY_TO_PAGE_RANGE_FOR_EXEC
     516/**
     517 * User data passed to the apply_to_page_range() callback.
     518 */
     519typedef struct LNXAPPLYPGRANGE
     520{
     521    /** Pointer to the memory object. */
     522    PRTR0MEMOBJLNX pMemLnx;
     523    /** The page protection flags to apply. */
     524    pgprot_t       fPg;
     525} LNXAPPLYPGRANGE;
     526/** Pointer to the user data. */
     527typedef LNXAPPLYPGRANGE *PLNXAPPLYPGRANGE;
     528/** Pointer to the const user data. */
     529typedef const LNXAPPLYPGRANGE *PCLNXAPPLYPGRANGE;
     530
     531/**
     532 * Callback called in apply_to_page_range().
     533 *
     534 * @returns Linux status code.
     535 * @param   pPte                Pointer to the page table entry for the given address.
     536 * @param   uAddr               The address to apply the new protection to.
     537 * @param   pvUser              The opaque user data.
     538 */
     539static DECLCALLBACK(int) rtR0MemObjLinuxApplyPageRange(pte_t *pPte, unsigned long uAddr, void *pvUser)
     540{
     541    PCLNXAPPLYPGRANGE pArgs = (PCLNXAPPLYPGRANGE)pvUser;
     542    PRTR0MEMOBJLNX pMemLnx = pArgs->pMemLnx;
     543    size_t idxPg = (uAddr - (unsigned long)pMemLnx->Core.pv) >> PAGE_SHIFT;
     544
     545    set_pte(pPte, mk_pte(pMemLnx->apPages[idxPg], pArgs->fPg));
     546    return 0;
     547}
     548#endif
    503549
    504550
     
    585631# endif
    586632        {
     633#  if defined(IPRT_USE_APPLY_TO_PAGE_RANGE_FOR_EXEC)
     634            if (fExecutable)
     635                pgprot_val(fPg) |= _PAGE_NX; /* Uses RTR0MemObjProtect to clear NX when memory ready, W^X fashion. */
     636#  endif
     637
    587638# ifdef VM_MAP
    588639            pMemLnx->Core.pv = vmap(&pMemLnx->apPages[0], pMemLnx->cPages, VM_MAP, fPg);
     
    18521903        return VINF_SUCCESS;
    18531904    }
     1905# elif defined(IPRT_USE_APPLY_TO_PAGE_RANGE_FOR_EXEC)
     1906    PRTR0MEMOBJLNX pMemLnx = (PRTR0MEMOBJLNX)pMem;
     1907    if (   pMemLnx->fExecutable
     1908        && pMemLnx->fMappedToRing0)
     1909    {
     1910        LNXAPPLYPGRANGE Args;
     1911        Args.pMemLnx = pMemLnx;
     1912        Args.fPg = rtR0MemObjLinuxConvertProt(fProt, true /*fKernel*/);
     1913        int rcLnx = apply_to_page_range(current->active_mm, (unsigned long)pMemLnx->Core.pv + offSub, cbSub,
     1914                                        rtR0MemObjLinuxApplyPageRange, (void *)&Args);
     1915        if (rcLnx)
     1916            return VERR_NOT_SUPPORTED;
     1917
     1918        return VINF_SUCCESS;
     1919    }
    18541920# endif
    18551921
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