ixgbe: Handle extended IPv6 headers in tx path
Subsystems (2)
PATCH v2 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. Thanks to Tom Herbert for noticing this problem. 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
--- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +19 -0
@@ -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,23 @@ 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 + +sizeof (struct ipv6hdr ) - + skb->data, + &l4_hdr, &frag_off); +if (rc <0 ) { +if (unlikely (net_ratelimit ())) { +dev_warn (tx_ring->dev, +"ipv6_skip_exthdr returned %d\n" , + rc); + } +break ; + } +if (frag_off) + l4_hdr =0 ;break ;default :if (unlikely (net_ratelimit ())) {
PATCH v2 1/1 ixgbe: Handle extended IPv6 headers in tx path
Quoted 44 lines · Mark D Rustad
Check for and handle IPv6 extended headers so that tx checksum offload can be done. Thanks to Tom Herbert for noticing this problem. Thanks to Alexander Duyck for recognizing problems with the first version of this patch.
Reported-by Tom Herbert <[email protected]>Signed-off-by Mark Rustad <[email protected]>---
Changed in V2:
- Useipv6_skip_exthdrinstead ofipv6_find_hdr
- Move code into L3 processing and avoid any possible loop
- Handle encapsulated IPv6 extended headers correctly--- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +12
-0@@ -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,23 @@ 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 + +sizeof (struct ipv6hdr ) - + skb->data, + &l4_hdr, &frag_off); +if (rc <0 ) { +if (unlikely (net_ratelimit ())) { + dev_warn(tx_ring->dev,
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, · line 7276
Quoted 10 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +7
-0+"ipv6_skip_exthdr returned %d\n" , + rc); + } +break ; + } +if (frag_off) + l4_hdr =0 ;break ;default :if (unlikely (net_ratelimit ())) {
Failures should not result in dev_warn, just call skb_checksum_help instead. Ignoring CHECKSUM_PARTIAL is guaranteed to be sending a bad checksum!
The patch parses the extension headers and verifies the protocol is supported (TCP, UDP, SCTP). But how does the device know the offset of the transport header to perform the checksum? Is the device capable of parsing the extension headers on transmit?
Thanks,
Tom
PATCH v2 1/1 ixgbe: Handle extended IPv6 headers in tx path
Quoted 51 lines · Tom Herbert
Quoted 50 lines · Mark D Rustad
Check for and handle IPv6 extended headers so that tx checksum offload can be done. Thanks to Tom Herbert for noticing this problem. Thanks to Alexander Duyck for recognizing problems with the first version of this patch.
Reported-by Tom Herbert <[email protected]>Signed-off-by Mark Rustad <[email protected]>---
Changed in V2:
- Useipv6_skip_exthdrinstead ofipv6_find_hdr
- Move code into L3 processing and avoid any possible loop
- Handle encapsulated IPv6 extended headers correctly--- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +19
-0@@ -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,23 @@ 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 + +sizeof (struct ipv6hdr ) - + skb->data, + &l4_hdr, &frag_off); +if (rc <0 ) { +if (unlikely (net_ratelimit ())) { +dev_warn (tx_ring->dev, +"ipv6_skip_exthdr returned %d\n" , + rc); + } +break ; + } +if (frag_off) + l4_hdr =0 ;
Quoted 8 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, · line 7276
Quoted 4 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +0
-0break ;default :if (unlikely (net_ratelimit ())) {Failures should not result in
dev_warn, just callskb_checksum_helpinstead. IgnoringCHECKSUM_PARTIALis guaranteed to be sending a bad checksum!
The problem is there are scenarios here where a checksum shouldn't be computed. If for example the frame is fragmented we should be displaying some sort of error message and not computing the checksum because no matter what we compute it isn't going to be valid.
However I can see your point. At least then this driver would be forward compatible in the event of an offload request for something that isn't supported by the hardware.
Quoted 4 lines
The patch parses the extension headers and verifies the protocol is supported (TCP, UDP, SCTP). But how does the device know the offset of the transport header to perform the checksum? Is the device capable of parsing the extension headers on transmit?
The device doesn't need to parse the extension headers. All the device needs is a pointer to the IPv6 header and the L4 header in order to compute and place the L4 checksum. That is the data that is being placed in the descriptor by the tx_csum function.
- Alex
PATCH v2 1/1 ixgbe: Handle extended IPv6 headers in tx path
Quoted 61 lines · Alexander Duyck
Quoted 51 lines · Tom Herbert
Quoted 50 lines · Mark D Rustad
Check for and handle IPv6 extended headers so that tx checksum offload can be done. Thanks to Tom Herbert for noticing this problem. Thanks to Alexander Duyck for recognizing problems with the first version of this patch.
Reported-by Tom Herbert <[email protected]>Signed-off-by Mark Rustad <[email protected]>---
Changed in V2:
- Useipv6_skip_exthdrinstead ofipv6_find_hdr
- Move code into L3 processing and avoid any possible loop
- Handle encapsulated IPv6 extended headers correctly--- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +19
-0@@ -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,23 @@ 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 + +sizeof (struct ipv6hdr ) - + skb->data, + &l4_hdr, &frag_off); +if (rc <0 ) { +if (unlikely (net_ratelimit ())) { +dev_warn (tx_ring->dev, +"ipv6_skip_exthdr returned %d\n" , + rc); + } +break ; + } +if (frag_off) + l4_hdr =0 ;Quoted 8 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, · line 7276
Quoted 4 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +0
-0break ;default :if (unlikely (net_ratelimit ())) {Failures should not result in
dev_warn, just callskb_checksum_helpinstead. IgnoringCHECKSUM_PARTIALis guaranteed to be sending a bad checksum!
Quoted 5 lines
The problem is there are scenarios here where a checksum shouldn't be computed. If for example the frame is fragmented we should be displaying some sort of error message and not computing the checksum because no matter what we compute it isn't going to be valid.
If the stack is sending fragments with CHECKSUM_PARTIAL set then that is a bug higher in the stack-- the driver does not need to worry about that.
PATCH v2 1/1 ixgbe: Handle extended IPv6 headers in tx path
Quoted 63 lines · Tom Herbert
Quoted 61 lines · Alexander Duyck
Quoted 59 lines · Tom Herbert
Quoted 44 lines · Mark D Rustad
Check for and handle IPv6 extended headers so that tx checksum offload can be done. Thanks to Tom Herbert for noticing this problem. Thanks to Alexander Duyck for recognizing problems with the first version of this patch.
Reported-by Tom Herbert <[email protected]>Signed-off-by Mark Rustad <[email protected]>---
Changed in V2:
- Useipv6_skip_exthdrinstead ofipv6_find_hdr
- Move code into L3 processing and avoid any possible loop
- Handle encapsulated IPv6 extended headers correctly--- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +12
-0@@ -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,23 @@ 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 + +sizeof (struct ipv6hdr ) - + skb->data, + &l4_hdr, &frag_off); +if (rc <0 ) { +if (unlikely (net_ratelimit ())) { + dev_warn(tx_ring->dev,drivers/net/ethernet/intel/ixgbe/ixgbe_main.c static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, · line 7276
Quoted 10 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +7
-0+"ipv6_skip_exthdr returned %d\n" , + rc); + } +break ; + } +if (frag_off) + l4_hdr =0 ;break ;default :if (unlikely (net_ratelimit ())) {Failures should not result in
dev_warn, just callskb_checksum_helpinstead. IgnoringCHECKSUM_PARTIALis guaranteed to be sending a bad checksum!
Quoted 8 lines
Quoted 5 lines
The problem is there are scenarios here where a checksum shouldn't be computed. If for example the frame is fragmented we should be displaying some sort of error message and not computing the checksum because no matter what we compute it isn't going to be valid.
If the stack is sending fragments with
CHECKSUM_PARTIALset then that is a bug higher in the stack-- the driver does not need to worry about that.
Right, but it is still something that needs to get fixed. By triggering the dev_warn here we at least create visibility that something has gone horribly wrong.
- Alex
Rustad
PATCH v2 1/1 ixgbe: Handle extended IPv6 headers in tx path
Quoted 8 lines · Alexander Duyck
Quoted 7 lines · Tom Herbert
Quoted 5 lines · Alexander Duyck
Quoted 4 lines · Tom Herbert
Failures should not result in
dev_warn, just callskb_checksum_helpinstead. IgnoringCHECKSUM_PARTIALis guaranteed to be sending a bad checksum!
But calling skb_checksum_help I think is a false sense of security. In the case of fragmentation for example, it can't possibly help. I'd rather find out that it is failing and figure out what to do about it.
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
The problem is there are scenarios here where a checksum shouldn't be computed. If for example the frame is fragmented we should be displaying some sort of error message and not computing the checksum because no matter what we compute it isn't going to be valid.
If the stack is sending fragments with
CHECKSUM_PARTIALset then that is a bug higher in the stack-- the driver does not need to worry about that.Right, but it is still something that needs to get fixed. By triggering the
dev_warnhere we at least create visibility that something has gone horribly wrong.
Right. It needs to be fixed one way or another. In some cases it would be the stack that needs a fix, in some cases a call to skb_checksum_help might be needed or maybe something else.
--
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/20151117/a6ec251f/attachment-0001.asc>
PATCH v2 1/1 ixgbe: Handle extended IPv6 headers in tx path
Quoted 5 lines · Mark D
Quoted 3 lines · Alexander Duyck
Quoted 2 lines · Tom Herbert
On Tue, Nov 17, 2015 at 8:41 AM, Alexander Duyck
<[email protected]> wrote:
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · Tom Herbert
Quoted 4 lines
Failures should not result in
dev_warn, just callskb_checksum_helpinstead. IgnoringCHECKSUM_PARTIALis guaranteed to be sending a bad checksum!But calling
skb_checksum_helpI think is a false sense of security. In the case of fragmentation for example, it can't possibly help. I'd rather find out that it is failing and figure out what to do about it.
The _only_ thing that is authoritative in checksum offload are the values of csum_start and csum_offset. If a driver ensures that checksum is properly calculated from start and set at the offset, then driver is implementing correct behavior and has no additional requirements as far as the stack is concerned. Neither does the stack does not care if this is done with offload to the device or by calling skb_checksum_help.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
The problem is there are scenarios here where a checksum shouldn't be computed. If for example the frame is fragmented we should be displaying some sort of error message and not computing the checksum because no matter what we compute it isn't going to be valid.
If the stack is sending fragments with
CHECKSUM_PARTIALset then that is a bug higher in the stack-- the driver does not need to worry about that.
Quoted 5 lines
Quoted 3 lines
Right, but it is still something that needs to get fixed. By triggering the
dev_warnhere we at least create visibility that something has gone horribly wrong.Right. It needs to be fixed one way or another. In some cases it would be the stack that needs a fix, in some cases a call to
skb_checksum_helpmight be needed or maybe something else.
Are you actually seeing fragments with CHECKSUM_PARTIAL set?
Tom
Rustad
PATCH v2 1/1 ixgbe: Handle extended IPv6 headers in tx path
Quoted 16 lines · Tom Herbert
The _only_ thing that is authoritative in checksum offload are the values of
csum_startandcsum_offset. If a driver ensures that checksum is properly calculated from start and set at the offset, then driver is implementing correct behavior and has no additional requirements as far as the stack is concerned. Neither does the stack does not care if this is done with offload to the device or by callingskb_checksum_help.Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
The problem is there are scenarios here where a checksum shouldn't be computed. If for example the frame is fragmented we should be displaying some sort of error message and not computing the checksum because no matter what we compute it isn't going to be valid.
If the stack is sending fragments with
CHECKSUM_PARTIALset then that is a bug higher in the stack-- the driver does not need to worry about that.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Right, but it is still something that needs to get fixed. By triggering the
dev_warnhere we at least create visibility that something has gone horribly wrong.Right. It needs to be fixed one way or another. In some cases it would be the stack that needs a fix, in some cases a call to
skb_checksum_helpmight be needed or maybe something else.Are you actually seeing fragments with
CHECKSUM_PARTIALset?
I haven't seen any yet and I don't expect to. But the dev_warn that was in this area prior to the current patch was triggered when I first sent IPv6 packets with extended headers. Yes, the checksum was not computed, but there also was a warning in the log. Likewise when I didn't have the encapsulation working for this case, when I tried it I got a warning in the log. So it does indicate when things are broken and so is useful. Of course these were fixed by the driver patch because they were the result of deficiencies in the driver, which you first spotted by code inspection.
--
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/20151117/9596ceba/attachment.asc>
PATCH v2 1/1 ixgbe: Handle extended IPv6 headers in tx path
Quoted 22 lines · Mark D
Quoted 20 lines · Tom Herbert
The _only_ thing that is authoritative in checksum offload are the values of
csum_startandcsum_offset. If a driver ensures that checksum is properly calculated from start and set at the offset, then driver is implementing correct behavior and has no additional requirements as far as the stack is concerned. Neither does the stack does not care if this is done with offload to the device or by callingskb_checksum_help.Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
The problem is there are scenarios here where a checksum shouldn't be computed. If for example the frame is fragmented we should be displaying some sort of error message and not computing the checksum because no matter what we compute it isn't going to be valid.
If the stack is sending fragments with
CHECKSUM_PARTIALset then that is a bug higher in the stack-- the driver does not need to worry about that.Right, but it is still something that needs to get fixed. By triggering the
dev_warnhere we at least create visibility that something has gone horribly wrong.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Right. It needs to be fixed one way or another. In some cases it would be the stack that needs a fix, in some cases a call to
skb_checksum_helpmight be needed or maybe something else.Are you actually seeing fragments with
CHECKSUM_PARTIALset?I haven't seen any yet and I don't expect to. But the
dev_warnthat was in this area prior to the current patch was triggered when I first sent IPv6 packets with extended headers. Yes, the checksum was not computed, but there also was a warning in the log. Likewise when I didn't have the encapsulation working for this case, when I tried it I got a warning in the log. So it does indicate when things are broken and so is useful. Of course these were fixed by the driver patch because they were the result of deficiencies in the driver, which you first spotted by code inspection.
This does not entirely fix the problem though. It is a valid use case that someone can send an UDP packet with an extension header that is unknown to ipv6_skip_exthdr. The driver can do a dev_warn if it wants to in this case I suppose, but sending out the packet without setting the checksum is incorrect. The rule is simple: if the drive cannot offload a checksum then call skb_checksum_help-- this as a default can never make matters worse.
Tom
Quoted 2 lines
--
Mark Rustad, Networking Division, Intel Corporation
Rustad
PATCH v2 1/1 ixgbe: Handle extended IPv6 headers in tx path
Quoted 7 lines · Tom Herbert
This does not entirely fix the problem though. It is a valid use case that someone can send an UDP packet with an extension header that is unknown to
ipv6_skip_exthdr. The driver can do adev_warnif it wants to in this case I suppose, but sending out the packet without setting the checksum is incorrect. The rule is simple: if the drive cannot offload a checksum then call skb_checksum_help-- this as a default can never make matters worse.
I suppose there could be both a message and the call to skb_checksum_help. The only drawback to that is a rate-limited message spamming the log that might go unnoticed for some time because things "work". I don't know what the security wonks would think about unrecognized extended headers being generated by an application. Hmm. Is it really possible to use an extended header that the kernel doesn't know about? If the kernel knows about it, then ipv6_skip_exthdr should work.
If the consensus is to add the call, I don't have a strong objection, I just have some reservations about it.
--
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/20151117/795243e6/attachment.asc>