Title: [294005] trunk/Source/WebKit
Revision
294005
Author
[email protected]
Date
2022-05-10 01:52:10 -0700 (Tue, 10 May 2022)

Log Message

RemoteVideoFrameObjectHeapProxyProcessor binary semaphore usage might trigger deadlocks in case of GPUProcess crash
https://bugs.webkit.org/show_bug.cgi?id=240161
<rdar://problem/92849827>

Reviewed by Eric Carlson.

In case of GPUProcess crash when waiting for a converted buffer, we would never call the semaphore signal method.
This would hang the main thread since this code path is main thread only.
To prevent this, we use synchronous IPC to send the buffer conversion order.
Once it is done, we use the binary semaphore to synchronize the main thread with the work queue on which we are receiving the converted buffer.
It is ok to use a binary semaphore at that point since we know the web process has or is processing the converted buffer IPC messages.
We also make sure to recreate the SharedVideoFrameWriter in case it was disabled due the GPUProcess connection being closed.

Covered by existing tests, in particular LayoutTests/webrtc/captureCanvas-webrtc.html.

* GPUProcess/media/RemoteVideoFrameObjectHeap.cpp:
(WebKit::RemoteVideoFrameObjectHeap::convertBuffer):
* GPUProcess/media/RemoteVideoFrameObjectHeap.h:
* GPUProcess/media/RemoteVideoFrameObjectHeap.messages.in:
* WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.cpp:
(WebKit::RemoteVideoFrameObjectHeapProxyProcessor::getNativeImage):
* WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.h:
* WebProcess/GPU/webrtc/SharedVideoFrame.h:
(WebKit::SharedVideoFrameWriter::isDisabled const):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (294004 => 294005)


--- trunk/Source/WebKit/ChangeLog	2022-05-10 07:45:49 UTC (rev 294004)
+++ trunk/Source/WebKit/ChangeLog	2022-05-10 08:52:10 UTC (rev 294005)
@@ -1,3 +1,30 @@
+2022-05-10  Youenn Fablet  <[email protected]>
+
+        RemoteVideoFrameObjectHeapProxyProcessor binary semaphore usage might trigger deadlocks in case of GPUProcess crash
+        https://bugs.webkit.org/show_bug.cgi?id=240161
+        <rdar://problem/92849827>
+
+        Reviewed by Eric Carlson.
+
+        In case of GPUProcess crash when waiting for a converted buffer, we would never call the semaphore signal method.
+        This would hang the main thread since this code path is main thread only.
+        To prevent this, we use synchronous IPC to send the buffer conversion order.
+        Once it is done, we use the binary semaphore to synchronize the main thread with the work queue on which we are receiving the converted buffer.
+        It is ok to use a binary semaphore at that point since we know the web process has or is processing the converted buffer IPC messages.
+        We also make sure to recreate the SharedVideoFrameWriter in case it was disabled due the GPUProcess connection being closed.
+
+        Covered by existing tests, in particular LayoutTests/webrtc/captureCanvas-webrtc.html.
+
+        * GPUProcess/media/RemoteVideoFrameObjectHeap.cpp:
+        (WebKit::RemoteVideoFrameObjectHeap::convertBuffer):
+        * GPUProcess/media/RemoteVideoFrameObjectHeap.h:
+        * GPUProcess/media/RemoteVideoFrameObjectHeap.messages.in:
+        * WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.cpp:
+        (WebKit::RemoteVideoFrameObjectHeapProxyProcessor::getNativeImage):
+        * WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.h:
+        * WebProcess/GPU/webrtc/SharedVideoFrame.h:
+        (WebKit::SharedVideoFrameWriter::isDisabled const):
+
 2022-05-07  Wenson Hsieh  <[email protected]>
 
         [iOS] Adjust some viewport behaviors when multitasking mode is enabled

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp (294004 => 294005)


--- trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp	2022-05-10 07:45:49 UTC (rev 294004)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp	2022-05-10 08:52:10 UTC (rev 294005)
@@ -31,6 +31,7 @@
 #include "RemoteVideoFrameObjectHeapMessages.h"
 #include "RemoteVideoFrameObjectHeapProxyProcessorMessages.h"
 #include "RemoteVideoFrameProxy.h"
+#include <wtf/Scope.h>
 #include <wtf/WorkQueue.h>
 
 #if PLATFORM(COCOA)
@@ -136,8 +137,10 @@
     completionHandler(WTFMove(pixelBuffer));
 }
 
-void RemoteVideoFrameObjectHeap::convertBuffer(SharedVideoFrame::Buffer&& buffer)
+void RemoteVideoFrameObjectHeap::convertBuffer(SharedVideoFrame::Buffer&& buffer, CompletionHandler<void()>&& callback)
 {
+    auto scope = makeScopeExit([&callback] { callback(); });
+
     auto pixelBuffer = m_sharedVideoFrameReader.readBuffer(WTFMove(buffer));
     if (!pixelBuffer) {
         m_connection->send(Messages::RemoteVideoFrameObjectHeapProxyProcessor::NewConvertedVideoFrameBuffer { { } }, 0);

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.h (294004 => 294005)


--- trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.h	2022-05-10 07:45:49 UTC (rev 294004)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.h	2022-05-10 08:52:10 UTC (rev 294005)
@@ -65,7 +65,7 @@
 #if PLATFORM(COCOA)
     void getVideoFrameBuffer(RemoteVideoFrameReadReference&&, bool canSendIOSurface);
     void pixelBuffer(RemoteVideoFrameReadReference&&, CompletionHandler<void(RetainPtr<CVPixelBufferRef>)>&&);
-    void convertBuffer(SharedVideoFrame::Buffer&&);
+    void convertBuffer(SharedVideoFrame::Buffer&&, CompletionHandler<void()>&&);
     void setSharedVideoFrameSemaphore(IPC::Semaphore&&);
     void setSharedVideoFrameMemory(const SharedMemory::IPCHandle&);
 #endif

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.messages.in (294004 => 294005)


--- trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.messages.in	2022-05-10 07:45:49 UTC (rev 294004)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.messages.in	2022-05-10 08:52:10 UTC (rev 294005)
@@ -28,7 +28,7 @@
     PixelBuffer(WebKit::RemoteVideoFrameReadReference read) -> (RetainPtr<CVPixelBufferRef> result) Synchronous
     SetSharedVideoFrameSemaphore(IPC::Semaphore semaphore)
     SetSharedVideoFrameMemory(WebKit::SharedMemory::IPCHandle storageHandle)
-    ConvertBuffer(struct WebKit::SharedVideoFrame::Buffer buffer)
+    ConvertBuffer(struct WebKit::SharedVideoFrame::Buffer buffer) -> () Synchronous
 #endif
     ReleaseVideoFrame(WebKit::RemoteVideoFrameWriteReference write)
 }

Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.cpp (294004 => 294005)


--- trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.cpp	2022-05-10 07:45:49 UTC (rev 294004)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.cpp	2022-05-10 08:52:10 UTC (rev 294005)
@@ -58,6 +58,7 @@
 
 void RemoteVideoFrameObjectHeapProxyProcessor::gpuProcessConnectionDidClose(GPUProcessConnection& connection)
 {
+    m_sharedVideoFrameWriter.disable();
     {
         Locker lock(m_connectionLock);
         m_connectionID = { };
@@ -133,6 +134,9 @@
 {
     auto& connection = WebProcess::singleton().ensureGPUProcessConnection().connection();
 
+    if (m_sharedVideoFrameWriter.isDisabled())
+        m_sharedVideoFrameWriter = { };
+
     auto nativePixelBuffer = videoFrame.pixelBuffer();
     auto colorSpace = createCGColorSpaceForCVPixelBuffer(nativePixelBuffer);
     auto buffer = m_sharedVideoFrameWriter.writeBuffer(nativePixelBuffer,
@@ -141,7 +145,12 @@
     if (!buffer)
         return nullptr;
 
-    connection.send(Messages::RemoteVideoFrameObjectHeap::ConvertBuffer { WTFMove(*buffer) }, 0);
+    auto result = connection.sendSync(Messages::RemoteVideoFrameObjectHeap::ConvertBuffer { *buffer }, Messages::RemoteVideoFrameObjectHeap::ConvertBuffer::Reply { }, 0, GPUProcessConnection::defaultTimeout);
+    if (!result) {
+        m_sharedVideoFrameWriter.disable();
+        return nullptr;
+    }
+
     m_conversionSemaphore.wait();
 
     auto pixelBuffer = WTFMove(m_convertedBuffer);

Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.h (294004 => 294005)


--- trunk/Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.h	2022-05-10 07:45:49 UTC (rev 294004)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.h	2022-05-10 08:52:10 UTC (rev 294005)
@@ -74,6 +74,7 @@
     std::optional<SharedVideoFrame::Buffer> writeBuffer(const webrtc::VideoFrame&, const Function<void(IPC::Semaphore&)>&, const Function<void(const SharedMemory::IPCHandle&)>&);
 #endif
     void disable();
+    bool isDisabled() const { return m_isDisabled; }
 
 private:
     bool wait(const Function<void(IPC::Semaphore&)>&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to