linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] usb: xhci: fix uninitialized completion when USB3 port got wrong status
@ 2018-10-22 17:42 Aaron Ma
  2018-10-22 17:42 ` [PATCH v2 2/2] usb: xhci: fix timeout for transition from RExit to U0 Aaron Ma
  2018-10-23 10:42 ` [PATCH v2 1/2] usb: xhci: fix uninitialized completion when USB3 port got wrong status Mathias Nyman
  0 siblings, 2 replies; 4+ messages in thread
From: Aaron Ma @ 2018-10-22 17:42 UTC (permalink / raw)
  To: aaron.ma, mathias.nyman, gregkh, linux-usb, linux-kernel

Realtek USB3.0 Card Reader [0bda:0328] reports wrong port status on
Cannon lake PCH USB3.1 xHCI [8086:a36d] after resume from S3,
after clear port reset it works fine.

Since this device is registered on USB3 roothub at boot,
when port status reports not superspeed, xhci_get_port_status will call
an uninitialized completion in bus_state[0].
Kernel will hang because of NULL pointer.

Restrict the USB2 resume status check in USB2 roothub to fix hang issue.

Cc: stable@vger.kernel.org
Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
---
 drivers/usb/host/xhci-hub.c  | 2 +-
 drivers/usb/host/xhci-ring.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 7e2a531ba321..56a08daa7431 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -876,7 +876,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
 			status |= USB_PORT_STAT_SUSPEND;
 	}
 	if ((raw_port_status & PORT_PLS_MASK) == XDEV_RESUME &&
-		!DEV_SUPERSPEED_ANY(raw_port_status)) {
+		!DEV_SUPERSPEED_ANY(raw_port_status) && hcd->speed < HCD_USB3) {
 		if ((raw_port_status & PORT_RESET) ||
 				!(raw_port_status & PORT_PE))
 			return 0xffffffff;
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index f0a99aa0ac58..7318fc422b6c 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1634,7 +1634,7 @@ static void handle_port_status(struct xhci_hcd *xhci,
 	 * RExit to a disconnect state).  If so, let the the driver know it's
 	 * out of the RExit state.
 	 */
-	if (!DEV_SUPERSPEED_ANY(portsc) &&
+	if (!DEV_SUPERSPEED_ANY(portsc) && hcd->speed < HCD_USB3 &&
 			test_and_clear_bit(hcd_portnum,
 				&bus_state->rexit_ports)) {
 		complete(&bus_state->rexit_done[hcd_portnum]);
-- 
2.19.1


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

* [PATCH v2 2/2] usb: xhci: fix timeout for transition from RExit to U0
  2018-10-22 17:42 [PATCH v2 1/2] usb: xhci: fix uninitialized completion when USB3 port got wrong status Aaron Ma
@ 2018-10-22 17:42 ` Aaron Ma
  2018-10-23 10:43   ` Mathias Nyman
  2018-10-23 10:42 ` [PATCH v2 1/2] usb: xhci: fix uninitialized completion when USB3 port got wrong status Mathias Nyman
  1 sibling, 1 reply; 4+ messages in thread
From: Aaron Ma @ 2018-10-22 17:42 UTC (permalink / raw)
  To: aaron.ma, mathias.nyman, gregkh, linux-usb, linux-kernel

This definition is used by msecs_to_jiffies in milliseconds.
According to the comments, max rexit timeout should be 20ms.
Align with the comments to properly calculate the delay.

Verified on Sunrise Point-LP and Cannon Lake.

Cc: stable@vger.kernel.org
Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
---
 drivers/usb/host/xhci-hub.c | 4 ++--
 drivers/usb/host/xhci.h     | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 56a08daa7431..af168ada8f86 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -920,7 +920,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
 			time_left = wait_for_completion_timeout(
 					&bus_state->rexit_done[wIndex],
 					msecs_to_jiffies(
-						XHCI_MAX_REXIT_TIMEOUT));
+						XHCI_MAX_REXIT_TIMEOUT_MS));
 			spin_lock_irqsave(&xhci->lock, flags);
 
 			if (time_left) {
@@ -934,7 +934,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
 			} else {
 				int port_status = readl(port->addr);
 				xhci_warn(xhci, "Port resume took longer than %i msec, port status = 0x%x\n",
-						XHCI_MAX_REXIT_TIMEOUT,
+						XHCI_MAX_REXIT_TIMEOUT_MS,
 						port_status);
 				status |= USB_PORT_STAT_SUSPEND;
 				clear_bit(wIndex, &bus_state->rexit_ports);
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 6230a578324c..237877042262 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1678,7 +1678,7 @@ struct xhci_bus_state {
  * It can take up to 20 ms to transition from RExit to U0 on the
  * Intel Lynx Point LP xHCI host.
  */
-#define	XHCI_MAX_REXIT_TIMEOUT	(20 * 1000)
+#define	XHCI_MAX_REXIT_TIMEOUT_MS	20
 
 static inline unsigned int hcd_index(struct usb_hcd *hcd)
 {
-- 
2.19.1


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

* Re: [PATCH v2 1/2] usb: xhci: fix uninitialized completion when USB3 port got wrong status
  2018-10-22 17:42 [PATCH v2 1/2] usb: xhci: fix uninitialized completion when USB3 port got wrong status Aaron Ma
  2018-10-22 17:42 ` [PATCH v2 2/2] usb: xhci: fix timeout for transition from RExit to U0 Aaron Ma
@ 2018-10-23 10:42 ` Mathias Nyman
  1 sibling, 0 replies; 4+ messages in thread
From: Mathias Nyman @ 2018-10-23 10:42 UTC (permalink / raw)
  To: Aaron Ma, mathias.nyman, gregkh, linux-usb, linux-kernel

On 22.10.2018 20:42, Aaron Ma wrote:
> Realtek USB3.0 Card Reader [0bda:0328] reports wrong port status on
> Cannon lake PCH USB3.1 xHCI [8086:a36d] after resume from S3,
> after clear port reset it works fine.
> 
> Since this device is registered on USB3 roothub at boot,
> when port status reports not superspeed, xhci_get_port_status will call
> an uninitialized completion in bus_state[0].
> Kernel will hang because of NULL pointer.
> 
> Restrict the USB2 resume status check in USB2 roothub to fix hang issue.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Aaron Ma <aaron.ma@canonical.com>

Thanks, adding to queue, will send forward after rc1

-Mathias

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

* Re: [PATCH v2 2/2] usb: xhci: fix timeout for transition from RExit to U0
  2018-10-22 17:42 ` [PATCH v2 2/2] usb: xhci: fix timeout for transition from RExit to U0 Aaron Ma
@ 2018-10-23 10:43   ` Mathias Nyman
  0 siblings, 0 replies; 4+ messages in thread
From: Mathias Nyman @ 2018-10-23 10:43 UTC (permalink / raw)
  To: Aaron Ma, mathias.nyman, gregkh, linux-usb, linux-kernel

On 22.10.2018 20:42, Aaron Ma wrote:
> This definition is used by msecs_to_jiffies in milliseconds.
> According to the comments, max rexit timeout should be 20ms.
> Align with the comments to properly calculate the delay.
> 
> Verified on Sunrise Point-LP and Cannon Lake.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Aaron Ma <aaron.ma@canonical.com>

Thanks, adding to queue, will send forward after rc1

-Mathias

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

end of thread, other threads:[~2018-10-23 10:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-22 17:42 [PATCH v2 1/2] usb: xhci: fix uninitialized completion when USB3 port got wrong status Aaron Ma
2018-10-22 17:42 ` [PATCH v2 2/2] usb: xhci: fix timeout for transition from RExit to U0 Aaron Ma
2018-10-23 10:43   ` Mathias Nyman
2018-10-23 10:42 ` [PATCH v2 1/2] usb: xhci: fix uninitialized completion when USB3 port got wrong status Mathias Nyman

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