As the virtio-net offload API is used for netdev-linux ports, but provides no information about the potentially encapsulated protocol concerned by a checksum request, specific informations from this netdev- specific implementation is propagated into OVS code, and must be carefully evaluated when some tunnel gets decapsulated.
This induces a cost in "normal" processing path, while the netdev-linux path is not performance critical. This patch removes such specific information, yet try harder to parse the packet on the Rx side and set offload flags accordingly for non encapsulated traffic. For encapsulated traffic, the inner checksum is computed. Signed-off-by: David Marchand <david.march...@redhat.com> --- Changes since v5: - added a coverage counter for invalid requests from the Linux kernel, - reused parse_tcp_flags(), this requires a temp hack in patch 1, setting L4 csum status (this disappears when L4 offloads are reworked later in this series), Changes since v3: - dropped setting Tx flags, Changes since v1: - fixed patch reordering issue: offloads fields was being added instead of later in this series, --- lib/dp-packet.c | 3 -- lib/dp-packet.h | 24 -------------- lib/dpif-netdev-extract-avx512.c | 2 -- lib/flow.c | 6 ---- lib/netdev-linux.c | 57 ++++++++++++++++++++++++++------ lib/netdev-native-tnl.c | 6 +--- 6 files changed, 48 insertions(+), 50 deletions(-) diff --git a/lib/dp-packet.c b/lib/dp-packet.c index dad0d7be3a..6a9bfd63ba 100644 --- a/lib/dp-packet.c +++ b/lib/dp-packet.c @@ -39,9 +39,6 @@ dp_packet_init__(struct dp_packet *b, size_t allocated, enum dp_packet_source so dp_packet_init_specific(b); /* By default assume the packet type to be Ethernet. */ b->packet_type = htonl(PT_ETH); - /* Reset csum start and offset. */ - b->csum_start = 0; - b->csum_offset = 0; } static void diff --git a/lib/dp-packet.h b/lib/dp-packet.h index 549802167d..084e89bd99 100644 --- a/lib/dp-packet.h +++ b/lib/dp-packet.h @@ -178,8 +178,6 @@ struct dp_packet { or UINT16_MAX. */ uint32_t cutlen; /* length in bytes to cut from the end. */ ovs_be32 packet_type; /* Packet type as defined in OpenFlow */ - uint16_t csum_start; /* Position to start checksumming from. */ - uint16_t csum_offset; /* Offset to place checksum. */ union { struct pkt_metadata md; uint64_t data[DP_PACKET_CONTEXT_SIZE / 8]; @@ -1539,34 +1537,12 @@ dp_packet_ol_set_l4_csum_bad(struct dp_packet *p) *dp_packet_ol_flags_ptr(p) |= DP_PACKET_OL_RX_L4_CKSUM_BAD; } -/* Marks packet 'p' with good integrity if checksum offload locations - * were provided. In the case of encapsulated packets, these values may - * be deeper into the packet than OVS might expect. But the packet - * should still be considered to have good integrity. - * The 'csum_start' is the offset from the begin of the packet headers. - * The 'csum_offset' is the offset from start to place the checksum. - * The csum_start and csum_offset fields are set from the virtio_net_hdr - * struct that may be provided by a netdev on packet ingress. */ -static inline void -dp_packet_ol_l4_csum_check_partial(struct dp_packet *p) -{ - if (p->csum_start && p->csum_offset) { - dp_packet_ol_set_l4_csum_partial(p); - } -} - static inline void dp_packet_reset_packet(struct dp_packet *b, int off) { dp_packet_set_size(b, dp_packet_size(b) - off); dp_packet_set_data(b, ((unsigned char *) dp_packet_data(b) + off)); dp_packet_reset_offsets(b); - - if (b->csum_start >= off && b->csum_offset) { - /* Adjust values for decapsulation. */ - b->csum_start -= off; - dp_packet_ol_set_l4_csum_partial(b); - } } static inline uint32_t ALWAYS_INLINE diff --git a/lib/dpif-netdev-extract-avx512.c b/lib/dpif-netdev-extract-avx512.c index 57ca4c71b7..3ae850c2d5 100644 --- a/lib/dpif-netdev-extract-avx512.c +++ b/lib/dpif-netdev-extract-avx512.c @@ -776,7 +776,6 @@ mfex_ipv6_set_hwol(struct dp_packet *pkt) static void mfex_tcp_set_hwol(struct dp_packet *pkt) { - dp_packet_ol_l4_csum_check_partial(pkt); if (dp_packet_l4_checksum_good(pkt) || dp_packet_ol_l4_csum_partial(pkt)) { dp_packet_hwol_set_csum_tcp(pkt); @@ -786,7 +785,6 @@ mfex_tcp_set_hwol(struct dp_packet *pkt) static void mfex_udp_set_hwol(struct dp_packet *pkt) { - dp_packet_ol_l4_csum_check_partial(pkt); if (dp_packet_l4_checksum_good(pkt) || dp_packet_ol_l4_csum_partial(pkt)) { dp_packet_hwol_set_csum_udp(pkt); diff --git a/lib/flow.c b/lib/flow.c index c2e1e4ad6f..988ae6bfdc 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -1080,7 +1080,6 @@ miniflow_extract(struct dp_packet *packet, struct miniflow *dst) } else if (dl_type == htons(ETH_TYPE_IPV6)) { dp_packet_update_rss_hash_ipv6_tcp_udp(packet); } - dp_packet_ol_l4_csum_check_partial(packet); if (dp_packet_l4_checksum_good(packet) || dp_packet_ol_l4_csum_partial(packet)) { dp_packet_hwol_set_csum_tcp(packet); @@ -1100,7 +1099,6 @@ miniflow_extract(struct dp_packet *packet, struct miniflow *dst) } else if (dl_type == htons(ETH_TYPE_IPV6)) { dp_packet_update_rss_hash_ipv6_tcp_udp(packet); } - dp_packet_ol_l4_csum_check_partial(packet); if (dp_packet_l4_checksum_good(packet) || dp_packet_ol_l4_csum_partial(packet)) { if (tunneling) { @@ -1118,7 +1116,6 @@ miniflow_extract(struct dp_packet *packet, struct miniflow *dst) miniflow_push_be16(mf, tp_dst, sctp->sctp_dst); miniflow_push_be16(mf, ct_tp_src, ct_tp_src); miniflow_push_be16(mf, ct_tp_dst, ct_tp_dst); - dp_packet_ol_l4_csum_check_partial(packet); if (dp_packet_l4_checksum_good(packet) || dp_packet_ol_l4_csum_partial(packet)) { dp_packet_hwol_set_csum_sctp(packet); @@ -1309,20 +1306,17 @@ parse_tcp_flags(struct dp_packet *packet, if (nw_proto == IPPROTO_TCP && size >= TCP_HEADER_LEN) { const struct tcp_header *tcp = data; - dp_packet_ol_l4_csum_check_partial(packet); if (dp_packet_l4_checksum_good(packet) || dp_packet_ol_l4_csum_partial(packet)) { dp_packet_hwol_set_csum_tcp(packet); } return TCP_FLAGS(tcp->tcp_ctl); } else if (nw_proto == IPPROTO_UDP && size >= UDP_HEADER_LEN) { - dp_packet_ol_l4_csum_check_partial(packet); if (dp_packet_l4_checksum_good(packet) || dp_packet_ol_l4_csum_partial(packet)) { dp_packet_hwol_set_csum_udp(packet); } } else if (nw_proto == IPPROTO_SCTP && size >= SCTP_HEADER_LEN) { - dp_packet_ol_l4_csum_check_partial(packet); if (dp_packet_l4_checksum_good(packet) || dp_packet_ol_l4_csum_partial(packet)) { dp_packet_hwol_set_csum_sctp(packet); diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index af7438f1ee..4fec93caf4 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -89,6 +89,8 @@ COVERAGE_DEFINE(netdev_get_hwaddr); COVERAGE_DEFINE(netdev_set_hwaddr); COVERAGE_DEFINE(netdev_get_ethtool); COVERAGE_DEFINE(netdev_set_ethtool); +COVERAGE_DEFINE(netdev_linux_invalid_l4_csum); +COVERAGE_DEFINE(netdev_linux_unknown_l4_csum); #ifndef IFLA_IF_NETNSID @@ -7055,16 +7057,51 @@ netdev_linux_parse_vnet_hdr(struct dp_packet *b) } if (vnet->flags == VIRTIO_NET_HDR_F_NEEDS_CSUM) { - /* The packet has offloaded checksum. However, there is no - * additional information like the protocol used, so it would - * require to parse the packet here. The checksum starting point - * and offset are going to be verified when the packet headers - * are parsed during miniflow extraction. */ - b->csum_start = (OVS_FORCE uint16_t) vnet->csum_start; - b->csum_offset = (OVS_FORCE uint16_t) vnet->csum_offset; - } else { - b->csum_start = 0; - b->csum_offset = 0; + uint16_t csum_offset = (OVS_FORCE uint16_t) vnet->csum_offset; + uint16_t csum_start = (OVS_FORCE uint16_t) vnet->csum_start; + + if (csum_start >= dp_packet_size(b) + || csum_start + csum_offset >= dp_packet_size(b)) { + COVERAGE_INC(netdev_linux_invalid_l4_csum); + return EINVAL; + } + + /* Chicken/egg situation, report L4 checksum as partial so that + * L4 extraction works. */ + dp_packet_ol_set_l4_csum_partial(b); + parse_tcp_flags(b, NULL, NULL, NULL); + + if (csum_start == b->l4_ofs + && ((csum_offset == offsetof(struct tcp_header, tcp_csum) + && dp_packet_hwol_l4_is_tcp(b)) + || (csum_offset == offsetof(struct udp_header, udp_csum) + && dp_packet_hwol_l4_is_udp(b)) + || (csum_offset == offsetof(struct sctp_header, sctp_csum) + && dp_packet_hwol_l4_is_sctp(b)))) { + /* Nothing to do, L4 csum is already marked as partial. */ + } else { + ovs_be16 *csum_l4; + void *l4; + + COVERAGE_INC(netdev_linux_unknown_l4_csum); + + csum_l4 = dp_packet_at(b, csum_start + csum_offset, + sizeof *csum_l4); + if (!csum_l4) { + return EINVAL; + } + + l4 = dp_packet_at(b, csum_start, dp_packet_size(b) - csum_start); + *csum_l4 = csum(l4, dp_packet_size(b) - csum_start); + + if (dp_packet_hwol_l4_is_tcp(b) + || dp_packet_hwol_l4_is_udp(b) + || dp_packet_hwol_l4_is_sctp(b)) { + dp_packet_ol_set_l4_csum_good(b); + } else { + *dp_packet_ol_flags_ptr(b) &= ~DP_PACKET_OL_RX_L4_CKSUM_MASK; + } + } } int ret = 0; diff --git a/lib/netdev-native-tnl.c b/lib/netdev-native-tnl.c index 6dc47de392..89208bd0d0 100644 --- a/lib/netdev-native-tnl.c +++ b/lib/netdev-native-tnl.c @@ -337,11 +337,7 @@ netdev_tnl_push_udp_header(const struct netdev *netdev OVS_UNUSED, } else { dp_packet_hwol_set_csum_udp(packet); } - } - - if (packet->csum_start && packet->csum_offset) { - dp_packet_ol_set_l4_csum_partial(packet); - } else if (!udp->udp_csum) { + } else { dp_packet_ol_set_l4_csum_good(packet); } -- 2.49.0 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev