Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp376289ybz; Fri, 1 May 2020 00:07:40 -0700 (PDT) X-Google-Smtp-Source: APiQypJlLob35/wbS0OqwBcLYJCfA0IEXbp1WzziSaHc6TZUJDcGkOhvkSfCl3q0lP8wI4TimLnh X-Received: by 2002:a17:907:262b:: with SMTP id aq11mr1911015ejc.277.1588316860577; Fri, 01 May 2020 00:07:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588316860; cv=none; d=google.com; s=arc-20160816; b=LLoozDDT7wgYyzTfne1kLI5LpqqcxsprH4wd3f/XOwQZcnsxbkyGOLN04Qm4TP+RcX anTJugBvS0DitZnNx+8iDARDQsHT3IKAUoB4trdFBD1OezPkJKwq3UFJ6N7zJFTxPZ7F SMSE54xm6lJE+X0rX73qwWZqRVqDTDWKfqNYUL5Ul4QJKyCKHASKuY3us6JNGetFxoUh IodUG0MVqM1JU/EtZefLima9bc7Wua2yqTTzV0ACm3l0OZ2z9qfA4ncJFcs8z05wKrQX ndwBUGfmxZCWQEXMl5hwE7fEAiivJ4A/arfRWmgwBQbI9oRb7/6gu6twyoR+cBt/V83a 9xow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=S+hSmMEvdYwrVVWyaEw/TRHez5Ofyco9VFgTJljDiOs=; b=GWQQ/2K96XaPRAPCrAuTpmh/Oxpharc6BEtDcSWvlZgCjkWij0PU0FFRdjVk4OQ5nd ifl73oKmNwW2DIHYPkXhR7yFydL+MXLki0VHSGQajYxXkcvWxdF+WcoXqAaBFCla8INR GWEG316A/wXBLA3qFcEovt0QH4DF00wl1ToBa42W1FQkE5jb1hN6p+/nFQrTO2AS4Z3z PSPKgwhh1cxUvYeBu6QrC3PjAN4yPLXyIqkm9/Or9qAJtiDv+X56yrnP3U6SAzLpMcYM oHraTN9GLTIrB1I5LObcTF392sqIP0lU5evgEM630o3VOjWSH4kssDnaUWraYpQDSe/w lOrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0HQDrcct; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i25si1095973edb.304.2020.05.01.00.07.16; Fri, 01 May 2020 00:07:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0HQDrcct; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728304AbgEAHFD (ORCPT + 99 others); Fri, 1 May 2020 03:05:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:60176 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726452AbgEAHFD (ORCPT ); Fri, 1 May 2020 03:05:03 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3458D20787; Fri, 1 May 2020 07:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588316702; bh=+XNsx/y7wpr3wXy4+AywlP59DpP+Q7EqeGtvYes8QWk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=0HQDrcctKw6flmvjHVvIBWYkP25DJeJXiS0x+RkzSggT6XtcSFNPt0PjIwM6NmBw/ 72L/lTCOQWWxEHvoGp22DQ8IKTCVHcygWsxqpJ27+br65wjoP68yqHNdzdTK1U9A9q M9FwRrSn1Fj5fEpdJakqcJP0gm2B+VZrgkXud5dk= Date: Fri, 1 May 2020 09:05:00 +0200 From: Greg KH To: Jeremy Linton 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 Message-ID: <20200501070500.GA887524@kroah.com> References: <20200430211922.929165-1-jeremy.linton@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200430211922.929165-1-jeremy.linton@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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