Title: [292655] branches/safari-613-branch/Source/WebKit
Revision
292655
Author
[email protected]
Date
2022-04-08 17:13:44 -0700 (Fri, 08 Apr 2022)

Log Message

Cherry-pick r291881. rdar://problem/90848454

    [GPU Process] RemoteRenderingBackend::stopListeningForIPC() should not change the RemoteResourceCache on the main thread
    https://bugs.webkit.org/show_bug.cgi?id=238298
    rdar://90731372

    Reviewed by Simon Fraser.

    To release the RemoteResourceCache and the rendering resource request on
    the WorkQueue thread, RemoteRenderingBackend::stopListeningForIPC() dispatches
    an empty lambda to its WorkQueue but m_renderingResourcesRequest and
    m_remoteResourceCache are captured by-move to initializers to this lambda.

    But this means m_remoteResourceCache is changed on the main thread while
    the WorkQueue thread may be accessing it to get a cached remote resource.
    The EWS crashes showed that, RemoteRenderingBackend::stopListeningForIPC()
    on the main thread is waiting its WorkQueue to stop and complete all its
    work including the dispatched empty lambda. And the WorkQueue thread is
    getting wrong resource counters from the RemoteResourceCache. This would
    happen if the HashMaps of RemoteResourceCache were emptied on the main
    thread while the counters had outdated values.

    To fix this thread safety issue, the RemoteResourceCache should not ever
    be changed on the main thread. Since capturing by-move is kind of change,
    we will capture m_renderingResourcesRequest and m_remoteResourceCache by
    reference and we let the dispatched lambda explicitly releases them on
    the WorkQueue thread.

    * GPUProcess/graphics/RemoteRenderingBackend.cpp:
    (WebKit::RemoteRenderingBackend::stopListeningForIPC):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@291881 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-613-branch/Source/WebKit/ChangeLog (292654 => 292655)


--- branches/safari-613-branch/Source/WebKit/ChangeLog	2022-04-09 00:13:42 UTC (rev 292654)
+++ branches/safari-613-branch/Source/WebKit/ChangeLog	2022-04-09 00:13:44 UTC (rev 292655)
@@ -1,5 +1,72 @@
 2022-04-07  Alan Coon  <[email protected]>
 
+        Cherry-pick r291881. rdar://problem/90848454
+
+    [GPU Process] RemoteRenderingBackend::stopListeningForIPC() should not change the RemoteResourceCache on the main thread
+    https://bugs.webkit.org/show_bug.cgi?id=238298
+    rdar://90731372
+    
+    Reviewed by Simon Fraser.
+    
+    To release the RemoteResourceCache and the rendering resource request on
+    the WorkQueue thread, RemoteRenderingBackend::stopListeningForIPC() dispatches
+    an empty lambda to its WorkQueue but m_renderingResourcesRequest and
+    m_remoteResourceCache are captured by-move to initializers to this lambda.
+    
+    But this means m_remoteResourceCache is changed on the main thread while
+    the WorkQueue thread may be accessing it to get a cached remote resource.
+    The EWS crashes showed that, RemoteRenderingBackend::stopListeningForIPC()
+    on the main thread is waiting its WorkQueue to stop and complete all its
+    work including the dispatched empty lambda. And the WorkQueue thread is
+    getting wrong resource counters from the RemoteResourceCache. This would
+    happen if the HashMaps of RemoteResourceCache were emptied on the main
+    thread while the counters had outdated values.
+    
+    To fix this thread safety issue, the RemoteResourceCache should not ever
+    be changed on the main thread. Since capturing by-move is kind of change,
+    we will capture m_renderingResourcesRequest and m_remoteResourceCache by
+    reference and we let the dispatched lambda explicitly releases them on
+    the WorkQueue thread.
+    
+    * GPUProcess/graphics/RemoteRenderingBackend.cpp:
+    (WebKit::RemoteRenderingBackend::stopListeningForIPC):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@291881 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-03-25  Said Abou-Hallawa  <[email protected]>
+
+            [GPU Process] RemoteRenderingBackend::stopListeningForIPC() should not change the RemoteResourceCache on the main thread
+            https://bugs.webkit.org/show_bug.cgi?id=238298
+            rdar://90731372
+
+            Reviewed by Simon Fraser.
+
+            To release the RemoteResourceCache and the rendering resource request on
+            the WorkQueue thread, RemoteRenderingBackend::stopListeningForIPC() dispatches
+            an empty lambda to its WorkQueue but m_renderingResourcesRequest and
+            m_remoteResourceCache are captured by-move to initializers to this lambda.
+
+            But this means m_remoteResourceCache is changed on the main thread while
+            the WorkQueue thread may be accessing it to get a cached remote resource.
+            The EWS crashes showed that, RemoteRenderingBackend::stopListeningForIPC()
+            on the main thread is waiting its WorkQueue to stop and complete all its
+            work including the dispatched empty lambda. And the WorkQueue thread is
+            getting wrong resource counters from the RemoteResourceCache. This would
+            happen if the HashMaps of RemoteResourceCache were emptied on the main
+            thread while the counters had outdated values.
+
+            To fix this thread safety issue, the RemoteResourceCache should not ever
+            be changed on the main thread. Since capturing by-move is kind of change,
+            we will capture m_renderingResourcesRequest and m_remoteResourceCache by
+            reference and we let the dispatched lambda explicitly releases them on
+            the WorkQueue thread.
+
+            * GPUProcess/graphics/RemoteRenderingBackend.cpp:
+            (WebKit::RemoteRenderingBackend::stopListeningForIPC):
+
+2022-04-07  Alan Coon  <[email protected]>
+
         Cherry-pick r291821. rdar://problem/89145552
 
     REGRESSION(r286590): Links with URL schemes are not clickable in Mail

Modified: branches/safari-613-branch/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp (292654 => 292655)


--- branches/safari-613-branch/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp	2022-04-09 00:13:42 UTC (rev 292654)
+++ branches/safari-613-branch/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp	2022-04-09 00:13:44 UTC (rev 292655)
@@ -112,9 +112,14 @@
 void RemoteRenderingBackend::stopListeningForIPC()
 {
     ASSERT(RunLoop::isMain());
-    // Make sure we destroy the ResourceCache on the WorkQueue since it gets populated on the WorkQueue.
-    // Make sure rendering resource request is released after destroying the cache.
-    m_workQueue->dispatch([renderingResourcesRequest = WTFMove(m_renderingResourcesRequest), remoteResourceCache = WTFMove(m_remoteResourceCache)] { });
+
+    // This item is dispatched to the WorkQueue before calling stopAndWaitForCompletion() such that it will process it last, after any existing work.
+    m_workQueue->dispatch([&] {
+        // Make sure we destroy the ResourceCache on the WorkQueue since it gets populated on the WorkQueue.
+        // Make sure rendering resource request is released after destroying the cache.
+        m_remoteResourceCache = { m_gpuConnectionToWebProcess->webProcessIdentifier() };
+        m_renderingResourcesRequest = { };
+    });
     m_workQueue->stopAndWaitForCompletion();
 
     m_streamConnection->stopReceivingMessages(Messages::RemoteRenderingBackend::messageReceiverName(), m_renderingBackendIdentifier.toUInt64());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to