Re: OHCI root_port_reset() deadly loop...

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: David Miller
Date: Monday, October 8, 2007 - 9:44 pm

From: David Brownell <david-b@pacbell.net>
Date: Mon, 08 Oct 2007 21:36:43 -0700


If the hardware hangs and the register stops incrementing,
the entire kernel will hang.  That is unacceptable.

We do need it.


Ok, fixed.


0x111


Absolutely nothing clears in the register from it's initial value.

Here is the patch with the limit_2 initial value fixed.

I kept loop_1 in there, it is necessary.  No kernel code should
hang in an endless loop because of malfunctioning hardware.

Signed-off-by: David S. Miller <davem@davemloft.net>

diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index bb9cc59..9149593 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -563,14 +563,19 @@ static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port)
 	u32	temp;
 	u16	now = ohci_readl(ohci, &ohci->regs->fmnumber);
 	u16	reset_done = now + PORT_RESET_MSEC;
+	int	limit_1;
 
 	/* build a "continuous enough" reset signal, with up to
 	 * 3msec gap between pulses.  scheduler HZ==100 must work;
 	 * this might need to be deadline-scheduled.
 	 */
-	do {
+	limit_1 = 100;
+	while (--limit_1 >= 0) {
+		int limit_2;
+
 		/* spin until any current reset finishes */
-		for (;;) {
+		limit_2 = PORT_RESET_HW_MSEC * 2;
+		while (--limit_2 >= 0) {
 			temp = ohci_readl (ohci, portstat);
 			/* handle e.g. CardBus eject */
 			if (temp == ~(u32)0)
@@ -579,6 +584,10 @@ static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port)
 				break;
 			udelay (500);
 		}
+		if (limit_2 < 0) {
+			ohci_warn(ohci, "Root port inner-loop reset timeout, "
+				  "portstat[%08x]\n", temp);
+		}
 
 		if (!(temp & RH_PS_CCS))
 			break;
@@ -589,7 +598,14 @@ static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port)
 		ohci_writel (ohci, RH_PS_PRS, portstat);
 		msleep(PORT_RESET_HW_MSEC);
 		now = ohci_readl(ohci, &ohci->regs->fmnumber);
-	} while (tick_before(now, reset_done));
+		if (!tick_before(now, reset_done))
+			break;
+	}
+	if (limit_1 < 0) {
+		ohci_warn(ohci, "Root port outer-loop reset timeout, "
+			  "now[%04x] reset_done[%04x]\n",
+			  now, reset_done);
+	}
 	/* caller synchronizes using PRSC */
 
 	return 0;
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
OHCI root_port_reset() deadly loop..., David Miller, (Sat Oct 6, 11:53 pm)
Re: OHCI root_port_reset() deadly loop..., David Brownell, (Sun Oct 7, 12:31 am)
Re: OHCI root_port_reset() deadly loop..., David Miller, (Sun Oct 7, 12:51 am)
Re: OHCI root_port_reset() deadly loop..., David Miller, (Mon Oct 8, 4:54 pm)
Re: OHCI root_port_reset() deadly loop..., Greg KH, (Mon Oct 8, 8:10 pm)
Re: OHCI root_port_reset() deadly loop..., David Miller, (Mon Oct 8, 8:16 pm)
Re: OHCI root_port_reset() deadly loop..., David Brownell, (Mon Oct 8, 8:34 pm)
Re: OHCI root_port_reset() deadly loop..., David Miller, (Mon Oct 8, 8:42 pm)
Re: OHCI root_port_reset() deadly loop..., David Brownell, (Mon Oct 8, 9:09 pm)
Re: OHCI root_port_reset() deadly loop..., David Brownell, (Mon Oct 8, 9:36 pm)
Re: OHCI root_port_reset() deadly loop..., Greg KH, (Mon Oct 8, 9:39 pm)
Re: OHCI root_port_reset() deadly loop..., David Miller, (Mon Oct 8, 9:44 pm)
Re: OHCI root_port_reset() deadly loop..., David Miller, (Mon Oct 8, 9:47 pm)
Re: OHCI root_port_reset() deadly loop..., David Brownell, (Mon Oct 8, 10:00 pm)
Re: OHCI root_port_reset() deadly loop..., Benjamin Herrenschmidt, (Mon Oct 8, 10:11 pm)
Re: OHCI root_port_reset() deadly loop..., Benjamin Herrenschmidt, (Mon Oct 8, 10:13 pm)
Re: OHCI root_port_reset() deadly loop..., David Miller, (Mon Oct 8, 10:23 pm)
Re: OHCI root_port_reset() deadly loop..., David Miller, (Mon Oct 8, 10:26 pm)
Re: OHCI root_port_reset() deadly loop..., Greg KH, (Mon Oct 8, 11:06 pm)
Re: OHCI root_port_reset() deadly loop..., Benjamin Herrenschmidt, (Mon Oct 8, 11:37 pm)
Re: OHCI root_port_reset() deadly loop..., Benjamin Herrenschmidt, (Mon Oct 8, 11:43 pm)
Re: OHCI root_port_reset() deadly loop..., David Brownell, (Tue Oct 9, 9:38 am)
Re: OHCI root_port_reset() deadly loop..., David Brownell, (Tue Oct 9, 11:48 am)
Re: OHCI root_port_reset() deadly loop..., David Miller, (Tue Oct 9, 1:41 pm)
Re: OHCI root_port_reset() deadly loop..., Greg KH, (Tue Oct 9, 1:46 pm)
Re: OHCI root_port_reset() deadly loop..., David Brownell, (Tue Oct 9, 2:05 pm)
Re: OHCI root_port_reset() deadly loop..., David Brownell, (Tue Oct 9, 2:09 pm)
Re: [Linux-usb-users] OHCI root_port_reset() deadly loop..., David Brownell, (Tue Oct 16, 11:26 am)