[NTOSKRNL] When marking a VACB dirty on unmap/unpin, use CcRosMarkDirtyVacb().
authorPierre Schweitzer <pierre@reactos.org>
Sat, 27 Jan 2018 09:57:50 +0000 (10:57 +0100)
committerPierre Schweitzer <pierre@reactos.org>
Sat, 27 Jan 2018 09:59:27 +0000 (10:59 +0100)
This should help reducing race conditions with lazy writer, and thus reduce random BSODs.

CORE-14263

ntoskrnl/cc/view.c

index 0340c68..706623b 100644 (file)
@@ -517,26 +517,25 @@ CcRosReleaseVacb (
     BOOLEAN Mapped)
 {
     BOOLEAN WasDirty;
-    KIRQL oldIrql;
 
     ASSERT(SharedCacheMap);
 
     DPRINT("CcRosReleaseVacb(SharedCacheMap 0x%p, Vacb 0x%p, Valid %u)\n",
            SharedCacheMap, Vacb, Valid);
 
-    KeAcquireGuardedMutex(&ViewLock);
-    KeAcquireSpinLock(&SharedCacheMap->CacheMapLock, &oldIrql);
-
     Vacb->Valid = Valid;
 
-    WasDirty = Vacb->Dirty;
-    Vacb->Dirty = Vacb->Dirty || Dirty;
-
-    if (!WasDirty && Vacb->Dirty)
+    WasDirty = FALSE;
+    if (Dirty)
     {
-        InsertTailList(&DirtyVacbListHead, &Vacb->DirtyVacbListEntry);
-        CcTotalDirtyPages += VACB_MAPPING_GRANULARITY / PAGE_SIZE;
-        Vacb->SharedCacheMap->DirtyPages += VACB_MAPPING_GRANULARITY / PAGE_SIZE;
+        if (!Vacb->Dirty && Dirty)
+        {
+            CcRosMarkDirtyVacb(Vacb);
+        }
+        else
+        {
+            WasDirty = TRUE;
+        }
     }
 
     if (Mapped)
@@ -553,8 +552,6 @@ CcRosReleaseVacb (
         CcRosVacbIncRefCount(Vacb);
     }
 
-    KeReleaseSpinLock(&SharedCacheMap->CacheMapLock, oldIrql);
-    KeReleaseGuardedMutex(&ViewLock);
     CcRosReleaseVacbLock(Vacb);
 
     return STATUS_SUCCESS;
@@ -676,7 +673,6 @@ CcRosUnmapVacb (
 {
     PROS_VACB Vacb;
     BOOLEAN WasDirty;
-    KIRQL oldIrql;
 
     ASSERT(SharedCacheMap);
 
@@ -689,21 +685,21 @@ CcRosUnmapVacb (
         return STATUS_UNSUCCESSFUL;
     }
 
-    KeAcquireGuardedMutex(&ViewLock);
-    KeAcquireSpinLock(&SharedCacheMap->CacheMapLock, &oldIrql);
-
-    WasDirty = Vacb->Dirty;
-    Vacb->Dirty = Vacb->Dirty || NowDirty;
-
-    Vacb->MappedCount--;
-
-    if (!WasDirty && NowDirty)
+    WasDirty = FALSE;
+    if (NowDirty)
     {
-        InsertTailList(&DirtyVacbListHead, &Vacb->DirtyVacbListEntry);
-        CcTotalDirtyPages += VACB_MAPPING_GRANULARITY / PAGE_SIZE;
-        Vacb->SharedCacheMap->DirtyPages += VACB_MAPPING_GRANULARITY / PAGE_SIZE;
+        if (!Vacb->Dirty && NowDirty)
+        {
+            CcRosMarkDirtyVacb(Vacb);
+        }
+        else
+        {
+            WasDirty = TRUE;
+        }
     }
 
+    Vacb->MappedCount--;
+
     CcRosVacbDecRefCount(Vacb);
     if (!WasDirty && NowDirty)
     {
@@ -714,8 +710,6 @@ CcRosUnmapVacb (
         CcRosVacbDecRefCount(Vacb);
     }
 
-    KeReleaseSpinLock(&SharedCacheMap->CacheMapLock, oldIrql);
-    KeReleaseGuardedMutex(&ViewLock);
     CcRosReleaseVacbLock(Vacb);
 
     return STATUS_SUCCESS;