Skip to contentSkip to conversation

EHCI: Update qTD next pointer in QH overlay region during unlink

PATCH In review Pavankumar Kondeti 3 participants 4 messages Sep 7, 2012 2 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 EHCI: Update qTD next pointer in QH overlay region during unlink

There is a possibility of QH overlay region having reference to a stale qTD pointer during unlink.

Consider an endpoint having two pending qTD before unlink process begins. The endpoint's QH queue looks like this.

qTD1 --> qTD2 --> Dummy

To unlink qTD2, QH is removed from asynchronous list and Asynchronous Advance Doorbell is programmed. The qTD1's next qTD pointer is set to qTD2'2 next qTD pointer and qTD2 is retired upon controller's doorbell interrupt. If QH's current qTD pointer points to qTD1, transfer overlay region still have reference to qTD2. But qtD2 is just unlinked and freed. This may cause EHCI system error. Fix this by updating qTD next pointer in QH overlay region with the qTD next pointer of the current qTD.

---
 drivers/usb/host/ehci-q.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-q.c +10 -2
index 9bc39ca..4b66374 100644
@@ -128,9 +128,17 @@ qh_refresh (struct ehci_hcd *ehci, struct ehci_qh *qh)
 	else {
 		qtd = list_entry (qh->qtd_list.next,
 				struct ehci_qtd, qtd_list);
-		/* first qtd may already be partially processed */
-		if (cpu_to_hc32(ehci, qtd->qtd_dma) == qh->hw->hw_current)
+		/*
+		 * first qtd may already be partially processed.
+		 * If we come here during unlink, the QH overlay region
+		 * might have reference to the just unlinked qtd. The
+		 * qtd is updated in qh_completions(). Update the QH
+		 * overlay here.
+		 */
+		if (cpu_to_hc32(ehci, qtd->qtd_dma) == qh->hw->hw_current) {
+			qh->hw->hw_qtd_next = qtd->hw_next;
 			qtd = NULL;
+		}
 	}
 
 	if (qtd)
Signature · 3 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation.
maintainer Acked-by on v1 1/1
#2 lore raw
Quoted 35 lines · Pavankumar Kondeti

There is a possibility of QH overlay region having reference to a stale qTD pointer during unlink.

Consider an endpoint having two pending qTD before unlink process begins. The endpoint's QH queue looks like this.

qTD1 --> qTD2 --> Dummy

To unlink qTD2, QH is removed from asynchronous list and Asynchronous Advance Doorbell is programmed. The qTD1's next qTD pointer is set to qTD2'2 next qTD pointer and qTD2 is retired upon controller's doorbell interrupt. If QH's current qTD pointer points to qTD1, transfer overlay region still have reference to qTD2. But qtD2 is just unlinked and freed. This may cause EHCI system error. Fix this by updating qTD next pointer in QH overlay region with the qTD next pointer of the current qTD.

---
 drivers/usb/host/ehci-q.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-q.c +4 -2
index 9bc39ca..4b66374 100644
@@ -128,9 +128,17 @@ qh_refresh (struct ehci_hcd *ehci, struct ehci_qh *qh)
 	else {
 		qtd = list_entry (qh->qtd_list.next,
 				struct ehci_qtd, qtd_list);
-		/* first qtd may already be partially processed */
-		if (cpu_to_hc32(ehci, qtd->qtd_dma) == qh->hw->hw_current)
+		/*
+		 * first qtd may already be partially processed.
+		 * If we come here during unlink, the QH overlay region
+		 * might have reference to the just unlinked qtd. The

drivers/usb/host/ehci-q.c qh_refresh (struct ehci_hcd *ehci, struct ehci_qh *qh) · line 144

Quoted 10 lines
drivers/usb/host/ehci-q.c +6 -0
+		 * qtd is updated in qh_completions(). Update the QH
+		 * overlay here.
+		 */
+		if (cpu_to_hc32(ehci, qtd->qtd_dma) == qh->hw->hw_current) {
+			qh->hw->hw_qtd_next = qtd->hw_next;
 			qtd = NULL;
+		}
 	}
 
 	if (qtd)

Have you been able to determine that this eliminates your host system errors?

Alan Stern

#3 lore raw
Quoted 46 lines · Alan Stern
Quoted 44 lines · Pavankumar Kondeti

There is a possibility of QH overlay region having reference to a stale qTD pointer during unlink.

Consider an endpoint having two pending qTD before unlink process begins. The endpoint's QH queue looks like this.

qTD1 --> qTD2 --> Dummy

To unlink qTD2, QH is removed from asynchronous list and Asynchronous Advance Doorbell is programmed. The qTD1's next qTD pointer is set to qTD2'2 next qTD pointer and qTD2 is retired upon controller's doorbell interrupt. If QH's current qTD pointer points to qTD1, transfer overlay region still have reference to qTD2. But qtD2 is just unlinked and freed. This may cause EHCI system error. Fix this by updating qTD next pointer in QH overlay region with the qTD next pointer of the current qTD.

---
 drivers/usb/host/ehci-q.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-q.c +10 -2
index 9bc39ca..4b66374 100644
@@ -128,9 +128,17 @@ qh_refresh (struct ehci_hcd *ehci, struct ehci_qh *qh)
 	else {
 		qtd = list_entry (qh->qtd_list.next,
 				struct ehci_qtd, qtd_list);
-		/* first qtd may already be partially processed */
-		if (cpu_to_hc32(ehci, qtd->qtd_dma) == qh->hw->hw_current)
+		/*
+		 * first qtd may already be partially processed.
+		 * If we come here during unlink, the QH overlay region
+		 * might have reference to the just unlinked qtd. The
+		 * qtd is updated in qh_completions(). Update the QH
+		 * overlay here.
+		 */
+		if (cpu_to_hc32(ehci, qtd->qtd_dma) == qh->hw->hw_current) {
+			qh->hw->hw_qtd_next = qtd->hw_next;
 			qtd = NULL;
+		}
 	}
 
Quoted 4 lines

drivers/usb/host/ehci-q.c qh_refresh (struct ehci_hcd *ehci, struct ehci_qh *qh) · line 144

Quoted 1 line
drivers/usb/host/ehci-q.c +0 -0
 	if (qtd)

Thanks Alan for reviewing the patch.

Quoted 2 lines

Have you been able to determine that this eliminates your host system errors?

Yes. We are able to determine that this patch is fixing the EHCI system error.

Signature · 3 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation.

A message that is not in the archive (sent off-list or not yet received): Pine.LNX.4.44L0.1209071151130.1674-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org

#5 lore raw
Quoted 46 lines · Alan Stern
Quoted 44 lines · Pavankumar Kondeti

There is a possibility of QH overlay region having reference to a stale qTD pointer during unlink.

Consider an endpoint having two pending qTD before unlink process begins. The endpoint's QH queue looks like this.

qTD1 --> qTD2 --> Dummy

To unlink qTD2, QH is removed from asynchronous list and Asynchronous Advance Doorbell is programmed. The qTD1's next qTD pointer is set to qTD2'2 next qTD pointer and qTD2 is retired upon controller's doorbell interrupt. If QH's current qTD pointer points to qTD1, transfer overlay region still have reference to qTD2. But qtD2 is just unlinked and freed. This may cause EHCI system error. Fix this by updating qTD next pointer in QH overlay region with the qTD next pointer of the current qTD.

---
 drivers/usb/host/ehci-q.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
drivers/usb/host/ehci-q.c +10 -2
index 9bc39ca..4b66374 100644
@@ -128,9 +128,17 @@ qh_refresh (struct ehci_hcd *ehci, struct ehci_qh *qh)
 	else {
 		qtd = list_entry (qh->qtd_list.next,
 				struct ehci_qtd, qtd_list);
-		/* first qtd may already be partially processed */
-		if (cpu_to_hc32(ehci, qtd->qtd_dma) == qh->hw->hw_current)
+		/*
+		 * first qtd may already be partially processed.
+		 * If we come here during unlink, the QH overlay region
+		 * might have reference to the just unlinked qtd. The
+		 * qtd is updated in qh_completions(). Update the QH
+		 * overlay here.
+		 */
+		if (cpu_to_hc32(ehci, qtd->qtd_dma) == qh->hw->hw_current) {
+			qh->hw->hw_qtd_next = qtd->hw_next;
 			qtd = NULL;
+		}
 	}
 
Quoted 3 lines

drivers/usb/host/ehci-q.c qh_refresh (struct ehci_hcd *ehci, struct ehci_qh *qh) · line 144

Quoted 1 line
drivers/usb/host/ehci-q.c +0 -0
 	if (qtd)

I forgot to mention: This patch should be included in the next 3.6-rc release and marked for -stable.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html