From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB65EC5517A for ; Wed, 11 Nov 2020 12:59:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 70A79207BB for ; Wed, 11 Nov 2020 12:59:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JS4mU4TA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726460AbgKKM7Q (ORCPT ); Wed, 11 Nov 2020 07:59:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726274AbgKKM7N (ORCPT ); Wed, 11 Nov 2020 07:59:13 -0500 Received: from mail-vs1-xe43.google.com (mail-vs1-xe43.google.com [IPv6:2607:f8b0:4864:20::e43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8FF5C0613D1; Wed, 11 Nov 2020 04:59:12 -0800 (PST) Received: by mail-vs1-xe43.google.com with SMTP id f7so1080660vsh.10; Wed, 11 Nov 2020 04:59:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=9c3b8G3Bp/cuV3iOdFfs+mQaVoix3q8VFUXW2JYkOJQ=; b=JS4mU4TAuC8UfNRLQo95j74Wy0bpKCMyF8bH5vLzs9bKuYtLVM6YkEAeiFEonVHand Ni2go2VCz4ILd0adRuV1owHsCY/TIPVK/2E25+rNeel1a2Y19XBTiumoMfSGlQ66psIc 09OMIhdpUnI4yCYq8mHpMku3df28dEXiMztX8d/DcxnbyBrZMpFFSpU6dx/K5pgjfQ3b 8Eja/FZBwDUj+S++A3aD+4DZLkS2A04Eso9AY0Znh8jk0g492aj0dbZ4fhUxubMf7qlk Ru22dPSEzoVZ1mVJMWaZR9gNL731G5OW30i6NQ6vs10IhQRpxSatzRAaFHL/bMdRQhUU nuiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=9c3b8G3Bp/cuV3iOdFfs+mQaVoix3q8VFUXW2JYkOJQ=; b=r2kOviNQlKOdhInu3zKOQwSS2hISSP+mlwoFc9AVf5GjPcqp6PkN0ezWQWSJRj1TmH rxjrosPnE9hsipA6LNLq1mE2P6vUf94N9y3LQWtKbMHGMMjpf2T/l6xt5Ynsbl8Cexsy S7vvR/jK3F6neiVYcXanhUveZbF+bOF1Bxa2vjvl8OgYzzVXwoXLPLzlEunfU2FYlhSh 42pFCv+LWo1vQMRatf1CCF2APjWMkN8v+xE70pnMLN9+j0uRyoax/WHpV3X6UzlcDnw6 04wXs6pMlTvtT7YJkeflt1hxwGpaNsBiInaWc24ALoaZ7kNBj0L0bYRojZ/T0XYaW0y2 LkdA== X-Gm-Message-State: AOAM531NcGCmeK80yPoglaUq5Yp/P5HUTJpZ2rciF6h89V8wBr46mq2M M+ZwwpeXih8y+m1NJa3FolaPQPmTXZJhmq9jOPI= X-Google-Smtp-Source: ABdhPJxx5ZveZN11JVa/zAFlTsBoln+le6QOzs1ZvpO1w5LVcCP89v3xSBnP3RcHANUcvzBQszK/3eboE63M/C9qVH0= X-Received: by 2002:a67:fa10:: with SMTP id i16mr16212531vsq.3.1605099551606; Wed, 11 Nov 2020 04:59:11 -0800 (PST) MIME-Version: 1.0 References: <20201022122421.133976-1-gnurou@gmail.com> <695e6163-7bdc-d120-cd02-0cff6efb53ef@xs4all.nl> <92db8b0e-c348-70ef-a607-eb5c42f86fac@xs4all.nl> <817895e0-6207-9fbb-5581-0bf784c63915@xs4all.nl> In-Reply-To: <817895e0-6207-9fbb-5581-0bf784c63915@xs4all.nl> From: Alexandre Courbot Date: Wed, 11 Nov 2020 21:58:59 +0900 Message-ID: Subject: Re: [PATCH] media: v4l2-mem2mem: always call poll_wait() on queues To: Hans Verkuil Cc: Mauro Carvalho Chehab , linux-media , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org On Wed, Nov 11, 2020 at 9:47 PM Hans Verkuil wrote: > > On 11/11/2020 13:41, Alexandre Courbot wrote: > > On Thu, Nov 5, 2020 at 11:05 PM Alexandre Courbot wrote: > >> > >> On Thu, Nov 5, 2020 at 10:12 PM Hans Verkuil wrote: > >>> > >>> On 05/11/2020 13:52, Alexandre Courbot wrote: > >>>> On Thu, Nov 5, 2020 at 9:36 PM Hans Verkuil wrote: > >>>>> > >>>>> On 05/11/2020 13:21, Alexandre Courbot wrote: > >>>>>> On Tue, Nov 3, 2020 at 6:48 PM Hans Verkuil wrote: > >>>>>>> > >>>>>>> On 03/11/2020 09:51, Alexandre Courbot wrote: > >>>>>>>> Hi Hans, > >>>>>>>> > >>>>>>>> On Sat, Oct 31, 2020 at 12:09 AM Hans Verkuil wrote: > >>>>>>>>> > >>>>>>>>> On 22/10/2020 14:24, Alexandre Courbot wrote: > >>>>>>>>>> do_poll()/do_select() seem to set the _qproc member of poll_table to > >>>>>>>>>> NULL the first time they are called on a given table, making subsequent > >>>>>>>>>> calls of poll_wait() on that table no-ops. This is a problem for mem2mem > >>>>>>>>>> which calls poll_wait() on the V4L2 queues' waitqueues only when a > >>>>>>>>>> queue-related event is requested, which may not necessarily be the case > >>>>>>>>>> during the first poll. > >>>>>>>>>> > >>>>>>>>>> For instance, a stateful decoder is typically only interested in > >>>>>>>>>> EPOLLPRI events when it starts, and will switch to listening to both > >>>>>>>>>> EPOLLPRI and EPOLLIN after receiving the initial resolution change event > >>>>>>>>>> and configuring the CAPTURE queue. However by the time that switch > >>>>>>>>>> happens and v4l2_m2m_poll_for_data() is called for the first time, > >>>>>>>>>> poll_wait() has become a no-op and the V4L2 queues waitqueues thus > >>>>>>>>>> cannot be registered. > >>>>>>>>>> > >>>>>>>>>> Fix this by moving the registration to v4l2_m2m_poll() and do it whether > >>>>>>>>>> or not one of the queue-related events are requested. > >>>>>>>>> > >>>>>>>>> This looks good, but would it be possible to add a test for this to > >>>>>>>>> v4l2-compliance? (Look for POLL_MODE_EPOLL in v4l2-test-buffers.cpp) > >>>>>>>>> > >>>>>>>>> If I understand this right, calling EPOLL_CTL_ADD for EPOLLPRI, then > >>>>>>>>> calling EPOLL_CTL_ADD for EPOLLIN/OUT would trigger this? Or does there > >>>>>>>>> have to be an epoll_wait call in between? > >>>>>>>> > >>>>>>>> Even without an epoll_wait() in between the behavior is visible. > >>>>>>>> v4l2_m2m_poll() will be called once during the initial EPOLL_CTL_ADD > >>>>>>>> and this will trigger the bug. > >>>>>>>> > >>>>>>>>> Another reason for adding this test is that I wonder if regular capture > >>>>>>>>> or output V4L2 devices don't have the same issue. > >>>>>>>>> > >>>>>>>>> It's a very subtle bug and so adding a test for this to v4l2-compliance > >>>>>>>>> would be very useful. > >>>>>>>> > >>>>>>>> I fully agree, this is very counter-intuitive since what basically > >>>>>>>> happens is that the kernel's poll_wait() function becomes a no-op > >>>>>>>> after the poll() hook of a driver is called for the first time. There > >>>>>>>> is no way one can expect this behavior just from browsing the code so > >>>>>>>> this is likely to affect other drivers. > >>>>>>>> > >>>>>>>> As for the test itself, we can easily reproduce the conditions for > >>>>>>>> failure in v4l2-test-buffers.cpp's captureBufs() function, but doing > >>>>>>>> so will make the streaming tests fail without being specific about the > >>>>>>>> cause. Or maybe we should add another pollmode to specifically test > >>>>>>>> epoll in this setup? Can I get your thoughts? > >>>>>>> > >>>>>>> No, just keep it as part of the poll test. Just add comments at the place > >>>>>>> where it fails describing this error. > >>>>>>> > >>>>>>> After all, it *is* a poll() bug, so it is only fair that it is tested as > >>>>>>> part of the epoll test. > >>>>>>> > >>>>>>> Can you call EPOLL_CTL_ADD with ev.events set to 0? And then call it again > >>>>>>> with the actual value that you need? If that triggers this issue as well, > >>>>>>> then that is a nice test (but perhaps EPOLL_CTL_ADD won't call poll() if > >>>>>>> ev.events is 0, but perhaps EPOLLERR would work instead of 0). > >>>>>> > >>>>>> Yup, actually the following is enough to make v4l2-compliance -s fail > >>>>>> with vicodec: > >>>>> > >>>>> Does it also fail with vivid? I am curious to know whether this issue is > >>>>> m2m specific or a more general problem. > >>>> > >>>> It does fail actually! And that made me notice that vb2_poll() uses > >>>> the same pattern as v4l2_m2m_poll() (probably because the latter is > >>>> inspired by the former?) and needs to be fixed similarly. I will send > >>>> another patch to fix vb2_poll() as well, thanks for pointing it out! > >>> > >>> I was afraid of that. > >>> > >>> Testing epoll for control events would be interesting as well. The > >>> vivid radio device is an example of a device that has controls, but > >>> does not do streaming (so is not using vb2). > >>> > >>> But from what I can see v4l2_ctrl_poll() does the right thing, so this > >>> should be fine. > >> > >> Indeed, it unconditionally calls poll_wait() with all the wait queues > >> that may wake us up (that is, only one), so there is no problem there. > > > > Sorry, I noticed that this patch was marked with "Changes Requested" > > in patchwork, but isn't it valid as-is? We need a similar change to > > VB2, but that should go as a separate patch IMHO. I'm fine with doing > > both in one go if you prefer that though. > > > > In at least one reply you mentioned that you wanted to add a comment (reply > from 23 Oct). That's why I changed it to 'Changes Requested'. Ah, that's correct. Thanks for clarifying. > Also, I prefer to fix both m2m and vb2 at the same time (separate patches, > but part of the same patch series). And together with a separate patch improving > v4l2-compliance. Ack - will submit a series and a separate patch for v4l-utils.