linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Prabhakar lad <prabhakar.csengg@gmail.com>
Cc: LMML <linux-media@vger.kernel.org>,
	Mauro Carvalho Chehab <mchehab@redhat.com>,
	DLOS <davinci-linux-open-source@linux.davincidsp.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Hans Verkuil <hans.verkuil@cisco.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>
Subject: Re: [PATCH v2] media: davinci: vpif: align the buffers size to page page size boundary
Date: Tue, 16 Apr 2013 13:18:43 +0200	[thread overview]
Message-ID: <2933946.BRNjyJUSVm@avalon> (raw)
In-Reply-To: <1366109670-28030-1-git-send-email-prabhakar.csengg@gmail.com>

Hi Prabhakar,

(CC'ing Marek)

On Tuesday 16 April 2013 16:24:30 Prabhakar lad wrote:
> From: Lad, Prabhakar <prabhakar.csengg@gmail.com>
> 
> with recent commit with id 068a0df76023926af958a336a78bef60468d2033
> which adds add length check for mmap, the application were failing to
> mmap the buffers.
> 
> This patch aligns the the buffer size to page size boundary for both
> capture and display driver so the it pass the check.
> 
> Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Cc: Hans Verkuil <hans.verkuil@cisco.com>
> Cc: Mauro Carvalho Chehab <mchehab@redhat.com>
> ---
>  Changes for v2:
>  1: Fixed a typo in commit message.
> 
>  drivers/media/platform/davinci/vpif_capture.c |    1 +
>  drivers/media/platform/davinci/vpif_display.c |    1 +
>  2 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/media/platform/davinci/vpif_capture.c
> b/drivers/media/platform/davinci/vpif_capture.c index 5f98df1..25981d6
> 100644
> --- a/drivers/media/platform/davinci/vpif_capture.c
> +++ b/drivers/media/platform/davinci/vpif_capture.c
> @@ -183,6 +183,7 @@ static int vpif_buffer_queue_setup(struct vb2_queue *vq,
> *nbuffers = config_params.min_numbuffers;
> 
>  	*nplanes = 1;
> +	size = PAGE_ALIGN(size);

I wonder if that's the best fix.

The queue_setup operation is supposed to return the size required by the 
driver for each plane. Depending on the hardware requirements, that size might 
not be a multiple of the page size.

As we can't mmap() a fraction of a page, the allocated plane size needs to be 
rounded up to the next page boundary to allow mmap() support. The dma-contig 
and dma-sg allocators already do so in their alloc operation, but the vmalloc 
allocator doesn't.

The recent "media: vb2: add length check for mmap" patch verifies that the 
mmap() size requested by userspace doesn't exceed the buffer size. As the 
mmap() size is rounded up to the next page boundary the check will fail for 
buffer sizes that are not multiple of the page size.

Your fix will not result in overallocation (as the allocator already rounds 
the size up), but will prevent the driver from importing a buffer large enough 
for the hardware but not rounded up to the page size.

A better fix might be to round up the buffer size in the buffer size check at 
mmap() time, and fix the vmalloc allocator to round up the size. That the 
allocator, not drivers, is responsible for buffer size alignment should be 
documented in videobuf2-core.h.

>  	sizes[0] = size;
>  	alloc_ctxs[0] = common->alloc_ctx;
> 
> diff --git a/drivers/media/platform/davinci/vpif_display.c
> b/drivers/media/platform/davinci/vpif_display.c index 1b3fb5c..3414715
> 100644
> --- a/drivers/media/platform/davinci/vpif_display.c
> +++ b/drivers/media/platform/davinci/vpif_display.c
> @@ -162,6 +162,7 @@ static int vpif_buffer_queue_setup(struct vb2_queue *vq,
> *nbuffers = config_params.min_numbuffers;
> 
>  	*nplanes = 1;
> +	size = PAGE_ALIGN(size);
>  	sizes[0] = size;
>  	alloc_ctxs[0] = common->alloc_ctx;
>  	return 0;

-- 
Regards,

Laurent Pinchart


  parent reply	other threads:[~2013-04-16 11:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-16 10:54 [PATCH v2] media: davinci: vpif: align the buffers size to page page size boundary Prabhakar lad
2013-04-16 10:56 ` Prabhakar Lad
2013-04-16 11:18 ` Laurent Pinchart [this message]
2013-04-18  4:47   ` Prabhakar Lad
2013-04-18 11:21     ` Mauro Carvalho Chehab
2013-04-18 11:35       ` Mauro Carvalho Chehab
2013-04-18 13:22         ` Laurent Pinchart
2013-04-18 14:08           ` Mauro Carvalho Chehab
2013-04-18 14:18             ` Laurent Pinchart
2013-04-16 11:39 ` Sergei Shtylyov

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=2933946.BRNjyJUSVm@avalon \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=davinci-linux-open-source@linux.davincidsp.com \
    --cc=hans.verkuil@cisco.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mchehab@redhat.com \
    --cc=prabhakar.csengg@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;
as well as URLs for NNTP newsgroup(s).