crc-offload: Split RX CRC offload from csum offload
Subsystems (12)
cover crc-offload: Split RX CRC offload from csum offload
In this patch set we create csum_valid_crc32 flag in the skbuff. This is used by drivers to report a valid offloaded CRC, in lieu of setting CHECKSUM_UNNECESSARY. The benefits of this are:
1) It's compatible with checksum-complete. We can do checksum- complete with a validate CRC at the same time
2) Checksum-unnecessary conversion may erase the indication of the offloaded CRC. For instance in a SCTP/UDP packet where the driver reports both the non-zero UDP checksum and the CRC have been validate (i.e. csum_level is set to 1), then checksum- complete conversion erases the indication and the host has to compute the CRC again
3) It just seems awkward in general to be mixing fundamentally different verifications, and wouldn't be surprising if there are more bugs lurking in this area
Additionally, some helper functions are added:
- skb_csum_crc32_unnecessary
- skb_reset_csum_crc32_unnecessary
- skb_set_csum_crc32_unnecessary
Changed FCOE and SCTP input to call skb_csum_crc32_unnecessary and skb_reset_csum_crc32_unnecessary
Call the helper function skb_set_csum_crc32_unnecessary from drivers instead of setting CHECKSUM_UNNECESSARY. This includes cavium thunder, gve, hisilicon, hns3, idpf, ixgbe, wangxun. If I missed any please let me know. The change was fairly simple, just need to identify that the SCTP or FCOE CRC was validated and call the function.
Tom Herbert (10):
skbuff: Rename csum_not_inet to csum_is_crc32
skbuff: Add csum_valid_crc32 flag
sctp: Call skb_csum_crc32_unnecessary
fcoe: Call skb_csum_crc32_unnecessary
cavium_thunder: Call skb_set_csum_crc32_unnecessary
gve: Call skb_set_csum_crc32_unnecessary
hisilicon: Call skb_set_csum_crc32_unnecessary
idpf: Call skb_set_csum_crc32_unnecessary
ixgbe: Call skb_set_csum_crc32_unnecessary
wangxun: Call skb_set_csum_crc32_unnecessary
.../net/ethernet/cavium/thunder/nicvf_main.c | 5 +- drivers/net/ethernet/google/gve/gve_rx_dqo.c | 4 +- drivers/net/ethernet/hisilicon/hns/hns_enet.c | 5 +- .../net/ethernet/hisilicon/hns3/hns3_enet.c | 18 ++++-- .../ethernet/intel/idpf/idpf_singleq_txrx.c | 4 +- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 2 +- drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c | 2 +- drivers/net/ethernet/wangxun/libwx/wx_lib.c | 5 +- drivers/scsi/fcoe/fcoe.c | 6 +- include/linux/skbuff.h | 58 +++++++++++++++---- net/core/dev.c | 2 +- net/sched/act_csum.c | 2 +- net/sctp/input.c | 6 +- net/sctp/offload.c | 2 +- net/sctp/output.c | 2 +- 15 files changed, 89 insertions(+), 34 deletions(-)
Signature · 1 line
2.34.1
RFC 1/10 skbuff: Rename csum_not_inet to csum_is_crc32
csum_not_inet really refers to SCTP or FCOE CRC. Rename to be more precise
--- include/linux/skbuff.h | 18 +++++++++--------- net/core/dev.c | 2 +- net/sched/act_csum.c | 2 +- net/sctp/offload.c | 2 +- net/sctp/output.c | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-)
include/linux/skbuff.h +9 -9
@@ -185,7 +185,7 @@* skb_csum_hwoffload_help() can be called to resolve %CHECKSUM_PARTIAL based * on network device checksumming capabilities: if a packet does not match * them, skb_checksum_help() or skb_crc32c_help() (depending on the value of -* &sk_buff.csum_not_inet, see :ref:`crc`) +* &sk_buff.csum_is_crc32, see :ref:`crc`) * is called to resolve the checksum. * * - %CHECKSUM_NONE
@@ -215,12 +215,12 @@* - This feature indicates that a device is capable of * offloading the SCTP CRC in a packet. To perform this offload the stack * will set csum_start and csum_offset accordingly, set ip_summed to -* %CHECKSUM_PARTIAL and set csum_not_inet to 1, to provide an indication +* %CHECKSUM_PARTIAL and set csum_is_crc32 to 1, to provide an indication * in the skbuff that the %CHECKSUM_PARTIAL refers to CRC32c. * A driver that supports both IP checksum offload and SCTP CRC32c offload * must verify which offload is configured for a packet by testing the -* value of &sk_buff.csum_not_inet; skb_crc32c_csum_help() is provided to -* resolve %CHECKSUM_PARTIAL on skbs where csum_not_inet is set to 1. +* value of &sk_buff.csum_is_crc32; skb_crc32c_csum_help() is provided to +* resolve %CHECKSUM_PARTIAL on skbs where csum_is_crc32 is set to 1. * * * - %NETIF_F_FCOE_CRC * - This feature indicates that a device is capable of offloading the FCOE
@@ -822,7 +822,7 @@ enum skb_tstamp_type {* @encapsulation: indicates the inner headers in the skbuff are valid * @encap_hdr_csum: software checksum is needed * @csum_valid: checksum is already valid -* @csum_not_inet: use CRC32c to resolve CHECKSUM_PARTIAL +* @csum_is_crc32: use CRC32c to resolve CHECKSUM_PARTIAL * @csum_complete_sw: checksum was completed by software * @csum_level: indicates the number of consecutive checksums found in * the packet minus one that have been verified as
@@ -1006,7 +1006,7 @@ struct sk_buff {#endif __u8 slow_gro:1;#if IS_ENABLED (CONFIG_IP_SCTP ) - __u8 csum_not_inet:1; + __u8 csum_is_crc32:1;#endif #if defined(CONFIG_NET_SCHED ) || defined(CONFIG_NET_XGRESS )
@@ -5098,17 +5098,17 @@ static inline void skb_set_redirected_noclear(struct sk_buff *skb,static inline bool skb_csum_is_sctp (struct sk_buff *skb) {#if IS_ENABLED (CONFIG_IP_SCTP ) -return skb->csum_not_inet; +return skb->csum_is_crc32;#else return 0 ;#endif } -static inline void skb_reset_csum_not_inet (struct sk_buff *skb) +static inline void skb_reset_csum_is_crc32 (struct sk_buff *skb) { skb->ip_summed =CHECKSUM_NONE ;#if IS_ENABLED (CONFIG_IP_SCTP ) - skb->csum_not_inet =0 ; + skb->csum_is_crc32 =0 ;#endif }
net/core/dev.c +1 -1
@@ -3382,7 +3382,7 @@ int skb_crc32c_csum_help(struct sk_buff *skb) skb->len - start, ~(__u32 )0 , crc32c_csum_stub)); *(__le32 *)(skb->data + offset) = crc32c_csum; -skb_reset_csum_not_inet (skb); +skb_reset_csum_is_crc32 (skb); out:return ret; }
net/sched/act_csum.c +1 -1
@@ -376,7 +376,7 @@ static int tcf_csum_sctp(struct sk_buff *skb, unsigned int ihl, sctph->checksum =sctp_compute_cksum (skb,skb_network_offset (skb) + ihl); -skb_reset_csum_not_inet (skb); +skb_reset_csum_is_crc32 (skb);return 1 ; }
net/sctp/offload.c +1 -1
@@ -27,7 +27,7 @@static __le32 sctp_gso_make_checksum (struct sk_buff *skb) { skb->ip_summed =CHECKSUM_NONE ; - skb->csum_not_inet =0 ; + skb->csum_is_crc32 =0 ;/* csum and csum_start in GSO CB may be needed to do the UDP * checksum when it's a UDP tunneling packet. */
net/sctp/output.c +1 -1
@@ -553,7 +553,7 @@ static int sctp_packet_pack(struct sctp_packet *packet, }else { chksum: head->ip_summed =CHECKSUM_PARTIAL ; - head->csum_not_inet =1 ; + head->csum_is_crc32 =1 ; head->csum_start =skb_transport_header (head) - head->head; head->csum_offset = offsetof(struct sctphdr , checksum); }
Signature · 1 line
2.34.1
Re: [RFC net-next 01/10] skbuff: Rename csum_not_inet to csum_is_crc32
Quoted 4 lines · Tom Herbert
csum_not_inetreally refers to SCTP or FCOE CRC. Rename to be more preciseSigned-off-by Tom Herbert <[email protected]>
I checked that you haven't missed any instances of csum_not_inet unmodified.
The rename seems straightforward and unobjectionable given that the description of the csum_not_inet field said that it was a crc32 anway.
The previous name also contained an awkward negation. Removing that seems like an improvement.
FWIW,
RFC 2/10 skbuff: Add csum_valid_crc32 flag
In reply to Tom HerbertWhen a device gets notification of that a CRC has been validated (either for SCTP or FCOE) then this is treated as an instance of checksum-unnecessary. This creates a few problems:
1) It's incompatible with checksum-complete. We cannot do checksum- complete with a validate CRC at the same time
2) Checksum-unnecessary conversion may erase the indication of the offloaded CRC. For instance in a SCTP/UDP packet where the driver reports both the non-zero UDP checksum and the CRC have been validated (i.e. csum_level is set to 1), then checksum- complete conversion erases the indication and the host has to compute the CRC again
3) It just seems awkward in general to be mixing fundamentally different verifications, and wouldn't be surprising if there are bugs lurking in this area
This patch introduces csum_valid_crc32 flag in the skbuff. This is used to inidicate an offloaded CRC. It's independent of the checksum fields.
Additionally, some helper functions are added:
- skb_csum_crc32_unnecessary
- skb_set_csum_crc32_unnecessary
- skb_reset_csum_crc32_unnecessary
Add comment about new method for offloading SCTP and FCOE RX CRC
--- include/linux/skbuff.h | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-)
include/linux/skbuff.h +37 -3
@@ -119,8 +119,6 @@* zero UDP checksum for either IPv4 or IPv6, the networking stack * may perform further validation in this case. * - GRE: only if the checksum is present in the header. -* - SCTP: indicates the CRC in SCTP header has been validated. -* - FCOE: indicates the CRC in FC frame has been validated. * * &sk_buff.csum_level indicates the number of consecutive checksums found in * the packet minus one that have been verified as %CHECKSUM_UNNECESSARY.
@@ -142,7 +140,6 @@* * - Even if device supports only some protocols, but is able to produce * skb->csum, it MUST use CHECKSUM_COMPLETE, not CHECKSUM_UNNECESSARY. -* - CHECKSUM_COMPLETE is not applicable to SCTP and FCoE protocols. * * - %CHECKSUM_PARTIAL *
@@ -156,6 +153,15 @@* packet that are after the checksum being offloaded are not considered to * be verified. * +* SCTP or FCOE CRC in received packets verfied by device +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* An SCTP or FCOE CRC may be verified by device and reported as valid by a +* driver. This is done by setting skb->csum_valid_crc32 to 1. The helper +* function skb_set_csum_crc32_unnecessary should be called to do that. +* The CRC validation can be checked by calling skb_csum_crc32_unnecessary +* and cleared by calling skb_reset_csum_crc32_unnecessary +* * Checksumming on transmit for non-GSO * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
@@ -1008,6 +1014,9 @@ struct sk_buff {#if IS_ENABLED (CONFIG_IP_SCTP ) __u8 csum_is_crc32:1;#endif +#if IS_ENABLED (CONFIG_IP_SCTP ) ||IS_ENABLED (CONFIG_FCOE ) + __u8 csum_valid_crc32:1; +#endif #if defined(CONFIG_NET_SCHED ) || defined(CONFIG_NET_XGRESS )__u16 tc_index;/* traffic control index */
@@ -4453,6 +4462,31 @@ static inline int skb_csum_unnecessary(const struct sk_buff *skb) skb_checksum_start_offset(skb) >= 0)); } +static inline int skb_csum_crc32_unnecessary (const struct sk_buff *skb) +{ +#if IS_ENABLED (CONFIG_IP_SCTP ) ||IS_ENABLED (CONFIG_FCOE ) +return (skb->csum_valid_crc32 || + (skb->ip_summed ==CHECKSUM_PARTIAL && +skb_checksum_start_offset (skb) >=0 )); +#else +return 0 ; +#endif +} + +static inline void skb_reset_csum_crc32_unnecessary (struct sk_buff *skb) +{ +#if IS_ENABLED (CONFIG_IP_SCTP ) ||IS_ENABLED (CONFIG_FCOE ) + skb->csum_valid_crc32 =0 ; +#endif +} + +static inline void skb_set_csum_crc32_unnecessary (struct sk_buff *skb) +{ +#if IS_ENABLED (CONFIG_IP_SCTP ) ||IS_ENABLED (CONFIG_FCOE ) + skb->csum_valid_crc32 =1 ; +#endif +} +/** * skb_checksum_complete - Calculate checksum of an entire packet * @skb: packet to process
Signature · 1 line
2.34.1
RFC 3/10 sctp: Call skb_csum_crc32_unnecessary
In reply to Tom HerbertInstead of checking for CHECKSUM_UNNECESSARY, call skb_csum_crc32_unnecessary to see if the SCTP CRC has been validated. If it is then call skb_reset_csum_crc32_unnecessary to clear the flag
--- net/sctp/input.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
net/sctp/input.c +2 -4
@@ -124,14 +124,12 @@ int sctp_rcv(struct sk_buff *skb)/* Pull up the IP header. */ __skb_pull (skb,skb_transport_offset (skb)); - skb->csum_valid =0 ;/* Previous value not applicable */ -if (skb_csum_unnecessary (skb)) -__skb_decr_checksum_unnecessary (skb); +if (skb_csum_crc32_unnecessary (skb)) +skb_reset_csum_crc32_unnecessary (skb);else if (!sctp_checksum_disable && !is_gso &&sctp_rcv_checksum (net, skb) <0 ) goto discard_it; - skb->csum_valid =1 ;__skb_pull (skb,sizeof (struct sctphdr ));
Signature · 1 line
2.34.1
RFC 4/10 fcoe: Call skb_csum_crc32_unnecessary
In reply to Tom HerbertInstead of checking for CHECKSUM_UNNECESSARY, call skb_csum_crc32_unnecessary to see if the FCOE CRC has been validated. If it is, then call skb_reset_csum_crc32_unnecessary to clear the flag
--- drivers/scsi/fcoe/fcoe.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/scsi/fcoe/fcoe.c +4 -2
@@ -1612,10 +1612,12 @@ static inline int fcoe_filter_frames(struct fc_lport *lport,* it's solicited data, in which case, the FCP layer would * check it during the copy. */ -if (lport->crc_offload && skb->ip_summed ==CHECKSUM_UNNECESSARY ) +if (lport->crc_offload &&skb_csum_crc32_unnecessary (skb)) {fr_flags (fp) &= ~FCPHF_CRC_UNCHECKED ; -else +skb_reset_csum_crc32_unnecessary (skb); + }else {fr_flags (fp) |=FCPHF_CRC_UNCHECKED ; + } fh =fc_frame_header_get (fp);if (fh->fh_r_ctl ==FC_RCTL_DD_SOL_DATA && fh->fh_type ==FC_TYPE_FCP )
Signature · 1 line
2.34.1
RFC 5/10 cavium_thunder: Call skb_set_csum_crc32_unnecessary
In reply to Tom HerbertWhen a validated offload CRC for SCTP is detected call skb_set_csum_crc32_unnecessary instead of setting CHECKSUM_UNNECESSARY
--- drivers/net/ethernet/cavium/thunder/nicvf_main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/cavium/thunder/nicvf_main.c +4 -1
@@ -824,7 +824,10 @@ static void nicvf_rcv_pkt_handler(struct net_device *netdev,skb_record_rx_queue (skb, rq_idx);if (netdev->hw_features &NETIF_F_RXCSUM ) {/* HW by default verifies TCP/UDP/SCTP checksums */ - skb->ip_summed =CHECKSUM_UNNECESSARY ; +if (cqe_rx->l4_type ==L4TYPE_SCTP ) +skb_set_csum_crc32_unnecessary (skb); +else + skb->ip_summed =CHECKSUM_UNNECESSARY ; }else {skb_checksum_none_assert (skb); }
Signature · 1 line
2.34.1
RFC 6/10 gve: Call skb_set_csum_crc32_unnecessary
In reply to Tom HerbertWhen a validated offload CRC for SCTP is detected call skb_set_csum_crc32_unnessary instead of setting CHECKSUM_UNNECESSARY
--- drivers/net/ethernet/google/gve/gve_rx_dqo.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/google/gve/gve_rx_dqo.c +3 -1
@@ -625,9 +625,11 @@ static void gve_rx_skb_csum(struct sk_buff *skb,case GVE_L4_TYPE_TCP :case GVE_L4_TYPE_UDP :case GVE_L4_TYPE_ICMP : -case GVE_L4_TYPE_SCTP : skb->ip_summed =CHECKSUM_UNNECESSARY ;break ; +case GVE_L4_TYPE_SCTP : +skb_set_csum_crc32_unnecessary (skb); +break ;default :break ; }
Signature · 1 line
2.34.1
RFC 7/10 hisilicon: Call skb_set_csum_crc32_unnecessary
In reply to Tom HerbertWhen a validated offload CRC for SCTP is detected call skb_set_csum_crc32_unnessary instead of setting CHECKSUM_UNNECESSARY
--- drivers/net/ethernet/hisilicon/hns/hns_enet.c | 5 ++++- .../net/ethernet/hisilicon/hns3/hns3_enet.c | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-)
drivers/net/ethernet/hisilicon/hns/hns_enet.c +4 -1
@@ -556,7 +556,10 @@ static void hns_nic_rx_checksum(struct hns_nic_ring_data *ring_data,return ;/* now, this has to be a packet with valid RX checksum */ - skb->ip_summed =CHECKSUM_UNNECESSARY ; +if (l4id ==HNS_RX_FLAG_L4ID_SCTP ) +skb_set_csum_crc32_unnecessary (skb); +else + skb->ip_summed =CHECKSUM_UNNECESSARY ; } static int hns_nic_poll_rx_skb(struct hns_nic_ring_data *ring_data,
drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +13 -5
@@ -3908,11 +3908,19 @@ static void hns3_rx_handle_csum(struct sk_buff *skb, u32 l234info, HNS3_RXD_L4ID_S);/* Can checksum ipv4 or ipv6 + UDP/TCP/SCTP packets */ if ((l3_type ==HNS3_L3_TYPE_IPV4 || - l3_type ==HNS3_L3_TYPE_IPV6 ) && - (l4_type ==HNS3_L4_TYPE_UDP || - l4_type ==HNS3_L4_TYPE_TCP || - l4_type ==HNS3_L4_TYPE_SCTP )) - skb->ip_summed =CHECKSUM_UNNECESSARY ; + l3_type ==HNS3_L3_TYPE_IPV6 )) { +switch (l4_type) { +case HNS3_L4_TYPE_UDP : +case HNS3_L4_TYPE_TCP : + skb->ip_summed =CHECKSUM_UNNECESSARY ; +break ; +case HNS3_L4_TYPE_SCTP : +skb_set_csum_crc32_unnecessary (skb); +break ; +default : +break ; + } + }break ;default :break ;
Signature · 1 line
2.34.1
RFC 8/10 idpf: Call skb_set_csum_crc32_unnecessary
In reply to Tom HerbertWhen a validated offload CRC for SCTP is detected call skb_set_csum_crc32_unnecessary instead of setting CHECKSUM_UNNECESSARY
--- drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c | 4 +++- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +3 -1
@@ -698,9 +698,11 @@ static void idpf_rx_singleq_csum(struct idpf_queue *rxq, struct sk_buff *skb,case IDPF_RX_PTYPE_INNER_PROT_ICMP :case IDPF_RX_PTYPE_INNER_PROT_TCP :case IDPF_RX_PTYPE_INNER_PROT_UDP : -case IDPF_RX_PTYPE_INNER_PROT_SCTP : skb->ip_summed =CHECKSUM_UNNECESSARY ;return ; +case IDPF_RX_PTYPE_INNER_PROT_SCTP : +skb_set_csum_crc32_unnecessary (skb); +return ;default :return ; }
drivers/net/ethernet/intel/idpf/idpf_txrx.c +1 -1
@@ -2804,7 +2804,7 @@ static void idpf_rx_csum(struct idpf_queue *rxq, struct sk_buff *skb, }break ;case IDPF_RX_PTYPE_INNER_PROT_SCTP : - skb->ip_summed =CHECKSUM_UNNECESSARY ; +skb_set_csum_crc32_unnecessary (skb);break ;default :break ;
Signature · 1 line
2.34.1
RFC 9/10 ixgbe: Call skb_set_csum_crc32_unnecessary
In reply to Tom HerbertWhen a validated offload CRC for FCOE is detected call skb_set_csum_crc32_unnessary instead of setting CHECKSUM_UNNECESSARY
--- drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c +1 -1
@@ -398,7 +398,7 @@ int ixgbe_fcoe_ddp(struct ixgbe_adapter *adapter,if (fcerr ==cpu_to_le32 (IXGBE_FCERR_BADCRC )) skb->ip_summed =CHECKSUM_NONE ;else - skb->ip_summed =CHECKSUM_UNNECESSARY ; +skb_set_csum_crc32_unnecessary (skb);if (eth_hdr (skb)->h_proto ==htons (ETH_P_8021Q )) fh = (struct fc_frame_header *)(skb->data +
Signature · 1 line
2.34.1
RFC 10/10 wangxun: Call skb_set_csum_crc32_unnecessary
In reply to Tom HerbertWhen a validated offload CRC for SCTP is detected call skb_set_csum_crc32_unnessary instead of setting CHECKSUM_UNNECESSARY
--- drivers/net/ethernet/wangxun/libwx/wx_lib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/wangxun/libwx/wx_lib.c +4 -1
@@ -558,7 +558,10 @@ static void wx_rx_checksum(struct wx_ring *ring, }/* It must be a TCP or UDP or SCTP packet with a valid checksum */ - skb->ip_summed =CHECKSUM_UNNECESSARY ; +if (dptype.prot ==WX_DEC_PTYPE_PROT_SCTP ) +skb_set_csum_crc32_unnecessary (skb); +else + skb->ip_summed =CHECKSUM_UNNECESSARY ;/* If there is an outer header present that might contain a checksum * we need to bump the checksum level by 1 to reflect the fact that
Signature · 1 line
2.34.1