VirtualBox

Changeset 90667 in vbox for trunk


Ignore:
Timestamp:
Aug 12, 2021 5:07:35 PM (3 years ago)
Author:
vboxsync
Message:

VMM/PDMCritSectRwLeaveShared: Signal waiting writers from ring-0/HM. bugref:6695

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/PDMAllCritSectRw.cpp

    r90665 r90667  
    652652     * Check the direction and take action accordingly.
    653653     */
     654#ifdef IN_RING0
     655    PVMCPUCC pVCpu       = NULL;
     656#endif
    654657    uint64_t u64State    = PDMCRITSECTRW_READ_STATE(&pThis->s.Core.u.s.u64State);
    655658    uint64_t u64OldState = u64State;
     
    685688#if defined(IN_RING3) || defined(IN_RING0)
    686689# ifdef IN_RING0
    687                 if (   RTThreadPreemptIsEnabled(NIL_RTTHREAD)
    688                     && ASMIntAreEnabled())
     690                Assert(RTSemEventIsSignalSafe() == RTSemEventMultiIsSignalSafe());
     691                if (!pVCpu)
     692                    pVCpu = VMMGetCpu(pVM);
     693                if (   pVCpu == NULL /* non-EMT access, if we implement it must be able to block */
     694                    || VMMRZCallRing3IsEnabled(pVCpu)
     695                    || RTSemEventIsSignalSafe()
     696                    || (   VMMR0ThreadCtxHookIsEnabled(pVCpu)       /* Doesn't matter if Signal() blocks if we have hooks, ... */
     697                        && RTThreadPreemptIsEnabled(NIL_RTTHREAD)   /* ... and preemption is still enabled, */
     698                        && ASMIntAreEnabled())                      /* ... and interrupts hasn't yet been disabled. Special pre-GC HM env. */
     699                   )
    689700# endif
    690701                {
     
    694705                    if (ASMAtomicCmpXchgU64(&pThis->s.Core.u.s.u64State, u64State, u64OldState))
    695706                    {
    696                         int rc = SUPSemEventSignal(pVM->pSession, (SUPSEMEVENT)pThis->s.Core.hEvtWrite);
     707                        int rc;
     708# ifdef IN_RING0
     709                        STAM_REL_COUNTER_INC(&pThis->s.StatContentionRZLeaveShared);
     710                        if (!RTSemEventIsSignalSafe() && pVCpu != NULL)
     711                        {
     712                            VMMR0EMTBLOCKCTX Ctx;
     713                            rc = VMMR0EmtPrepareToBlock(pVCpu, VINF_SUCCESS, __FUNCTION__, pThis, &Ctx);
     714                            VMM_ASSERT_RELEASE_MSG_RETURN(pVM, RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
     715
     716                            rc = SUPSemEventSignal(pVM->pSession, (SUPSEMEVENT)pThis->s.Core.hEvtWrite);
     717
     718                            VMMR0EmtResumeAfterBlocking(pVCpu, &Ctx);
     719                        }
     720                        else
     721# endif
     722                            rc = SUPSemEventSignal(pVM->pSession, (SUPSEMEVENT)pThis->s.Core.hEvtWrite);
    697723                        AssertRC(rc);
    698                         break;
     724                        return rc;
    699725                    }
    700726                }
     
    706732                {
    707733                    /* Queue the exit request (ring-3). */
    708                     PVMCPUCC    pVCpu = VMMGetCpu(pVM);                 AssertPtr(pVCpu);
     734# ifndef IN_RING0
     735                    PVMCPUCC    pVCpu = VMMGetCpu(pVM); AssertPtr(pVCpu);
     736# endif
    709737                    uint32_t    i     = pVCpu->pdm.s.cQueuedCritSectRwShrdLeaves++;
    710738                    LogFlow(("PDMCritSectRwLeaveShared: [%d]=%p => R3 c=%d (%#llx)\n", i, pThis, c, u64State));
     
    728756
    729757            ASMNopPause();
     758            if (RT_LIKELY(pThis->s.Core.u32Magic == RTCRITSECTRW_MAGIC))
     759            { }
     760            else
     761                return VERR_SEM_DESTROYED;
     762            ASMNopPause();
     763
    730764            u64State = PDMCRITSECTRW_READ_STATE(&pThis->s.Core.u.s.u64State);
    731765            u64OldState = u64State;
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