Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp459371pxb; Thu, 5 Nov 2020 04:54:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJzzYg3mz/3wJZgjb9STvZmzQsZWyDrjqyP7gzBmokrdCAcP/gZzb1+/FMHLkXhB3M1PUK7t X-Received: by 2002:aa7:c889:: with SMTP id p9mr2325075eds.110.1604580854703; Thu, 05 Nov 2020 04:54:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604580854; cv=none; d=google.com; s=arc-20160816; b=PbqLD751AY204lyHHp0+rZOl849IScK80GvhCI4BHYjCsS+kFU5Xc0ksaLx7GY9NUC AQP60kDI0hd2B7I5BnL/5m+T8lRZ9E5b0y4Y8M32SR73RODmROZqakj+glOpXM/7Pbjj zr9wav3+TuZBbx4foAEyX53LissOfwGCmbVfPkP44DkIEzHVWpgzudJh218OC6baLwSk pkH9ksg8Q4ZuTwbx5oT731P/GtpspaS6apDJTBXJUmZ56yD4sBLbpydhlO2/0HJGpHkl NSfu7VKYuoJrOkMao/cLOjE4tsGmJpeIASEUh2NZjEb8owfREL3FQwO2gr6uEC9HbuX7 tlbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=3l1aRcqcF78cHksRWV2XnGoE+BVDrbrW5Cq1V4B7e5Y=; b=U6jG01UlAcFAfBbcXYDzVLTEU5XX2dW4ciSeRXzS1qwQC9OrtD3aL3TKbyUfGDsLbF duwjoQDgdlLFb23RgRR25Bkr512hdE34Bof2SACvxlVpRKECqA6btiZnGdNqy4vIYenl MGX2NQ8m5yJcF+mokb2fIA6BNTtADjIcPnWo8zPdQd8RC2OB2PvD14/VoL8PK/rphJZs d3ZZBN+pwyAtEta1jcd4WLPATfcLuQEhXaEMWzjtRaAgQFQ46jd3RRXjuW5CUhDZBwEj kjWrh54hiiRycbciob25ZgvbwwKxBNZ3PY5Y/Tp74c8dAnMrxM7LfAzprrx16NaeggbE l4xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kFimWqOS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z26si979515eje.469.2020.11.05.04.53.51; Thu, 05 Nov 2020 04:54:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kFimWqOS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730445AbgKEMwa (ORCPT + 99 others); Thu, 5 Nov 2020 07:52:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726777AbgKEMwa (ORCPT ); Thu, 5 Nov 2020 07:52:30 -0500 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 021BBC0613CF; Thu, 5 Nov 2020 04:52:30 -0800 (PST) Received: by mail-lj1-x243.google.com with SMTP id p15so1437616ljj.8; Thu, 05 Nov 2020 04:52:29 -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=3l1aRcqcF78cHksRWV2XnGoE+BVDrbrW5Cq1V4B7e5Y=; b=kFimWqOSZmu7KJoGa7QTQRAC4Ob+z+sncY88iSFZ7UBMu8Refa4KM4RzahvxmQfcrI cSvRUa3GRIRuFTBT50mEXd3b68yS2I/fhlPfbvQEDPOgwnAFWczHt8TXzS7uBVDvpqP4 MKnhv1qk0+1Yc7is2/z4hQYX8UKpeh0fQBU1tSgtgn8d04Bg7gxXvBW+Hdb4Y8MghVeg Wt8C7NfZ+yrmMMhEF9/ZMQlRBkouZgwtrU598BkNVwORvgX+Mv7zivAeldVQRW3/0fNQ MOvtaYBMDSZ1SROZ5riHHWnHTSc19OsoMFKRrEm3KKexGyiwIsHBTc0o/ugk4KxLcXhT Ngeg== 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=3l1aRcqcF78cHksRWV2XnGoE+BVDrbrW5Cq1V4B7e5Y=; b=MXDYUvkEZLbr+3YpiJGXAlqX9uhO2iKiSoo7bftqvBFspnVuPwe+cbMavzmh2kXlko vt/EMHYB6hOSFDel3s9oRTp0PBgwhrG+dzGoawIWo0A2nrFULkEdd2tk0w3TuhMLtzQD V7ZgIgVm0GtMHiWXj9pp+NVyYSlLEXC596tJKvHyE0qz7m2gkH7gg+j0/vNmqqhKir1r 6nhGDj3F4YlNTXvrob8nDlOJXn/8E3M1ZnVN2W8LSrNlUUYh9TxK6yN3eoxch+puzmBs QokP8y1zUnDbRYy0MhkN8TyLYj7FFLj9WS7uBa0aAC24xseOmCevnFTBn1q4ZMQzvL8z zhPw== X-Gm-Message-State: AOAM531LtfR4LcN/T/wkaubRkx2NDmOw6ySXQHEYOxj7F1L6HpwpJGob rfo/6DiJWEpp/PqpjqQN7JCjg85squ4t+19vm1I= X-Received: by 2002:a2e:b169:: with SMTP id a9mr896988ljm.84.1604580748404; Thu, 05 Nov 2020 04:52:28 -0800 (PST) MIME-Version: 1.0 References: <20201022122421.133976-1-gnurou@gmail.com> <695e6163-7bdc-d120-cd02-0cff6efb53ef@xs4all.nl> In-Reply-To: <695e6163-7bdc-d120-cd02-0cff6efb53ef@xs4all.nl> From: Alexandre Courbot Date: Thu, 5 Nov 2020 21:52:16 +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-kernel@vger.kernel.org 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!