Skip to contentSkip to conversation

net/usb/ax88179_178a driver broken in linux-3.12

DISCUSSION Mark Lord 8 participants 23 messages Nov 17, 2013 – Dec 2, 2013 3 messages not in the archive

Subsystems (6)
lore
Share & tools
lore

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

Mark Lord

author
#1 lore raw
Quoted 7 lines · Mark Lord

The USB3 network adapter locks up consistently for me here in 3.12, but was working without issues in 3.11.x

Source of the problem is this patch:

   http://patchwork.ozlabs.org/patch/264021/

Reverting the patch fixes the adapter.

Okay, upon closer inspection, the bug appears to be a math error. Here's a simpler (non-revert) patch to fix the bug that was introduced in 3.12.

(un-mangled copy attached; reproduced below for ease of viewing).

Don't exceed more than the 8 bytes of reserved ("needed_headroom") space when calling pskb_expand_head. This fixes a bug introduced in linux-3.12.0.

drivers/net/usb/ax88179_178a.c 2013-11-17 13:47:26.127971404 -0500 renamed from ax88179_178a.c.orig 2013-11-03 18:41:51.000000000 -0500 +3 -3
@@ -1183,10 +1183,10 @@
        if (((skb->len + 8) % frame_size) == 0)
                tx_hdr2 |= 0x80008000;  /* Enable padding */
 
-       headroom = skb_headroom(skb) - 8;
+       headroom = skb_headroom(skb);
 
-       if ((skb_header_cloned(skb) || headroom < 0) &&
-           pskb_expand_head(skb, headroom < 0 ? 8 : 0, 0, GFP_ATOMIC)) {
+       if ((skb_header_cloned(skb) || headroom < 8) &&
+           pskb_expand_head(skb, headroom < 8 ? 8 - headroom : 0, 0, GFP_ATOMIC)) {
                dev_kfree_skb_any(skb);
                return NULL;
        }
Signature · 3 lines
Mark Lord
Real-Time Remedies Inc.
[email protected]

Don't exceed more than the 8 bytes of reserved ("needed_headroom") space when calling pskb_expand_head. This fixes a bug introduced in linux-3.12.0.

drivers/net/usb/ax88179_178a.c renamed from ax88179_178a.c.orig +3 -3
@@ -1183,10 +1183,10 @@
 	if (((skb->len + 8) % frame_size) == 0)
 		tx_hdr2 |= 0x80008000;	/* Enable padding */
 
-	headroom = skb_headroom(skb) - 8;
+	headroom = skb_headroom(skb);
 
-	if ((skb_header_cloned(skb) || headroom < 0) &&
-	    pskb_expand_head(skb, headroom < 0 ? 8 : 0, 0, GFP_ATOMIC)) {
+	if ((skb_header_cloned(skb) || headroom < 8) &&
+	    pskb_expand_head(skb, headroom < 8 ? 8 - headroom : 0, 0, GFP_ATOMIC)) {
 		dev_kfree_skb_any(skb);
 		return NULL;
 	}
author
#2 lore raw
Quoted 27 lines · Mark Lord
Quoted 7 lines · Mark Lord

The USB3 network adapter locks up consistently for me here in 3.12, but was working without issues in 3.11.x

Source of the problem is this patch:

   http://patchwork.ozlabs.org/patch/264021/

Reverting the patch fixes the adapter.

Okay, upon closer inspection, the bug appears to be a math error. Here's a simpler (non-revert) patch to fix the bug that was introduced in 3.12.

(un-mangled copy attached; reproduced below for ease of viewing).

Don't exceed more than the 8 bytes of reserved ("needed_headroom") space when calling pskb_expand_head. This fixes a bug introduced in linux-3.12.0.

drivers/net/usb/ax88179_178a.c 2013-11-17 13:47:26.127971404 -0500 renamed from ax88179_178a.c.orig 2013-11-03 18:41:51.000000000 -0500 +0 -0
@@ -1183,10 +1183,10 @@
        if (((skb->len + 8) % frame_size) == 0)
                tx_hdr2 |= 0x80008000;  /* Enable padding */
 

drivers/net/usb/ax88179_178a.c 2013-11-17 13:47:26.127971404 -0500 line 1192

Quoted 10 lines
drivers/net/usb/ax88179_178a.c 2013-11-17 13:47:26.127971404 -0500 renamed from ax88179_178a.c.orig 2013-11-03 18:41:51.000000000 -0500 +3 -3
-       headroom = skb_headroom(skb) - 8;
+       headroom = skb_headroom(skb);
 
-       if ((skb_header_cloned(skb) || headroom < 0) &&
-           pskb_expand_head(skb, headroom < 0 ? 8 : 0, 0, GFP_ATOMIC)) {
+       if ((skb_header_cloned(skb) || headroom < 8) &&
+           pskb_expand_head(skb, headroom < 8 ? 8 - headroom : 0, 0, GFP_ATOMIC)) {
                dev_kfree_skb_any(skb);
                return NULL;
        }

Dagnabbit.. that still locked up just after I sent the email, despite working fine in testing prior to that.

So.. sticking with the full revert here for now.
Perhaps one of you chaps can spot the bug.

Signature · 3 lines
Mark Lord
Real-Time Remedies Inc.
[email protected]
#3 lore raw
Quoted 4 lines · Mark Lord
Quoted 3 lines · Mark Lord
Quoted 2 lines

The USB3 network adapter locks up consistently for me here in 3.12, but was working without issues in 3.11.x

The xhci driver is well broken in 3.12.

Try disabling GSO and TSO so that the xhci driver is never given fragments.

David

#4 lore raw
Quoted 7 lines

From: David Laight

Quoted 4 lines · Mark Lord
Quoted 3 lines · Mark Lord
Quoted 2 lines

The USB3 network adapter locks up consistently for me here in 3.12, but was working without issues in 3.11.x

The xhci driver is well broken in 3.12.

To correct myself...

The xhci driver has never correctly support scatter-gather requests. In 3.12 code was added to usbnet to generate SG transmits, and to the ax88179_178a driver to use them.
TCP segmentation offload was then enabled - with does generate SG transfers.

SG transfers for 'disks' almost certainly work because the fragment boundaries are 'adequately aligned'.

David

author
#5 lore raw
Quoted 16 lines · David Laight
Quoted 7 lines

From: David Laight

Quoted 4 lines · Mark Lord
Quoted 3 lines · Mark Lord
Quoted 2 lines

The USB3 network adapter locks up consistently for me here in 3.12, but was working without issues in 3.11.x

The xhci driver is well broken in 3.12.

To correct myself...

The xhci driver has never correctly support scatter-gather requests. In 3.12 code was added to usbnet to generate SG transmits, and to the ax88179_178a driver to use them.
TCP segmentation offload was then enabled - with does generate SG transfers.

Quoted 5 lines

SG transfers for 'disks' almost certainly work because the fragment boundaries are 'adequately aligned'.

David

Well, that's all very nice and whatnot,
except the ax88179_178a driver still does not work in linux-3.12, whereas it works fine in all earlier kernels.

That's a regression.
And a simple revert (earlier in this thread) fixes it.

So.. let's revert it for now, until a proper xhci compatible patch is produced.

Signature · 3 lines
Mark Lord
Real-Time Remedies Inc.
[email protected]
#6 lore raw
Quoted 24 lines

From: Mark Lord

Quoted 16 lines · David Laight
Quoted 7 lines

From: David Laight

Quoted 4 lines · Mark Lord
Quoted 3 lines · Mark Lord
Quoted 2 lines

The USB3 network adapter locks up consistently for me here in 3.12, but was working without issues in 3.11.x

The xhci driver is well broken in 3.12.

To correct myself...

The xhci driver has never correctly support scatter-gather requests. In 3.12 code was added to usbnet to generate SG transmits, and to the ax88179_178a driver to use them.
TCP segmentation offload was then enabled - with does generate SG transfers.

Quoted 5 lines

SG transfers for 'disks' almost certainly work because the fragment boundaries are 'adequately aligned'.

David

Quoted 8 lines

Well, that's all very nice and whatnot,
except the ax88179_178a driver still does not work in linux-3.12, whereas it works fine in all earlier kernels.

That's a regression.
And a simple revert (earlier in this thread) fixes it.

So.. let's revert it for now, until a proper xhci compatible patch is produced.

Which changes did you revert?
I think you must have gone right back to the version that doesn't so scatter-gather.

There is a patch to xhci-ring.c that should fix the SG problem.
http://www.spinics.net/lists/linux-usb/msg97176.html

I think it should apply to the 3.12 sources.

Note that with older kernels the asix card I have will drop/discard short bursts of tx/rx packets. I've not seen that with 3.12 and the xhci-ring.c patch.

David

author
#7 lore raw
Quoted 2 lines · David Laight

Which changes did you revert?

Just the bits that changed how the headroom/tailroom sizes were checked and adjusted. See attachment for the revert patch I am using here. My mailer unfortunately likes to mangle inline patches.

=========snip===========
Revert USB 3.0 network driver changes that break the adapter (lockups) in 3.12. This just puts back the original code from previous kernels.

drivers/net/usb/ax88179_178a.c 2013-11-17 13:23:39.525734277 -0500 renamed from drivers/net/usb/ax88179_178a.c.orig 2013-11-03 18:41:51.000000000 -0500 +17 -4
@@ -1177,18 +1177,31 @@
        int frame_size = dev->maxpacket;
        int mss = skb_shinfo(skb)->gso_size;
        int headroom;
+       int tailroom;
 
        tx_hdr1 = skb->len;
        tx_hdr2 = mss;
        if (((skb->len + 8) % frame_size) == 0)
                tx_hdr2 |= 0x80008000;  /* Enable padding */
 
-       headroom = skb_headroom(skb) - 8;
+       headroom = skb_headroom(skb);
+       tailroom = skb_tailroom(skb);
 
-       if ((skb_header_cloned(skb) || headroom < 0) &&
-           pskb_expand_head(skb, headroom < 0 ? 8 : 0, 0, GFP_ATOMIC)) {
+       if (!skb_header_cloned(skb) &&
+           !skb_cloned(skb) &&
+           (headroom + tailroom) >= 8) {
+               if (headroom < 8) {
+                       skb->data = memmove(skb->head + 8, skb->data, skb->len);
+                       skb_set_tail_pointer(skb, skb->len);
+               }
+       } else {
+               struct sk_buff *skb2;
+
+               skb2 = skb_copy_expand(skb, 8, 0, flags);
                dev_kfree_skb_any(skb);
-               return NULL;
+               skb = skb2;
+               if (!skb)
+                       return NULL;
        }
 
        skb_push(skb, 4);
Signature · 3 lines
Mark Lord
Real-Time Remedies Inc.
[email protected]

Revert USB 3.0 network driver changes that break the adapter (lockups) in 3.12. This just puts back the original code from previous kernels.

drivers/net/usb/ax88179_178a.c renamed from drivers/net/usb/ax88179_178a.c.orig +17 -4
@@ -1177,18 +1177,31 @@
 	int frame_size = dev->maxpacket;
 	int mss = skb_shinfo(skb)->gso_size;
 	int headroom;
+	int tailroom;
 
 	tx_hdr1 = skb->len;
 	tx_hdr2 = mss;
 	if (((skb->len + 8) % frame_size) == 0)
 		tx_hdr2 |= 0x80008000;	/* Enable padding */
 
-	headroom = skb_headroom(skb) - 8;
+	headroom = skb_headroom(skb);
+	tailroom = skb_tailroom(skb);
 
-	if ((skb_header_cloned(skb) || headroom < 0) &&
-	    pskb_expand_head(skb, headroom < 0 ? 8 : 0, 0, GFP_ATOMIC)) {
+	if (!skb_header_cloned(skb) &&
+	    !skb_cloned(skb) &&
+	    (headroom + tailroom) >= 8) {
+		if (headroom < 8) {
+			skb->data = memmove(skb->head + 8, skb->data, skb->len);
+			skb_set_tail_pointer(skb, skb->len);
+		}
+	} else {
+		struct sk_buff *skb2;
+
+		skb2 = skb_copy_expand(skb, 8, 0, flags);
 		dev_kfree_skb_any(skb);
-		return NULL;
+		skb = skb2;
+		if (!skb)
+			return NULL;
 	}
 
 	skb_push(skb, 4);
#8 lore raw
Quoted 43 lines

From: Mark Lord [mailto:[email protected]]

Quoted 2 lines · David Laight

Which changes did you revert?

Just the bits that changed how the headroom/tailroom sizes were checked and adjusted. See attachment for the revert patch I am using here. My mailer unfortunately likes to mangle inline patches.

=========snip===========
Revert USB 3.0 network driver changes that break the adapter (lockups) in 3.12. This just puts back the original code from previous kernels.

drivers/net/usb/ax88179_178a.c 2013-11-17 13:23:39.525734277 -0500 renamed from drivers/net/usb/ax88179_178a.c.orig 2013-11-03 18:41:51.000000000 -0500 +12 -3
@@ -1177,18 +1177,31 @@
        int frame_size = dev->maxpacket;
        int mss = skb_shinfo(skb)->gso_size;
        int headroom;
+       int tailroom;
 
        tx_hdr1 = skb->len;
        tx_hdr2 = mss;
        if (((skb->len + 8) % frame_size) == 0)
                tx_hdr2 |= 0x80008000;  /* Enable padding */
 
-       headroom = skb_headroom(skb) - 8;
+       headroom = skb_headroom(skb);
+       tailroom = skb_tailroom(skb);
 
-       if ((skb_header_cloned(skb) || headroom < 0) &&
-           pskb_expand_head(skb, headroom < 0 ? 8 : 0, 0, GFP_ATOMIC)) {
+       if (!skb_header_cloned(skb) &&
+           !skb_cloned(skb) &&
+           (headroom + tailroom) >= 8) {
+               if (headroom < 8) {
+                       skb->data = memmove(skb->head + 8, skb->data, skb->len);
+                       skb_set_tail_pointer(skb, skb->len);
+               }
+       } else {
+               struct sk_buff *skb2;

drivers/net/usb/ax88179_178a.c 2013-11-17 13:23:39.525734277 -0500 line 1207

Quoted 10 lines
drivers/net/usb/ax88179_178a.c 2013-11-17 13:23:39.525734277 -0500 renamed from drivers/net/usb/ax88179_178a.c.orig 2013-11-03 18:41:51.000000000 -0500 +5 -1
+
+               skb2 = skb_copy_expand(skb, 8, 0, flags);
                dev_kfree_skb_any(skb);
-               return NULL;
+               skb = skb2;
+               if (!skb)
+                       return NULL;
        }
 
        skb_push(skb, 4);

At a guess it will be a difference between pskb_expand_head() and skb_copy_expand(). The latter probably generates a linear skb. The extra check for skb_cloned() probably also applies - and forces a data copy.

Have you tried the patch to xhci-ring.c?

David

author
#9 lore raw
In reply to David Laight
Quoted 1 line · David Laight
Quoted 1 line

From: Mark Lord

..

Quoted 6 lines
Quoted 6 lines

except the ax88179_178a driver still does not work in linux-3.12, whereas it works fine in all earlier kernels.

That's a regression.
And a simple revert (earlier in this thread) fixes it.
So.. let's revert it for now, until a proper xhci compatible patch is produced.

...

Quoted 4 lines

There is a patch to xhci-ring.c that should fix the SG problem.
http://www.spinics.net/lists/linux-usb/msg97176.html

I think it should apply to the 3.12 sources.

I am running with that patch here now (thanks),
and it too appears to prevent the lockups.

But is this patch upstream already?
If yes, then it needs to get pushed out to -stable for 3.12 at least.

If not upstream, then the revert is probably safest for -stable, rather than new code that has never been upstream before.

Both patches are attached to this email.
One or the other is required for the USB 3.0 network adapters to function in 3.12.

Thanks

Signature · 3 lines
Mark Lord
Real-Time Remedies Inc.
[email protected]

Revert USB 3.0 network driver changes that break the adapter (lockups) in 3.12. This just puts back the original code from previous kernels.

drivers/net/usb/ax88179_178a.c renamed from drivers/net/usb/ax88179_178a.c.orig +17 -4
@@ -1177,18 +1177,31 @@
 	int frame_size = dev->maxpacket;
 	int mss = skb_shinfo(skb)->gso_size;
 	int headroom;
+	int tailroom;
 
 	tx_hdr1 = skb->len;
 	tx_hdr2 = mss;
 	if (((skb->len + 8) % frame_size) == 0)
 		tx_hdr2 |= 0x80008000;	/* Enable padding */
 
-	headroom = skb_headroom(skb) - 8;
+	headroom = skb_headroom(skb);
+	tailroom = skb_tailroom(skb);
 
-	if ((skb_header_cloned(skb) || headroom < 0) &&
-	    pskb_expand_head(skb, headroom < 0 ? 8 : 0, 0, GFP_ATOMIC)) {
+	if (!skb_header_cloned(skb) &&
+	    !skb_cloned(skb) &&
+	    (headroom + tailroom) >= 8) {
+		if (headroom < 8) {
+			skb->data = memmove(skb->head + 8, skb->data, skb->len);
+			skb_set_tail_pointer(skb, skb->len);
+		}
+	} else {
+		struct sk_buff *skb2;
+
+		skb2 = skb_copy_expand(skb, 8, 0, flags);
 		dev_kfree_skb_any(skb);
-		return NULL;
+		skb = skb2;
+		if (!skb)
+			return NULL;
 	}
 
 	skb_push(skb, 4);

Section 4.11.7.1 of rev 1.0 of the xhci specification states that a link TRB can only occur at a boundary between underlying USB frames (512 bytes for 480M).

If this isn't done the USB frames aren't formatted correctly and, for example, the USB3 ethernet ax88179_178a card will stop sending (while still receiving) when running a netperf tcp transmit test with (say) and 8k buffer.

This should be a candidate for stable, the ax88179_178a driver defaults to gso and tso enabled so it passes a lot of fragmented skb to the USB stack.

---

Changes for v2:

1) Only act on bulk endpoints.
While isoc endpoints could suffer from the same problem it is much less likely and can't be fixed by adding NOP TRBs (they would stop data being sent in the poll interval).

2) When writing the NOP TRB use the count of TRBs instead of scanning for the link TRB.

 drivers/usb/host/xhci-ring.c | 53 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 51 insertions(+), 2 deletions(-)
drivers/usb/host/xhci-ring.c +51 -2

59 lines not on this page · raw message

#10 lore raw
Quoted 21 lines · Mark Lord
Quoted 1 line · David Laight
Quoted 1 line

From: Mark Lord

..

Quoted 6 lines
Quoted 6 lines

except the ax88179_178a driver still does not work in linux-3.12, whereas it works fine in all earlier kernels.

That's a regression.
And a simple revert (earlier in this thread) fixes it.
So.. let's revert it for now, until a proper xhci compatible patch is produced.

...

Quoted 4 lines

There is a patch to xhci-ring.c that should fix the SG problem.
http://www.spinics.net/lists/linux-usb/msg97176.html

I think it should apply to the 3.12 sources.

I am running with that patch here now (thanks),
and it too appears to prevent the lockups.

But is this patch upstream already?
If yes, then it needs to get pushed out to -stable for 3.12 at least.

Quoted 6 lines

If not upstream, then the revert is probably safest for -stable, rather than new code that has never been upstream before.

Both patches are attached to this email.
One or the other is required for the USB 3.0 network adapters to function in 3.12.

I do not see any error in commit f27070158d6754765f2 ("ax88179_178a: avoid copy of tx tcp packets")

Quite the contrary in fact...

I suspect a TSO bug, and would rather disable TSO for this nic.

Have you tried to revert 3804fad45411b482
("USBNET: ax88179_178a: enable tso if usb host supports sg dma")

author
#11 lore raw
Quoted 26 lines · Eric Dumazet
Quoted 24 lines · Mark Lord
Quoted 1 line · David Laight
Quoted 1 line

From: Mark Lord

..

Quoted 6 lines
Quoted 6 lines

except the ax88179_178a driver still does not work in linux-3.12, whereas it works fine in all earlier kernels.

That's a regression.
And a simple revert (earlier in this thread) fixes it.
So.. let's revert it for now, until a proper xhci compatible patch is produced.

...

Quoted 4 lines

There is a patch to xhci-ring.c that should fix the SG problem.
http://www.spinics.net/lists/linux-usb/msg97176.html

I think it should apply to the 3.12 sources.

I am running with that patch here now (thanks),
and it too appears to prevent the lockups.

But is this patch upstream already?
If yes, then it needs to get pushed out to -stable for 3.12 at least.

If not upstream, then the revert is probably safest for -stable, rather than new code that has never been upstream before.

Quoted 8 lines
Quoted 2 lines

Both patches are attached to this email.
One or the other is required for the USB 3.0 network adapters to function in 3.12.

I do not see any error in commit f27070158d6754765f2 ("ax88179_178a: avoid copy of tx tcp packets") Quite the contrary in fact...

I suspect a TSO bug, and would rather disable TSO for this nic.

David's explanation for the XHCI issue seems to explain it nicely, and the patch he linked to does indeed address/fix the issue, without disabling TSO.

So on the evidence, probably NOT a TSO bug.

Signature · 3 lines
Mark Lord
Real-Time Remedies Inc.
[email protected]
#12 lore raw
In reply to Eric Dumazet
Quoted 7 lines

From: Eric Dumazet [mailto:[email protected]]

Quoted 5 lines · Mark Lord
Quoted 1 line · David Laight
Quoted 1 line

From: Mark Lord

..

Quoted 2 lines
Quoted 2 lines

except the ax88179_178a driver still does not work in linux-3.12, whereas it works fine in all earlier kernels.

I've seen lost packets in IIRC 3.2

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

That's a regression.
And a simple revert (earlier in this thread) fixes it.
So.. let's revert it for now, until a proper xhci compatible patch is produced.

...

Quoted 3 lines

There is a patch to xhci-ring.c that should fix the SG problem.
http://www.spinics.net/lists/linux-usb/msg97176.html

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

I think it should apply to the 3.12 sources.

I am running with that patch here now (thanks),
and it too appears to prevent the lockups.

But is this patch upstream already?
If yes, then it needs to get pushed out to -stable for 3.12 at least.

Having someone else confirm that there is a bug, and that the patch fixes it should help it get pushed to -stable.

Quoted 10 lines
Quoted 6 lines

If not upstream, then the revert is probably safest for -stable, rather than new code that has never been upstream before.

Both patches are attached to this email.
One or the other is required for the USB 3.0 network adapters to function in 3.12.

I do not see any error in commit f27070158d6754765f2 ("ax88179_178a: avoid copy of tx tcp packets")

Quoted 6 lines

Quite the contrary in fact...

I suspect a TSO bug, and would rather disable TSO for this nic.

Have you tried to revert 3804fad45411b482
("USBNET: ax88179_178a: enable tso if usb host supports sg dma")

It isn't directly a TSO problem.
There has always been a bug in the xhci driver for fragmented buffers. TSO just means it is given a lot of fragmented buffers.

As well as user-supplied fragmented buffers, the bug affects internal fragmentation that happens whenever a buffer crosses a 64k byte boundary (please hw engineers - stop doing this!)

I'm not sure whether usbnet would ever pass buffers that cross 64k boundaries. I've not seen one - even with TSO. But the rx buffers are 20k (doesn't seem ideal!) and could also be problematical.

USB mass storage has used SG for ages, the buffers must all be adequately aligned for the hardware - they won't meet the constraint for USB3 itself, but the documented restriction may be more severe than the actual one.

David

#13 lore raw
Quoted 7 lines · David Laight

It isn't directly a TSO problem.
There has always been a bug in the xhci driver for fragmented buffers. TSO just means it is given a lot of fragmented buffers.

As well as user-supplied fragmented buffers, the bug affects internal fragmentation that happens whenever a buffer crosses a 64k byte boundary (please hw engineers - stop doing this!)

TCP stack uses order-3 allocations.

This means 32KB for x86 (PAGE_SIZE=4096)

What is PAGE_SIZE for your arches ?

If there is a 6KB limit, we might adapt TCP to make sure we do not cross a 64KB boundary.

Other strategy would be to detect this case in the driver and split a problematic segment into two parts.

Quoted 9 lines

I'm not sure whether usbnet would ever pass buffers that cross 64k boundaries. I've not seen one - even with TSO. But the rx buffers are 20k (doesn't seem ideal!) and could also be problematical.

USB mass storage has used SG for ages, the buffers must all be adequately aligned for the hardware - they won't meet the constraint for USB3 itself, but the documented restriction may be more severe than the actual one.

#14 lore raw
Quoted 15 lines

From: Eric Dumazet [mailto:[email protected]]

Quoted 7 lines · David Laight

It isn't directly a TSO problem.
There has always been a bug in the xhci driver for fragmented buffers. TSO just means it is given a lot of fragmented buffers.

As well as user-supplied fragmented buffers, the bug affects internal fragmentation that happens whenever a buffer crosses a 64k byte boundary (please hw engineers - stop doing this!)

TCP stack uses order-3 allocations.

This means 32KB for x86 (PAGE_SIZE=4096)

Quoted 7 lines

What is PAGE_SIZE for your arches ?

If there is a 6KB limit, we might adapt TCP to make sure we do not cross a 64KB boundary.

Other strategy would be to detect this case in the driver and split a problematic segment into two parts.

The xhci code does all the checks for buffer fragments crossing 64k boundaries. I've posted a patch that uses a conservative upper limit for the number of fragments: 2 * number_of_sg_buffs + xfer_len/65536.
This saves scanning the sg list twice.

For those not reading linux-usb:

The xhci 'bug' is that an SG list may only cross the end of a ring segment at an aligned length.
For USB2 devices this will be 512 bytes. For USB3 the documented alignment could be 16k (depends on a burst size), but might only be 1k. (This is another place where the hw engineers haven't made life easy.) The only simple solution is to ensure that a SG list doesn't cross the end of a ring segment.

David

#16 lore raw
Quoted 11 lines

From: Of David Miller

Quoted 7 lines

From: "David Laight" <[email protected]>
Date: Tue, 19 Nov 2013 10:04:11 -0000

There is a patch to xhci-ring.c that should fix the SG problem.
http://www.spinics.net/lists/linux-usb/msg97176.html

I think it should apply to the 3.12 sources.

David, please get this into Linus's tree and queued up for -stable as soon as possible, thank you.

What do I have to do to expedite it?
I thought that Sarah would have to push the patch through.

It might be necessary to limit the number of SG fragments that the mass storage (etc) can generate to 63 (from unlimited). That should be a 1 line change somewhere.

David

#17 lore raw
Quoted 7 lines · David Laight
Quoted 7 lines

From: Of David Miller

Quoted 6 lines

From: "David Laight" <[email protected]>
Date: Tue, 19 Nov 2013 10:04:11 -0000

There is a patch to xhci-ring.c that should fix the SG problem.
http://www.spinics.net/lists/linux-usb/msg97176.html

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

I think it should apply to the 3.12 sources.

David, please get this into Linus's tree and queued up for -stable as soon as possible, thank you.

What do I have to do to expedite it?
I thought that Sarah would have to push the patch through.

Yes, I think the patch should come through my tree.

Quoted 3 lines

It might be necessary to limit the number of SG fragments that the mass storage (etc) can generate to 63 (from unlimited). That should be a 1 line change somewhere.

Greg's USB tree is frozen until after 3.13-rc1. The patch will have to wait until then, but it will be marked for stable.

I have no objection to the methodology of the patch, but we do need to figure out how to limit the number of scatter-gather list entries in the mass storage driver. We're still figuring out the exact limitation we need to use, and then the patch can be queued in my for-usb-linus branch for 3.13-rc1.

Note that the patch is a bandaid fix, and will only help bulk endpoints that are submitting scatter-gather transfers. Interrupt endpoints using scatter-gather will still run into these issues, but with David's patch, the URB submission will now fail, rather than allowing the transfer to be silently corrupted.

The real fix for this will probably be too large for stable, and is likely to take at least a kernel revision to fix.

Sarah Sharp

author
#18 lore raw
Quoted 43 lines · Mark Lord
Quoted 2 lines · David Laight

Which changes did you revert?

Just the bits that changed how the headroom/tailroom sizes were checked and adjusted. See attachment for the revert patch I am using here. My mailer unfortunately likes to mangle inline patches.

=========snip===========
Revert USB 3.0 network driver changes that break the adapter (lockups) in 3.12. This just puts back the original code from previous kernels.

drivers/net/usb/ax88179_178a.c 2013-11-17 13:23:39.525734277 -0500 renamed from drivers/net/usb/ax88179_178a.c.orig 2013-11-03 18:41:51.000000000 -0500 +12 -3
@@ -1177,18 +1177,31 @@
        int frame_size = dev->maxpacket;
        int mss = skb_shinfo(skb)->gso_size;
        int headroom;
+       int tailroom;
 
        tx_hdr1 = skb->len;
        tx_hdr2 = mss;
        if (((skb->len + 8) % frame_size) == 0)
                tx_hdr2 |= 0x80008000;  /* Enable padding */
 
-       headroom = skb_headroom(skb) - 8;
+       headroom = skb_headroom(skb);
+       tailroom = skb_tailroom(skb);
 
-       if ((skb_header_cloned(skb) || headroom < 0) &&
-           pskb_expand_head(skb, headroom < 0 ? 8 : 0, 0, GFP_ATOMIC)) {
+       if (!skb_header_cloned(skb) &&
+           !skb_cloned(skb) &&
+           (headroom + tailroom) >= 8) {
+               if (headroom < 8) {
+                       skb->data = memmove(skb->head + 8, skb->data, skb->len);
+                       skb_set_tail_pointer(skb, skb->len);
+               }
+       } else {
+               struct sk_buff *skb2;

drivers/net/usb/ax88179_178a.c 2013-11-17 13:23:39.525734277 -0500 line 1207

Quoted 10 lines
drivers/net/usb/ax88179_178a.c 2013-11-17 13:23:39.525734277 -0500 renamed from drivers/net/usb/ax88179_178a.c.orig 2013-11-03 18:41:51.000000000 -0500 +5 -1
+
+               skb2 = skb_copy_expand(skb, 8, 0, flags);
                dev_kfree_skb_any(skb);
-               return NULL;
+               skb = skb2;
+               if (!skb)
+                       return NULL;
        }
 
        skb_push(skb, 4);

Two kernels later, and this regression has still not been fixed.

A simple revert, folks.

Signature · 3 lines
Mark Lord
Real-Time Remedies Inc.
[email protected]

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

#20 lore raw

PiBGcm9tOiBNYXJrIExvcmQNCj4gU2VudDogMzAgTm92ZW1iZXIgMjAxMyAwMjo1OQ0KPiBUbzog U2FyYWggU2hhcnA7IERhdmlkIExhaWdodA0KPiBDYzogRGF2aWQgTWlsbGVyOyBlcmljLmR1bWF6 ZXRAZ21haWwuY29tOyBtaW5nLmxlaUBjYW5vbmljYWwuY29tOyBuZXRkZXZAdmdlci5rZXJuZWwu b3JnOyBsaW51eC0NCj4gdXNiQHZnZXIua2VybmVsLm9yZw0KPiBTdWJqZWN0OiBSZTogbmV0L3Vz Yi9heDg4MTc5XzE3OGEgZHJpdmVyIGJyb2tlbiBpbiBsaW51eC0zLjEyDQo+IA0KPiBPbiAxMy0x MS0xOSAwODo0NCBBTSwgTWFyayBMb3JkIHdyb3RlOg0KPiA+IE9uIDEzLTExLTE5IDA1OjA0IEFN LCBEYXZpZCBMYWlnaHQgd3JvdGU6DQo+ID4+DQo+ID4+IFdoaWNoIGNoYW5nZXMgZGlkIHlvdSBy ZXZlcnQ/DQo+ID4NCj4gPiBKdXN0IHRoZSBiaXRzIHRoYXQgY2hhbmdlZCBob3cgdGhlIGhlYWRy b29tL3RhaWxyb29tIHNpemVzDQo+ID4gd2VyZSBjaGVja2VkIGFuZCBhZGp1c3RlZC4gIFNlZSBh dHRhY2htZW50IGZvciB0aGUgcmV2ZXJ0IHBhdGNoDQo+ID4gSSBhbSB1c2luZyBoZXJlLiAgTXkg bWFpbGVyIHVuZm9ydHVuYXRlbHkgbGlrZXMgdG8gbWFuZ2xlIGlubGluZSBwYXRjaGVzLg0KPiA+ DQouLi4NCj4gDQo+IFR3byBrZXJuZWxzIGxhdGVyLCBhbmQgdGhpcyByZWdyZXNzaW9uIGhhcyBz dGlsbCBub3QgYmVlbiBmaXhlZC4NCj4gDQo+IEEgc2ltcGxlIHJldmVydCwgZm9sa3MuDQoNClJl dmVydGluZyB0aGUgYXg4ODE3OV8xNzhhIGRyaXZlciBkb2Vzbid0IGZpeCB0aGUgcHJvYmxlbS4N CkknbSBzZWVuIHR4L3J4IGlzc3VlcyB3aXRoIGl0IG9uIG11Y2ggb2xkZXIga2VybmVscyB0aGF0 IGRvbid0DQphcHBlYXIgd2l0aCBhIGN1cnJlbnQga2VybmVsIGFuZCB0aGUgZml4ZWQgeGhjaSBj b2RlLg0KDQpTYXJhaCBuZWVkcyB0byBmZWVkIHRoZSB4aGNpX3JpbmcuYyBmaXggdGhyb3VnaCBp bnRvIHN0YWJsZS4NCg0KCURhdmlkDQoNCg==
--
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

author
#21 lore raw
Quoted 20 lines · David Laight
Quoted 16 lines

From: Mark Lord
Sent: 30 November 2013 02:59
To: Sarah Sharp; David Laight
Cc: David Miller; [email protected]; [email protected]; [email protected]; linux- [email protected]
Subject: Re: net/usb/ax88179_178a driver broken in linux-3.12

Quoted 8 lines · Mark Lord
Quoted 2 lines · David Laight

Which changes did you revert?

Just the bits that changed how the headroom/tailroom sizes were checked and adjusted. See attachment for the revert patch I am using here. My mailer unfortunately likes to mangle inline patches.

...

Quoted 3 lines

Two kernels later, and this regression has still not been fixed.

Quoted 7 lines
Quoted 1 line

A simple revert, folks.

Reverting the ax88179_178a driver doesn't fix the problem. I'm seen tx/rx issues with it on much older kernels that don't appear with a current kernel and the fixed xhci code.

Sarah needs to feed the xhci_ring.c fix through into stable.

Oh, I agree. But Linus makes a MASSIVE distinction between things that have always been broken, and REGRESSIONS from the immediately prior kernel that can be tracked to a single update.

Let's see some action, here folks!

Signature · 3 lines
Mark Lord
Real-Time Remedies Inc.
[email protected]

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

#23 lore raw
Quoted 27 lines · Mark Lord
Quoted 26 lines · David Laight
Quoted 16 lines

From: Mark Lord
Sent: 30 November 2013 02:59
To: Sarah Sharp; David Laight
Cc: David Miller; [email protected]; [email protected]; [email protected]; linux- [email protected]
Subject: Re: net/usb/ax88179_178a driver broken in linux-3.12

Quoted 8 lines · Mark Lord
Quoted 2 lines · David Laight

Which changes did you revert?

Just the bits that changed how the headroom/tailroom sizes were checked and adjusted. See attachment for the revert patch I am using here. My mailer unfortunately likes to mangle inline patches.

...

Quoted 4 lines

Two kernels later, and this regression has still not been fixed.

A simple revert, folks.

Reverting the ax88179_178a driver doesn't fix the problem. I'm seen tx/rx issues with it on much older kernels that don't appear with a current kernel and the fixed xhci code.

Quoted 7 lines
Quoted 1 line

Sarah needs to feed the xhci_ring.c fix through into stable.

Oh, I agree. But Linus makes a MASSIVE distinction between things that have always been broken, and REGRESSIONS from the immediately prior kernel that can be tracked to a single update.

Let's see some action, here folks!

I'm working on it. You will probably have to wait for -rc3, depending on when Greg sends his next pull request. I will Cc you on the pull request and patch, which should be sent out today.

Sarah Sharp
--
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

author
#24 lore raw
Quoted 1 line · Sarah Sharp
Quoted 1 line · David Laight

..

Quoted 1 line
Quoted 1 line
Quoted 1 line

Sarah needs to feed the xhci_ring.c fix through into stable.

..

Quoted 3 lines

I'm working on it. You will probably have to wait for -rc3, depending on when Greg sends his next pull request. I will Cc you on the pull request and patch, which should be sent out today.

Super, exactly what we need, thanks!

Signature · 3 lines
Mark Lord
Real-Time Remedies Inc.
[email protected]
#25 lore raw
In reply to Sarah Sharp
Quoted 34 lines · Sarah Sharp
Quoted 33 lines · Mark Lord
Quoted 20 lines · David Laight
Quoted 16 lines

From: Mark Lord
Sent: 30 November 2013 02:59
To: Sarah Sharp; David Laight
Cc: David Miller; [email protected]; [email protected]; [email protected]; linux- [email protected]
Subject: Re: net/usb/ax88179_178a driver broken in linux-3.12

Quoted 8 lines · Mark Lord
Quoted 2 lines · David Laight

Which changes did you revert?

Just the bits that changed how the headroom/tailroom sizes were checked and adjusted. See attachment for the revert patch I am using here. My mailer unfortunately likes to mangle inline patches.

...

Quoted 3 lines

Two kernels later, and this regression has still not been fixed.

Quoted 7 lines
Quoted 1 line

A simple revert, folks.

Reverting the ax88179_178a driver doesn't fix the problem. I'm seen tx/rx issues with it on much older kernels that don't appear with a current kernel and the fixed xhci code.

Sarah needs to feed the xhci_ring.c fix through into stable.

Oh, I agree. But Linus makes a MASSIVE distinction between things that have always been broken, and REGRESSIONS from the immediately prior kernel that can be tracked to a single update.

Quoted 5 lines
Quoted 1 line

Let's see some action, here folks!

I'm working on it. You will probably have to wait for -rc3, depending on when Greg sends his next pull request. I will Cc you on the pull request and patch, which should be sent out today.

It's impossible to get into -rc2 given that it was released last week :) --
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