Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752001AbdHCNUT (ORCPT ); Thu, 3 Aug 2017 09:20:19 -0400 Received: from foss.arm.com ([217.140.101.70]:40448 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751815AbdHCNUQ (ORCPT ); Thu, 3 Aug 2017 09:20:16 -0400 Subject: Re: [PATCH v2] dma-mapping: skip USB devices when configuring DMA during probe To: Johan Hovold , Christoph Hellwig , Marek Szyprowski , Greg Kroah-Hartman Cc: =?UTF-8?Q?Andreas_F=c3=a4rber?= , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, stable , Sricharan R , Stefan Wahren References: <20170803131444.4101-1-johan@kernel.org> From: Robin Murphy Message-ID: Date: Thu, 3 Aug 2017 14:20:11 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170803131444.4101-1-johan@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3435 Lines: 97 On 03/08/17 14:14, Johan Hovold wrote: > USB devices use the DMA mask and offset of the controller, which have > already been setup when a device is probed. Note that modifying the > DMA mask of a USB device would change the mask for the controller (and > all devices on the bus) as the mask is literally shared. > > Since commit 2bf698671205 ("USB: of: fix root-hub device-tree node > handling"), of_dma_configure() would be called also for root hubs, which > use the device node of the controller. A separate, long-standing bug > that makes of_dma_configure() generate a 30-bit DMA mask from the RPI3's > "dma-ranges" would thus set a broken mask also for the controller. This > in turn prevents USB devices from enumerating when control transfers > fail: > > dwc2 3f980000.usb: Cannot do DMA to address 0x000000003a166a00 > > Note that the aforementioned DMA-mask bug was benign for the HCD itself > as the dwc2 driver overwrites the mask previously set by > of_dma_configure() for the platform device in its probe callback. The > mask would only later get corrupted when the root-hub child device was > probed. > > Fix this, and similar future problems, by simply skipping USB devices > when dma_configure() is called during probe. > > Fixes: 09515ef5ddad ("of/acpi: Configure dma operations at probe time for platform/amba/pci bus devices") > Cc: stable # 4.12 > Cc: Robin Murphy > Cc: Sricharan R > Cc: Stefan Wahren > Reported-by: Hans Verkuil > Signed-off-by: Johan Hovold Reviewed-by: Robin Murphy > --- > > v2 > - amend commit message and point out that the long-standing 30-bit DMA-mask > bug was benign to the dwc2 HCD itself (Robin) > - add and use a new dev_is_usb() helper (Robin) > > > drivers/base/dma-mapping.c | 8 ++++++++ > include/linux/usb.h | 5 +++++ > 2 files changed, 13 insertions(+) > > diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c > index b555ff9dd8fc..604e99e6660a 100644 > --- a/drivers/base/dma-mapping.c > +++ b/drivers/base/dma-mapping.c > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > #include > > /* > @@ -345,6 +346,10 @@ int dma_configure(struct device *dev) > enum dev_dma_attr attr; > int ret = 0; > > + /* USB devices share the controller's mask. */ > + if (dev_is_usb(dev)) > + return 0; > + > if (dev_is_pci(dev)) { > bridge = pci_get_host_bridge_device(to_pci_dev(dev)); > dma_dev = bridge; > @@ -369,6 +374,9 @@ int dma_configure(struct device *dev) > > void dma_deconfigure(struct device *dev) > { > + if (dev_is_usb(dev)) > + return; > + > of_dma_deconfigure(dev); > acpi_dma_deconfigure(dev); > } > diff --git a/include/linux/usb.h b/include/linux/usb.h > index cb9fbd54386e..f86ad9d8c756 100644 > --- a/include/linux/usb.h > +++ b/include/linux/usb.h > @@ -1222,6 +1222,11 @@ struct usb_device_driver { > > extern struct bus_type usb_bus_type; > > +static inline bool dev_is_usb(struct device *dev) > +{ > + return dev->bus == &usb_bus_type; > +} > + > /** > * struct usb_class_driver - identifies a USB driver that wants to use the USB major number > * @name: the usb class device name for this driver. Will show up in sysfs. >