{"id":13511,"url":"https://patchwork.libcamera.org/api/1.1/patches/13511/?format=json","web_url":"https://patchwork.libcamera.org/patch/13511/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210826132346.1238420-2-nicolas@ndufresne.ca>","date":"2021-08-26T13:23:44","name":"[libcamera-devel,v2,1/3] gstreamer: Fix deadlock when last allocator ref is held by buffer","commit_ref":"1ca5513396b4fa52f7305e19b7db0ae525dbd730","pull_url":null,"state":"accepted","archived":false,"hash":"21d5f46109b69cecc45d1edded7c0138359d5183","submitter":{"id":30,"url":"https://patchwork.libcamera.org/api/1.1/people/30/?format=json","name":"Nicolas Dufresne","email":"nicolas@ndufresne.ca"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13511/mbox/","series":[{"id":2399,"url":"https://patchwork.libcamera.org/api/1.1/series/2399/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2399","date":"2021-08-26T13:23:43","name":"Fix Gnome Cheese and multiple camera","version":2,"mbox":"https://patchwork.libcamera.org/series/2399/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13511/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13511/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 48FDBBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Aug 2021 13:24:02 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0675468925;\n\tThu, 26 Aug 2021 15:24:02 +0200 (CEST)","from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6771A68915\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Aug 2021 15:24:00 +0200 (CEST)","from [127.0.0.1] (localhost [127.0.0.1])\n\t(Authenticated sender: nicolas) with ESMTPSA id 7E3251F44332"],"From":"Nicolas Dufresne <nicolas@ndufresne.ca>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 26 Aug 2021 09:23:44 -0400","Message-Id":"<20210826132346.1238420-2-nicolas@ndufresne.ca>","X-Mailer":"git-send-email 2.31.1","In-Reply-To":"<20210826132346.1238420-1-nicolas@ndufresne.ca>","References":"<20210826132346.1238420-1-nicolas@ndufresne.ca>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 1/3] gstreamer: Fix deadlock when last\n\tallocator ref is held by buffer","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"Nicolas Dufresne <nicolas.dufresne@collabora.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n\nThis deadlock occurs when a buffer is holding the last reference on\nthe allocator. In gst_libcamera_allocator_release() we must drop the\nobject lock before dropping the last ref of that object since the\ndestructor will lock it again causing deadlock.\n\nThis was notice while switching camera or resolution in Cheese software.\n\nSigned-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/gstreamer/gstlibcameraallocator.cpp | 17 ++++++++++-------\n 1 file changed, 10 insertions(+), 7 deletions(-)","diff":"diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp\nindex 7bd8ba2d..a8fa4f86 100644\n--- a/src/gstreamer/gstlibcameraallocator.cpp\n+++ b/src/gstreamer/gstlibcameraallocator.cpp\n@@ -108,15 +108,18 @@ gst_libcamera_allocator_release(GstMiniObject *mini_object)\n {\n \tGstMemory *mem = GST_MEMORY_CAST(mini_object);\n \tGstLibcameraAllocator *self = GST_LIBCAMERA_ALLOCATOR(mem->allocator);\n-\tGLibLocker lock(GST_OBJECT(self));\n-\tauto *frame = reinterpret_cast<FrameWrap *>(gst_mini_object_get_qdata(mini_object, FrameWrap::getQuark()));\n \n-\tgst_memory_ref(mem);\n+\t{\n+\t\tGLibLocker lock(GST_OBJECT(self));\n+\t\tauto *frame = reinterpret_cast<FrameWrap *>(gst_mini_object_get_qdata(mini_object, FrameWrap::getQuark()));\n+\n+\t\tgst_memory_ref(mem);\n \n-\tif (frame->releasePlane()) {\n-\t\tauto *pool = reinterpret_cast<GQueue *>(g_hash_table_lookup(self->pools, frame->stream_));\n-\t\tg_return_val_if_fail(pool, TRUE);\n-\t\tg_queue_push_tail(pool, frame);\n+\t\tif (frame->releasePlane()) {\n+\t\t\tauto *pool = reinterpret_cast<GQueue *>(g_hash_table_lookup(self->pools, frame->stream_));\n+\t\t\tg_return_val_if_fail(pool, TRUE);\n+\t\t\tg_queue_push_tail(pool, frame);\n+\t\t}\n \t}\n \n \t/* Keep last in case we are holding on the last allocator ref. */\n","prefixes":["libcamera-devel","v2","1/3"]}