[{"id":19081,"web_url":"https://patchwork.libcamera.org/comment/19081/","msgid":"<YSbHO12/1EZHY34z@pendragon.ideasonboard.com>","date":"2021-08-25T22:42:03","subject":"Re: [libcamera-devel] [PATCH v1 1/3] gstreamer: Fix deadlock when\n\tlast allocator ref is held by buffer","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Nicolas,\n\nThank you for the patch.\n\nOn Wed, Aug 25, 2021 at 05:18:50PM -0400, Nicolas Dufresne wrote:\n> From: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n> \n> This deadlock occurs when a buffer is holding the last reference on\n> the allocator. In gst_libcamera_allocator_release() we must drop the\n> object lock before dropping the last ref of that object since the\n> destructor will lock it again causing deadlock.\n> \n> This was notice while switching camera or resolution in Cheese software.\n> \n> Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  src/gstreamer/gstlibcameraallocator.cpp | 17 ++++++++++-------\n>  1 file changed, 10 insertions(+), 7 deletions(-)\n> \n> diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp\n> index 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. */","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 3F6BEBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 25 Aug 2021 22:42:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 634BC60505;\n\tThu, 26 Aug 2021 00:42:18 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6805360504\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Aug 2021 00:42:16 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C92DC24F;\n\tThu, 26 Aug 2021 00:42:15 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"mrQCs6V4\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1629931336;\n\tbh=rOSVby6fovRKxs2dZjUbPtMT3KQoJsOU1lBBsynUX9I=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=mrQCs6V4zvyK2QbmfIew68idVXeUM6rkl/G95brNLv4821F+4xjVm1PeBaMMTOtP7\n\tfhsbmgIRK7sjAgrVm5prGU+z4y61tNcbOTTjhqMNqNqDldY6Mgsbneytj1KdG211kR\n\tYUzEVRyMysq+V0h/1JwprnkwkPMrkZFZQMx9xZac=","Date":"Thu, 26 Aug 2021 01:42:03 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Nicolas Dufresne <nicolas@ndufresne.ca>","Message-ID":"<YSbHO12/1EZHY34z@pendragon.ideasonboard.com>","References":"<20210825211852.1207168-1-nicolas@ndufresne.ca>\n\t<20210825211852.1207168-2-nicolas@ndufresne.ca>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20210825211852.1207168-2-nicolas@ndufresne.ca>","Subject":"Re: [libcamera-devel] [PATCH v1 1/3] gstreamer: Fix deadlock when\n\tlast allocator 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":"libcamera-devel@lists.libcamera.org,\n\tNicolas Dufresne <nicolas.dufresne@collabora.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]