stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] dma-mapping: skip USB devices when configuring DMA during probe
@ 2017-08-03 13:14 Johan Hovold
  2017-08-03 13:20 ` Robin Murphy
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Johan Hovold @ 2017-08-03 13:14 UTC (permalink / raw)
  To: Christoph Hellwig, Marek Szyprowski, Greg Kroah-Hartman
  Cc: Andreas Färber, linux-usb, linux-kernel, linux-rpi-kernel,
	Johan Hovold, stable, Robin Murphy, Sricharan R, Stefan Wahren

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 <stable@vger.kernel.org>	# 4.12
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Sricharan R <sricharan@codeaurora.org>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Reported-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Johan Hovold <johan@kernel.org>
---

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 <linux/gfp.h>
 #include <linux/of_device.h>
 #include <linux/slab.h>
+#include <linux/usb.h>
 #include <linux/vmalloc.h>
 
 /*
@@ -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.
-- 
2.13.3

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

* Re: [PATCH v2] dma-mapping: skip USB devices when configuring DMA during probe
  2017-08-03 13:14 [PATCH v2] dma-mapping: skip USB devices when configuring DMA during probe Johan Hovold
@ 2017-08-03 13:20 ` Robin Murphy
  2017-08-03 14:04 ` Alan Stern
  2017-08-06 11:27 ` kbuild test robot
  2 siblings, 0 replies; 9+ messages in thread
From: Robin Murphy @ 2017-08-03 13:20 UTC (permalink / raw)
  To: Johan Hovold, Christoph Hellwig, Marek Szyprowski,
	Greg Kroah-Hartman
  Cc: Andreas Färber, linux-usb, linux-kernel, linux-rpi-kernel,
	stable, Sricharan R, Stefan Wahren

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 <stable@vger.kernel.org>	# 4.12
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Sricharan R <sricharan@codeaurora.org>
> Cc: Stefan Wahren <stefan.wahren@i2se.com>
> Reported-by: Hans Verkuil <hverkuil@xs4all.nl>
> Signed-off-by: Johan Hovold <johan@kernel.org>

Reviewed-by: Robin Murphy <robin.murphy@arm.com>

> ---
> 
> 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 <linux/gfp.h>
>  #include <linux/of_device.h>
>  #include <linux/slab.h>
> +#include <linux/usb.h>
>  #include <linux/vmalloc.h>
>  
>  /*
> @@ -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.
> 

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

* Re: [PATCH v2] dma-mapping: skip USB devices when configuring DMA during probe
  2017-08-03 13:14 [PATCH v2] dma-mapping: skip USB devices when configuring DMA during probe Johan Hovold
  2017-08-03 13:20 ` Robin Murphy
@ 2017-08-03 14:04 ` Alan Stern
  2017-08-03 14:23   ` Johan Hovold
  2017-08-06 11:27 ` kbuild test robot
  2 siblings, 1 reply; 9+ messages in thread
From: Alan Stern @ 2017-08-03 14:04 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Christoph Hellwig, Marek Szyprowski, Greg Kroah-Hartman,
	Andreas Färber, linux-usb, linux-kernel, linux-rpi-kernel,
	stable, Robin Murphy, Sricharan R, Stefan Wahren

On Thu, 3 Aug 2017, 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 <stable@vger.kernel.org>	# 4.12
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Sricharan R <sricharan@codeaurora.org>
> Cc: Stefan Wahren <stefan.wahren@i2se.com>
> Reported-by: Hans Verkuil <hverkuil@xs4all.nl>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
> 
> 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)


> 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;
> +}
> +

Will this work if the USB subsystem is built as a module?

Alan Stern

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

* Re: [PATCH v2] dma-mapping: skip USB devices when configuring DMA during probe
  2017-08-03 14:04 ` Alan Stern
@ 2017-08-03 14:23   ` Johan Hovold
  2017-08-03 14:48     ` Robin Murphy
  2017-08-03 14:49     ` Johan Hovold
  0 siblings, 2 replies; 9+ messages in thread
From: Johan Hovold @ 2017-08-03 14:23 UTC (permalink / raw)
  To: Alan Stern
  Cc: Johan Hovold, Christoph Hellwig, Marek Szyprowski,
	Greg Kroah-Hartman, Andreas Färber, linux-usb, linux-kernel,
	linux-rpi-kernel, stable, Robin Murphy, Sricharan R,
	Stefan Wahren

On Thu, Aug 03, 2017 at 10:04:21AM -0400, Alan Stern wrote:
> On Thu, 3 Aug 2017, 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 <stable@vger.kernel.org>	# 4.12
> > Cc: Robin Murphy <robin.murphy@arm.com>
> > Cc: Sricharan R <sricharan@codeaurora.org>
> > Cc: Stefan Wahren <stefan.wahren@i2se.com>
> > Reported-by: Hans Verkuil <hverkuil@xs4all.nl>
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> > ---

> > 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;
> > +}
> > +
> 
> Will this work if the USB subsystem is built as a module?

Nope. :-/

Add another flag (e.g. skip_dma_configure) to struct device for now?

Thanks,
Johan

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

* Re: [PATCH v2] dma-mapping: skip USB devices when configuring DMA during probe
  2017-08-03 14:23   ` Johan Hovold
@ 2017-08-03 14:48     ` Robin Murphy
  2017-08-03 14:53       ` Johan Hovold
  2017-08-03 14:49     ` Johan Hovold
  1 sibling, 1 reply; 9+ messages in thread
From: Robin Murphy @ 2017-08-03 14:48 UTC (permalink / raw)
  To: Johan Hovold, Alan Stern
  Cc: Christoph Hellwig, Marek Szyprowski, Greg Kroah-Hartman,
	Andreas Färber, linux-usb, linux-kernel, linux-rpi-kernel,
	stable, Sricharan R, Stefan Wahren

On 03/08/17 15:23, Johan Hovold wrote:
> On Thu, Aug 03, 2017 at 10:04:21AM -0400, Alan Stern wrote:
>> On Thu, 3 Aug 2017, 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 <stable@vger.kernel.org>	# 4.12
>>> Cc: Robin Murphy <robin.murphy@arm.com>
>>> Cc: Sricharan R <sricharan@codeaurora.org>
>>> Cc: Stefan Wahren <stefan.wahren@i2se.com>
>>> Reported-by: Hans Verkuil <hverkuil@xs4all.nl>
>>> Signed-off-by: Johan Hovold <johan@kernel.org>
>>> ---
> 
>>> 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;
>>> +}
>>> +
>>
>> Will this work if the USB subsystem is built as a module?
> 
> Nope. :-/

Oh bum, I hadn't even realised usb_bus_type could be modular.

> Add another flag (e.g. skip_dma_configure) to struct device for now?

Would it be sufficient to look for dev->of_node_reused, or is it also
possible for USB devices to have OF nodes of their own such that
of_dma_configure() would still blat the mask with a 32-bit default?
(Although that would still un-break Rpi3, even if strictly wrong)

Robin.

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

* Re: [PATCH v2] dma-mapping: skip USB devices when configuring DMA during probe
  2017-08-03 14:23   ` Johan Hovold
  2017-08-03 14:48     ` Robin Murphy
@ 2017-08-03 14:49     ` Johan Hovold
  2017-08-03 15:57       ` Johan Hovold
  1 sibling, 1 reply; 9+ messages in thread
From: Johan Hovold @ 2017-08-03 14:49 UTC (permalink / raw)
  To: Alan Stern
  Cc: Johan Hovold, Christoph Hellwig, Marek Szyprowski,
	Greg Kroah-Hartman, Andreas Färber, linux-usb, linux-kernel,
	linux-rpi-kernel, stable, Robin Murphy, Sricharan R,
	Stefan Wahren

On Thu, Aug 03, 2017 at 04:23:08PM +0200, Johan Hovold wrote:
> On Thu, Aug 03, 2017 at 10:04:21AM -0400, Alan Stern wrote:
> > On Thu, 3 Aug 2017, 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 <stable@vger.kernel.org>	# 4.12
> > > Cc: Robin Murphy <robin.murphy@arm.com>
> > > Cc: Sricharan R <sricharan@codeaurora.org>
> > > Cc: Stefan Wahren <stefan.wahren@i2se.com>
> > > Reported-by: Hans Verkuil <hverkuil@xs4all.nl>
> > > Signed-off-by: Johan Hovold <johan@kernel.org>
> > > ---
> 
> > > 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;
> > > +}
> > > +
> > 
> > Will this work if the USB subsystem is built as a module?
> 
> Nope. :-/
> 
> Add another flag (e.g. skip_dma_configure) to struct device for now?

Or we can make sure that of_dma_configure() is only ever called for
platform_devices by checking against platform_bus_type instead.

I guess this was the intention of 09515ef5ddad ("of/acpi: Configure dma
operations at probe time for platform/amba/pci bus devices") too.

Thanks,
Johan

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

* Re: [PATCH v2] dma-mapping: skip USB devices when configuring DMA during probe
  2017-08-03 14:48     ` Robin Murphy
@ 2017-08-03 14:53       ` Johan Hovold
  0 siblings, 0 replies; 9+ messages in thread
From: Johan Hovold @ 2017-08-03 14:53 UTC (permalink / raw)
  To: Robin Murphy
  Cc: Johan Hovold, Alan Stern, Christoph Hellwig, Marek Szyprowski,
	Greg Kroah-Hartman, Andreas Färber, linux-usb, linux-kernel,
	linux-rpi-kernel, stable, Sricharan R, Stefan Wahren

On Thu, Aug 03, 2017 at 03:48:06PM +0100, Robin Murphy wrote:
> On 03/08/17 15:23, Johan Hovold wrote:
> > On Thu, Aug 03, 2017 at 10:04:21AM -0400, Alan Stern wrote:
> >> On Thu, 3 Aug 2017, Johan Hovold wrote:
> >>> 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;
> >>> +}
> >>> +
> >>
> >> Will this work if the USB subsystem is built as a module?
> > 
> > Nope. :-/
> 
> Oh bum, I hadn't even realised usb_bus_type could be modular.
> 
> > Add another flag (e.g. skip_dma_configure) to struct device for now?
> 
> Would it be sufficient to look for dev->of_node_reused, or is it also
> possible for USB devices to have OF nodes of their own such that
> of_dma_configure() would still blat the mask with a 32-bit default?
> (Although that would still un-break Rpi3, even if strictly wrong)

Yes, USB devices can have their own OF nodes so of_node_reused would not
prevent of_dma_configure() from being called for them.

But testing against the platform bus instead of not-USB should do the
trick.

Johan

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

* Re: [PATCH v2] dma-mapping: skip USB devices when configuring DMA during probe
  2017-08-03 14:49     ` Johan Hovold
@ 2017-08-03 15:57       ` Johan Hovold
  0 siblings, 0 replies; 9+ messages in thread
From: Johan Hovold @ 2017-08-03 15:57 UTC (permalink / raw)
  To: Alan Stern
  Cc: Johan Hovold, Christoph Hellwig, Marek Szyprowski,
	Greg Kroah-Hartman, Andreas Färber, linux-usb, linux-kernel,
	linux-rpi-kernel, stable, Robin Murphy, Sricharan R,
	Stefan Wahren

On Thu, Aug 03, 2017 at 04:49:24PM +0200, Johan Hovold wrote:
> On Thu, Aug 03, 2017 at 04:23:08PM +0200, Johan Hovold wrote:
> > On Thu, Aug 03, 2017 at 10:04:21AM -0400, Alan Stern wrote:
> > > On Thu, 3 Aug 2017, 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 <stable@vger.kernel.org>	# 4.12
> > > > Cc: Robin Murphy <robin.murphy@arm.com>
> > > > Cc: Sricharan R <sricharan@codeaurora.org>
> > > > Cc: Stefan Wahren <stefan.wahren@i2se.com>
> > > > Reported-by: Hans Verkuil <hverkuil@xs4all.nl>
> > > > Signed-off-by: Johan Hovold <johan@kernel.org>
> > > > ---
> > 
> > > > 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;
> > > > +}
> > > > +
> > > 
> > > Will this work if the USB subsystem is built as a module?
> > 
> > Nope. :-/
> > 
> > Add another flag (e.g. skip_dma_configure) to struct device for now?
> 
> Or we can make sure that of_dma_configure() is only ever called for
> platform_devices by checking against platform_bus_type instead.
> 
> I guess this was the intention of 09515ef5ddad ("of/acpi: Configure dma
> operations at probe time for platform/amba/pci bus devices") too.

Or perhaps not, as of_dma_configure() should also be called for pci
devices.

I suggest adding a new flag to struct device.

Johan

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

* Re: [PATCH v2] dma-mapping: skip USB devices when configuring DMA during probe
  2017-08-03 13:14 [PATCH v2] dma-mapping: skip USB devices when configuring DMA during probe Johan Hovold
  2017-08-03 13:20 ` Robin Murphy
  2017-08-03 14:04 ` Alan Stern
@ 2017-08-06 11:27 ` kbuild test robot
  2 siblings, 0 replies; 9+ messages in thread
From: kbuild test robot @ 2017-08-06 11:27 UTC (permalink / raw)
  To: Johan Hovold
  Cc: kbuild-all, Christoph Hellwig, Marek Szyprowski,
	Greg Kroah-Hartman, Andreas Färber, linux-usb, linux-kernel,
	linux-rpi-kernel, Johan Hovold, stable, Robin Murphy, Sricharan R,
	Stefan Wahren

[-- Attachment #1: Type: text/plain, Size: 998 bytes --]

Hi Johan,

[auto build test ERROR on driver-core/driver-core-testing]
[also build test ERROR on v4.13-rc3 next-20170804]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Johan-Hovold/dma-mapping-skip-USB-devices-when-configuring-DMA-during-probe/20170804-155414
config: x86_64-randconfig-a0-08061415 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

   drivers/base/dma-mapping.o: In function `dma_configure':
>> (.text+0x7de): undefined reference to `usb_bus_type'
   drivers/base/dma-mapping.o: In function `dma_deconfigure':
   (.text+0x8ca): undefined reference to `usb_bus_type'

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 21909 bytes --]

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

end of thread, other threads:[~2017-08-06 11:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-03 13:14 [PATCH v2] dma-mapping: skip USB devices when configuring DMA during probe Johan Hovold
2017-08-03 13:20 ` Robin Murphy
2017-08-03 14:04 ` Alan Stern
2017-08-03 14:23   ` Johan Hovold
2017-08-03 14:48     ` Robin Murphy
2017-08-03 14:53       ` Johan Hovold
2017-08-03 14:49     ` Johan Hovold
2017-08-03 15:57       ` Johan Hovold
2017-08-06 11:27 ` kbuild test robot

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