Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp795095ybz; Fri, 1 May 2020 08:40:43 -0700 (PDT) X-Google-Smtp-Source: APiQypI4EK9ptLTbgDBNEHjRm08/KPpJqE3Wuj+UDKoZ6a9gFV527TNxrl1bny9+TkTra0+cZTBI X-Received: by 2002:a17:906:d8cf:: with SMTP id re15mr3649079ejb.186.1588347643052; Fri, 01 May 2020 08:40:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588347643; cv=none; d=google.com; s=arc-20160816; b=apDqUHIUmxPLioEkJbaTCb3cotKA6hqIs28pJxlhHRV9mV4GXRwzeDrvI1VjpI4dBP KWKfOmhr25riAaWYeuL1VNJCLL+jg1PLCa4uEJWpwoMwfaWto++cihTG8DFypp3YvICp mtT5pr7YcPNbnUe/vlGEIYi+Wkki4TM/hKG/PDeWFH2rchAanWceKT6BYP6A+3436ATt CCJ2aMvY0FYA/Y0bv6vKh4qSOXIT3qZPgL8DbmKVN+TE/eQF2c7P9pfHAXStxlj55pHY jNod0YNiQrR23o6HoVSFd49Hd2EosKAfHF5jQUz4gXkTeWlp2HtH9MmtPpf5LJEojCKg YiQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=QVpSqiom+qi+0tizuCDZqE5qcMmaHi8/uTjw/5ilPc8=; b=iL4rNUPXxXIVF/uYa6EfHW71cCh79yP4TyA8CmjsmmTovjrwrAraTlvc1ULpenUMfL mXmgAOAlJi4JRU5wYcCd7y8JZiorevE0IcjhIXNjR+SiMYjX/q3PJbMStpDpQHeAqpXR vXlRRBNiy8n+RDEwCk9UsmLUMN8TDSboSLr4y4cs13wv8UwGcMjsHyFx3NlUgzpIQlmL hLdt7PX8QHYH2lxEgS6X26C8M9EzugTuwDGwRMizISx6+VtrPIx7n6JLLw6HHOMDSNce 5y2MiPHJMUIUst1NuSW9JB+4jb66XDWQDY9HD8drcUCutCvy1I5IS8S3mOdKqDx8YVaT LE2Q== ARC-Authentication-Results: i=1; mx.google.com; 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 s13si1969552ejd.436.2020.05.01.08.40.20; Fri, 01 May 2020 08:40:43 -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; 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 S1729812AbgEAPgW (ORCPT + 99 others); Fri, 1 May 2020 11:36:22 -0400 Received: from foss.arm.com ([217.140.110.172]:42798 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729008AbgEAPgW (ORCPT ); Fri, 1 May 2020 11:36:22 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 53DA130E; Fri, 1 May 2020 08:36:21 -0700 (PDT) Received: from [10.57.39.240] (unknown [10.57.39.240]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 050AD3F68F; Fri, 1 May 2020 08:36:19 -0700 (PDT) Subject: Re: [PATCH] usb: usbfs: correct kernel->user page attribute mismatch To: Greg KH , Jeremy Linton Cc: git@thegavinli.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, jarkko.sakkinen@linux.intel.com, stern@rowland.harvard.edu, linux-arm-kernel@lists.infradead.org References: <20200430211922.929165-1-jeremy.linton@arm.com> <20200501070500.GA887524@kroah.com> From: Robin Murphy Message-ID: Date: Fri, 1 May 2020 16:36:17 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200501070500.GA887524@kroah.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-05-01 8:05 am, Greg KH wrote: > 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? They have. Here's where the most recent one in my inbox ended, which has breadcrumbs to a couple more: https://lore.kernel.org/linux-arm-kernel/20190808130525.GA1756@kroah.com/ Note the author ;) From memory, all the previous attempts wound up getting stuck on the subtlety that buffers from hcd_alloc() may or may not actually have come from the DMA API. Since then, the localmem_pool rework has probably helped a bit, but I'm not sure we've ever really nailed down whether kmalloc()ed buffers from PIO-mode controllers (i.e. the !hcd_uses_dma() case) can end up down this devio path. Robin.