Skip to contentSkip to conversation

openvswitch: Fix setting ipv6 fields causing hw csum failure

PATCH Superseded Paul Blakey 3 participants 4 messages Feb 20, 2022 – Feb 22, 2022

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 openvswitch: Fix setting ipv6 fields causing hw csum failure

Ipv6 ttl, label and tos fields are modified without first pulling/pushing the ipv6 header, which would have updated the hw csum (if available). This might cause csum validation when sending the packet to the stack, as can be seen in the trace below.

Fix this by updating skb->csum if available.

Trace resulted by ipv6 ttl dec and then sending packet to conntrack [actions: set(ipv6(hlimit=63)),ct(zone=99)]:

[295241.900063] s_pf0vf2: hw csum failure
[295241.923191] Call Trace:
[295241.925728]  <IRQ>
[295241.927836]  dump_stack+0x5c/0x80
[295241.931240]  __skb_checksum_complete+0xac/0xc0
[295241.935778]  nf_conntrack_tcp_packet+0x398/0xba0 [nf_conntrack]
[295241.953030]  nf_conntrack_in+0x498/0x5e0 [nf_conntrack]
[295241.958344]  __ovs_ct_lookup+0xac/0x860 [openvswitch]
[295241.968532]  ovs_ct_execute+0x4a7/0x7c0 [openvswitch]
[295241.979167]  do_execute_actions+0x54a/0xaa0 [openvswitch]
[295242.001482]  ovs_execute_actions+0x48/0x100 [openvswitch]
[295242.006966]  ovs_dp_process_packet+0x96/0x1d0 [openvswitch]
[295242.012626]  ovs_vport_receive+0x6c/0xc0 [openvswitch]
[295242.028763]  netdev_frame_hook+0xc0/0x180 [openvswitch]
[295242.034074]  __netif_receive_skb_core+0x2ca/0xcb0
[295242.047498]  netif_receive_skb_internal+0x3e/0xc0
[295242.052291]  napi_gro_receive+0xba/0xe0
[295242.056231]  mlx5e_handle_rx_cqe_mpwrq_rep+0x12b/0x250 [mlx5_core]
[295242.062513]  mlx5e_poll_rx_cq+0xa0f/0xa30 [mlx5_core]
[295242.067669]  mlx5e_napi_poll+0xe1/0x6b0 [mlx5_core]
[295242.077958]  net_rx_action+0x149/0x3b0
[295242.086762]  __do_softirq+0xd7/0x2d6
[295242.090427]  irq_exit+0xf7/0x100
[295242.093748]  do_IRQ+0x7f/0xd0
[295242.096806]  common_interrupt+0xf/0xf
[295242.100559]  </IRQ>
[295242.102750] RIP: 0033:0x7f9022e88cbd
[295242.125246] RSP: 002b:00007f9022282b20 EFLAGS: 00000246 ORIG_RAX: ffffffffffffffda
[295242.132900] RAX: 0000000000000005 RBX: 0000000000000010 RCX: 0000000000000000
[295242.140120] RDX: 00007f9022282ba8 RSI: 00007f9022282a30 RDI: 00007f9014005c30
[295242.147337] RBP: 00007f9014014d60 R08: 0000000000000020 R09: 00007f90254a8340
[295242.154557] R10: 00007f9022282a28 R11: 0000000000000246 R12: 0000000000000000
[295242.161775] R13: 00007f902308c000 R14: 000000000000002b R15: 00007f9022b71f40
Fixes 3fdbd1ce11e5 ("openvswitch: add ipv6 'set' action")

---
Changelog:
v4->v3:
Use new helper csum_block_replace
v2->v3:
Use u8 instead of __u8
Fix sparse warnings on conversions
v1->v2:
Replaced push pull rcsum checksum calc with actual checksum calc

 include/net/checksum.h    |  7 ++++++
 net/openvswitch/actions.c | 47 ++++++++++++++++++++++++++++++++-------
 2 files changed, 46 insertions(+), 8 deletions(-)
include/net/checksum.h +7 -0
index 5218041e5c8f..ce39e47b2881 100644
@@ -106,6 +106,12 @@ csum_block_sub(__wsum csum, __wsum csum2, int offset)
 	return csum_block_add(csum, ~csum2, offset);
 }
 
+static inline __wsum
+csum_block_replace(__wsum csum, __wsum old, __wsum new, int offset)
+{
+	return csum_block_add(csum_block_sub(csum, old, offset), new, offset);
+}
+
 static inline __wsum csum_unfold(__sum16 n)
 {
 	return (__force __wsum)n;
@@ -184,4 +190,5 @@ static inline __wsum wsum_negate(__wsum val)
 {
 	return (__force __wsum)-((__force u32)val);
 }
+
 #endif
net/openvswitch/actions.c +39 -8

69 lines not on this page · raw message

Signature · 1 line
2.30.1
#1 lore raw

From: Paul Blakey

Quoted 9 lines

Sent: 20 February 2022 13:21

Ipv6 ttl, label and tos fields are modified without first pulling/pushing the ipv6 header, which would have updated the hw csum (if available). This might cause csum validation when sending the packet to the stack, as can be seen in the trace below.

Fix this by updating skb->csum if available.

...

include/net/checksum.h csum_block_sub(__wsum csum, __wsum csum2, int offset) · line 113

Quoted 5 lines
include/net/checksum.h +5 -0
+static inline __wsum
+csum_block_replace(__wsum csum, __wsum old, __wsum new, int offset)
+{
+	return csum_block_add(csum_block_sub(csum, old, offset), new, offset);
+}

That look computationally OTT for sub 32bit adjustments.

It ought to be enough to do:

	return csum_add(old_csum, 0xf0000fff + new - old);

Although it will need 'tweaking' for odd aligned 24bit values.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#2 lore raw
Quoted 22 lines · David Laight

From: Paul Blakey

Quoted 9 lines

Sent: 20 February 2022 13:21

Ipv6 ttl, label and tos fields are modified without first pulling/pushing the ipv6 header, which would have updated the hw csum (if available). This might cause csum validation when sending the packet to the stack, as can be seen in the trace below.

Fix this by updating skb->csum if available.

...

include/net/checksum.h csum_block_sub(__wsum csum, __wsum csum2, int offset) · line 113

Quoted 5 lines
include/net/checksum.h +5 -0
+static inline __wsum
+csum_block_replace(__wsum csum, __wsum old, __wsum new, int offset)
+{
+	return csum_block_add(csum_block_sub(csum, old, offset), new, offset);
+}

That look computationally OTT for sub 32bit adjustments.

It ought to be enough to do:

	return csum_add(old_csum, 0xf0000fff + new - old);
Quoted 9 lines

Although it will need 'tweaking' for odd aligned 24bit values.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

I'm not comfortable with manually implementing some low-level bit fideling checksum calculation, while covering all cases. And as you said it also doesnt have the offset param (odd aligned). The same could be said about csum_block_add()/sub(), replace() just uses them. I think the csum operations are more readable and should be inlined/optimize, so can we do it the readable way, and then, if needed, optimize it?

maintainer
#3 lore raw
In reply to Paul Blakey

You'll need to rebase, the patch which made everything force inlined got merged.

include/net/checksum.h csum_block_sub(__wsum csum, __wsum csum2, int offset) · line 112

Quoted 4 lines · On Sun, 20 Feb 2022 15:21:14 +0200 Paul Blakey wrote:
include/net/checksum.h +4 -0
+static inline __wsum
+csum_block_replace(__wsum csum, __wsum old, __wsum new, int offset)
+{
+	return csum_block_add(csum_block_sub(csum, old, offset), new, offset);

Why still _block? Since the arguments are pre-shifted we should be able to subtract and add the entire thing, and the math will work out. Obviously you'd need to shift by the offset in the word, not in a byte in the caller.

include/net/checksum.h static inline __wsum wsum_negate(__wsum val) · line 193

Quoted 10 lines
include/net/checksum.h +3 -0
+}
+
 static inline __wsum csum_unfold(__sum16 n)
 {
 	return (__force __wsum)n;
@@ -184,4 +190,5 @@ static inline __wsum wsum_negate(__wsum val)
 {
 	return (__force __wsum)-((__force u32)val);
 }
+

Spurious?

Quoted 1 line
(quoted diff) +0 -0
 #endif