usb: devio: fix mmap() on non-coherent DMA architectures
PATCH v2 1/1 usb: devio: fix mmap() on non-coherent DMA architectures
From: Gavin Li <[email protected]>
On architectures that are not (or are optionally) DMA coherent, dma_alloc_coherent() returns an address into the vmalloc space, and calling virt_to_phys() on this address returns an unusable physical address.
This patch replaces the raw remap_pfn_range() call with a call to dmap_mmap_coherent(), which takes care of the differences between coherent and non-coherent code paths.
Tested on an arm64 rk3399 board.
--- drivers/usb/core/devio.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/usb/core/devio.c +3 -4
@@ -250,11 +250,10 @@ static int usbdev_mmap(struct file *file, struct vm_area_struct *vma) usbm->vma_use_count =1 ;INIT_LIST_HEAD (&usbm->memlist); -if (remap_pfn_range (vma, vma->vm_start, -virt_to_phys (usbm->mem) >>PAGE_SHIFT , - size, vma->vm_page_prot) <0 ) { + ret =dma_mmap_coherent (ps->dev->bus->sysdev, vma, mem, dma_handle, size); +if (ret) {dec_usb_memory_use_count (usbm, &usbm->vma_use_count); -return -EAGAIN ; +return ret; } vma->vm_flags |=VM_IO ;
Signature · 1 line
2.26.2
Resubmitting this patch from a few months ago now that the "x86/PAT:
... map pfn RAM range req uncached-minus" warning mentioned earlier seems to have been fixed.
Quoted 39 lines · On Wed, May 6, 2020 at 5:57 PM <[email protected]> wrote:
From: Gavin Li <[email protected]>
On architectures that are not (or are optionally) DMA coherent,
dma_alloc_coherent()returns an address into the vmalloc space, and callingvirt_to_phys()on this address returns an unusable physical address.This patch replaces the raw
remap_pfn_range()call with a call todmap_mmap_coherent(), which takes care of the differences between coherent and non-coherent code paths.Tested on an arm64 rk3399 board.
--- drivers/usb/core/devio.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/usb/core/devio.c +3
-5@@ -250,11 +250,10 @@ static int usbdev_mmap(struct file *file, struct vm_area_struct *vma) usbm->vma_use_count =1 ;INIT_LIST_HEAD (&usbm->memlist); -if (remap_pfn_range (vma, vma->vm_start, -virt_to_phys (usbm->mem) >>PAGE_SHIFT , - size, vma->vm_page_prot) <0 ) { + ret =dma_mmap_coherent (ps->dev->bus->sysdev, vma, mem, dma_handle, size); +if (ret) {dec_usb_memory_use_count (usbm, &usbm->vma_use_count); -return -EAGAIN ; +return ret; } vma->vm_flags |=VM_IO ; --2.26.2
Greg Kroah-Hartman
maintainerQuoted 7 lines · On Wed, May 06, 2020 at 05:56:47PM -0700, [email protected] wrote:
From: Gavin Li <[email protected]>
On architectures that are not (or are optionally) DMA coherent,
dma_alloc_coherent()returns an address into the vmalloc space, and callingvirt_to_phys()on this address returns an unusable physical address.
Quoted 8 lines
This patch replaces the raw
remap_pfn_range()call with a call todmap_mmap_coherent(), which takes care of the differences between coherent and non-coherent code paths.Tested on an arm64 rk3399 board.
--- drivers/usb/core/devio.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
I don't think you ran checkpatch.pl on your patch :(
Also, please see 2bef9aed6f0e ("usb: usbfs: correct kernel->user page attribute mismatch") in linux-next, does that resolve this problem for you? I think it does the same thing as your patch does...
thanks,
greg k-h