[{"id":30541,"web_url":"https://patchwork.libcamera.org/comment/30541/","msgid":"<172258445022.2725865.9219461624389115207@ping.linuxembedded.co.uk>","date":"2024-08-02T07:40:50","subject":"Re: [PATCH 1/2] libcamera: v4l2_device: Retry ::ioctl on EINTR","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Umang,\n\nQuoting Umang Jain (2024-08-02 08:24:15)\n> V4L userspace API documentation clearly mentions the handling of\n> EINTR on ioctl(). Align with the xioctl() reference provided in [1].\n> \n> Retry the ::ioctl() if failed with errno == EINTR. Use a do..while{}\n> to check the return value of ::ioctl() and errno value. If the return\n> value is found to be -1, and errno is set with EINTR, the ioctl() call\n> should be retried.\n> \n> [1]: https://docs.kernel.org/userspace-api/media/v4l/capture.c.html\n> \n\nI haven't checked where, but I presume any of the operations that can be\nlong running or blocking in the kernel such as DQ_BUF would have\ninterruptible locks, which would make this important to have.\n\nBecause we use poll/select to only call those when we know there will be\nsomething available, I expect that the chance of hitting this is\nincredibly low, - but I do believe it's more correct to ensure we handle\nthis.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n> ---\n>  src/libcamera/v4l2_device.cpp | 8 +++++++-\n>  1 file changed, 7 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index 4a2048cf..2e92db0f 100644\n> --- a/src/libcamera/v4l2_device.cpp\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -454,11 +454,17 @@ int V4L2Device::setFrameStartEnabled(bool enable)\n>   */\n>  int V4L2Device::ioctl(unsigned long request, void *argp)\n>  {\n> +       int ret;\n> +\n> +       do {\n> +               ret = ::ioctl(fd_.get(), request, argp);\n> +       } while (ret == -1 && errno == EINTR);\n> +\n>         /*\n>          * Printing out an error message is usually better performed\n>          * in the caller, which can provide more context.\n>          */\n> -       if (::ioctl(fd_.get(), request, argp) < 0)\n> +       if (ret < 0)\n>                 return -errno;\n>  \n>         return 0;\n> -- \n> 2.45.2\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 35F70C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  2 Aug 2024 07:40:56 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 79E6363381;\n\tFri,  2 Aug 2024 09:40:55 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 732036195E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  2 Aug 2024 09:40:53 +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 3B6227F3;\n\tFri,  2 Aug 2024 09:40:04 +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=\"smxdInWl\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1722584404;\n\tbh=io7zdqrhrDZ+tNZf+tRJjDbKEWzU0fD5YLxlU9MWQhc=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=smxdInWlqY5PXBAHNYTm5k9TxmVfG3u5p/ZKXfjP8oeGD6ZQjAzJTNf9mL0gweoFp\n\tXF1PTBDJHPD6p5ceP6RA1glOjxN1eT2/gpLMJlmdw8fPyrXsoOVT+Dx6xpv+1Dmk3k\n\tE0pIPpE8o0qti2haPejUunP5Qr0Df4lcnpaTn0WU=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20240802072416.25297-2-umang.jain@ideasonboard.com>","References":"<20240802072416.25297-1-umang.jain@ideasonboard.com>\n\t<20240802072416.25297-2-umang.jain@ideasonboard.com>","Subject":"Re: [PATCH 1/2] libcamera: v4l2_device: Retry ::ioctl on EINTR","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Umang Jain <umang.jain@ideasonboard.com>","To":"Umang Jain <umang.jain@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 02 Aug 2024 08:40:50 +0100","Message-ID":"<172258445022.2725865.9219461624389115207@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":30543,"web_url":"https://patchwork.libcamera.org/comment/30543/","msgid":"<20240802120150.GE18732@pendragon.ideasonboard.com>","date":"2024-08-02T12:01:50","subject":"Re: [PATCH 1/2] libcamera: v4l2_device: Retry ::ioctl on EINTR","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Umang,\n\nThank you for the patch.\n\nOn Fri, Aug 02, 2024 at 12:54:15PM +0530, Umang Jain wrote:\n> V4L userspace API documentation clearly mentions the handling of\n> EINTR on ioctl(). Align with the xioctl() reference provided in [1].\n\nI'll need a better rationale, cargo-cult programming isn't a good enough\nexplanation.\n\n> Retry the ::ioctl() if failed with errno == EINTR. Use a do..while{}\n> to check the return value of ::ioctl() and errno value. If the return\n> value is found to be -1, and errno is set with EINTR, the ioctl() call\n> should be retried.\n> \n> [1]: https://docs.kernel.org/userspace-api/media/v4l/capture.c.html\n> \n> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n> ---\n>  src/libcamera/v4l2_device.cpp | 8 +++++++-\n>  1 file changed, 7 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index 4a2048cf..2e92db0f 100644\n> --- a/src/libcamera/v4l2_device.cpp\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -454,11 +454,17 @@ int V4L2Device::setFrameStartEnabled(bool enable)\n>   */\n>  int V4L2Device::ioctl(unsigned long request, void *argp)\n>  {\n> +\tint ret;\n> +\n> +\tdo {\n> +\t\tret = ::ioctl(fd_.get(), request, argp);\n> +\t} while (ret == -1 && errno == EINTR);\n> +\n>  \t/*\n>  \t * Printing out an error message is usually better performed\n>  \t * in the caller, which can provide more context.\n>  \t */\n> -\tif (::ioctl(fd_.get(), request, argp) < 0)\n> +\tif (ret < 0)\n>  \t\treturn -errno;\n>  \n>  \treturn 0;","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 2A966C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  2 Aug 2024 12:02:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1F40363381;\n\tFri,  2 Aug 2024 14:02:13 +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 2E3C36336B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  2 Aug 2024 14:02:11 +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 AC3A8524;\n\tFri,  2 Aug 2024 14:01:21 +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=\"ByjuDHud\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1722600081;\n\tbh=C2cIufy4vRhko51WDRrq5Jin8kJb+7hhc7Webs76pJU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ByjuDHud2ixM2Z4LPDDN/y3i+jK9lX284wT22NELKbt1arJCyZ7BvgwpTGF61h7TK\n\twzWm1G1yFvHBA4CcEdh1iMnhAWZQjDU3BgOELt/PJiVeTiA6GcpsGIWrZUIafQjE6+\n\tXTk1lQhsLFI2LUmDpnINFKsf9wJpDvdwcKMYEcpo=","Date":"Fri, 2 Aug 2024 15:01:50 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Umang Jain <umang.jain@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH 1/2] libcamera: v4l2_device: Retry ::ioctl on EINTR","Message-ID":"<20240802120150.GE18732@pendragon.ideasonboard.com>","References":"<20240802072416.25297-1-umang.jain@ideasonboard.com>\n\t<20240802072416.25297-2-umang.jain@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240802072416.25297-2-umang.jain@ideasonboard.com>","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":30545,"web_url":"https://patchwork.libcamera.org/comment/30545/","msgid":"<20240802130313.GG18732@pendragon.ideasonboard.com>","date":"2024-08-02T13:03:13","subject":"Re: [PATCH 1/2] libcamera: v4l2_device: Retry ::ioctl on EINTR","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Fri, Aug 02, 2024 at 08:40:50AM +0100, Kieran Bingham wrote:\n> Hi Umang,\n> \n> Quoting Umang Jain (2024-08-02 08:24:15)\n> > V4L userspace API documentation clearly mentions the handling of\n> > EINTR on ioctl(). Align with the xioctl() reference provided in [1].\n> > \n> > Retry the ::ioctl() if failed with errno == EINTR. Use a do..while{}\n> > to check the return value of ::ioctl() and errno value. If the return\n> > value is found to be -1, and errno is set with EINTR, the ioctl() call\n> > should be retried.\n> > \n> > [1]: https://docs.kernel.org/userspace-api/media/v4l/capture.c.html\n> > \n> \n> I haven't checked where, but I presume any of the operations that can be\n> long running or blocking in the kernel such as DQ_BUF would have\n> interruptible locks, which would make this important to have.\n> \n> Because we use poll/select to only call those when we know there will be\n> something available, I expect that the chance of hitting this is\n> incredibly low, - but I do believe it's more correct to ensure we handle\n> this.\n\nAnother piece of information that is missing from the commit message and\nthe cover letter is how this series came to be, and if it fixes a\nproblem that has been noticed.\n\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nThe implementation is too much of a hack for my taste. The coments on\n2/2 asking for factoring code out apply here too.\n\n> > Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n> > ---\n> >  src/libcamera/v4l2_device.cpp | 8 +++++++-\n> >  1 file changed, 7 insertions(+), 1 deletion(-)\n> > \n> > diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> > index 4a2048cf..2e92db0f 100644\n> > --- a/src/libcamera/v4l2_device.cpp\n> > +++ b/src/libcamera/v4l2_device.cpp\n> > @@ -454,11 +454,17 @@ int V4L2Device::setFrameStartEnabled(bool enable)\n> >   */\n> >  int V4L2Device::ioctl(unsigned long request, void *argp)\n> >  {\n> > +       int ret;\n> > +\n> > +       do {\n> > +               ret = ::ioctl(fd_.get(), request, argp);\n> > +       } while (ret == -1 && errno == EINTR);\n> > +\n> >         /*\n> >          * Printing out an error message is usually better performed\n> >          * in the caller, which can provide more context.\n> >          */\n> > -       if (::ioctl(fd_.get(), request, argp) < 0)\n> > +       if (ret < 0)\n> >                 return -errno;\n> >  \n> >         return 0;","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 05BD6C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  2 Aug 2024 13:03:36 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0F5A363383;\n\tFri,  2 Aug 2024 15:03:36 +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 89D906336B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  2 Aug 2024 15:03:34 +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 0E525496;\n\tFri,  2 Aug 2024 15:02:44 +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=\"ETDGtXnd\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1722603765;\n\tbh=x1l7G2tFY2TP9TYoKwG1PbJER+Dc+K4M04Pb4DoqQ6g=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ETDGtXndlKgLDZrm4dhjNkOXmLA5Rcx2z+QFYTVTxr+Xqgb7P6lcZu6j08wvrMxXB\n\tCozukwlsxX8znxvfy1oMNYWb2NOW41cxEBgqwTYUO7NvGAiHGAu2CLnDHxzPtfsTtK\n\tDZ+CHwCGO/ejBzEctMiTG5kzO4keuBMxolBoQk24=","Date":"Fri, 2 Aug 2024 16:03:13 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Umang Jain <umang.jain@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH 1/2] libcamera: v4l2_device: Retry ::ioctl on EINTR","Message-ID":"<20240802130313.GG18732@pendragon.ideasonboard.com>","References":"<20240802072416.25297-1-umang.jain@ideasonboard.com>\n\t<20240802072416.25297-2-umang.jain@ideasonboard.com>\n\t<172258445022.2725865.9219461624389115207@ping.linuxembedded.co.uk>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<172258445022.2725865.9219461624389115207@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>"}}]