Add AVX512 Ipv6 optimized profile for vlan/IPv6/UDP and vlan/IPv6/TCP, IPv6/UDP and IPv6/TCP.
MFEX autovalidaton test-case already has the IPv6 support for validating against the scalar mfex. Signed-off-by: Kumar Amber <kumar.am...@intel.com> Signed-off-by: Harry van Haaren <harry.van.haa...@intel.com> Co-authored-by: Harry van Haaren <harry.van.haa...@intel.com> --- v5: - Add variable length checks for IPv6 and TCP. v4: - Rebase to master. v2: - Fix CI build error. - Fix check-patch sign-offs. --- --- NEWS | 5 + lib/automake.mk | 1 + lib/dpif-netdev-extract-avx512.c | 277 +++++++++++++++++++++++++++++- lib/dpif-netdev-private-extract.c | 51 +++++- lib/dpif-netdev-private-extract.h | 12 ++ 5 files changed, 344 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index df633e8e2..422708912 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,11 @@ Post-v2.17.0 * 'relay' service model now supports transaction history, i.e. honors the 'last-txn-id' field in 'monitor_cond_since' requests from clients. + - Userspace datapath: + * Add AVX512 optimized profiles to miniflow extract for IPv6/UDP and + IPv6/TCP. + * Add AVX512 optimized profiles to miniflow extract for VLAN/IPv6/UDP + and VLAN/IPv6/TCP. v2.17.0 - xx xxx xxxx --------------------- diff --git a/lib/automake.mk b/lib/automake.mk index a23cdc4ad..139220c23 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -33,6 +33,7 @@ lib_libopenvswitchavx512_la_CFLAGS = \ -mavx512f \ -mavx512bw \ -mavx512dq \ + -mavx512vl \ -mbmi \ -mbmi2 \ -fPIC \ diff --git a/lib/dpif-netdev-extract-avx512.c b/lib/dpif-netdev-extract-avx512.c index c1c1fefb6..8056aa9d6 100644 --- a/lib/dpif-netdev-extract-avx512.c +++ b/lib/dpif-netdev-extract-avx512.c @@ -49,6 +49,8 @@ #include "dpif-netdev-private-extract.h" #include "dpif-netdev-private-flow.h" +#define plen ip6_ctlun.ip6_un1.ip6_un1_plen + /* AVX512-BW level permutex2var_epi8 emulation. */ static inline __m512i __attribute__((target("avx512bw"))) @@ -137,6 +139,7 @@ _mm512_maskz_permutexvar_epi8_wrap(__mmask64 kmask, __m512i idx, __m512i a) #define PATTERN_ETHERTYPE_MASK PATTERN_ETHERTYPE_GEN(0xFF, 0xFF) #define PATTERN_ETHERTYPE_IPV4 PATTERN_ETHERTYPE_GEN(0x08, 0x00) #define PATTERN_ETHERTYPE_DT1Q PATTERN_ETHERTYPE_GEN(0x81, 0x00) +#define PATTERN_ETHERTYPE_IPV6 PATTERN_ETHERTYPE_GEN(0x86, 0xDD) /* VLAN (Dot1Q) patterns and masks. */ #define PATTERN_DT1Q_MASK \ @@ -201,6 +204,40 @@ _mm512_maskz_permutexvar_epi8_wrap(__mmask64 kmask, __m512i idx, __m512i a) NU, NU, NU, NU, NU, NU, NU, NU, 38, 39, 40, 41, NU, NU, NU, NU, /* TCP */ \ NU, NU, NU, NU, NU, NU, NU, NU, /* Unused. */ +/* Generator for checking IPv6 ver. */ +#define PATTERN_IPV6_GEN(VER_TRC, PROTO) \ + VER_TRC, /* Version: 4bits and Traffic class: 4bits. */ \ + 0, 0, 0, /* Traffic class: 4bits and Flow Label: 24bits. */ \ + 0, 0, /* Payload length 16bits. */ \ + PROTO, 0, /* Next Header 8bits and Hop limit 8bits. */ \ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Src IP: 128bits. */ \ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Dst IP: 128bits. */ + +#define PATTERN_IPV6_MASK PATTERN_IPV6_GEN(0xF0, 0xFF) +#define PATTERN_IPV6_UDP PATTERN_IPV6_GEN(0x60, 0x11) +#define PATTERN_IPV6_TCP PATTERN_IPV6_GEN(0x60, 0x06) + +#define PATTERN_IPV6_SHUFFLE \ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, NU, NU, /* Ether */ \ + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, /* IPv6 */ \ + 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, /* IPv6 */ \ + NU, NU, NU, NU, NU, NU, NU, NU, NU, NU, NU, NU, NU, NU, NU, NU, /* Unused */ + +/* VLAN (Dot1Q) patterns and masks. */ +#define PATTERN_DT1Q_MASK \ + 0x00, 0x00, 0xFF, 0xFF, +#define PATTERN_DT1Q_IPV6 \ + 0x00, 0x00, 0x86, 0xDD, + +#define PATTERN_DT1Q_IPV6_SHUFFLE \ + /* Ether (2 blocks): Note that *VLAN* type is written here. */ \ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 16, 17, 0, 0, \ + /* VLAN (1 block): Note that the *EtherHdr->Type* is written here. */ \ + 12, 13, 14, 15, 0, 0, 0, 0, \ + 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, /* IPv6 */ \ + 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, /* IPv6 */ \ + NU, NU, NU, NU, NU, NU, NU, NU, /* Unused */ + /* Generation of K-mask bitmask values, to zero out data in result. Note that * these correspond 1:1 to the above "*_SHUFFLE" values, and bit used must be * set in this K-mask, and "NU" values must be zero in the k-mask. Each mask @@ -213,6 +250,10 @@ _mm512_maskz_permutexvar_epi8_wrap(__mmask64 kmask, __m512i idx, __m512i a) #define KMASK_IPV4 0xF0FFULL #define KMASK_UDP 0x000FULL #define KMASK_TCP 0x0F00ULL +#define KMASK_IPV6 0xFFFFULL +#define KMASK_ETHER_IPV6 0x3FFFULL +#define KMASK_DT1Q_IPV6 0xFF0FULL +#define KMASK_IPV6_NOHDR 0x00FFULL #define PATTERN_IPV4_UDP_KMASK \ (KMASK_ETHER | (KMASK_IPV4 << 16) | (KMASK_UDP << 32)) @@ -226,6 +267,13 @@ _mm512_maskz_permutexvar_epi8_wrap(__mmask64 kmask, __m512i idx, __m512i a) #define PATTERN_DT1Q_IPV4_TCP_KMASK \ (KMASK_ETHER | (KMASK_DT1Q << 16) | (KMASK_IPV4 << 24) | (KMASK_TCP << 40)) +#define PATTERN_IPV6_KMASK \ + (KMASK_ETHER_IPV6 | (KMASK_IPV6 << 16) | (KMASK_IPV6 << 32)) + +#define PATTERN_DT1Q_IPV6_KMASK \ + (KMASK_ETHER_IPV6 | (KMASK_DT1Q_IPV6 << 16) | (KMASK_IPV6 << 32) | \ + (KMASK_IPV6_NOHDR << 48)) + /* Miniflow Strip post-processing masks. * This allows unsetting specific bits from the resulting miniflow. It is used * for e.g. IPv4 where the "DF" bit is never pushed to the miniflow itself. @@ -324,6 +372,10 @@ enum MFEX_PROFILES { PROFILE_ETH_IPV4_TCP, PROFILE_ETH_VLAN_IPV4_UDP, PROFILE_ETH_VLAN_IPV4_TCP, + PROFILE_ETH_IPV6_UDP, + PROFILE_ETH_IPV6_TCP, + PROFILE_ETH_VLAN_IPV6_TCP, + PROFILE_ETH_VLAN_IPV6_UDP, PROFILE_COUNT, }; @@ -415,8 +467,132 @@ static const struct mfex_profile mfex_profiles[PROFILE_COUNT] = }, .dp_pkt_min_size = 58, }, + + [PROFILE_ETH_IPV6_UDP] = { + .probe_mask.u8_data = { PATTERN_ETHERTYPE_MASK PATTERN_IPV6_MASK }, + .probe_data.u8_data = { PATTERN_ETHERTYPE_IPV6 PATTERN_IPV6_UDP }, + + .store_shuf.u8_data = { PATTERN_IPV6_SHUFFLE }, + .store_kmsk = PATTERN_IPV6_KMASK, + + .mf_bits = { 0x18a0000000000000, 0x000000000004043c}, + .dp_pkt_offs = { + 0, UINT16_MAX, 14, 54, + }, + .dp_pkt_min_size = 62, + }, + + [PROFILE_ETH_IPV6_TCP] = { + .probe_mask.u8_data = { PATTERN_ETHERTYPE_MASK PATTERN_IPV6_MASK }, + .probe_data.u8_data = { PATTERN_ETHERTYPE_IPV6 PATTERN_IPV6_TCP }, + + .store_shuf.u8_data = { PATTERN_IPV6_SHUFFLE }, + .store_kmsk = PATTERN_IPV6_KMASK, + + .mf_bits = { 0x18a0000000000000, 0x000000000004443c}, + .dp_pkt_offs = { + 0, UINT16_MAX, 14, 54, + }, + .dp_pkt_min_size = 74, + }, + + [PROFILE_ETH_VLAN_IPV6_TCP] = { + .probe_mask.u8_data = { + PATTERN_ETHERTYPE_MASK PATTERN_DT1Q_MASK PATTERN_IPV6_MASK }, + .probe_data.u8_data = { + PATTERN_ETHERTYPE_DT1Q PATTERN_DT1Q_IPV6 PATTERN_IPV6_TCP }, + + .store_shuf.u8_data = { PATTERN_DT1Q_IPV6_SHUFFLE }, + .store_kmsk = PATTERN_DT1Q_IPV6_KMASK, + + .mf_bits = { 0x38a0000000000000, 0x000000000004443c}, + .dp_pkt_offs = { + 14, UINT16_MAX, 18, 58, + }, + .dp_pkt_min_size = 78, + }, + + [PROFILE_ETH_VLAN_IPV6_UDP] = { + .probe_mask.u8_data = { + PATTERN_ETHERTYPE_MASK PATTERN_DT1Q_MASK PATTERN_IPV6_MASK }, + .probe_data.u8_data = { + PATTERN_ETHERTYPE_DT1Q PATTERN_DT1Q_IPV6 PATTERN_IPV6_UDP }, + + .store_shuf.u8_data = { PATTERN_DT1Q_IPV6_SHUFFLE }, + .store_kmsk = PATTERN_DT1Q_IPV6_KMASK, + + .mf_bits = { 0x38a0000000000000, 0x000000000004043c}, + .dp_pkt_offs = { + 14, UINT16_MAX, 18, 58, + }, + .dp_pkt_min_size = 66, + }, }; +/* IPv6 header helper function to fix TC, flow label and next header. */ +static inline void ALWAYS_INLINE +mfex_handle_ipv6_hdr_block(const uint8_t *ipv6, uint64_t *block) +{ + static const uint8_t data_shuf[16] = { + 0, 1, 2, 3, /* copy IPv6 label in place, it is masked later. */ + 1, 0, /* Byte-swap TC fields for LE usage. */ + 7, 6, /* Move TTL and next proto to MF required locations. */ + }; + + /* BE mask for IPv6 label, and mask to strip away unwanted TC bits. */ + const uint64_t mask = 0xffff0f00 | (UINT64_MAX << 40); + uint64_t mask_data[2] = { mask, mask }; + + /* Load constant data. Is lifted to occur 1x per burst, not per packet. */ + __m128i ipv6_hdr = _mm_loadu_si128((void *) ipv6); + __m128i v_mask = _mm_loadu_si128((void *) mask_data); + __m128i v_shuf_mask = _mm_loadu_si128((void *) data_shuf); + + /* Shuffle data layout, shift 16-bits to get TC fixed, mask to cleanup. */ + __m128i v_ipv6 = _mm_shuffle_epi8(ipv6_hdr, v_shuf_mask); + __m128i v_tc_shift = _mm_mask_slli_epi16(v_ipv6, 0b100, v_ipv6, 4); + __m128i v_ipv6_m = _mm_and_si128(v_tc_shift, v_mask); + + *block = _mm_extract_epi64(v_ipv6_m, 0); +} + +/* IPv6 Protocol specific helper functions, for handling L4 UDP/TCP. */ +static inline void +mfex_handle_ipv6_l4(const uint8_t *ports, uint64_t *block) +{ + void *ptr_ports = (void *) ports; + uint32_t l4_ports = *(uint32_t *) ptr_ports; + *block = l4_ports; +} + +/* IPv6 specific helper functions, for calculating offsets/lengths. */ +static int +mfex_ipv6_set_l2_pad_size(struct dp_packet *pkt, + struct ovs_16aligned_ip6_hdr *nh, + uint32_t payload_size_ipv6, + uint32_t next_hdr_size) +{ + /* Handle dynamic l2_pad_size. */ + uint16_t p_len = ntohs(nh->plen); + + /* Error if IP total length is greater than remaining packet size. */ + bool err_ipv6_len_too_high = p_len >= payload_size_ipv6; + + /* Error if IP total length is less than the size of the IP header + * itself, and the size of the next-protocol this profile matches on. + */ + bool err_ipv6_len_too_low = (IPV6_HEADER_LEN + next_hdr_size) > p_len; + + /* Ensure the l2 pad size will not overflow. */ + bool err_len_u16_overflow = (payload_size_ipv6 - p_len) > UINT16_MAX; + + if (OVS_UNLIKELY(err_ipv6_len_too_high || err_ipv6_len_too_low || + err_len_u16_overflow)) { + return -1; + } + dp_packet_set_l2_pad_size(pkt, payload_size_ipv6 - p_len); + return 0; +} /* Protocol specific helper functions, for calculating offsets/lenghts. */ static int32_t @@ -467,6 +643,14 @@ mfex_handle_tcp_flags(const struct tcp_header *tcp, uint64_t *block) *block = ctl_u64 << 32; } +static int +mfex_check_tcp_data_offset(const struct tcp_header *tcp) +{ + /* we dont support TCP options, offset must be 5. */ + bool ret = TCP_OFFSET(tcp->tcp_ctl) == 5; + return ret; +} + /* Generic loop to process any mfex profile. This code is specialized into * multiple actual MFEX implementation functions. Its marked ALWAYS_INLINE * to ensure the compiler specializes each instance. The code is marked "hot" @@ -614,6 +798,94 @@ mfex_avx512_process(struct dp_packet_batch *packets, } } break; + + case PROFILE_ETH_IPV6_UDP: { + /* Handle dynamic l2_pad_size. */ + uint32_t payload_size_ipv6 = size - sizeof(struct eth_header); + struct ovs_16aligned_ip6_hdr *nh = (void *)&pkt[sizeof + (struct eth_header)]; + if (mfex_ipv6_set_l2_pad_size(packet, nh, payload_size_ipv6, + UDP_HEADER_LEN)) { + continue; + } + + /* Process IPv6 header for TC, flow Label and next header. */ + mfex_handle_ipv6_hdr_block(&pkt[ETH_HEADER_LEN], &blocks[8]); + + /* Process UDP header. */ + mfex_handle_ipv6_l4((void *)&pkt[54], &blocks[9]); + + } break; + + case PROFILE_ETH_IPV6_TCP: { + /* Handle dynamic l2_pad_size. */ + uint32_t payload_size_ipv6 = size - sizeof(struct eth_header); + struct ovs_16aligned_ip6_hdr *nh = (void *)&pkt[sizeof + (struct eth_header)]; + if (mfex_ipv6_set_l2_pad_size(packet, nh, payload_size_ipv6, + TCP_HEADER_LEN)) { + continue; + } + + /* Process IPv6 header for TC, flow Label and next header. */ + mfex_handle_ipv6_hdr_block(&pkt[ETH_HEADER_LEN], &blocks[8]); + + /* Process TCP header. */ + mfex_handle_ipv6_l4((void *)&pkt[54], &blocks[10]); + const struct tcp_header *tcp = (void *)&pkt[54]; + if (!mfex_check_tcp_data_offset(tcp)) { + continue; + } + mfex_handle_tcp_flags(tcp, &blocks[9]); + + } break; + + case PROFILE_ETH_VLAN_IPV6_TCP: { + mfex_vlan_pcp(pkt[14], &keys[i].buf[4]); + + /* Handle dynamic l2_pad_size. */ + uint32_t payload_size_ipv6 = size - VLAN_ETH_HEADER_LEN; + struct ovs_16aligned_ip6_hdr *nh = (void *)&pkt + [VLAN_ETH_HEADER_LEN]; + if (mfex_ipv6_set_l2_pad_size(packet, nh, payload_size_ipv6, + TCP_HEADER_LEN)) { + continue; + } + + /* Process IPv6 header for TC, flow Label and next header. */ + mfex_handle_ipv6_hdr_block(&pkt[VLAN_ETH_HEADER_LEN], + &blocks[9]); + + /* Process TCP header. */ + mfex_handle_ipv6_l4((void *)&pkt[58], &blocks[11]); + const struct tcp_header *tcp = (void *)&pkt[58]; + if (!mfex_check_tcp_data_offset(tcp)) { + continue; + } + mfex_handle_tcp_flags(tcp, &blocks[10]); + + } break; + + case PROFILE_ETH_VLAN_IPV6_UDP: { + mfex_vlan_pcp(pkt[14], &keys[i].buf[4]); + + /* Handle dynamic l2_pad_size. */ + uint32_t payload_size_ipv6 = size - VLAN_ETH_HEADER_LEN; + struct ovs_16aligned_ip6_hdr *nh = (void *)&pkt + [VLAN_ETH_HEADER_LEN]; + if (mfex_ipv6_set_l2_pad_size(packet, nh, payload_size_ipv6, + TCP_HEADER_LEN)) { + continue; + } + + /* Process IPv6 header for TC, flow Label and next header. */ + mfex_handle_ipv6_hdr_block(&pkt[VLAN_ETH_HEADER_LEN], + &blocks[9]); + + /* Process UDP header. */ + mfex_handle_ipv6_l4((void *)&pkt[58], &blocks[10]); + + } break; default: break; }; @@ -659,7 +931,10 @@ DECLARE_MFEX_FUNC(ip_udp, PROFILE_ETH_IPV4_UDP) DECLARE_MFEX_FUNC(ip_tcp, PROFILE_ETH_IPV4_TCP) DECLARE_MFEX_FUNC(dot1q_ip_udp, PROFILE_ETH_VLAN_IPV4_UDP) DECLARE_MFEX_FUNC(dot1q_ip_tcp, PROFILE_ETH_VLAN_IPV4_TCP) - +DECLARE_MFEX_FUNC(ipv6_udp, PROFILE_ETH_IPV6_UDP) +DECLARE_MFEX_FUNC(ipv6_tcp, PROFILE_ETH_IPV6_TCP) +DECLARE_MFEX_FUNC(dot1q_ipv6_tcp, PROFILE_ETH_VLAN_IPV6_TCP) +DECLARE_MFEX_FUNC(dot1q_ipv6_udp, PROFILE_ETH_VLAN_IPV6_UDP) static int32_t avx512_isa_probe(uint32_t needs_vbmi) diff --git a/lib/dpif-netdev-private-extract.c b/lib/dpif-netdev-private-extract.c index 4b2f12015..c11309def 100644 --- a/lib/dpif-netdev-private-extract.c +++ b/lib/dpif-netdev-private-extract.c @@ -93,7 +93,56 @@ static struct dpif_miniflow_extract_impl mfex_impls[] = { [MFEX_IMPL_DOT1Q_IPv4_TCP] = { .probe = mfex_avx512_probe, .extract_func = mfex_avx512_dot1q_ip_tcp, - .name = "avx512_dot1q_ipv4_tcp", }, + .name = "avx512_dot1q_ipv4_tcp", + }, + + [MFEX_IMPL_VMBI_IPv6_UDP] = { + .probe = mfex_avx512_vbmi_probe, + .extract_func = mfex_avx512_vbmi_ipv6_udp, + .name = "avx512_vbmi_ipv6_udp", + }, + + [MFEX_IMPL_IPv6_UDP] = { + .probe = mfex_avx512_probe, + .extract_func = mfex_avx512_ipv6_udp, + .name = "avx512_ipv6_udp", + }, + + [MFEX_IMPL_VMBI_IPv6_TCP] = { + .probe = mfex_avx512_vbmi_probe, + .extract_func = mfex_avx512_vbmi_ipv6_tcp, + .name = "avx512_vbmi_ipv6_tcp", + }, + + [MFEX_IMPL_IPv6_TCP] = { + .probe = mfex_avx512_probe, + .extract_func = mfex_avx512_ipv6_tcp, + .name = "avx512_ipv6_tcp", + }, + + [MFEX_IMPL_VMBI_DOT1Q_IPv6_TCP] = { + .probe = mfex_avx512_vbmi_probe, + .extract_func = mfex_avx512_vbmi_dot1q_ipv6_tcp, + .name = "avx512_vbmi_avx512_dot1q_ipv6_tcp", + }, + + [MFEX_IMPL_DOT1Q_IPv6_TCP] = { + .probe = mfex_avx512_probe, + .extract_func = mfex_avx512_dot1q_ipv6_tcp, + .name = "avx512_dot1q_ipv6_tcp", + }, + + [MFEX_IMPL_VMBI_DOT1Q_IPv6_UDP] = { + .probe = mfex_avx512_vbmi_probe, + .extract_func = mfex_avx512_vbmi_dot1q_ipv6_udp, + .name = "avx512_vbmi_avx512_dot1q_ipv6_udp", + }, + + [MFEX_IMPL_DOT1Q_IPv6_UDP] = { + .probe = mfex_avx512_probe, + .extract_func = mfex_avx512_dot1q_ipv6_udp, + .name = "avx512_dot1q_ipv6_udp", + }, #endif }; diff --git a/lib/dpif-netdev-private-extract.h b/lib/dpif-netdev-private-extract.h index f9a757ba4..e10d840f3 100644 --- a/lib/dpif-netdev-private-extract.h +++ b/lib/dpif-netdev-private-extract.h @@ -90,6 +90,14 @@ enum dpif_miniflow_extract_impl_idx { MFEX_IMPL_DOT1Q_IPv4_UDP, MFEX_IMPL_VMBI_DOT1Q_IPv4_TCP, MFEX_IMPL_DOT1Q_IPv4_TCP, + MFEX_IMPL_VMBI_IPv6_UDP, + MFEX_IMPL_IPv6_UDP, + MFEX_IMPL_VMBI_IPv6_TCP, + MFEX_IMPL_IPv6_TCP, + MFEX_IMPL_VMBI_DOT1Q_IPv6_TCP, + MFEX_IMPL_DOT1Q_IPv6_TCP, + MFEX_IMPL_VMBI_DOT1Q_IPv6_UDP, + MFEX_IMPL_DOT1Q_IPv6_UDP, #endif MFEX_IMPL_MAX }; @@ -197,6 +205,10 @@ DECLARE_AVX512_MFEX_PROTOTYPE(ip_udp); DECLARE_AVX512_MFEX_PROTOTYPE(ip_tcp); DECLARE_AVX512_MFEX_PROTOTYPE(dot1q_ip_udp); DECLARE_AVX512_MFEX_PROTOTYPE(dot1q_ip_tcp); +DECLARE_AVX512_MFEX_PROTOTYPE(ipv6_udp); +DECLARE_AVX512_MFEX_PROTOTYPE(ipv6_tcp); +DECLARE_AVX512_MFEX_PROTOTYPE(dot1q_ipv6_tcp); +DECLARE_AVX512_MFEX_PROTOTYPE(dot1q_ipv6_udp); #endif /* __x86_64__ */ -- 2.25.1 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev