net: faster and simpler CRC32C computation
Subsystems (12)
Eric Biggers
maintainerv2 cover net: faster and simpler CRC32C computation
Update networking code that computes the CRC32C of packets to just call crc32c() without unnecessary abstraction layers. The result is faster and simpler code.
Patches 1-7 add skb_crc32c() and remove the overly-abstracted and inefficient __skb_checksum().
Patches 8-10 replace skb_copy_and_hash_datagram_iter() with skb_copy_and_crc32c_datagram_iter(), eliminating the unnecessary use of the crypto layer. This unblocks the conversion of nvme-tcp to call crc32c() directly instead of using the crypto layer, which patch 9 does.
Please consider this series for net-next for 6.16.
Changed in v2:
- Added some benchmarks to commit message of "net: add skb_crc32c()"
- Added "Return:" to kerneldoc for skb_copy_and_crc32c_datagram_iter()
- Added Reviewed-by's
- Addressed review comments on nvme-tcp patch
Eric Biggers (10):
net: introduce CONFIG_NET_CRC32C
net: add skb_crc32c()
net: use skb_crc32c() in skb_crc32c_csum_help() RDMA/siw: use skb_crc32c() instead of __skb_checksum()
sctp: use skb_crc32c() instead of __skb_checksum()
net: fold __skb_checksum() into skb_checksum() lib/crc32: remove unused support for CRC32C combination
net: add skb_copy_and_crc32c_datagram_iter()
nvme-tcp: use crc32c() and skb_copy_and_crc32c_datagram_iter()
net: remove skb_copy_and_hash_datagram_iter()
drivers/infiniband/sw/siw/Kconfig | 1 + drivers/infiniband/sw/siw/siw.h | 22 +---- drivers/nvme/host/Kconfig | 4 +- drivers/nvme/host/tcp.c | 124 +++++++++------------------- include/linux/crc32.h | 23 ------ include/linux/skbuff.h | 16 +--- include/net/checksum.h | 12 --- include/net/sctp/checksum.h | 29 +------ lib/crc32.c | 6 -- lib/tests/crc_kunit.c | 6 -- net/Kconfig | 4 + net/core/datagram.c | 36 ++++---- net/core/dev.c | 10 +-- net/core/skbuff.c | 132 ++++++++++++++++++------------ net/netfilter/Kconfig | 4 +- net/netfilter/ipvs/Kconfig | 2 +- net/openvswitch/Kconfig | 2 +- net/sched/Kconfig | 2 +- net/sctp/Kconfig | 2 +- net/sctp/offload.c | 1 - 20 files changed, 161 insertions(+), 277 deletions(-)
base-commit: a8ae8a0e848e3506c95e45e7cb6e640502495f1a
Signature · 1 line
2.49.0
Eric Biggers
maintainerPATCH v2 1/10 net: introduce CONFIG_NET_CRC32C
From: Eric Biggers <[email protected]>
Add a hidden kconfig symbol NET_CRC32C that will group together the functions that calculate CRC32C checksums of packets, so that these don't have to be built into NET-enabled kernels that don't need them.
Make skb_crc32c_csum_help() (which is called only when IP_SCTP is enabled) conditional on this symbol, and make IP_SCTP select it.
--- net/Kconfig | 4 ++++ net/core/dev.c | 2 ++ net/sctp/Kconfig | 1 + 3 files changed, 7 insertions(+)
net/Kconfig +4 -0
@@ -73,10 +73,14 @@ config NET_DEVMEM depends on PAGE_POOL config NET_SHAPER bool +config NET_CRC32C + bool + select CRC32 + menu "Networking options" source "net/packet/Kconfig" source "net/unix/Kconfig" source "net/tls/Kconfig"
net/core/dev.c +2 -0
@@ -3594,10 +3594,11 @@ int skb_checksum_help(struct sk_buff *skb) out:return ret; }EXPORT_SYMBOL (skb_checksum_help); +#ifdef CONFIG_NET_CRC32C int skb_crc32c_csum_help (struct sk_buff *skb) {__le32 crc32c_csum;int ret =0 , offset, start;
@@ -3633,10 +3634,11 @@ int skb_crc32c_csum_help(struct sk_buff *skb)skb_reset_csum_not_inet (skb); out: return ret; }EXPORT_SYMBOL (skb_crc32c_csum_help); +#endif /* CONFIG_NET_CRC32C */ __be16 skb_network_protocol (struct sk_buff *skb,int *depth) {__be16 type = skb->protocol;
net/sctp/Kconfig +1 -0
@@ -9,10 +9,11 @@ menuconfig IP_SCTP depends on IPV6 || IPV6=n select CRC32 select CRYPTO select CRYPTO_HMAC select CRYPTO_SHA1 + select NET_CRC32C select NET_UDP_TUNNEL help Stream Control Transmission Protocol From RFC 2960 <http://www.ietf.org/rfc/rfc2960.txt>.
base-commit: a8ae8a0e848e3506c95e45e7cb6e640502495f1a
Signature · 1 line
2.49.0
Re: [PATCH v2 01/10] net: introduce CONFIG_NET_CRC32C
Quoted 9 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Add a hidden kconfig symbol
NET_CRC32Cthat will group together the functions that calculate CRC32C checksums of packets, so that these don't have to be built into NET-enabled kernels that don't need them.Make
skb_crc32c_csum_help()(which is called only whenIP_SCTPis enabled) conditional on this symbol, and makeIP_SCTPselect it.
Quoted 7 lines
Signed-off-by Eric Biggers <[email protected]>--- net/Kconfig | 4 ++++ net/core/dev.c | 2 ++ net/sctp/Kconfig | 1 + 3 files changed, 7 insertions(+)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Eric Biggers
maintainerPATCH v2 2/10 net: add skb_crc32c()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Add skb_crc32c(), which calculates the CRC32C of a sk_buff. It will replace __skb_checksum(), which unnecessarily supports arbitrary checksums. Compared to __skb_checksum(), skb_crc32c():
- Uses the correct type for CRC32C values (u32, not __wsum).
- Does not require the caller to provide a skb_checksum_ops struct.
- Is faster because it does not use indirect calls and does not use the very slow crc32c_combine().
According to commit 2817a336d4d5 ("net: skb_checksum: allow custom update/combine for walking skb") which added __skb_checksum(), the original motivation for the abstraction layer was to avoid code duplication for CRC32C and other checksums in the future. However:
- No additional checksums showed up after CRC32C. __skb_checksum() is only used with the "regular" net checksum and CRC32C.
- Indirect calls are expensive. Commit 2544af0344ba ("net: avoid indirect calls in L4 checksum calculation") worked around this using the INDIRECT_CALL_1 macro. But that only avoided the indirect call for the net checksum, and at the cost of an extra branch.
- The checksums use different types (__wsum and u32), causing casts to be needed.
- It made the checksums of fragments be combined (rather than chained) for both checksums, despite this being highly counterproductive for CRC32C due to how slow crc32c_combine() is. This can clearly be seen in commit 4c2f24549644 ("sctp: linearize early if it's not GSO") which tried to work around this performance bug. With a dedicated function for each checksum, we can instead just use the proper strategy for each checksum.
As shown by the following tables, the new function skb_crc32c() is faster than __skb_checksum(), with the improvement varying greatly from 5% to 2500% depending on the case. The largest improvements come from fragmented packets, mainly due to eliminating the inefficient crc32c_combine(). But linear packets are improved too, especially shorter ones, mainly due to eliminating indirect calls. These benchmarks were done on AMD Zen 5. On that CPU, Linux uses IBRS instead of retpoline; an even greater improvement might be seen with retpoline:
Linear sk_buffs
Length in bytes __skb_checksum cycles skb_crc32c cycles
=============== ===================== =================
64 43 18
256 94 77
1420 204 161
16384 1735 1642
Nonlinear sk_buffs (even split between head and one fragment)
Length in bytes __skb_checksum cycles skb_crc32c cycles
=============== ===================== =================
64 579 22
256 829 77
1420 1506 194
16384 4365 1682
--- include/linux/skbuff.h | 1 + net/core/skbuff.c | 73 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+)
include/linux/skbuff.h +1 -0
@@ -4201,10 +4201,11 @@ extern const struct skb_checksum_ops *crc32c_csum_stub __read_mostly;__wsum __skb_checksum (const struct sk_buff *skb,int offset,int len,__wsum csum,const struct skb_checksum_ops *ops);__wsum skb_checksum (const struct sk_buff *skb,int offset,int len,__wsum csum); +u32 skb_crc32c (const struct sk_buff *skb,int offset,int len,u32 crc);static inline void *__must_check __skb_header_pointer (const struct sk_buff *skb,int offset,int len,const void *data,int hlen,void *buffer) {
net/core/skbuff.c +73 -0
93 lines not on this page · raw message
Signature · 1 line
2.49.0
Re: [PATCH v2 02/10] net: add skb_crc32c()
Quoted 64 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Add
skb_crc32c(), which calculates the CRC32C of ask_buff. It will replace__skb_checksum(), which unnecessarily supports arbitrary checksums. Compared to__skb_checksum(),skb_crc32c():- Uses the correct type for CRC32C values (u32, not
__wsum).- Does not require the caller to provide a
skb_checksum_opsstruct.- Is faster because it does not use indirect calls and does not use the very slow
crc32c_combine().According to commit
2817a336d4d5("net:skb_checksum: allow custom update/combine for walking skb") which added__skb_checksum(), the original motivation for the abstraction layer was to avoid code duplication for CRC32C and other checksums in the future. However:- No additional checksums showed up after CRC32C.
__skb_checksum()is only used with the "regular" net checksum and CRC32C.- Indirect calls are expensive. Commit
2544af0344ba("net: avoid indirect calls in L4 checksum calculation") worked around this using theINDIRECT_CALL_1macro. But that only avoided the indirect call for the net checksum, and at the cost of an extra branch.- The checksums use different types (
__wsumand u32), causing casts to be needed.- It made the checksums of fragments be combined (rather than chained) for both checksums, despite this being highly counterproductive for CRC32C due to how slow
crc32c_combine()is. This can clearly be seen in commit4c2f24549644("sctp: linearize early if it's not GSO") which tried to work around this performance bug. With a dedicated function for each checksum, we can instead just use the proper strategy for each checksum.As shown by the following tables, the new function
skb_crc32c()is faster than__skb_checksum(), with the improvement varying greatly from 5% to 2500% depending on the case. The largest improvements come from fragmented packets, mainly due to eliminating the inefficientcrc32c_combine(). But linear packets are improved too, especially shorter ones, mainly due to eliminating indirect calls. These benchmarks were done on AMD Zen 5. On that CPU, Linux uses IBRS instead of retpoline; an even greater improvement might be seen with retpoline:Linear
sk_buffsLength in bytes
__skb_checksumcyclesskb_crc32ccycles
=============== ===================== =================
64 43 18
256 94 77
1420 204 161
16384 1735 1642Nonlinear
sk_buffs(even split between head and one fragment)Length in bytes
__skb_checksumcyclesskb_crc32ccycles
=============== ===================== =================
64 579 22
256 829 77
1420 1506 194
16384 4365 1682
Quoted 6 lines
Signed-off-by Eric Biggers <[email protected]>--- include/linux/skbuff.h | 1 + net/core/skbuff.c | 73 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Eric Biggers
maintainerPATCH v2 3/10 net: use skb_crc32c() in skb_crc32c_csum_help()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Instead of calling __skb_checksum() with a skb_checksum_ops struct that does CRC32C, just call the new function skb_crc32c(). This is faster and simpler.
--- net/core/dev.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
net/core/dev.c +3 -5
@@ -3597,11 +3597,11 @@ int skb_checksum_help(struct sk_buff *skb)EXPORT_SYMBOL (skb_checksum_help);#ifdef CONFIG_NET_CRC32C int skb_crc32c_csum_help (struct sk_buff *skb) { -__le32 crc32c_csum; +u32 crc;int ret =0 , offset, start;if (skb->ip_summed !=CHECKSUM_PARTIAL ) goto out;
@@ -3625,14 +3625,12 @@ int skb_crc32c_csum_help(struct sk_buff *skb) ret =skb_ensure_writable (skb, offset +sizeof (__le32));if (ret) goto out; - crc32c_csum =cpu_to_le32 (~__skb_checksum (skb, start, - skb->len - start, ~(__u32 )0 , - crc32c_csum_stub)); - *(__le32 *)(skb->data + offset) = crc32c_csum; + crc = ~skb_crc32c (skb, start, skb->len - start, ~0 ); + *(__le32 *)(skb->data + offset) =cpu_to_le32 (crc);skb_reset_csum_not_inet (skb); out:return ret; }EXPORT_SYMBOL (skb_crc32c_csum_help);
Signature · 1 line
2.49.0
Re: [PATCH v2 03/10] net: use skb_crc32c() in skb_crc32c_csum_help()
Quoted 11 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Instead of calling
__skb_checksum()with askb_checksum_opsstruct that does CRC32C, just call the new functionskb_crc32c(). This is faster and simpler.Signed-off-by Eric Biggers <[email protected]>--- net/core/dev.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Eric Biggers
maintainerPATCH v2 4/10 RDMA/siw: use skb_crc32c() instead of __skb_checksum()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Instead of calling __skb_checksum() with a skb_checksum_ops struct that does CRC32C, just call the new function skb_crc32c(). This is faster and simpler.
--- drivers/infiniband/sw/siw/Kconfig | 1 + drivers/infiniband/sw/siw/siw.h | 22 +--------------------- 2 files changed, 2 insertions(+), 21 deletions(-)
drivers/infiniband/sw/siw/Kconfig +1 -0
@@ -1,10 +1,11 @@ config RDMA_SIW tristate "Software RDMA over TCP/IP (iWARP) driver" depends on INET && INFINIBAND depends on INFINIBAND_VIRT_DMA select CRC32 + select NET_CRC32C help This driver implements the iWARP RDMA transport over the Linux TCP/IP network stack. It enables a system with a standard Ethernet adapter to interoperate with a iWARP adapter or with another system running the SIW driver.
drivers/infiniband/sw/siw/siw.h +1 -21
@@ -691,33 +691,13 @@ static inline void siw_crc_oneshot(const void *data, size_t len, u8 out[4])siw_crc_init (&crc);siw_crc_update (&crc, data, len);return siw_crc_final (&crc, out); } -static inline __wsum siw_csum_update (const void *buff,int len,__wsum sum) -{ -return (__force __wsum )crc32c ((__force __u32 )sum, buff, len); -} - -static inline __wsum siw_csum_combine (__wsum csum,__wsum csum2,int offset, -int len) -{ -return (__force __wsum )crc32c_combine ((__force __u32 )csum, - (__force __u32 )csum2, len); -} -static inline void siw_crc_skb (struct siw_rx_stream *srx,unsigned int len) { -const struct skb_checksum_ops siw_cs_ops = { - .update = siw_csum_update, - .combine = siw_csum_combine, - }; -__wsum crc = (__force __wsum )srx->mpa_crc; - - crc =__skb_checksum (srx->skb, srx->skb_offset, len, crc, - &siw_cs_ops); - srx->mpa_crc = (__force u32 )crc; + srx->mpa_crc =skb_crc32c (srx->skb, srx->skb_offset, len, srx->mpa_crc); }#define siw_dbg (ibdev, fmt, ...) \ ibdev_dbg(ibdev, "%s: " fmt, __func__, ##__VA_ARGS__)
Signature · 1 line
2.49.0
Re: [PATCH v2 04/10] RDMA/siw: use skb_crc32c() instead of __skb_checksum()
Quoted 6 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Instead of calling
__skb_checksum()with askb_checksum_opsstruct that does CRC32C, just call the new functionskb_crc32c(). This is faster and simpler.
Quoted 7 lines
Reviewed-by Bernard Metzler <[email protected]>Signed-off-by Eric Biggers <[email protected]>--- drivers/infiniband/sw/siw/Kconfig | 1 + drivers/infiniband/sw/siw/siw.h | 22 +--------------------- 2 files changed, 2 insertions(+), 21 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Eric Biggers
maintainerPATCH v2 5/10 sctp: use skb_crc32c() instead of __skb_checksum()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Make sctp_compute_cksum() just use the new function skb_crc32c(), instead of calling __skb_checksum() with a skb_checksum_ops struct that does CRC32C. This is faster and simpler.
--- include/net/sctp/checksum.h | 29 +++-------------------------- net/netfilter/Kconfig | 4 ++-- net/netfilter/ipvs/Kconfig | 2 +- net/openvswitch/Kconfig | 2 +- net/sched/Kconfig | 2 +- net/sctp/Kconfig | 1 - net/sctp/offload.c | 1 - 7 files changed, 8 insertions(+), 33 deletions(-)
include/net/sctp/checksum.h +3 -26
@@ -13,51 +13,28 @@* * Written or modified by: * Dinakaran Joseph * Jon Grimm <[email protected]> * Sridhar Samudrala <[email protected]> -* -* Rewritten to use libcrc32c by: * Vlad Yasevich <[email protected]> */ #ifndef __sctp_checksum_h__#define __sctp_checksum_h__#include <linux/types.h> #include <linux/sctp.h> -#include <linux/crc32c.h> -#include <linux/crc32.h> - -static inline __wsum sctp_csum_update (const void *buff,int len,__wsum sum) -{ -return (__force __wsum )crc32c ((__force __u32 )sum, buff, len); -} - -static inline __wsum sctp_csum_combine (__wsum csum,__wsum csum2, -int offset,int len) -{ -return (__force __wsum )crc32c_combine ((__force __u32 )csum, - (__force __u32 )csum2, len); -} - -static const struct skb_checksum_ops sctp_csum_ops = { - .update = sctp_csum_update, - .combine = sctp_csum_combine, -};static inline __le32 sctp_compute_cksum (const struct sk_buff *skb,unsigned int offset) {struct sctphdr *sh = (struct sctphdr *)(skb->data + offset);__le32 old = sh->checksum; -__wsum new; +u32 new; sh->checksum =0 ; - new = ~__skb_checksum (skb, offset, skb->len - offset, ~(__wsum )0 , - &sctp_csum_ops); + new = ~skb_crc32c (skb, offset, skb->len - offset, ~0 ); sh->checksum = old; - -return cpu_to_le32 ((__force __u32 )new); +return cpu_to_le32 (new); }#endif /* __sctp_checksum_h__ */
net/netfilter/Kconfig +2 -2
@@ -210,11 +210,11 @@ config NF_CT_PROTO_GRE config NF_CT_PROTO_SCTP bool 'SCTP protocol connection tracking support' depends on NETFILTER_ADVANCED default y - select CRC32 + select NET_CRC32C help With this option enabled, the layer 3 independent connection tracking code will be able to do state tracking on SCTP connections. If unsure, say Y.
@@ -473,11 +473,11 @@ config NETFILTER_SYNPROXY endif # NF_CONNTRACK config NF_TABLES select NETFILTER_NETLINK - select CRC32 + select NET_CRC32C tristate "Netfilter nf_tables support" help nftables is the new packet classification framework that intends to replace the existing {ip,ip6,arp,eb}_tables infrastructure. It provides a pseudo-state machine with an extensible instruction-set
net/netfilter/ipvs/Kconfig +1 -1
@@ -103,11 +103,11 @@ config IP_VS_PROTO_AH This option enables support for load balancing AH (Authentication Header) transport protocol. Say Y if unsure. config IP_VS_PROTO_SCTP bool "SCTP load balancing support" - select CRC32 + select NET_CRC32C help This option enables support for load balancing SCTP transport protocol. Say Y if unsure. comment "IPVS scheduler"
net/openvswitch/Kconfig +1 -1
@@ -9,12 +9,12 @@ config OPENVSWITCH depends on !NF_CONNTRACK || \ (NF_CONNTRACK && ((!NF_DEFRAG_IPV6 || NF_DEFRAG_IPV6) && \ (!NF_NAT || NF_NAT) && \ (!NETFILTER_CONNCOUNT || NETFILTER_CONNCOUNT))) depends on PSAMPLE || !PSAMPLE - select CRC32 select MPLS + select NET_CRC32C select NET_MPLS_GSO select DST_CACHE select NET_NSH select NF_CONNTRACK_OVS if NF_CONNTRACK select NF_NAT_OVS if NF_NAT
net/sched/Kconfig +1 -1
@@ -794,11 +794,11 @@ config NET_ACT_SKBEDIT module will be called act_skbedit. config NET_ACT_CSUM tristate "Checksum Updating" depends on NET_CLS_ACT && INET - select CRC32 + select NET_CRC32C help Say Y here to update some common checksum after some direct packet alterations. To compile this code as a module, choose M here: the
net/sctp/Kconfig +0 -1
@@ -5,11 +5,10 @@ menuconfig IP_SCTP tristate "The SCTP Protocol" depends on INET depends on IPV6 || IPV6=n - select CRC32 select CRYPTO select CRYPTO_HMAC select CRYPTO_SHA1 select NET_CRC32C select NET_UDP_TUNNEL
net/sctp/offload.c +0 -1
@@ -109,11 +109,10 @@ int __init sctp_offload_init(void) ret =inet6_add_offload (&sctp6_offload,IPPROTO_SCTP );if (ret) goto ipv4; - crc32c_csum_stub = &sctp_csum_ops;return ret; ipv4:inet_del_offload (&sctp_offload,IPPROTO_SCTP ); out:
Signature · 1 line
2.49.0
Re: [PATCH v2 05/10] sctp: use skb_crc32c() instead of __skb_checksum()
Quoted 7 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Make
sctp_compute_cksum()just use the new functionskb_crc32c(), instead of calling__skb_checksum()with askb_checksum_opsstruct that does CRC32C. This is faster and simpler.Signed-off-by Eric Biggers <[email protected]>
Quoted 10 lines
--- include/net/sctp/checksum.h | 29 +++-------------------------- net/netfilter/Kconfig | 4 ++-- net/netfilter/ipvs/Kconfig | 2 +- net/openvswitch/Kconfig | 2 +- net/sched/Kconfig | 2 +- net/sctp/Kconfig | 1 - net/sctp/offload.c | 1 - 7 files changed, 8 insertions(+), 33 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Eric Biggers
maintainerPATCH v2 6/10 net: fold __skb_checksum() into skb_checksum()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Now that the only remaining caller of __skb_checksum() is skb_checksum(), fold __skb_checksum() into skb_checksum(). This makes struct skb_checksum_ops unnecessary, so remove that too and simply do the "regular" net checksum. It also makes the wrapper functions csum_partial_ext() and csum_block_add_ext() unnecessary, so remove those too and just use the underlying functions.
--- include/linux/skbuff.h | 9 ------- include/net/checksum.h | 12 --------- net/core/skbuff.c | 59 +++++------------------------------------- 3 files changed, 7 insertions(+), 73 deletions(-)
include/linux/skbuff.h +0 -9
@@ -4190,19 +4190,10 @@ static inline int memcpy_from_msg(void *data, struct msghdr *msg, int len)static inline int memcpy_to_msg (struct msghdr *msg,void *data,int len) {return copy_to_iter (data, len, &msg->msg_iter) == len ?0 : -EFAULT ; } -struct skb_checksum_ops { -__wsum (*update)(const void *mem,int len,__wsum wsum); -__wsum (*combine)(__wsum csum,__wsum csum2,int offset,int len); -}; - -extern const struct skb_checksum_ops *crc32c_csum_stub__read_mostly ; - -__wsum __skb_checksum (const struct sk_buff *skb,int offset,int len, -__wsum csum,const struct skb_checksum_ops *ops);__wsum skb_checksum (const struct sk_buff *skb,int offset,int len,__wsum csum);u32 skb_crc32c (const struct sk_buff *skb,int offset,int len,u32 crc); static inline void * __must_check
include/net/checksum.h +0 -12
@@ -96,16 +96,10 @@ static __always_inline __wsum csum_block_add(__wsum csum, __wsum csum2, int offset) { return csum_add(csum, csum_shift(csum2, offset)); } -static __always_inline __wsum -csum_block_add_ext (__wsum csum,__wsum csum2,int offset,int len) -{ -return csum_block_add (csum, csum2, offset); -} - static __always_inline __wsumcsum_block_sub (__wsum csum,__wsum csum2,int offset) {return csum_block_add (csum, ~csum2, offset); }
@@ -113,16 +107,10 @@ csum_block_sub(__wsum csum, __wsum csum2, int offset) static __always_inline __wsum csum_unfold(__sum16 n) {return (__force __wsum )n; } -static __always_inline -__wsum csum_partial_ext(const void *buff, int len, __wsum sum) -{ -return csum_partial (buff, len, sum); -} -#define CSUM_MANGLED_0 ((__force __sum16)0xffff) static __always_inline void csum_replace_by_diff(__sum16 *sum, __wsum diff) { *sum =csum_fold (csum_add (diff, ~csum_unfold (*sum)));
net/core/skbuff.c +7 -52
120 lines not on this page · raw message
Signature · 1 line
2.49.0
Re: [PATCH v2 06/10] net: fold __skb_checksum() into skb_checksum()
Quoted 9 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Now that the only remaining caller of
__skb_checksum()isskb_checksum(), fold__skb_checksum()intoskb_checksum(). This makes structskb_checksum_opsunnecessary, so remove that too and simply do the "regular" net checksum. It also makes the wrapper functionscsum_partial_ext()andcsum_block_add_ext()unnecessary, so remove those too and just use the underlying functions.
Quoted 7 lines
Signed-off-by Eric Biggers <[email protected]>--- include/linux/skbuff.h | 9 ------- include/net/checksum.h | 12 --------- net/core/skbuff.c | 59 +++++------------------------------------- 3 files changed, 7 insertions(+), 73 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Eric Biggers
maintainerPATCH v2 7/10 lib/crc32: remove unused support for CRC32C combination
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
crc32c_combine() and crc32c_shift() are no longer used (except by the KUnit test that tests them), and their current implementation is very slow. Remove them.
--- include/linux/crc32.h | 23 ----------------------- lib/crc32.c | 6 ------ lib/tests/crc_kunit.c | 6 ------ 3 files changed, 35 deletions(-)
include/linux/crc32.h +0 -23
@@ -74,33 +74,10 @@ u32 crc32_le_shift(u32 crc, size_t len);static inline u32 crc32_le_combine (u32 crc1,u32 crc2,size_t len2) {return crc32_le_shift (crc1, len2) ^ crc2; } -u32 crc32c_shift (u32 crc,size_t len); - -/** -* crc32c_combine - Combine two crc32c check values into one. For two sequences -* of bytes, seq1 and seq2 with lengths len1 and len2, crc32c() -* check values were calculated for each, crc1 and crc2. -* -* @crc1: crc32c of the first block -* @crc2: crc32c of the second block -* @len2: length of the second block -* -* Return: The crc32c() check value of seq1 and seq2 concatenated, requiring -* only crc1, crc2, and len2. Note: If seq_full denotes the concatenated -* memory area of seq1 with seq2, and crc_full the crc32c() value of -* seq_full, then crc_full == crc32c_combine(crc1, crc2, len2) when -* crc_full was seeded with the same initializer as crc1, and crc2 seed -* was 0. See also crc_combine_test(). -*/ -static inline u32 crc32c_combine (u32 crc1,u32 crc2,size_t len2) -{ -return crc32c_shift (crc1, len2) ^ crc2; -} -#define crc32 (seed, data, length) crc32_le(seed, (unsigned char const *)(data), length)/* * Helpers for hash table generation of ethernet nics: *
lib/crc32.c +0 -6
@@ -117,16 +117,10 @@ u32 crc32_le_shift(u32 crc, size_t len) {return crc32_generic_shift (crc, len,CRC32_POLY_LE ); }EXPORT_SYMBOL (crc32_le_shift); -u32 crc32c_shift (u32 crc,size_t len) -{ -return crc32_generic_shift (crc, len,CRC32C_POLY_LE ); -} -EXPORT_SYMBOL (crc32c_shift); -u32 crc32_be_base (u32 crc,const u8 *p,size_t len) {while (len--) crc = (crc <<8 ) ^ crc32table_be[(crc >>24 ) ^ *p++];return crc;
lib/tests/crc_kunit.c +0 -6
@@ -389,21 +389,15 @@ static void crc32_be_benchmark(struct kunit *test)static u64 crc32c_wrapper (u64 crc,const u8 *p,size_t len) {return crc32c (crc, p, len); } -static u64 crc32c_combine_wrapper (u64 crc1,u64 crc2,size_t len2) -{ -return crc32c_combine (crc1, crc2, len2); -} -static const struct crc_variant crc_variant_crc32c = { .bits =32 , .le = true, .poly =0x82f63b78 , .func = crc32c_wrapper, - .combine_func = crc32c_combine_wrapper, };static void crc32c_test (struct kunit *test) {crc_test (test, &crc_variant_crc32c);
Signature · 1 line
2.49.0
Re: [PATCH v2 07/10] lib/crc32: remove unused support for CRC32C combination
Quoted 6 lines · Eric Biggers
From: Eric Biggers <[email protected]>
crc32c_combine()andcrc32c_shift()are no longer used (except by the KUnit test that tests them), and their current implementation is very slow. Remove them.
Quoted 7 lines
Signed-off-by Eric Biggers <[email protected]>--- include/linux/crc32.h | 23 ----------------------- lib/crc32.c | 6 ------ lib/tests/crc_kunit.c | 6 ------ 3 files changed, 35 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Eric Biggers
maintainerPATCH v2 8/10 net: add skb_copy_and_crc32c_datagram_iter()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Since skb_copy_and_hash_datagram_iter() is used only with CRC32C, the crypto_ahash abstraction provides no value. Add skb_copy_and_crc32c_datagram_iter() which just calls crc32c() directly.
This is faster and simpler. It also doesn't have the weird dependency issue where skb_copy_and_hash_datagram_iter() depends on CONFIG_CRYPTO_HASH=y without that being expressed explicitly in the kconfig (presumably because it was too heavyweight for NET to select). The new function is conditional on the hidden boolean symbol NET_CRC32C, which selects CRC32. So it gets compiled only when something that actually needs CRC32C packet checksums is enabled, it has no implicit dependency, and it doesn't depend on the heavyweight crypto layer.
--- include/linux/skbuff.h | 2 ++ net/core/datagram.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+)
include/linux/skbuff.h +2 -0
@@ -4135,10 +4135,12 @@ static inline int skb_copy_datagram_msg(const struct sk_buff *from, int offset,int skb_copy_and_csum_datagram_msg (struct sk_buff *skb,int hlen,struct msghdr *msg);int skb_copy_and_hash_datagram_iter (const struct sk_buff *skb,int offset,struct iov_iter *to,int len,struct ahash_request *hash); +int skb_copy_and_crc32c_datagram_iter (const struct sk_buff *skb,int offset, +struct iov_iter *to,int len,u32 *crcp);int skb_copy_datagram_from_iter (struct sk_buff *skb,int offset,struct iov_iter *from,int len);int zerocopy_sg_from_iter (struct sk_buff *skb,struct iov_iter *frm);void skb_free_datagram (struct sock *sk,struct sk_buff *skb);int skb_kill_datagram (struct sock *sk,struct sk_buff *skb,unsigned int flags);
net/core/datagram.c +33 -0
@@ -50,10 +50,11 @@#include <linux/spinlock.h> #include <linux/slab.h> #include <linux/pagemap.h> #include <linux/iov_iter.h> #include <linux/indirect_call_wrapper.h> +#include <linux/crc32.h> #include <net/protocol.h> #include <linux/skbuff.h> #include <net/checksum.h>
@@ -517,10 +518,42 @@ int skb_copy_and_hash_datagram_iter(const struct sk_buff *skb, int offset,return __skb_datagram_iter (skb, offset, to, len, true, hash_and_copy_to_iter, hash); }EXPORT_SYMBOL (skb_copy_and_hash_datagram_iter); +#ifdef CONFIG_NET_CRC32C +static size_t crc32c_and_copy_to_iter (const void *addr,size_t bytes, +void *_crcp,struct iov_iter *i) +{ +u32 *crcp = _crcp; +size_t copied; + + copied =copy_to_iter (addr, bytes, i); + *crcp =crc32c (*crcp, addr, copied); +return copied; +} + +/** +* skb_copy_and_crc32c_datagram_iter - Copy datagram to an iovec iterator +* and update a CRC32C value. +* @skb: buffer to copy +* @offset: offset in the buffer to start copying from +* @to: iovec iterator to copy to +* @len: amount of data to copy from buffer to iovec +* @crcp: pointer to CRC32C value to update +* +* Return: 0 on success, -EFAULT if there was a fault during copy. +*/ +int skb_copy_and_crc32c_datagram_iter (const struct sk_buff *skb,int offset, +struct iov_iter *to,int len,u32 *crcp) +{ +return __skb_datagram_iter (skb, offset, to, len, true, + crc32c_and_copy_to_iter, crcp); +} +EXPORT_SYMBOL (skb_copy_and_crc32c_datagram_iter); +#endif /* CONFIG_NET_CRC32C */ +static size_t simple_copy_to_iter (const void *addr,size_t bytes,void *data__always_unused ,struct iov_iter *i) {return copy_to_iter (addr, bytes, i); }
Signature · 1 line
2.49.0
Re: [PATCH v2 08/10] net: add skb_copy_and_crc32c_datagram_iter()
Quoted 15 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Since
skb_copy_and_hash_datagram_iter()is used only with CRC32C, thecrypto_ahashabstraction provides no value. Addskb_copy_and_crc32c_datagram_iter()which just callscrc32c()directly.This is faster and simpler. It also doesn't have the weird dependency issue where
skb_copy_and_hash_datagram_iter()depends onCONFIG_CRYPTO_HASH=ywithout that being expressed explicitly in the kconfig (presumably because it was too heavyweight for NET to select). The new function is conditional on the hidden boolean symbolNET_CRC32C, which selects CRC32. So it gets compiled only when something that actually needs CRC32C packet checksums is enabled, it has no implicit dependency, and it doesn't depend on the heavyweight crypto layer.
Quoted 6 lines
Signed-off-by Eric Biggers <[email protected]>--- include/linux/skbuff.h | 2 ++ net/core/datagram.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Eric Biggers
maintainerPATCH v2 9/10 nvme-tcp: use crc32c() and skb_copy_and_crc32c_datagram_iter()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Now that the crc32c() library function directly takes advantage of architecture-specific optimizations and there also now exists a function skb_copy_and_crc32c_datagram_iter(), it is unnecessary to go through the crypto_ahash API. Just use those functions. This is much simpler, and it also improves performance due to eliminating the crypto API overhead.
--- drivers/nvme/host/Kconfig | 4 +- drivers/nvme/host/tcp.c | 124 ++++++++++++-------------------------- 2 files changed, 42 insertions(+), 86 deletions(-)
drivers/nvme/host/Kconfig +2 -2
@@ -82,13 +82,13 @@ config NVME_FC config NVME_TCP tristate "NVM Express over Fabrics TCP host driver" depends on INET depends on BLOCK + select CRC32 + select NET_CRC32C select NVME_FABRICS - select CRYPTO - select CRYPTO_CRC32C help This provides support for the NVMe over Fabrics protocol using the TCP transport. This allows you to use remote block devices exported using the NVMe protocol set.
drivers/nvme/host/tcp.c +40 -84
316 lines not on this page · raw message
Signature · 1 line
2.49.0
Re: [PATCH v2 09/10] nvme-tcp: use crc32c() and skb_copy_and_crc32c_datagram_iter()
Quoted 8 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Now that the
crc32c()library function directly takes advantage of architecture-specific optimizations and there also now exists a functionskb_copy_and_crc32c_datagram_iter(), it is unnecessary to go through thecrypto_ahashAPI. Just use those functions. This is much simpler, and it also improves performance due to eliminating the crypto API overhead.
Quoted 8 lines
Reviewed-by Christoph Hellwig <[email protected]>Reviewed-by Sagi Grimberg <[email protected]>Signed-off-by Eric Biggers <[email protected]>--- drivers/nvme/host/Kconfig | 4 +- drivers/nvme/host/tcp.c | 124 ++++++++++++-------------------------- 2 files changed, 42 insertions(+), 86 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Eric Biggers
maintainerPATCH v2 10/10 net: remove skb_copy_and_hash_datagram_iter()
In reply to Eric BiggersFrom: Eric Biggers <[email protected]>
Now that skb_copy_and_hash_datagram_iter() is no longer used, remove it.
--- include/linux/skbuff.h | 4 ---- net/core/datagram.c | 37 ------------------------------------- 2 files changed, 41 deletions(-)
include/linux/skbuff.h +0 -4
@@ -272,11 +272,10 @@/* return minimum truesize of one skb containing X bytes of data */ #define SKB_TRUESIZE (X ) ((X) + \ SKB_DATA_ALIGN(sizeof(struct sk_buff)) + \ SKB_DATA_ALIGN(sizeof(struct skb_shared_info))) -struct ahash_request ;struct net_device ;struct scatterlist ;struct pipe_inode_info ;struct iov_iter ;struct napi_struct ;
@@ -4132,13 +4131,10 @@ static inline int skb_copy_datagram_msg(const struct sk_buff *from, int offset, {return skb_copy_datagram_iter (from, offset, &msg->msg_iter, size); }int skb_copy_and_csum_datagram_msg (struct sk_buff *skb,int hlen,struct msghdr *msg); -int skb_copy_and_hash_datagram_iter (const struct sk_buff *skb,int offset, -struct iov_iter *to,int len, -struct ahash_request *hash);int skb_copy_and_crc32c_datagram_iter (const struct sk_buff *skb,int offset,struct iov_iter *to,int len,u32 *crcp);int skb_copy_datagram_from_iter (struct sk_buff *skb,int offset,struct iov_iter *from,int len);int zerocopy_sg_from_iter (struct sk_buff *skb,struct iov_iter *frm);
net/core/datagram.c +0 -37
@@ -60,11 +60,10 @@#include <net/checksum.h> #include <net/sock.h> #include <net/tcp_states.h> #include <trace/events/skb.h> #include <net/busy_poll.h> -#include <crypto/hash.h> #include "devmem.h" /* * Is a socket 'connection oriented' ?
@@ -482,46 +481,10 @@ static int __skb_datagram_iter(const struct sk_buff *skb, int offset, goto fault;return 0 ; } -static size_t hash_and_copy_to_iter (const void *addr,size_t bytes,void *hashp, -struct iov_iter *i) -{ -#ifdef CONFIG_CRYPTO_HASH -struct ahash_request *hash = hashp; -struct scatterlist sg; -size_t copied; - - copied =copy_to_iter (addr, bytes, i); -sg_init_one (&sg, addr, copied); -ahash_request_set_crypt (hash, &sg,NULL , copied); -crypto_ahash_update (hash); -return copied; -#else -return 0 ; -#endif -} - -/** -* skb_copy_and_hash_datagram_iter - Copy datagram to an iovec iterator -* and update a hash. -* @skb: buffer to copy -* @offset: offset in the buffer to start copying from -* @to: iovec iterator to copy to -* @len: amount of data to copy from buffer to iovec -* @hash: hash request to update -*/ -int skb_copy_and_hash_datagram_iter (const struct sk_buff *skb,int offset, -struct iov_iter *to,int len, -struct ahash_request *hash) -{ -return __skb_datagram_iter (skb, offset, to, len, true, - hash_and_copy_to_iter, hash); -} -EXPORT_SYMBOL (skb_copy_and_hash_datagram_iter); -#ifdef CONFIG_NET_CRC32C static size_t crc32c_and_copy_to_iter (const void *addr,size_t bytes,void *_crcp,struct iov_iter *i) {u32 *crcp = _crcp;
Signature · 1 line
2.49.0
Re: [PATCH v2 10/10] net: remove skb_copy_and_hash_datagram_iter()
Quoted 10 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Now that
skb_copy_and_hash_datagram_iter()is no longer used, remove it.Signed-off-by Eric Biggers <[email protected]>--- include/linux/skbuff.h | 4 ---- net/core/datagram.c | 37 ------------------------------------- 2 files changed, 41 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Quoted 7 lines · On Mon, 19 May 2025 10:50:02 -0700 Eric Biggers wrote:
Update networking code that computes the CRC32C of packets to just call
crc32c()without unnecessary abstraction layers. The result is faster and simpler code.Patches 1-7 add
skb_crc32c()and remove the overly-abstracted and inefficient__skb_checksum().
Quoted 6 lines
Patches 8-10 replace
skb_copy_and_hash_datagram_iter()withskb_copy_and_crc32c_datagram_iter(), eliminating the unnecessary use of the crypto layer. This unblocks the conversion of nvme-tcp to callcrc32c()directly instead of using the crypto layer, which patch 9 does.Please consider this series for net-next for 6.16.
Applied to net-next with Leon's ack he sent to v1. Thanks!