From: Mauro Carvalho Chehab <mchehab@redhat.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: 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 08:50:28 -0300 [thread overview]
Message-ID: <4D74C684.7090507@redhat.com> (raw)
In-Reply-To: <201103061821.31705.laurent.pinchart@ideasonboard.com>
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.
Ok, i see. This is not the best world, as I suspect that developers will
just try to enable media controller for a few devices without taking enough
care to avoid buffer overflows.
While we don't have a better way for doing it, please add a note at the kernel
api doc saying about that, briefly describing how to properly lock it, because
this is not obvious at all.
Cheers,
Mauro
next prev parent reply other threads:[~2011-03-07 11:50 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 [this message]
[not found] ` <201103071302.49323.hansverk@cisco.com>
2011-03-07 13:00 ` Mauro Carvalho Chehab
2011-03-07 13:04 ` Mauro Carvalho Chehab
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=4D74C684.7090507@redhat.com \
--to=mchehab@redhat.com \
--cc=alsa-devel@alsa-project.org \
--cc=dacohen@gmail.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