[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190227221917.62567-1-djkurtz@chromium.org>
Date: Wed, 27 Feb 2019 15:19:17 -0700
From: Daniel Kurtz <djkurtz@...omium.org>
To: unlisted-recipients:; (no To-header on input)
Cc: rrangel@...omium.org, Daniel Kurtz <djkurtz@...omium.org>,
Mathias Nyman <mathias.nyman@...el.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
linux-usb@...r.kernel.org (open list:USB XHCI DRIVER),
linux-kernel@...r.kernel.org (open list)
Subject: [PATCH] xhci: use iopoll for xhci_handshake
In cases such as xhci_abort_cmd_ring(), xhci_handshake() is called with
a spin lock held (and local interrupts disabled) with a huge 5 second
timeout. This can translates to 5 million calls to udelay(1). By its
very nature, udelay() is not meant to be precise, it only guarantees to
delay a minimum of 1 microsecond. Therefore the actual delay of
xhci_handshake() can be significantly longer. If the average udelay(1)
is greater than 2.2 us, the total time in xhci_handshake() - with
interrupts disabled can be > 11 seconds triggering the kernel's soft lockup
detector.
To avoid this, let's replace the open coded io polling loop with one from
iopoll.h that uses a loop timed with the more presumably reliable ktime
infrastructure.
Signed-off-by: Daniel Kurtz <djkurtz@...omium.org>
---
drivers/usb/host/xhci.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 005e65922608e..fde5ff84ba69b 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -16,6 +16,7 @@
#include <linux/slab.h>
#include <linux/dmi.h>
#include <linux/dma-mapping.h>
+#include <linux/iopoll.h>
#include "xhci.h"
#include "xhci-trace.h"
@@ -69,18 +70,18 @@ static bool td_on_ring(struct xhci_td *td, struct xhci_ring *ring)
int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, int usec)
{
u32 result;
+ int ret;
- do {
- result = readl(ptr);
- if (result == ~(u32)0) /* card removed */
- return -ENODEV;
- result &= mask;
- if (result == done)
- return 0;
- udelay(1);
- usec--;
- } while (usec > 0);
- return -ETIMEDOUT;
+ ret = readl_poll_timeout_atomic(ptr, result,
+ ((result & mask) == done || (result == ~(u32)0)),
+ 1, usec);
+ if (ret)
+ return ret;
+
+ if (result == ~(u32)0) /* card removed */
+ return -ENODEV;
+
+ return 0;
}
/*
--
2.21.0.rc2.261.ga7da99ff1b-goog
Powered by blists - more mailing lists