From: Mauro Carvalho Chehab <maurochehab@gmail.com>
To: Hans Verkuil <hansverk@cisco.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Sylwester Nawrocki <snjw23@gmail.com>,
David Cohen <dacohen@gmail.com>,
Hans Verkuil <hverkuil@xs4all.nl>,
"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
alsa-devel@alsa-project.org,
Sakari Ailus <sakari.ailus@retiisi.org.uk>,
Pawel Osciak <pawel@osciak.com>
Subject: Re: [GIT PULL FOR 2.6.39] Media controller and OMAP3 ISP driver
Date: Mon, 07 Mar 2011 10:04:54 -0300 [thread overview]
Message-ID: <4D74D7F6.1000508@gmail.com> (raw)
In-Reply-To: <4D74D6E4.8080501@redhat.com>
Em 07-03-2011 10:00, Mauro Carvalho Chehab escreveu:
> Em 07-03-2011 09:02, Hans Verkuil escreveu:
>> On Monday, March 07, 2011 12:50:28 Mauro Carvalho Chehab wrote:
>>
>>> Em 06-03-2011 14:21, Laurent Pinchart escreveu:
>>
>>>> Hi Mauro,
>>
>>>>
>>
>>>> On Sunday 06 March 2011 14:32:44 Mauro Carvalho Chehab wrote:
>>
>>>>> Em 06-03-2011 08:38, Laurent Pinchart escreveu:
>>
>>>>>> On Sunday 06 March 2011 11:56:04 Mauro Carvalho Chehab wrote:
>>
>>>>>>> Em 05-03-2011 20:23, Sylwester Nawrocki escreveu:
>>
>>>>>>>
>>
>>>>>>> A somewhat unrelated question that occurred to me today: what happens
>>
>>>>>>> when a format change happens while streaming?
>>
>>>>>>>
>>
>>>>>>> Considering that some formats need more bits than others, this could
>>
>>>>>>> lead into buffer overflows, either internally at the device or
>>
>>>>>>> externally, on bridges that just forward whatever it receives to the
>>
>>>>>>> DMA buffers (there are some that just does that). I didn't see anything
>>
>>>>>>> inside the mc code preventing such condition to happen, and probably
>>
>>>>>>> implementing it won't be an easy job. So, one alternative would be to
>>
>>>>>>> require some special CAPS if userspace tries to set the mbus format
>>
>>>>>>> directly, or to recommend userspace to create media controller nodes
>>
>>>>>>> with 0600 permission.
>>
>>>>>>
>>
>>>>>> That's not really a media controller issue. Whether formats can be
>>
>>>>>> changed during streaming is a driver decision. The OMAP3 ISP driver
>>
>>>>>> won't allow formats to be changed during streaming. If the hardware
>>
>>>>>> allows for such format changes, drivers can implement support for that
>>
>>>>>> and make sure that no buffer overflow will occur.
>>
>>>>>
>>
>>>>> Such issues is caused by having two API's that allow format changes, one
>>
>>>>> that does it device-based, and another one doing it subdev-based.
>>
>>>>>
>>
>>>>> Ok, drivers can implementing locks to prevent such troubles, but, without
>>
>>>>> the core providing a reliable mechanism, it is hard to implement a
>>
>>>>> correct lock.
>>
>>>>>
>>
>>>>> For example, let's suppose that some driver is using mt9m111 subdev (I just
>>
>>>>> picked one random sensor that supports lots of MBUS formats). There's
>>
>>>>> nothing there preventing a subdev call for it to change mbus format while
>>
>>>>> streaming. Worse than that, the sensor driver has no way to block it, as
>>
>>>>> it doesn't know that the bridge driver is streaming or not.
>>
>>>>>
>>
>>>>> The code at subdev_do_ioctl() is just:
>>
>>>>>
>>
>>>>> case VIDIOC_SUBDEV_S_FMT: {
>>
>>>>> struct v4l2_subdev_format *format = arg;
>>
>>>>>
>>
>>>>> if (format->which != V4L2_SUBDEV_FORMAT_TRY &&
>>
>>>>> format->which != V4L2_SUBDEV_FORMAT_ACTIVE)
>>
>>>>> return -EINVAL;
>>
>>>>>
>>
>>>>> if (format->pad >= sd->entity.num_pads)
>>
>>>>> return -EINVAL;
>>
>>>>>
>>
>>>>> return v4l2_subdev_call(sd, pad, set_fmt, subdev_fh, format);
>>
>>>>> }
>>
>>>>>
>>
>>>>> So, mc core won't be preventing it.
>>
>>>>>
>>
>>>>> So, I can't see how such subdev request would be implementing a logic to
>>
>>>>> return -EBUSY on those cases.
>>
>>>>
>>
>>>> Drivers can use the media_device graph_mutex to serialize format and stream
>>
>>>> management calls. A finer grain locking mechanism implemented in the core
>>
>>>> might be better, but we're not stuck without a solution at the moment.
>>
>> Am I missing something here? Isn't it as simple as remembering whether the
>>
>> subdev is in streaming mode (s_stream(1) was called) or not? When streaming
>>
>> any attempt to change the format should return an error (unless the hardware
>>
>> can handle it, of course).
>>
>> This is the same as for the 'regular' V4L2 API.
>
> Not all subdevs implement s_stream, and I suspect that not all bridge drivers
> calls it. The random example I've looked didn't implement (mt9m111.c), but even
> some that implements it (like mt9m001.c) currently don't store the stream status
> or use it to prevent a format change.
>
> At the moment we open the possibility to directly access the subdev,
> developers might think that all they need to use the new API is to enable
> the subdev to create subdev nodes (btw, the first mc patch series were enabling
> it by default). However, opening subdev access without address such issues will
> lead into a security breach, as buffer overflows will happen if hardware can't
> handle format changes in the middle of a streaming [1].
>
> Also, a lock there will only work if properly implemented at the bridge driver,
> as a bridge driver that implement the media controller should implement something
> like the following sequence (at VIDIOC_REQBUFS):
>
> lock_format_changes_at_subdev(); /* step 1 */
> get_subdev_formats(); /* step 2 */
> program_bridge_to follow_subdev_format_and_s_fmt(); /* step 3 */
> reserve_memory(); /* step 4 */
> start_streaming(); /* step 5 */
>
>
> In the above, s_stream should be called at the step 1, and not at step 5, as,
> otherwise, a race condition will happen, if a MBUS format change happens between
> step 1 and 5.
In time: assuming that s_stream would implement such lock.
Also: it this is a mandatory requirement, it should be part of API documentation.
Otherwise, we'll have subdevs that will implement the lock using one way, and others
using a different way, creating an mess at the subdevs in a way that some subdevs
will work with bridge A, but not with bridge B, that has a different requirement
for such lock.
Cheers,
Mauro.
next prev parent reply other threads:[~2011-03-07 13:05 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-17 15:06 [GIT PULL FOR 2.6.39] Media controller and OMAP3 ISP driver Laurent Pinchart
2011-03-02 20:13 ` Mauro Carvalho Chehab
2011-03-03 9:29 ` Laurent Pinchart
2011-03-03 10:25 ` Laurent Pinchart
2011-03-04 19:25 ` Mauro Carvalho Chehab
2011-03-05 13:02 ` Laurent Pinchart
2011-03-05 18:22 ` Mauro Carvalho Chehab
2011-03-05 20:48 ` Laurent Pinchart
2011-03-07 11:57 ` Mauro Carvalho Chehab
2011-03-07 12:06 ` David Cohen
2011-03-07 13:38 ` Laurent Pinchart
2011-03-07 22:04 ` Laurent Pinchart
2011-03-11 15:40 ` Mauro Carvalho Chehab
2011-03-11 15:48 ` Laurent Pinchart
2011-03-04 20:10 ` Mauro Carvalho Chehab
2011-03-04 20:14 ` David Cohen
2011-03-05 11:52 ` Hans Verkuil
2011-03-05 13:04 ` David Cohen
2011-03-05 14:02 ` Hans Verkuil
2011-03-05 14:29 ` Sylwester Nawrocki
2011-03-05 18:14 ` Mauro Carvalho Chehab
2011-03-05 23:23 ` Sylwester Nawrocki
2011-03-06 10:56 ` Mauro Carvalho Chehab
2011-03-06 11:38 ` Laurent Pinchart
2011-03-06 13:32 ` Mauro Carvalho Chehab
2011-03-06 17:21 ` Laurent Pinchart
2011-03-07 11:50 ` Mauro Carvalho Chehab
[not found] ` <201103071302.49323.hansverk@cisco.com>
2011-03-07 13:00 ` Mauro Carvalho Chehab
2011-03-07 13:04 ` Mauro Carvalho Chehab [this message]
2011-03-07 13:46 ` Laurent Pinchart
2011-03-04 20:49 ` Mauro Carvalho Chehab
2011-03-04 21:31 ` Mauro Carvalho Chehab
2011-03-05 12:03 ` Hans Verkuil
2011-03-04 22:16 ` Mauro Carvalho Chehab
2011-03-04 22:33 ` David Cohen
2011-03-04 22:43 ` Mauro Carvalho Chehab
2011-03-04 22:49 ` David Cohen
2011-03-04 23:49 ` Mauro Carvalho Chehab
2011-03-05 0:40 ` David Cohen
2011-03-06 8:34 ` Sakari Ailus
2011-03-06 10:17 ` Laurent Pinchart
2011-03-07 11:56 ` Mauro Carvalho Chehab
2011-03-07 12:08 ` Sakari Ailus
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=4D74D7F6.1000508@gmail.com \
--to=maurochehab@gmail.com \
--cc=alsa-devel@alsa-project.org \
--cc=dacohen@gmail.com \
--cc=hansverk@cisco.com \
--cc=hverkuil@xs4all.nl \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=pawel@osciak.com \
--cc=sakari.ailus@retiisi.org.uk \
--cc=snjw23@gmail.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