xfrm: some fixes for GSO with SW crypto
Subsystems (3)
cover xfrm: some fixes for GSO with SW crypto
This series fixes a few issues with GSO. Some recent patches made the incorrect assumption that GSO is only used by offload. The first two patches in this series restores the old behavior.
The final patch is in the UDP GSO code, but fixes an issue with IPsec that is currently masked by the lack of GSO for SW crypto. With GSO, VXLAN over IPsec doesn't get checksummed.
Sabrina Dubroca (3):
xfrm: restore GSO for SW crypto
Revert "xfrm: Remove unneeded device check from validate_xmit_xfrm"
udp: also consider secpath when evaluating ipsec use for checksumming
net/ipv4/udp_offload.c | 2 +- net/xfrm/xfrm_device.c | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-)
Signature · 1 line
2.50.0
PATCH 1/3 xfrm: restore GSO for SW crypto
Commit 49431af6c4ef incorrectly assumes that the GSO path is only used by HW offload, but it's also useful for SW crypto.
This patch re-enables GSO for SW crypto. It's not an exact revert to preserve the other changes made to xfrm_dev_offload_ok afterwards, but it reverts all of its effects.
--- net/xfrm/xfrm_device.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/xfrm/xfrm_device.c +7 -2
@@ -415,10 +415,12 @@ bool xfrm_dev_offload_ok(struct sk_buff *skb, struct xfrm_state *x)struct net_device *dev = x->xso.dev;bool check_tunnel_size; -if (x->xso.type ==XFRM_DEV_OFFLOAD_UNSPECIFIED ) +if (!x->type_offload || + (x->xso.type ==XFRM_DEV_OFFLOAD_UNSPECIFIED && x->encap))return false; -if ((dev ==xfrm_dst_path (dst)->dev) && !xdst->child->xfrm) { +if ((!dev || dev ==xfrm_dst_path (dst)->dev) && + !xdst->child->xfrm) { mtu =xfrm_state_mtu (x, xdst->child_mtu_cached);if (skb->len <= mtu) goto ok;
@@ -430,6 +432,9 @@ bool xfrm_dev_offload_ok(struct sk_buff *skb, struct xfrm_state *x)return false; ok: +if (!dev) +return true; + check_tunnel_size = x->xso.type ==XFRM_DEV_OFFLOAD_PACKET && x->props.mode ==XFRM_MODE_TUNNEL ;switch (x->props.family) {
Signature · 1 line
2.50.0
Re: [PATCH ipsec 1/3] xfrm: restore GSO for SW crypto
Quoted 7 lines · Sabrina Dubroca
Commit
49431af6c4efincorrectly assumes that the GSO path is only used by HW offload, but it's also useful for SW crypto.This patch re-enables GSO for SW crypto. It's not an exact revert to preserve the other changes made to
xfrm_dev_offload_okafterwards, but it reverts all of its effects.
Quoted 6 lines
Fixes 49431af6c4ef ("xfrm: rely on XFRM offload")Signed-off-by Sabrina Dubroca <[email protected]>--- net/xfrm/xfrm_device.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
Thanks,
Re: [PATCH ipsec 1/3] xfrm: restore GSO for SW crypto
In reply to Sabrina DubrocaQuoted 9 lines · Sabrina Dubroca
Commit
49431af6c4efincorrectly assumes that the GSO path is only used by HW offload, but it's also useful for SW crypto.This patch re-enables GSO for SW crypto. It's not an exact revert to preserve the other changes made to
xfrm_dev_offload_okafterwards, but it reverts all of its effects.Fixes 49431af6c4ef ("xfrm: rely on XFRM offload")Signed-off-by Sabrina Dubroca <[email protected]>
Thanks a lot.
Zhu Yanjun
Quoted 33 lines
--- net/xfrm/xfrm_device.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)net/xfrm/xfrm_device.c +7
-2@@ -415,10 +415,12 @@ bool xfrm_dev_offload_ok(struct sk_buff *skb, struct xfrm_state *x)struct net_device *dev = x->xso.dev;bool check_tunnel_size; -if (x->xso.type ==XFRM_DEV_OFFLOAD_UNSPECIFIED ) +if (!x->type_offload || + (x->xso.type ==XFRM_DEV_OFFLOAD_UNSPECIFIED && x->encap))return false; -if ((dev ==xfrm_dst_path (dst)->dev) && !xdst->child->xfrm) { +if ((!dev || dev ==xfrm_dst_path (dst)->dev) && + !xdst->child->xfrm) { mtu =xfrm_state_mtu (x, xdst->child_mtu_cached);if (skb->len <= mtu) goto ok;@@ -430,6 +432,9 @@ bool xfrm_dev_offload_ok(struct sk_buff *skb, struct xfrm_state *x)return false; ok: +if (!dev) +return true; + check_tunnel_size = x->xso.type ==XFRM_DEV_OFFLOAD_PACKET && x->props.mode ==XFRM_MODE_TUNNEL ;switch (x->props.family) {
Signature · 2 lines
Best Regards, Yanjun.Zhu
PATCH 2/3 Revert "xfrm: Remove unneeded device check from validate_xmit_xfrm"
In reply to Sabrina DubrocaThis reverts commit d53dda291bbd993a29b84d358d282076e3d01506.
This change causes traffic using GSO with SW crypto running through a NIC capable of HW offload to no longer get segmented during validate_xmit_xfrm.
--- net/xfrm/xfrm_device.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/xfrm/xfrm_device.c +6 -1
@@ -145,6 +145,10 @@ struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t featurreturn NULL ; } +/* This skb was already validated on the upper/virtual dev */ +if ((x->xso.dev != dev) && (x->xso.real_dev == dev)) +return skb; +local_irq_save (flags); sd =this_cpu_ptr (&softnet_data); err = !skb_queue_empty (&sd->xfrm_backlog);
@@ -155,7 +159,8 @@ struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t featurreturn skb; } -if (skb_is_gso (skb) &&unlikely (xmit_xfrm_check_overflow (skb))) { +if (skb_is_gso (skb) && (unlikely (x->xso.dev != dev) || +unlikely (xmit_xfrm_check_overflow (skb)))) {struct sk_buff *segs;/* Packet got rerouted, fixup features and segment it. */
Signature · 1 line
2.50.0
Re: [PATCH ipsec 2/3] Revert "xfrm: Remove unneeded device check from validate_xmit_xfrm"
Quoted 6 lines · Sabrina Dubroca
This reverts commit
d53dda291bbd993a29b84d358d282076e3d01506.This change causes traffic using GSO with SW crypto running through a NIC capable of HW offload to no longer get segmented during
validate_xmit_xfrm.
Quoted 6 lines
Fixes d53dda291bbd ("xfrm: Remove unneeded device check from validate_xmit_xfrm")Signed-off-by Sabrina Dubroca <[email protected]>--- net/xfrm/xfrm_device.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Thanks,
Re: [PATCH ipsec 2/3] Revert "xfrm: Remove unneeded device check from validate_xmit_xfrm"
In reply to Sabrina DubrocaQuoted 9 lines · Sabrina Dubroca
This reverts commit
d53dda291bbd993a29b84d358d282076e3d01506.This change causes traffic using GSO with SW crypto running through a NIC capable of HW offload to no longer get segmented during
validate_xmit_xfrm.Fixes d53dda291bbd ("xfrm: Remove unneeded device check from
validate_xmit_xfrm")
Thanks for the fix, but I'm curious about details.
In that commit, I tried to map all of the possible code paths. Can you please explain what code paths I missed that need real_dev given that only bonding should use it now?
Thanks,
Cosmin.
Re: [PATCH ipsec 2/3] Revert "xfrm: Remove unneeded device check from validate_xmit_xfrm"
Quoted 11 lines · Cosmin Ratiu
Quoted 9 lines · Sabrina Dubroca
This reverts commit
d53dda291bbd993a29b84d358d282076e3d01506.This change causes traffic using GSO with SW crypto running through a NIC capable of HW offload to no longer get segmented during
validate_xmit_xfrm.Fixes d53dda291bbd ("xfrm: Remove unneeded device check from
validate_xmit_xfrm")
Quoted 5 lines
Thanks for the fix, but I'm curious about details.
In that commit, I tried to map all of the possible code paths. Can you please explain what code paths I missed that need
real_devgiven that only bonding should use it now?
After running some more tests, it's not about real_dev, it's the other check ("unlikely(x->xso.dev != dev)" below) that you also removed in that patch that causes the issue in my setup. I don't know how you decided that it should be dropped, since it predates bonding's ipsec offload.
The codepath is the usual:__dev_queue_xmit -> validate_xmit_skb -> validate_xmit_xfrm
Since the commit message made the incorrect claim "ESP offload off:validate_xmit_xfrm returns early on !xo." I didn't check if a partial revert was enough to fix the issue. My bad.
Signature · 1 line
Sabrina
Re: [PATCH ipsec 2/3] Revert "xfrm: Remove unneeded device check from validate_xmit_xfrm"
Quoted 21 lines · Sabrina Dubroca
Quoted 12 lines · Cosmin Ratiu
Quoted 10 lines · Sabrina Dubroca
This reverts commit
d53dda291bbd993a29b84d358d282076e3d01506.This change causes traffic using GSO with SW crypto running through a
NIC capable of HW offload to no longer get segmented duringvalidate_xmit_xfrm.Fixes d53dda291bbd ("xfrm: Remove unneeded device check from
validate_xmit_xfrm")Quoted 7 lines
Thanks for the fix, but I'm curious about details.
In that commit, I tried to map all of the possible code paths. Can you
please explain what code paths I missed that needreal_devgiven that
only bonding should use it now?
Quoted 6 lines
After running some more tests, it's not about
real_dev, it's the other
check ("unlikely(x->xso.dev != dev)" below) that you also removed in that patch that causes the issue in my setup. I don't know how you decided that it should be dropped, since it predates bonding's ipsec offload.
Apologies for that, I think I assumed that if offload is off, then xfrm_offload(skb) is NULL and the code bails out early on "if (!xo)". Seems I was wrong. On the TX side, the only place that adds a secpath and increments sp->olen (and thus add an xfrm_offload) is in xfrm_output, after the xfrm_dev_offload_ok check.
Quoted 7 lines
The codepath is the usual:
__dev_queue_xmit->validate_xmit_skb->validate_xmit_xfrmSince the commit message made the incorrect claim "ESP offload off:
validate_xmit_xfrmreturns early on !xo." I didn't check if a partial revert was enough to fix the issue. My bad.
No problem, good that we caught the actual issue. Will you prepare a follow-up patch then?
Cosmin.
Re: [PATCH ipsec 2/3] Revert "xfrm: Remove unneeded device check from validate_xmit_xfrm"
Quoted 29 lines · Cosmin Ratiu
Quoted 21 lines · Sabrina Dubroca
Quoted 12 lines · Cosmin Ratiu
Quoted 10 lines · Sabrina Dubroca
This reverts commit
d53dda291bbd993a29b84d358d282076e3d01506.This change causes traffic using GSO with SW crypto running through a
NIC capable of HW offload to no longer get segmented duringvalidate_xmit_xfrm.Fixes d53dda291bbd ("xfrm: Remove unneeded device check from
validate_xmit_xfrm")Quoted 7 lines
Thanks for the fix, but I'm curious about details.
In that commit, I tried to map all of the possible code paths. Can you
please explain what code paths I missed that needreal_devgiven that
only bonding should use it now?Quoted 6 lines
After running some more tests, it's not about
real_dev, it's the other
check ("unlikely(x->xso.dev != dev)" below) that you also removed in that patch that causes the issue in my setup. I don't know how you decided that it should be dropped, since it predates bonding's ipsec offload.
Quoted 5 lines
Apologies for that, I think I assumed that if offload is off, then
xfrm_offload(skb)is NULL and the code bails out early on "if (!xo)". Seems I was wrong. On the TX side, the only place that adds a secpath and incrementssp->olen(and thus add anxfrm_offload) is inxfrm_output, after thexfrm_dev_offload_okcheck.
Yes, the "offload" code is used for both HW offload and "SW offloads" (aka GSO/GRO).
Quoted 9 lines
Quoted 7 lines
The codepath is the usual:
__dev_queue_xmit->validate_xmit_skb->validate_xmit_xfrmSince the commit message made the incorrect claim "ESP offload off:
validate_xmit_xfrmreturns early on !xo." I didn't check if a partial revert was enough to fix the issue. My bad.No problem, good that we caught the actual issue. Will you prepare a follow-up patch then?
I'll send a v2 of this series with this patch updated. Thanks.
Signature · 1 line
Sabrina
PATCH 3/3 udp: also consider secpath when evaluating ipsec use for checksumming
In reply to Sabrina DubrocaCommit b40c5f4fde22 ("udp: disable inner UDP checksum offloads in IPsec case") tried to fix checksumming in UFO when the packets are going through IPsec, so that we can't rely on offloads because the UDP header and payload will be encrypted.
But when doing a TCP test over VXLAN going through IPsec transport mode with GSO enabled (esp4_offload module loaded), I'm seeing broken UDP checksums on the encap after successful decryption.
The skbs get to udp4_ufo_fragment/__skb_udp_tunnel_segment via __dev_queue_xmit -> validate_xmit_skb -> skb_gso_segment and at this point we've already dropped the dst (unless the device sets IFF_XMIT_DST_RELEASE, which is not common), so need_ipsec is false and we proceed with checksum offload.
Make need_ipsec also check the secpath, which is not dropped on this callpath.
---
Since the issue is related to IPsec and currently not visible since GSO is currently broken for SW crypto, I'm including this patch in the same series for the ipsec tree. I can split it out if that's prefered, just let me know.
net/ipv4/udp_offload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/udp_offload.c +1 -1
@@ -224,7 +224,7 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb, remcsum = !!(skb_shinfo (skb)->gso_type &SKB_GSO_TUNNEL_REMCSUM ); skb->remcsum_offload = remcsum; - need_ipsec =skb_dst (skb) &&dst_xfrm (skb_dst (skb)); + need_ipsec = (skb_dst (skb) &&dst_xfrm (skb_dst (skb))) ||skb_sec_path (skb);/* Try to offload checksum if possible */ offload_csum = !!(need_csum && !need_ipsec &&
Signature · 1 line
2.50.0