All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandre Courbot <gnurou@gmail.com>
To: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Nicolas Dufresne <nicolas.dufresne@collabora.com>,
	linux-media <linux-media@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] media: v4l2-mem2mem: consider OUTPUT queue first when polling
Date: Wed, 26 Aug 2020 20:21:19 +0900	[thread overview]
Message-ID: <CAAVeFuLnfeBG89hVsM8JuFaCP+s7RTZe_OvFM6WPVH0dnkAZNA@mail.gmail.com> (raw)
In-Reply-To: <CAAEAJfBeJnSjqfyhosM_6jP4C+wQ7UVmt=oG_O0w--sAf0=0PQ@mail.gmail.com>

On Wed, Aug 26, 2020 at 1:08 PM Ezequiel Garcia
<ezequiel@vanguardiasur.com.ar> wrote:
>
> Hi Alexandre,
>
> On Tue, 25 Aug 2020 at 11:56, Alexandre Courbot <gnurou@gmail.com> wrote:
> >
> > If poll() is called on a m2m device with the EPOLLOUT event after the
> > last buffer of the CAPTURE queue is dequeued, any buffer available on
> > OUTPUT queue will never be signaled because v4l2_m2m_poll_for_data()
> > starts by checking whether dst_q->last_buffer_dequeued is set and
> > returns EPOLLIN in this case, without looking at the state of the OUTPUT
> > queue.
> >
> > Fix this by checking the state of the OUTPUT queue before considering
> > that early-return case.
> >
> > This also has the side-effect of bringing the two blocks of code dealing
> > with the CAPTURE queue next to one another, and saves us one spin
> > lock/unlock cycle, for what it's worth.
> >
> > Signed-off-by: Alexandre Courbot <gnurou@gmail.com>
>
> Change looks good to me.
>
> Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
>
> Do you think it qualifies for -stable? The issue has been
> here since the dawn of time.

Indeed, and this should be quite a rare corner case. I will leave that
call to the maintainers.

>
> Thanks,
> Ezequiel
>
> > ---
> >  drivers/media/v4l2-core/v4l2-mem2mem.c | 23 +++++++++++------------
> >  1 file changed, 11 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
> > index 95a8f2dc5341d..0d0192119af20 100644
> > --- a/drivers/media/v4l2-core/v4l2-mem2mem.c
> > +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
> > @@ -862,6 +862,15 @@ static __poll_t v4l2_m2m_poll_for_data(struct file *file,
> >              list_empty(&dst_q->queued_list)))
> >                 return EPOLLERR;
> >
> > +       spin_lock_irqsave(&src_q->done_lock, flags);
> > +       if (!list_empty(&src_q->done_list))
> > +               src_vb = list_first_entry(&src_q->done_list, struct vb2_buffer,
> > +                                               done_entry);
> > +       if (src_vb && (src_vb->state == VB2_BUF_STATE_DONE
> > +                       || src_vb->state == VB2_BUF_STATE_ERROR))
> > +               rc |= EPOLLOUT | EPOLLWRNORM;
> > +       spin_unlock_irqrestore(&src_q->done_lock, flags);
> > +
> >         spin_lock_irqsave(&dst_q->done_lock, flags);
> >         if (list_empty(&dst_q->done_list)) {
> >                 /*
> > @@ -870,21 +879,11 @@ static __poll_t v4l2_m2m_poll_for_data(struct file *file,
> >                  */
> >                 if (dst_q->last_buffer_dequeued) {
> >                         spin_unlock_irqrestore(&dst_q->done_lock, flags);
> > -                       return EPOLLIN | EPOLLRDNORM;
> > +                       rc |= EPOLLIN | EPOLLRDNORM;
> > +                       return rc;
> >                 }
> >         }
> > -       spin_unlock_irqrestore(&dst_q->done_lock, flags);
> >
> > -       spin_lock_irqsave(&src_q->done_lock, flags);
> > -       if (!list_empty(&src_q->done_list))
> > -               src_vb = list_first_entry(&src_q->done_list, struct vb2_buffer,
> > -                                               done_entry);
> > -       if (src_vb && (src_vb->state == VB2_BUF_STATE_DONE
> > -                       || src_vb->state == VB2_BUF_STATE_ERROR))
> > -               rc |= EPOLLOUT | EPOLLWRNORM;
> > -       spin_unlock_irqrestore(&src_q->done_lock, flags);
> > -
> > -       spin_lock_irqsave(&dst_q->done_lock, flags);
> >         if (!list_empty(&dst_q->done_list))
> >                 dst_vb = list_first_entry(&dst_q->done_list, struct vb2_buffer,
> >                                                 done_entry);
> > --
> > 2.28.0
> >

  reply	other threads:[~2020-08-26 11:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-25 14:55 [PATCH 0/2] media: v4l2-mem2mem: fix poll() bug Alexandre Courbot
2020-08-25 14:55 ` [PATCH 1/2] media: v4l2-mem2mem: consider OUTPUT queue first when polling Alexandre Courbot
2020-08-26  4:07   ` Ezequiel Garcia
2020-08-26 11:21     ` Alexandre Courbot [this message]
2020-08-25 14:55 ` [PATCH 2/2] media: v4l2-mem2mem: simplify poll logic a bit Alexandre Courbot
2020-08-26  4:15   ` Ezequiel Garcia
2020-08-26 11:19     ` Alexandre Courbot
2020-08-26 14:32       ` Ezequiel Garcia
2020-08-26 15:23         ` Hans Verkuil
2020-08-26 12:46   ` Hans Verkuil
2020-08-25 22:10 ` [PATCH 0/2] media: v4l2-mem2mem: fix poll() bug Ezequiel Garcia
2020-08-26 11:25   ` Alexandre Courbot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAAVeFuLnfeBG89hVsM8JuFaCP+s7RTZe_OvFM6WPVH0dnkAZNA@mail.gmail.com \
    --to=gnurou@gmail.com \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=nicolas.dufresne@collabora.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.