From: Greg KH <gregkh@linuxfoundation.org>
To: Jeremy Linton <jeremy.linton@arm.com>
Cc: linux-usb@vger.kernel.org, stern@rowland.harvard.edu,
git@thegavinli.com, jarkko.sakkinen@linux.intel.com,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] usb: usbfs: correct kernel->user page attribute mismatch
Date: Fri, 1 May 2020 09:05:00 +0200 [thread overview]
Message-ID: <20200501070500.GA887524@kroah.com> (raw)
In-Reply-To: <20200430211922.929165-1-jeremy.linton@arm.com>
On Thu, Apr 30, 2020 at 04:19:22PM -0500, Jeremy Linton wrote:
> On arm64, and possibly other architectures, requesting
> IO coherent memory may return Normal-NC if the underlying
> hardware isn't coherent. If these pages are then
> remapped into userspace as Normal, that defeats the
> purpose of getting Normal-NC, as well as resulting in
> mappings with differing cache attributes.
What is "Normal-NC"?
> In particular this happens with libusb, when it attempts
> to create zero-copy buffers as is used by rtl-sdr, and
What is "rtl-sdr"
> maybe other applications. The result is usually
> application death.
So is this a new problem? Old problem? Old problem only showing up on
future devices? On current devices? I need a hint here as to know if
this is a bugfix or just work to make future devices work properly.
>
> If dma_mmap_attr() is used instead of remap_pfn_range,
> the page cache/etc attributes can be matched between the
> kernel and userspace.
>
> Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
> ---
> drivers/usb/core/devio.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
> index 6833c918abce..1e7458dd6e5d 100644
> --- a/drivers/usb/core/devio.c
> +++ b/drivers/usb/core/devio.c
> @@ -217,6 +217,7 @@ static int usbdev_mmap(struct file *file, struct vm_area_struct *vma)
> {
> struct usb_memory *usbm = NULL;
> struct usb_dev_state *ps = file->private_data;
> + struct usb_hcd *hcd = bus_to_hcd(ps->dev->bus);
> size_t size = vma->vm_end - vma->vm_start;
> void *mem;
> unsigned long flags;
> @@ -250,9 +251,7 @@ 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) {
> + if (dma_mmap_attrs(hcd->self.sysdev, vma, mem, dma_handle, size, 0)) {
Given that this code has not changed since 2016, how has no one noticed
this issue before?
And have you tested this change out on other systems (i.e. x86) to
ensure that this still works properly?
And why isn't this call used more by drivers if this is a real issue?
And will this cause issues with how the userspace mapping is handled as
now we rely on userspace to do things differently? Or am I reading the
dma_mmap_attrs() documentation wrong?
thanks,
greg k-h
next prev parent reply other threads:[~2020-05-01 7:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-30 21:19 [PATCH] usb: usbfs: correct kernel->user page attribute mismatch Jeremy Linton
2020-05-01 7:05 ` Greg KH [this message]
2020-05-01 10:37 ` Mark Rutland
2020-05-01 10:54 ` Marc Zyngier
2020-05-01 10:55 ` Greg KH
2020-05-01 15:36 ` Robin Murphy
2020-05-01 15:47 ` Jeremy Linton
2020-05-04 7:13 ` Greg KH
2020-05-04 13:21 ` Jeremy Linton
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=20200501070500.GA887524@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=git@thegavinli.com \
--cc=jarkko.sakkinen@linux.intel.com \
--cc=jeremy.linton@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
/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 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).