VirtualBox

Changeset 26947 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 2, 2010 2:11:43 PM (15 years ago)
Author:
vboxsync
Message:

Avoid deadlocks in PGMR3PhysFreeRamPages

Location:
trunk/src/VBox/VMM
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/PGMInternal.h

    r26718 r26947  
    841841/** Can use a page directory entry to map the continous range. */
    842842#define PGM_PAGE_PDE_TYPE_PDE                  2
     843/** Can use a page directory entry to map the continous range - temporarily disabled (by page monitoring). */
     844#define PGM_PAGE_PDE_TYPE_PDE_DISABLED         3
    843845/** @} */
    844846
  • trunk/src/VBox/VMM/PGMPhys.cpp

    r26616 r26947  
    839839
    840840/**
    841  * Frees a range of ram pages, replacing them with ZERO pages
     841 * Frees a range of ram pages, replacing them with ZERO pages; helper for PGMR3PhysFreeRamPages
    842842 *
    843843 * @returns VBox status code.
     
    846846 * @param   paPhysPage  Array of guest physical addresses
    847847 */
    848 VMMR3DECL(int) PGMR3PhysFreeRamPages(PVM pVM, unsigned cPages, RTGCPHYS *paPhysPage)
     848static DECLCALLBACK(void) pgmR3PhysFreeRamPagesHelper(PVM pVM, unsigned cPages, RTGCPHYS *paPhysPage)
    849849{
    850850    uintptr_t paUser[2];
     
    854854    int rc = VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_ONCE, pgmR3PhysFreeRamPagesRendezvous, (void *)paUser);
    855855    AssertRC(rc);
     856
     857    /* Made a copy in PGMR3PhysFreeRamPages; free it here. */
     858    RTMemFree(paPhysPage);
     859}
     860
     861/**
     862 * Frees a range of ram pages, replacing them with ZERO pages
     863 *
     864 * @returns VBox status code.
     865 * @param   pVM         The VM handle.
     866 * @param   cPages      Number of pages to free
     867 * @param   paPhysPage  Array of guest physical addresses
     868 */
     869VMMR3DECL(int) PGMR3PhysFreeRamPages(PVM pVM, unsigned cPages, RTGCPHYS *paPhysPage)
     870{
     871    int rc;
     872
     873    /* Currently only used by the VMM device in responds to a balloon request. */
     874    if (pVM->cCpus > 1)
     875    {
     876        unsigned cbPhysPage = cPages * sizeof(paPhysPage[0]);
     877        RTGCPHYS *paPhysPageCopy = (RTGCPHYS *)RTMemAlloc(cbPhysPage);
     878        AssertReturn(paPhysPageCopy, VERR_NO_MEMORY);
     879
     880        memcpy(paPhysPageCopy, paPhysPage, cbPhysPage);
     881
     882        /* We own the IOM lock here and could cause a deadlock by waiting for another VCPU that is blocking on the IOM lock. */
     883        rc = VMR3ReqCallNoWait(pVM, VMCPUID_ANY_QUEUE, (PFNRT)pgmR3PhysFreeRamPagesHelper, 3, pVM, cPages, paPhysPageCopy);
     884        AssertRC(rc);
     885    }
     886    else
     887    {
     888        uintptr_t paUser[2];
     889
     890        paUser[0] = cPages;
     891        paUser[1] = (uintptr_t)paPhysPage;
     892        rc = VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_ONCE, pgmR3PhysFreeRamPagesRendezvous, (void *)paUser);
     893        AssertRC(rc);
     894    }
    856895    return rc;
    857896}
     897
    858898
    859899/**
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