Skip to contentSkip to conversation

ixgbe: Handle extended IPv6 headers in tx path

PATCH Superseded Mark D Rustad 4 participants 4 messages Nov 17, 2015 – Nov 18, 2015

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 ixgbe: Handle extended IPv6 headers in tx path

Check for and handle IPv6 extended headers so that tx checksum offload can be done. Also use skb_checksum_help for unexpected cases. Thanks to Tom Herbert for noticing these problems. Thanks to Alexander Duyck for recognizing problems with the first version of this patch.

---
Changed in V2:
- Use ipv6_skip_exthdr instead of ipv6_find_hdr
- Move code into L3 processing and avoid any possible loop
- Handle encapsulated IPv6 extended headers correctly Changed in V3:
- Call skb_checksum_help for unexpected cases
- Move unlikely() calls to more appropriate places
- Reaarange terms in call to ipv6_skip_exthdr to reduce line count
- Combined 2 unlikely error cases into one

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |   23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +22 -1
index 1ffbe85eab7b..c058ce616b28 100644
@@ -7229,6 +7229,8 @@ static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
 			struct tcphdr *tcphdr;
 			u8 *raw;
 		} transport_hdr;
+		__be16 frag_off;
+		int rc;
 
 		if (skb->encapsulation) {
 			network_hdr.raw = skb_inner_network_header(skb);
@@ -7252,6 +7254,21 @@ static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
 		case 6:
 			vlan_macip_lens |= transport_hdr.raw - network_hdr.raw;
 			l4_hdr = network_hdr.ipv6->nexthdr;
+			if (likely((transport_hdr.raw - network_hdr.raw) ==
+				   sizeof(struct ipv6hdr)))
+				break;
+			rc = ipv6_skip_exthdr(skb, network_hdr.raw - skb->data +
+						   sizeof(struct ipv6hdr),
+					      &l4_hdr, &frag_off);
+			if (unlikely(rc < 0 || frag_off)) {
+				if (net_ratelimit()) {
+					dev_warn(tx_ring->dev,
+						 "ipv6_skip_exthdr returns %d\n",
+						 rc);
+				}
+				skb_checksum_help(skb);
+				goto no_csum;
+			}
 			break;
 		default:
 			if (unlikely(net_ratelimit())) {
@@ -7259,6 +7276,8 @@ static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
 					 "partial checksum but version=%d\n",
 					 network_hdr.ipv4->version);
 			}
+			skb_checksum_help(skb);
+			goto no_csum;
 		}
 
 		switch (l4_hdr) {
@@ -7282,13 +7301,15 @@ static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
 				 "partial checksum but l4 proto=%x!\n",
 				 l4_hdr);
 			}
-			break;
+			skb_checksum_help(skb);
+			goto no_csum;
 		}
 
 		/* update TX checksum flag */
 		first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
 	}
 
+no_csum:
 	/* vlan_macip_lens: MACLEN, VLAN tag */
 	vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
 
#1 lore raw

PATCH v3 1/1 ixgbe: Handle extended IPv6 headers in tx path

Quoted 40 lines · Mark D Rustad

Check for and handle IPv6 extended headers so that tx checksum offload can be done. Also use skb_checksum_help for unexpected cases. Thanks to Tom Herbert for noticing these problems. Thanks to Alexander Duyck for recognizing problems with the first version of this patch.

---
Changed in V2:
- Use ipv6_skip_exthdr instead of ipv6_find_hdr
- Move code into L3 processing and avoid any possible loop
- Handle encapsulated IPv6 extended headers correctly Changed in V3:
- Call skb_checksum_help for unexpected cases
- Move unlikely() calls to more appropriate places
- Reaarange terms in call to ipv6_skip_exthdr to reduce line count
- Combined 2 unlikely error cases into one

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |   23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +3 -0
index 1ffbe85eab7b..c058ce616b28 100644
@@ -7229,6 +7229,8 @@ static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
                        struct tcphdr *tcphdr;
                        u8 *raw;
                } transport_hdr;
+               __be16 frag_off;
+               int rc;
 
                if (skb->encapsulation) {
                        network_hdr.raw = skb_inner_network_header(skb);
@@ -7252,6 +7254,21 @@ static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
                case 6:
                        vlan_macip_lens |= transport_hdr.raw - network_hdr.raw;
                        l4_hdr = network_hdr.ipv6->nexthdr;
+                       if (likely((transport_hdr.raw - network_hdr.raw) ==

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, · line 7267

Quoted 10 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +10 -0
+                                  sizeof(struct ipv6hdr)))
+                               break;
+                       rc = ipv6_skip_exthdr(skb, network_hdr.raw - skb->data +
+                                                  sizeof(struct ipv6hdr),
+                                             &l4_hdr, &frag_off);
+                       if (unlikely(rc < 0 || frag_off)) {
+                               if (net_ratelimit()) {
+                                       dev_warn(tx_ring->dev,
+                                                "ipv6_skip_exthdr returns %d\n",
+                                                rc);

Now that I am seeing this it seems like this is getting kind of clunky. Perhaps we should look at coalescing all of these warning messages into one message at the end of the l4_hdr section.

Also it seems like you could ignore the rc value and just focus on the frag_off value. If the function fails the l4_hdr will remain the extended header value and fall into the error path in the l4_hdr switch section below. You could probably use NEXTHDR_FRAGMENT as the l4_hdr value if frag_off is non-zero.

Quoted 8 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +4 -0
+                               }
+                               skb_checksum_help(skb);
+                               goto no_csum;
+                       }
                        break;
                default:
                        if (unlikely(net_ratelimit())) {

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, · line 7281

Quoted 6 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +2 -0
@@ -7259,6 +7276,8 @@ static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
                                         "partial checksum but version=%d\n",
                                         network_hdr.ipv4->version);
                        }
+                       skb_checksum_help(skb);
+                       goto no_csum;
                }

Perhaps this can be coalesced into one warning message below in the l4_hdr check section. The l4_hdr won't be updated anyway so it will fall through to the error case there.

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, · line 7303

Quoted 6 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +0 -0
                switch (l4_hdr) {
@@ -7282,13 +7301,15 @@ static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
                                 "partial checksum but l4 proto=%x!\n",
                                 l4_hdr);
                        }

The bit up here could probably be updated to include the L3 protocol type. With the L3 and L4 protocol values you should be able to get the same amount of error data as you could with the previous messages. Basically we just want to avoid adding too much unnecessary code to handle exceptions that aren't likely to happen.

Quoted 14 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +3 -1
-                       break;
+                       skb_checksum_help(skb);
+                       goto no_csum;
                }
 
                /* update TX checksum flag */
                first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
        }
 
+no_csum:
        /* vlan_macip_lens: MACLEN, VLAN tag */
        vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
 
#2 lore raw

PATCH v3 1/1 ixgbe: Handle extended IPv6 headers in tx path

Quoted 9 lines · Alexander Duyck

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, · line 7267

Quoted 8 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +8 -0
+                       rc = ipv6_skip_exthdr(skb, network_hdr.raw - skb->data +
+                                                  sizeof(struct ipv6hdr),
+                                             &l4_hdr, &frag_off);
+                       if (unlikely(rc < 0 || frag_off)) {
+                               if (net_ratelimit()) {
+                                       dev_warn(tx_ring->dev,
+                                                "ipv6_skip_exthdr returns %d\n",
+                                                rc);
Quoted 6 lines

Now that I am seeing this it seems like this is getting kind of clunky. Perhaps we should look at coalescing all of these warning messages into one message at the end of the l4_hdr section.

Also it seems like you could ignore the rc value and just focus on the frag_off value.

Almost. If rc < 0, then frag_off will not have been assigned to. If I initialize frag_off to 0, then rc can be completely eliminated as you suggest.

Quoted 4 lines

If the function fails the l4_hdr will remain the
extended header value and fall into the error path in the l4_hdr switch section below. You could probably use NEXTHDR_FRAGMENT as the l4_hdr value if frag_off is non-zero.

Clever. That does get a bit of information out and coalesce the error cases nicely. I'll try that out.

--
Mark Rustad, Networking Division, Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 841 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20151118/7776b41b/attachment-0001.asc>

#3 lore raw

PATCH v3 1/1 ixgbe: Handle extended IPv6 headers in tx path

In reply to Alexander Duyck
Quoted 47 lines · Alexander Duyck
Quoted 46 lines · Mark D Rustad

Check for and handle IPv6 extended headers so that tx checksum offload can be done. Also use skb_checksum_help for unexpected cases. Thanks to Tom Herbert for noticing these problems. Thanks to Alexander Duyck for recognizing problems with the first version of this patch.

---
Changed in V2:
- Use ipv6_skip_exthdr instead of ipv6_find_hdr
- Move code into L3 processing and avoid any possible loop
- Handle encapsulated IPv6 extended headers correctly Changed in V3:
- Call skb_checksum_help for unexpected cases
- Move unlikely() calls to more appropriate places
- Reaarange terms in call to ipv6_skip_exthdr to reduce line count
- Combined 2 unlikely error cases into one

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |   23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +9 -0
index 1ffbe85eab7b..c058ce616b28 100644
@@ -7229,6 +7229,8 @@ static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
                        struct tcphdr *tcphdr;
                        u8 *raw;
                } transport_hdr;
+               __be16 frag_off;
+               int rc;
 
                if (skb->encapsulation) {
                        network_hdr.raw = skb_inner_network_header(skb);
@@ -7252,6 +7254,21 @@ static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
                case 6:
                        vlan_macip_lens |= transport_hdr.raw - network_hdr.raw;
                        l4_hdr = network_hdr.ipv6->nexthdr;
+                       if (likely((transport_hdr.raw - network_hdr.raw) ==
+                                  sizeof(struct ipv6hdr)))
+                               break;
+                       rc = ipv6_skip_exthdr(skb, network_hdr.raw - skb->data +
+                                                  sizeof(struct ipv6hdr),
+                                             &l4_hdr, &frag_off);
+                       if (unlikely(rc < 0 || frag_off)) {
Quoted 9 lines

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, · line 7267

Quoted 4 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +4 -0
+                               if (net_ratelimit()) {
+                                       dev_warn(tx_ring->dev,
+                                                "ipv6_skip_exthdr returns %d\n",
+                                                rc);

Now that I am seeing this it seems like this is getting kind of clunky. Perhaps we should look at coalescing all of these warning messages into one message at the end of the l4_hdr section.

TBH, almost all of this complexity would go away if the device implemented NETIF_F_HW_CSUM. Since the NIC already seems capable of taking a variable value for the L4 hdr offset, it seems like this is already close to being able to that. Probably, we just need to disable the pseudo header calculation being done in the NIC. I suspect the offset still must either be 16 or 6 (corresponding to TCP or UDP checksum offsets), but even with this limitation NETIF_F_HW_CSUM is a win.

Tom