From: Johan Hovold <johan@kernel.org>
To: Christoph Hellwig <hch@lst.de>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Andreas Färber" <afaerber@suse.de>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
"Alan Stern" <stern@rowland.harvard.edu>,
"Johan Hovold" <johan@kernel.org>,
stable <stable@vger.kernel.org>,
"Robin Murphy" <robin.murphy@arm.com>,
"Sricharan R" <sricharan@codeaurora.org>,
"Stefan Wahren" <stefan.wahren@i2se.com>
Subject: [PATCH v3] dma-mapping: skip USB devices when configuring DMA during probe
Date: Thu, 3 Aug 2017 17:52:08 +0200 [thread overview]
Message-ID: <20170803155208.22165-1-johan@kernel.org> (raw)
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 adding a flag to struct device
which prevents driver core from calling dma_configure() during probe and
making sure it is set for USB devices.
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>
---
v3
- add flag to struct device to prevent DMA configuration during probe instead
of checking for the USB bus type, which is not available when USB is built
as a module as noted by Alan
- drop moderated rpi list from CC
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 | 6 ++++++
drivers/usb/core/usb.c | 1 +
include/linux/device.h | 3 +++
3 files changed, 10 insertions(+)
diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c
index b555ff9dd8fc..f9f703be0ad1 100644
--- a/drivers/base/dma-mapping.c
+++ b/drivers/base/dma-mapping.c
@@ -345,6 +345,9 @@ int dma_configure(struct device *dev)
enum dev_dma_attr attr;
int ret = 0;
+ if (dev->skip_dma_configure)
+ return 0;
+
if (dev_is_pci(dev)) {
bridge = pci_get_host_bridge_device(to_pci_dev(dev));
dma_dev = bridge;
@@ -369,6 +372,9 @@ int dma_configure(struct device *dev)
void dma_deconfigure(struct device *dev)
{
+ if (dev->skip_dma_configure)
+ return;
+
of_dma_deconfigure(dev);
acpi_dma_deconfigure(dev);
}
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 17681d5638ac..2a85d905b539 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -588,6 +588,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
* Note: calling dma_set_mask() on a USB device would set the
* mask for the entire HCD, so don't do that.
*/
+ dev->dev.skip_dma_configure = true;
dev->dev.dma_mask = bus->sysdev->dma_mask;
dev->dev.dma_pfn_offset = bus->sysdev->dma_pfn_offset;
set_dev_node(&dev->dev, dev_to_node(bus->sysdev));
diff --git a/include/linux/device.h b/include/linux/device.h
index 723cd54b94da..022cf258068b 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -877,6 +877,8 @@ struct dev_links_info {
* @offline: Set after successful invocation of bus type's .offline().
* @of_node_reused: Set if the device-tree node is shared with an ancestor
* device.
+ * @skip_dma_configure: Set if driver core should not configure DMA for this
+ * device during probe.
*
* At the lowest level, every device in a Linux system is represented by an
* instance of struct device. The device structure contains the information
@@ -965,6 +967,7 @@ struct device {
bool offline_disabled:1;
bool offline:1;
bool of_node_reused:1;
+ bool skip_dma_configure:1;
};
static inline struct device *kobj_to_dev(struct kobject *kobj)
--
2.13.3
next reply other threads:[~2017-08-03 15:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-03 15:52 Johan Hovold [this message]
2017-08-03 16:07 ` [PATCH v3] dma-mapping: skip USB devices when configuring DMA during probe Greg Kroah-Hartman
2017-08-03 16:23 ` Johan Hovold
2017-08-05 8:38 ` Christoph Hellwig
2017-08-08 18:03 ` Johan Hovold
2017-08-11 6:02 ` Stefan Wahren
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=20170803155208.22165-1-johan@kernel.org \
--to=johan@kernel.org \
--cc=afaerber@suse.de \
--cc=gregkh@linuxfoundation.org \
--cc=hch@lst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=robin.murphy@arm.com \
--cc=sricharan@codeaurora.org \
--cc=stable@vger.kernel.org \
--cc=stefan.wahren@i2se.com \
--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).