[{"id":34010,"web_url":"https://patchwork.libcamera.org/comment/34010/","msgid":"<174540091287.2882969.15475356577314669218@ping.linuxembedded.co.uk>","date":"2025-04-23T09:35:12","subject":"Re: [PATCH 01/27] libcamera: MappedFrameBuffer: Add tracking of mmap\n\tfile descriptors to MappedFrameBuffer","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Bryan O'Donoghue (2025-04-22 22:58:54)\n> In order to import via eglCreateImageKHR via an file descriptor we need to\n> have access to the file descriptor associated with the plane.\n> \n> Extend MappedFrameBuffer to track the file descriptor giving an accessor\n> method in-line with the existing planes_ accessor.\n> \n\nI expect the answers are later in the series, but I would expect if you\nneed the file descriptors - you should get them from the FrameBuffer\ndirectly, not the 'MappedFrameBuffer' otherwise you're just making a\ncopy of something you already have to be able to access it ? (It could\nbe fine - but depends on what the use case is)\n\n\n\n> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n> ---\n>  include/libcamera/internal/mapped_framebuffer.h | 2 ++\n>  src/libcamera/mapped_framebuffer.cpp            | 1 +\n>  2 files changed, 3 insertions(+)\n> \n> diff --git a/include/libcamera/internal/mapped_framebuffer.h b/include/libcamera/internal/mapped_framebuffer.h\n> index 6aaabf50..cb81243e 100644\n> --- a/include/libcamera/internal/mapped_framebuffer.h\n> +++ b/include/libcamera/internal/mapped_framebuffer.h\n> @@ -31,6 +31,7 @@ public:\n>         bool isValid() const { return error_ == 0; }\n>         int error() const { return error_; }\n>         const std::vector<Plane> &planes() const { return planes_; }\n> +       const std::vector<int> &fds() const { return fds_; }\n>  \n>  protected:\n>         MappedBuffer();\n> @@ -38,6 +39,7 @@ protected:\n>         int error_;\n>         std::vector<Plane> planes_;\n>         std::vector<Plane> maps_;\n> +       std::vector<int> fds_;\n>  \n>  private:\n>         LIBCAMERA_DISABLE_COPY(MappedBuffer)\n> diff --git a/src/libcamera/mapped_framebuffer.cpp b/src/libcamera/mapped_framebuffer.cpp\n> index f54bbf21..82ab132c 100644\n> --- a/src/libcamera/mapped_framebuffer.cpp\n> +++ b/src/libcamera/mapped_framebuffer.cpp\n> @@ -237,6 +237,7 @@ MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags)\n>                 }\n>  \n>                 planes_.emplace_back(info.address + plane.offset, plane.length);\n> +               fds_.emplace_back(fd);\n>         }\n>  }\n>  \n> -- \n> 2.49.0\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 831DEBE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 23 Apr 2025 09:35:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9306068ACB;\n\tWed, 23 Apr 2025 11:35:17 +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 2B3DE617E5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 23 Apr 2025 11:35:16 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9F9B522A;\n\tWed, 23 Apr 2025 11:35:14 +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=\"bY83w6EK\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1745400914;\n\tbh=0MevBbXZt6OBp0xs/cCfLy3sZ0XdLw/XbBMRGlrF3ic=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=bY83w6EKAUrF10Mf7LKpirKIdNzZMD1J3ZP4LdpQkQeQ9R9s5vS24wT+z+FjoYEDR\n\tDxuPdJXc6YxUaS4qJSRLxmHuI+gPE0FGM7GlR/OGuWE8xUF6DiHddkmYOBJhg+P7ht\n\t5KFMp2Ra2ftsThJkfx5vUuOlN4QEkjYY6C3Hfb8A=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250422215920.4297-2-bryan.odonoghue@linaro.org>","References":"<20250422215920.4297-1-bryan.odonoghue@linaro.org>\n\t<20250422215920.4297-2-bryan.odonoghue@linaro.org>","Subject":"Re: [PATCH 01/27] libcamera: MappedFrameBuffer: Add tracking of mmap\n\tfile descriptors to MappedFrameBuffer","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"hdegoede@redhat.com, mzamazal@redhat.com, bryan.odonoghue@linaro.org,\n\tbod.linux@nxsw.ie","To":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 23 Apr 2025 10:35:12 +0100","Message-ID":"<174540091287.2882969.15475356577314669218@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":34012,"web_url":"https://patchwork.libcamera.org/comment/34012/","msgid":"<20250423094334.GD17813@pendragon.ideasonboard.com>","date":"2025-04-23T09:43:34","subject":"Re: [PATCH 01/27] libcamera: MappedFrameBuffer: Add tracking of mmap\n\tfile descriptors to MappedFrameBuffer","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Wed, Apr 23, 2025 at 10:35:12AM +0100, Kieran Bingham wrote:\n> Quoting Bryan O'Donoghue (2025-04-22 22:58:54)\n> > In order to import via eglCreateImageKHR via an file descriptor we need to\n> > have access to the file descriptor associated with the plane.\n> > \n> > Extend MappedFrameBuffer to track the file descriptor giving an accessor\n> > method in-line with the existing planes_ accessor.\n> \n> I expect the answers are later in the series, but I would expect if you\n> need the file descriptors - you should get them from the FrameBuffer\n> directly, not the 'MappedFrameBuffer' otherwise you're just making a\n> copy of something you already have to be able to access it ? (It could\n> be fine - but depends on what the use case is)\n\nStoring them here as plain integers opens the door to use-after-free. I\nalso expect answers later in the series, let's see if we can make the\ncode harder to use incorrectly.\n\n> > Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n> > ---\n> >  include/libcamera/internal/mapped_framebuffer.h | 2 ++\n> >  src/libcamera/mapped_framebuffer.cpp            | 1 +\n> >  2 files changed, 3 insertions(+)\n> > \n> > diff --git a/include/libcamera/internal/mapped_framebuffer.h b/include/libcamera/internal/mapped_framebuffer.h\n> > index 6aaabf50..cb81243e 100644\n> > --- a/include/libcamera/internal/mapped_framebuffer.h\n> > +++ b/include/libcamera/internal/mapped_framebuffer.h\n> > @@ -31,6 +31,7 @@ public:\n> >         bool isValid() const { return error_ == 0; }\n> >         int error() const { return error_; }\n> >         const std::vector<Plane> &planes() const { return planes_; }\n> > +       const std::vector<int> &fds() const { return fds_; }\n> >  \n> >  protected:\n> >         MappedBuffer();\n> > @@ -38,6 +39,7 @@ protected:\n> >         int error_;\n> >         std::vector<Plane> planes_;\n> >         std::vector<Plane> maps_;\n> > +       std::vector<int> fds_;\n> >  \n> >  private:\n> >         LIBCAMERA_DISABLE_COPY(MappedBuffer)\n> > diff --git a/src/libcamera/mapped_framebuffer.cpp b/src/libcamera/mapped_framebuffer.cpp\n> > index f54bbf21..82ab132c 100644\n> > --- a/src/libcamera/mapped_framebuffer.cpp\n> > +++ b/src/libcamera/mapped_framebuffer.cpp\n> > @@ -237,6 +237,7 @@ MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags)\n> >                 }\n> >  \n> >                 planes_.emplace_back(info.address + plane.offset, plane.length);\n> > +               fds_.emplace_back(fd);\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 A314DBE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 23 Apr 2025 09:43:39 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BFBF268ACF;\n\tWed, 23 Apr 2025 11:43:38 +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 BA5CD68AC5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 23 Apr 2025 11:43:37 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DF75722A;\n\tWed, 23 Apr 2025 11:43:35 +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=\"ST3fSrZo\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1745401416;\n\tbh=RxJ0wEpMZmkVqgfR4jZc/t7f2hIn0vPiGQQEECUXogA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ST3fSrZoecuztOnPA18xbaKKXVvVy4nGV31No6LcIco1uKhwYot5jPP5rvBzcy9iL\n\tsBfxLtWe6XgmfqkFoQmhCVpYEAjIi39xCB1jg5gYrVpxCy+uOn1f97+M+mW+7IPEQq\n\tVkwPNxxhQdKiLWpfvoBqaQv8KyCrDFP+MMdymplY=","Date":"Wed, 23 Apr 2025 12:43:34 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>,\n\tlibcamera-devel@lists.libcamera.org, hdegoede@redhat.com,\n\tmzamazal@redhat.com, bod.linux@nxsw.ie","Subject":"Re: [PATCH 01/27] libcamera: MappedFrameBuffer: Add tracking of mmap\n\tfile descriptors to MappedFrameBuffer","Message-ID":"<20250423094334.GD17813@pendragon.ideasonboard.com>","References":"<20250422215920.4297-1-bryan.odonoghue@linaro.org>\n\t<20250422215920.4297-2-bryan.odonoghue@linaro.org>\n\t<174540091287.2882969.15475356577314669218@ping.linuxembedded.co.uk>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<174540091287.2882969.15475356577314669218@ping.linuxembedded.co.uk>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]