All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>,
	linux-media@vger.kernel.org, linux-sh@vger.kernel.org,
	Sakari Ailus <sakari.ailus@iki.fi>,
	Katsuya MATSUBARA <matsu@igel.co.jp>,
	Sylwester Nawrocki <sylvester.nawrocki@gmail.com>
Subject: Re: [PATCH v6 04/10] media: vb2: Take queue or device lock in vb2_fop_mmap()
Date: Tue, 06 Aug 2013 20:09:57 +0000	[thread overview]
Message-ID: <47444631.Heq6Wo9coy@avalon> (raw)
In-Reply-To: <201308061239.27188.hverkuil@xs4all.nl>

Hi Hans,

On Tuesday 06 August 2013 12:39:27 Hans Verkuil wrote:
> On Mon 5 August 2013 19:53:23 Laurent Pinchart wrote:
> > The vb2_fop_mmap() function is a plug-in implementation of the mmap()
> > file operation that calls vb2_mmap() on the queue associated with the
> > video device. Neither the vb2_fop_mmap() function nor the v4l2_mmap()
> > mmap handler in the V4L2 core take any lock, leading to race conditions
> > between mmap() and other buffer-related ioctls such as VIDIOC_REQBUFS.
> > 
> > Fix it by taking the queue or device lock around the vb2_mmap() call.
> 
> Hi Laurent,
> 
> Can you do the same for vb2_fop_get_unmapped_area()?

Sure. I'll repost a v7 of this patch that fixes both mmap and 
get_unmapped_area.

> > Signed-off-by: Laurent Pinchart
> > <laurent.pinchart+renesas@ideasonboard.com>
> > ---
> > 
> >  drivers/media/v4l2-core/videobuf2-core.c | 9 ++++++++-
> >  1 file changed, 8 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/media/v4l2-core/videobuf2-core.c
> > b/drivers/media/v4l2-core/videobuf2-core.c index 9fc4bab..bd4bade 100644
> > --- a/drivers/media/v4l2-core/videobuf2-core.c
> > +++ b/drivers/media/v4l2-core/videobuf2-core.c
> > @@ -2578,8 +2578,15 @@ EXPORT_SYMBOL_GPL(vb2_ioctl_expbuf);
> > 
> >  int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma)
> >  {
> >  
> >  	struct video_device *vdev = video_devdata(file);
> > 
> > +	struct mutex *lock = vdev->queue->lock ? vdev->queue->lock : vdev-
>lock;
> > +	int err;
> > 
> > -	return vb2_mmap(vdev->queue, vma);
> > +	if (lock && mutex_lock_interruptible(lock))
> > +		return -ERESTARTSYS;
> > +	err = vb2_mmap(vdev->queue, vma);
> > +	if (lock)
> > +		mutex_unlock(lock);
> > +	return err;
> > 
> >  }
> >  EXPORT_SYMBOL_GPL(vb2_fop_mmap);
-- 
Regards,

Laurent Pinchart

WARNING: multiple messages have this Message-ID (diff)
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>,
	linux-media@vger.kernel.org, linux-sh@vger.kernel.org,
	Sakari Ailus <sakari.ailus@iki.fi>,
	Katsuya MATSUBARA <matsu@igel.co.jp>,
	Sylwester Nawrocki <sylvester.nawrocki@gmail.com>
Subject: Re: [PATCH v6 04/10] media: vb2: Take queue or device lock in vb2_fop_mmap()
Date: Tue, 06 Aug 2013 22:09:57 +0200	[thread overview]
Message-ID: <47444631.Heq6Wo9coy@avalon> (raw)
In-Reply-To: <201308061239.27188.hverkuil@xs4all.nl>

Hi Hans,

On Tuesday 06 August 2013 12:39:27 Hans Verkuil wrote:
> On Mon 5 August 2013 19:53:23 Laurent Pinchart wrote:
> > The vb2_fop_mmap() function is a plug-in implementation of the mmap()
> > file operation that calls vb2_mmap() on the queue associated with the
> > video device. Neither the vb2_fop_mmap() function nor the v4l2_mmap()
> > mmap handler in the V4L2 core take any lock, leading to race conditions
> > between mmap() and other buffer-related ioctls such as VIDIOC_REQBUFS.
> > 
> > Fix it by taking the queue or device lock around the vb2_mmap() call.
> 
> Hi Laurent,
> 
> Can you do the same for vb2_fop_get_unmapped_area()?

Sure. I'll repost a v7 of this patch that fixes both mmap and 
get_unmapped_area.

> > Signed-off-by: Laurent Pinchart
> > <laurent.pinchart+renesas@ideasonboard.com>
> > ---
> > 
> >  drivers/media/v4l2-core/videobuf2-core.c | 9 ++++++++-
> >  1 file changed, 8 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/media/v4l2-core/videobuf2-core.c
> > b/drivers/media/v4l2-core/videobuf2-core.c index 9fc4bab..bd4bade 100644
> > --- a/drivers/media/v4l2-core/videobuf2-core.c
> > +++ b/drivers/media/v4l2-core/videobuf2-core.c
> > @@ -2578,8 +2578,15 @@ EXPORT_SYMBOL_GPL(vb2_ioctl_expbuf);
> > 
> >  int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma)
> >  {
> >  
> >  	struct video_device *vdev = video_devdata(file);
> > 
> > +	struct mutex *lock = vdev->queue->lock ? vdev->queue->lock : vdev-
>lock;
> > +	int err;
> > 
> > -	return vb2_mmap(vdev->queue, vma);
> > +	if (lock && mutex_lock_interruptible(lock))
> > +		return -ERESTARTSYS;
> > +	err = vb2_mmap(vdev->queue, vma);
> > +	if (lock)
> > +		mutex_unlock(lock);
> > +	return err;
> > 
> >  }
> >  EXPORT_SYMBOL_GPL(vb2_fop_mmap);
-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2013-08-06 20:09 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-05 17:53 [PATCH v6 00/10] Renesas VSP1 driver Laurent Pinchart
2013-08-05 17:53 ` Laurent Pinchart
2013-08-05 17:53 ` [PATCH v6 01/10] media: Add support for circular graph traversal Laurent Pinchart
2013-08-05 17:53   ` Laurent Pinchart
2013-08-05 17:53 ` [PATCH v6 02/10] Documentation: media: Clarify the VIDIOC_CREATE_BUFS format requirements Laurent Pinchart
2013-08-05 17:53   ` Laurent Pinchart
2013-08-06 10:36   ` Hans Verkuil
2013-08-06 10:36     ` Hans Verkuil
2013-08-05 17:53 ` [PATCH v6 03/10] media: vb2: Clarify queue_setup() and buf_prepare() usage documentation Laurent Pinchart
2013-08-05 17:53   ` Laurent Pinchart
2013-08-05 17:53 ` [PATCH v6 04/10] media: vb2: Take queue or device lock in vb2_fop_mmap() Laurent Pinchart
2013-08-05 17:53   ` Laurent Pinchart
2013-08-06 10:39   ` Hans Verkuil
2013-08-06 10:39     ` Hans Verkuil
2013-08-06 20:09     ` Laurent Pinchart [this message]
2013-08-06 20:09       ` Laurent Pinchart
2013-08-06 20:10     ` [PATCH v7] media: vb2: Take queue or device lock in mmap-related vb2 ioctl handlers Laurent Pinchart
2013-08-06 20:10       ` Laurent Pinchart
2013-08-07  6:30       ` Hans Verkuil
2013-08-07  6:30         ` Hans Verkuil
2014-05-23 13:54       ` Hans Verkuil
2014-05-23 13:54         ` Hans Verkuil
2014-05-26 22:38         ` Laurent Pinchart
2014-05-26 22:38           ` Laurent Pinchart
2014-06-25 16:58         ` Sasha Levin
2014-06-25 16:58           ` Sasha Levin
2014-07-01 21:08           ` Laurent Pinchart
2014-07-01 21:08             ` Laurent Pinchart
2014-07-02  6:33             ` Hans Verkuil
2014-07-02  6:33               ` Hans Verkuil
2014-07-02  7:56               ` Laurent Pinchart
2014-07-02  7:56                 ` Laurent Pinchart
2013-08-05 17:53 ` [PATCH v6 05/10] v4l: Fix V4L2_MBUS_FMT_YUV10_1X30 media bus pixel code value Laurent Pinchart
2013-08-05 17:53   ` Laurent Pinchart
2013-08-05 17:53 ` [PATCH v6 06/10] v4l: Add media format codes for ARGB8888 and AYUV8888 on 32-bit busses Laurent Pinchart
2013-08-05 17:53   ` Laurent Pinchart
2013-08-05 17:53 ` [PATCH v6 07/10] v4l: Add V4L2_PIX_FMT_NV16M and V4L2_PIX_FMT_NV61M formats Laurent Pinchart
2013-08-05 17:53   ` Laurent Pinchart
2013-08-05 17:53 ` [PATCH v6 08/10] v4l: Renesas R-Car VSP1 driver Laurent Pinchart
2013-08-05 17:53 ` [PATCH v6 09/10] vsp1: Fix lack of the sink entity registration for enabled links Laurent Pinchart
2013-08-05 17:53   ` Laurent Pinchart
2013-08-05 17:53 ` [PATCH v6 10/10] vsp1: Use the maximum number of entities defined in platform data Laurent Pinchart
2013-08-05 17:53   ` Laurent Pinchart

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=47444631.Heq6Wo9coy@avalon \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=hverkuil@xs4all.nl \
    --cc=laurent.pinchart+renesas@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=matsu@igel.co.jp \
    --cc=sakari.ailus@iki.fi \
    --cc=sylvester.nawrocki@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 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.