Title: [291881] trunk/Source/WebKit
Revision
291881
Author
[email protected]
Date
2022-03-25 13:07:32 -0700 (Fri, 25 Mar 2022)

Log Message

[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):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (291880 => 291881)


--- trunk/Source/WebKit/ChangeLog	2022-03-25 19:34:19 UTC (rev 291880)
+++ trunk/Source/WebKit/ChangeLog	2022-03-25 20:07:32 UTC (rev 291881)
@@ -1,3 +1,34 @@
+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-03-25  Per Arne Vollan  <[email protected]>
 
         [macOS][WP] Remove unused sandbox extension rule

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp (291880 => 291881)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp	2022-03-25 19:34:19 UTC (rev 291880)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp	2022-03-25 20:07:32 UTC (rev 291881)
@@ -114,9 +114,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