public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
	linux-media@vger.kernel.org, mchehab@osg.samsung.com,
	hans.verkuil@cisco.com
Subject: Re: em38xx locking question
Date: Tue, 10 Mar 2015 15:16:54 +0100	[thread overview]
Message-ID: <54FEFCD6.5090807@xs4all.nl> (raw)
In-Reply-To: <54FEFA83.2080205@vanguardiasur.com.ar>

On 03/10/2015 03:06 PM, Ezequiel Garcia wrote:
> 
> 
> On 03/10/2015 10:46 AM, Hans Verkuil wrote:
>> On 03/10/2015 02:29 PM, Ezequiel Garcia wrote:
>>>
>>>
>>> On 03/10/2015 10:26 AM, Hans Verkuil wrote:
>>>> On 03/10/2015 02:18 PM, Ezequiel Garcia wrote:
>>>>> Mauro,
>>>>>
>>>>> Function drivers/media/usb/em28xx/em28xx-video.c:get_next_buf
>>>>> (copy pasted below for reference) does not take the list spinlock,
>>>>> yet it modifies the list. Is that correct?
>>>>
>>>> That looks wrong to me. You really need spinlocks here.
>>>>
>>>
>>> OK, second question then. Is there any way to guarantee the URBs irq handler
>>> is *not* running, when vb2_ops are called (e.g. stop_streaming)?
>>
>> That depends on the op. But stop_streaming is the op that is supposed to
>> turn off the streaming (and thus the irq), so it depends on the order
>> of how things are done in that function.
>>
> 
> Ah, right. As long as you kill the urbs before you try to access the
> current buffer, everything is OK.
> 
>>> Otherwise, given stop_streaming will return the current buffer to vb2
>>> (dev->usb_ctl.vid_buf), I believe that will race against the irq handler,
>>> which is processing it.
>>>
> 
>>> It seems that's currently racy as well.
>>
>> Hmm, the stop_streaming code looks fine at first sight, but I think there
>> is a race if you start streaming both video and vbi, and then stop streaming
>> one of the two. I think the code might keep calling get_next_buf() in that
>> case, even if for that stream the streaming was stopped.
>>
>> This is a problem anyway: get_next_buf() should do this check at the beginning:
>>
>> 	if (!vb2_start_streaming_called(vb2_queue))
>> 		return NULL;
>>
>> to prevent it from using buffer before start_streaming was actually called.
>>
> 
> I'd say get_next_buf() is called only in the URB complete handler path,
> and hence only after start_streaming.

Well, no. If you are streaming just video and then start streaming vbi in addition
to the video, then I think get_next_buf() can be called for the VBI stream
before start_streaming is called for that VBI stream.

	Hans

> However, maybe there's a subtle
> issue here: URB complete handler can be called _while_ start_streaming
> is still running.
> 


      reply	other threads:[~2015-03-10 14:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-10 13:18 em38xx locking question Ezequiel Garcia
2015-03-10 13:26 ` Hans Verkuil
2015-03-10 13:29   ` Ezequiel Garcia
2015-03-10 13:46     ` Hans Verkuil
2015-03-10 14:06       ` Ezequiel Garcia
2015-03-10 14:16         ` Hans Verkuil [this message]

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=54FEFCD6.5090807@xs4all.nl \
    --to=hverkuil@xs4all.nl \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=hans.verkuil@cisco.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@osg.samsung.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox