[{"id":33069,"web_url":"https://patchwork.libcamera.org/comment/33069/","msgid":"<85tta169sb.fsf@mzamazal-thinkpadp1gen3.tpbc.csb>","date":"2025-01-14T09:10:12","subject":"Re: [PATCH v2] DmaBufAllocator: Avoid syncing with an invalid file\n\tdescriptor","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Harvey Yang <chenghaoyang@chromium.org> writes:\n\n> As DmaSyncer disables the copy c'tor, the move c'tor will be used\n> instead. This leaves some DmaSyncers with invalid SharedFDs. They should\n> avoid syncing with invalid file descriptors in the d'tor.\n>\n> Fixes: 545046a41e17 (\"DmaBufAllocator: Make DmaSyncer non-copyable\")\n> Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>\n> Tested-by: Milan Zamazal <mzamazal@redhat.com>\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n> ---\n>  src/libcamera/dma_buf_allocator.cpp | 7 ++++++-\n>  1 file changed, 6 insertions(+), 1 deletion(-)\n>\n> diff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp\n> index a014c3b4263c..d8c62dd67a96 100644\n> --- a/src/libcamera/dma_buf_allocator.cpp\n> +++ b/src/libcamera/dma_buf_allocator.cpp\n> @@ -325,7 +325,12 @@ DmaSyncer::DmaSyncer(SharedFD fd, SyncType type)\n>  \n>  DmaSyncer::~DmaSyncer()\n>  {\n> -\tsync(DMA_BUF_SYNC_END);\n> +\t/*\n> +\t * DmaSyncer might be moved and left with an empty SharedFD.\n> +\t * Avoid syncing with an invalid file descriptor in this case.\n> +\t */\n> +\tif (fd_.isValid())\n> +\t\tsync(DMA_BUF_SYNC_END);\n>  }\n>  \n>  void DmaSyncer::sync(uint64_t step)","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 E2290C3304\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 14 Jan 2025 09:10:21 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BDE986851C;\n\tTue, 14 Jan 2025 10:10:20 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C783F608A9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Jan 2025 10:10:18 +0100 (CET)","from mail-wr1-f69.google.com (mail-wr1-f69.google.com\n\t[209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-317-rM8xpj59PWGjQHF0MsDndA-1; Tue, 14 Jan 2025 04:10:15 -0500","by mail-wr1-f69.google.com with SMTP id\n\tffacd0b85a97d-38a9118c486so3216659f8f.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Jan 2025 01:10:15 -0800 (PST)","from mzamazal-thinkpadp1gen3.tpbc.csb (nat-pool-brq-t.redhat.com.\n\t[213.175.37.10]) by smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-38a8e4b80b2sm14088361f8f.80.2025.01.14.01.10.12\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 14 Jan 2025 01:10:12 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"RUNjbr++\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1736845817;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=eo09kX4kUnk3ygIzLchKAEeJR7mSKRpZ9TTi8uTA1bA=;\n\tb=RUNjbr++Iz4vbHc1w/jZtypirW73ng0Tv8X8TxQdPmuMW9oNyz5gION0amJ3/HdrnF1zQr\n\tmDAS5X2vjgUfXN9YFKM1/zUXN3r0sgjEska8lJbhJS3CgWFMSKGUqNqMk3SUVSHaxlnJEZ\n\tP7w/be2VWEedjYgdELW5eXn0ZMmnqes=","X-MC-Unique":"rM8xpj59PWGjQHF0MsDndA-1","X-Mimecast-MFC-AGG-ID":"rM8xpj59PWGjQHF0MsDndA","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1736845814; x=1737450614;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=eo09kX4kUnk3ygIzLchKAEeJR7mSKRpZ9TTi8uTA1bA=;\n\tb=O8ZaKaovqIJsPZzDC4gVMVUNd0/VnZB5r0MGY6CHZ0epCW//xz/5AgrvCtoMV3vL89\n\tjk509FCV7KhU45AgpD7wNCGpjWC+uS9cCTOXL3XgxGZRL40caRihCosQ3nLczPasQzie\n\tTQL+rA1WrhFtq+NK0dzQ16RKFofsQCKo+BdSbjGuu2MB5lSqpJmBDfYqkxRrSdrvc4BZ\n\tLcqPzbjYuMBwpdZ7X56UZu0VT0xMioJbRijFeCwydySoYuOpWatMk39ZHCGLj80xDmOe\n\thh6/ByZX7i5OkE9VDnLekdWE6yjRp5OBmyVHQ8cqy2fBG42NRcXb27hbM4GaRiOACddt\n\tR4Dw==","X-Gm-Message-State":"AOJu0YwaRmbZ8aIvY+XJ2DNf/waGrJnxEIbtL0bkWOjYyfINzrzz5n3d\n\t9U3/7vGY6mso1aGP681HQvv0lugbMh66UtLW8IxnZ8FczBJFjsnMxR/CZlCizzdu8QJpNs03IQB\n\tBIF9LJ8dr+lcrdXmtQ9zFaQw0bjOMi6QESAkWA8/RjU9cLhz7kHxRAmhNqYXN6dvatmAcSjgvgx\n\tUtGKzHPkiNbDN4hgboMllYItWw5lm7wZdyCqvR8jizxePC8BnNd4QF7dc=","X-Gm-Gg":"ASbGnctVHpxIuURIiahxeRYKu1AI+WZJuVUe2tBHnCzWE7NPGnQytj0xWmP3L9fpQoe\n\tKyudPvtb482Ym9IEP+MDjuCXoqw3CqB3TJsb28PC4GpA8WAXppqLPMDiuggVKezCM2jAhCBUpDg\n\t+WSWlQUNtlLlv7fWohgegRJ7KomgKfGKdmQXhO1IxXsZq3FpPSfkEw8g3689yNUQP33crD79d1Z\n\tf24WmeTU/zEn5PMYPVe5E695SDRYT7S/VynNF04ZBN6NqHqQwZl29SYCCAXHdquzQlYS2VA82ym\n\twDFqfrQ++NtMHGWvCJHf8J+639JHLQNa","X-Received":["by 2002:a5d:47af:0:b0:38b:dbeb:63a2 with SMTP id\n\tffacd0b85a97d-38bdbeb64acmr6000602f8f.55.1736845814055; \n\tTue, 14 Jan 2025 01:10:14 -0800 (PST)","by 2002:a5d:47af:0:b0:38b:dbeb:63a2 with SMTP id\n\tffacd0b85a97d-38bdbeb64acmr6000570f8f.55.1736845813595; \n\tTue, 14 Jan 2025 01:10:13 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IGRjLNCQysccSS1+2hg7PjgOOQWoCqMCZYs3HA1SDxZu5Y4yo0C+49H5DuNGVmiXxfAy8N3BQ==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Harvey Yang <chenghaoyang@chromium.org>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v2] DmaBufAllocator: Avoid syncing with an invalid file\n\tdescriptor","In-Reply-To":"<20250113202843.843466-1-chenghaoyang@chromium.org> (Harvey\n\tYang's message of \"Mon, 13 Jan 2025 20:28:38 +0000\")","References":"<20250113202843.843466-1-chenghaoyang@chromium.org>","Date":"Tue, 14 Jan 2025 10:10:12 +0100","Message-ID":"<85tta169sb.fsf@mzamazal-thinkpadp1gen3.tpbc.csb>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"PRALHsjGgdTvaZKcHsGqt4ckRPQCsemN4ua2zq0Fj44_1736845815","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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":33080,"web_url":"https://patchwork.libcamera.org/comment/33080/","msgid":"<173689292855.1594000.1003498741832537352@ping.linuxembedded.co.uk>","date":"2025-01-14T22:15:28","subject":"Re: [PATCH v2] DmaBufAllocator: Avoid syncing with an invalid file\n\tdescriptor","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Milan Zamazal (2025-01-14 09:10:12)\n> Harvey Yang <chenghaoyang@chromium.org> writes:\n> \n> > As DmaSyncer disables the copy c'tor, the move c'tor will be used\n> > instead. This leaves some DmaSyncers with invalid SharedFDs. They should\n> > avoid syncing with invalid file descriptors in the d'tor.\n> >\n> > Fixes: 545046a41e17 (\"DmaBufAllocator: Make DmaSyncer non-copyable\")\n> > Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>\n> > Tested-by: Milan Zamazal <mzamazal@redhat.com>\n> \n> Reviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nWill push through CI and merge iff/when it completes.\n\n--\nKieran\n\n\n> \n> > ---\n> >  src/libcamera/dma_buf_allocator.cpp | 7 ++++++-\n> >  1 file changed, 6 insertions(+), 1 deletion(-)\n> >\n> > diff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp\n> > index a014c3b4263c..d8c62dd67a96 100644\n> > --- a/src/libcamera/dma_buf_allocator.cpp\n> > +++ b/src/libcamera/dma_buf_allocator.cpp\n> > @@ -325,7 +325,12 @@ DmaSyncer::DmaSyncer(SharedFD fd, SyncType type)\n> >  \n> >  DmaSyncer::~DmaSyncer()\n> >  {\n> > -     sync(DMA_BUF_SYNC_END);\n> > +     /*\n> > +      * DmaSyncer might be moved and left with an empty SharedFD.\n> > +      * Avoid syncing with an invalid file descriptor in this case.\n> > +      */\n> > +     if (fd_.isValid())\n> > +             sync(DMA_BUF_SYNC_END);\n> >  }\n> >  \n> >  void DmaSyncer::sync(uint64_t step)\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 364F8C3301\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 14 Jan 2025 22:15:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6F94D68521;\n\tTue, 14 Jan 2025 23:15:32 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 19CA8607D6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Jan 2025 23:15:31 +0100 (CET)","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 878947E9;\n\tTue, 14 Jan 2025 23:14:33 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Irp6xaQx\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1736892873;\n\tbh=nuFWIfMSHPI9xGhavUTraOM4Pqa3C8tq/2O3BRKF1EA=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=Irp6xaQxf6fqB597POTX1aM3dHEyh6CaWQ5oUBht4nozgl5wJ+7ckX8yHuZzBYj+T\n\tVmHa8u6DCaAV9K/qsOXiLXB/2ybhjkIrLZSXzLVSDO4xZJoH7pXF0BNAiX/aDv+m+y\n\tt10fDgw6brno58znfGifUymAJsWHG4sii4s7tAhg=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<85tta169sb.fsf@mzamazal-thinkpadp1gen3.tpbc.csb>","References":"<20250113202843.843466-1-chenghaoyang@chromium.org>\n\t<85tta169sb.fsf@mzamazal-thinkpadp1gen3.tpbc.csb>","Subject":"Re: [PATCH v2] DmaBufAllocator: Avoid syncing with an invalid file\n\tdescriptor","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","To":"Harvey Yang <chenghaoyang@chromium.org>,\n\tMilan Zamazal <mzamazal@redhat.com>","Date":"Tue, 14 Jan 2025 22:15:28 +0000","Message-ID":"<173689292855.1594000.1003498741832537352@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>"}}]