Skip to contentSkip to conversation

ibmveth: v1 calculate correct gso_size and set gso_type

PATCH In review Jon Maxwell 5 participants 17 messages Oct 26, 2016 – Dec 13, 2016

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ibmveth: v1 calculate correct gso_size and set gso_type

We recently encountered a bug where a few customers using ibmveth on the same LPAR hit an issue where a TCP session hung when large receive was enabled. Closer analysis revealed that the session was stuck because the one side was advertising a zero window repeatedly.

We narrowed this down to the fact the ibmveth driver did not set gso_size which is translated by TCP into the MSS later up the stack. The MSS is used to calculate the TCP window size and as that was abnormally large, it was calculating a zero window, even although the sockets receive buffer was completely empty.

We were able to reproduce this and worked with IBM to fix this. Thanks Tom and Marcelo for all your help and review on this.

The patch fixes both our internal reproduction tests and our customers tests.

---
 drivers/net/ethernet/ibm/ibmveth.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/ethernet/ibm/ibmveth.c +20 -0
index 29c05d0..c51717e 100644
@@ -1182,6 +1182,8 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 	int frames_processed = 0;
 	unsigned long lpar_rc;
 	struct iphdr *iph;
+	bool large_packet = 0;
+	u16 hdr_len = ETH_HLEN + sizeof(struct tcphdr);
 
 restart_poll:
 	while (frames_processed < budget) {
@@ -1236,10 +1238,28 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 						iph->check = 0;
 						iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
 						adapter->rx_large_packets++;
+						large_packet = 1;
 					}
 				}
 			}
 
+			if (skb->len > netdev->mtu) {
+				iph = (struct iphdr *)skb->data;
+				if (be16_to_cpu(skb->protocol) == ETH_P_IP &&
+				    iph->protocol == IPPROTO_TCP) {
+					hdr_len += sizeof(struct iphdr);
+					skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+					skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+				} else if (be16_to_cpu(skb->protocol) == ETH_P_IPV6 &&
+					   iph->protocol == IPPROTO_TCP) {
+					hdr_len += sizeof(struct ipv6hdr);
+					skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
+					skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+				}
+				if (!large_packet)
+					adapter->rx_large_packets++;
+			}
+
 			napi_gro_receive(napi, skb);	/* send it up */
 
 			netdev->stats.rx_packets++;
Signature · 1 line
1.8.3.1
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Jon Maxwell

We recently encountered a bug where a few customers using ibmveth on the same LPAR hit an issue where a TCP session hung when large receive was enabled. Closer analysis revealed that the session was stuck because the one side was advertising a zero window repeatedly.

We narrowed this down to the fact the ibmveth driver did not set gso_size which is translated by TCP into the MSS later up the stack. The MSS is used to calculate the TCP window size and as that was abnormally large, it was calculating a zero window, even although the sockets receive buffer was completely empty.

Quoted 6 lines

We were able to reproduce this and worked with IBM to fix this. Thanks Tom and Marcelo for all your help and review on this.

The patch fixes both our internal reproduction tests and our customers tests.

Thanks, Jon.

Quoted 46 lines
---
 drivers/net/ethernet/ibm/ibmveth.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/ethernet/ibm/ibmveth.c +20 -0
index 29c05d0..c51717e 100644
@@ -1182,6 +1182,8 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 	int frames_processed = 0;
 	unsigned long lpar_rc;
 	struct iphdr *iph;
+	bool large_packet = 0;
+	u16 hdr_len = ETH_HLEN + sizeof(struct tcphdr);
 
 restart_poll:
 	while (frames_processed < budget) {
@@ -1236,10 +1238,28 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 						iph->check = 0;
 						iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
 						adapter->rx_large_packets++;
+						large_packet = 1;
 					}
 				}
 			}
 
+			if (skb->len > netdev->mtu) {
+				iph = (struct iphdr *)skb->data;
+				if (be16_to_cpu(skb->protocol) == ETH_P_IP &&
+				    iph->protocol == IPPROTO_TCP) {
+					hdr_len += sizeof(struct iphdr);
+					skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+					skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+				} else if (be16_to_cpu(skb->protocol) == ETH_P_IPV6 &&
+					   iph->protocol == IPPROTO_TCP) {
+					hdr_len += sizeof(struct ipv6hdr);
+					skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
+					skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+				}
+				if (!large_packet)
+					adapter->rx_large_packets++;
+			}
+
 			napi_gro_receive(napi, skb);	/* send it up */
 
 			netdev->stats.rx_packets++;
#2 lore raw
In reply to Jon Maxwell
Quoted 51 lines · Jon Maxwell

We recently encountered a bug where a few customers using ibmveth on the same LPAR hit an issue where a TCP session hung when large receive was enabled. Closer analysis revealed that the session was stuck because the one side was advertising a zero window repeatedly.

We narrowed this down to the fact the ibmveth driver did not set gso_size which is translated by TCP into the MSS later up the stack. The MSS is used to calculate the TCP window size and as that was abnormally large, it was calculating a zero window, even although the sockets receive buffer was completely empty.

We were able to reproduce this and worked with IBM to fix this. Thanks Tom and Marcelo for all your help and review on this.

The patch fixes both our internal reproduction tests and our customers tests.

---
 drivers/net/ethernet/ibm/ibmveth.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/ethernet/ibm/ibmveth.c +11 -0
index 29c05d0..c51717e 100644
@@ -1182,6 +1182,8 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 	int frames_processed = 0;
 	unsigned long lpar_rc;
 	struct iphdr *iph;
+	bool large_packet = 0;
+	u16 hdr_len = ETH_HLEN + sizeof(struct tcphdr);
 
 restart_poll:
 	while (frames_processed < budget) {
@@ -1236,10 +1238,28 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 						iph->check = 0;
 						iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
 						adapter->rx_large_packets++;
+						large_packet = 1;
 					}
 				}
 			}
 
+			if (skb->len > netdev->mtu) {
+				iph = (struct iphdr *)skb->data;
+				if (be16_to_cpu(skb->protocol) == ETH_P_IP &&
+				    iph->protocol == IPPROTO_TCP) {
+					hdr_len += sizeof(struct iphdr);
+					skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+					skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+				} else if (be16_to_cpu(skb->protocol) == ETH_P_IPV6 &&

drivers/net/ethernet/ibm/ibmveth.c static int ibmveth_poll(struct napi_struct *napi, int budget) · line 1263

Quoted 10 lines
drivers/net/ethernet/ibm/ibmveth.c +9 -0
+					   iph->protocol == IPPROTO_TCP) {
+					hdr_len += sizeof(struct ipv6hdr);
+					skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
+					skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+				}
+				if (!large_packet)
+					adapter->rx_large_packets++;
+			}
+
 

This might break forwarding and PMTU discovery.

You force gso_size to device mtu, regardless of real MSS used by the TCP sender.

Don't you have the MSS provided in RX descriptor, instead of guessing the value ?

#3 lore raw
Quoted 64 lines · Eric Dumazet
Quoted 51 lines · Jon Maxwell

We recently encountered a bug where a few customers using ibmveth on the same LPAR hit an issue where a TCP session hung when large receive was enabled. Closer analysis revealed that the session was stuck because the one side was advertising a zero window repeatedly.

We narrowed this down to the fact the ibmveth driver did not set gso_size which is translated by TCP into the MSS later up the stack. The MSS is used to calculate the TCP window size and as that was abnormally large, it was calculating a zero window, even although the sockets receive buffer was completely empty.

We were able to reproduce this and worked with IBM to fix this. Thanks Tom and Marcelo for all your help and review on this.

The patch fixes both our internal reproduction tests and our customers tests.

---
 drivers/net/ethernet/ibm/ibmveth.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/ethernet/ibm/ibmveth.c +11 -0
index 29c05d0..c51717e 100644
@@ -1182,6 +1182,8 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 	int frames_processed = 0;
 	unsigned long lpar_rc;
 	struct iphdr *iph;
+	bool large_packet = 0;
+	u16 hdr_len = ETH_HLEN + sizeof(struct tcphdr);
 
 restart_poll:
 	while (frames_processed < budget) {
@@ -1236,10 +1238,28 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 						iph->check = 0;
 						iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
 						adapter->rx_large_packets++;
+						large_packet = 1;
 					}
 				}
 			}
 
+			if (skb->len > netdev->mtu) {
+				iph = (struct iphdr *)skb->data;
+				if (be16_to_cpu(skb->protocol) == ETH_P_IP &&
+				    iph->protocol == IPPROTO_TCP) {
+					hdr_len += sizeof(struct iphdr);
+					skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+					skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+				} else if (be16_to_cpu(skb->protocol) == ETH_P_IPV6 &&

drivers/net/ethernet/ibm/ibmveth.c static int ibmveth_poll(struct napi_struct *napi, int budget) · line 1263

Quoted 10 lines
drivers/net/ethernet/ibm/ibmveth.c +9 -0
+					   iph->protocol == IPPROTO_TCP) {
+					hdr_len += sizeof(struct ipv6hdr);
+					skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
+					skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+				}
+				if (!large_packet)
+					adapter->rx_large_packets++;
+			}
+
 

This might break forwarding and PMTU discovery.

Quoted 8 lines

You force gso_size to device mtu, regardless of real MSS used by the TCP sender.

Don't you have the MSS provided in RX descriptor, instead of guessing the value ?

The MSS is not always available unfortunately, so this is the best solution there is at the moment.

#4 lore raw
Quoted 68 lines · Thomas Falcon
Quoted 67 lines · Eric Dumazet
Quoted 51 lines · Jon Maxwell

We recently encountered a bug where a few customers using ibmveth on the same LPAR hit an issue where a TCP session hung when large receive was enabled. Closer analysis revealed that the session was stuck because the one side was advertising a zero window repeatedly.

We narrowed this down to the fact the ibmveth driver did not set gso_size which is translated by TCP into the MSS later up the stack. The MSS is used to calculate the TCP window size and as that was abnormally large, it was calculating a zero window, even although the sockets receive buffer was completely empty.

We were able to reproduce this and worked with IBM to fix this. Thanks Tom and Marcelo for all your help and review on this.

The patch fixes both our internal reproduction tests and our customers tests.

---
 drivers/net/ethernet/ibm/ibmveth.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/ethernet/ibm/ibmveth.c +11 -0
index 29c05d0..c51717e 100644
@@ -1182,6 +1182,8 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 	int frames_processed = 0;
 	unsigned long lpar_rc;
 	struct iphdr *iph;
+	bool large_packet = 0;
+	u16 hdr_len = ETH_HLEN + sizeof(struct tcphdr);
 
 restart_poll:
 	while (frames_processed < budget) {
@@ -1236,10 +1238,28 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 						iph->check = 0;
 						iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
 						adapter->rx_large_packets++;
+						large_packet = 1;
 					}
 				}
 			}
 
+			if (skb->len > netdev->mtu) {
+				iph = (struct iphdr *)skb->data;
+				if (be16_to_cpu(skb->protocol) == ETH_P_IP &&
+				    iph->protocol == IPPROTO_TCP) {
+					hdr_len += sizeof(struct iphdr);
+					skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+					skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+				} else if (be16_to_cpu(skb->protocol) == ETH_P_IPV6 &&

drivers/net/ethernet/ibm/ibmveth.c static int ibmveth_poll(struct napi_struct *napi, int budget) · line 1263

Quoted 10 lines
drivers/net/ethernet/ibm/ibmveth.c +9 -0
+					   iph->protocol == IPPROTO_TCP) {
+					hdr_len += sizeof(struct ipv6hdr);
+					skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
+					skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+				}
+				if (!large_packet)
+					adapter->rx_large_packets++;
+			}
+
 

This might break forwarding and PMTU discovery.

You force gso_size to device mtu, regardless of real MSS used by the TCP sender.

Quoted 6 lines
Quoted 5 lines

Don't you have the MSS provided in RX descriptor, instead of guessing the value ?

The MSS is not always available unfortunately, so this is the best solution there is at the moment.

Hmm... then what about skb_shinfo(skb)->gso_segs ?

ip_rcv() for example has :

        __IP_ADD_STATS(net,
                       IPSTATS_MIB_NOECTPKTS + (iph->tos & INET_ECN_MASK),
                       max_t(unsigned short, 1, skb_shinfo(skb)->gso_segs));

Also prefer : (skb->protocol == htons(ETH_P_IP)) tests

And the ipv6 test is wrong :

} else if (be16_to_cpu(skb->protocol) == ETH_P_IPV6 &&

           iph->protocol == IPPROTO_TCP) {

Since iph is a pointer to ipv4 iphdr .

#5 lore raw
Quoted 76 lines · Eric Dumazet
Quoted 68 lines · Thomas Falcon
Quoted 67 lines · Eric Dumazet
Quoted 51 lines · Jon Maxwell

We recently encountered a bug where a few customers using ibmveth on the same LPAR hit an issue where a TCP session hung when large receive was enabled. Closer analysis revealed that the session was stuck because the one side was advertising a zero window repeatedly.

We narrowed this down to the fact the ibmveth driver did not set gso_size which is translated by TCP into the MSS later up the stack. The MSS is used to calculate the TCP window size and as that was abnormally large, it was calculating a zero window, even although the sockets receive buffer was completely empty.

We were able to reproduce this and worked with IBM to fix this. Thanks Tom and Marcelo for all your help and review on this.

The patch fixes both our internal reproduction tests and our customers tests.

---
 drivers/net/ethernet/ibm/ibmveth.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/ethernet/ibm/ibmveth.c +11 -0
index 29c05d0..c51717e 100644
@@ -1182,6 +1182,8 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
   int frames_processed = 0;
   unsigned long lpar_rc;
   struct iphdr *iph;
+  bool large_packet = 0;
+  u16 hdr_len = ETH_HLEN + sizeof(struct tcphdr);
 
 restart_poll:
   while (frames_processed < budget) {
@@ -1236,10 +1238,28 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
                                           iph->check = 0;
                                           iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
                                           adapter->rx_large_packets++;
+                                          large_packet = 1;
                                   }
                           }
                   }
 
+                  if (skb->len > netdev->mtu) {
+                          iph = (struct iphdr *)skb->data;
+                          if (be16_to_cpu(skb->protocol) == ETH_P_IP &&
+                              iph->protocol == IPPROTO_TCP) {
+                                  hdr_len += sizeof(struct iphdr);
+                                  skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+                                  skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+                          } else if (be16_to_cpu(skb->protocol) == ETH_P_IPV6 &&

drivers/net/ethernet/ibm/ibmveth.c static int ibmveth_poll(struct napi_struct *napi, int budget) · line 1263

Quoted 10 lines
drivers/net/ethernet/ibm/ibmveth.c +9 -0
+                                     iph->protocol == IPPROTO_TCP) {
+                                  hdr_len += sizeof(struct ipv6hdr);
+                                  skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
+                                  skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+                          }
+                          if (!large_packet)
+                                  adapter->rx_large_packets++;
+                  }
+
 

This might break forwarding and PMTU discovery.

You force gso_size to device mtu, regardless of real MSS used by the TCP sender.

Quoted 6 lines
Quoted 5 lines

Don't you have the MSS provided in RX descriptor, instead of guessing the value ?

The MSS is not always available unfortunately, so this is the best solution there is at the moment.

Quoted 9 lines

Hmm... then what about skb_shinfo(skb)->gso_segs ?

ip_rcv() for example has :

        __IP_ADD_STATS(net,
                       IPSTATS_MIB_NOECTPKTS + (iph->tos & INET_ECN_MASK),
                       max_t(unsigned short, 1, skb_shinfo(skb)->gso_segs));

Okay thanks Eric. As the MSS is the main concern, let me work with the team here and see if we find can a better way to do this. Will take care of the other points you raised at the same time.

Quoted 13 lines

Also prefer : (skb->protocol == htons(ETH_P_IP)) tests

And the ipv6 test is wrong :

} else if (be16_to_cpu(skb->protocol) == ETH_P_IPV6 &&

           iph->protocol == IPPROTO_TCP) {

Since iph is a pointer to ipv4 iphdr .

#6 lore raw
In reply to Eric Dumazet
Quoted 65 lines · Eric Dumazet
Quoted 51 lines · Jon Maxwell

We recently encountered a bug where a few customers using ibmveth on the same LPAR hit an issue where a TCP session hung when large receive was enabled. Closer analysis revealed that the session was stuck because the one side was advertising a zero window repeatedly.

We narrowed this down to the fact the ibmveth driver did not set gso_size which is translated by TCP into the MSS later up the stack. The MSS is used to calculate the TCP window size and as that was abnormally large, it was calculating a zero window, even although the sockets receive buffer was completely empty.

We were able to reproduce this and worked with IBM to fix this. Thanks Tom and Marcelo for all your help and review on this.

The patch fixes both our internal reproduction tests and our customers tests.

---
 drivers/net/ethernet/ibm/ibmveth.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/ethernet/ibm/ibmveth.c +11 -0
index 29c05d0..c51717e 100644
@@ -1182,6 +1182,8 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 	int frames_processed = 0;
 	unsigned long lpar_rc;
 	struct iphdr *iph;
+	bool large_packet = 0;
+	u16 hdr_len = ETH_HLEN + sizeof(struct tcphdr);
 
 restart_poll:
 	while (frames_processed < budget) {
@@ -1236,10 +1238,28 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 						iph->check = 0;
 						iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
 						adapter->rx_large_packets++;
+						large_packet = 1;
 					}
 				}
 			}
 
+			if (skb->len > netdev->mtu) {
+				iph = (struct iphdr *)skb->data;
+				if (be16_to_cpu(skb->protocol) == ETH_P_IP &&
+				    iph->protocol == IPPROTO_TCP) {
+					hdr_len += sizeof(struct iphdr);
+					skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+					skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+				} else if (be16_to_cpu(skb->protocol) == ETH_P_IPV6 &&

drivers/net/ethernet/ibm/ibmveth.c static int ibmveth_poll(struct napi_struct *napi, int budget) · line 1263

Quoted 10 lines
drivers/net/ethernet/ibm/ibmveth.c +9 -0
+					   iph->protocol == IPPROTO_TCP) {
+					hdr_len += sizeof(struct ipv6hdr);
+					skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
+					skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+				}
+				if (!large_packet)
+					adapter->rx_large_packets++;
+			}
+
 

This might break forwarding and PMTU discovery.

Quoted 5 lines

You force gso_size to device mtu, regardless of real MSS used by the TCP sender.

Don't you have the MSS provided in RX descriptor, instead of guessing the value ?

We've had some further discussions on this with the Virtual I/O Server (VIOS) development team. The large receive aggregation in the VIOS (AIX based) is actually being done by software in the VIOS. What they may be able to do is when performing this aggregation, they could look at the packet lengths of all the packets being aggregated and take the largest packet size within the aggregation unit, minus the header length and return that to the virtual ethernet client which we could then stuff into gso_size. They are currently assessing how feasible this would be to do and whether it would impact other bits of the code. However, assuming this does end up being an option, would this address the concerns here or is that going to break something else I'm not thinking of?

Unfortunately, I don't think we'd have a good way to get gso_segs set correctly as I don't see how that would get passed back up the interface.

Thanks,

Brian

Signature · 3 lines
Brian King
Power Linux I/O
IBM Linux Technology Center
#7 lore raw
Quoted 72 lines · Brian King
Quoted 65 lines · Eric Dumazet
Quoted 51 lines · Jon Maxwell

We recently encountered a bug where a few customers using ibmveth on the same LPAR hit an issue where a TCP session hung when large receive was enabled. Closer analysis revealed that the session was stuck because the one side was advertising a zero window repeatedly.

We narrowed this down to the fact the ibmveth driver did not set gso_size which is translated by TCP into the MSS later up the stack. The MSS is used to calculate the TCP window size and as that was abnormally large, it was calculating a zero window, even although the sockets receive buffer was completely empty.

We were able to reproduce this and worked with IBM to fix this. Thanks Tom and Marcelo for all your help and review on this.

The patch fixes both our internal reproduction tests and our customers tests.

---
 drivers/net/ethernet/ibm/ibmveth.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/ethernet/ibm/ibmveth.c +11 -0
index 29c05d0..c51717e 100644
@@ -1182,6 +1182,8 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
     int frames_processed = 0;
     unsigned long lpar_rc;
     struct iphdr *iph;
+    bool large_packet = 0;
+    u16 hdr_len = ETH_HLEN + sizeof(struct tcphdr);
 
 restart_poll:
     while (frames_processed < budget) {
@@ -1236,10 +1238,28 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
                                             iph->check = 0;
                                             iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
                                             adapter->rx_large_packets++;
+                                            large_packet = 1;
                                     }
                             }
                     }
 
+                    if (skb->len > netdev->mtu) {
+                            iph = (struct iphdr *)skb->data;
+                            if (be16_to_cpu(skb->protocol) == ETH_P_IP &&
+                                iph->protocol == IPPROTO_TCP) {
+                                    hdr_len += sizeof(struct iphdr);
+                                    skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+                                    skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+                            } else if (be16_to_cpu(skb->protocol) == ETH_P_IPV6 &&

drivers/net/ethernet/ibm/ibmveth.c static int ibmveth_poll(struct napi_struct *napi, int budget) · line 1263

Quoted 10 lines
drivers/net/ethernet/ibm/ibmveth.c +9 -0
+                                       iph->protocol == IPPROTO_TCP) {
+                                    hdr_len += sizeof(struct ipv6hdr);
+                                    skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
+                                    skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+                            }
+                            if (!large_packet)
+                                    adapter->rx_large_packets++;
+                    }
+
 

This might break forwarding and PMTU discovery.

Quoted 5 lines

You force gso_size to device mtu, regardless of real MSS used by the TCP sender.

Don't you have the MSS provided in RX descriptor, instead of guessing the value ?

Quoted 10 lines

We've had some further discussions on this with the Virtual I/O Server (VIOS) development team. The large receive aggregation in the VIOS (AIX based) is actually being done by software in the VIOS. What they may be able to do is when performing this aggregation, they could look at the packet lengths of all the packets being aggregated and take the largest packet size within the aggregation unit, minus the header length and return that to the virtual ethernet client which we could then stuff into gso_size. They are currently assessing how feasible this would be to do and whether it would impact other bits of the code. However, assuming this does end up being an option, would this address the concerns here or is that going to break something else I'm not thinking of?

I was discussing this with a colleague and although this is better than what we have so far. We wonder if there could be a corner case where it ends up with a smaller value than the current MSS. For example if the application sent a burst of small TCP packets with the PUSH bit set. In that case they may not be coalesced by GRO. The VIOS could probably be coded to detect that condition and use the previous MSS. But that may not necessarily be the current MSS.

The ibmveth driver passes the MSS via gso_size to the VIOS. Either as the 3rd argument of ibmveth_send() or via tcp_hdr(skb)->check which is presumably over-written when the VIOS does the TSO. Would it be possible to keep a copy of this value on the TX side on the VIOS before it over-written and then some how pass that up to the RX side along with frame and set gso_size to that which should be the current MSS?

Regards

Jon

Quoted 14 lines

Unfortunately, I don't think we'd have a good way to get gso_segs set correctly as I don't see how that would get passed back up the interface.

Thanks,

Brian

--
Brian King
Power Linux I/O
IBM Linux Technology Center

#8 lore raw
Quoted 84 lines · Jonathan Maxwell
Quoted 72 lines · Brian King
Quoted 65 lines · Eric Dumazet
Quoted 51 lines · Jon Maxwell

We recently encountered a bug where a few customers using ibmveth on the same LPAR hit an issue where a TCP session hung when large receive was enabled. Closer analysis revealed that the session was stuck because the one side was advertising a zero window repeatedly.

We narrowed this down to the fact the ibmveth driver did not set gso_size which is translated by TCP into the MSS later up the stack. The MSS is used to calculate the TCP window size and as that was abnormally large, it was calculating a zero window, even although the sockets receive buffer was completely empty.

We were able to reproduce this and worked with IBM to fix this. Thanks Tom and Marcelo for all your help and review on this.

The patch fixes both our internal reproduction tests and our customers tests.

---
 drivers/net/ethernet/ibm/ibmveth.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/ethernet/ibm/ibmveth.c +11 -0
index 29c05d0..c51717e 100644
@@ -1182,6 +1182,8 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
     int frames_processed = 0;
     unsigned long lpar_rc;
     struct iphdr *iph;
+    bool large_packet = 0;
+    u16 hdr_len = ETH_HLEN + sizeof(struct tcphdr);
 
 restart_poll:
     while (frames_processed < budget) {
@@ -1236,10 +1238,28 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
                                             iph->check = 0;
                                             iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
                                             adapter->rx_large_packets++;
+                                            large_packet = 1;
                                     }
                             }
                     }
 
+                    if (skb->len > netdev->mtu) {
+                            iph = (struct iphdr *)skb->data;
+                            if (be16_to_cpu(skb->protocol) == ETH_P_IP &&
+                                iph->protocol == IPPROTO_TCP) {
+                                    hdr_len += sizeof(struct iphdr);
+                                    skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+                                    skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+                            } else if (be16_to_cpu(skb->protocol) == ETH_P_IPV6 &&

drivers/net/ethernet/ibm/ibmveth.c static int ibmveth_poll(struct napi_struct *napi, int budget) · line 1263

Quoted 10 lines
drivers/net/ethernet/ibm/ibmveth.c +9 -0
+                                       iph->protocol == IPPROTO_TCP) {
+                                    hdr_len += sizeof(struct ipv6hdr);
+                                    skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
+                                    skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+                            }
+                            if (!large_packet)
+                                    adapter->rx_large_packets++;
+                    }
+
 

This might break forwarding and PMTU discovery.

Quoted 5 lines

You force gso_size to device mtu, regardless of real MSS used by the TCP sender.

Don't you have the MSS provided in RX descriptor, instead of guessing the value ?

Quoted 10 lines

We've had some further discussions on this with the Virtual I/O Server (VIOS) development team. The large receive aggregation in the VIOS (AIX based) is actually being done by software in the VIOS. What they may be able to do is when performing this aggregation, they could look at the packet lengths of all the packets being aggregated and take the largest packet size within the aggregation unit, minus the header length and return that to the virtual ethernet client which we could then stuff into gso_size. They are currently assessing how feasible this would be to do and whether it would impact other bits of the code. However, assuming this does end up being an option, would this address the concerns here or is that going to break something else I'm not thinking of?

Quoted 5 lines

I was discussing this with a colleague and although this is better than what we have so far. We wonder if there could be a corner case where it ends up with a smaller value than the current MSS. For example if the application sent a burst of small TCP packets with the PUSH bit set. In that case they may not be coalesced by GRO. The VIOS could

Would that be a big problem though? Other than a performance degradation in this specific case, do you see a functional issue with this approach?

Quoted 9 lines

probably be coded to detect that condition and use the previous MSS. But that may not necessarily be the current MSS.

The ibmveth driver passes the MSS via gso_size to the VIOS. Either as the 3rd argument of ibmveth_send() or via tcp_hdr(skb)->check which is presumably over-written when the VIOS does the TSO. Would it be possible to keep a copy of this value on the TX side on the VIOS before it over-written and then some how pass that up to the RX side along with frame and set gso_size to that which should be the current MSS?

That seems like it might be more difficult. Wouldn't that require the VIOS to track the MSS on a per connection basis, since the MSS might differ based on the source / destination? I discussed with VIOS development, and they don't do any connection tracking where they'd be able to insert this.

Unless there is a functional issue with the approach to have the VIOS insert the MSS based on the size of the packets received off the wire, I think that might be our best option...

Thanks,

Brian

Quoted 20 lines

Regards

Jon

Quoted 14 lines

Unfortunately, I don't think we'd have a good way to get gso_segs set correctly as I don't see how that would get passed back up the interface.

Thanks,

Brian

--
Brian King
Power Linux I/O
IBM Linux Technology Center

Signature · 3 lines
Brian King
Power Linux I/O
IBM Linux Technology Center
#9 lore raw
In reply to Eric Dumazet
Quoted 65 lines · Eric Dumazet
Quoted 51 lines · Jon Maxwell

We recently encountered a bug where a few customers using ibmveth on the same LPAR hit an issue where a TCP session hung when large receive was enabled. Closer analysis revealed that the session was stuck because the one side was advertising a zero window repeatedly.

We narrowed this down to the fact the ibmveth driver did not set gso_size which is translated by TCP into the MSS later up the stack. The MSS is used to calculate the TCP window size and as that was abnormally large, it was calculating a zero window, even although the sockets receive buffer was completely empty.

We were able to reproduce this and worked with IBM to fix this. Thanks Tom and Marcelo for all your help and review on this.

The patch fixes both our internal reproduction tests and our customers tests.

---
 drivers/net/ethernet/ibm/ibmveth.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/ethernet/ibm/ibmveth.c +11 -0
index 29c05d0..c51717e 100644
@@ -1182,6 +1182,8 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 	int frames_processed = 0;
 	unsigned long lpar_rc;
 	struct iphdr *iph;
+	bool large_packet = 0;
+	u16 hdr_len = ETH_HLEN + sizeof(struct tcphdr);
 
 restart_poll:
 	while (frames_processed < budget) {
@@ -1236,10 +1238,28 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 						iph->check = 0;
 						iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
 						adapter->rx_large_packets++;
+						large_packet = 1;
 					}
 				}
 			}
 
+			if (skb->len > netdev->mtu) {
+				iph = (struct iphdr *)skb->data;
+				if (be16_to_cpu(skb->protocol) == ETH_P_IP &&
+				    iph->protocol == IPPROTO_TCP) {
+					hdr_len += sizeof(struct iphdr);
+					skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+					skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+				} else if (be16_to_cpu(skb->protocol) == ETH_P_IPV6 &&

drivers/net/ethernet/ibm/ibmveth.c static int ibmveth_poll(struct napi_struct *napi, int budget) · line 1263

Quoted 10 lines
drivers/net/ethernet/ibm/ibmveth.c +9 -0
+					   iph->protocol == IPPROTO_TCP) {
+					hdr_len += sizeof(struct ipv6hdr);
+					skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
+					skb_shinfo(skb)->gso_size = netdev->mtu - hdr_len;
+				}
+				if (!large_packet)
+					adapter->rx_large_packets++;
+			}
+
 

This might break forwarding and PMTU discovery.

Quoted 5 lines

You force gso_size to device mtu, regardless of real MSS used by the TCP sender.

Don't you have the MSS provided in RX descriptor, instead of guessing the value ?

Eric,

We are currently pursuing making changes to the Power Virtual I/O Server to provide the MSS to the ibmveth driver. However, this will take time to go through test and ultimately get released. Although imperfect, this patch does help a real customer hitting this issue right now. Would you object to this patch getting merged as is, with the understanding that when we get the change in the Virtual I/O Server released, we will revert this interim change and apply the new method?

Thanks,

Brian

Signature · 3 lines
Brian King
Power Linux I/O
IBM Linux Technology Center
#10 lore raw

PATCH 1/1 ibmveth: set correct gso_size and gso_type

In reply to Jon Maxwell

This patch is based on an earlier one submitted
by Jon Maxwell with the following commit message:

"We recently encountered a bug where a few customers using ibmveth on the same LPAR hit an issue where a TCP session hung when large receive was enabled. Closer analysis revealed that the session was stuck because the one side was advertising a zero window repeatedly.

We narrowed this down to the fact the ibmveth driver did not set gso_size which is translated by TCP into the MSS later up the stack. The MSS is used to calculate the TCP window size and as that was abnormally large, it was calculating a zero window, even although the sockets receive buffer was completely empty."

We rely on the Virtual I/O Server partition in a pseries environment to provide the MSS through the TCP header checksum field. The stipulation is that users should not disable checksum offloading if rx packet aggregation is enabled through VIOS.

Some firmware offerings provide the MSS in the RX buffer. This is signalled by a bit in the RX queue descriptor.

---
 drivers/net/ethernet/ibm/ibmveth.c | 65 ++++++++++++++++++++++++++++++++++++--
 drivers/net/ethernet/ibm/ibmveth.h |  1 +
 2 files changed, 64 insertions(+), 2 deletions(-)
drivers/net/ethernet/ibm/ibmveth.c +63 -2
index ebe6071..a36022b 100644
@@ -58,7 +58,7 @@
 
 static const char ibmveth_driver_name[] = "ibmveth";
 static const char ibmveth_driver_string[] = "IBM Power Virtual Ethernet Driver";
-#define ibmveth_driver_version "1.05"
+#define ibmveth_driver_version "1.06"
 
 MODULE_AUTHOR("Santiago Leon <[email protected]>");
 MODULE_DESCRIPTION("IBM Power Virtual Ethernet Driver");
@@ -137,6 +137,11 @@ static inline int ibmveth_rxq_frame_offset(struct ibmveth_adapter *adapter)
 	return ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_OFF_MASK;
 }
 
+static inline int ibmveth_rxq_large_packet(struct ibmveth_adapter *adapter)
+{
+	return ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_LRG_PKT;
+}
+
 static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter)
 {
 	return be32_to_cpu(adapter->rx_queue.queue_addr[adapter->rx_queue.index].length);
@@ -1174,6 +1179,45 @@ static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb,
 	goto retry_bounce;
 }
 
+static void ibmveth_rx_mss_helper(struct sk_buff *skb, u16 mss, int lrg_pkt)
+{
+	int offset = 0;
+
+	/* only TCP packets will be aggregated */
+	if (skb->protocol == htons(ETH_P_IP)) {
+		struct iphdr *iph = (struct iphdr *)skb->data;
+
+		if (iph->protocol == IPPROTO_TCP) {
+			offset = iph->ihl * 4;
+			skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+		} else {
+			return;
+		}
+	} else if (skb->protocol == htons(ETH_P_IPV6)) {
+		struct ipv6hdr *iph6 = (struct ipv6hdr *)skb->data;
+
+		if (iph6->nexthdr == IPPROTO_TCP) {
+			offset = sizeof(struct ipv6hdr);
+			skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
+		} else {
+			return;
+		}
+	} else {
+		return;
+	}
+	/* if mss is not set through Large Packet bit/mss in rx buffer,
+	 * expect that the mss will be written to the tcp header checksum.
+	 */
+	if (lrg_pkt) {
+		skb_shinfo(skb)->gso_size = mss;
+	} else if (offset) {
+		struct tcphdr *tcph = (struct tcphdr *)(skb->data + offset);
+
+		skb_shinfo(skb)->gso_size = ntohs(tcph->check);
+		tcph->check = 0;
+	}
+}
+
 static int ibmveth_poll(struct napi_struct *napi, int budget)
 {
 	struct ibmveth_adapter *adapter =
@@ -1182,6 +1226,7 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 	int frames_processed = 0;
 	unsigned long lpar_rc;
 	struct iphdr *iph;
+	u16 mss = 0;
 
 restart_poll:
 	while (frames_processed < budget) {
@@ -1199,9 +1244,21 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 			int length = ibmveth_rxq_frame_length(adapter);
 			int offset = ibmveth_rxq_frame_offset(adapter);
 			int csum_good = ibmveth_rxq_csum_good(adapter);
+			int lrg_pkt = ibmveth_rxq_large_packet(adapter);
 
 			skb = ibmveth_rxq_get_buffer(adapter);
 
+			/* if the large packet bit is set in the rx queue
+			 * descriptor, the mss will be written by PHYP eight
+			 * bytes from the start of the rx buffer, which is
+			 * skb->data at this stage
+			 */
+			if (lrg_pkt) {
+				__be64 *rxmss = (__be64 *)(skb->data + 8);
+
+				mss = (u16)be64_to_cpu(*rxmss);
+			}
+
 			new_skb = NULL;
 			if (length < rx_copybreak)
 				new_skb = netdev_alloc_skb(netdev, length);
@@ -1235,11 +1292,15 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 					if (iph->check == 0xffff) {
 						iph->check = 0;
 						iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
-						adapter->rx_large_packets++;
 					}
 				}
 			}
 
+			if (length > netdev->mtu + ETH_HLEN) {
+				ibmveth_rx_mss_helper(skb, mss, lrg_pkt);
+				adapter->rx_large_packets++;
+			}
+
 			napi_gro_receive(napi, skb);	/* send it up */
 
 			netdev->stats.rx_packets++;
drivers/net/ethernet/ibm/ibmveth.h +1 -0
index 4eade67..7acda04 100644
@@ -209,6 +209,7 @@ struct ibmveth_rx_q_entry {
 #define IBMVETH_RXQ_TOGGLE		0x80000000
 #define IBMVETH_RXQ_TOGGLE_SHIFT	31
 #define IBMVETH_RXQ_VALID		0x40000000
+#define IBMVETH_RXQ_LRG_PKT		0x04000000
 #define IBMVETH_RXQ_NO_CSUM		0x02000000
 #define IBMVETH_RXQ_CSUM_GOOD		0x01000000
 #define IBMVETH_RXQ_OFF_MASK		0x0000FFFF
Signature · 1 line
1.8.3.1
#11 lore raw

PATCH v2 1/1 ibmveth: set correct gso_size and gso_type

This patch is based on an earlier one submitted
by Jon Maxwell with the following commit message:

"We recently encountered a bug where a few customers using ibmveth on the same LPAR hit an issue where a TCP session hung when large receive was enabled. Closer analysis revealed that the session was stuck because the one side was advertising a zero window repeatedly.

We narrowed this down to the fact the ibmveth driver did not set gso_size which is translated by TCP into the MSS later up the stack. The MSS is used to calculate the TCP window size and as that was abnormally large, it was calculating a zero window, even although the sockets receive buffer was completely empty."

We rely on the Virtual I/O Server partition in a pseries environment to provide the MSS through the TCP header checksum field. The stipulation is that users should not disable checksum offloading if rx packet aggregation is enabled through VIOS.

Some firmware offerings provide the MSS in the RX buffer. This is signalled by a bit in the RX queue descriptor.

---
v2: calculate gso_segs after Eric Dumazet's comments on the earlier patch
and make sure everyone is included on CC

---
 drivers/net/ethernet/ibm/ibmveth.c | 72 ++++++++++++++++++++++++++++++++++++--
 drivers/net/ethernet/ibm/ibmveth.h |  1 +
 2 files changed, 71 insertions(+), 2 deletions(-)
drivers/net/ethernet/ibm/ibmveth.c +70 -2
index ebe6071..f0c3ae7 100644
@@ -58,7 +58,7 @@
 
 static const char ibmveth_driver_name[] = "ibmveth";
 static const char ibmveth_driver_string[] = "IBM Power Virtual Ethernet Driver";
-#define ibmveth_driver_version "1.05"
+#define ibmveth_driver_version "1.06"
 
 MODULE_AUTHOR("Santiago Leon <[email protected]>");
 MODULE_DESCRIPTION("IBM Power Virtual Ethernet Driver");
@@ -137,6 +137,11 @@ static inline int ibmveth_rxq_frame_offset(struct ibmveth_adapter *adapter)
 	return ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_OFF_MASK;
 }
 
+static inline int ibmveth_rxq_large_packet(struct ibmveth_adapter *adapter)
+{
+	return ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_LRG_PKT;
+}
+
 static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter)
 {
 	return be32_to_cpu(adapter->rx_queue.queue_addr[adapter->rx_queue.index].length);
@@ -1174,6 +1179,52 @@ static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb,
 	goto retry_bounce;
 }
 
+static void ibmveth_rx_mss_helper(struct sk_buff *skb, u16 mss, int lrg_pkt)
+{
+	struct tcphdr *tcph;
+	int offset = 0;
+	int hdr_len;
+
+	/* only TCP packets will be aggregated */
+	if (skb->protocol == htons(ETH_P_IP)) {
+		struct iphdr *iph = (struct iphdr *)skb->data;
+
+		if (iph->protocol == IPPROTO_TCP) {
+			offset = iph->ihl * 4;
+			skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+		} else {
+			return;
+		}
+	} else if (skb->protocol == htons(ETH_P_IPV6)) {
+		struct ipv6hdr *iph6 = (struct ipv6hdr *)skb->data;
+
+		if (iph6->nexthdr == IPPROTO_TCP) {
+			offset = sizeof(struct ipv6hdr);
+			skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
+		} else {
+			return;
+		}
+	} else {
+		return;
+	}
+	/* if mss is not set through Large Packet bit/mss in rx buffer,
+	 * expect that the mss will be written to the tcp header checksum.
+	 */
+	tcph = (struct tcphdr *)(skb->data + offset);
+	hdr_len = offset + tcph->doff * 4;
+	if (lrg_pkt) {
+		skb_shinfo(skb)->gso_size = mss;
+		skb_shinfo(skb)->gso_segs =
+					DIV_ROUND_UP(skb->len - hdr_len, mss);
+	} else if (offset) {
+		skb_shinfo(skb)->gso_size = ntohs(tcph->check);
+		skb_shinfo(skb)->gso_segs =
+				DIV_ROUND_UP(skb->len - hdr_len,
+					     skb_shinfo(skb)->gso_size);
+		tcph->check = 0;
+	}
+}
+
 static int ibmveth_poll(struct napi_struct *napi, int budget)
 {
 	struct ibmveth_adapter *adapter =
@@ -1182,6 +1233,7 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 	int frames_processed = 0;
 	unsigned long lpar_rc;
 	struct iphdr *iph;
+	u16 mss = 0;
 
 restart_poll:
 	while (frames_processed < budget) {
@@ -1199,9 +1251,21 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 			int length = ibmveth_rxq_frame_length(adapter);
 			int offset = ibmveth_rxq_frame_offset(adapter);
 			int csum_good = ibmveth_rxq_csum_good(adapter);
+			int lrg_pkt = ibmveth_rxq_large_packet(adapter);
 
 			skb = ibmveth_rxq_get_buffer(adapter);
 
+			/* if the large packet bit is set in the rx queue
+			 * descriptor, the mss will be written by PHYP eight
+			 * bytes from the start of the rx buffer, which is
+			 * skb->data at this stage
+			 */
+			if (lrg_pkt) {
+				__be64 *rxmss = (__be64 *)(skb->data + 8);
+
+				mss = (u16)be64_to_cpu(*rxmss);
+			}
+
 			new_skb = NULL;
 			if (length < rx_copybreak)
 				new_skb = netdev_alloc_skb(netdev, length);
@@ -1235,11 +1299,15 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 					if (iph->check == 0xffff) {
 						iph->check = 0;
 						iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
-						adapter->rx_large_packets++;
 					}
 				}
 			}
 
+			if (length > netdev->mtu + ETH_HLEN) {
+				ibmveth_rx_mss_helper(skb, mss, lrg_pkt);
+				adapter->rx_large_packets++;
+			}
+
 			napi_gro_receive(napi, skb);	/* send it up */
 
 			netdev->stats.rx_packets++;
drivers/net/ethernet/ibm/ibmveth.h +1 -0
index 4eade67..7acda04 100644
@@ -209,6 +209,7 @@ struct ibmveth_rx_q_entry {
 #define IBMVETH_RXQ_TOGGLE		0x80000000
 #define IBMVETH_RXQ_TOGGLE_SHIFT	31
 #define IBMVETH_RXQ_VALID		0x40000000
+#define IBMVETH_RXQ_LRG_PKT		0x04000000
 #define IBMVETH_RXQ_NO_CSUM		0x02000000
 #define IBMVETH_RXQ_CSUM_GOOD		0x01000000
 #define IBMVETH_RXQ_OFF_MASK		0x0000FFFF
Signature · 1 line
1.8.3.1
#12 lore raw

Re: [PATCH net v2] ibmveth: set correct gso_size and gso_type

drivers/net/ethernet/ibm/ibmveth.c static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb, · line 1225

Quoted 12 lines · Thomas Falcon

This patch is based on an earlier one submitted
by Jon Maxwell with the following commit message:

drivers/net/ethernet/ibm/ibmveth.c +8 -0
+					DIV_ROUND_UP(skb->len - hdr_len, mss);
+	} else if (offset) {
+		skb_shinfo(skb)->gso_size = ntohs(tcph->check);
+		skb_shinfo(skb)->gso_segs =
+				DIV_ROUND_UP(skb->len - hdr_len,
+					     skb_shinfo(skb)->gso_size);
+		tcph->check = 0;
+	}

Are you sure that tcph->check could never be 0 on some cases ?

That would crash on a divide by 0

#13 lore raw

PATCH v3 1/1 ibmveth: set correct gso_size and gso_type

In reply to Thomas Falcon

This patch is based on an earlier one submitted
by Jon Maxwell with the following commit message:

"We recently encountered a bug where a few customers using ibmveth on the same LPAR hit an issue where a TCP session hung when large receive was enabled. Closer analysis revealed that the session was stuck because the one side was advertising a zero window repeatedly.

We narrowed this down to the fact the ibmveth driver did not set gso_size which is translated by TCP into the MSS later up the stack. The MSS is used to calculate the TCP window size and as that was abnormally large, it was calculating a zero window, even although the sockets receive buffer was completely empty."

We rely on the Virtual I/O Server partition in a pseries environment to provide the MSS through the TCP header checksum field. The stipulation is that users should not disable checksum offloading if rx packet aggregation is enabled through VIOS.

Some firmware offerings provide the MSS in the RX buffer. This is signalled by a bit in the RX queue descriptor.

---
v3: include a check for non-zero mss when calculating gso_segs

v2: calculate gso_segs after Eric Dumazet's comments on the earlier patch
and make sure everyone is included on CC

---
 drivers/net/ethernet/ibm/ibmveth.c | 72 ++++++++++++++++++++++++++++++++++++--
 drivers/net/ethernet/ibm/ibmveth.h |  1 +
 2 files changed, 71 insertions(+), 2 deletions(-)
drivers/net/ethernet/ibm/ibmveth.c +70 -2
index ebe6071..6dc24a1 100644
@@ -58,7 +58,7 @@
 
 static const char ibmveth_driver_name[] = "ibmveth";
 static const char ibmveth_driver_string[] = "IBM Power Virtual Ethernet Driver";
-#define ibmveth_driver_version "1.05"
+#define ibmveth_driver_version "1.06"
 
 MODULE_AUTHOR("Santiago Leon <[email protected]>");
 MODULE_DESCRIPTION("IBM Power Virtual Ethernet Driver");
@@ -137,6 +137,11 @@ static inline int ibmveth_rxq_frame_offset(struct ibmveth_adapter *adapter)
 	return ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_OFF_MASK;
 }
 
+static inline int ibmveth_rxq_large_packet(struct ibmveth_adapter *adapter)
+{
+	return ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_LRG_PKT;
+}
+
 static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter)
 {
 	return be32_to_cpu(adapter->rx_queue.queue_addr[adapter->rx_queue.index].length);
@@ -1174,6 +1179,52 @@ static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb,
 	goto retry_bounce;
 }
 
+static void ibmveth_rx_mss_helper(struct sk_buff *skb, u16 mss, int lrg_pkt)
+{
+	struct tcphdr *tcph;
+	int offset = 0;
+	int hdr_len;
+
+	/* only TCP packets will be aggregated */
+	if (skb->protocol == htons(ETH_P_IP)) {
+		struct iphdr *iph = (struct iphdr *)skb->data;
+
+		if (iph->protocol == IPPROTO_TCP) {
+			offset = iph->ihl * 4;
+			skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+		} else {
+			return;
+		}
+	} else if (skb->protocol == htons(ETH_P_IPV6)) {
+		struct ipv6hdr *iph6 = (struct ipv6hdr *)skb->data;
+
+		if (iph6->nexthdr == IPPROTO_TCP) {
+			offset = sizeof(struct ipv6hdr);
+			skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
+		} else {
+			return;
+		}
+	} else {
+		return;
+	}
+	/* if mss is not set through Large Packet bit/mss in rx buffer,
+	 * expect that the mss will be written to the tcp header checksum.
+	 */
+	tcph = (struct tcphdr *)(skb->data + offset);
+	hdr_len = offset + tcph->doff * 4;
+	if (lrg_pkt) {
+		skb_shinfo(skb)->gso_size = mss;
+	} else if (offset) {
+		skb_shinfo(skb)->gso_size = ntohs(tcph->check);
+		tcph->check = 0;
+	}
+
+	if (skb_shinfo(skb)->gso_size)
+		skb_shinfo(skb)->gso_segs =
+				DIV_ROUND_UP(skb->len - hdr_len,
+					     skb_shinfo(skb)->gso_size);
+}
+
 static int ibmveth_poll(struct napi_struct *napi, int budget)
 {
 	struct ibmveth_adapter *adapter =
@@ -1182,6 +1233,7 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 	int frames_processed = 0;
 	unsigned long lpar_rc;
 	struct iphdr *iph;
+	u16 mss = 0;
 
 restart_poll:
 	while (frames_processed < budget) {
@@ -1199,9 +1251,21 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 			int length = ibmveth_rxq_frame_length(adapter);
 			int offset = ibmveth_rxq_frame_offset(adapter);
 			int csum_good = ibmveth_rxq_csum_good(adapter);
+			int lrg_pkt = ibmveth_rxq_large_packet(adapter);
 
 			skb = ibmveth_rxq_get_buffer(adapter);
 
+			/* if the large packet bit is set in the rx queue
+			 * descriptor, the mss will be written by PHYP eight
+			 * bytes from the start of the rx buffer, which is
+			 * skb->data at this stage
+			 */
+			if (lrg_pkt) {
+				__be64 *rxmss = (__be64 *)(skb->data + 8);
+
+				mss = (u16)be64_to_cpu(*rxmss);
+			}
+
 			new_skb = NULL;
 			if (length < rx_copybreak)
 				new_skb = netdev_alloc_skb(netdev, length);
@@ -1235,11 +1299,15 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 					if (iph->check == 0xffff) {
 						iph->check = 0;
 						iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
-						adapter->rx_large_packets++;
 					}
 				}
 			}
 
+			if (length > netdev->mtu + ETH_HLEN) {
+				ibmveth_rx_mss_helper(skb, mss, lrg_pkt);
+				adapter->rx_large_packets++;
+			}
+
 			napi_gro_receive(napi, skb);	/* send it up */
 
 			netdev->stats.rx_packets++;
drivers/net/ethernet/ibm/ibmveth.h +1 -0
index 4eade67..7acda04 100644
@@ -209,6 +209,7 @@ struct ibmveth_rx_q_entry {
 #define IBMVETH_RXQ_TOGGLE		0x80000000
 #define IBMVETH_RXQ_TOGGLE_SHIFT	31
 #define IBMVETH_RXQ_VALID		0x40000000
+#define IBMVETH_RXQ_LRG_PKT		0x04000000
 #define IBMVETH_RXQ_NO_CSUM		0x02000000
 #define IBMVETH_RXQ_CSUM_GOOD		0x01000000
 #define IBMVETH_RXQ_OFF_MASK		0x0000FFFF
Signature · 1 line
1.8.3.1
maintainer
#14 lore raw

Re: [PATCH net v3] ibmveth: set correct gso_size and gso_type

From: Thomas Falcon <[email protected]>
Date: Sat, 10 Dec 2016 12:39:48 -0600

Quoted 4 lines

v3: include a check for non-zero mss when calculating gso_segs

v2: calculate gso_segs after Eric Dumazet's comments on the earlier patch
and make sure everyone is included on CC

I already applied v1 which made it all the way even to Linus's tree. So you'll have to send me relative fixups if there are things to fix or change since v1.

You must always generate patches against the current 'net' tree.

#15 lore raw

Re: [PATCH net v3] ibmveth: set correct gso_size and gso_type

Quoted 5 lines · David Miller

From: Thomas Falcon <[email protected]>
Date: Sat, 10 Dec 2016 12:39:48 -0600

Quoted 2 lines

v3: include a check for non-zero mss when calculating gso_segs

Quoted 8 lines
Quoted 2 lines

v2: calculate gso_segs after Eric Dumazet's comments on the earlier patch
and make sure everyone is included on CC

I already applied v1 which made it all the way even to Linus's tree. So you'll have to send me relative fixups if there are things to fix or change since v1.

You must always generate patches against the current 'net' tree.

Sorry about that. Thank you for applying it on short notice. I agree that using the TCP checksum field is not ideal, but it was a compromise with the VIOS team. Hopefully, there will be a better way in the future.

Thanks again,

Tom

maintainer Applied
#16 lore raw

Re: [PATCH] ibmveth: set correct gso_size and gso_type

In reply to Thomas Falcon

From: Thomas Falcon <[email protected]>
Date: Thu, 8 Dec 2016 16:40:03 -0600

Quoted 22 lines

This patch is based on an earlier one submitted
by Jon Maxwell with the following commit message:

"We recently encountered a bug where a few customers using ibmveth on the same LPAR hit an issue where a TCP session hung when large receive was enabled. Closer analysis revealed that the session was stuck because the one side was advertising a zero window repeatedly.

We narrowed this down to the fact the ibmveth driver did not set gso_size which is translated by TCP into the MSS later up the stack. The MSS is used to calculate the TCP window size and as that was abnormally large, it was calculating a zero window, even although the sockets receive buffer was completely empty."

We rely on the Virtual I/O Server partition in a pseries environment to provide the MSS through the TCP header checksum field. The stipulation is that users should not disable checksum offloading if rx packet aggregation is enabled through VIOS.

Some firmware offerings provide the MSS in the RX buffer. This is signalled by a bit in the RX queue descriptor.

Quoted 6 lines

Applied, although mis-using the TCP checksum field for this is kind of bogus. I'm surprised there wasn't some other place you could stick this value, which wouldn't modify the packet contents.