When NETIF_F_CSUM_MASK bits are all 0 on netdev features, validate_xmit_skb
uses skb_checksum_help to compute 16-bit, 2-complement checksum on non-GSO
skbs having ip_summed equal to CHECKSUM_PARTIAL.
This results in a systematic corruption of SCTP packets, since they need
to be checksummed with crc32c. Moreover, this is done regardless the value
of NETIF_F_SCTP_CRC, so any chance to offload crc32c computation on the
NIC is lost. Finally, even when at least one bit in NETIF_F_CSUM_MASK is
set on netdev features, validate_xmit_skb skips checksum computation - but
then most NIC drivers can only call skb_checksum_help if their HW can't
offload the checksum computation. Depending on the driver code, this
results in wrong handling of SCTP, leading to:
- packet being dropped
- packet being transmitted with identically-zero checksum
- packet being transmitted with 2-complement checksum instead of crc32c
This series tries to address the above issue, by providing:
- the possibility to compute crc32c on skbs in Linux net core [patch 1]
- skb_sctp_csum_help, a function sharing common code with the original
skb_checksum_help, that performs SW checksumming for skbs using crc32c
[patch 2 and patch 3]
- skb_csum_hwoffload_help, called by validate xmit skb to perform SW
checksumming using the correct algorithm based on the value of IP
protocol number and netdev features bitmask [patch 4]
- an update to Linux documentation [patch 5]
Davide Caratti (5):
skbuff: add stub to help computing crc32c on SCTP packets
net: split skb_checksum_help
net: introduce skb_sctp_csum_help
net: more accurate checksumming in validate_xmit_skb
Documentation: add description of skb_sctp_csum_help
Documentation/networking/checksum-offloads.txt | 9 +-
include/linux/netdevice.h | 1 +
include/linux/skbuff.h | 5 +-
net/core/dev.c | 132 +++++++++++++++++++++----
net/core/skbuff.c | 20 ++++
net/sctp/offload.c | 7 ++
6 files changed, 151 insertions(+), 23 deletions(-)
--
2.7.4
skb_checksum_help is designed to compute the Internet Checksum only. To
avoid duplicating code when other checksumming algorithms (e.g. crc32c)
are used, separate common part from RFC1624-specific part.
Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: Davide Caratti <redacted>
---
net/core/dev.c | 51 +++++++++++++++++++++++++++++++++++----------------
1 file changed, 35 insertions(+), 16 deletions(-)
@@ -2532,13 +2532,36 @@ static void skb_warn_bad_offload(const struct sk_buff *skb)skb_shinfo(skb)->gso_type,skb->ip_summed);}-/*-*Invalidatehardwarechecksumwhenpacketistobemangled,and+/* compute 16-bit RFC1624 checksum and store it at skb->data + offset */+staticintskb_rfc1624_csum(structsk_buff*skb,intoffset)+{+__wsumcsum;+intret=0;++csum=skb_checksum(skb,offset,skb->len-offset,0);++offset+=skb->csum_offset;+BUG_ON(offset+sizeof(__sum16)>skb_headlen(skb));++if(skb_cloned(skb)&&+!skb_clone_writable(skb,offset+sizeof(__sum16))){+ret=pskb_expand_head(skb,0,0,GFP_ATOMIC);+if(ret)+gotoout;+}+*(__sum16*)(skb->data+offset)=csum_fold(csum)?:CSUM_MANGLED_0;+out:+returnret;+}++/* Invalidate hardware checksum when packet is to be mangled, and*completechecksummanuallyonoutgoingpath.+*@skb-bufferthatneedschecksum+*@csum_algo(skb,offset)-functionusedtocomputethechecksum*/-intskb_checksum_help(structsk_buff*skb)+staticint__skb_checksum_help(structsk_buff*skb,+int(*csum_algo)(structsk_buff*,int)){-__wsumcsum;intret=0,offset;if(skb->ip_summed==CHECKSUM_COMPLETE)
@@ -2560,24 +2583,20 @@ int skb_checksum_help(struct sk_buff *skb)offset=skb_checksum_start_offset(skb);BUG_ON(offset>=skb_headlen(skb));-csum=skb_checksum(skb,offset,skb->len-offset,0);--offset+=skb->csum_offset;-BUG_ON(offset+sizeof(__sum16)>skb_headlen(skb));--if(skb_cloned(skb)&&-!skb_clone_writable(skb,offset+sizeof(__sum16))){-ret=pskb_expand_head(skb,0,0,GFP_ATOMIC);-if(ret)-gotoout;-}-*(__sum16*)(skb->data+offset)=csum_fold(csum)?:CSUM_MANGLED_0;+ret=csum_algo(skb,offset);+if(ret)+gotoout;out_set_summed:skb->ip_summed=CHECKSUM_NONE;out:returnret;}++intskb_checksum_help(structsk_buff*skb)+{+return__skb_checksum_help(skb,skb_rfc1624_csum);+}EXPORT_SYMBOL(skb_checksum_help);__be16skb_network_protocol(structsk_buff*skb,int*depth)
skb_sctp_csum_help is like skb_checksum_help, but it is designed for
checksumming SCTP packets using crc32c (see RFC3309), provided that
sctp.ko has been loaded before. In case sctp.ko is not loaded, invoking
skb_sctp_csum_help() on a skb results in the following printout:
sk_buff: attempt to compute crc32c without sctp.ko
Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: Davide Caratti <redacted>
---
include/linux/netdevice.h | 1 +
include/linux/skbuff.h | 3 ++-
net/core/dev.c | 29 +++++++++++++++++++++++++++++
3 files changed, 32 insertions(+), 1 deletion(-)
@@ -2554,6 +2554,29 @@ static int skb_rfc1624_csum(struct sk_buff *skb, int offset)returnret;}+/* compute 32-bit RFC3309 checksum and store it at skb->data + offset */+staticintskb_rfc3309_csum(structsk_buff*skb,intoffset)+{+__le32crc32c_csum;+intret=0;++crc32c_csum=cpu_to_le32(~__skb_checksum(skb,offset,+skb->len-offset,~(__u32)0,+sctp_csum_stub));+offset+=skb->csum_offset;+BUG_ON((offset+sizeof(__le32))>skb_headlen(skb));++if(skb_cloned(skb)&&+!skb_clone_writable(skb,offset+sizeof(__le32))){+ret=pskb_expand_head(skb,0,0,GFP_ATOMIC);+if(ret)+gotoout;+}+*(__le32*)(skb->data+offset)=crc32c_csum;+out:+returnret;+}+/* Invalidate hardware checksum when packet is to be mangled, and*completechecksummanuallyonoutgoingpath.*@skb-bufferthatneedschecksum
@@ -2599,6 +2622,12 @@ int skb_checksum_help(struct sk_buff *skb)}EXPORT_SYMBOL(skb_checksum_help);+intskb_sctp_csum_help(structsk_buff*skb)+{+return__skb_checksum_help(skb,skb_rfc3309_csum);+}+EXPORT_SYMBOL(skb_sctp_csum_help);+__be16skb_network_protocol(structsk_buff*skb,int*depth){__be16type=skb->protocol;
introduce skb_csum_hwoffload_help and use it as a replacement for
skb_checksum_help in validate_xmit_skb, to compute checksum using crc32c or
2-complement Internet Checksum (or leave the packet unchanged and let the
NIC do the checksum), depending on netdev checksum offloading capabilities
and on presence of IPPROTO_SCTP as protocol number in IPv4/IPv6 header.
Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: Davide Caratti <redacted>
---
net/core/dev.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 50 insertions(+), 2 deletions(-)
Add description of skb_sctp_csum_help in networking/checksum-offload.txt;
while at it, remove reference to skb_csum_off_chk* functions, since they
are not present anymore in Linux since commit cf53b1da73bd ('Revert "net:
Add driver helper functions to determine checksum"').
Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: Davide Caratti <redacted>
---
Documentation/networking/checksum-offloads.txt | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
@@ -49,9 +49,9 @@ A driver declares its offload capabilities in netdev->hw_features; see and csum_offset given in the SKB; if it tries to deduce these itself in hardware (as some NICs do) the driver should check that the values in the SKB match those which the hardware will deduce, and if not, fall back to- checksumming in software instead (with skb_checksum_help or one of the- skb_csum_off_chk* functions as mentioned in include/linux/skbuff.h). This- is a pain, but that's what you get when hardware tries to be clever.+ checksumming in software instead (with skb_checksum_help or+ skb_sctp_csum_help functions as mentioned in include/linux/skbuff.h).+ This is a pain, but that's what you get when hardware tries to be clever. The stack should, for the most part, assume that checksum offload is supported by the underlying device. The only place that should check is
@@ -60,7 +60,8 @@ The stack should, for the most part, assume that checksum offload is may include other offloads besides TX Checksum Offload) and, if they are not supported or enabled on the device (determined by netdev->features), performs the corresponding offload in software. In the case of TX- Checksum Offload, that means calling skb_checksum_help(skb).+ Checksum Offload, that means calling skb_sctp_csum_help(skb) for SCTP+ packets, and skb_checksum_help(skb) for other packets. LCO: Local Checksum Offload
sctp_compute_checksum requires crc32c symbol (provided by libcrc32c), so
it can't be used in net core. Like it has been done previously with other
symbols (e.g. ipv6_dst_lookup), introduce a stub struct skb_checksum_ops
to allow computation of SCTP checksum in net core after sctp.ko (and thus
libcrc32c) has been loaded.
Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: Davide Caratti <redacted>
---
include/linux/skbuff.h | 2 ++
net/core/skbuff.c | 20 ++++++++++++++++++++
net/sctp/offload.c | 7 +++++++
3 files changed, 29 insertions(+)
@@ -2235,6 +2235,26 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,}EXPORT_SYMBOL(skb_copy_and_csum_bits);+static__wsumwarn_sctp_csum_update(constvoid*buff,intlen,__wsumsum)+{+net_warn_ratelimited("attempt to compute crc32c without sctp.ko\n");+return0;+}++static__wsumwarn_sctp_csum_combine(__wsumcsum,__wsumcsum2,+intoffset,intlen)+{+net_warn_ratelimited("attempt to compute crc32c without sctp.ko\n");+return0;+}++conststructskb_checksum_ops*sctp_csum_stub__read_mostly=+&(structskb_checksum_ops){+.update=warn_sctp_csum_update,+.combine=warn_sctp_csum_combine,+};+EXPORT_SYMBOL(sctp_csum_stub);+/***skb_zerocopy_headlen-Calculateheadroomneededforskb_zerocopy()*@from:sourcebuffer
From: Tom Herbert <hidden> Date: 2017-01-23 20:59:50
On Mon, Jan 23, 2017 at 8:52 AM, Davide Caratti [off-list ref] wrote:
quoted hunk
skb_checksum_help is designed to compute the Internet Checksum only. To
avoid duplicating code when other checksumming algorithms (e.g. crc32c)
are used, separate common part from RFC1624-specific part.
Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: Davide Caratti <redacted>
---
net/core/dev.c | 51 +++++++++++++++++++++++++++++++++++----------------
1 file changed, 35 insertions(+), 16 deletions(-)
@@ -2532,13 +2532,36 @@ static void skb_warn_bad_offload(const struct sk_buff *skb)skb_shinfo(skb)->gso_type,skb->ip_summed);}-/*-*Invalidatehardwarechecksumwhenpacketistobemangled,and+/* compute 16-bit RFC1624 checksum and store it at skb->data + offset */+staticintskb_rfc1624_csum(structsk_buff*skb,intoffset)+{+__wsumcsum;+intret=0;++csum=skb_checksum(skb,offset,skb->len-offset,0);++offset+=skb->csum_offset;+BUG_ON(offset+sizeof(__sum16)>skb_headlen(skb));++if(skb_cloned(skb)&&+!skb_clone_writable(skb,offset+sizeof(__sum16))){+ret=pskb_expand_head(skb,0,0,GFP_ATOMIC);+if(ret)+gotoout;+}+*(__sum16*)(skb->data+offset)=csum_fold(csum)?:CSUM_MANGLED_0;+out:+returnret;+}++/* Invalidate hardware checksum when packet is to be mangled, and*completechecksummanuallyonoutgoingpath.+*@skb-bufferthatneedschecksum+*@csum_algo(skb,offset)-functionusedtocomputethechecksum*/-intskb_checksum_help(structsk_buff*skb)+staticint__skb_checksum_help(structsk_buff*skb,+int(*csum_algo)(structsk_buff*,int)){-__wsumcsum;intret=0,offset;if(skb->ip_summed==CHECKSUM_COMPLETE)
skb_checksum_help is specific to the Internet checksum. For instance,
CHECKSUM_COMPLETE can _only_ refer to Internet checksum calculation
nothing else will work. Checksums and CRCs are very different things
with very different processing. They are not interchangeable, have
very different properties, and hence it is a mistake to try to shoe
horn things so that they use a common infrastructure.
It might make sense to create some CRC helper functions, but last time
I checked there are so few users of CRC in skbufs I'm not even sure
that would make sense.
Tom
From: David Laight <hidden> Date: 2017-01-24 16:35:27
From: Tom Herbert
Sent: 23 January 2017 21:00
..
skb_checksum_help is specific to the Internet checksum. For instance,
CHECKSUM_COMPLETE can _only_ refer to Internet checksum calculation
nothing else will work. Checksums and CRCs are very different things
with very different processing. They are not interchangeable, have
very different properties, and hence it is a mistake to try to shoe
horn things so that they use a common infrastructure.
It might make sense to create some CRC helper functions, but last time
I checked there are so few users of CRC in skbufs I'm not even sure
that would make sense.
I can imagine horrid things happening if someone tries to encapsulate
SCTP/IP in UDP (or worse UDP/IP in SCTP).
For UDP in UDP I suspect that CHECKSUM_COMPLETE on an inner UDP packet
allows the outer checksum be calculated by ignoring the inner packet
(since it sums to zero).
This just isn't true if SCTP is involved.
There are tricks to generate a crc of a longer packet, but they'd only
work for SCTP in SCTP.
For non-encapsulated packets it is a different matter.
David
skb_checksum_help is specific to the Internet checksum. For instance,
CHECKSUM_COMPLETE can _only_ refer to Internet checksum calculation
nothing else will work. Checksums and CRCs are very different things
with very different processing. They are not interchangeable, have
very different properties, and hence it is a mistake to try to shoe
horn things so that they use a common infrastructure.
true, we don't need to test CHECKSUM_COMPLETE on skbs carrying SCTP.
So maybe we can simply replace patches 2/5 and 3/5 with the smaller one at
the bottom of this message.
quoted
It might make sense to create some CRC helper functions, but last time
I checked there are so few users of CRC in skbufs I'm not even sure
that would make sense.
This is exactly the cause of issues I see with SCTP. These packets can be
wrongly checksummed using skb_checksum_help, or simply not checksummed at
all; and in both cases, the packet goes out from the NIC with wrong L4
checksum.
For example: there are scenarios, even the trivial one below, where skb
carrying SCTP packets are wrongly checksummed, because the originating
socket read NETIF_F_SCTP_CRC bit in the underlying device features.
Then, after the kernel forwards the skb, the final transmission
happens on another device where CRC offload is not available: this
typically leads to bad checksums on transmitted SCTP packets.
namespace 1 | namespace 2
|
| br0
| +------- Linux bridge -------+
| | |
| V V
vethA <-----------> vethB eth0
|
|
when a socket bound to vethA in namespace 1 generates an INIT packet,
it's not checksummed since veth devices have NETIF_F_SCTP_CRC set [1].
Then, after vethB receives the packet in namespace 2, linux bridge
forwards it to eth0, and (depending on eth0 driver code), it will be
transmitted with wrong CRC32c or simply dropped.
On Tue, 2017-01-24 at 16:35 +0000, David Laight wrote:
I can imagine horrid things happening if someone tries to encapsulate
SCTP/IP in UDP (or worse UDP/IP in SCTP).
For UDP in UDP I suspect that CHECKSUM_COMPLETE on an inner UDP packet
allows the outer checksum be calculated by ignoring the inner packet
(since it sums to zero).
This just isn't true if SCTP is involved.
There are tricks to generate a crc of a longer packet, but they'd only
work for SCTP in SCTP.
For non-encapsulated packets it is a different matter.
If we limit the scope to skbs having ip_summed equal to CHECKSUM_PARTIAL,
like it's done in patch 4, we only need checksumming the packet starting
from csum_start to its end, and copy the computed value to csum_offset.
The difficult thing is discriminating skbs that need CRC32c, namely SCTP,
from the rest of the traffic (that will likely be checksummed by
skb_checksum_help).
Currently, the only way to fix wrong CRCs in the scenario above is to
configure tc filter with "csum" action on eth0 egress, to compensate the
missing capability of eth0 driver to deal with SCTP packets having
ip_summed equal to CHECKSUM_PARTIAL [2].
Patch 4 in the series is an attempt to solve the issue, both for
encapsulated and non-encapsulated skbs, calling skb_csum_hwoffload_help()
inside validate_xmit_skb. In order to look for unchecksummed SCTP packets,
I took inspiration from a Linux-4.4 commit (6ae23ad36253 "net: Add driver
helper functions ...) to implement skb_csum_hwoffload_help, then I called
it in validate_xmit_skb() to fix situations that can't be recovered by the
NIC driver (it's the case where NETIF_F_CSUM_MASK bits are all zero).
Today most NICs can provide at least HW offload for Internet Checksum:
that's why I'm a bit doubtful if it's ok to spend extra CPU cycles in
validate_xmit_skb() to ensure correct CRC in some scenarios.
Since this issue affects some (not all) NICs, maybe it's better to drop
patch 4, or part of it, and provide a fix for individual drivers that
don't currently handle non-checksummed SCTP packets. But to do that, we
need at least patch 1 and the small code below.
------------------- 8< --------------------------
* accordingly. Note the there is no indication in the skbuff that the
* CHECKSUM_PARTIAL refers to an FCOE checksum, a driver that supports
* both IP checksum offload and FCOE CRC offload must verify which offload
- * is configured for a packet presumably by inspecting packet headers.
+ * is configured for a packet presumably by inspecting packet headers; in
+ * case, skb_sctp_csum_help is provided to compute CRC on SCTP packets.
*
* E. Checksumming on output with GSO.
*
@@ -2580,6 +2580,42 @@ int skb_checksum_help(struct sk_buff *skb)
}
EXPORT_SYMBOL(skb_checksum_help);
+int skb_sctp_csum_help(struct sk_buff *skb)
+{
+ __le32 crc32c_csum;
+ int ret = 0, offset;
+
+ if (skb->ip_summed != CHECKSUM_PARTIAL)
+ goto out;
+ if (unlikely(skb_is_gso(skb)))
+ goto out;
+ if (skb_has_shared_frag(skb)) {
+ ret = __skb_linearize(skb);
+ if (ret)
+ goto out;
+ }
+
+ offset = skb_checksum_start_offset(skb);
+ crc32c_csum = cpu_to_le32(~__skb_checksum(skb, offset,
+ skb->len - offset, ~(__u32)0,
+ sctp_csum_stub));
+
+ offset += offsetof(struct sctphdr, checksum);
+ BUG_ON(offset >= skb_headlen(skb));
+
+ if (skb_cloned(skb) &&
+ !skb_clone_writable(skb, offset + sizeof(__le32))) {
+ ret = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
+ if (ret)
+ goto out;
+ }
+ *(__le32 *)(skb->data + offset) = crc32c_csum;
+ skb->ip_summed = CHECKSUM_NONE;
+out:
+ return ret;
+}
+EXPORT_SYMBOL(skb_sctp_csum_help);
+
__be16 skb_network_protocol(struct sk_buff *skb, int *depth)
{
__be16 type = skb->protocol;
--
2.7.4
------------------- >8 --------------------------
Thank you again for paying attention to this, and I would appreciate if
you share your opinion.
Notes:
[1] see commit c80fafbbb59e ("veth: sctp: add NETIF_F_SCTP_CRC to device
features")
[2] see commit c008b33f3ef ("net/sched: act_csum: compute crc32c on SCTP
packets"). We could also turn off NETIF_F_SCTP_CRC bit from vethA, but
this would generate useless crc32c calculations if the SCTP server is not
outside the physical node (e.g. it is bound to br0), leading to a
throughput degradation.
From: David Laight <hidden> Date: 2017-02-02 16:55:21
From: Davide Caratti
Sent: 02 February 2017 15:07
quoted
From: Tom Herbert
quoted
Sent: 23 January 2017 21:00
..
quoted
skb_checksum_help is specific to the Internet checksum. For instance,
CHECKSUM_COMPLETE can _only_ refer to Internet checksum calculation
nothing else will work. Checksums and CRCs are very different things
with very different processing. They are not interchangeable, have
very different properties, and hence it is a mistake to try to shoe
horn things so that they use a common infrastructure.
true, we don't need to test CHECKSUM_COMPLETE on skbs carrying SCTP.
So maybe we can simply replace patches 2/5 and 3/5 with the smaller one at
the bottom of this message.
I have to admit to not knowing exactly what the CHECKSUM_xxx flags actually mean.
I have a good idea about what the intention is though.
...
On Tue, 2017-01-24 at 16:35 +0000, David Laight wrote:
quoted
I can imagine horrid things happening if someone tries to encapsulate
SCTP/IP in UDP (or worse UDP/IP in SCTP).
For UDP in UDP I suspect that CHECKSUM_COMPLETE on an inner UDP packet
allows the outer checksum be calculated by ignoring the inner packet
(since it sums to zero).
This just isn't true if SCTP is involved.
There are tricks to generate a crc of a longer packet, but they'd only
work for SCTP in SCTP.
For non-encapsulated packets it is a different matter.
If we limit the scope to skbs having ip_summed equal to CHECKSUM_PARTIAL,
like it's done in patch 4, we only need checksumming the packet starting
from csum_start to its end, and copy the computed value to csum_offset.
The difficult thing is discriminating skbs that need CRC32c, namely SCTP,
from the rest of the traffic (that will likely be checksummed by
skb_checksum_help).
...
I'm guessing that the SCTP code only sets CHECKSUM_PARTIAL (and doesn't
perform the checksum) if it somehow knows that the target interface
supports CRC32c checksums.
I'd put the onus on any such interface to perform the checksum (and
set CHECKSUM_COMPLETE (or is it UNNECESSARY?) before passing the
message onto an interface that doesn't advertise CRC32 support.
You certainly don't want to have to go through all the ethernet drivers!
From: Tom Herbert <hidden> Date: 2017-02-02 18:08:07
On Thu, Feb 2, 2017 at 7:07 AM, Davide Caratti [off-list ref] wrote:
hello Tom and David,
thank you for the attention.
quoted
From: Tom Herbert
quoted
Sent: 23 January 2017 21:00
..
quoted
skb_checksum_help is specific to the Internet checksum. For instance,
CHECKSUM_COMPLETE can _only_ refer to Internet checksum calculation
nothing else will work. Checksums and CRCs are very different things
with very different processing. They are not interchangeable, have
very different properties, and hence it is a mistake to try to shoe
horn things so that they use a common infrastructure.
true, we don't need to test CHECKSUM_COMPLETE on skbs carrying SCTP.
So maybe we can simply replace patches 2/5 and 3/5 with the smaller one at
the bottom of this message.
quoted
quoted
It might make sense to create some CRC helper functions, but last time
I checked there are so few users of CRC in skbufs I'm not even sure
that would make sense.
This is exactly the cause of issues I see with SCTP. These packets can be
wrongly checksummed using skb_checksum_help, or simply not checksummed at
all; and in both cases, the packet goes out from the NIC with wrong L4
checksum.
Okay, makes sense. Please consider doing the following:
- Add a bit to skbuf called something like "csum_not_inet". When
ip_summed == CHECKSUM_PARTIAL and this bit is set that means we are
dealing with something other than an Internet checksum.
- At the top of skb_checksum_help (or maybe before the point where the
inet specific checksum start begins do something like:
if (unlikely(skb->csum_not_inet))
return skb_checksum_help_not_inet(...);
The rest of skb_checksum_help should remained unchanged.
- Add a description of the new bit and how skb_checksum_help can work
to the comments for CHECKSUM_PARTIAL in skbuff.h
- Add FCOE to the list of protocol that can set CHECKSUM_UNNECESSARY
for a CRC/csum
- Add a note to CHECKSUM_COMPLETE section that it can only refer to an
Internet checksum
Thanks,
Tom
quoted hunk
For example: there are scenarios, even the trivial one below, where skb
carrying SCTP packets are wrongly checksummed, because the originating
socket read NETIF_F_SCTP_CRC bit in the underlying device features.
Then, after the kernel forwards the skb, the final transmission
happens on another device where CRC offload is not available: this
typically leads to bad checksums on transmitted SCTP packets.
namespace 1 | namespace 2
|
| br0
| +------- Linux bridge -------+
| | |
| V V
vethA <-----------> vethB eth0
|
|
when a socket bound to vethA in namespace 1 generates an INIT packet,
it's not checksummed since veth devices have NETIF_F_SCTP_CRC set [1].
Then, after vethB receives the packet in namespace 2, linux bridge
forwards it to eth0, and (depending on eth0 driver code), it will be
transmitted with wrong CRC32c or simply dropped.
On Tue, 2017-01-24 at 16:35 +0000, David Laight wrote:
quoted
I can imagine horrid things happening if someone tries to encapsulate
SCTP/IP in UDP (or worse UDP/IP in SCTP).
For UDP in UDP I suspect that CHECKSUM_COMPLETE on an inner UDP packet
allows the outer checksum be calculated by ignoring the inner packet
(since it sums to zero).
This just isn't true if SCTP is involved.
There are tricks to generate a crc of a longer packet, but they'd only
work for SCTP in SCTP.
For non-encapsulated packets it is a different matter.
If we limit the scope to skbs having ip_summed equal to CHECKSUM_PARTIAL,
like it's done in patch 4, we only need checksumming the packet starting
from csum_start to its end, and copy the computed value to csum_offset.
The difficult thing is discriminating skbs that need CRC32c, namely SCTP,
from the rest of the traffic (that will likely be checksummed by
skb_checksum_help).
Currently, the only way to fix wrong CRCs in the scenario above is to
configure tc filter with "csum" action on eth0 egress, to compensate the
missing capability of eth0 driver to deal with SCTP packets having
ip_summed equal to CHECKSUM_PARTIAL [2].
Patch 4 in the series is an attempt to solve the issue, both for
encapsulated and non-encapsulated skbs, calling skb_csum_hwoffload_help()
inside validate_xmit_skb. In order to look for unchecksummed SCTP packets,
I took inspiration from a Linux-4.4 commit (6ae23ad36253 "net: Add driver
helper functions ...) to implement skb_csum_hwoffload_help, then I called
it in validate_xmit_skb() to fix situations that can't be recovered by the
NIC driver (it's the case where NETIF_F_CSUM_MASK bits are all zero).
Today most NICs can provide at least HW offload for Internet Checksum:
that's why I'm a bit doubtful if it's ok to spend extra CPU cycles in
validate_xmit_skb() to ensure correct CRC in some scenarios.
Since this issue affects some (not all) NICs, maybe it's better to drop
patch 4, or part of it, and provide a fix for individual drivers that
don't currently handle non-checksummed SCTP packets. But to do that, we
need at least patch 1 and the small code below.
------------------- 8< --------------------------
@@ -2580,6 +2580,42 @@ int skb_checksum_help(struct sk_buff *skb)}EXPORT_SYMBOL(skb_checksum_help);+intskb_sctp_csum_help(structsk_buff*skb)+{+__le32crc32c_csum;+intret=0,offset;++if(skb->ip_summed!=CHECKSUM_PARTIAL)+gotoout;+if(unlikely(skb_is_gso(skb)))+gotoout;+if(skb_has_shared_frag(skb)){+ret=__skb_linearize(skb);+if(ret)+gotoout;+}++offset=skb_checksum_start_offset(skb);+crc32c_csum=cpu_to_le32(~__skb_checksum(skb,offset,+skb->len-offset,~(__u32)0,+sctp_csum_stub));++offset+=offsetof(structsctphdr,checksum);+BUG_ON(offset>=skb_headlen(skb));++if(skb_cloned(skb)&&+!skb_clone_writable(skb,offset+sizeof(__le32))){+ret=pskb_expand_head(skb,0,0,GFP_ATOMIC);+if(ret)+gotoout;+}+*(__le32*)(skb->data+offset)=crc32c_csum;+skb->ip_summed=CHECKSUM_NONE;+out:+returnret;+}+EXPORT_SYMBOL(skb_sctp_csum_help);+__be16skb_network_protocol(structsk_buff*skb,int*depth){__be16type=skb->protocol;--
2.7.4
------------------- >8 --------------------------
Thank you again for paying attention to this, and I would appreciate if
you share your opinion.
Notes:
[1] see commit c80fafbbb59e ("veth: sctp: add NETIF_F_SCTP_CRC to device
features")
[2] see commit c008b33f3ef ("net/sched: act_csum: compute crc32c on SCTP
packets"). We could also turn off NETIF_F_SCTP_CRC bit from vethA, but
this would generate useless crc32c calculations if the SCTP server is not
outside the physical node (e.g. it is bound to br0), leading to a
throughput degradation.
From: Tom Herbert <hidden> Date: 2017-02-27 15:18:26
On Mon, Feb 27, 2017 at 5:39 AM, Davide Caratti [off-list ref] wrote:
On Mon, 2017-01-23 at 12:59 -0800, Tom Herbert wrote:
quoted
quoted
quoted
quoted
It might make sense to create some CRC helper functions, but last time
I checked there are so few users of CRC in skbufs I'm not even sure
that would make sense.
hello Tom and David,
after some (thinking + testing) time, I'm going to re-post this RFC as v2 with
some feedbacks. Thank you in advance for looking at it!
On Thu, 2017-02-02 at 10:08 -0800, Tom Herbert wrote:
quoted
On Thu, 2017-02-02 at 16:07 +0100, Davide Caratti wrote:
quoted
This is exactly the cause of issues I see with SCTP. These packets can be
wrongly checksummed using skb_checksum_help, or simply not checksummed at
all; and in both cases, the packet goes out from the NIC with wrong L4
checksum.
Okay, makes sense. Please consider doing the following:
- Add a bit to skbuf called something like "csum_not_inet". When
ip_summed == CHECKSUM_PARTIAL and this bit is set that means we are
dealing with something other than an Internet checksum.
Ok, done. Another solution would be to extend possible values of
skb->ip_summed, and define a new value suitable for identifying
not-yet-checksummed SCTP packets (something like CRC32C_PARTIAL). Since
skb->ip_summed is 2-bit wide, the overall effect on skb metadata is the
same as adding skb->csum_not_inet [1].
quoted
- At the top of skb_checksum_help (or maybe before the point where the
inet specific checksum start begins do something like:
if (unlikely(skb->csum_not_inet))
return skb_checksum_help_not_inet(...);
The rest of skb_checksum_help should remained unchanged.
According to documentation [2], validate_xmit_skb() is a good place where
the if() statement above can be done, to preserve the possibility of having
the CRC32c computation offloaded by the NIC hardware:
if (unlikely(skb->csum_not_inet && !(features & NETIF_F_SCTP_CRC))
return skb_checksum_help_not_inet(...);
On Thu, 2017-02-02 at 16:55 +0000, David Laight wrote:
quoted
I'd put the onus on any such interface to perform the checksum (and
set CHECKSUM_COMPLETE (or is it UNNECESSARY?) before passing the
message onto an interface that doesn't advertise CRC32 support.
You certainly don't want to have to go through all the ethernet drivers!
Ideally, a driver not able to offload checksum computation should call
skb_checksum_help() or skb_sctp_csum_help() to resolve CHECKSUM_PARTIAL
and turn it to CHECKSUM_NONE.
But this wouldn't solve all possible setups: there can be scenarios
where the NIC is configured with NETIF_F_SCTP_CRC set and NETIF_F_CSUM_HW
cleared (it's evil, but possible). In this situation, non-GSO SCTP packets
having CHECKSUM_PARTIAL will be systematically corrupted when they are
processed by validate_xmit_skb().
On Thu, 2017-02-02 at 10:08 -0800, Tom Herbert wrote:
quoted
- Add a description of the new bit and how skb_checksum_help can work
to the comments for CHECKSUM_PARTIAL in skbuff.h
Done.
quoted
- Add FCOE to the list of protocol that can set CHECKSUM_UNNECESSARY
for a CRC/csum
Done.
quoted
- Add a note to CHECKSUM_COMPLETE section that it can only refer to an
Internet checksum
Done.
/* references + notes */
[1] ... this recalls to latest comment from David Laight:
On Thu, 2017-02-02 at 16:55 +0000, David Laight wrote:
quoted
I have to admit to not knowing exactly what the CHECKSUM_xxx flags
actually mean. I have a good idea about what the intention is though.
According to domumentation, CHECKSUM_COMPLETE and CHECKSUM_UNNECESSARY are
not used for SCTP (nor in the TX path at all); nevertheless, IPVS snat/dnat
actually set CHECKSUM_UNNECESSARY on SCTP packets after the checksum is
updated (see 97203abe6bc4 "net: ipvs: sctp: do not recalc...).
CHECKSUM_PARTIAL is the preferred mechanism on the transmit path this
defers defers the checksum computation as long as possible.
Unfortunately, if SCTP is encapsulated in UDP we will probably need to
run the SCTP CRC on the host which will be done with your changes to
skb_checksum_help.
I'm not sure if setting CHECKSUM_UNNECESSARY fits my case, because this would
implicitly skip RX validation when using devices like veth or loopback.
CHECKSUM_UNNECESSARY can be used in the transmit path (really the
forwarding path), however this I think this must imply that the
checksum in the packet must be correct. Please see my post about
drivers that are mistakingly using CHECKSUM_UNNECESSARY with LRO since
the checksum in the packet sent into the stack is not correct.
Tom
On Mon, 2017-01-23 at 12:59 -0800, Tom Herbert wrote:
quoted
quoted
quoted
It might make sense to create some CRC helper functions, but last time
I checked there are so few users of CRC in skbufs I'm not even sure
that would make sense.
hello Tom and David,
after some (thinking + testing) time, I'm going to re-post this RFC as v2 with
some feedbacks. Thank you in advance for looking at it!
On Thu, 2017-02-02 at 10:08 -0800, Tom Herbert wrote:
On Thu, 2017-02-02 at 16:07 +0100, Davide Caratti wrote:
quoted
This is exactly the cause of issues I see with SCTP. These packets can be
wrongly checksummed using skb_checksum_help, or simply not checksummed at
all; and in both cases, the packet goes out from the NIC with wrong L4
checksum.
Okay, makes sense. Please consider doing the following:
- Add a bit to skbuf called something like "csum_not_inet". When
ip_summed == CHECKSUM_PARTIAL and this bit is set that means we are
dealing with something other than an Internet checksum.
Ok, done. Another solution would be to extend possible values of
skb->ip_summed, and define a new value suitable for identifying
not-yet-checksummed SCTP packets (something like CRC32C_PARTIAL). Since
skb->ip_summed is 2-bit wide, the overall effect on skb metadata is the
same as adding skb->csum_not_inet [1].
- At the top of skb_checksum_help (or maybe before the point where the
inet specific checksum start begins do something like:
if (unlikely(skb->csum_not_inet))
return skb_checksum_help_not_inet(...);
The rest of skb_checksum_help should remained unchanged.
According to documentation [2], validate_xmit_skb() is a good place where
the if() statement above can be done, to preserve the possibility of having
the CRC32c computation offloaded by the NIC hardware:
if (unlikely(skb->csum_not_inet && !(features & NETIF_F_SCTP_CRC))
return skb_checksum_help_not_inet(...);
On Thu, 2017-02-02 at 16:55 +0000, David Laight wrote:
I'd put the onus on any such interface to perform the checksum (and
set CHECKSUM_COMPLETE (or is it UNNECESSARY?) before passing the
message onto an interface that doesn't advertise CRC32 support.
You certainly don't want to have to go through all the ethernet drivers!
Ideally, a driver not able to offload checksum computation should call
skb_checksum_help() or skb_sctp_csum_help() to resolve CHECKSUM_PARTIAL
and turn it to CHECKSUM_NONE.
But this wouldn't solve all possible setups: there can be scenarios
where the NIC is configured with NETIF_F_SCTP_CRC set and NETIF_F_CSUM_HW
cleared (it's evil, but possible). In this situation, non-GSO SCTP packets
having CHECKSUM_PARTIAL will be systematically corrupted when they are
processed by validate_xmit_skb().
On Thu, 2017-02-02 at 10:08 -0800, Tom Herbert wrote:
- Add a description of the new bit and how skb_checksum_help can work
to the comments for CHECKSUM_PARTIAL in skbuff.h
Done.
- Add FCOE to the list of protocol that can set CHECKSUM_UNNECESSARY
for a CRC/csum
Done.
- Add a note to CHECKSUM_COMPLETE section that it can only refer to an
Internet checksum
Done.
/* references + notes */
[1] ... this recalls to latest comment from David Laight:
On Thu, 2017-02-02 at 16:55 +0000, David Laight wrote:
I have to admit to not knowing exactly what the CHECKSUM_xxx flags
actually mean. I have a good idea about what the intention is though.
According to domumentation, CHECKSUM_COMPLETE and CHECKSUM_UNNECESSARY are
not used for SCTP (nor in the TX path at all); nevertheless, IPVS snat/dnat
actually set CHECKSUM_UNNECESSARY on SCTP packets after the checksum is
updated (see 97203abe6bc4 "net: ipvs: sctp: do not recalc...).
I'm not sure if setting CHECKSUM_UNNECESSARY fits my case, because this would
implicitly skip RX validation when using devices like veth or loopback.
[2] Documentation/networking/checksum_offloads.txt
regards,
On Mon, 2017-02-27 at 07:11 -0800, Tom Herbert wrote:
CHECKSUM_PARTIAL is the preferred mechanism on the transmit path this
defers defers the checksum computation as long as possible.
Unfortunately, if SCTP is encapsulated in UDP we will probably need to
run the SCTP CRC on the host which will be done with your changes to
skb_checksum_help.
right. Tunnel devices have NETIF_F_SCTP_CRC bit cleared and
NETIF_F_HW_CSUM bit set: so, in this case csum_not_inet can help
recovering non-GSO SCTP packets having ip_summed equal to
CHECKSUM_PARTIAL.
quoted
I'm not sure if setting CHECKSUM_UNNECESSARY fits my case, because this would
implicitly skip RX validation when using devices like veth or loopback.
CHECKSUM_UNNECESSARY can be used in the transmit path (really the
forwarding path), however this I think this must imply that the
checksum in the packet must be correct. Please see my post about
drivers that are mistakingly using CHECKSUM_UNNECESSARY with LRO since
the checksum in the packet sent into the stack is not correct.
Ok, now I'm more convinced to use CHECKSUM_NONE :-)
thank you for the attention!
regards
skb_sctp_csum_help is like skb_checksum_help, but it is designed for
checksumming SCTP packets using crc32c (see RFC3309), provided that
sctp.ko has been loaded before. In case sctp.ko is not loaded, invoking
skb_sctp_csum_help on a skb results in the following printout:
sk_buff: attempt to compute crc32c without sctp.ko
Signed-off-by: Davide Caratti <redacted>
---
include/linux/netdevice.h | 1 +
include/linux/skbuff.h | 3 ++-
net/core/dev.c | 40 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 43 insertions(+), 1 deletion(-)
@@ -2578,6 +2579,45 @@ int skb_checksum_help(struct sk_buff *skb)}EXPORT_SYMBOL(skb_checksum_help);+intskb_sctp_csum_help(structsk_buff*skb)+{+__le32crc32c_csum;+intret=0,offset;++if(skb->ip_summed!=CHECKSUM_PARTIAL)+gotoout;++if(unlikely(skb_is_gso(skb)))+gotoout;++/* Before computing a checksum, we should make sure no frag could+*bemodifiedbyanexternalentity:checksumcouldbewrong.+*/+if(unlikely(skb_has_shared_frag(skb))){+ret=__skb_linearize(skb);+if(ret)+gotoout;+}++offset=skb_checksum_start_offset(skb);+crc32c_csum=cpu_to_le32(~__skb_checksum(skb,offset,+skb->len-offset,~(__u32)0,+sctp_csum_stub));+offset+=offsetof(structsctphdr,checksum);+BUG_ON(offset>=skb_headlen(skb));++if(skb_cloned(skb)&&+!skb_clone_writable(skb,offset+sizeof(__le32))){+ret=pskb_expand_head(skb,0,0,GFP_ATOMIC);+if(ret)+gotoout;+}+*(__le32*)(skb->data+offset)=crc32c_csum;+skb->ip_summed=CHECKSUM_NONE;+out:+returnret;+}+__be16skb_network_protocol(structsk_buff*skb,int*depth){__be16type=skb->protocol;
sctp_compute_checksum requires crc32c symbol (provided by libcrc32c), so
it can't be used in net core. Like it has been done previously with other
symbols (e.g. ipv6_dst_lookup), introduce a stub struct skb_checksum_ops
to allow computation of SCTP checksum in net core after sctp.ko (and thus
libcrc32c) has been loaded.
Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: Davide Caratti <redacted>
---
include/linux/skbuff.h | 2 ++
net/core/skbuff.c | 20 ++++++++++++++++++++
net/sctp/offload.c | 7 +++++++
3 files changed, 29 insertions(+)
@@ -2242,6 +2242,26 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,}EXPORT_SYMBOL(skb_copy_and_csum_bits);+static__wsumwarn_sctp_csum_update(constvoid*buff,intlen,__wsumsum)+{+net_warn_ratelimited("attempt to compute crc32c without sctp.ko\n");+return0;+}++static__wsumwarn_sctp_csum_combine(__wsumcsum,__wsumcsum2,+intoffset,intlen)+{+net_warn_ratelimited("attempt to compute crc32c without sctp.ko\n");+return0;+}++conststructskb_checksum_ops*sctp_csum_stub__read_mostly=+&(structskb_checksum_ops){+.update=warn_sctp_csum_update,+.combine=warn_sctp_csum_combine,+};+EXPORT_SYMBOL(sctp_csum_stub);+/***skb_zerocopy_headlen-Calculateheadroomneededforskb_zerocopy()*@from:sourcebuffer
Introduce skb->csum_not_inet to identify not-yet-checksummed SCTP packets.
Use this bit in combination with netdev feature bit in validate_xmit_skb,
to discriminate whether skb needs crc32c or 2-complement Internet Checksum
(or none of the two, when the underlying device can do checksum offload).
Signed-off-by: Davide Caratti <redacted>
---
include/linux/skbuff.h | 1 +
net/core/dev.c | 14 ++++++++++++--
net/netfilter/ipvs/ip_vs_proto_sctp.c | 1 +
net/netfilter/nf_nat_proto_sctp.c | 1 +
net/sched/act_csum.c | 1 +
net/sctp/output.c | 1 +
6 files changed, 17 insertions(+), 2 deletions(-)
Add description of skb_sctp_csum_help in networking/checksum-offload.txt,
and document its usage in combination with skb->csum_not_inet. While at
it, remove reference to skb_csum_off_chk* functions, since they have been
removed from Linux source tree since commit cf53b1da73bd ("Revert "net:
Add driver helper functions to determine checksum""), and add missing
explaination of CHECKSUM_UNNECESSARY for FCOE protocol.
Signed-off-by: Davide Caratti <redacted>
---
Documentation/networking/checksum-offloads.txt | 7 ++++---
include/linux/skbuff.h | 25 ++++++++++++-------------
2 files changed, 16 insertions(+), 16 deletions(-)
@@ -49,8 +49,8 @@ A driver declares its offload capabilities in netdev->hw_features; see and csum_offset given in the SKB; if it tries to deduce these itself in hardware (as some NICs do) the driver should check that the values in the SKB match those which the hardware will deduce, and if not, fall back to- checksumming in software instead (with skb_checksum_help or one of the- skb_csum_off_chk* functions as mentioned in include/linux/skbuff.h). This+ checksumming in software instead (with skb_checksum_help or+ skb_sctp_csum_help functions as mentioned in include/linux/skbuff.h). This is a pain, but that's what you get when hardware tries to be clever. The stack should, for the most part, assume that checksum offload is
@@ -60,7 +60,8 @@ The stack should, for the most part, assume that checksum offload is may include other offloads besides TX Checksum Offload) and, if they are not supported or enabled on the device (determined by netdev->features), performs the corresponding offload in software. In the case of TX- Checksum Offload, that means calling skb_checksum_help(skb).+ Checksum Offload, that means calling skb_sctp_csum_help(skb) for SCTP+ packets, and skb_checksum_help(skb) for other packets. LCO: Local Checksum Offload
From: Tom Herbert <hidden> Date: 2017-02-28 19:51:41
On Tue, Feb 28, 2017 at 2:32 AM, Davide Caratti [off-list ref] wrote:
quoted hunk
Introduce skb->csum_not_inet to identify not-yet-checksummed SCTP packets.
Use this bit in combination with netdev feature bit in validate_xmit_skb,
to discriminate whether skb needs crc32c or 2-complement Internet Checksum
(or none of the two, when the underlying device can do checksum offload).
Signed-off-by: Davide Caratti <redacted>
---
include/linux/skbuff.h | 1 +
net/core/dev.c | 14 ++++++++++++--
net/netfilter/ipvs/ip_vs_proto_sctp.c | 1 +
net/netfilter/nf_nat_proto_sctp.c | 1 +
net/sched/act_csum.c | 1 +
net/sctp/output.c | 1 +
6 files changed, 17 insertions(+), 2 deletions(-)
Unfortunately this potentially pushes the skbuf flags over 32 bits if
I count correctly. I suggest that you rename csum_bad to
csum_not_inet. Looks like csum_bad is only set by a grand total of one
driver and I don't believe that is enough to justify its existence.
It's probably a good time to remove it.
quoted hunk
#ifdef CONFIG_NET_SCHED
__u16 tc_index; /* traffic control index */
From: Alexander Duyck <hidden> Date: 2017-02-28 23:13:55
On Tue, Feb 28, 2017 at 2:32 AM, Davide Caratti [off-list ref] wrote:
sctp_compute_checksum requires crc32c symbol (provided by libcrc32c), so
it can't be used in net core. Like it has been done previously with other
symbols (e.g. ipv6_dst_lookup), introduce a stub struct skb_checksum_ops
to allow computation of SCTP checksum in net core after sctp.ko (and thus
libcrc32c) has been loaded.
At a minimum the name really needs to change. SCTP does not do
checksums. It does a CRC, and a CRC is a very different thing. The
fact that somebody decided that offloading a CRC could use the same
framework is very unfortunate, and your patch descriptions in this
whole set are calling out a CRC as checksums which it is not.
I don't want to see anything "checksum" or "csum" related in the
naming when it comes to dealing with SCTP unless we absolutely have to
have it. So any function names or structures with sctp in the name
should call out "crc32" or "crc", please don't use checksum.
@@ -2242,6 +2242,26 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,}EXPORT_SYMBOL(skb_copy_and_csum_bits);+static__wsumwarn_sctp_csum_update(constvoid*buff,intlen,__wsumsum)+{+net_warn_ratelimited("attempt to compute crc32c without sctp.ko\n");+return0;+}++static__wsumwarn_sctp_csum_combine(__wsumcsum,__wsumcsum2,+intoffset,intlen)+{+net_warn_ratelimited("attempt to compute crc32c without sctp.ko\n");+return0;+}++conststructskb_checksum_ops*sctp_csum_stub__read_mostly=+&(structskb_checksum_ops){+.update=warn_sctp_csum_update,+.combine=warn_sctp_csum_combine,+};+EXPORT_SYMBOL(sctp_csum_stub);+/***skb_zerocopy_headlen-Calculateheadroomneededforskb_zerocopy()*@from:sourcebuffer
From: Tom Herbert <hidden> Date: 2017-03-01 03:17:59
On Tue, Feb 28, 2017 at 2:46 PM, Alexander Duyck
[off-list ref] wrote:
On Tue, Feb 28, 2017 at 2:32 AM, Davide Caratti [off-list ref] wrote:
quoted
sctp_compute_checksum requires crc32c symbol (provided by libcrc32c), so
it can't be used in net core. Like it has been done previously with other
symbols (e.g. ipv6_dst_lookup), introduce a stub struct skb_checksum_ops
to allow computation of SCTP checksum in net core after sctp.ko (and thus
libcrc32c) has been loaded.
At a minimum the name really needs to change. SCTP does not do
checksums. It does a CRC, and a CRC is a very different thing. The
fact that somebody decided that offloading a CRC could use the same
framework is very unfortunate, and your patch descriptions in this
whole set are calling out a CRC as checksums which it is not.
I don't want to see anything "checksum" or "csum" related in the
naming when it comes to dealing with SCTP unless we absolutely have to
have it. So any function names or structures with sctp in the name
should call out "crc32" or "crc", please don't use checksum.
Alexander,
I agree that internal functions to sctp should not refer to checksum,
but I think we need to take care to be consistent with any external
API (even if somebody made a mistake defining it this way :-) ). As
you know the checksum interface must be very precisely defined, there
is no leeway for ambiguity. Many places in the stack use csum and
CHECKSUM_* to refer to the API not the actual algorithm, others don't
(e.g. CHECKSUM_UNNECESSARY can apply to SCTP checksum,
CHECKSUM_COMPLETE must be an Internet checksum).
For instance, in that light skb_sctp_csum_help is appropriately named
I think because this is being called from skb_csum_help and refers to
the interface to resolve a checksum.
Tom
@@ -2242,6 +2242,26 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,}EXPORT_SYMBOL(skb_copy_and_csum_bits);+static__wsumwarn_sctp_csum_update(constvoid*buff,intlen,__wsumsum)+{+net_warn_ratelimited("attempt to compute crc32c without sctp.ko\n");+return0;+}++static__wsumwarn_sctp_csum_combine(__wsumcsum,__wsumcsum2,+intoffset,intlen)+{+net_warn_ratelimited("attempt to compute crc32c without sctp.ko\n");+return0;+}++conststructskb_checksum_ops*sctp_csum_stub__read_mostly=+&(structskb_checksum_ops){+.update=warn_sctp_csum_update,+.combine=warn_sctp_csum_combine,+};+EXPORT_SYMBOL(sctp_csum_stub);+/***skb_zerocopy_headlen-Calculateheadroomneededforskb_zerocopy()*@from:sourcebuffer
From: David Laight <hidden> Date: 2017-03-01 10:55:20
From: Alexander Duyck
Sent: 28 February 2017 22:46
...
I don't want to see anything "checksum" or "csum" related in the
naming when it comes to dealing with SCTP unless we absolutely have to
have it. So any function names or structures with sctp in the name
should call out "crc32" or "crc", please don't use checksum.
Then also change all the places that refer the IP 1's compliment
checksum to ipchecksum.
David
On Tue, 2017-02-28 at 14:46 -0800, Alexander Duyck wrote:
On Tue, Feb 28, 2017 at 2:32 AM, Davide Caratti [off-list ref] wrote:
quoted
sctp_compute_checksum requires crc32c symbol (provided by libcrc32c), so
it can't be used in net core. Like it has been done previously with other
symbols (e.g. ipv6_dst_lookup), introduce a stub struct skb_checksum_ops
to allow computation of SCTP checksum in net core after sctp.ko (and thus
libcrc32c) has been loaded.
At a minimum the name really needs to change. SCTP does not do
checksums. It does a CRC, and a CRC is a very different thing. The
fact that somebody decided that offloading a CRC could use the same
framework is very unfortunate, and your patch descriptions in this
whole set are calling out a CRC as checksums which it is not.
I don't want to see anything "checksum" or "csum" related in the
naming when it comes to dealing with SCTP unless we absolutely have
to have it. So any function names or structures with sctp in the name
should call out "crc32" or "crc", please don't use checksum.
On Wed, 2017-03-01 at 10:53 +0000, David Laight wrote:
Then also change all the places that refer the IP 1's compliment
checksum to ipchecksum.
(but crc32 uses a different polynomial than crc32c! :-) ) I understand
your concerns, nevertheless we are writing to a member of struct sctphdr
whose name is 'checksum' since the earliest introduction of SCTP; moreover,
similar terminology ('crc32c checksum') is used throughout all RFC4960.
That's why I don't think anybody will be confused by usage of 'csum' or
'checksum' words.
On Tue, 2017-02-28 at 19:17 -0800, Tom Herbert wrote:
I agree that internal functions to sctp should not refer to checksum,
but I think we need to take care to be consistent with any external
API (even if somebody made a mistake defining it this way :-) ). As
you know the checksum interface must be very precisely defined, there
is no leeway for ambiguity.
We can make the new symbols more generic removing 'sctp' from the
symbol name, and writing explicitly that skb needs crc32c (rather than
skb does not need internet checksum).
Proposal:
we use crc32c, possibly combined with 'csum' or 'checksum', just like
it has been done in RFC4960. So, symbol names can be replaced as follows:
RFC v2 name | RFC v3 name
-------------------------+-----------------------------
warn_sctp_csum_update | warn_crc32c_csum_update
warn_sctp_csum_combine | warn_crc32c_csum_combine
sctp_csum_stub | crc32c_csum_stub
sctp_csum_ops | crc32c_csum_ops
skb_sctp_csum_help | skb_crc32c_csum_help
skb->csum_not_inet | skb->crc32c_csum
please let me know if the proposal can be acceptable from your point of view.
On Tue, 2017-02-28 at 11:50 -0800, Tom Herbert wrote:
Unfortunately this potentially pushes the skbuf flags over 32 bits if
I count correctly. I suggest that you rename csum_bad to
csum_not_inet. Looks like csum_bad is only set by a grand total of one
driver and I don't believe that is enough to justify its existence.
It's probably a good time to remove it.
you are right: find below the current layout obtained with 'allyesconfig':
short unsigned int queue_mapping; /* 140 2 */
unsigned char __cloned_offset[0]; /* 142 0 */
unsigned char cloned:1; /* 142: 7 1 */
unsigned char nohdr:1; /* 142: 6 1 */
unsigned char fclone:2; /* 142: 4 1 */
unsigned char peeked:1; /* 142: 3 1 */
unsigned char head_frag:1; /* 142: 2 1 */
unsigned char xmit_more:1; /* 142: 1 1 */
unsigned char __unused:1; /* 142: 0 1 */
/* XXX 1 byte hole, try to pack */
unsigned int headers_start[0]; /* 144 0 */
unsigned char __pkt_type_offset[0]; /* 144 0 */
unsigned char pkt_type:3; /* 144: 5 1 */
<...>
unsigned char ipvs_property:1; /* 147: 7 1 */
unsigned char inner_protocol_type:1; /* 147: 6 1 */
unsigned char remcsum_offload:1; /* 147: 5 1 */
unsigned char offload_fwd_mark:1; /* 147: 4 1 */
unsigned char tc_skip_classify:1; /* 147: 3 1 */
unsigned char tc_at_ingress:1; /* 147: 2 1 */
unsigned char tc_redirected:1; /* 147: 1 1 */
unsigned char tc_from_ingress:1; /* 147: 0 1 */
short unsigned int tc_index; /* 148 2 */
/* XXX 2 bytes hole, try to pack */
union {
unsigned int csum; /* 4 */
struct {
short unsigned int csum_start; /* 152 2 */
short unsigned int csum_offset; /* 154 2 */
}; /* 4 */
} /* 152 4 */
skb->tc_from_ingress is the last element of the 32 bits starting at
skb->pkt_type. There are 16 bits free before skb->csum, and 9 free bits
before skb->pkt_type. I don't think I can easily make room by removing
'csum_bad' as per your suggestion, because it is used by GRO and
netfilter code also (see users of __skb_mark_checksum_bad()). So, either
I place 'csum_not_inet' in one of the two above intervals (i.e replacing
__unused with csum_not_inet AKA crc32c_csum), or I have to give up the
(good) idea of using a bit in sk_buff.
BTW: unlike what I see with other NICs, using ixgbe driver I don't see
corrupted L4 packets, even when SCTP CRC offload is turned off. Looking
at the code, I see ixgbe_tx_csum does a simple test to identify SCTP in
packets with CHECKSUM_PARTIAL and have their checksum resolved by the
hardware:
switch (skb->csum_offset) {
case offsetof(struct tcphdr, check):
/* it's TCP */
/* fall-through */
case offsetof(struct udphdr, check)
/* it's UDP */
break;
case offsetof(struct scphdr, checksum):
if (/* an ipv4 or ipv6 header with protocol equal to
* IPPOROTO_SCTP is found
*/)
/* it's SCTP */
break;
}
/* fall through */
default:
skb_checksum_help(skb);
}
The above code is functionally similar to what I did in patch 4/5 of the
initial series (http://www.spinics.net/lists/linux-sctp/msg05608.html).
Should we consider it again for fixing wrong CRC32c issues in case using
a bit in struct sk_buff is not viable?
On Tue, 2017-02-28 at 11:50 -0800, Tom Herbert wrote:
Return value looks complex. Maybe we should just change
skb_csum_*_help to return bool, true of checksum was handled false if
not.
These functions can return -EINVAL if skb is a GSO packet, or -ENOMEM if
skb_linearize(skb) or pskb_expand_head(skb) fail, or 0. I would preserve the
return value of skb_checksum_help() and provide similar range of return values
for skb_sctp_csum_help() (also known as skb_crc32c_csum_help()): this can
help eventual future attempts to remove skb_warn_bad_offload(). It makes
sense to make boolean the return value of skb_csum_hwoffload_help(),
since we are using it only for non-GSO packets.
Thank you in advance for the feedbacks,
regards,
From: Alexander Duyck <hidden> Date: 2017-03-07 18:43:43
On Mon, Mar 6, 2017 at 1:51 PM, Davide Caratti [off-list ref] wrote:
On Tue, 2017-02-28 at 14:46 -0800, Alexander Duyck wrote:
quoted
On Tue, Feb 28, 2017 at 2:32 AM, Davide Caratti [off-list ref] wrote:
quoted
sctp_compute_checksum requires crc32c symbol (provided by libcrc32c), so
it can't be used in net core. Like it has been done previously with other
symbols (e.g. ipv6_dst_lookup), introduce a stub struct skb_checksum_ops
to allow computation of SCTP checksum in net core after sctp.ko (and thus
libcrc32c) has been loaded.
At a minimum the name really needs to change. SCTP does not do
checksums. It does a CRC, and a CRC is a very different thing. The
fact that somebody decided that offloading a CRC could use the same
framework is very unfortunate, and your patch descriptions in this
whole set are calling out a CRC as checksums which it is not.
I don't want to see anything "checksum" or "csum" related in the
naming when it comes to dealing with SCTP unless we absolutely have
to have it. So any function names or structures with sctp in the name
should call out "crc32" or "crc", please don't use checksum.
On Wed, 2017-03-01 at 10:53 +0000, David Laight wrote:
quoted
Then also change all the places that refer the IP 1's compliment
checksum to ipchecksum.
(but crc32 uses a different polynomial than crc32c! :-) ) I understand
your concerns, nevertheless we are writing to a member of struct sctphdr
whose name is 'checksum' since the earliest introduction of SCTP; moreover,
similar terminology ('crc32c checksum') is used throughout all RFC4960.
That's why I don't think anybody will be confused by usage of 'csum' or
'checksum' words.
On Tue, 2017-02-28 at 19:17 -0800, Tom Herbert wrote:
quoted
I agree that internal functions to sctp should not refer to checksum,
but I think we need to take care to be consistent with any external
API (even if somebody made a mistake defining it this way :-) ). As
you know the checksum interface must be very precisely defined, there
is no leeway for ambiguity.
We can make the new symbols more generic removing 'sctp' from the
symbol name, and writing explicitly that skb needs crc32c (rather than
skb does not need internet checksum).
Proposal:
we use crc32c, possibly combined with 'csum' or 'checksum', just like
it has been done in RFC4960. So, symbol names can be replaced as follows:
RFC v2 name | RFC v3 name
-------------------------+-----------------------------
warn_sctp_csum_update | warn_crc32c_csum_update
warn_sctp_csum_combine | warn_crc32c_csum_combine
sctp_csum_stub | crc32c_csum_stub
sctp_csum_ops | crc32c_csum_ops
skb_sctp_csum_help | skb_crc32c_csum_help
skb->csum_not_inet | skb->crc32c_csum
please let me know if the proposal can be acceptable from your point of view.
I do like this approach better. You might even take this one step
further. You could convert crc32_csum into a 1 bit enum for now.
Basically you would use 0 for 1's compliement csum, and 1 to represent
a crc32c csum. Then if we end up having to add another bit for
something like FCoE in the future it would give us 4 possible checksum
types instead of just giving us 1 with a bit mask.
On Tue, 2017-02-28 at 11:50 -0800, Tom Herbert wrote:
quoted
Unfortunately this potentially pushes the skbuf flags over 32 bits if
I count correctly. I suggest that you rename csum_bad to
csum_not_inet. Looks like csum_bad is only set by a grand total of one
driver and I don't believe that is enough to justify its existence.
It's probably a good time to remove it.
you are right: find below the current layout obtained with 'allyesconfig':
short unsigned int queue_mapping; /* 140 2 */
unsigned char __cloned_offset[0]; /* 142 0 */
unsigned char cloned:1; /* 142: 7 1 */
unsigned char nohdr:1; /* 142: 6 1 */
unsigned char fclone:2; /* 142: 4 1 */
unsigned char peeked:1; /* 142: 3 1 */
unsigned char head_frag:1; /* 142: 2 1 */
unsigned char xmit_more:1; /* 142: 1 1 */
unsigned char __unused:1; /* 142: 0 1 */
/* XXX 1 byte hole, try to pack */
unsigned int headers_start[0]; /* 144 0 */
unsigned char __pkt_type_offset[0]; /* 144 0 */
unsigned char pkt_type:3; /* 144: 5 1 */
<...>
unsigned char ipvs_property:1; /* 147: 7 1 */
unsigned char inner_protocol_type:1; /* 147: 6 1 */
unsigned char remcsum_offload:1; /* 147: 5 1 */
unsigned char offload_fwd_mark:1; /* 147: 4 1 */
unsigned char tc_skip_classify:1; /* 147: 3 1 */
unsigned char tc_at_ingress:1; /* 147: 2 1 */
unsigned char tc_redirected:1; /* 147: 1 1 */
unsigned char tc_from_ingress:1; /* 147: 0 1 */
short unsigned int tc_index; /* 148 2 */
/* XXX 2 bytes hole, try to pack */
union {
unsigned int csum; /* 4 */
struct {
short unsigned int csum_start; /* 152 2 */
short unsigned int csum_offset; /* 154 2 */
}; /* 4 */
} /* 152 4 */
skb->tc_from_ingress is the last element of the 32 bits starting at
skb->pkt_type. There are 16 bits free before skb->csum, and 9 free bits
before skb->pkt_type. I don't think I can easily make room by removing
'csum_bad' as per your suggestion, because it is used by GRO and
netfilter code also (see users of __skb_mark_checksum_bad()). So, either
I place 'csum_not_inet' in one of the two above intervals (i.e replacing
__unused with csum_not_inet AKA crc32c_csum), or I have to give up the
(good) idea of using a bit in sk_buff.
BTW: unlike what I see with other NICs, using ixgbe driver I don't see
corrupted L4 packets, even when SCTP CRC offload is turned off. Looking
at the code, I see ixgbe_tx_csum does a simple test to identify SCTP in
packets with CHECKSUM_PARTIAL and have their checksum resolved by the
hardware:
switch (skb->csum_offset) {
case offsetof(struct tcphdr, check):
/* it's TCP */
/* fall-through */
case offsetof(struct udphdr, check)
/* it's UDP */
break;
case offsetof(struct scphdr, checksum):
if (/* an ipv4 or ipv6 header with protocol equal to
* IPPOROTO_SCTP is found
*/)
/* it's SCTP */
break;
}
/* fall through */
default:
skb_checksum_help(skb);
}
The above code is functionally similar to what I did in patch 4/5 of the
initial series (http://www.spinics.net/lists/linux-sctp/msg05608.html).
Should we consider it again for fixing wrong CRC32c issues in case using
a bit in struct sk_buff is not viable?
I would say if you can't use an extra bit to indicate the checksum
type you probably don't have too much other choice.
As far as the patch you provided I would say it is a good start, but
was a bit to aggressive in a few spots. For now we don't have support
for offloading crc32c when encapsulating a frame so you don't need to
worry about that too much for now. Also as far as the features test
you should only need to find that one of the feature bits is set in
the list you were testing. What might make sense would be to look
into updating can_checksum_protocol to possibly factor in csum_offset
when determining if we can offload it or not.
On Tue, 2017-02-28 at 11:50 -0800, Tom Herbert wrote:
quoted
Return value looks complex. Maybe we should just change
skb_csum_*_help to return bool, true of checksum was handled false if
not.
These functions can return -EINVAL if skb is a GSO packet, or -ENOMEM if
skb_linearize(skb) or pskb_expand_head(skb) fail, or 0. I would preserve the
return value of skb_checksum_help() and provide similar range of return values
for skb_sctp_csum_help() (also known as skb_crc32c_csum_help()): this can
help eventual future attempts to remove skb_warn_bad_offload(). It makes
sense to make boolean the return value of skb_csum_hwoffload_help(),
since we are using it only for non-GSO packets.
Thank you in advance for the feedbacks,
regards,
--
davide
hello Alexander and Tom,
On Tue, 2017-03-07 at 10:06 -0800, Alexander Duyck wrote:
You might even take this one step
further. You could convert crc32_csum into a 1 bit enum for now.
Basically you would use 0 for 1's compliement csum, and 1 to represent
a crc32c csum. Then if we end up having to add another bit for
something like FCoE in the future it would give us 4 possible checksum
types instead of just giving us 1 with a bit mask.
<...>
I would say if you can't use an extra bit to indicate the checksum type
you probably don't have too much other choice.
Unluckily, there are no free bits in struct sk_buff (i.e. there is 1 + 8
bits after skb->xmit_more, but its content would be be lost after
__copy_skb_header() _ so simply we can't use them).
As soon as two bits in sk_buff are freed, we will be able to rely on the
skb metadata, instead of inspecting the packet headers, to understand
what algorithm is used to ensure data integrity in the packet.
As far as the patch you provided I would say it is a good start, but
was a bit to aggressive in a few spots. For now we don't have support
for offloading crc32c when encapsulating a frame so you don't need to
worry about that too much for now.
Ok _ so, skb_csum_hwoffload_help(skb, features) will assume that skb needs
crc32c if all the following conditions are met:
- feature bitmask does not have NETIF_F_SCTP_CRC bit set
- skb->csum_offset is equal to 8 (i.e. offsetof(struct sctphdr,checksum)).
- skb is carrying an (outer, non encapsulated) IPv4/IPv6 header with
protocol number equal to 132 (i.e. IPPROTO_SCTP)
In any other case, we will compute the internet checksum or do nothing _
just what it's happening right now for non-GSO packets reaching
validate_xmit_skb(). I think this implementation can be extended to the
FCoE case if needed.
Also as far as the features test
you should only need to find that one of the feature bits is set in
the list you were testing. What might make sense would be to look
into updating can_checksum_protocol to possibly factor in csum_offset
when determining if we can offload it or not.
Looking again at the code, I noticed that the number of test on 'features'
bits can be reduced: see below.
can_checksum_protocol() takes an ethertype as parameter, so we would need
to invent a non-standardized valure for SCTP. Moreover, it is used in
skb_segment() for GSO: so, adding extra CPU cycles would affect
performance on a path where the kernel is already showing the right
behavior (GSO SCTP packets have their CRC32 computed correctly when
sctp_gso_segment() is called).
hello Tom,
quoted
On Tue, 2017-02-28 at 11:50 -0800, Tom Herbert wrote:
quoted
Return value looks complex. Maybe we should just change
skb_csum_*_help to return bool, true of checksum was handled false if
not.
These functions can return -EINVAL if skb is a GSO packet, or -ENOMEM if
skb_linearize(skb) or pskb_expand_head(skb) fail, or 0. I would preserve the
return value of skb_checksum_help() and provide similar range of return values
for skb_sctp_csum_help() (also known as skb_crc32c_csum_help()): this can
help eventual future attempts to remove skb_warn_bad_offload(). It makes
sense to make boolean the return value of skb_csum_hwoffload_help(),
since we are using it only for non-GSO packets.
the above statement is still valid after the body of the function changed. A
very small thing: according to the kernel coding style, I should find a
'predicative' name for this function. Something like
skb_can_resolve_partial_csum(),
(which is terrible, I know)
or similar / better.
Please let me know if you think the code below is ok for you.
Thank you in advance!
regards,
--
davide
From: Tom Herbert <hidden> Date: 2017-03-18 22:43:45
On Sat, Mar 18, 2017 at 6:17 AM, Davide Caratti [off-list ref] wrote:
hello Alexander and Tom,
On Tue, 2017-03-07 at 10:06 -0800, Alexander Duyck wrote:
quoted
You might even take this one step
further. You could convert crc32_csum into a 1 bit enum for now.
Basically you would use 0 for 1's compliement csum, and 1 to represent
a crc32c csum. Then if we end up having to add another bit for
something like FCoE in the future it would give us 4 possible checksum
types instead of just giving us 1 with a bit mask.
<...>
quoted
I would say if you can't use an extra bit to indicate the checksum type
you probably don't have too much other choice.
Unluckily, there are no free bits in struct sk_buff (i.e. there is 1 + 8
bits after skb->xmit_more, but its content would be be lost after
__copy_skb_header() _ so simply we can't use them).
As soon as two bits in sk_buff are freed, we will be able to rely on the
skb metadata, instead of inspecting the packet headers, to understand
what algorithm is used to ensure data integrity in the packet.
quoted
As far as the patch you provided I would say it is a good start, but
was a bit to aggressive in a few spots. For now we don't have support
for offloading crc32c when encapsulating a frame so you don't need to
worry about that too much for now.
Ok _ so, skb_csum_hwoffload_help(skb, features) will assume that skb needs
crc32c if all the following conditions are met:
- feature bitmask does not have NETIF_F_SCTP_CRC bit set
- skb->csum_offset is equal to 8 (i.e. offsetof(struct sctphdr,checksum)).
- skb is carrying an (outer, non encapsulated) IPv4/IPv6 header with
protocol number equal to 132 (i.e. IPPROTO_SCTP)
That's too complicated. Just create a non_ip_csum bit in skbuff.
csum_bad can replaced with this I think. If the bit is set then more
work can be done to differentiate between alternative checksums.
Tom
quoted hunk
In any other case, we will compute the internet checksum or do nothing _
just what it's happening right now for non-GSO packets reaching
validate_xmit_skb(). I think this implementation can be extended to the
FCoE case if needed.
quoted
Also as far as the features test
you should only need to find that one of the feature bits is set in
the list you were testing. What might make sense would be to look
into updating can_checksum_protocol to possibly factor in csum_offset
when determining if we can offload it or not.
Looking again at the code, I noticed that the number of test on 'features'
bits can be reduced: see below.
can_checksum_protocol() takes an ethertype as parameter, so we would need
to invent a non-standardized valure for SCTP. Moreover, it is used in
skb_segment() for GSO: so, adding extra CPU cycles would affect
performance on a path where the kernel is already showing the right
behavior (GSO SCTP packets have their CRC32 computed correctly when
sctp_gso_segment() is called).
hello Tom,
quoted
quoted
On Tue, 2017-02-28 at 11:50 -0800, Tom Herbert wrote:
quoted
Return value looks complex. Maybe we should just change
skb_csum_*_help to return bool, true of checksum was handled false if
not.
These functions can return -EINVAL if skb is a GSO packet, or -ENOMEM if
skb_linearize(skb) or pskb_expand_head(skb) fail, or 0. I would preserve the
return value of skb_checksum_help() and provide similar range of return values
for skb_sctp_csum_help() (also known as skb_crc32c_csum_help()): this can
help eventual future attempts to remove skb_warn_bad_offload(). It makes
sense to make boolean the return value of skb_csum_hwoffload_help(),
since we are using it only for non-GSO packets.
the above statement is still valid after the body of the function changed. A
very small thing: according to the kernel coding style, I should find a
'predicative' name for this function. Something like
skb_can_resolve_partial_csum(),
(which is terrible, I know)
or similar / better.
Please let me know if you think the code below is ok for you.
Thank you in advance!
regards,
--
davide
On Tue, 2017-03-07 at 10:06 -0800, Alexander Duyck wrote:
You might even take this one step
further. You could convert crc32_csum into a 1 bit enum for now.
Basically you would use 0 for 1's compliement csum, and 1 to represent
a crc32c csum. Then if we end up having to add another bit for
something like FCoE in the future it would give us 4 possible checksum
types instead of just giving us 1 with a bit mask.
On Sat, 2017-03-18 at 15:35 -0700, Tom Herbert wrote:
Just create a non_ip_csum bit in skbuff.
csum_bad can replaced with this I think. If the bit is set then more
work can be done to differentiate between alternative checksums.
hello Alexander and Tom,
I refreshed the series including your suggestions.
Some followups are still possible:
* drivers that parse the packet header to correctly resolve CHECKSUM_PARTIAL
(e.g. ixgbe_tx_csum()) can benefit from skb->csum_algo savng some CPU cycles
(e.g. avoiding calling ip_hdr(skb)->protocol or ixgbe_ipv6_csum_is_sctp(skb)).
* drivers that call skb_checksum_help() to resolve CHECKSUM_PARTIAL can
call skb_crc32c_csum_help (or skb_csum_hwoffload_help(skb, 0)) to avoid
wrong CRC on SCTP packets.
thank you in advance for looking at this!
regards,
sctp_compute_checksum requires crc32c symbol (provided by libcrc32c), so
it can't be used in net core. Like it has been done previously with other
symbols (e.g. ipv6_dst_lookup), introduce a stub struct skb_checksum_ops
to allow computation of crc32c checksum in net core after sctp.ko (and thus
libcrc32c) has been loaded.
Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: Davide Caratti <redacted>
---
include/linux/skbuff.h | 2 ++
net/core/skbuff.c | 24 ++++++++++++++++++++++++
net/sctp/offload.c | 7 +++++++
3 files changed, 33 insertions(+)
@@ -2242,6 +2242,30 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,}EXPORT_SYMBOL(skb_copy_and_csum_bits);+static__wsumwarn_crc32c_csum_update(constvoid*buff,intlen,__wsumsum)+{+net_warn_ratelimited(+"%s: attempt to compute crc32c without libcrc32c.ko\n",+__func__);+return0;+}++static__wsumwarn_crc32c_csum_combine(__wsumcsum,__wsumcsum2,+intoffset,intlen)+{+net_warn_ratelimited(+"%s: attempt to compute crc32c without libcrc32c.ko\n",+__func__);+return0;+}++conststructskb_checksum_ops*crc32c_csum_stub__read_mostly=+&(structskb_checksum_ops){+.update=warn_crc32c_csum_update,+.combine=warn_crc32c_csum_combine,+};+EXPORT_SYMBOL(crc32c_csum_stub);+/***skb_zerocopy_headlen-Calculateheadroomneededforskb_zerocopy()*@from:sourcebuffer
skb_crc32c_csum_help is like skb_checksum_help, but it is designed for
checksumming SCTP packets using crc32c (see RFC3309), provided that
libcrc32c.ko has been loaded before. In case libcrc32c is not loaded,
invoking skb_crc32c_csum_help on a skb results in one the following
printouts:
warn_crc32c_csum_update: attempt to compute crc32c without libcrc32c.ko
warn_crc32c_csum_combine: attempt to compute crc32c without libcrc32c.ko
Signed-off-by: Davide Caratti <redacted>
---
include/linux/netdevice.h | 1 +
include/linux/skbuff.h | 3 ++-
net/core/dev.c | 40 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 43 insertions(+), 1 deletion(-)
@@ -2606,6 +2607,45 @@ int skb_checksum_help(struct sk_buff *skb)}EXPORT_SYMBOL(skb_checksum_help);+intskb_crc32c_csum_help(structsk_buff*skb)+{+__le32crc32c_csum;+intret=0,offset;++if(skb->ip_summed!=CHECKSUM_PARTIAL)+gotoout;++if(unlikely(skb_is_gso(skb)))+gotoout;++/* Before computing a checksum, we should make sure no frag could+*bemodifiedbyanexternalentity:checksumcouldbewrong.+*/+if(unlikely(skb_has_shared_frag(skb))){+ret=__skb_linearize(skb);+if(ret)+gotoout;+}++offset=skb_checksum_start_offset(skb);+crc32c_csum=cpu_to_le32(~__skb_checksum(skb,offset,+skb->len-offset,~(__u32)0,+crc32c_csum_stub));+offset+=offsetof(structsctphdr,checksum);+BUG_ON(offset>=skb_headlen(skb));++if(skb_cloned(skb)&&+!skb_clone_writable(skb,offset+sizeof(__le32))){+ret=pskb_expand_head(skb,0,0,GFP_ATOMIC);+if(ret)+gotoout;+}+*(__le32*)(skb->data+offset)=crc32c_csum;+skb->ip_summed=CHECKSUM_NONE;+out:+returnret;+}+__be16skb_network_protocol(structsk_buff*skb,int*depth){__be16type=skb->protocol;
This bit was introduced with 5a21232983aa ("net: Support for csum_bad in
skbuff") to reduce the stack workload when processing RX packets carrying
a wrong Internet Checksum. Up to now, only one driver (besides GRO core)
are setting it.
The test on NAPI_GRO_CB(skb)->flush in dev_gro_receive() is now done
before the test on same_flow, to preserve behavior in case of wrong
checksum.
Suggested-by: Tom Herbert <redacted>
Signed-off-by: Davide Caratti <redacted>
---
drivers/net/ethernet/aquantia/atlantic/aq_ring.c | 2 +-
include/linux/netdevice.h | 4 +---
include/linux/skbuff.h | 23 ++---------------------
net/bridge/netfilter/nft_reject_bridge.c | 5 +----
net/core/dev.c | 8 +++-----
net/ipv4/netfilter/nf_reject_ipv4.c | 2 +-
net/ipv6/netfilter/nf_reject_ipv6.c | 3 ---
7 files changed, 9 insertions(+), 38 deletions(-)
@@ -222,7 +222,7 @@ int aq_ring_rx_clean(struct aq_ring_s *self, int *work_done, int budget)skb->protocol=eth_type_trans(skb,ndev);if(unlikely(buff->is_cso_err)){++self->stats.rx.errors;-__skb_mark_checksum_bad(skb);+skb->ip_summed=CHECKSUM_NONE;}else{if(buff->is_ip_cso){__skb_incr_checksum_unnecessary(skb);
@@ -742,7 +742,7 @@ struct sk_buff {__u8csum_valid:1;__u8csum_complete_sw:1;__u8csum_level:2;-__u8csum_bad:1;+__u8__unused:1;/* one bit hole */__u8dst_pending_confirm:1;#ifdef CONFIG_IPV6_NDISC_NODETYPE
@@ -3386,21 +3386,6 @@ static inline void __skb_incr_checksum_unnecessary(struct sk_buff *skb)}}-staticinlinevoid__skb_mark_checksum_bad(structsk_buff*skb)-{-/* Mark current checksum as bad (typically called from GRO-*path).Inthecasethatip_summedisCHECKSUM_NONE-*thismustbethefirstchecksumencounteredinthepacket.-*Whenip_summedisCHECKSUM_UNNECESSARY,thisisthefirst-*checksumafterthelastonevalidated.ForUDP,azero-*checksumcannotbemarkedasbad.-*/--if(skb->ip_summed==CHECKSUM_NONE||-skb->ip_summed==CHECKSUM_UNNECESSARY)-skb->csum_bad=1;-}-/* Check if we need to perform checksum complete validation.**Returnstrueifchecksumcompleteisneeded,falseotherwise
@@ -3454,9 +3439,6 @@ static inline __sum16 __skb_checksum_validate_complete(struct sk_buff *skb,skb->csum_valid=1;return0;}-}elseif(skb->csum_bad){-/* ip_summed == CHECKSUM_NONE in this case */-return(__force__sum16)1;}skb->csum=psum;
skb->csum_algo carries the indication on which algorithm is needed to
compute checksum on skb in the transmit path, when skb->ip_summed is
equal to CHECKSUM_PARTIAL. If skb carries a SCTP packet and crc32c
hasn't been yet written in L4 header, skb->csum_algo is assigned to
CRC32C_CHECKSUM. In any other case, skb->csum_algo is set to
INTERNET_CHECKSUM.
Suggested-by: Tom Herbert <redacted>
Signed-off-by: Davide Caratti <redacted>
---
include/linux/skbuff.h | 28 ++++++++++++++++++++--------
net/core/dev.c | 2 +-
net/netfilter/ipvs/ip_vs_proto_sctp.c | 2 +-
net/netfilter/nf_nat_proto_sctp.c | 2 +-
net/sched/act_csum.c | 2 +-
net/sctp/offload.c | 2 +-
net/sctp/output.c | 3 ++-
7 files changed, 27 insertions(+), 14 deletions(-)
skb_csum_hwoffload_help() uses netdev features and skb->csum_algo to
determine if skb needs software computation of Internet Checksum or crc32c
(or nothing, if this computation can be done by the hardware). Use it in
place of skb_checksum_help() in validate_xmit_skb() to avoid corruption
of non-GSO SCTP packets having skb->ip_summed equal to CHECKSUM_PARTIAL.
While at it, remove references to skb_csum_off_chk* functions, since they
are not present anymore in Linux since commit cf53b1da73bd ('Revert "net:
Add driver helper functions to determine checksum"').
Signed-off-by: Davide Caratti <redacted>
---
Documentation/networking/checksum-offloads.txt | 12 ++++++++----
include/linux/netdevice.h | 3 +++
include/linux/skbuff.h | 11 ++++-------
net/core/dev.c | 14 ++++++++++++--
4 files changed, 27 insertions(+), 13 deletions(-)
@@ -35,6 +35,10 @@ This interface only allows a single checksum to be offloaded. Where encapsulation is used, the packet may have multiple checksum fields in different header layers, and the rest will have to be handled by another mechanism such as LCO or RCO.+CRC can also be offloaded using this interface, by means of filling+ skb->csum_start and skb->csum_offset as described above, and setting+ skb->csum_algo to values different than INTERNET_CHECKSUM: see skbuff.h+ comment (section 'D') for more details. No offloading of the IP header checksum is performed; it is always done in software. This is OK because when we build the IP header, we obviously have it in cache, so summing it isn't expensive. It's also rather short.
@@ -49,9 +53,9 @@ A driver declares its offload capabilities in netdev->hw_features; see and csum_offset given in the SKB; if it tries to deduce these itself in hardware (as some NICs do) the driver should check that the values in the SKB match those which the hardware will deduce, and if not, fall back to- checksumming in software instead (with skb_checksum_help or one of the- skb_csum_off_chk* functions as mentioned in include/linux/skbuff.h). This- is a pain, but that's what you get when hardware tries to be clever.+ checksumming in software instead (with skb_csum_hwoffload_help() or one of+ the skb_checksum_help() / skb_crc32c_csum_help functions, as mentioned in+ include/linux/skbuff.h). The stack should, for the most part, assume that checksum offload is supported by the underlying device. The only place that should check is
@@ -60,7 +64,7 @@ The stack should, for the most part, assume that checksum offload is may include other offloads besides TX Checksum Offload) and, if they are not supported or enabled on the device (determined by netdev->features), performs the corresponding offload in software. In the case of TX- Checksum Offload, that means calling skb_checksum_help(skb).+ Checksum Offload, that means calling skb_csum_hwoffload_help(skb, features). LCO: Local Checksum Offload
if skb carries an SCTP packet and ip_summed is CHECKSUM_PARTIAL, it needs
CRC32c in place of Internet Checksum: use skb_csum_hwoffload_help to avoid
corrupting such packets while queueing them towards userspace.
Signed-off-by: Davide Caratti <redacted>
---
net/openvswitch/datapath.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -453,7 +453,7 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,/* Complete checksum if needed */if(skb->ip_summed==CHECKSUM_PARTIAL&&-(err=skb_checksum_help(skb)))+(err=skb_csum_hwoffload_help(skb,0)))gotoout;/* Older versions of OVS user space enforce alignment of the last
Add FCoE to the list of protocols that can set CHECKSUM_UNNECESSARY; add a
note to CHECKSUM_COMPLETE section to specify that it does not apply to SCTP
and FCoE protocols.
Suggested-by: Tom Herbert <redacted>
Signed-off-by: Davide Caratti <redacted>
---
include/linux/skbuff.h | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
From: Tom Herbert <hidden> Date: 2017-04-07 15:43:53
On Fri, Apr 7, 2017 at 7:16 AM, Davide Caratti [off-list ref] wrote:
quoted hunk
skb->csum_algo carries the indication on which algorithm is needed to
compute checksum on skb in the transmit path, when skb->ip_summed is
equal to CHECKSUM_PARTIAL. If skb carries a SCTP packet and crc32c
hasn't been yet written in L4 header, skb->csum_algo is assigned to
CRC32C_CHECKSUM. In any other case, skb->csum_algo is set to
INTERNET_CHECKSUM.
Suggested-by: Tom Herbert <redacted>
Signed-off-by: Davide Caratti <redacted>
---
include/linux/skbuff.h | 28 ++++++++++++++++++++--------
net/core/dev.c | 2 +-
net/netfilter/ipvs/ip_vs_proto_sctp.c | 2 +-
net/netfilter/nf_nat_proto_sctp.c | 2 +-
net/sched/act_csum.c | 2 +-
net/sctp/offload.c | 2 +-
net/sctp/output.c | 3 ++-
7 files changed, 27 insertions(+), 14 deletions(-)
@@ -742,8 +744,10 @@ struct sk_buff {__u8csum_valid:1;__u8csum_complete_sw:1;__u8csum_level:2;-__u8__unused:1;/* one bit hole */-+enum{+INTERNET_CHECKSUM=0,+CRC32C_CHECKSUM,+}csum_algo:1;
I am worried this opens the door to a new open ended functionality
that will be rarely used in practice. Checksum offload is pervasive,
CRC offload is still a very narrow use case. Adding yet more
CRC/checksum variants will need more bits. It may be sufficient for
now just to make this a single bit which indicates "ones' checksum" or
indicates "other". In this case of "other" we need some analysis so
determine which checksum it is, this might be something that flow
dissector could support.
The old code is better. CHECKSUM_UNNECESSARY already applies to non IP
checksums. There is nothing special about crc32 in this regard and
skb->csum_algo should only be valid when skb->ip_summed ==
CHECKSUM_PARTIAL so no need to set it here. This point should also be
in documentation.
I am worried this opens the door to a new open ended functionality
that will be rarely used in practice. Checksum offload is pervasive,
CRC offload is still a very narrow use case.
thank you for the prompt response. I thought there was a silent
agreement on that - Alexander proposed usage of an enum bitfield to be
ready for FCoE (and I'm not against it, unless I have to find a second
free bit in struct sk_buff :-) ). But maybe I'm misunderstanding your
concern: is it the name of the variable, (csum_algo instead of
crc32c_csum), or the usage of enum bitfield (or both?) ?
On Fri, 2017-04-07 at 08:43 -0700, Tom Herbert wrote:
Adding yet more
CRC/checksum variants will need more bits. It may be sufficient for
now just to make this a single bit which indicates "ones' checksum" or
indicates "other". In this case of "other" we need some analysis so
determine which checksum it is, this might be something that flow
dissector could support.
... which is my intent: by the way, from my perspective, we don't need more than 1 bit
to extend the functionality. While reviewing my code, I was also considering
extending the witdth of skb->ip_summed from 2 to 3 bit, so that it was possible
to
#define
CRC32C_PARTIAL <- for SCTP
CRC_PARTIAL <- for FCoE
CHECKSUM_PARTIAL <- for everything else
It's conceptually the same thing, and the free bit is used more
efficiently. But then I would need to check all places where
CHECKSUM_PARTIAL is used in assignments and test: so, I told myself it's
not worth doing it until somebody requests to extend this functionality to
FCoE.
This seems odd to me. skb->csum_algo and skb->ip_summed always end up
having the same value.
this is accidentally true for CHEKSUM_NONE and CHECKSUM_PARTIAL, and only
if skb carries a SCTP packet. This was my intent:
ip_summed (2 bit) | csum_algo (1 bit)
---------------------------------------+-------------------
CHEKSUM_NONE = 0 | INTERNET_CHECKSUM = 0
CHECKSUM_PARTIAL = 1 | CRC32C_CHECKSUM = 1
CHECKSUM_COMPLETE = 2 (not applicable) | INTERNET_CHECKSUM = 0 (don't care)
CHECKSUM_UNNECESSARY = 3 | INTERNET_CHECKSUM = 0
I can do this in a more explicit way, changing the prototype to
static inline void skb_set_crc32c_ipsummed(struct sk_buff *skb,
const u8 ip_summed,
const u8 csum_algo)
(with the advantage of saving a test on the value of ip_summed).
Find in the comment below the reason why I'm clearing csum_algo every time
the SCTP CRC32c is computed.
The old code is better. CHECKSUM_UNNECESSARY already applies to non IP
checksums. There is nothing special about crc32 in this regard and
skb->csum_algo should only be valid when skb->ip_summed ==
CHECKSUM_PARTIAL so no need to set it here. This point should also be
in documentation.
In my understanding, csum_algo needs to be set to INTERNET_CHECKSUM after the
CRC32c is computed. Otherwise, after subsequent operation on the skb (e.g. it
is encapsulated in a UDP frame), there is the possibility for skb->ip_summed
to become CHECKSUM_PARTIAL again. So, to ensure that skb_checksum_help() and
not skb_crc32c_help() will be called, csum_algo must be 0.
To minimize the impact of the patch, I substituted all assignments of skb->ip_summed,
done by SCTP-related code, with calls to skb_set_crc32c_ipsummed(). The alternative is
to explicitly set csum_algo to 0 (INTERNET_CHECKSUM) in SCTP-related code. Do you agree?
thank you in advance,
regards
I am worried this opens the door to a new open ended functionality
that will be rarely used in practice. Checksum offload is pervasive,
CRC offload is still a very narrow use case.
thank you for the prompt response. I thought there was a silent
agreement on that - Alexander proposed usage of an enum bitfield to be
ready for FCoE (and I'm not against it, unless I have to find a second
free bit in struct sk_buff :-) ). But maybe I'm misunderstanding your
concern: is it the name of the variable, (csum_algo instead of
crc32c_csum), or the usage of enum bitfield (or both?) ?
On Fri, 2017-04-07 at 08:43 -0700, Tom Herbert wrote:
quoted
Adding yet more
CRC/checksum variants will need more bits. It may be sufficient for
now just to make this a single bit which indicates "ones' checksum" or
indicates "other". In this case of "other" we need some analysis so
determine which checksum it is, this might be something that flow
dissector could support.
... which is my intent: by the way, from my perspective, we don't need more than 1 bit
to extend the functionality. While reviewing my code, I was also considering
extending the witdth of skb->ip_summed from 2 to 3 bit, so that it was possible
to
Maybe just call it csum_not_ip then. Then just do "if
(unlikely(skb->csum_not_ip)) ..."
#define
CRC32C_PARTIAL <- for SCTP
CRC_PARTIAL <- for FCoE
CHECKSUM_PARTIAL <- for everything else
It's conceptually the same thing, and the free bit is used more
efficiently. But then I would need to check all places where
CHECKSUM_PARTIAL is used in assignments and test: so, I told myself it's
not worth doing it until somebody requests to extend this functionality to
FCoE.
I've thought about extending ip_summed before with something like
csum_invalid. I think it opens up a can of worms since ip_summed is
being used in so many places already and the semantics of each value
have to be extremely well defined for the whole system (this is one
place where we can't tolerate any ambiguity at all and it everything
needs to be clearly documented).
This seems odd to me. skb->csum_algo and skb->ip_summed always end up
having the same value.
this is accidentally true for CHEKSUM_NONE and CHECKSUM_PARTIAL, and only
if skb carries a SCTP packet. This was my intent:
ip_summed (2 bit) | csum_algo (1 bit)
---------------------------------------+-------------------
CHEKSUM_NONE = 0 | INTERNET_CHECKSUM = 0
CHECKSUM_PARTIAL = 1 | CRC32C_CHECKSUM = 1
CHECKSUM_COMPLETE = 2 (not applicable) | INTERNET_CHECKSUM = 0 (don't care)
CHECKSUM_UNNECESSARY = 3 | INTERNET_CHECKSUM = 0
I can do this in a more explicit way, changing the prototype to
static inline void skb_set_crc32c_ipsummed(struct sk_buff *skb,
const u8 ip_summed,
const u8 csum_algo)
(with the advantage of saving a test on the value of ip_summed).
Find in the comment below the reason why I'm clearing csum_algo every time
the SCTP CRC32c is computed.
The old code is better. CHECKSUM_UNNECESSARY already applies to non IP
checksums. There is nothing special about crc32 in this regard and
skb->csum_algo should only be valid when skb->ip_summed ==
CHECKSUM_PARTIAL so no need to set it here. This point should also be
in documentation.
In my understanding, csum_algo needs to be set to INTERNET_CHECKSUM after the
CRC32c is computed. Otherwise, after subsequent operation on the skb (e.g. it
is encapsulated in a UDP frame), there is the possibility for skb->ip_summed
to become CHECKSUM_PARTIAL again. So, to ensure that skb_checksum_help() and
not skb_crc32c_help() will be called, csum_algo must be 0.
ip_summed should no longer be CHECKSUM_PARTIAL with CRC32c is computed.
To minimize the impact of the patch, I substituted all assignments of skb->ip_summed,
done by SCTP-related code, with calls to skb_set_crc32c_ipsummed(). The alternative is
to explicitly set csum_algo to 0 (INTERNET_CHECKSUM) in SCTP-related code. Do you agree?
No, like I said the only case where this new bit is relevant is when
CHECKSUM_PARTIAL for a CRC is being done. When it's set for offloading
sctp crc it must be set. When CRC is resolved, in the helper for
instance, it must be cleared. If these rules are properly followed
then the bit will be zero in all other cases without needing any
additional work or conditionals.
Tom
thank you,
On Fri, 2017-04-07 at 08:43 -0700, Tom Herbert wrote:
Maybe just call it csum_not_ip then. Then just do "if
(unlikely(skb->csum_not_ip)) ..."
OK, I will rename the bit, avoid the enum and use the 'unlikely'. Up to now,
this series uses the bit for SCTP only and leaves unmodified behavior of
offloaded FCoE frames: please let me know if you disagree on that.
On Fri, 2017-04-07 at 08:43 -0700, Tom Herbert wrote:
On Fri, Apr 7, 2017 at 10:29 AM, Davide Caratti [off-list ref] wrote:
quoted
In my understanding, csum_algo needs to be set to INTERNET_CHECKSUM after the
CRC32c is computed. Otherwise, after subsequent operation on the skb (e.g. it
is encapsulated in a UDP frame), there is the possibility for skb->ip_summed
to become CHECKSUM_PARTIAL again. So, to ensure that skb_checksum_help() and
not skb_crc32c_help() will be called, csum_algo must be 0.
ip_summed should no longer be CHECKSUM_PARTIAL with CRC32c is computed.
Even though it's uncommon, skb->ip_summed can become CHECKSUM_PARTIAL again
after the CRC32c is computed and CHECKSUM_NONE is set: for example, when a
veth and a vxlan with UDP checksums are enslaved to the same bridge, and the
NIC below vxlan has no checksumming capabilities. Here, validate_xmit_skb is
called three times on the same skb (see perf output at the bottom):
* before transmission on the veth: here ip_summed is CHECKSUM_PARTIAL, but
the device supports CRC32c offload so the skb is (correctly) untouched.
* before vxlan encapsulation: here ip_summed is CHECKSUM_PARTIAL,
skb->csum_not_inet is 1 and NETIF_F_SCTP_CRC is not set. Here,
skb_csum_hwoffload_help() correctly fills the CRC32c and assigns ip_summed
to CHECKSUM_NONE.
* before transmission on the NIC: ip_summed is CHECKSUM_PARTIAL again (because
udp_set_csum changed csum_start and csum_offset to point to the tunnel
UDP header). No bit in NETIF_F_HW_CSUM is set: if skb->csum_not_inet is still 1,
the helper (wrongly) computes CRC32c again, thus corrupting the outer UDP
transport header. On the contrary, if skb->csum_not_inet is 0, skb_checksum_help()
correctly resolves CHECKSUM_PARTIAL.
To avoid this problem, skb->csum_not_inet must be assigned to 0 every time
the CHECKSUM_PARTIAL is resolved on skb carrying SCTP packets.
quoted
To minimize the impact of the patch, I substituted all assignments of skb->ip_summed,
done by SCTP-related code, with calls to skb_set_crc32c_ipsummed(). The alternative is
to explicitly set csum_algo to 0 (INTERNET_CHECKSUM) in SCTP-related code. Do you agree?
No, like I said the only case where this new bit is relevant is when
CHECKSUM_PARTIAL for a CRC is being done. When it's set for offloading
sctp crc it must be set. When CRC is resolved, in the helper for
instance, it must be cleared. If these rules are properly followed
then the bit will be zero in all other cases without needing any
additional work or conditionals.
At a minimum, this csum_not_inet bit needs to be cleared in three places:
1) in skb_crc32c_csum_help, to fix scenarios like veth->bridge->vxlan->NIC above.
2) in sctp_gso_make_checksum, a SCTP GSO packet is segmented and CRC32c is written
on each segment. skb->ip_summed transitions from CHECKSUM_PARTIAL to CHECKSUM_NONE.
3) in act_csum, because TC action mangling the packet are called before
validate_xmit_skb().
It is not necessary to do it in netfilter NAT (even it is harmless), because
SCTP packets having CHECKSUM_PARTIAL are not resolved (since commit 3189a290f98d
"netfilter: nat: skip checksum on offload SCTP packets"). And it should be not
needed in IPVS code, because ip_summed is set to CHECKSUM_UNNECESSARY, so skb
is not going to be checksummed anymore.
thank you in advance for the feedback!
regards,
hello Tom,
On Fri, 2017-04-07 at 11:11 -0700, Tom Herbert wrote:
maybe just call it csum_not_ip then. Then just do "if
(unlikely(skb->csum_not_ip)) ..."
Ok, done. V4 uses this bit for SCTP only and leaves unmodified behavior
when offloaded FCoE frames are processed. Further work is still possible
to extend this fix for FCoE, if needed, either by using additional sk_buff
bits, or using skb->csum_not_ip and use other data (e.g. skb->csum_offset)
to distinguish SCTP from FCoE.
the only case where this new bit is relevant is when
CHECKSUM_PARTIAL for a CRC is being done. When it's set for offloading
sctp crc it must be set. When CRC is resolved, in the helper for
instance, it must be cleared.
in V4 the bit is set when SCTP packets with offloaded checksum are
generated; the bit is cleared when CRC32c is resolved for such packets
(i.e. skb->ip_summed transitions from CHECKSUM_PARTIAL to CHECKSUM_NONE).
Any feedbacks are appreciated!
thank you in advance,
--
davide
Davide Caratti (7):
skbuff: add stub to help computing crc32c on SCTP packets
net: introduce skb_crc32c_csum_help
sk_buff: remove support for csum_bad in sk_buff
net: use skb->csum_not_inet to identify packets needing crc32c
net: more accurate checksumming in validate_xmit_skb()
openvswitch: more accurate checksumming in queue_userspace_packet()
sk_buff.h: improve description of CHECKSUM_{COMPLETE,UNNECESSARY}
Documentation/networking/checksum-offloads.txt | 11 +++--
drivers/net/ethernet/aquantia/atlantic/aq_ring.c | 2 +-
include/linux/netdevice.h | 8 +--
include/linux/skbuff.h | 58 +++++++++-------------
net/bridge/netfilter/nft_reject_bridge.c | 5 +-
net/core/dev.c | 63 +++++++++++++++++++++---
net/core/skbuff.c | 24 +++++++++
net/ipv4/netfilter/nf_reject_ipv4.c | 2 +-
net/ipv6/netfilter/nf_reject_ipv6.c | 3 --
net/openvswitch/datapath.c | 2 +-
net/sched/act_csum.c | 1 +
net/sctp/offload.c | 8 +++
net/sctp/output.c | 1 +
13 files changed, 128 insertions(+), 60 deletions(-)
--
2.7.4
sctp_compute_checksum requires crc32c symbol (provided by libcrc32c), so
it can't be used in net core. Like it has been done previously with other
symbols (e.g. ipv6_dst_lookup), introduce a stub struct skb_checksum_ops
to allow computation of crc32c checksum in net core after sctp.ko (and thus
libcrc32c) has been loaded.
Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: Davide Caratti <redacted>
---
include/linux/skbuff.h | 2 ++
net/core/skbuff.c | 24 ++++++++++++++++++++++++
net/sctp/offload.c | 7 +++++++
3 files changed, 33 insertions(+)
@@ -2242,6 +2242,30 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,}EXPORT_SYMBOL(skb_copy_and_csum_bits);+static__wsumwarn_crc32c_csum_update(constvoid*buff,intlen,__wsumsum)+{+net_warn_ratelimited(+"%s: attempt to compute crc32c without libcrc32c.ko\n",+__func__);+return0;+}++static__wsumwarn_crc32c_csum_combine(__wsumcsum,__wsumcsum2,+intoffset,intlen)+{+net_warn_ratelimited(+"%s: attempt to compute crc32c without libcrc32c.ko\n",+__func__);+return0;+}++conststructskb_checksum_ops*crc32c_csum_stub__read_mostly=+&(structskb_checksum_ops){+.update=warn_crc32c_csum_update,+.combine=warn_crc32c_csum_combine,+};+EXPORT_SYMBOL(crc32c_csum_stub);+/***skb_zerocopy_headlen-Calculateheadroomneededforskb_zerocopy()*@from:sourcebuffer
skb_crc32c_csum_help is like skb_checksum_help, but it is designed for
checksumming SCTP packets using crc32c (see RFC3309), provided that
libcrc32c.ko has been loaded before. In case libcrc32c is not loaded,
invoking skb_crc32c_csum_help on a skb results in one the following
printouts:
warn_crc32c_csum_update: attempt to compute crc32c without libcrc32c.ko
warn_crc32c_csum_combine: attempt to compute crc32c without libcrc32c.ko
Signed-off-by: Davide Caratti <redacted>
---
include/linux/netdevice.h | 1 +
include/linux/skbuff.h | 3 ++-
net/core/dev.c | 40 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 43 insertions(+), 1 deletion(-)
@@ -2606,6 +2607,45 @@ int skb_checksum_help(struct sk_buff *skb)}EXPORT_SYMBOL(skb_checksum_help);+intskb_crc32c_csum_help(structsk_buff*skb)+{+__le32crc32c_csum;+intret=0,offset;++if(skb->ip_summed!=CHECKSUM_PARTIAL)+gotoout;++if(unlikely(skb_is_gso(skb)))+gotoout;++/* Before computing a checksum, we should make sure no frag could+*bemodifiedbyanexternalentity:checksumcouldbewrong.+*/+if(unlikely(skb_has_shared_frag(skb))){+ret=__skb_linearize(skb);+if(ret)+gotoout;+}++offset=skb_checksum_start_offset(skb);+crc32c_csum=cpu_to_le32(~__skb_checksum(skb,offset,+skb->len-offset,~(__u32)0,+crc32c_csum_stub));+offset+=offsetof(structsctphdr,checksum);+BUG_ON(offset>=skb_headlen(skb));++if(skb_cloned(skb)&&+!skb_clone_writable(skb,offset+sizeof(__le32))){+ret=pskb_expand_head(skb,0,0,GFP_ATOMIC);+if(ret)+gotoout;+}+*(__le32*)(skb->data+offset)=crc32c_csum;+skb->ip_summed=CHECKSUM_NONE;+out:+returnret;+}+__be16skb_network_protocol(structsk_buff*skb,int*depth){__be16type=skb->protocol;
skb_csum_hwoffload_help() uses netdev features and skb->csum_not_inet to
determine if skb needs software computation of Internet Checksum or crc32c
(or nothing, if this computation can be done by the hardware). Use it in
place of skb_checksum_help() in validate_xmit_skb() to avoid corruption
of non-GSO SCTP packets having skb->ip_summed equal to CHECKSUM_PARTIAL.
While at it, remove references to skb_csum_off_chk* functions, since they
are not present anymore in Linux since commit cf53b1da73bd ('Revert "net:
Add driver helper functions to determine checksum"').
Signed-off-by: Davide Caratti <redacted>
---
Documentation/networking/checksum-offloads.txt | 11 +++++++----
include/linux/netdevice.h | 3 +++
include/linux/skbuff.h | 13 +++++--------
net/core/dev.c | 14 ++++++++++++--
4 files changed, 27 insertions(+), 14 deletions(-)
@@ -35,6 +35,9 @@ This interface only allows a single checksum to be offloaded. Where encapsulation is used, the packet may have multiple checksum fields in different header layers, and the rest will have to be handled by another mechanism such as LCO or RCO.+CRC32c can also be offloaded using this interface, by means of filling+ skb->csum_start and skb->csum_offset as described above, and setting+ skb->csum_not_inet: see skbuff.h comment (section 'D') for more details. No offloading of the IP header checksum is performed; it is always done in software. This is OK because when we build the IP header, we obviously have it in cache, so summing it isn't expensive. It's also rather short.
@@ -49,9 +52,9 @@ A driver declares its offload capabilities in netdev->hw_features; see and csum_offset given in the SKB; if it tries to deduce these itself in hardware (as some NICs do) the driver should check that the values in the SKB match those which the hardware will deduce, and if not, fall back to- checksumming in software instead (with skb_checksum_help or one of the- skb_csum_off_chk* functions as mentioned in include/linux/skbuff.h). This- is a pain, but that's what you get when hardware tries to be clever.+ checksumming in software instead (with skb_csum_hwoffload_help() or one of+ the skb_checksum_help() / skb_crc32c_csum_help functions, as mentioned in+ include/linux/skbuff.h). The stack should, for the most part, assume that checksum offload is supported by the underlying device. The only place that should check is
@@ -60,7 +63,7 @@ The stack should, for the most part, assume that checksum offload is may include other offloads besides TX Checksum Offload) and, if they are not supported or enabled on the device (determined by netdev->features), performs the corresponding offload in software. In the case of TX- Checksum Offload, that means calling skb_checksum_help(skb).+ Checksum Offload, that means calling skb_csum_hwoffload_help(skb, features). LCO: Local Checksum Offload
if skb carries an SCTP packet and ip_summed is CHECKSUM_PARTIAL, it needs
CRC32c in place of Internet Checksum: use skb_csum_hwoffload_help to avoid
corrupting such packets while queueing them towards userspace.
Signed-off-by: Davide Caratti <redacted>
---
net/openvswitch/datapath.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -453,7 +453,7 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,/* Complete checksum if needed */if(skb->ip_summed==CHECKSUM_PARTIAL&&-(err=skb_checksum_help(skb)))+(err=skb_csum_hwoffload_help(skb,0)))gotoout;/* Older versions of OVS user space enforce alignment of the last
Add FCoE to the list of protocols that can set CHECKSUM_UNNECESSARY; add a
note to CHECKSUM_COMPLETE section to specify that it does not apply to SCTP
and FCoE protocols.
Suggested-by: Tom Herbert <redacted>
Signed-off-by: Davide Caratti <redacted>
---
include/linux/skbuff.h | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
skb->csum_not_inet carries the indication on which algorithm is needed to
compute checksum on skb in the transmit path, when skb->ip_summed is equal
to CHECKSUM_PARTIAL. If skb carries a SCTP packet and crc32c hasn't been
yet written in L4 header, skb->csum_not_inet is assigned to 1; otherwise,
assume Internet Checksum is needed and thus set skb->csum_not_inet to 0.
Suggested-by: Tom Herbert <redacted>
Signed-off-by: Davide Caratti <redacted>
---
include/linux/skbuff.h | 16 +++++++++-------
net/core/dev.c | 1 +
net/sched/act_csum.c | 1 +
net/sctp/offload.c | 1 +
net/sctp/output.c | 1 +
5 files changed, 13 insertions(+), 7 deletions(-)
This bit was introduced with 5a21232983aa ("net: Support for csum_bad in
skbuff") to reduce the stack workload when processing RX packets carrying
a wrong Internet Checksum. Up to now, only one driver (besides GRO core)
are setting it.
The test on NAPI_GRO_CB(skb)->flush in dev_gro_receive() is now done
before the test on same_flow, to preserve behavior in case of wrong
checksum.
Suggested-by: Tom Herbert <redacted>
Signed-off-by: Davide Caratti <redacted>
---
drivers/net/ethernet/aquantia/atlantic/aq_ring.c | 2 +-
include/linux/netdevice.h | 4 +---
include/linux/skbuff.h | 23 ++---------------------
net/bridge/netfilter/nft_reject_bridge.c | 5 +----
net/core/dev.c | 8 +++-----
net/ipv4/netfilter/nf_reject_ipv4.c | 2 +-
net/ipv6/netfilter/nf_reject_ipv6.c | 3 ---
7 files changed, 9 insertions(+), 38 deletions(-)
@@ -223,7 +223,7 @@ int aq_ring_rx_clean(struct aq_ring_s *self, int *work_done, int budget)skb->protocol=eth_type_trans(skb,ndev);if(unlikely(buff->is_cso_err)){++self->stats.rx.errors;-__skb_mark_checksum_bad(skb);+skb->ip_summed=CHECKSUM_NONE;}else{if(buff->is_ip_cso){__skb_incr_checksum_unnecessary(skb);
@@ -743,7 +743,7 @@ struct sk_buff {__u8csum_valid:1;__u8csum_complete_sw:1;__u8csum_level:2;-__u8csum_bad:1;+__u8__csum_bad_unused:1;/* one bit hole */__u8dst_pending_confirm:1;#ifdef CONFIG_IPV6_NDISC_NODETYPE
@@ -3387,21 +3387,6 @@ static inline void __skb_incr_checksum_unnecessary(struct sk_buff *skb)}}-staticinlinevoid__skb_mark_checksum_bad(structsk_buff*skb)-{-/* Mark current checksum as bad (typically called from GRO-*path).Inthecasethatip_summedisCHECKSUM_NONE-*thismustbethefirstchecksumencounteredinthepacket.-*Whenip_summedisCHECKSUM_UNNECESSARY,thisisthefirst-*checksumafterthelastonevalidated.ForUDP,azero-*checksumcannotbemarkedasbad.-*/--if(skb->ip_summed==CHECKSUM_NONE||-skb->ip_summed==CHECKSUM_UNNECESSARY)-skb->csum_bad=1;-}-/* Check if we need to perform checksum complete validation.**Returnstrueifchecksumcompleteisneeded,falseotherwise
@@ -3455,9 +3440,6 @@ static inline __sum16 __skb_checksum_validate_complete(struct sk_buff *skb,skb->csum_valid=1;return0;}-}elseif(skb->csum_bad){-/* ip_summed == CHECKSUM_NONE in this case */-return(__force__sum16)1;}skb->csum=psum;
On Thu, Apr 20, 2017 at 03:38:08PM +0200, Davide Caratti wrote:
quoted hunk
skb_crc32c_csum_help is like skb_checksum_help, but it is designed for
checksumming SCTP packets using crc32c (see RFC3309), provided that
libcrc32c.ko has been loaded before. In case libcrc32c is not loaded,
invoking skb_crc32c_csum_help on a skb results in one the following
printouts:
warn_crc32c_csum_update: attempt to compute crc32c without libcrc32c.ko
warn_crc32c_csum_combine: attempt to compute crc32c without libcrc32c.ko
Signed-off-by: Davide Caratti <redacted>
---
include/linux/netdevice.h | 1 +
include/linux/skbuff.h | 3 ++-
net/core/dev.c | 40 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 43 insertions(+), 1 deletion(-)
@@ -2606,6 +2607,45 @@ int skb_checksum_help(struct sk_buff *skb)}EXPORT_SYMBOL(skb_checksum_help);+intskb_crc32c_csum_help(structsk_buff*skb)+{+__le32crc32c_csum;+intret=0,offset;++if(skb->ip_summed!=CHECKSUM_PARTIAL)+gotoout;++if(unlikely(skb_is_gso(skb)))+gotoout;++/* Before computing a checksum, we should make sure no frag could+*bemodifiedbyanexternalentity:checksumcouldbewrong.+*/+if(unlikely(skb_has_shared_frag(skb))){+ret=__skb_linearize(skb);+if(ret)+gotoout;+}++offset=skb_checksum_start_offset(skb);+crc32c_csum=cpu_to_le32(~__skb_checksum(skb,offset,+skb->len-offset,~(__u32)0,+crc32c_csum_stub));+offset+=offsetof(structsctphdr,checksum);+BUG_ON(offset>=skb_headlen(skb));
I suggest using WARN_ON_ONCE() here and returning an error instead. Will
still allow debugging and won't disrupt the system.
+
+ if (skb_cloned(skb) &&
+ !skb_clone_writable(skb, offset + sizeof(__le32))) {
+ ret = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
+ if (ret)
+ goto out;
+ }
We could do this check (including the BUG_ON/WARN check above) before
the actual crc32 calc. This can fail, and if it does, we will have
calculated it in vain. Note how offset doesn't really depend on the
checksum result.
I know skb_checksum_help also does it this way, maybe it was because of
some cache optimization on the offset += checksum offset operation?
+ *(__le32 *)(skb->data + offset) = crc32c_csum;
+ skb->ip_summed = CHECKSUM_NONE;
+out:
+ return ret;
+}
+
__be16 skb_network_protocol(struct sk_buff *skb, int *depth)
{
__be16 type = skb->protocol;
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, Apr 20, 2017 at 03:38:06PM +0200, Davide Caratti wrote:
hello Tom,
On Fri, 2017-04-07 at 11:11 -0700, Tom Herbert wrote:
quoted
maybe just call it csum_not_ip then. Then just do "if
(unlikely(skb->csum_not_ip)) ..."
Ok, done. V4 uses this bit for SCTP only and leaves unmodified behavior
when offloaded FCoE frames are processed. Further work is still possible
to extend this fix for FCoE, if needed, either by using additional sk_buff
bits, or using skb->csum_not_ip and use other data (e.g. skb->csum_offset)
to distinguish SCTP from FCoE.
quoted
the only case where this new bit is relevant is when
CHECKSUM_PARTIAL for a CRC is being done. When it's set for offloading
sctp crc it must be set. When CRC is resolved, in the helper for
instance, it must be cleared.
in V4 the bit is set when SCTP packets with offloaded checksum are
generated; the bit is cleared when CRC32c is resolved for such packets
(i.e. skb->ip_summed transitions from CHECKSUM_PARTIAL to CHECKSUM_NONE).
Any feedbacks are appreciated!
thank you in advance,
--
davide
Davide Caratti (7):
skbuff: add stub to help computing crc32c on SCTP packets
net: introduce skb_crc32c_csum_help
sk_buff: remove support for csum_bad in sk_buff
net: use skb->csum_not_inet to identify packets needing crc32c
net: more accurate checksumming in validate_xmit_skb()
openvswitch: more accurate checksumming in queue_userspace_packet()
sk_buff.h: improve description of CHECKSUM_{COMPLETE,UNNECESSARY}
Other than the comments I did on patch 2, this series LGTM.
Documentation/networking/checksum-offloads.txt | 11 +++--
drivers/net/ethernet/aquantia/atlantic/aq_ring.c | 2 +-
include/linux/netdevice.h | 8 +--
include/linux/skbuff.h | 58 +++++++++-------------
net/bridge/netfilter/nft_reject_bridge.c | 5 +-
net/core/dev.c | 63 +++++++++++++++++++++---
net/core/skbuff.c | 24 +++++++++
net/ipv4/netfilter/nf_reject_ipv4.c | 2 +-
net/ipv6/netfilter/nf_reject_ipv6.c | 3 --
net/openvswitch/datapath.c | 2 +-
net/sched/act_csum.c | 1 +
net/sctp/offload.c | 8 +++
net/sctp/output.c | 1 +
13 files changed, 128 insertions(+), 60 deletions(-)
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Tom Herbert <hidden> Date: 2017-04-29 20:18:36
On Thu, Apr 20, 2017 at 6:38 AM, Davide Caratti [off-list ref] wrote:
quoted hunk
skb->csum_not_inet carries the indication on which algorithm is needed to
compute checksum on skb in the transmit path, when skb->ip_summed is equal
to CHECKSUM_PARTIAL. If skb carries a SCTP packet and crc32c hasn't been
yet written in L4 header, skb->csum_not_inet is assigned to 1; otherwise,
assume Internet Checksum is needed and thus set skb->csum_not_inet to 0.
Suggested-by: Tom Herbert <redacted>
Signed-off-by: Davide Caratti <redacted>
---
include/linux/skbuff.h | 16 +++++++++-------
net/core/dev.c | 1 +
net/sched/act_csum.c | 1 +
net/sctp/offload.c | 1 +
net/sctp/output.c | 1 +
5 files changed, 13 insertions(+), 7 deletions(-)
From: Tom Herbert <hidden> Date: 2017-04-29 20:20:05
On Thu, Apr 20, 2017 at 6:38 AM, Davide Caratti [off-list ref] wrote:
quoted hunk
Add FCoE to the list of protocols that can set CHECKSUM_UNNECESSARY; add a
note to CHECKSUM_COMPLETE section to specify that it does not apply to SCTP
and FCoE protocols.
Suggested-by: Tom Herbert <redacted>
Signed-off-by: Davide Caratti <redacted>
---
include/linux/skbuff.h | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
From: Tom Herbert <hidden> Date: 2017-04-29 20:21:35
On Thu, Apr 20, 2017 at 6:38 AM, Davide Caratti [off-list ref] wrote:
quoted hunk
This bit was introduced with 5a21232983aa ("net: Support for csum_bad in
skbuff") to reduce the stack workload when processing RX packets carrying
a wrong Internet Checksum. Up to now, only one driver (besides GRO core)
are setting it.
The test on NAPI_GRO_CB(skb)->flush in dev_gro_receive() is now done
before the test on same_flow, to preserve behavior in case of wrong
checksum.
Suggested-by: Tom Herbert <redacted>
Signed-off-by: Davide Caratti <redacted>
---
drivers/net/ethernet/aquantia/atlantic/aq_ring.c | 2 +-
include/linux/netdevice.h | 4 +---
include/linux/skbuff.h | 23 ++---------------------
net/bridge/netfilter/nft_reject_bridge.c | 5 +----
net/core/dev.c | 8 +++-----
net/ipv4/netfilter/nf_reject_ipv4.c | 2 +-
net/ipv6/netfilter/nf_reject_ipv6.c | 3 ---
7 files changed, 9 insertions(+), 38 deletions(-)
@@ -223,7 +223,7 @@ int aq_ring_rx_clean(struct aq_ring_s *self, int *work_done, int budget)skb->protocol=eth_type_trans(skb,ndev);if(unlikely(buff->is_cso_err)){++self->stats.rx.errors;-__skb_mark_checksum_bad(skb);+skb->ip_summed=CHECKSUM_NONE;}else{if(buff->is_ip_cso){__skb_incr_checksum_unnecessary(skb);
@@ -743,7 +743,7 @@ struct sk_buff {__u8csum_valid:1;__u8csum_complete_sw:1;__u8csum_level:2;-__u8csum_bad:1;+__u8__csum_bad_unused:1;/* one bit hole */__u8dst_pending_confirm:1;#ifdef CONFIG_IPV6_NDISC_NODETYPE
@@ -3387,21 +3387,6 @@ static inline void __skb_incr_checksum_unnecessary(struct sk_buff *skb)}}-staticinlinevoid__skb_mark_checksum_bad(structsk_buff*skb)-{-/* Mark current checksum as bad (typically called from GRO-*path).Inthecasethatip_summedisCHECKSUM_NONE-*thismustbethefirstchecksumencounteredinthepacket.-*Whenip_summedisCHECKSUM_UNNECESSARY,thisisthefirst-*checksumafterthelastonevalidated.ForUDP,azero-*checksumcannotbemarkedasbad.-*/--if(skb->ip_summed==CHECKSUM_NONE||-skb->ip_summed==CHECKSUM_UNNECESSARY)-skb->csum_bad=1;-}-/* Check if we need to perform checksum complete validation.**Returnstrueifchecksumcompleteisneeded,falseotherwise
@@ -3455,9 +3440,6 @@ static inline __sum16 __skb_checksum_validate_complete(struct sk_buff *skb,skb->csum_valid=1;return0;}-}elseif(skb->csum_bad){-/* ip_summed == CHECKSUM_NONE in this case */-return(__force__sum16)1;}skb->csum=psum;