linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] usb: devio: fix mmap() on non-coherent DMA architectures
@ 2020-05-07  0:56 gavinli
  2020-05-07  0:59 ` Gavin Li
  2020-05-07  6:39 ` Greg Kroah-Hartman
  0 siblings, 2 replies; 3+ messages in thread
From: gavinli @ 2020-05-07  0:56 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-usb, Gavin Li

From: Gavin Li <gavinli@thegavinli.com>

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(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 6833c918abce..9d0043dd8e64 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -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


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

* Re: [PATCH v2] usb: devio: fix mmap() on non-coherent DMA architectures
  2020-05-07  0:56 [PATCH v2] usb: devio: fix mmap() on non-coherent DMA architectures gavinli
@ 2020-05-07  0:59 ` Gavin Li
  2020-05-07  6:39 ` Greg Kroah-Hartman
  1 sibling, 0 replies; 3+ messages in thread
From: Gavin Li @ 2020-05-07  0:59 UTC (permalink / raw)
  Cc: Greg Kroah-Hartman, linux-usb

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.


On Wed, May 6, 2020 at 5:57 PM <gavinli@thegavinli.com> wrote:
>
> From: Gavin Li <gavinli@thegavinli.com>
>
> 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(-)
>
> diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
> index 6833c918abce..9d0043dd8e64 100644
> --- a/drivers/usb/core/devio.c
> +++ b/drivers/usb/core/devio.c
> @@ -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
>

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

* Re: [PATCH v2] usb: devio: fix mmap() on non-coherent DMA architectures
  2020-05-07  0:56 [PATCH v2] usb: devio: fix mmap() on non-coherent DMA architectures gavinli
  2020-05-07  0:59 ` Gavin Li
@ 2020-05-07  6:39 ` Greg Kroah-Hartman
  1 sibling, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2020-05-07  6:39 UTC (permalink / raw)
  To: gavinli; +Cc: linux-usb

On Wed, May 06, 2020 at 05:56:47PM -0700, gavinli@thegavinli.com wrote:
> From: Gavin Li <gavinli@thegavinli.com>
> 
> 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(-)

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

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

end of thread, other threads:[~2020-05-07  6:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-07  0:56 [PATCH v2] usb: devio: fix mmap() on non-coherent DMA architectures gavinli
2020-05-07  0:59 ` Gavin Li
2020-05-07  6:39 ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).