All of lore.kernel.org
 help / color / mirror / Atom feed
From: Devin Heitmueller <dheitmueller@kernellabs.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: Mauro Carvalho Chehab <m.chehab@samsung.com>,
	Linux Media Mailing List <linux-media@vger.kernel.org>,
	Hans Verkuil <hans.verkuil@cisco.com>
Subject: Re: [REVIEW PATCH 3/3] saa7134: convert to vb2
Date: Fri, 18 Apr 2014 09:49:34 -0400	[thread overview]
Message-ID: <CAGoCfix1j8kLQQe3yMDj+bqi=Pyj_K+en31a-h32+HMzVU1arQ@mail.gmail.com> (raw)
In-Reply-To: <5351106E.4080700@xs4all.nl>

> This was a bit confusing following the previous paragraph. I meant to say that the
> *saa7134* userptr implementation is not USERPTR at all but PAGE_ALIGNED_USERPTR.
>
> A proper USERPTR implementation (like in bttv) can use any malloc()ed pointer as
> it should, but saa7134 can't as it requires the application to align the pointer
> to a page boundary, which is non-standard.

It's probably worth mentioning at this point that there's a bug in
videobuf2_vmalloc() where it forces the buffer provided by userptr
mode to be page aligned.  This causes issues if you hand it a buffer
that isn't actually page aligned, as it writes to an arbitrary offset
into the buffer instead of the start of the buffer you provided.

I've had the following patch in my private tree for months, but had
been hesitant to submit it since I didn't know if it would effect
other implementations.  I wasn't sure if USERPTR mode required the
buffers to be page aligned and I was violating the spec.

Devin

From: Devin Heitmueller <dheitmueller@kernellabs.com>
Date: Fri, 17 May 2013 19:53:02 +0000 (-0400)
Subject: Fix alignment bug when using VB2 with userptr mode

Fix alignment bug when using VB2 with userptr mode

If we pass in a USERPTR buffer that isn't page aligned, the driver
will align it (and not tell userland).  The result is that the driver
thinks the video starts in one place while userland thinks it starts
in another.  This manifests itself as the video being horizontally
shifted and there being garbage from the start of the field up to
that point.

This problem was seen with both the em28xx and uvc drivers when
testing on the Davinci platform (where the buffers allocated are
not necessarily page aligned).
---

diff --git a/linux/drivers/media/v4l2-core/videobuf2-vmalloc.c
b/linux/drivers/media/v4l2-core/videobuf2-vmalloc.c
index 94efa04..ad7ce7c 100644
--- a/linux/drivers/media/v4l2-core/videobuf2-vmalloc.c
+++ b/linux/drivers/media/v4l2-core/videobuf2-vmalloc.c
@@ -82,7 +82,7 @@ static void *vb2_vmalloc_get_userptr(void
*alloc_ctx, unsigned long vaddr,
  return NULL;

  buf->write = write;
- offset = vaddr & ~PAGE_MASK;
+ offset = 0;
  buf->size = size;

-- 
Devin J. Heitmueller - Kernel Labs
http://www.kernellabs.com

  reply	other threads:[~2014-04-18 13:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-10 12:20 REVIEW PATCH 0/3] saa7134: convert to vb2 Hans Verkuil
2014-03-10 12:20 ` [REVIEW PATCH 1/3] vb2: add thread support Hans Verkuil
2014-03-10 12:20 ` [REVIEW PATCH 2/3] vb2: Add videobuf2-dvb support Hans Verkuil
2014-03-10 12:20 ` [REVIEW PATCH 3/3] saa7134: convert to vb2 Hans Verkuil
2014-04-16 22:23   ` Mauro Carvalho Chehab
2014-04-16 22:33     ` Hans Verkuil
2014-04-17  2:17       ` Mauro Carvalho Chehab
2014-04-17  9:49         ` Hans Verkuil
2014-04-17 13:13           ` Mauro Carvalho Chehab
2014-04-18 11:45             ` Hans Verkuil
2014-04-18 13:49               ` Devin Heitmueller [this message]
2014-04-18 14:11                 ` Hans Verkuil
2014-04-18 14:28                   ` Devin Heitmueller

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='CAGoCfix1j8kLQQe3yMDj+bqi=Pyj_K+en31a-h32+HMzVU1arQ@mail.gmail.com' \
    --to=dheitmueller@kernellabs.com \
    --cc=hans.verkuil@cisco.com \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    --cc=m.chehab@samsung.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.