All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] mmaping with VIVT cache
@ 2010-09-16  0:25 P F
  2010-09-16 23:05 ` Russell King - ARM Linux
  0 siblings, 1 reply; 12+ messages in thread
From: P F @ 2010-09-16  0:25 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Russell,

--- On Tue, 9/14/10, Russell King - ARM Linux <linux@arm.linux.org.uk> wrote:
> 
> The fact is that mapping buffers as cacheable into
> userspace on non-
> coherent architectures _will_ result in the cache contents
> getting in
> the way of updates to the DMA'd buffer.? It's a
> fundamental property
> of such hardware implementations.

Thank you for the explanation.

I realize this is driver specific, but I would like to confirm that your
explanation matches my problem.  Unless I misunderstand the UVC driver,
the buffer which is mapped into userspace is distinct from the one which
is updated by DMA.

The mmap'd buffer is allocated by vmalloc_32(), and later mapped with
vmalloc_to_page()/vm_insert_page().  The DMA'd buffer is allocated by
usb_buffer_alloc().  At the appropriate time, the DMA'd buffer is
memcpy()'d into the mmap'd buffer, and userspace is allowed to handle it,
at which point it is corrupt.

Is this scenario consistent with your above explanation, or does your explanation require that the mmap'd buffer and DMA'd buffer be one and
the same?



      

^ permalink raw reply	[flat|nested] 12+ messages in thread
* [RFC] mmaping with VIVT cache
@ 2010-09-17 19:07 P F
  2010-09-17 21:06 ` Russell King - ARM Linux
  0 siblings, 1 reply; 12+ messages in thread
From: P F @ 2010-09-17 19:07 UTC (permalink / raw)
  To: linux-arm-kernel

--- On Thu, 9/16/10, Russell King - ARM Linux <linux@arm.linux.org.uk> wrote:
> On Wed, Sep 15, 2010 at 05:25:38PM-0700, P F wrote:
> > The mmap'd buffer is allocated by vmalloc_32(), and later mapped with
> > vmalloc_to_page()/vm_insert_page().? The DMA'dbuffer is allocated by
> > usb_buffer_alloc().? At the appropriate time, the DMA'd buffer is
> > memcpy()'d into the mmap'd buffer, and userspace is allowed to handle
> > it, at which point it is corrupt.
> 
> Ah, that's slightly different as you're not talking about
> the DMA buffers themselves.
> 
> However, anyone who is not familiar with VIVT or aliasing
> VIPT caches is going to be caught out by this sort of thing (which
> basically means most ARMs, and at least some PA-RISC.)

Again, thank you for the explanation, Russell.? For some reason I did not
quite grok the root cause of this issue before, but it is now clear to me.

> I don't think we have any APIs in the kernel to handle
> aliasing between the vmalloc space and userspace...

Perhaps I am revealing my ignorance of the driver ecosystem, but I find
this somewhat surprising.? I would think that this sort of construction
would not be uncommon.

For this issue, I can see two solutions:
1.) somehow make the vmalloc'd space non-cacheable so both the user- and
kernelspace mappings match, and there is no cache to alias
2.) invalidate the cache of the userspace mapping before handing the
buffer to userspace (after memcpy() above)

As Laurent noted earlier, (1) is a nonstarter as it has a negative
performance impact.? (2) I propose is a valid and correct solution.? This
is driver-specific, but each buffer corresponds to an image frame (e.g.,
from a webcam), so they are independent, and therefore it does not make
sense to share the cache between frames.? As long as userspace holds the
buffer, the cache is valid, but once it relinquishes the buffer, the cache
holds only stale data and should be purged.

>From your comment, I take it that there is no kernel API to invalidate the
cache of a range in a VMA.  Do you think linux-mm would be a more
appropriate forum to continue investigating?  Any input would be
appreciated.


      

^ permalink raw reply	[flat|nested] 12+ messages in thread
* [RFC] mmaping with VIVT cache
@ 2010-09-13 19:58 P F
  2010-09-14 23:50 ` Russell King - ARM Linux
  0 siblings, 1 reply; 12+ messages in thread
From: P F @ 2010-09-13 19:58 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

Please excuse the pseudonym.

I have recently encountered a problem in the context of the UVC (webcam)
driver.  The driver maintainer, Laurent, suggested that we bring the
thread to linux-arm-kernel for wider discussion.  See here for reference:
http://lists.berlios.de/pipermail/linux-uvc-devel/2010-August/005864.html

The problem I encountered was this: using an ARM926EJ-S with OHCI USB host,
I noticed intermittent graphical corruption of frames captured by several
different webcams, both UVC and non-UVC.

I was able to isolate the corruption down to one specific instance.  In
this instance, I collected three images:
1A.jpg - collected from host, prior to corruption
2A.jpg - collected from host, demonstrating corruption
2B.jpg - collected from inline USB analyzer, same image as 2A

Images 1A and 2A are in sequence, i.e., 2A immediately follows 1A.  2B is
not corrupted, and a binary diff between 2A and 2B shows two 32-byte
chunks have been changed.  A binary diff between 2A and 1A shows that
these same two chunks match.  Therefore, it seems there is some
contamination of the second image by the first.

As I described in the linked message, I found a workaround for this issue
by adding
  vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot)
in the UVC driver's mmap() function, but Laurent explained that this was
invalid.

Does anybody have ideas for a proper fix?  I can reproduce this corruption
easily, and would be happy to test proposed patches.

Best regards


      
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1A.jpg
Type: image/jpeg
Size: 10109 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20100913/147ad402/attachment-0003.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2A.jpg
Type: image/jpeg
Size: 11660 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20100913/147ad402/attachment-0004.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2B.jpg
Type: image/jpeg
Size: 11660 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20100913/147ad402/attachment-0005.jpg>

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2010-09-20 11:31 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-16  0:25 [RFC] mmaping with VIVT cache P F
2010-09-16 23:05 ` Russell King - ARM Linux
  -- strict thread matches above, loose matches on Subject: below --
2010-09-17 19:07 P F
2010-09-17 21:06 ` Russell King - ARM Linux
2010-09-20 10:38   ` Pawel Moll
2010-09-20 10:50     ` Russell King - ARM Linux
2010-09-20 11:31       ` Pawel Moll
2010-09-13 19:58 P F
2010-09-14 23:50 ` Russell King - ARM Linux
2010-09-15  1:06   ` Eric Miao
2010-09-15  7:31     ` Russell King - ARM Linux
2010-09-15  7:37       ` Eric Miao

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.