[-,v1] V4L-Fix videobuf_dma_contig_user_get() for non-aligned offsets
Commit Message
From: Muralidharan Karicheri <m-karicheri2@ti.com>
If a USERPTR address that is not aligned to page boundary is passed to the
videobuf_dma_contig_user_get() function, it saves a page aligned address to
the dma_handle. This is not correct. This issue is observed when using USERPTR
IO machism for buffer exchange.
Updates from last version:-
Adding offset for size calculation as per comment from Magnus Damm. This
ensures the last page is also included for checking if memory is
contiguous.
Signed-off-by: Muralidharan Karicheri <m-karicheri2@ti.com>
---
drivers/media/video/videobuf-dma-contig.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
Comments
On Wed, Dec 9, 2009 at 6:36 AM, <m-karicheri2@ti.com> wrote:
> From: Muralidharan Karicheri <m-karicheri2@ti.com>
>
> If a USERPTR address that is not aligned to page boundary is passed to the
> videobuf_dma_contig_user_get() function, it saves a page aligned address to
> the dma_handle. This is not correct. This issue is observed when using USERPTR
> IO machism for buffer exchange.
>
> Updates from last version:-
>
> Adding offset for size calculation as per comment from Magnus Damm. This
> ensures the last page is also included for checking if memory is
> contiguous.
>
> Signed-off-by: Muralidharan Karicheri <m-karicheri2@ti.com>
Hi Murali,
I've spent some time testing this patch with the SuperH CEU driver in
USERPTR mode. My test case is based on capture.c with places a bunch
of QVGA frames directly after each other. The size of each QVGA frame
is not an even multiple of 4k page size, so some of the frames will
use a non-aligned start addresses. Currently the CEU driver page
aligns the size of each frame, but I'll fix that in an upcoming patch.
Thank you!
Acked-by: Magnus Damm <damm@opensource.se>
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Magnus,
Thanks for testing and approving the patch.
Mauro,
Could you merge this bug fix?
Murali Karicheri
Software Design Engineer
Texas Instruments Inc.
Germantown, MD 20874
phone: 301-407-9583
email: m-karicheri2@ti.com
>-----Original Message-----
>From: Magnus Damm [mailto:magnus.damm@gmail.com]
>Sent: Wednesday, December 09, 2009 8:00 AM
>To: Karicheri, Muralidharan
>Cc: linux-media@vger.kernel.org
>Subject: Re: [PATCH - v1] V4L-Fix videobuf_dma_contig_user_get() for non-
>aligned offsets
>
>On Wed, Dec 9, 2009 at 6:36 AM, <m-karicheri2@ti.com> wrote:
>> From: Muralidharan Karicheri <m-karicheri2@ti.com>
>>
>> If a USERPTR address that is not aligned to page boundary is passed to
>the
>> videobuf_dma_contig_user_get() function, it saves a page aligned address
>to
>> the dma_handle. This is not correct. This issue is observed when using
>USERPTR
>> IO machism for buffer exchange.
>>
>> Updates from last version:-
>>
>> Adding offset for size calculation as per comment from Magnus Damm. This
>> ensures the last page is also included for checking if memory is
>> contiguous.
>>
>> Signed-off-by: Muralidharan Karicheri <m-karicheri2@ti.com>
>
>Hi Murali,
>
>I've spent some time testing this patch with the SuperH CEU driver in
>USERPTR mode. My test case is based on capture.c with places a bunch
>of QVGA frames directly after each other. The size of each QVGA frame
>is not an even multiple of 4k page size, so some of the frames will
>use a non-aligned start addresses. Currently the CEU driver page
>aligns the size of each frame, but I'll fix that in an upcoming patch.
>Thank you!
>
>Acked-by: Magnus Damm <damm@opensource.se>
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
@@ -141,9 +141,11 @@ static int videobuf_dma_contig_user_get(struct videobuf_dma_contig_memory *mem,
struct vm_area_struct *vma;
unsigned long prev_pfn, this_pfn;
unsigned long pages_done, user_address;
+ unsigned int offset;
int ret;
- mem->size = PAGE_ALIGN(vb->size);
+ offset = vb->baddr & ~PAGE_MASK;
+ mem->size = PAGE_ALIGN(vb->size + offset);
mem->is_userptr = 0;
ret = -EINVAL;
@@ -166,7 +168,7 @@ static int videobuf_dma_contig_user_get(struct videobuf_dma_contig_memory *mem,
break;
if (pages_done == 0)
- mem->dma_handle = this_pfn << PAGE_SHIFT;
+ mem->dma_handle = (this_pfn << PAGE_SHIFT) + offset;
else if (this_pfn != (prev_pfn + 1))
ret = -EFAULT;