[{"id":15526,"web_url":"https://patchwork.libcamera.org/comment/15526/","msgid":"<YEZSMh1/zAp+CQBI@pendragon.ideasonboard.com>","date":"2021-03-08T16:34:58","subject":"Re: [libcamera-devel] [PATCH] libcamera: pipeline: ipu3: Stop IPA\n\tbefore stopping devices","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Mon, Mar 08, 2021 at 04:29:15PM +0000, Kieran Bingham wrote:\n> The IPA should be stopped before the hardware devices to ensure that\n> all asynchronous actions have completed within the IPA before resources\n> are removed and released.\n\nThis makes sense,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nI however wonder if we should set a \"stopping\" flag before calling\ndata->ipa_->stop(), to let the handlers for all the asynchronous actions\ninvoked during stop() know that we're stopping. This would for instance\nallow us to avoid requeing buffers unnecessarily. Maybe it's not the\nbest way to handle the issue, and in any case, if it's needed, it's a\ncandidate for a patch on top.\n\nDoes this solve the buffer queue after buffer free bug ?\n\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  src/libcamera/pipeline/ipu3/ipu3.cpp | 4 ++--\n>  1 file changed, 2 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index 2b4d31500533..498f85634a83 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -764,13 +764,13 @@ void PipelineHandlerIPU3::stop(Camera *camera)\n>  \tIPU3CameraData *data = cameraData(camera);\n>  \tint ret = 0;\n>  \n> +\tdata->ipa_->stop();\n> +\n>  \tret |= data->imgu_->stop();\n>  \tret |= data->cio2_.stop();\n>  \tif (ret)\n>  \t\tLOG(IPU3, Warning) << \"Failed to stop camera \" << camera->id();\n>  \n> -\tdata->ipa_->stop();\n> -\n>  \tfreeBuffers(camera);\n>  }\n>","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 90D6FBD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  8 Mar 2021 16:35:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E680668A92;\n\tMon,  8 Mar 2021 17:35:30 +0100 (CET)","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 A4D6260520\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  8 Mar 2021 17:35:29 +0100 (CET)","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 15B41AC1;\n\tMon,  8 Mar 2021 17:35:29 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"YoqY+uOs\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1615221329;\n\tbh=TnJ9I/6gGHthqTfsH+PFcb1nY5GNaPagA5aoaPfEVF0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=YoqY+uOsnAHzSiI5L1HjIjgzIxxgYGX8uW+zv5A0pucPqLTmqk40mjcxvYlD7mHfe\n\tjgKlNBSSSyMEjGOgRM1C6mkdRelQs3sMC2Hs4Tq6Ku6W64ezuFq1pO5KOkG37AjYIh\n\tv2Kz17NUKyvsfGh5Q0/O5uMpp+Z9Y6bbtA0bct2s=","Date":"Mon, 8 Mar 2021 18:34:58 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<YEZSMh1/zAp+CQBI@pendragon.ideasonboard.com>","References":"<20210308162915.523021-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210308162915.523021-1-kieran.bingham@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: pipeline: ipu3: Stop IPA\n\tbefore stopping devices","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 <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":15527,"web_url":"https://patchwork.libcamera.org/comment/15527/","msgid":"<YEZSwvfL1clHpgSZ@oden.dyn.berto.se>","date":"2021-03-08T16:37:22","subject":"Re: [libcamera-devel] [PATCH] libcamera: pipeline: ipu3: Stop IPA\n\tbefore stopping devices","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Kieran,\n\nOn 2021-03-08 16:29:15 +0000, Kieran Bingham wrote:\n> The IPA should be stopped before the hardware devices to ensure that\n> all asynchronous actions have completed within the IPA before resources\n> are removed and released.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  src/libcamera/pipeline/ipu3/ipu3.cpp | 4 ++--\n>  1 file changed, 2 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index 2b4d31500533..498f85634a83 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -764,13 +764,13 @@ void PipelineHandlerIPU3::stop(Camera *camera)\n>  \tIPU3CameraData *data = cameraData(camera);\n>  \tint ret = 0;\n>  \n> +\tdata->ipa_->stop();\n> +\n>  \tret |= data->imgu_->stop();\n>  \tret |= data->cio2_.stop();\n>  \tif (ret)\n>  \t\tLOG(IPU3, Warning) << \"Failed to stop camera \" << camera->id();\n>  \n> -\tdata->ipa_->stop();\n> -\n\nIIRC correctly this order was picked because before the cio2 is stopped \nbuffers may still be dequeued and therefor handed to the IPA for \nprocessing. This was however done before the new IPC change and with a \nmock IPA. How does this work with the new IPC/IPA if the pipeline \nhandler tries to post buffers to be processed before the CIO2 is \nstopped?\n\n\n>  \tfreeBuffers(camera);\n\nShould not all resources shared between pipeline and IPA be available \nuntil the buffers are freed here?\n\n>  }\n>  \n> -- \n> 2.25.1\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","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 0AE66BD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  8 Mar 2021 16:37:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7395C68A9F;\n\tMon,  8 Mar 2021 17:37:25 +0100 (CET)","from mail-lj1-x233.google.com (mail-lj1-x233.google.com\n\t[IPv6:2a00:1450:4864:20::233])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C827B60520\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  8 Mar 2021 17:37:24 +0100 (CET)","by mail-lj1-x233.google.com with SMTP id c19so8565125ljn.12\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 08 Mar 2021 08:37:24 -0800 (PST)","from localhost (h-209-203.A463.priv.bahnhof.se. [155.4.209.203])\n\tby smtp.gmail.com with ESMTPSA id\n\tz18sm1402618lfj.176.2021.03.08.08.37.23\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 08 Mar 2021 08:37:23 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com\n\theader.b=\"b6sNBJ4C\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=75W0Wd2IBABaoH6T7K+8Xsr8zGqdBS47P9lk7JiJ7ws=;\n\tb=b6sNBJ4C+dIgb2JnJ9US2ShKxWW5TyvgGNAt5Ay4MMk9+UTX7c6lLvgFIOyd43GQIN\n\tdMdoJJFCTq4LNA/MJqDg5AyoUy6uPzR6300hMaHN1EXV6SALSseCLJgvvrQz6Nxoj2It\n\tw2ykjF0O6lQyhARXOILvL+Zya2v7I5VaotkhoOqkpvHva3c8J1gavnXk2ro8G67Eo+Go\n\tObSqtHxdAMuiDnDLHilu9ia6GH4XFMTKCEY99Y4ITxf1OK0/blVBJ1lsLf1qkHxNpX89\n\tts/gJnqJPUfTgt6g81WlJs0gh+vtE0R7eDM9vmN7uUeap7u+f72pN+96rzIiL/u3LMS9\n\tsFCA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=75W0Wd2IBABaoH6T7K+8Xsr8zGqdBS47P9lk7JiJ7ws=;\n\tb=e4gvZotAGOj00wRUn/+NOo1GaBAXCYtqemwA2//HA6W3rMYOI6SoTVUFNt2oIp50ej\n\t5nK8KwQnrbXFqanA/0Bh0DMVDsLn/8WvYD294V1noMCF3DX2jpuP+/HnK8kJDhQN9iOB\n\taOS21lsbO9QTYE7ASCTx7lpna8u3gng54tQ6pmrx/Q1zauqubOrUnyJdT4yKRH0yYmx2\n\tw1RdzGaNcp8R6QCZFz8c/a1D7wFQWg0+XGxlYmeSeBsGXGZSPrwKz6JBVshseDa/LSus\n\tJZt7oTL4/m5cNv2201naE+340M7jBkGjXCfwustVt9NXimBN/oXTaYnsY2uZq6qWFWnn\n\tA3oA==","X-Gm-Message-State":"AOAM532vRqLINWcCmdzDdgLpJRIQUO/EY35rbT7tL7VJnuus0HvMPlTM\n\tg6ASuXxG8pC2WdwMOSoPW3RYcgu7grokXw==","X-Google-Smtp-Source":"ABdhPJyTK32gcrcYh/Oxwdenmn0qOyV5gJbiYTSolXzA5g6gBcCmIy7W9cx0p8hQv9RwvEwO3MWGvw==","X-Received":"by 2002:a2e:b888:: with SMTP id\n\tr8mr14079612ljp.505.1615221444032; \n\tMon, 08 Mar 2021 08:37:24 -0800 (PST)","Date":"Mon, 8 Mar 2021 17:37:22 +0100","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<YEZSwvfL1clHpgSZ@oden.dyn.berto.se>","References":"<20210308162915.523021-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210308162915.523021-1-kieran.bingham@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: pipeline: ipu3: Stop IPA\n\tbefore stopping devices","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 <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"iso-8859-1\"","Content-Transfer-Encoding":"quoted-printable","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":15528,"web_url":"https://patchwork.libcamera.org/comment/15528/","msgid":"<dadc113f-8135-8211-787f-9fc8035c737d@ideasonboard.com>","date":"2021-03-08T16:40:56","subject":"Re: [libcamera-devel] [PATCH] libcamera: pipeline: ipu3: Stop IPA\n\tbefore stopping devices","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"On 08/03/2021 16:37, Niklas Söderlund wrote:\n> Hi Kieran,\n> \n> On 2021-03-08 16:29:15 +0000, Kieran Bingham wrote:\n>> The IPA should be stopped before the hardware devices to ensure that\n>> all asynchronous actions have completed within the IPA before resources\n>> are removed and released.\n>>\n>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>> ---\n>>  src/libcamera/pipeline/ipu3/ipu3.cpp | 4 ++--\n>>  1 file changed, 2 insertions(+), 2 deletions(-)\n>>\n>> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n>> index 2b4d31500533..498f85634a83 100644\n>> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n>> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n>> @@ -764,13 +764,13 @@ void PipelineHandlerIPU3::stop(Camera *camera)\n>>  \tIPU3CameraData *data = cameraData(camera);\n>>  \tint ret = 0;\n>>  \n>> +\tdata->ipa_->stop();\n>> +\n>>  \tret |= data->imgu_->stop();\n>>  \tret |= data->cio2_.stop();\n>>  \tif (ret)\n>>  \t\tLOG(IPU3, Warning) << \"Failed to stop camera \" << camera->id();\n>>  \n>> -\tdata->ipa_->stop();\n>> -\n> \n> IIRC correctly this order was picked because before the cio2 is stopped \n> buffers may still be dequeued and therefor handed to the IPA for \n> processing. This was however done before the new IPC change and with a \n> mock IPA. How does this work with the new IPC/IPA if the pipeline \n> handler tries to post buffers to be processed before the CIO2 is \n> stopped?\n\nThe IPA before stopped sends events that cause thigns to be queued to\nthe v4l2 devices.\n\nThis hits the fact that the v42l buffer cache is null because the\nbuffers have been released.\n\nSo we must stop the IPA before the devices..\n\n\nBut then we must also make sure the IPA is not processing frames and\nevents from buffer completions after it has stopped....\n\n\n> \n>>  \tfreeBuffers(camera);\n> \n> Should not all resources shared between pipeline and IPA be available \n> until the buffers are freed here?\n\nWe're battling a use-after-free I think at the minute so indeed, this\ncould be relevant.\n\n> \n>>  }\n>>  \n>> -- \n>> 2.25.1\n>>\n>> _______________________________________________\n>> libcamera-devel mailing list\n>> libcamera-devel@lists.libcamera.org\n>> https://lists.libcamera.org/listinfo/libcamera-devel\n>","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 BF9B1BD80C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  8 Mar 2021 16:41:01 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 37B2568A9C;\n\tMon,  8 Mar 2021 17:41:01 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AF6C768A92\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  8 Mar 2021 17:40:59 +0100 (CET)","from [192.168.0.20]\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0D591AC1;\n\tMon,  8 Mar 2021 17:40:58 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"dEyjALs9\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1615221659;\n\tbh=5wopBX6Ayqb5JULe6+3RoiL/HcYY9Q3vuOzhFarjnuE=;\n\th=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From;\n\tb=dEyjALs9gUztXVjJTYNFcIEURrzJQ4XTNtXJLBQS0XipOsIRs3FKwcbZAohH84bHr\n\tUXJ3/vURqPx59zkKBGOrzVSgj/EVUTDQNNJkVtFdMqiijkkWPX++ptW6wWaVM93HfI\n\t106zM2/lbUAZRyyJiwpk9uvBqY4tLnNbyoj0THYs=","To":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","References":"<20210308162915.523021-1-kieran.bingham@ideasonboard.com>\n\t<YEZSwvfL1clHpgSZ@oden.dyn.berto.se>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ\n\tcSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf\n\tKr2EAbc6tgg6DkAEHJb+1okosV09+0+TXywYvtEop/WUOWQ+zo+Y/OBd+8Ptgt1pDRyOBzL8\n\tRXa8ZqRf0Mwg75D+dKntZeJHzPRJyrlfQokngAAs4PaFt6UfS+ypMAF37T6CeDArQC41V3ko\n\tlPn1yMsVD0p+6i3DPvA/GPIksDC4owjnzVX9kM8Zc5Cx+XoAN0w5Eqo4t6qEVbuettxx55gq\n\t8K8FieAjgjMSxngo/HST8TpFeqI5nVeq0/lqtBRQKumuIqDg+Bkr4L1V/PSB6XgQcOdhtd36\n\tOe9X9dXB8YSNt7VjOcO7BTmFn/Z8r92mSAfHXpb07YJWJosQOQARAQABtDBLaWVyYW4gQmlu\n\tZ2hhbSA8a2llcmFuLmJpbmdo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YenDx0Fg2BSlLvLvXM0vU8\n\tpQk3kgDu7kb/7PRYrZvBsr21EIQoIjXbZxDz/o7z95frkP71EaICttZ6k9q5oxxA5WC6sTXc\n\tMW8zs8avFNuA9VpXt0YupJd2ijtZy2mpZNG02fFVXhIn4G807G7+9mhuC4XG5rKlBBUXTvPU\n\tAfYnB4JBDLmLzBFavQfvonSfbitgXwCG3vS+9HEwAjU30Bar1PEOmIbiAoMzuKeRm2LVpmq4\n\tWZw01QYHU/GUV/zHJSFk","Organization":"Ideas on Board","Message-ID":"<dadc113f-8135-8211-787f-9fc8035c737d@ideasonboard.com>","Date":"Mon, 8 Mar 2021 16:40:56 +0000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101\n\tThunderbird/68.10.0","MIME-Version":"1.0","In-Reply-To":"<YEZSwvfL1clHpgSZ@oden.dyn.berto.se>","Content-Language":"en-GB","Subject":"Re: [libcamera-devel] [PATCH] libcamera: pipeline: ipu3: Stop IPA\n\tbefore stopping devices","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>","Reply-To":"kieran.bingham@ideasonboard.com","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":15529,"web_url":"https://patchwork.libcamera.org/comment/15529/","msgid":"<d840e72e-fa02-4944-d88a-e85896b7ad02@ideasonboard.com>","date":"2021-03-08T16:42:58","subject":"Re: [libcamera-devel] [PATCH] libcamera: pipeline: ipu3: Stop IPA\n\tbefore stopping devices","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"On 08/03/2021 16:34, Laurent Pinchart wrote:\n> Hi Kieran,\n> \n> Thank you for the patch.\n> \n> On Mon, Mar 08, 2021 at 04:29:15PM +0000, Kieran Bingham wrote:\n>> The IPA should be stopped before the hardware devices to ensure that\n>> all asynchronous actions have completed within the IPA before resources\n>> are removed and released.\n> \n> This makes sense,\n> \n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> I however wonder if we should set a \"stopping\" flag before calling\n> data->ipa_->stop(), to let the handlers for all the asynchronous actions\n> invoked during stop() know that we're stopping. This would for instance\n> allow us to avoid requeing buffers unnecessarily. Maybe it's not the\n> best way to handle the issue, and in any case, if it's needed, it's a\n> candidate for a patch on top.\n> \n> Does this solve the buffer queue after buffer free bug ?\n\n\nIt solves the buffer queue after device stop bug - but indeed, pulls out\n(or leaves visible) a use-after-free on the FrameBufferAllocator with\nwhat seems like a unique pointer to a FrameBuffer being around after the\nAllocator releases all the FrameBuffers...\n\nhttps://paste.debian.net/1188407/\n\n\n\n> \n>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>> ---\n>>  src/libcamera/pipeline/ipu3/ipu3.cpp | 4 ++--\n>>  1 file changed, 2 insertions(+), 2 deletions(-)\n>>\n>> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n>> index 2b4d31500533..498f85634a83 100644\n>> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n>> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n>> @@ -764,13 +764,13 @@ void PipelineHandlerIPU3::stop(Camera *camera)\n>>  \tIPU3CameraData *data = cameraData(camera);\n>>  \tint ret = 0;\n>>  \n>> +\tdata->ipa_->stop();\n>> +\n>>  \tret |= data->imgu_->stop();\n>>  \tret |= data->cio2_.stop();\n>>  \tif (ret)\n>>  \t\tLOG(IPU3, Warning) << \"Failed to stop camera \" << camera->id();\n>>  \n>> -\tdata->ipa_->stop();\n>> -\n>>  \tfreeBuffers(camera);\n>>  }\n>>  \n>","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 8CC68BD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  8 Mar 2021 16:43:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BAC7E68AA4;\n\tMon,  8 Mar 2021 17:43:02 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 18AF468A92\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  8 Mar 2021 17:43:01 +0100 (CET)","from [192.168.0.20]\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 84738AC1;\n\tMon,  8 Mar 2021 17:43:00 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"B4qLX2j4\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1615221780;\n\tbh=3n5l5dcnl78nCtwsvQ0utNBQs+T3ZKFp108fulH2ySQ=;\n\th=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From;\n\tb=B4qLX2j4p2YqKg7El6VdIDV8g15xcfNjRh9XhBqavXXFpYNwe1ARKLjXUSFjAW+XV\n\t40s/XhkvZbRrSFIhMAyl8Ebi1fw/ezYiGEGPD/J0U7blNfEA5UYRSRldwaV4yROSF6\n\tA83Xs+T/SGH1hj8D6JC6f5setBVjeY11S0T9HhSA=","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","References":"<20210308162915.523021-1-kieran.bingham@ideasonboard.com>\n\t<YEZSMh1/zAp+CQBI@pendragon.ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ\n\tcSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf\n\tKr2EAbc6tgg6DkAEHJb+1okosV09+0+TXywYvtEop/WUOWQ+zo+Y/OBd+8Ptgt1pDRyOBzL8\n\tRXa8ZqRf0Mwg75D+dKntZeJHzPRJyrlfQokngAAs4PaFt6UfS+ypMAF37T6CeDArQC41V3ko\n\tlPn1yMsVD0p+6i3DPvA/GPIksDC4owjnzVX9kM8Zc5Cx+XoAN0w5Eqo4t6qEVbuettxx55gq\n\t8K8FieAjgjMSxngo/H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VzSqMMIYkkZcjV2SWQyUGxSwq0O/sx\n\tS0A8/atCHUXOboUsn54qdxrVDaK+6jIAuo8JiRWctP16KjzUM7MO0/+4zllM8EY57rXrj48j\n\tsbEYX0YQnzaj+jO6kJtoZsIaYR7rMMq9aUAjyiaEZpmP1qF/2sYenDx0Fg2BSlLvLvXM0vU8\n\tpQk3kgDu7kb/7PRYrZvBsr21EIQoIjXbZxDz/o7z95frkP71EaICttZ6k9q5oxxA5WC6sTXc\n\tMW8zs8avFNuA9VpXt0YupJd2ijtZy2mpZNG02fFVXhIn4G807G7+9mhuC4XG5rKlBBUXTvPU\n\tAfYnB4JBDLmLzBFavQfvonSfbitgXwCG3vS+9HEwAjU30Bar1PEOmIbiAoMzuKeRm2LVpmq4\n\tWZw01QYHU/GUV/zHJSFk","Organization":"Ideas on Board","Message-ID":"<d840e72e-fa02-4944-d88a-e85896b7ad02@ideasonboard.com>","Date":"Mon, 8 Mar 2021 16:42:58 +0000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101\n\tThunderbird/68.10.0","MIME-Version":"1.0","In-Reply-To":"<YEZSMh1/zAp+CQBI@pendragon.ideasonboard.com>","Content-Language":"en-GB","Subject":"Re: [libcamera-devel] [PATCH] libcamera: pipeline: ipu3: Stop IPA\n\tbefore stopping devices","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>","Reply-To":"kieran.bingham@ideasonboard.com","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":15530,"web_url":"https://patchwork.libcamera.org/comment/15530/","msgid":"<7005e68b-2831-9e32-9b83-082fc8c2506b@ideasonboard.com>","date":"2021-03-08T16:46:12","subject":"Re: [libcamera-devel] [PATCH] libcamera: pipeline: ipu3: Stop IPA\n\tbefore stopping devices","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"On 08/03/2021 16:37, Niklas Söderlund wrote:\n> Hi Kieran,\n> \n> On 2021-03-08 16:29:15 +0000, Kieran Bingham wrote:\n>> The IPA should be stopped before the hardware devices to ensure that\n>> all asynchronous actions have completed within the IPA before resources\n>> are removed and released.\n>>\n>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>> ---\n>>  src/libcamera/pipeline/ipu3/ipu3.cpp | 4 ++--\n>>  1 file changed, 2 insertions(+), 2 deletions(-)\n>>\n>> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n>> index 2b4d31500533..498f85634a83 100644\n>> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n>> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n>> @@ -764,13 +764,13 @@ void PipelineHandlerIPU3::stop(Camera *camera)\n>>  \tIPU3CameraData *data = cameraData(camera);\n>>  \tint ret = 0;\n>>  \n>> +\tdata->ipa_->stop();\n>> +\n>>  \tret |= data->imgu_->stop();\n>>  \tret |= data->cio2_.stop();\n>>  \tif (ret)\n>>  \t\tLOG(IPU3, Warning) << \"Failed to stop camera \" << camera->id();\n>>  \n>> -\tdata->ipa_->stop();\n>> -\n> \n> IIRC correctly this order was picked because before the cio2 is stopped \n> buffers may still be dequeued and therefor handed to the IPA for \n> processing. This was however done before the new IPC change and with a \n> mock IPA. How does this work with the new IPC/IPA if the pipeline \n> handler tries to post buffers to be processed before the CIO2 is \n> stopped?\n> \n> \n>>  \tfreeBuffers(camera);\n> \n> Should not all resources shared between pipeline and IPA be available \n> until the buffers are freed here?\n\nfreeBuffers()  releases:\n\n  frameInfos->clear();\n  data->ipa_->unmapBuffers(ids);\n  ipaBuffers_.clear();\n  data->imgu_->freeBuffers();\n\nSurely we need to make sure both the devices and IPA have stopped before\nwe free these resources?\n\nSo I think freeBuffers should remain at the end...\n\n\n\n> \n>>  }\n>>  \n>> -- \n>> 2.25.1\n>>\n>> _______________________________________________\n>> libcamera-devel mailing list\n>> libcamera-devel@lists.libcamera.org\n>> https://lists.libcamera.org/listinfo/libcamera-devel\n>","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 2DD0EBD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  8 Mar 2021 16:46:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7BCB068AA4;\n\tMon,  8 Mar 2021 17:46:17 +0100 (CET)","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 0D02F68A92\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  8 Mar 2021 17:46:16 +0100 (CET)","from [192.168.0.20]\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4D36FAC1;\n\tMon,  8 Mar 2021 17:46:15 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Qn2W6DjW\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1615221975;\n\tbh=G7PkGNm74D1hf95UXJAGBXDLuVazqrSwhPbvjGaNwuQ=;\n\th=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From;\n\tb=Qn2W6DjWMgmyJnbhf+/pyxQWqdE+2B49LaFs7l6XYEzvvcLZF2TbE5w3BPWyL+qJK\n\tMYzhoFR9k1HkBak7ZILxsYTXfeDXXjPbC127TqFOY/+rWhZkJ34MUdHEKr7FZhhWtg\n\tzJ4JXEgIYOEXz7cJpfZNi3LWH9/qXzOiA63elEok=","To":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","References":"<20210308162915.523021-1-kieran.bingham@ideasonboard.com>\n\t<YEZSwvfL1clHpgSZ@oden.dyn.berto.se>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ\n\tcSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf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HNCeTkG7+qCDlSaBPclcPGYrTwCt0YWPU2TgGgJrVhYT20ierN8LUvj\n\t6qOPTd+Uk7NFzL65qkh80ZKNBFddx1AabQpSVQKbdcLb8OFs85kuSvFdgqZwgxA1vl4TFhNz\n\tPZ79NAmXLackAx3sOVFhk4WQaKRshCB7cSl+RIng5S/ThOBlwNlcKG7j7W2MC06BlTbdEkUp\n\tECzuuRBv8wX4OQl+hbWbB/VKIx5HKlLu1eypen/5lNVzSqMMIYkkZcjV2SWQyUGxSwq0O/sx\n\tS0A8/atCHUXOboUsn54qdxrVDaK+6jIAuo8JiRWctP16KjzUM7MO0/+4zllM8EY57rXrj48j\n\tsbEYX0YQnzaj+jO6kJtoZsIaYR7rMMq9aUAjyiaEZpmP1qF/2sYenDx0Fg2BSlLvLvXM0vU8\n\tpQk3kgDu7kb/7PRYrZvBsr21EIQoIjXbZxDz/o7z95frkP71EaICttZ6k9q5oxxA5WC6sTXc\n\tMW8zs8avFNuA9VpXt0YupJd2ijtZy2mpZNG02fFVXhIn4G807G7+9mhuC4XG5rKlBBUXTvPU\n\tAfYnB4JBDLmLzBFavQfvonSfbitgXwCG3vS+9HEwAjU30Bar1PEOmIbiAoMzuKeRm2LVpmq4\n\tWZw01QYHU/GUV/zHJSFk","Organization":"Ideas on Board","Message-ID":"<7005e68b-2831-9e32-9b83-082fc8c2506b@ideasonboard.com>","Date":"Mon, 8 Mar 2021 16:46:12 +0000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101\n\tThunderbird/68.10.0","MIME-Version":"1.0","In-Reply-To":"<YEZSwvfL1clHpgSZ@oden.dyn.berto.se>","Content-Language":"en-GB","Subject":"Re: [libcamera-devel] [PATCH] libcamera: pipeline: ipu3: Stop IPA\n\tbefore stopping devices","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>","Reply-To":"kieran.bingham@ideasonboard.com","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":15531,"web_url":"https://patchwork.libcamera.org/comment/15531/","msgid":"<YEZVfVxpJDCJq9QQ@pendragon.ideasonboard.com>","date":"2021-03-08T16:49:01","subject":"Re: [libcamera-devel] [PATCH] libcamera: pipeline: ipu3: Stop IPA\n\tbefore stopping devices","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nOn Mon, Mar 08, 2021 at 04:40:56PM +0000, Kieran Bingham wrote:\n> On 08/03/2021 16:37, Niklas Söderlund wrote:\n> > On 2021-03-08 16:29:15 +0000, Kieran Bingham wrote:\n> >> The IPA should be stopped before the hardware devices to ensure that\n> >> all asynchronous actions have completed within the IPA before resources\n> >> are removed and released.\n> >>\n> >> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> >> ---\n> >>  src/libcamera/pipeline/ipu3/ipu3.cpp | 4 ++--\n> >>  1 file changed, 2 insertions(+), 2 deletions(-)\n> >>\n> >> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> >> index 2b4d31500533..498f85634a83 100644\n> >> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> >> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> >> @@ -764,13 +764,13 @@ void PipelineHandlerIPU3::stop(Camera *camera)\n> >>  \tIPU3CameraData *data = cameraData(camera);\n> >>  \tint ret = 0;\n> >>  \n> >> +\tdata->ipa_->stop();\n> >> +\n> >>  \tret |= data->imgu_->stop();\n> >>  \tret |= data->cio2_.stop();\n> >>  \tif (ret)\n> >>  \t\tLOG(IPU3, Warning) << \"Failed to stop camera \" << camera->id();\n> >>  \n> >> -\tdata->ipa_->stop();\n> >> -\n> > \n> > IIRC correctly this order was picked because before the cio2 is stopped \n> > buffers may still be dequeued and therefor handed to the IPA for \n> > processing. This was however done before the new IPC change and with a \n> > mock IPA. How does this work with the new IPC/IPA if the pipeline \n> > handler tries to post buffers to be processed before the CIO2 is \n> > stopped?\n> \n> The IPA before stopped sends events that cause thigns to be queued to\n> the v4l2 devices.\n> \n> This hits the fact that the v42l buffer cache is null because the\n> buffers have been released.\n> \n> So we must stop the IPA before the devices..\n> \n> But then we must also make sure the IPA is not processing frames and\n> events from buffer completions after it has stopped....\n\nI don't think this can happen, as V4L2 events are processed in the event\nloop, and we don't return to the event loop between data->ipa_->stop()\nand the imgu and cio2 stop calls. The IPA stop() call is different, as\nit calls IPCPipeUnixSocket::call(), which has a manual call to\nThread::current()->eventDispatcher()->processEvents() to wait for the\nIPA response to the stop message.\n\nThere's a race condition there, as other events could also be processed.\nWe need to extend the EventDispatcher::processEvents() API to specify\nevent types (or something similar).\n\n> >>  \tfreeBuffers(camera);\n> > \n> > Should not all resources shared between pipeline and IPA be available \n> > until the buffers are freed here?\n> \n> We're battling a use-after-free I think at the minute so indeed, this\n> could be relevant.\n> \n> >>  }\n> >>","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 D3210BD80C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  8 Mar 2021 16:49:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3323368AA4;\n\tMon,  8 Mar 2021 17:49:35 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 09C8F68A92\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  8 Mar 2021 17:49:33 +0100 (CET)","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 7AB90AC1;\n\tMon,  8 Mar 2021 17:49:32 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"rz0zafhq\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1615222172;\n\tbh=hT5CXJtwLwANjXKLBwOuKTECouG1sWvoVM7ptw8snI8=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=rz0zafhqr4K2gzoGoJ8yr9qk+fk0dG465I6xcziP12+ElTPTPumVZLCwmtak1tPT8\n\t7GQaPCARiB45pA0mgkir4Aj8HqarA3oteF0i1Oz4baYkAPj/zIg3lQ2hAmGT64Bh0c\n\tTK8Jmj2NjbM8qmlzF+Nd78tLLTiSGthKHmrTdtZ0=","Date":"Mon, 8 Mar 2021 18:49:01 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<YEZVfVxpJDCJq9QQ@pendragon.ideasonboard.com>","References":"<20210308162915.523021-1-kieran.bingham@ideasonboard.com>\n\t<YEZSwvfL1clHpgSZ@oden.dyn.berto.se>\n\t<dadc113f-8135-8211-787f-9fc8035c737d@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<dadc113f-8135-8211-787f-9fc8035c737d@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: pipeline: ipu3: Stop IPA\n\tbefore stopping devices","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 <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]