All of lore.kernel.org
 help / color / mirror / Atom feed
* usbfs zerocopy broken on ARM/ARM64
@ 2018-11-06 22:32 Steve Markgraf
  2018-11-07 11:35 ` Mark Rutland
  2018-11-07 12:31 ` Russell King - ARM Linux
  0 siblings, 2 replies; 5+ messages in thread
From: Steve Markgraf @ 2018-11-06 22:32 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

Preface: I've been directed here after posting this to linux-
usb at vger.kernel.org.

I'm the author of a userspace library that makes use of the usbfs
zerocopy-feature via libusb-1.0, and recently received a bug report that
garbage data is received with bulk transfers on ARM-based systems.

When I debugged the issue, I found out that the Kernel maps seemingly
random memory to my transfer buffers, containing memory of other
processes or even the Kernel itself.

The code that does the mapping in drivers/usb/core/devio.c:
(line 243 in v4.20-rc1)

> if (remap_pfn_range(vma, vma->vm_start,
>                     virt_to_phys(usbm->mem) >> PAGE_SHIFT,
>                     size, vma->vm_page_prot) < 0) {

With the following change the issue is fixed for ARM systems, but it
breaks x86 systems:

-                      virt_to_phys(usbm->mem) >> PAGE_SHIFT,
+                      page_to_pfn(virt_to_page(dma_addr)),

Both usbm->mem and dma_addr are returned by the previous call to
usb_alloc_coherent().
Here's an example of the pointers generated by the two macros on an
ARM64 system for the same buffer:

virt_to_phys(usbm->mem) >> PAGE_SHIFT: 00000000808693ce
page_to_pfn(virt_to_page(dma_addr)):   000000009775a856

>From what I read so far I got the impression that the 'proper' way would
be to use dma_mmap_coherent() with dma_addr instead of
remap_pfn_range(), however, I did not get it to work. Can anyone help
out?

Regards,
Steve

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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-06 22:32 usbfs zerocopy broken on ARM/ARM64 Steve Markgraf
2018-11-07 11:35 ` Mark Rutland
2018-11-07 12:23   ` Robin Murphy
2018-11-07 12:31 ` Russell King - ARM Linux
2018-11-09 20:58   ` Steve Markgraf

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.