Index: trunk/src/VBox/Devices/Bus/DevIommuAmd.cpp
===================================================================
--- trunk/src/VBox/Devices/Bus/DevIommuAmd.cpp	(revision 90434)
+++ trunk/src/VBox/Devices/Bus/DevIommuAmd.cpp	(revision 90436)
@@ -197,5 +197,5 @@
     } while (0)
 
-/** Acquires the PDM lock (shouldn't really fail). */
+/** Acquires the PDM lock (can fail under extraordinary circumstance in in ring-0). */
 #ifdef IN_RING3
 # define IOMMU_LOCK(a_pDevIns, a_pThisCC)           (a_pThisCC)->CTX_SUFF(pIommuHlp)->pfnLock((a_pDevIns), VERR_IGNORED)
@@ -204,5 +204,5 @@
     do { \
         int const rcLock = (a_pThisCC)->CTX_SUFF(pIommuHlp)->pfnLock((a_pDevIns), VINF_SUCCESS); \
-        AssertRC(rcLock); \
+        PDM_CRITSECT_RELEASE_ASSERT_RC_DEV((a_pDevIns), NULL, rcLock); \
     } while (0)
 #endif
Index: trunk/src/VBox/Devices/Bus/DevIommuIntel.cpp
===================================================================
--- trunk/src/VBox/Devices/Bus/DevIommuIntel.cpp	(revision 90434)
+++ trunk/src/VBox/Devices/Bus/DevIommuIntel.cpp	(revision 90436)
@@ -66,5 +66,5 @@
     } while (0)
 
-/** Acquires the DMAR lock (not expected to fail). */
+/** Acquires the DMAR lock (can fail under extraordinary circumstance in in ring-0). */
 #ifdef IN_RING3
 # define DMAR_LOCK(a_pDevIns, a_pThisCC)            (a_pThisCC)->CTX_SUFF(pIommuHlp)->pfnLock((a_pDevIns), VERR_IGNORED)
@@ -73,5 +73,5 @@
     do { \
         int const rcLock = (a_pThisCC)->CTX_SUFF(pIommuHlp)->pfnLock((a_pDevIns), VINF_SUCCESS); \
-        AssertRC(rcLock); \
+        PDM_CRITSECT_RELEASE_ASSERT_RC_DEV((a_pDevIns), NULL, rcLock); \
     } while (0)
 #endif
Index: trunk/src/VBox/Devices/Bus/DevPCI.cpp
===================================================================
--- trunk/src/VBox/Devices/Bus/DevPCI.cpp	(revision 90434)
+++ trunk/src/VBox/Devices/Bus/DevPCI.cpp	(revision 90436)
@@ -819,5 +819,5 @@
     {
         PDEVPCIROOT pThis = PDMINS_2_DATA(pDevIns, PDEVPCIROOT);
-        PCI_LOCK(pDevIns, VINF_IOM_R3_IOPORT_WRITE);
+        PCI_LOCK_RET(pDevIns, VINF_IOM_R3_IOPORT_WRITE);
         pThis->uConfigReg = u32 & ~3; /* Bits 0-1 are reserved and we silently clear them */
         PCI_UNLOCK(pDevIns);
@@ -839,5 +839,5 @@
     {
         PDEVPCIROOT pThis = PDMINS_2_DATA(pDevIns, PDEVPCIROOT);
-        PCI_LOCK(pDevIns, VINF_IOM_R3_IOPORT_READ);
+        PCI_LOCK_RET(pDevIns, VINF_IOM_R3_IOPORT_READ);
         *pu32 = pThis->uConfigReg;
         PCI_UNLOCK(pDevIns);
@@ -863,5 +863,5 @@
     if (!(offPort % cb))
     {
-        PCI_LOCK(pDevIns, VINF_IOM_R3_IOPORT_WRITE);
+        PCI_LOCK_RET(pDevIns, VINF_IOM_R3_IOPORT_WRITE);
         rcStrict = pci_data_write(pDevIns, PDMINS_2_DATA(pDevIns, PDEVPCIROOT), offPort, u32, cb);
         PCI_UNLOCK(pDevIns);
@@ -882,5 +882,5 @@
     if (!(offPort % cb))
     {
-        PCI_LOCK(pDevIns, VINF_IOM_R3_IOPORT_READ);
+        PCI_LOCK_RET(pDevIns, VINF_IOM_R3_IOPORT_READ);
         VBOXSTRICTRC rcStrict = pci_data_read(PDMINS_2_DATA(pDevIns, PDEVPCIROOT), offPort, cb, pu32);
         PCI_UNLOCK(pDevIns);
Index: trunk/src/VBox/Devices/Bus/DevPciIch9.cpp
===================================================================
--- trunk/src/VBox/Devices/Bus/DevPciIch9.cpp	(revision 90434)
+++ trunk/src/VBox/Devices/Bus/DevPciIch9.cpp	(revision 90436)
@@ -282,5 +282,5 @@
         u32 &= ~3;
 
-        PCI_LOCK(pDevIns, VINF_IOM_R3_IOPORT_WRITE);
+        PCI_LOCK_RET(pDevIns, VINF_IOM_R3_IOPORT_WRITE);
         pThis->uConfigReg = u32;
         PCI_UNLOCK(pDevIns);
@@ -306,5 +306,5 @@
         PDEVPCIROOT pThis = PDMINS_2_DATA(pDevIns, PDEVPCIROOT);
 
-        PCI_LOCK(pDevIns, VINF_IOM_R3_IOPORT_READ);
+        PCI_LOCK_RET(pDevIns, VINF_IOM_R3_IOPORT_READ);
         *pu32 = pThis->uConfigReg;
         PCI_UNLOCK(pDevIns);
@@ -388,5 +388,5 @@
     if (!(offPort % cb))
     {
-        PCI_LOCK(pDevIns, VINF_IOM_R3_IOPORT_WRITE);
+        PCI_LOCK_RET(pDevIns, VINF_IOM_R3_IOPORT_WRITE);
 
         if (pThis->uConfigReg & (1 << 31))
@@ -486,5 +486,5 @@
         *pu32 = 0xffffffff;
 
-        PCI_LOCK(pDevIns, VINF_IOM_R3_IOPORT_READ);
+        PCI_LOCK_RET(pDevIns, VINF_IOM_R3_IOPORT_READ);
 
         /* Configuration space mapping enabled? */
@@ -678,5 +678,5 @@
 
     /* Perform configuration space write */
-    PCI_LOCK(pDevIns, VINF_IOM_R3_MMIO_WRITE);
+    PCI_LOCK_RET(pDevIns, VINF_IOM_R3_MMIO_WRITE);
     VBOXSTRICTRC rcStrict = ich9pciConfigWrite(pDevIns, pPciRoot, &aDest, u32, cb, VINF_IOM_R3_MMIO_WRITE);
     PCI_UNLOCK(pDevIns);
@@ -702,5 +702,5 @@
     /* Perform configuration space read */
     uint32_t     u32Value = 0;
-    PCI_LOCK(pDevIns, VINF_IOM_R3_MMIO_READ);
+    PCI_LOCK_RET(pDevIns, VINF_IOM_R3_MMIO_READ);
     VBOXSTRICTRC rcStrict = ich9pciConfigRead(pPciRoot, &aDest, cb, &u32Value, VINF_IOM_R3_MMIO_READ);
     PCI_UNLOCK(pDevIns);
Index: trunk/src/VBox/Devices/Bus/DevPciInternal.h
===================================================================
--- trunk/src/VBox/Devices/Bus/DevPciInternal.h	(revision 90434)
+++ trunk/src/VBox/Devices/Bus/DevPciInternal.h	(revision 90436)
@@ -187,14 +187,17 @@
 #define DEVPCIBUS_2_DEVPCIROOT(pPciBus) RT_FROM_MEMBER(pPciBus, DEVPCIROOT, PciBus)
 
-/** @def PCI_LOCK
+
+/** @def PCI_LOCK_RET
  * Acquires the PDM lock. This is a NOP if locking is disabled. */
+#define PCI_LOCK_RET(pDevIns, rcBusy) \
+    do { \
+        int const rcLock = PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC)->CTX_SUFF(pPciHlp)->pfnLock((pDevIns), rcBusy); \
+        if (rcLock == VINF_SUCCESS) \
+        { /* likely */ } \
+        else \
+            return rcLock; \
+    } while (0)
 /** @def PCI_UNLOCK
  * Releases the PDM lock. This is a NOP if locking is disabled. */
-#define PCI_LOCK(pDevIns, rc) \
-    do { \
-        int rc2 = PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC)->CTX_SUFF(pPciHlp)->pfnLock((pDevIns), rc); \
-        if (rc2 != VINF_SUCCESS) \
-            return rc2; \
-    } while (0)
 #define PCI_UNLOCK(pDevIns) \
     PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC)->CTX_SUFF(pPciHlp)->pfnUnlock(pDevIns)
Index: trunk/src/VBox/Devices/PC/DevIoApic.cpp
===================================================================
--- trunk/src/VBox/Devices/PC/DevIoApic.cpp	(revision 90434)
+++ trunk/src/VBox/Devices/PC/DevIoApic.cpp	(revision 90436)
@@ -874,5 +874,5 @@
     bool fRemoteIrrCleared = false;
     int rc = IOAPIC_LOCK(pDevIns, pThis, pThisCC, VINF_SUCCESS);
-    AssertRC(rc);
+    PDM_CRITSECT_RELEASE_ASSERT_RC_DEV(pDevIns, NULL, rc);
 
     for (uint8_t idxRte = 0; idxRte < RT_ELEMENTS(pThis->au64RedirTable); idxRte++)
@@ -937,5 +937,5 @@
     {
         int rc = IOAPIC_LOCK(pDevIns, pThis, pThisCC, VINF_SUCCESS);
-        AssertRC(rc);
+        PDM_CRITSECT_RELEASE_ASSERT_RC_DEV(pDevIns, NULL, rc);
 
         uint8_t  const idxRte        = iIrq;
Index: trunk/src/VBox/Devices/PC/DevPIC.cpp
===================================================================
--- trunk/src/VBox/Devices/PC/DevPIC.cpp	(revision 90434)
+++ trunk/src/VBox/Devices/PC/DevPIC.cpp	(revision 90436)
@@ -58,14 +58,16 @@
 *   Defined Constants And Macros                                                                                                 *
 *********************************************************************************************************************************/
-/** @def PIC_LOCK
+/** @def PIC_LOCK_RET
  * Acquires the PDM lock. This is a NOP if locking is disabled. */
+#define PIC_LOCK_RET(a_pDevIns, a_pThisCC, rcBusy) \
+    do { \
+        int const rcLock = (a_pThisCC)->pPicHlp->pfnLock((a_pDevIns), rcBusy); \
+        if (rcLock == VINF_SUCCESS) \
+        { /* likely */ } \
+        else \
+            return rcLock; \
+    } while (0)
 /** @def PIC_UNLOCK
  * Releases the PDM lock. This is a NOP if locking is disabled. */
-#define PIC_LOCK(a_pDevIns, a_pThisCC, rc) \
-    do { \
-        int rc2 = (a_pThisCC)->pPicHlp->pfnLock((a_pDevIns), rc); \
-        if (rc2 != VINF_SUCCESS) \
-            return rc2; \
-    } while (0)
 #define PIC_UNLOCK(a_pDevIns, a_pThisCC) \
     (a_pThisCC)->pPicHlp->pfnUnlock((a_pDevIns))
@@ -681,5 +683,5 @@
     {
         int rc;
-        PIC_LOCK(pDevIns, pThisCC, VINF_IOM_R3_IOPORT_READ);
+        PIC_LOCK_RET(pDevIns, pThisCC, VINF_IOM_R3_IOPORT_READ);
         *pu32 = pic_ioport_read(pDevIns, pThis, pThisCC, &RT_SAFE_SUBSCRIPT(pThis->aPics, iPic), offPort, &rc);
         PIC_UNLOCK(pDevIns, pThisCC);
@@ -704,5 +706,5 @@
     {
         VBOXSTRICTRC rc;
-        PIC_LOCK(pDevIns, pThisCC, VINF_IOM_R3_IOPORT_WRITE);
+        PIC_LOCK_RET(pDevIns, pThisCC, VINF_IOM_R3_IOPORT_WRITE);
         rc = pic_ioport_write(pDevIns, pThis, pThisCC, &RT_SAFE_SUBSCRIPT(pThis->aPics, iPic), offPort, u32);
         PIC_UNLOCK(pDevIns, pThisCC);
@@ -722,5 +724,5 @@
         PDEVPICCC   pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PDEVPICCC);
         PPICSTATE   pPic    = (PPICSTATE)pvUser;
-        PIC_LOCK(pDevIns, pThisCC, VINF_IOM_R3_IOPORT_READ);
+        PIC_LOCK_RET(pDevIns, pThisCC, VINF_IOM_R3_IOPORT_READ);
         *pu32 = pPic->elcr;
         PIC_UNLOCK(pDevIns, pThisCC);
@@ -741,5 +743,5 @@
         PDEVPICCC   pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PDEVPICCC);
         PPICSTATE   pPic    = (PPICSTATE)pvUser;
-        PIC_LOCK(pDevIns, pThisCC, VINF_IOM_R3_IOPORT_WRITE);
+        PIC_LOCK_RET(pDevIns, pThisCC, VINF_IOM_R3_IOPORT_WRITE);
         pPic->elcr = u32 & pPic->elcr_mask;
         PIC_UNLOCK(pDevIns, pThisCC);
Index: trunk/src/VBox/VMM/VMMAll/PDMAll.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMAll/PDMAll.cpp	(revision 90434)
+++ trunk/src/VBox/VMM/VMMAll/PDMAll.cpp	(revision 90436)
@@ -300,5 +300,7 @@
 /**
  * Locks PDM.
- * This might call back to Ring-3 in order to deal with lock contention in GC and R3.
+ *
+ * This might call back to Ring-3 in order to deal with lock contention in RC
+ * and R0.
  *
  * @param   pVM     The cross context VM structure.
@@ -308,10 +310,16 @@
 #ifdef IN_RING3
     int rc = PDMCritSectEnter(pVM, &pVM->pdm.s.CritSect, VERR_IGNORED);
+    AssertRC(rc);
 #else
     int rc = PDMCritSectEnter(pVM, &pVM->pdm.s.CritSect, VERR_GENERAL_FAILURE);
-    if (rc == VERR_GENERAL_FAILURE)
-        rc = VMMRZCallRing3NoCpu(pVM, VMMCALLRING3_PDM_LOCK, 0);
+    if (RT_SUCCESS(rc))
+    { /* likely */ }
+    else
+    {
+        if (rc == VERR_GENERAL_FAILURE)
+            rc = VMMRZCallRing3NoCpu(pVM, VMMCALLRING3_PDM_LOCK, 0);
+        PDM_CRITSECT_RELEASE_ASSERT_RC(pVM, &pVM->pdm.s.CritSect, rc);
+    }
 #endif
-    AssertRC(rc);
 }
 
@@ -323,9 +331,9 @@
  * @returns rc if we're in GC or R0 and can't get the lock.
  * @param   pVM     The cross context VM structure.
- * @param   rc      The RC to return in GC or R0 when we can't get the lock.
- */
-int pdmLockEx(PVMCC pVM, int rc)
-{
-    return PDMCritSectEnter(pVM, &pVM->pdm.s.CritSect, rc);
+ * @param   rcBusy  The RC to return in GC or R0 when we can't get the lock.
+ */
+int pdmLockEx(PVMCC pVM, int rcBusy)
+{
+    return PDMCritSectEnter(pVM, &pVM->pdm.s.CritSect, rcBusy);
 }
 
Index: trunk/src/VBox/VMM/include/PDMInternal.h
===================================================================
--- trunk/src/VBox/VMM/include/PDMInternal.h	(revision 90434)
+++ trunk/src/VBox/VMM/include/PDMInternal.h	(revision 90436)
@@ -1694,5 +1694,5 @@
 
 void        pdmLock(PVMCC pVM);
-int         pdmLockEx(PVMCC pVM, int rc);
+int         pdmLockEx(PVMCC pVM, int rcBusy);
 void        pdmUnlock(PVMCC pVM);
 bool        pdmLockIsOwner(PVMCC pVM);
