net/tap RSS BPF rewrite
Subsystems (2)
cover net/tap RSS BPF rewrite
This is a early (alpha) view of my recent work to to update (gut job) of the RSS handling in the tap device. The rework was so big that it did not make sense to do it in incremental stages.
Overall it comes out much simpler and cleaner. Much more testing is needed, at this point it will load the program and try and setup filter (but fails).
Stephen Hemminger (2):
tap: stop "vendoring" linux bpf headers
tap: rework BPF handling
.gitignore | 3 - drivers/net/tap/bpf/.gitignore | 2 + drivers/net/tap/bpf/Makefile | 21 +- drivers/net/tap/bpf/README | 12 + drivers/net/tap/bpf/bpf_api.h | 276 - drivers/net/tap/bpf/bpf_elf.h | 53 - drivers/net/tap/bpf/bpf_extract.py | 86 - drivers/net/tap/bpf/tap_bpf_program.c | 255 - drivers/net/tap/bpf/tap_rss.c | 269 + drivers/net/tap/meson.build | 26 +- drivers/net/tap/rte_eth_tap.c | 2 + drivers/net/tap/rte_eth_tap.h | 9 +- drivers/net/tap/tap_bpf.h | 121 - drivers/net/tap/tap_bpf_api.c | 190 - drivers/net/tap/tap_bpf_insns.h | 1743 ---- drivers/net/tap/tap_flow.c | 530 +- drivers/net/tap/tap_flow.h | 11 +- drivers/net/tap/tap_rss.h | 14 +- drivers/net/tap/tap_rss.skel.h | 11625 ++++++++++++++++++++++++ drivers/net/tap/tap_rss.stub.h | 45 + 20 files changed, 12137 insertions(+), 3156 deletions(-) create mode 100644 drivers/net/tap/bpf/.gitignore create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c delete mode 100644 drivers/net/tap/tap_bpf.h delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h create mode 100644 drivers/net/tap/tap_rss.skel.h create mode 100644 drivers/net/tap/tap_rss.stub.h
Signature · 1 line
2.43.0
RFC 1/2 tap: stop "vendoring" linux bpf headers
The proper place for finding bpf structures and functions is in linux/bpf.h. The original version was trying to workaround the case where the build environment was running on old pre BPF version of Glibc, but the target environment had BPF. This is not a supportable build method, and not how rest of DPDK works.
Having own private (and divergent) version headers leads to future problems when BPF definitions evolve.
Since DPDK officially supports only LTS or later kernel there is no need for the #ifdef workarounds in the TAP flow code. Cloning headers leads to problems and no longer needed.
--- drivers/net/tap/bpf/bpf_extract.py | 1 - drivers/net/tap/tap_bpf.h | 121 ----------------------------- drivers/net/tap/tap_bpf_api.c | 20 +++-- drivers/net/tap/tap_bpf_insns.h | 1 - drivers/net/tap/tap_flow.c | 89 --------------------- 5 files changed, 13 insertions(+), 219 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf.h
drivers/net/tap/bpf/bpf_extract.py +0 -1
@@ -65,7 +65,6 @@ def write_header(out, source): print(f' * Auto-generated from {source}', file=out) print(" * This not the original source file. Do NOT edit it.", file=out) print(" */\n", file=out) - print("#include <tap_bpf.h>", file=out) def main():
drivers/net/tap/tap_bpf.h deleted +0 -121
121 lines not on this page · raw message
drivers/net/tap/tap_bpf_api.c +13 -7
@@ -2,19 +2,19 @@* Copyright 2017 Mellanox Technologies, Ltd */ -#include <errno.h> -#include <string.h> #include <unistd.h> -#include <sys/queue.h> +#include <syscall.h> +#include <linux/bpf.h> -#include <rte_malloc.h> -#include <rte_eth_tap.h> #include <tap_flow.h> #include <tap_autoconf.h> -#include <tap_tcmsgs.h> -#include <tap_bpf.h> +#include <tap_bpf_insns.h> + +static int bpf_load (enum bpf_prog_type type,const struct bpf_insn *insns, +size_t insns_cnt,const char *license); +/** * Load BPF program (section cls_q) into the kernel and return a bpf fd *
@@ -89,7 +89,13 @@ static inline __u64 ptr_to_u64(const void *ptr)static inline int sys_bpf (enum bpf_cmd cmd,union bpf_attr *attr,unsigned int size) { +#ifdef __NR_bpfreturn syscall (__NR_bpf, cmd, attr, size); +#else +TAP_LOG (ERR ,"No bpf syscall, kernel headers too old?\n" ); + errno =ENOSYS ; +return -1 ; +#endif }/**
drivers/net/tap/tap_bpf_insns.h +0 -1
@@ -3,7 +3,6 @@* This not the original source file. Do NOT edit it. */ -#include <tap_bpf.h> static struct bpf_insn cls_q_insns[] = { {0x61 ,2 ,1 ,52 ,0x00000000 },
drivers/net/tap/tap_flow.c +0 -89
95 lines not on this page · raw message
Signature · 1 line
2.43.0
RFC 2/2 tap: rework BPF handling
In reply to Stephen HemmingerThere were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.
Key points:
- works with current kernels requiring BTF support[1]
- use libbpf for interactions with kernel
(no longer need the python extraction code)
- no longer needs to process packets twice;
the BPF reclassifier step is not needed
- does error checking on RSS flow parameters
- supports setting RSS key per flow (never done in original code)
- supports L3 only hash (original code was broken)
- supports IPv4 options and IPv6 extension header
- BPF program is only loaded once and not modified,
tc classid is used to find configuration
- remove unused code and fields
- code rewritten and commented for clarity
[1] This is based of the BPF map work in earlier patch from Madhuker Mythri <[email protected]>
Expect multiple checkpatch errors because it contains non RTE code (the BPF program) and autogenerated code from bpftool.
--- .gitignore | 3 - drivers/net/tap/bpf/.gitignore | 2 + drivers/net/tap/bpf/Makefile | 21 +- drivers/net/tap/bpf/README | 12 + drivers/net/tap/bpf/bpf_api.h | 276 - drivers/net/tap/bpf/bpf_elf.h | 53 - drivers/net/tap/bpf/bpf_extract.py | 85 - drivers/net/tap/bpf/tap_bpf_program.c | 255 - drivers/net/tap/bpf/tap_rss.c | 269 + drivers/net/tap/meson.build | 26 +- drivers/net/tap/rte_eth_tap.c | 2 + drivers/net/tap/rte_eth_tap.h | 9 +- drivers/net/tap/tap_bpf_api.c | 196 - drivers/net/tap/tap_bpf_insns.h | 1742 ---- drivers/net/tap/tap_flow.c | 443 +- drivers/net/tap/tap_flow.h | 11 +- drivers/net/tap/tap_rss.h | 14 +- drivers/net/tap/tap_rss.skel.h | 11625 ++++++++++++++++++++++++ drivers/net/tap/tap_rss.stub.h | 45 + 19 files changed, 12138 insertions(+), 2951 deletions(-) create mode 100644 drivers/net/tap/bpf/.gitignore create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h create mode 100644 drivers/net/tap/tap_rss.skel.h create mode 100644 drivers/net/tap/tap_rss.stub.h
.gitignore +0 -3
@@ -36,9 +36,6 @@ TAGS # ignore python bytecode files *.pyc -# ignore BPF programs -drivers/net/tap/bpf/tap_bpf_program.o - # DTS results dts/output
drivers/net/tap/bpf/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +# ignore the BPF object file +tap_rss.o
drivers/net/tap/bpf/Makefile +12 -9
@@ -2,18 +2,21 @@ # This file is not built as part of normal DPDK build. # It is used to generate the eBPF code for TAP RSS. -CLANG=clang -CLANG_OPTS=-O2 -TARGET=../tap_bpf_insns.h +CLANG = clang +BPFTOOL = /usr/sbin/bpftool +CLANG_OPTS = -O2 -Wall -Wextra +TARGET = ../tap_rss.skel.h + +CLANG_BPF_SYS_INCLUDES ?= $(shell $(CLANG) -v -E - </dev/null 2>&1 \ + | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') all: $(TARGET) clean: - rm tap_bpf_program.o $(TARGET) + rm tap_rss.o $(TARGET) -tap_bpf_program.o: tap_bpf_program.c - $(CLANG) $(CLANG_OPTS) -emit-llvm -c $< -o - | \ - llc -march=bpf -filetype=obj -o $@ +$(TARGET): tap_rss.o + $(BPFTOOL) gen skeleton $< > $@ -$(TARGET): tap_bpf_program.o - python3 bpf_extract.py -stap_bpf_program.c -o $@ $< +tap_rss.o: tap_rss.c + $(CLANG) $(CLANG_OPTS) $(CLANG_BPF_SYS_INCLUDES) -target bpf -c $< -g -o $@
drivers/net/tap/bpf/README new file +12 -0
@@ -0,0 +1,12 @@ +This is the BPF program used to implement the RSS across queues +flow action. It works like the skbedit tc filter but instead of mapping +to only one queues, it maps to multiple queues based on RSS hash. + +This version is built the BPF Compile Once — Run Everywhere (CO-RE) +framework and uses libbpf and bpftool. + +Limitations +- requires libbpf version XX or later +- rebuilding the BPF requires clang and bpftool +- only Toeplitz hash with standard 40 byte key is supported +- the number of queues per RSS action is limited to 16
drivers/net/tap/bpf/bpf_api.h deleted +0 -276
276 lines not on this page · raw message
drivers/net/tap/bpf/bpf_elf.h deleted +0 -53
53 lines not on this page · raw message
drivers/net/tap/bpf/bpf_extract.py deleted +0 -85
85 lines not on this page · raw message
drivers/net/tap/bpf/tap_bpf_program.c deleted +0 -255
255 lines not on this page · raw message
drivers/net/tap/bpf/tap_rss.c new file +269 -0
269 lines not on this page · raw message
drivers/net/tap/meson.build +7 -19
@@ -7,33 +7,21 @@ if not is_linux endif sources = files( 'rte_eth_tap.c', - 'tap_bpf_api.c', 'tap_flow.c', 'tap_intr.c', 'tap_netlink.c', 'tap_tcmsgs.c', ) +bpf_dep = dependency('libbpf', required: false, method: 'pkg-config') +if bpf_dep.found() + message('drivers/tap: RSS support (bpf)') + cflags += '-DHAVE_LIBBPF' + ext_deps += bpf_dep +endif + deps = ['bus_vdev', 'gso', 'hash'] cflags += '-DTAP_MAX_QUEUES=16' -# input array for meson symbol search: -# [ "MACRO to define if found", "header for the search", -# "enum/define", "symbol to search" ] -# -args = [ - [ 'HAVE_TC_FLOWER', 'linux/pkt_cls.h', 'TCA_FLOWER_UNSPEC' ], - [ 'HAVE_TC_VLAN_ID', 'linux/pkt_cls.h', 'TCA_FLOWER_KEY_VLAN_PRIO' ], - [ 'HAVE_TC_BPF', 'linux/pkt_cls.h', 'TCA_BPF_UNSPEC' ], - [ 'HAVE_TC_BPF_FD', 'linux/pkt_cls.h', 'TCA_BPF_FD' ], - [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ], - [ 'HAVE_TC_ACT_BPF_FD', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_FD' ], -] -config = configuration_data() -foreach arg:args - config.set(arg[0], cc.has_header_symbol(arg[1], arg[2])) -endforeach -configure_file(output : 'tap_autoconf.h', configuration : config) - require_iova_in_mbuf = false
drivers/net/tap/rte_eth_tap.c +2 -0
@@ -1138,6 +1138,7 @@ tap_dev_close(struct rte_eth_dev *dev)tap_flow_implicit_flush (internals,NULL );tap_nl_final (internals->nlsk_fd); internals->nlsk_fd =-1 ; +tap_flow_bpf_destroy (internals); }for (i =0 ; i <RTE_PMD_TAP_MAX_QUEUES ; i++) {
@@ -1959,6 +1960,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,strlcpy (pmd->name, tap_name,sizeof (pmd->name)); pmd->type = type; pmd->ka_fd =-1 ; + pmd->rss =NULL ; pmd->nlsk_fd =-1 ; pmd->gso_ctx_mp =NULL ;
drivers/net/tap/rte_eth_tap.h +4 -5
@@ -79,12 +79,11 @@ struct pmd_internals {int flow_isolate;/* 1 if flow isolation is enabled */ int flower_support;/* 1 if kernel supports, else 0 */ int flower_vlan_support;/* 1 if kernel supports, else 0 */ -int rss_enabled;/* 1 if RSS is enabled, else 0 */ int persist;/* 1 if keep link up, else 0 */ -/* implicit rules set when RSS is enabled */ -int map_fd;/* BPF RSS map fd */ -int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */ - LIST_HEAD(tap_rss_flows, rte_flow) rss_flows; + +struct tap_rss *rss;/* BPF program */ +uint16_t bpf_flowid;/* next BPF class id */ + LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */ LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
drivers/net/tap/tap_bpf_api.c deleted +0 -196
196 lines not on this page · raw message
drivers/net/tap/tap_bpf_insns.h deleted +0 -1742
1,742 lines not on this page · raw message
drivers/net/tap/tap_flow.c +154 -289
1 line not on this page · raw message
drivers/net/tap/tap_rss.skel.h new file +11625 -0
11,625 lines not on this page · raw message
drivers/net/tap/tap_rss.stub.h new file +45 -0
45 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.43.0
Part of the diff is not shown here. View the raw message.
v2 cover net/tap: RSS using BPF overhaul
In reply to Stephen HemmingerTHe support of doing RSS for rte_flow_action was a cool idea but it has been broken for several releases of DPDK as the kernel and BPF infrastructure changed.
This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF toolchain.
The result should be easier to read and maintain. The build process checks for the required components and if not there will stub out to not supported.
This patch series is mostly the same as the original RFC, most of the changes are to split it up and always build the BPF from source.
Stephen Hemminger (7):
net/tap: remove unused RSS hash types net/tap: validate and setup parameters for BPF RSS net/tap: stop "vendoring" linux bpf headers net/tap: rewrite the RSS BPF program net/tap: use libbpf to load new BPF program net/tap: remove no longer used files
MAINTAINERS: add maintainer for TAP device
.gitignore | 3 - MAINTAINERS | 1 + drivers/net/tap/bpf/Makefile | 19 - drivers/net/tap/bpf/README | 12 + drivers/net/tap/bpf/bpf_api.h | 276 ---- drivers/net/tap/bpf/bpf_elf.h | 53 - drivers/net/tap/bpf/bpf_extract.py | 86 -- drivers/net/tap/bpf/meson.build | 81 ++ drivers/net/tap/bpf/tap_bpf_program.c | 255 ---- drivers/net/tap/bpf/tap_rss.c | 272 ++++ drivers/net/tap/meson.build | 26 +- drivers/net/tap/rte_eth_tap.c | 2 + drivers/net/tap/rte_eth_tap.h | 9 +- drivers/net/tap/tap_bpf.h | 121 -- drivers/net/tap/tap_bpf_api.c | 190 --- drivers/net/tap/tap_bpf_insns.h | 1743 ------------------------- drivers/net/tap/tap_flow.c | 531 +++----- drivers/net/tap/tap_flow.h | 11 +- drivers/net/tap/tap_rss.h | 14 +- drivers/net/tap/tap_rss.stub.h | 45 + drivers/net/tap/tap_tcmsgs.h | 4 +- 21 files changed, 584 insertions(+), 3170 deletions(-) delete mode 100644 drivers/net/tap/bpf/Makefile create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py create mode 100644 drivers/net/tap/bpf/meson.build delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c delete mode 100644 drivers/net/tap/tap_bpf.h delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h create mode 100644 drivers/net/tap/tap_rss.stub.h
Signature · 1 line
2.43.0
PATCH v2 1/7 net/tap: remove unused RSS hash types
The driver doesn't support these other hash types, and there is no reason to implement these in future.
--- drivers/net/tap/tap_rss.h | 6 ------ 1 file changed, 6 deletions(-)
drivers/net/tap/tap_rss.h +0 -6
@@ -21,12 +21,6 @@ enum hash_field {HASH_FIELD_IPV4_L3_L4 ,/* IPv4 src/dst addr + L4 src/dst ports */ HASH_FIELD_IPV6_L3 ,/* IPv6 src/dst addr */ HASH_FIELD_IPV6_L3_L4, /* IPv6 src/dst addr + L4 src/dst ports */ -HASH_FIELD_L2_SRC ,/* Ethernet src addr */ -HASH_FIELD_L2_DST ,/* Ethernet dst addr */ -HASH_FIELD_L3_SRC ,/* L3 src addr */ -HASH_FIELD_L3_DST ,/* L3 dst addr */ -HASH_FIELD_L4_SRC ,/* TCP/UDP src ports */ - HASH_FIELD_L4_DST, /* TCP/UDP dst ports */ }; struct rss_key {
Signature · 1 line
2.43.0
PATCH v2 2/7 net/tap: validate and setup parameters for BPF RSS
In reply to Stephen HemmingerThe flow RSS support via BPF was not using the key, or hash type parameters. Which is good because they were never properly setup.
Fix the setup and validate the flow parameters, the BPF side gets fixed later.
--- drivers/net/tap/tap_bpf_insns.h | 16 ++++---- drivers/net/tap/tap_flow.c | 65 ++++++++++++++++++++++++++++++--- drivers/net/tap/tap_rss.h | 5 +-- 3 files changed, 70 insertions(+), 16 deletions(-)
drivers/net/tap/tap_bpf_insns.h +8 -8
@@ -1709,13 +1709,13 @@ static struct bpf_insn l3_l4_hash_insns[] = { {0x57, 1, 0, 0, 0x00000001}, {0x15, 1, 0, 1, 0x00000000}, {0xa7, 3, 0, 0, 0xfe0fee15}, - {0x71, 1, 0, 201, 0x00000000}, + {0x71, 1, 0, 45, 0x00000000}, {0x67, 1, 0, 0, 0x00000008}, - {0x71, 2, 0, 200, 0x00000000}, + {0x71, 2, 0, 44, 0x00000000}, {0x4f, 1, 2, 0, 0x00000000}, - {0x71, 2, 0, 202, 0x00000000}, + {0x71, 2, 0, 46, 0x00000000}, {0x67, 2, 0, 0, 0x00000010}, - {0x71, 4, 0, 203, 0x00000000}, + {0x71, 4, 0, 47, 0x00000000}, {0x67, 4, 0, 0, 0x00000018}, {0x4f, 4, 2, 0, 0x00000000}, {0x4f, 4, 1, 0, 0x00000000},
@@ -1725,13 +1725,13 @@ static struct bpf_insn l3_l4_hash_insns[] = { {0x57, 3, 0, 0, 0x0000000f}, {0x67, 3, 0, 0, 0x00000002}, {0x0f, 0, 3, 0, 0x00000000}, - {0x71, 1, 0, 137, 0x00000000}, + {0x71, 1, 0, 49, 0x00000000}, {0x67, 1, 0, 0, 0x00000008}, - {0x71, 2, 0, 136, 0x00000000}, + {0x71, 2, 0, 48, 0x00000000}, {0x4f, 1, 2, 0, 0x00000000}, - {0x71, 2, 0, 138, 0x00000000}, + {0x71, 2, 0, 50, 0x00000000}, {0x67, 2, 0, 0, 0x00000010}, - {0x71, 3, 0, 139, 0x00000000}, + {0x71, 3, 0, 51, 0x00000000}, {0x67, 3, 0, 0, 0x00000018}, {0x4f, 3, 2, 0, 0x00000000}, {0x4f, 3, 1, 0, 0x00000000},
drivers/net/tap/tap_flow.c +60 -5
99 lines not on this page · raw message
drivers/net/tap/tap_rss.h +2 -3
@@ -24,11 +24,10 @@ enum hash_field { };struct rss_key { -__u8 key[128 ];__u32 hash_fields; -__u32 key_size; -__u32 queues[TAP_MAX_QUEUES ]; +__u8 key[TAP_RSS_HASH_KEY_SIZE ];__u32 nb_queues; +__u32 queues[TAP_MAX_QUEUES ]; } __attribute__((packed));#endif /* _TAP_RSS_H_ */
Signature · 1 line
2.43.0
PATCH v2 3/7 net/tap: stop "vendoring" linux bpf headers
In reply to Stephen HemmingerThe proper place for finding bpf structures and functions is in linux/bpf.h. The original version was trying to workaround the case where the build environment was running on old pre BPF version of Glibc, but the target environment had BPF. This is not a supportable build method, and not how rest of DPDK works.
Having own private (and divergent) version headers leads to future problems when BPF definitions evolve.
Since DPDK officially supports only LTS or later kernel there is no need for the #ifdef workarounds in the TAP flow code. Cloning headers leads to problems and no longer needed.
--- drivers/net/tap/bpf/bpf_extract.py | 1 - drivers/net/tap/tap_bpf.h | 121 ----------------------------- drivers/net/tap/tap_bpf_api.c | 20 +++-- drivers/net/tap/tap_bpf_insns.h | 1 - drivers/net/tap/tap_flow.c | 89 --------------------- 5 files changed, 13 insertions(+), 219 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf.h
drivers/net/tap/bpf/bpf_extract.py +0 -1
@@ -65,7 +65,6 @@ def write_header(out, source): print(f' * Auto-generated from {source}', file=out) print(" * This not the original source file. Do NOT edit it.", file=out) print(" */\n", file=out) - print("#include <tap_bpf.h>", file=out) def main():
drivers/net/tap/tap_bpf.h deleted +0 -121
121 lines not on this page · raw message
drivers/net/tap/tap_bpf_api.c +13 -7
@@ -2,19 +2,19 @@* Copyright 2017 Mellanox Technologies, Ltd */ -#include <errno.h> -#include <string.h> #include <unistd.h> -#include <sys/queue.h> +#include <syscall.h> +#include <linux/bpf.h> -#include <rte_malloc.h> -#include <rte_eth_tap.h> #include <tap_flow.h> #include <tap_autoconf.h> -#include <tap_tcmsgs.h> -#include <tap_bpf.h> +#include <tap_bpf_insns.h> + +static int bpf_load (enum bpf_prog_type type,const struct bpf_insn *insns, +size_t insns_cnt,const char *license); +/** * Load BPF program (section cls_q) into the kernel and return a bpf fd *
@@ -89,7 +89,13 @@ static inline __u64 ptr_to_u64(const void *ptr)static inline int sys_bpf (enum bpf_cmd cmd,union bpf_attr *attr,unsigned int size) { +#ifdef __NR_bpfreturn syscall (__NR_bpf, cmd, attr, size); +#else +TAP_LOG (ERR ,"No bpf syscall, kernel headers too old?\n" ); + errno =ENOSYS ; +return -1 ; +#endif }/**
drivers/net/tap/tap_bpf_insns.h +0 -1
@@ -3,7 +3,6 @@* This not the original source file. Do NOT edit it. */ -#include <tap_bpf.h> static struct bpf_insn cls_q_insns[] = { {0x61 ,2 ,1 ,52 ,0x00000000 },
drivers/net/tap/tap_flow.c +0 -89
95 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 4/7 net/tap: rewrite the RSS BPF program
In reply to Stephen HemmingerRewrite the BPF program used to do queue based RSS. Important changes:
- uses newer BPF map format BTF
- accepts key as parameter rather than constant default
- can do L3 or L4 hashing
- supports IPv4 options
- supports IPv6 extension headers
- restructured for readability
The usage of BPF is different as well:
- the incoming configuration is looked up based on class parameters rather than patching the BPF.
- the resulting queue is placed in skb rather than requiring a second pass through classifier step.
Note: This version only works with later patch to enable it on the DPDK driver side. It is submitted as an incremental patch to allow for easier review. Bisection still works because the old instruction are still present for now.
--- .gitignore | 3 - drivers/net/tap/bpf/Makefile | 19 -- drivers/net/tap/bpf/README | 12 ++ drivers/net/tap/bpf/bpf_api.h | 276 -------------------------- drivers/net/tap/bpf/bpf_elf.h | 53 ----- drivers/net/tap/bpf/bpf_extract.py | 85 -------- drivers/net/tap/bpf/meson.build | 81 ++++++++ drivers/net/tap/bpf/tap_bpf_program.c | 255 ------------------------ drivers/net/tap/bpf/tap_rss.c | 272 +++++++++++++++++++++++++ 9 files changed, 365 insertions(+), 691 deletions(-) delete mode 100644 drivers/net/tap/bpf/Makefile create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py create mode 100644 drivers/net/tap/bpf/meson.build delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c
.gitignore +0 -3
@@ -36,9 +36,6 @@ TAGS # ignore python bytecode files *.pyc -# ignore BPF programs -drivers/net/tap/bpf/tap_bpf_program.o - # DTS results dts/output
drivers/net/tap/bpf/Makefile deleted +0 -19
@@ -1,19 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# This file is not built as part of normal DPDK build. -# It is used to generate the eBPF code for TAP RSS. - -CLANG=clang -CLANG_OPTS=-O2 -TARGET=../tap_bpf_insns.h - -all: $(TARGET) - -clean: - rm tap_bpf_program.o $(TARGET) - -tap_bpf_program.o: tap_bpf_program.c - $(CLANG) $(CLANG_OPTS) -emit-llvm -c $< -o - | \ - llc -march=bpf -filetype=obj -o $@ - -$(TARGET): tap_bpf_program.o - python3 bpf_extract.py -stap_bpf_program.c -o $@ $<
drivers/net/tap/bpf/README new file +12 -0
@@ -0,0 +1,12 @@ +This is the BPF program used to implement the RSS across queues +flow action. It works like the skbedit tc filter but instead of mapping +to only one queues, it maps to multiple queues based on RSS hash. + +This version is built the BPF Compile Once — Run Everywhere (CO-RE) +framework and uses libbpf and bpftool. + +Limitations +- requires libbpf version XX or later +- rebuilding the BPF requires clang and bpftool +- only Toeplitz hash with standard 40 byte key is supported +- the number of queues per RSS action is limited to 16
drivers/net/tap/bpf/bpf_api.h deleted +0 -276
276 lines not on this page · raw message
drivers/net/tap/bpf/bpf_elf.h deleted +0 -53
53 lines not on this page · raw message
drivers/net/tap/bpf/bpf_extract.py deleted +0 -85
85 lines not on this page · raw message
drivers/net/tap/bpf/meson.build new file +81 -0
81 lines not on this page · raw message
drivers/net/tap/bpf/tap_bpf_program.c deleted +0 -255
255 lines not on this page · raw message
drivers/net/tap/bpf/tap_rss.c new file +272 -0
272 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 5/7 net/tap: use libbpf to load new BPF program
In reply to Stephen HemmingerThere were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.
Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.
The new BPF program only needs a single action.
No need for action and re-classification step.
It alsow fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.
--- drivers/net/tap/meson.build | 26 +-- drivers/net/tap/rte_eth_tap.c | 2 + drivers/net/tap/rte_eth_tap.h | 9 +- drivers/net/tap/tap_flow.c | 391 +++++++++------------------------ drivers/net/tap/tap_flow.h | 11 +- drivers/net/tap/tap_rss.h | 3 + drivers/net/tap/tap_rss.stub.h | 45 ++++ drivers/net/tap/tap_tcmsgs.h | 4 +- 8 files changed, 163 insertions(+), 328 deletions(-) create mode 100644 drivers/net/tap/tap_rss.stub.h
drivers/net/tap/meson.build +7 -19
@@ -7,33 +7,21 @@ if not is_linux endif sources = files( 'rte_eth_tap.c', - 'tap_bpf_api.c', 'tap_flow.c', 'tap_intr.c', 'tap_netlink.c', 'tap_tcmsgs.c', ) +subdir('bpf') +if enable_tap_rss + cflags += '-DHAVE_BPF_RSS' + ext_deps += libbpf + sources += tap_rss_skel_h +endif + deps = ['bus_vdev', 'gso', 'hash'] cflags += '-DTAP_MAX_QUEUES=16' -# input array for meson symbol search: -# [ "MACRO to define if found", "header for the search", -# "enum/define", "symbol to search" ] -# -args = [ - [ 'HAVE_TC_FLOWER', 'linux/pkt_cls.h', 'TCA_FLOWER_UNSPEC' ], - [ 'HAVE_TC_VLAN_ID', 'linux/pkt_cls.h', 'TCA_FLOWER_KEY_VLAN_PRIO' ], - [ 'HAVE_TC_BPF', 'linux/pkt_cls.h', 'TCA_BPF_UNSPEC' ], - [ 'HAVE_TC_BPF_FD', 'linux/pkt_cls.h', 'TCA_BPF_FD' ], - [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ], - [ 'HAVE_TC_ACT_BPF_FD', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_FD' ], -] -config = configuration_data() -foreach arg:args - config.set(arg[0], cc.has_header_symbol(arg[1], arg[2])) -endforeach -configure_file(output : 'tap_autoconf.h', configuration : config) - require_iova_in_mbuf = false
drivers/net/tap/rte_eth_tap.c +2 -0
@@ -1138,6 +1138,7 @@ tap_dev_close(struct rte_eth_dev *dev)tap_flow_implicit_flush (internals,NULL );tap_nl_final (internals->nlsk_fd); internals->nlsk_fd =-1 ; +tap_flow_bpf_destroy (internals); }for (i =0 ; i <RTE_PMD_TAP_MAX_QUEUES ; i++) {
@@ -1959,6 +1960,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,strlcpy (pmd->name, tap_name,sizeof (pmd->name)); pmd->type = type; pmd->ka_fd =-1 ; + pmd->rss =NULL ; pmd->nlsk_fd =-1 ; pmd->gso_ctx_mp =NULL ;
drivers/net/tap/rte_eth_tap.h +4 -5
@@ -79,12 +79,11 @@ struct pmd_internals {int flow_isolate;/* 1 if flow isolation is enabled */ int flower_support;/* 1 if kernel supports, else 0 */ int flower_vlan_support;/* 1 if kernel supports, else 0 */ -int rss_enabled;/* 1 if RSS is enabled, else 0 */ int persist;/* 1 if keep link up, else 0 */ -/* implicit rules set when RSS is enabled */ -int map_fd;/* BPF RSS map fd */ -int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */ - LIST_HEAD(tap_rss_flows, rte_flow) rss_flows; + +struct tap_rss *rss;/* BPF program */ +uint16_t bpf_flowid;/* next BPF class id */ + LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */ LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
drivers/net/tap/tap_flow.c +100 -291
557 lines not on this page · raw message
drivers/net/tap/tap_flow.h +1 -10
@@ -9,7 +9,6 @@#include <rte_flow.h> #include <rte_flow_driver.h> #include <rte_eth_tap.h> -#include <tap_autoconf.h> /** * In TC, priority 0 means we require the kernel to allocate one for us.
@@ -41,10 +40,6 @@ enum implicit_rule_index { TAP_REMOTE_MAX_IDX, }; -enum bpf_fd_idx { -SEC_L3_L4 , -SEC_MAX , -};int tap_dev_flow_ops_get (struct rte_eth_dev *dev,const struct rte_flow_ops **ops);
@@ -57,10 +52,6 @@ int tap_flow_implicit_destroy(struct pmd_internals *pmd,int tap_flow_implicit_flush (struct pmd_internals *pmd,struct rte_flow_error *error); -int tap_flow_bpf_cls_q (__u32 queue_idx); -int tap_flow_bpf_calc_l3_l4_hash (__u32 key_idx,int map_fd); -int tap_flow_bpf_rss_map_create (unsigned int key_size,unsigned int value_size, -unsigned int max_entries); -int tap_flow_bpf_update_rss_elem (int fd,void *key,void *value); +void tap_flow_bpf_destroy (struct pmd_internals *pmd);#endif /* _TAP_FLOW_H_ */
drivers/net/tap/tap_rss.h +3 -0
@@ -9,6 +9,9 @@#define TAP_MAX_QUEUES 16#endif +/* Size of the map from BPF classid to queue table */ +#define TAP_RSS_MAX TAP_MAX_QUEUES +/* Fixed RSS hash key size in bytes. */ #define TAP_RSS_HASH_KEY_SIZE 40
drivers/net/tap/tap_rss.stub.h new file +45 -0
45 lines not on this page · raw message
drivers/net/tap/tap_tcmsgs.h +1 -3
@@ -6,7 +6,6 @@#ifndef _TAP_TCMSGS_H_#define _TAP_TCMSGS_H_ -#include <tap_autoconf.h> #include <linux/if_ether.h> #include <linux/rtnetlink.h> #include <linux/pkt_sched.h>
@@ -14,9 +13,8 @@#include <linux/tc_act/tc_mirred.h> #include <linux/tc_act/tc_gact.h> #include <linux/tc_act/tc_skbedit.h> -#ifdef HAVE_TC_ACT_BPF #include <linux/tc_act/tc_bpf.h> -#endif +#include <inttypes.h> #include <rte_ether.h>
Signature · 1 line
2.43.0
PATCH v2 6/7 net/tap: remove no longer used files
In reply to Stephen HemmingerThe BPF api was replaced by use of libbpf.
And the BPF instruction header was replaced by the skeleton.
--- drivers/net/tap/tap_bpf_api.c | 196 ---- drivers/net/tap/tap_bpf_insns.h | 1742 ------------------------------- 2 files changed, 1938 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h
drivers/net/tap/tap_bpf_api.c deleted +0 -196
@@ -1,196 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright 2017 Mellanox Technologies, Ltd -*/ - -#include <unistd.h> -#include <syscall.h> -#include <linux/bpf.h> - -#include <tap_flow.h> -#include <tap_autoconf.h> - -#include <tap_bpf_insns.h> - - -static int bpf_load (enum bpf_prog_type type,const struct bpf_insn *insns, -size_t insns_cnt,const char *license); - -/** -* Load BPF program (section cls_q) into the kernel and return a bpf fd -* -* @param queue_idx -* Queue index matching packet cb -* -* @return -* -1 if the BPF program couldn't be loaded. An fd (int) otherwise. -*/ -int tap_flow_bpf_cls_q (__u32 queue_idx) -{ - cls_q_insns[1 ].imm = queue_idx; - -return bpf_load (BPF_PROG_TYPE_SCHED_CLS , - (struct bpf_insn *)cls_q_insns, -RTE_DIM (cls_q_insns), -"Dual BSD/GPL" ); -} - -/** -* Load BPF program (section l3_l4) into the kernel and return a bpf fd. -* -* @param[in] key_idx -* RSS MAP key index -* -* @param[in] map_fd -* BPF RSS map file descriptor -* -* @return -* -1 if the BPF program couldn't be loaded. An fd (int) otherwise. -*/ -int tap_flow_bpf_calc_l3_l4_hash (__u32 key_idx,int map_fd) -{ - l3_l4_hash_insns[4 ].imm = key_idx; - l3_l4_hash_insns[9 ].imm = map_fd; - -return bpf_load (BPF_PROG_TYPE_SCHED_ACT , - (struct bpf_insn *)l3_l4_hash_insns, -RTE_DIM (l3_l4_hash_insns), -"Dual BSD/GPL" ); -} - -/** -* Helper function to convert a pointer to unsigned 64 bits -* -* @param[in] ptr -* pointer to address -* -* @return -* 64 bit unsigned long type of pointer address -*/ -static inline __u64 ptr_to_u64 (const void *ptr) -{ -return (__u64 )(unsigned long )ptr; -} - -/** -* Call BPF system call -* -* @param[in] cmd -* BPF command for program loading, map creation, map entry update, etc -* -* @param[in] attr -* System call attributes relevant to system call command -* -* @param[in] size -* size of attr parameter -* -* @return -* -1 if BPF system call failed, 0 otherwise -*/ -static inline int sys_bpf (enum bpf_cmd cmd,union bpf_attr *attr, -unsigned int size) -{ -#ifdef __NR_bpf -return syscall (__NR_bpf, cmd, attr, size); -#else -TAP_LOG (ERR ,"No bpf syscall, kernel headers too old?\n" ); - errno =ENOSYS ; -return -1 ; -#endif -} - -/** -* Load BPF instructions to kernel -* -* @param[in] type -* BPF program type: classifier or action -* -* @param[in] insns -* Array of BPF instructions (equivalent to BPF instructions) -* -* @param[in] insns_cnt -* Number of BPF instructions (size of array) -* -* @param[in] license -* License string that must be acknowledged by the kernel -* -* @return -* -1 if the BPF program couldn't be loaded, fd (file descriptor) otherwise -*/ -static int bpf_load (enum bpf_prog_type type, -const struct bpf_insn *insns, -size_t insns_cnt, -const char *license) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - attr.prog_type = type; - attr.insn_cnt = (__u32 )insns_cnt; - attr.insns =ptr_to_u64 (insns); - attr.license =ptr_to_u64 (license); - attr.log_buf =ptr_to_u64 (NULL ); - attr.log_level =0 ; - attr.kern_version =0 ; - -return sys_bpf (BPF_PROG_LOAD , &attr,sizeof (attr)); -} - -/** -* Create BPF map for RSS rules -* -* @param[in] key_size -* map RSS key size -* -* @param[in] value_size -* Map RSS value size -* -* @param[in] max_entries -* Map max number of RSS entries (limit on max RSS rules) -* -* @return -* -1 if BPF map couldn't be created, map fd otherwise -*/ -int tap_flow_bpf_rss_map_create (unsigned int key_size, -unsigned int value_size, -unsigned int max_entries) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - attr.map_type =BPF_MAP_TYPE_HASH ; - attr.key_size = key_size; - attr.value_size = value_size; - attr.max_entries = max_entries; - -return sys_bpf (BPF_MAP_CREATE , &attr,sizeof (attr)); -} - -/** -* Update RSS entry in BPF map -* -* @param[in] fd -* RSS map fd -* -* @param[in] key -* Pointer to RSS key whose entry is updated -* -* @param[in] value -* Pointer to RSS new updated value -* -* @return -* -1 if RSS entry failed to be updated, 0 otherwise -*/ -int tap_flow_bpf_update_rss_elem (int fd,void *key,void *value) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - - attr.map_type =BPF_MAP_TYPE_HASH ; - attr.map_fd = fd; - attr.key =ptr_to_u64 (key); - attr.value =ptr_to_u64 (value); - attr.flags =BPF_ANY ; - -return sys_bpf (BPF_MAP_UPDATE_ELEM , &attr,sizeof (attr)); -}
drivers/net/tap/tap_bpf_insns.h deleted +0 -1742
1,742 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 7/7 MAINTAINERS: add maintainer for TAP device
In reply to Stephen HemmingerAdd myself as maintainer for TAP device.
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -1015,6 +1015,7 @@ F: doc/guides/nics/pcap_ring.rst F: doc/guides/nics/features/pcap.ini Tap PMD +M: Stephen Hemminger <[email protected]> F: drivers/net/tap/ F: doc/guides/nics/tap.rst F: doc/guides/nics/features/tap.ini
Signature · 1 line
2.43.0
RE: [PATCH v2 7/7] MAINTAINERS: add maintainer for TAP device
Quoted 7 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, 7 February 2024 23.11Add myself as maintainer for TAP device.
Signed-off-by Stephen Hemminger <[email protected]>---
Thank you.
v3 cover net/tap: RSS using BPF overhaul
In reply to Stephen HemmingerThe support of doing RSS for rte_flow_action was a cool idea but it has been broken for several releases of DPDK as the kernel and BPF infrastructure changed.
This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF toolchain.
The result should be easier to read and maintain. The build process checks for the required components and if not there will stub out to not supported.
This patch series is mostly the same as the original RFC, most of the changes are to split it up and always build the BPF from source.
v3 - fix handling of case where libbpf not present and
therefore the not supported needs to be returned.
Stephen Hemminger (7):
net/tap: remove unused RSS hash types net/tap: validate and setup parameters for BPF RSS
tap: stop "vendoring" linux bpf headers net/tap: rewrite the RSS BPF program net/tap: use libbpf to load new BPF program net/tap: remove no longer used files
MAINTAINERS: add maintainer for TAP device
.gitignore | 3 - MAINTAINERS | 1 + drivers/net/tap/bpf/Makefile | 19 - drivers/net/tap/bpf/README | 12 + drivers/net/tap/bpf/bpf_api.h | 276 ---- drivers/net/tap/bpf/bpf_elf.h | 53 - drivers/net/tap/bpf/bpf_extract.py | 86 -- drivers/net/tap/bpf/meson.build | 81 ++ drivers/net/tap/bpf/tap_bpf_program.c | 255 ---- drivers/net/tap/bpf/tap_bpf_program.o | Bin 0 -> 28080 bytes drivers/net/tap/bpf/tap_rss.c | 272 ++++ drivers/net/tap/meson.build | 26 +- drivers/net/tap/rte_eth_tap.c | 2 + drivers/net/tap/rte_eth_tap.h | 9 +- drivers/net/tap/tap_bpf.h | 121 -- drivers/net/tap/tap_bpf_api.c | 190 --- drivers/net/tap/tap_bpf_insns.h | 1743 ------------------------- drivers/net/tap/tap_flow.c | 521 +++----- drivers/net/tap/tap_flow.h | 11 +- drivers/net/tap/tap_rss.h | 14 +- drivers/net/tap/tap_tcmsgs.h | 4 +- 21 files changed, 534 insertions(+), 3165 deletions(-) delete mode 100644 drivers/net/tap/bpf/Makefile create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py create mode 100644 drivers/net/tap/bpf/meson.build delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_bpf_program.o create mode 100644 drivers/net/tap/bpf/tap_rss.c delete mode 100644 drivers/net/tap/tap_bpf.h delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h
Signature · 1 line
2.43.0
PATCH v3 1/7 net/tap: remove unused RSS hash types
The driver doesn't support these other hash types, and there is no reason to implement these in future.
--- drivers/net/tap/tap_rss.h | 6 ------ 1 file changed, 6 deletions(-)
drivers/net/tap/tap_rss.h +0 -6
@@ -21,12 +21,6 @@ enum hash_field {HASH_FIELD_IPV4_L3_L4 ,/* IPv4 src/dst addr + L4 src/dst ports */ HASH_FIELD_IPV6_L3 ,/* IPv6 src/dst addr */ HASH_FIELD_IPV6_L3_L4, /* IPv6 src/dst addr + L4 src/dst ports */ -HASH_FIELD_L2_SRC ,/* Ethernet src addr */ -HASH_FIELD_L2_DST ,/* Ethernet dst addr */ -HASH_FIELD_L3_SRC ,/* L3 src addr */ -HASH_FIELD_L3_DST ,/* L3 dst addr */ -HASH_FIELD_L4_SRC ,/* TCP/UDP src ports */ - HASH_FIELD_L4_DST, /* TCP/UDP dst ports */ }; struct rss_key {
Signature · 1 line
2.43.0
PATCH v3 2/7 net/tap: validate and setup parameters for BPF RSS
In reply to Stephen HemmingerThe flow RSS support via BPF was not using the key, or hash type parameters. Which is good because they were never properly setup.
Fix the setup and validate the flow parameters, the BPF side gets fixed later.
--- drivers/net/tap/tap_bpf_insns.h | 16 ++++---- drivers/net/tap/tap_flow.c | 65 ++++++++++++++++++++++++++++++--- drivers/net/tap/tap_rss.h | 5 +-- 3 files changed, 70 insertions(+), 16 deletions(-)
drivers/net/tap/tap_bpf_insns.h +8 -8
@@ -1709,13 +1709,13 @@ static struct bpf_insn l3_l4_hash_insns[] = { {0x57, 1, 0, 0, 0x00000001}, {0x15, 1, 0, 1, 0x00000000}, {0xa7, 3, 0, 0, 0xfe0fee15}, - {0x71, 1, 0, 201, 0x00000000}, + {0x71, 1, 0, 45, 0x00000000}, {0x67, 1, 0, 0, 0x00000008}, - {0x71, 2, 0, 200, 0x00000000}, + {0x71, 2, 0, 44, 0x00000000}, {0x4f, 1, 2, 0, 0x00000000}, - {0x71, 2, 0, 202, 0x00000000}, + {0x71, 2, 0, 46, 0x00000000}, {0x67, 2, 0, 0, 0x00000010}, - {0x71, 4, 0, 203, 0x00000000}, + {0x71, 4, 0, 47, 0x00000000}, {0x67, 4, 0, 0, 0x00000018}, {0x4f, 4, 2, 0, 0x00000000}, {0x4f, 4, 1, 0, 0x00000000},
@@ -1725,13 +1725,13 @@ static struct bpf_insn l3_l4_hash_insns[] = { {0x57, 3, 0, 0, 0x0000000f}, {0x67, 3, 0, 0, 0x00000002}, {0x0f, 0, 3, 0, 0x00000000}, - {0x71, 1, 0, 137, 0x00000000}, + {0x71, 1, 0, 49, 0x00000000}, {0x67, 1, 0, 0, 0x00000008}, - {0x71, 2, 0, 136, 0x00000000}, + {0x71, 2, 0, 48, 0x00000000}, {0x4f, 1, 2, 0, 0x00000000}, - {0x71, 2, 0, 138, 0x00000000}, + {0x71, 2, 0, 50, 0x00000000}, {0x67, 2, 0, 0, 0x00000010}, - {0x71, 3, 0, 139, 0x00000000}, + {0x71, 3, 0, 51, 0x00000000}, {0x67, 3, 0, 0, 0x00000018}, {0x4f, 3, 2, 0, 0x00000000}, {0x4f, 3, 1, 0, 0x00000000},
drivers/net/tap/tap_flow.c +60 -5
99 lines not on this page · raw message
drivers/net/tap/tap_rss.h +2 -3
@@ -24,11 +24,10 @@ enum hash_field { };struct rss_key { -__u8 key[128 ];__u32 hash_fields; -__u32 key_size; -__u32 queues[TAP_MAX_QUEUES ]; +__u8 key[TAP_RSS_HASH_KEY_SIZE ];__u32 nb_queues; +__u32 queues[TAP_MAX_QUEUES ]; } __attribute__((packed));#endif /* _TAP_RSS_H_ */
Signature · 1 line
2.43.0
PATCH v3 3/7 tap: stop "vendoring" linux bpf headers
In reply to Stephen HemmingerThe proper place for finding bpf structures and functions is in linux/bpf.h. The original version was trying to workaround the case where the build environment was running on old pre BPF version of Glibc, but the target environment had BPF. This is not a supportable build method, and not how rest of DPDK works.
Having own private (and divergent) version headers leads to future problems when BPF definitions evolve.
Since DPDK officially supports only LTS or later kernel there is no need for the #ifdef workarounds in the TAP flow code. Cloning headers leads to problems and no longer needed.
--- drivers/net/tap/bpf/bpf_extract.py | 1 - drivers/net/tap/tap_bpf.h | 121 ----------------------------- drivers/net/tap/tap_bpf_api.c | 20 +++-- drivers/net/tap/tap_bpf_insns.h | 1 - drivers/net/tap/tap_flow.c | 89 --------------------- 5 files changed, 13 insertions(+), 219 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf.h
drivers/net/tap/bpf/bpf_extract.py +0 -1
@@ -65,7 +65,6 @@ def write_header(out, source): print(f' * Auto-generated from {source}', file=out) print(" * This not the original source file. Do NOT edit it.", file=out) print(" */\n", file=out) - print("#include <tap_bpf.h>", file=out) def main():
drivers/net/tap/tap_bpf.h deleted +0 -121
121 lines not on this page · raw message
drivers/net/tap/tap_bpf_api.c +13 -7
@@ -2,19 +2,19 @@* Copyright 2017 Mellanox Technologies, Ltd */ -#include <errno.h> -#include <string.h> #include <unistd.h> -#include <sys/queue.h> +#include <syscall.h> +#include <linux/bpf.h> -#include <rte_malloc.h> -#include <rte_eth_tap.h> #include <tap_flow.h> #include <tap_autoconf.h> -#include <tap_tcmsgs.h> -#include <tap_bpf.h> +#include <tap_bpf_insns.h> + +static int bpf_load (enum bpf_prog_type type,const struct bpf_insn *insns, +size_t insns_cnt,const char *license); +/** * Load BPF program (section cls_q) into the kernel and return a bpf fd *
@@ -89,7 +89,13 @@ static inline __u64 ptr_to_u64(const void *ptr)static inline int sys_bpf (enum bpf_cmd cmd,union bpf_attr *attr,unsigned int size) { +#ifdef __NR_bpfreturn syscall (__NR_bpf, cmd, attr, size); +#else +TAP_LOG (ERR ,"No bpf syscall, kernel headers too old?\n" ); + errno =ENOSYS ; +return -1 ; +#endif }/**
drivers/net/tap/tap_bpf_insns.h +0 -1
@@ -3,7 +3,6 @@* This not the original source file. Do NOT edit it. */ -#include <tap_bpf.h> static struct bpf_insn cls_q_insns[] = { {0x61 ,2 ,1 ,52 ,0x00000000 },
drivers/net/tap/tap_flow.c +0 -89
95 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v3 4/7 net/tap: rewrite the RSS BPF program
In reply to Stephen HemmingerRewrite the BPF program used to do queue based RSS. Important changes:
- uses newer BPF map format BTF
- accepts key as parameter rather than constant default
- can do L3 or L4 hashing
- supports IPv4 options
- supports IPv6 extension headers
- restructured for readability
The usage of BPF is different as well:
- the incoming configuration is looked up based on class parameters rather than patching the BPF.
- the resulting queue is placed in skb rather than requiring a second pass through classifier step.
Note: This version only works with later patch to enable it on the DPDK driver side. It is submitted as an incremental patch to allow for easier review. Bisection still works because the old instruction are still present for now.
--- .gitignore | 3 - drivers/net/tap/bpf/Makefile | 19 -- drivers/net/tap/bpf/README | 12 ++ drivers/net/tap/bpf/bpf_api.h | 276 -------------------------- drivers/net/tap/bpf/bpf_elf.h | 53 ----- drivers/net/tap/bpf/bpf_extract.py | 85 -------- drivers/net/tap/bpf/meson.build | 81 ++++++++ drivers/net/tap/bpf/tap_bpf_program.c | 255 ------------------------ drivers/net/tap/bpf/tap_rss.c | 272 +++++++++++++++++++++++++ 9 files changed, 365 insertions(+), 691 deletions(-) delete mode 100644 drivers/net/tap/bpf/Makefile create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py create mode 100644 drivers/net/tap/bpf/meson.build delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c
.gitignore +0 -3
@@ -36,9 +36,6 @@ TAGS # ignore python bytecode files *.pyc -# ignore BPF programs -drivers/net/tap/bpf/tap_bpf_program.o - # DTS results dts/output
drivers/net/tap/bpf/Makefile deleted +0 -19
@@ -1,19 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# This file is not built as part of normal DPDK build. -# It is used to generate the eBPF code for TAP RSS. - -CLANG=clang -CLANG_OPTS=-O2 -TARGET=../tap_bpf_insns.h - -all: $(TARGET) - -clean: - rm tap_bpf_program.o $(TARGET) - -tap_bpf_program.o: tap_bpf_program.c - $(CLANG) $(CLANG_OPTS) -emit-llvm -c $< -o - | \ - llc -march=bpf -filetype=obj -o $@ - -$(TARGET): tap_bpf_program.o - python3 bpf_extract.py -stap_bpf_program.c -o $@ $<
drivers/net/tap/bpf/README new file +12 -0
@@ -0,0 +1,12 @@ +This is the BPF program used to implement the RSS across queues +flow action. It works like the skbedit tc filter but instead of mapping +to only one queues, it maps to multiple queues based on RSS hash. + +This version is built the BPF Compile Once — Run Everywhere (CO-RE) +framework and uses libbpf and bpftool. + +Limitations +- requires libbpf version XX or later +- rebuilding the BPF requires clang and bpftool +- only Toeplitz hash with standard 40 byte key is supported +- the number of queues per RSS action is limited to 16
drivers/net/tap/bpf/bpf_api.h deleted +0 -276
276 lines not on this page · raw message
drivers/net/tap/bpf/bpf_elf.h deleted +0 -53
53 lines not on this page · raw message
drivers/net/tap/bpf/bpf_extract.py deleted +0 -85
85 lines not on this page · raw message
drivers/net/tap/bpf/meson.build new file +81 -0
81 lines not on this page · raw message
drivers/net/tap/bpf/tap_bpf_program.c deleted +0 -255
255 lines not on this page · raw message
drivers/net/tap/bpf/tap_rss.c new file +272 -0
272 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v3 5/7 net/tap: use libbpf to load new BPF program
In reply to Stephen HemmingerThere were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.
Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.
The new BPF program only needs a single action.
No need for action and re-classification step.
It alsow fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.
--- drivers/net/tap/bpf/tap_bpf_program.o | Bin 0 -> 28080 bytes drivers/net/tap/meson.build | 26 +- drivers/net/tap/rte_eth_tap.c | 2 + drivers/net/tap/rte_eth_tap.h | 9 +- drivers/net/tap/tap_flow.c | 381 +++++++------------------- drivers/net/tap/tap_flow.h | 11 +- drivers/net/tap/tap_rss.h | 3 + drivers/net/tap/tap_tcmsgs.h | 4 +- 8 files changed, 113 insertions(+), 323 deletions(-) create mode 100644 drivers/net/tap/bpf/tap_bpf_program.o
drivers/net/tap/bpf/tap_bpf_program.o new file binary +0 -0
drivers/net/tap/meson.build +7 -19
@@ -7,33 +7,21 @@ if not is_linux endif sources = files( 'rte_eth_tap.c', - 'tap_bpf_api.c', 'tap_flow.c', 'tap_intr.c', 'tap_netlink.c', 'tap_tcmsgs.c', ) +subdir('bpf') +if enable_tap_rss + cflags += '-DHAVE_BPF_RSS' + ext_deps += libbpf + sources += tap_rss_skel_h +endif + deps = ['bus_vdev', 'gso', 'hash'] cflags += '-DTAP_MAX_QUEUES=16' -# input array for meson symbol search: -# [ "MACRO to define if found", "header for the search", -# "enum/define", "symbol to search" ] -# -args = [ - [ 'HAVE_TC_FLOWER', 'linux/pkt_cls.h', 'TCA_FLOWER_UNSPEC' ], - [ 'HAVE_TC_VLAN_ID', 'linux/pkt_cls.h', 'TCA_FLOWER_KEY_VLAN_PRIO' ], - [ 'HAVE_TC_BPF', 'linux/pkt_cls.h', 'TCA_BPF_UNSPEC' ], - [ 'HAVE_TC_BPF_FD', 'linux/pkt_cls.h', 'TCA_BPF_FD' ], - [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ], - [ 'HAVE_TC_ACT_BPF_FD', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_FD' ], -] -config = configuration_data() -foreach arg:args - config.set(arg[0], cc.has_header_symbol(arg[1], arg[2])) -endforeach -configure_file(output : 'tap_autoconf.h', configuration : config) - require_iova_in_mbuf = false
drivers/net/tap/rte_eth_tap.c +2 -0
@@ -1138,6 +1138,7 @@ tap_dev_close(struct rte_eth_dev *dev)tap_flow_implicit_flush (internals,NULL );tap_nl_final (internals->nlsk_fd); internals->nlsk_fd =-1 ; +tap_flow_bpf_destroy (internals); }for (i =0 ; i <RTE_PMD_TAP_MAX_QUEUES ; i++) {
@@ -1959,6 +1960,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,strlcpy (pmd->name, tap_name,sizeof (pmd->name)); pmd->type = type; pmd->ka_fd =-1 ; + pmd->rss =NULL ; pmd->nlsk_fd =-1 ; pmd->gso_ctx_mp =NULL ;
drivers/net/tap/rte_eth_tap.h +4 -5
@@ -79,12 +79,11 @@ struct pmd_internals {int flow_isolate;/* 1 if flow isolation is enabled */ int flower_support;/* 1 if kernel supports, else 0 */ int flower_vlan_support;/* 1 if kernel supports, else 0 */ -int rss_enabled;/* 1 if RSS is enabled, else 0 */ int persist;/* 1 if keep link up, else 0 */ -/* implicit rules set when RSS is enabled */ -int map_fd;/* BPF RSS map fd */ -int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */ - LIST_HEAD(tap_rss_flows, rte_flow) rss_flows; + +struct tap_rss *rss;/* BPF program */ +uint16_t bpf_flowid;/* next BPF class id */ + LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */ LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
drivers/net/tap/tap_flow.c +95 -286
525 lines not on this page · raw message
drivers/net/tap/tap_flow.h +1 -10
@@ -9,7 +9,6 @@#include <rte_flow.h> #include <rte_flow_driver.h> #include <rte_eth_tap.h> -#include <tap_autoconf.h> /** * In TC, priority 0 means we require the kernel to allocate one for us.
@@ -41,10 +40,6 @@ enum implicit_rule_index { TAP_REMOTE_MAX_IDX, }; -enum bpf_fd_idx { -SEC_L3_L4 , -SEC_MAX , -};int tap_dev_flow_ops_get (struct rte_eth_dev *dev,const struct rte_flow_ops **ops);
@@ -57,10 +52,6 @@ int tap_flow_implicit_destroy(struct pmd_internals *pmd,int tap_flow_implicit_flush (struct pmd_internals *pmd,struct rte_flow_error *error); -int tap_flow_bpf_cls_q (__u32 queue_idx); -int tap_flow_bpf_calc_l3_l4_hash (__u32 key_idx,int map_fd); -int tap_flow_bpf_rss_map_create (unsigned int key_size,unsigned int value_size, -unsigned int max_entries); -int tap_flow_bpf_update_rss_elem (int fd,void *key,void *value); +void tap_flow_bpf_destroy (struct pmd_internals *pmd);#endif /* _TAP_FLOW_H_ */
drivers/net/tap/tap_rss.h +3 -0
@@ -9,6 +9,9 @@#define TAP_MAX_QUEUES 16#endif +/* Size of the map from BPF classid to queue table */ +#define TAP_RSS_MAX TAP_MAX_QUEUES +/* Fixed RSS hash key size in bytes. */ #define TAP_RSS_HASH_KEY_SIZE 40
drivers/net/tap/tap_tcmsgs.h +1 -3
@@ -6,7 +6,6 @@#ifndef _TAP_TCMSGS_H_#define _TAP_TCMSGS_H_ -#include <tap_autoconf.h> #include <linux/if_ether.h> #include <linux/rtnetlink.h> #include <linux/pkt_sched.h>
@@ -14,9 +13,8 @@#include <linux/tc_act/tc_mirred.h> #include <linux/tc_act/tc_gact.h> #include <linux/tc_act/tc_skbedit.h> -#ifdef HAVE_TC_ACT_BPF #include <linux/tc_act/tc_bpf.h> -#endif +#include <inttypes.h> #include <rte_ether.h>
Signature · 1 line
2.43.0
Re: [PATCH v3 5/7] net/tap: use libbpf to load new BPF program
drivers/net/tap/bpf/tap_bpf_program.o
Quoted 5 lines · On Thu, 8 Feb 2024 09:41:29 -0800 Stephen Hemminger…
drivers/net/tap/bpf/tap_bpf_program.o new file binary +0
-0
Ignore this debris, will fix in next version
PATCH v3 6/7 net/tap: remove no longer used files
In reply to Stephen HemmingerThe BPF api was replaced by use of libbpf.
And the BPF instruction header was replaced by the skeleton.
--- drivers/net/tap/tap_bpf_api.c | 196 ---- drivers/net/tap/tap_bpf_insns.h | 1742 ------------------------------- 2 files changed, 1938 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h
drivers/net/tap/tap_bpf_api.c deleted +0 -196
@@ -1,196 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright 2017 Mellanox Technologies, Ltd -*/ - -#include <unistd.h> -#include <syscall.h> -#include <linux/bpf.h> - -#include <tap_flow.h> -#include <tap_autoconf.h> - -#include <tap_bpf_insns.h> - - -static int bpf_load (enum bpf_prog_type type,const struct bpf_insn *insns, -size_t insns_cnt,const char *license); - -/** -* Load BPF program (section cls_q) into the kernel and return a bpf fd -* -* @param queue_idx -* Queue index matching packet cb -* -* @return -* -1 if the BPF program couldn't be loaded. An fd (int) otherwise. -*/ -int tap_flow_bpf_cls_q (__u32 queue_idx) -{ - cls_q_insns[1 ].imm = queue_idx; - -return bpf_load (BPF_PROG_TYPE_SCHED_CLS , - (struct bpf_insn *)cls_q_insns, -RTE_DIM (cls_q_insns), -"Dual BSD/GPL" ); -} - -/** -* Load BPF program (section l3_l4) into the kernel and return a bpf fd. -* -* @param[in] key_idx -* RSS MAP key index -* -* @param[in] map_fd -* BPF RSS map file descriptor -* -* @return -* -1 if the BPF program couldn't be loaded. An fd (int) otherwise. -*/ -int tap_flow_bpf_calc_l3_l4_hash (__u32 key_idx,int map_fd) -{ - l3_l4_hash_insns[4 ].imm = key_idx; - l3_l4_hash_insns[9 ].imm = map_fd; - -return bpf_load (BPF_PROG_TYPE_SCHED_ACT , - (struct bpf_insn *)l3_l4_hash_insns, -RTE_DIM (l3_l4_hash_insns), -"Dual BSD/GPL" ); -} - -/** -* Helper function to convert a pointer to unsigned 64 bits -* -* @param[in] ptr -* pointer to address -* -* @return -* 64 bit unsigned long type of pointer address -*/ -static inline __u64 ptr_to_u64 (const void *ptr) -{ -return (__u64 )(unsigned long )ptr; -} - -/** -* Call BPF system call -* -* @param[in] cmd -* BPF command for program loading, map creation, map entry update, etc -* -* @param[in] attr -* System call attributes relevant to system call command -* -* @param[in] size -* size of attr parameter -* -* @return -* -1 if BPF system call failed, 0 otherwise -*/ -static inline int sys_bpf (enum bpf_cmd cmd,union bpf_attr *attr, -unsigned int size) -{ -#ifdef __NR_bpf -return syscall (__NR_bpf, cmd, attr, size); -#else -TAP_LOG (ERR ,"No bpf syscall, kernel headers too old?\n" ); - errno =ENOSYS ; -return -1 ; -#endif -} - -/** -* Load BPF instructions to kernel -* -* @param[in] type -* BPF program type: classifier or action -* -* @param[in] insns -* Array of BPF instructions (equivalent to BPF instructions) -* -* @param[in] insns_cnt -* Number of BPF instructions (size of array) -* -* @param[in] license -* License string that must be acknowledged by the kernel -* -* @return -* -1 if the BPF program couldn't be loaded, fd (file descriptor) otherwise -*/ -static int bpf_load (enum bpf_prog_type type, -const struct bpf_insn *insns, -size_t insns_cnt, -const char *license) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - attr.prog_type = type; - attr.insn_cnt = (__u32 )insns_cnt; - attr.insns =ptr_to_u64 (insns); - attr.license =ptr_to_u64 (license); - attr.log_buf =ptr_to_u64 (NULL ); - attr.log_level =0 ; - attr.kern_version =0 ; - -return sys_bpf (BPF_PROG_LOAD , &attr,sizeof (attr)); -} - -/** -* Create BPF map for RSS rules -* -* @param[in] key_size -* map RSS key size -* -* @param[in] value_size -* Map RSS value size -* -* @param[in] max_entries -* Map max number of RSS entries (limit on max RSS rules) -* -* @return -* -1 if BPF map couldn't be created, map fd otherwise -*/ -int tap_flow_bpf_rss_map_create (unsigned int key_size, -unsigned int value_size, -unsigned int max_entries) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - attr.map_type =BPF_MAP_TYPE_HASH ; - attr.key_size = key_size; - attr.value_size = value_size; - attr.max_entries = max_entries; - -return sys_bpf (BPF_MAP_CREATE , &attr,sizeof (attr)); -} - -/** -* Update RSS entry in BPF map -* -* @param[in] fd -* RSS map fd -* -* @param[in] key -* Pointer to RSS key whose entry is updated -* -* @param[in] value -* Pointer to RSS new updated value -* -* @return -* -1 if RSS entry failed to be updated, 0 otherwise -*/ -int tap_flow_bpf_update_rss_elem (int fd,void *key,void *value) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - - attr.map_type =BPF_MAP_TYPE_HASH ; - attr.map_fd = fd; - attr.key =ptr_to_u64 (key); - attr.value =ptr_to_u64 (value); - attr.flags =BPF_ANY ; - -return sys_bpf (BPF_MAP_UPDATE_ELEM , &attr,sizeof (attr)); -}
drivers/net/tap/tap_bpf_insns.h deleted +0 -1742
1,742 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v3 7/7 MAINTAINERS: add maintainer for TAP device
In reply to Stephen HemmingerAdd myself as maintainer for TAP device.
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -1015,6 +1015,7 @@ F: doc/guides/nics/pcap_ring.rst F: doc/guides/nics/features/pcap.ini Tap PMD +M: Stephen Hemminger <[email protected]> F: drivers/net/tap/ F: doc/guides/nics/tap.rst F: doc/guides/nics/features/tap.ini
Signature · 1 line
2.43.0
v4 cover net/tap: queue flow action RSS using BPF redo
In reply to Stephen HemmingerThe support of doing RSS for rte_flow_action was a cool idea but it has been broken for several releases of DPDK as the kernel and BPF infrastructure changed.
This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF toolchain.
The result should be easier to read and maintain. The build process checks for the required components and if not there will stub out to not supported.
This patch series is mostly the same as the original RFC, most of the changes are to split it up and always build the BPF from source.
v4 - remove accidental inclusion of tap_bpf_program.o
split number of queues from the number of RSS queue flows define number of queues one place
Stephen Hemminger (7):
net/tap: remove unused RSS hash types net/tap: validate and setup parameters for BPF RSS
tap: stop "vendoring" linux bpf headers net/tap: rewrite the RSS BPF program net/tap: use libbpf to load new BPF program net/tap: remove no longer used files
MAINTAINERS: add maintainer for TAP device
.gitignore | 3 - MAINTAINERS | 1 + drivers/net/tap/bpf/Makefile | 19 - drivers/net/tap/bpf/README | 12 + drivers/net/tap/bpf/bpf_api.h | 276 ---- drivers/net/tap/bpf/bpf_elf.h | 53 - drivers/net/tap/bpf/bpf_extract.py | 86 -- drivers/net/tap/bpf/meson.build | 82 ++ drivers/net/tap/bpf/tap_bpf_program.c | 255 ---- drivers/net/tap/bpf/tap_rss.c | 272 ++++ drivers/net/tap/meson.build | 29 +- drivers/net/tap/rte_eth_tap.c | 2 + drivers/net/tap/rte_eth_tap.h | 9 +- drivers/net/tap/tap_bpf.h | 121 -- drivers/net/tap/tap_bpf_api.c | 190 --- drivers/net/tap/tap_bpf_insns.h | 1743 ------------------------- drivers/net/tap/tap_flow.c | 521 +++----- drivers/net/tap/tap_flow.h | 16 +- drivers/net/tap/tap_rss.h | 21 +- drivers/net/tap/tap_tcmsgs.h | 4 +- 20 files changed, 543 insertions(+), 3172 deletions(-) delete mode 100644 drivers/net/tap/bpf/Makefile create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py create mode 100644 drivers/net/tap/bpf/meson.build delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c delete mode 100644 drivers/net/tap/tap_bpf.h delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h
Signature · 1 line
2.43.0
PATCH v4 1/7 net/tap: remove unused RSS hash types
The driver doesn't support these other hash types, and there is no reason to implement these in future.
--- drivers/net/tap/tap_rss.h | 6 ------ 1 file changed, 6 deletions(-)
drivers/net/tap/tap_rss.h +0 -6
@@ -21,12 +21,6 @@ enum hash_field {HASH_FIELD_IPV4_L3_L4 ,/* IPv4 src/dst addr + L4 src/dst ports */ HASH_FIELD_IPV6_L3 ,/* IPv6 src/dst addr */ HASH_FIELD_IPV6_L3_L4, /* IPv6 src/dst addr + L4 src/dst ports */ -HASH_FIELD_L2_SRC ,/* Ethernet src addr */ -HASH_FIELD_L2_DST ,/* Ethernet dst addr */ -HASH_FIELD_L3_SRC ,/* L3 src addr */ -HASH_FIELD_L3_DST ,/* L3 dst addr */ -HASH_FIELD_L4_SRC ,/* TCP/UDP src ports */ - HASH_FIELD_L4_DST, /* TCP/UDP dst ports */ }; struct rss_key {
Signature · 1 line
2.43.0
PATCH v4 2/7 net/tap: validate and setup parameters for BPF RSS
In reply to Stephen HemmingerThe flow RSS support via BPF was not using the key, or hash type parameters. Which is good because they were never properly setup.
Fix the setup and validate the flow parameters, the BPF side gets fixed later.
--- drivers/net/tap/tap_bpf_insns.h | 16 ++++---- drivers/net/tap/tap_flow.c | 65 ++++++++++++++++++++++++++++++--- drivers/net/tap/tap_rss.h | 5 +-- 3 files changed, 70 insertions(+), 16 deletions(-)
drivers/net/tap/tap_bpf_insns.h +8 -8
@@ -1709,13 +1709,13 @@ static struct bpf_insn l3_l4_hash_insns[] = { {0x57, 1, 0, 0, 0x00000001}, {0x15, 1, 0, 1, 0x00000000}, {0xa7, 3, 0, 0, 0xfe0fee15}, - {0x71, 1, 0, 201, 0x00000000}, + {0x71, 1, 0, 45, 0x00000000}, {0x67, 1, 0, 0, 0x00000008}, - {0x71, 2, 0, 200, 0x00000000}, + {0x71, 2, 0, 44, 0x00000000}, {0x4f, 1, 2, 0, 0x00000000}, - {0x71, 2, 0, 202, 0x00000000}, + {0x71, 2, 0, 46, 0x00000000}, {0x67, 2, 0, 0, 0x00000010}, - {0x71, 4, 0, 203, 0x00000000}, + {0x71, 4, 0, 47, 0x00000000}, {0x67, 4, 0, 0, 0x00000018}, {0x4f, 4, 2, 0, 0x00000000}, {0x4f, 4, 1, 0, 0x00000000},
@@ -1725,13 +1725,13 @@ static struct bpf_insn l3_l4_hash_insns[] = { {0x57, 3, 0, 0, 0x0000000f}, {0x67, 3, 0, 0, 0x00000002}, {0x0f, 0, 3, 0, 0x00000000}, - {0x71, 1, 0, 137, 0x00000000}, + {0x71, 1, 0, 49, 0x00000000}, {0x67, 1, 0, 0, 0x00000008}, - {0x71, 2, 0, 136, 0x00000000}, + {0x71, 2, 0, 48, 0x00000000}, {0x4f, 1, 2, 0, 0x00000000}, - {0x71, 2, 0, 138, 0x00000000}, + {0x71, 2, 0, 50, 0x00000000}, {0x67, 2, 0, 0, 0x00000010}, - {0x71, 3, 0, 139, 0x00000000}, + {0x71, 3, 0, 51, 0x00000000}, {0x67, 3, 0, 0, 0x00000018}, {0x4f, 3, 2, 0, 0x00000000}, {0x4f, 3, 1, 0, 0x00000000},
drivers/net/tap/tap_flow.c +60 -5
99 lines not on this page · raw message
drivers/net/tap/tap_rss.h +2 -3
@@ -24,11 +24,10 @@ enum hash_field { };struct rss_key { -__u8 key[128 ];__u32 hash_fields; -__u32 key_size; -__u32 queues[TAP_MAX_QUEUES ]; +__u8 key[TAP_RSS_HASH_KEY_SIZE ];__u32 nb_queues; +__u32 queues[TAP_MAX_QUEUES ]; } __attribute__((packed));#endif /* _TAP_RSS_H_ */
Signature · 1 line
2.43.0
PATCH v4 3/7 tap: stop "vendoring" linux bpf headers
In reply to Stephen HemmingerThe proper place for finding bpf structures and functions is in linux/bpf.h. The original version was trying to workaround the case where the build environment was running on old pre BPF version of Glibc, but the target environment had BPF. This is not a supportable build method, and not how rest of DPDK works.
Having own private (and divergent) version headers leads to future problems when BPF definitions evolve.
Since DPDK officially supports only LTS or later kernel there is no need for the #ifdef workarounds in the TAP flow code. Cloning headers leads to problems and no longer needed.
--- drivers/net/tap/bpf/bpf_extract.py | 1 - drivers/net/tap/tap_bpf.h | 121 ----------------------------- drivers/net/tap/tap_bpf_api.c | 20 +++-- drivers/net/tap/tap_bpf_insns.h | 1 - drivers/net/tap/tap_flow.c | 89 --------------------- 5 files changed, 13 insertions(+), 219 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf.h
drivers/net/tap/bpf/bpf_extract.py +0 -1
@@ -65,7 +65,6 @@ def write_header(out, source): print(f' * Auto-generated from {source}', file=out) print(" * This not the original source file. Do NOT edit it.", file=out) print(" */\n", file=out) - print("#include <tap_bpf.h>", file=out) def main():
drivers/net/tap/tap_bpf.h deleted +0 -121
121 lines not on this page · raw message
drivers/net/tap/tap_bpf_api.c +13 -7
@@ -2,19 +2,19 @@* Copyright 2017 Mellanox Technologies, Ltd */ -#include <errno.h> -#include <string.h> #include <unistd.h> -#include <sys/queue.h> +#include <syscall.h> +#include <linux/bpf.h> -#include <rte_malloc.h> -#include <rte_eth_tap.h> #include <tap_flow.h> #include <tap_autoconf.h> -#include <tap_tcmsgs.h> -#include <tap_bpf.h> +#include <tap_bpf_insns.h> + +static int bpf_load (enum bpf_prog_type type,const struct bpf_insn *insns, +size_t insns_cnt,const char *license); +/** * Load BPF program (section cls_q) into the kernel and return a bpf fd *
@@ -89,7 +89,13 @@ static inline __u64 ptr_to_u64(const void *ptr)static inline int sys_bpf (enum bpf_cmd cmd,union bpf_attr *attr,unsigned int size) { +#ifdef __NR_bpfreturn syscall (__NR_bpf, cmd, attr, size); +#else +TAP_LOG (ERR ,"No bpf syscall, kernel headers too old?\n" ); + errno =ENOSYS ; +return -1 ; +#endif }/**
drivers/net/tap/tap_bpf_insns.h +0 -1
@@ -3,7 +3,6 @@* This not the original source file. Do NOT edit it. */ -#include <tap_bpf.h> static struct bpf_insn cls_q_insns[] = { {0x61 ,2 ,1 ,52 ,0x00000000 },
drivers/net/tap/tap_flow.c +0 -89
95 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v4 4/7 net/tap: rewrite the RSS BPF program
In reply to Stephen HemmingerRewrite the BPF program used to do queue based RSS. Important changes:
- uses newer BPF map format BTF
- accepts key as parameter rather than constant default
- can do L3 or L4 hashing
- supports IPv4 options
- supports IPv6 extension headers
- restructured for readability
The usage of BPF is different as well:
- the incoming configuration is looked up based on class parameters rather than patching the BPF.
- the resulting queue is placed in skb rather than requiring a second pass through classifier step.
Note: This version only works with later patch to enable it on the DPDK driver side. It is submitted as an incremental patch to allow for easier review. Bisection still works because the old instruction are still present for now.
--- .gitignore | 3 - drivers/net/tap/bpf/Makefile | 19 -- drivers/net/tap/bpf/README | 12 ++ drivers/net/tap/bpf/bpf_api.h | 276 -------------------------- drivers/net/tap/bpf/bpf_elf.h | 53 ----- drivers/net/tap/bpf/bpf_extract.py | 85 -------- drivers/net/tap/bpf/meson.build | 81 ++++++++ drivers/net/tap/bpf/tap_bpf_program.c | 255 ------------------------ drivers/net/tap/bpf/tap_rss.c | 272 +++++++++++++++++++++++++ 9 files changed, 365 insertions(+), 691 deletions(-) delete mode 100644 drivers/net/tap/bpf/Makefile create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py create mode 100644 drivers/net/tap/bpf/meson.build delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c
.gitignore +0 -3
@@ -36,9 +36,6 @@ TAGS # ignore python bytecode files *.pyc -# ignore BPF programs -drivers/net/tap/bpf/tap_bpf_program.o - # DTS results dts/output
drivers/net/tap/bpf/Makefile deleted +0 -19
@@ -1,19 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# This file is not built as part of normal DPDK build. -# It is used to generate the eBPF code for TAP RSS. - -CLANG=clang -CLANG_OPTS=-O2 -TARGET=../tap_bpf_insns.h - -all: $(TARGET) - -clean: - rm tap_bpf_program.o $(TARGET) - -tap_bpf_program.o: tap_bpf_program.c - $(CLANG) $(CLANG_OPTS) -emit-llvm -c $< -o - | \ - llc -march=bpf -filetype=obj -o $@ - -$(TARGET): tap_bpf_program.o - python3 bpf_extract.py -stap_bpf_program.c -o $@ $<
drivers/net/tap/bpf/README new file +12 -0
@@ -0,0 +1,12 @@ +This is the BPF program used to implement the RSS across queues +flow action. It works like the skbedit tc filter but instead of mapping +to only one queues, it maps to multiple queues based on RSS hash. + +This version is built the BPF Compile Once — Run Everywhere (CO-RE) +framework and uses libbpf and bpftool. + +Limitations +- requires libbpf version XX or later +- rebuilding the BPF requires clang and bpftool +- only Toeplitz hash with standard 40 byte key is supported +- the number of queues per RSS action is limited to 16
drivers/net/tap/bpf/bpf_api.h deleted +0 -276
276 lines not on this page · raw message
drivers/net/tap/bpf/bpf_elf.h deleted +0 -53
53 lines not on this page · raw message
drivers/net/tap/bpf/bpf_extract.py deleted +0 -85
85 lines not on this page · raw message
drivers/net/tap/bpf/meson.build new file +81 -0
81 lines not on this page · raw message
drivers/net/tap/bpf/tap_bpf_program.c deleted +0 -255
255 lines not on this page · raw message
drivers/net/tap/bpf/tap_rss.c new file +272 -0
272 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v4 4/7] net/tap: rewrite the RSS BPF program
Quoted 21 lines · Stephen Hemminger
Rewrite the BPF program used to do queue based RSS. Important changes:
- uses newer BPF map format BTF
- accepts key as parameter rather than constant default
- can do L3 or L4 hashing
- supports IPv4 options
- supports IPv6 extension headers
- restructured for readabilityThe usage of BPF is different as well:
- the incoming configuration is looked up based on class parameters rather than patching the BPF.
- the resulting queue is placed in skb rather than requiring a second pass through classifier step.Note: This version only works with later patch to enable it on the DPDK driver side. It is submitted as an incremental patch to allow for easier review. Bisection still works because the old instruction are still present for now.
Signed-off-by Stephen Hemminger <[email protected]>
<...>
Quoted 14 lines
drivers/net/tap/bpf/meson.build new file +7
-0@@ -0,0 +1,81 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024 Stephen Hemminger <[email protected]> + +enable_tap_rss = false + +libbpf = dependency('libbpf', required: false, method: 'pkg-config') +if not libbpf.found()
drivers/net/tap/bpf/meson.build line 17
Quoted 10 lines
drivers/net/tap/bpf/meson.build new file +10
-0+ message('net/tap: no RSS support missing libbpf') + subdir_done() +endif + +# Debian install this in /usr/sbin which is not in $PATH +bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false, version: '>= 5.6.0') +if not bpftool.found() + message('net/tap: no RSS support missing bpftool') + subdir_done() +endif
I am getting following build error:
'drivers/net/tap/bpf/meson.build:13:10: ERROR: Command /usr/sbin/bpftool --version failed with status 2.
'
There is a '/usr/sbin/bpftool' file but it is a script and gives following message when run:
"WARNING: bpftool not found for kernel 6.5.0-15"
This is with "Ubuntu 22.04.3 LTS"
Overall thanks for fixing tap BPF support.
Re: [PATCH v4 4/7] net/tap: rewrite the RSS BPF program
Quoted 56 lines · On Sat, 10 Feb 2024 00:54:15 +0000 Ferruh Yigit <[email protected]> wrote:
Quoted 21 lines · Stephen Hemminger
Rewrite the BPF program used to do queue based RSS. Important changes:
- uses newer BPF map format BTF
- accepts key as parameter rather than constant default
- can do L3 or L4 hashing
- supports IPv4 options
- supports IPv6 extension headers
- restructured for readabilityThe usage of BPF is different as well:
- the incoming configuration is looked up based on class parameters rather than patching the BPF.
- the resulting queue is placed in skb rather than requiring a second pass through classifier step.Note: This version only works with later patch to enable it on the DPDK driver side. It is submitted as an incremental patch to allow for easier review. Bisection still works because the old instruction are still present for now.
Signed-off-by Stephen Hemminger <[email protected]><...>
Quoted 14 lines
drivers/net/tap/bpf/meson.build new file +7
-0@@ -0,0 +1,81 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024 Stephen Hemminger <[email protected]> + +enable_tap_rss = false + +libbpf = dependency('libbpf', required: false, method: 'pkg-config') +if not libbpf.found()drivers/net/tap/bpf/meson.build line 17
Quoted 10 lines
drivers/net/tap/bpf/meson.build new file +10
-0+ message('net/tap: no RSS support missing libbpf') + subdir_done() +endif + +# Debian install this in /usr/sbin which is not in $PATH +bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false, version: '>= 5.6.0') +if not bpftool.found() + message('net/tap: no RSS support missing bpftool') + subdir_done() +endifI am getting following build error:
'drivers/net/tap/bpf/meson.build:13:10: ERROR: Command/usr/sbin/bpftool --versionfailed with status 2.
'
Quoted 8 lines
There is a '
/usr/sbin/bpftool' file but it is a script and gives following message when run:
"WARNING: bpftool not found for kernel 6.5.0-15"This is with "Ubuntu 22.04.3 LTS"
Overall thanks for fixing tap BPF support.
Just set up an equivalent Ubuntu VM 22.04 VM and made sure all packages were up to date.
Looks like Ubuntu borked the packaging of bpftool. Maybe Luca has some insight.
shemminger@ubuntu-22-04:~/dpdk$ sudo apt install libbpf-dev bpftool Reading package lists... Done Building dependency tree... Done Reading state information... Done Package bpftool is a virtual package provided by: linux-nvidia-6.2-tools-common 6.2.0-1003.3~22.04.1 linux-lowlatency-hwe-6.5-tools-common 6.5.0-17.17.1.1.1~22.04.1 linux-hwe-6.5-tools-common 6.5.0-17.17~22.04.1 linux-hwe-6.2-tools-common 6.2.0-39.40~22.04.1 You should explicitly select one to install.
Re: [PATCH v4 4/7] net/tap: rewrite the RSS BPF program
Quoted 74 lines · Stephen Hemminger
Quoted 56 lines · On Sat, 10 Feb 2024 00:54:15 +0000 Ferruh Yigit <[email protected]> wrote:
Quoted 21 lines · Stephen Hemminger
Rewrite the BPF program used to do queue based RSS. Important changes:
- uses newer BPF map format BTF
- accepts key as parameter rather than constant default
- can do L3 or L4 hashing
- supports IPv4 options
- supports IPv6 extension headers
- restructured for readabilityThe usage of BPF is different as well:
- the incoming configuration is looked up based on class parameters rather than patching the BPF.
- the resulting queue is placed in skb rather than requiring a second pass through classifier step.Note: This version only works with later patch to enable it on the DPDK driver side. It is submitted as an incremental patch to allow for easier review. Bisection still works because the old instruction are still present for now.
Signed-off-by Stephen Hemminger <[email protected]><...>
Quoted 14 lines
drivers/net/tap/bpf/meson.build new file +7
-0@@ -0,0 +1,81 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024 Stephen Hemminger <[email protected]> + +enable_tap_rss = false + +libbpf = dependency('libbpf', required: false, method: 'pkg-config') +if not libbpf.found()drivers/net/tap/bpf/meson.build line 17
Quoted 10 lines
drivers/net/tap/bpf/meson.build new file +10
-0+ message('net/tap: no RSS support missing libbpf') + subdir_done() +endif + +# Debian install this in /usr/sbin which is not in $PATH +bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false, version: '>= 5.6.0') +if not bpftool.found() + message('net/tap: no RSS support missing bpftool') + subdir_done() +endifI am getting following build error:
'drivers/net/tap/bpf/meson.build:13:10: ERROR: Command/usr/sbin/bpftool --versionfailed with status 2.
'Quoted 8 lines
There is a '
/usr/sbin/bpftool' file but it is a script and gives following message when run:
"WARNING: bpftool not found for kernel 6.5.0-15"This is with "Ubuntu 22.04.3 LTS"
Overall thanks for fixing tap BPF support.
Just set up an equivalent Ubuntu VM 22.04 VM and made sure all packages were up to date.
Looks like Ubuntu borked the packaging of bpftool. Maybe Luca has some insight.
Quoted 11 lines
shemminger@ubuntu-22-04:~/dpdk$ sudo apt install libbpf-dev bpftool Reading package lists... Done Building dependency tree... Done Reading state information... Done Package bpftool is a virtual package provided by: linux-nvidia-6.2-tools-common 6.2.0-1003.3~22.04.1 linux-lowlatency-hwe-6.5-tools-common 6.5.0-17.17.1.1.1~22.04.1 linux-hwe-6.5-tools-common 6.5.0-17.17~22.04.1 linux-hwe-6.2-tools-common 6.2.0-39.40~22.04.1 You should explicitly select one to install.
I can make it work but it can hit others too, we need something that detects this condition and disables tap/bpf.
Re: [PATCH v4 4/7] net/tap: rewrite the RSS BPF program
Quoted 13 lines · On Wed, 28 Feb 2024 17:27:31 +0000 Ferruh Yigit <[email protected]> wrote:
Quoted 12 lines
shemminger@ubuntu-22-04:~/dpdk$ sudo apt install libbpf-dev bpftool Reading package lists... Done Building dependency tree... Done Reading state information... Done Package bpftool is a virtual package provided by: linux-nvidia-6.2-tools-common 6.2.0-1003.3~22.04.1 linux-lowlatency-hwe-6.5-tools-common 6.5.0-17.17.1.1.1~22.04.1 linux-hwe-6.5-tools-common 6.5.0-17.17~22.04.1 linux-hwe-6.2-tools-common 6.2.0-39.40~22.04.1 You should explicitly select one to install.
Quoted 2 lines
I can make it work but it can hit others too, we need something that detects this condition and disables tap/bpf.
The meson rule checks for bpftool and when it doesn't find a working version it skips building the BPF RSS stuff.
PATCH v4 5/7 net/tap: use libbpf to load new BPF program
In reply to Stephen HemmingerThere were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.
Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.
The new BPF program only needs a single action.
No need for action and re-classification step.
It alsow fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.
--- drivers/net/tap/bpf/meson.build | 1 + drivers/net/tap/bpf/tap_rss.c | 2 +- drivers/net/tap/meson.build | 29 +-- drivers/net/tap/rte_eth_tap.c | 2 + drivers/net/tap/rte_eth_tap.h | 9 +- drivers/net/tap/tap_flow.c | 381 ++++++++------------------------ drivers/net/tap/tap_flow.h | 16 +- drivers/net/tap/tap_rss.h | 10 +- drivers/net/tap/tap_tcmsgs.h | 4 +- 9 files changed, 123 insertions(+), 331 deletions(-)
drivers/net/tap/bpf/meson.build +1 -0
@@ -42,6 +42,7 @@ clang_flags = [ '-O2', '-Wall', '-Wextra', + max_queues, '-target', 'bpf', '-g',
drivers/net/tap/bpf/tap_rss.c +1 -1
@@ -24,7 +24,7 @@ struct {__uint (type,BPF_MAP_TYPE_HASH );__uint (key_size,sizeof (__u16));__uint (value_size,sizeof (struct rss_key )); -__uint (max_entries,TAP_MAX_QUEUES ); +__uint (max_entries,TAP_RSS_MAX ); } rss_map SEC(".maps");
drivers/net/tap/meson.build +9 -20
@@ -7,33 +7,22 @@ if not is_linux endif sources = files( 'rte_eth_tap.c', - 'tap_bpf_api.c', 'tap_flow.c', 'tap_intr.c', 'tap_netlink.c', 'tap_tcmsgs.c', ) -deps = ['bus_vdev', 'gso', 'hash'] +max_queues = '-DTAP_MAX_QUEUES=16' +cflags += max_queues -cflags += '-DTAP_MAX_QUEUES=16' +subdir('bpf') +if enable_tap_rss + cflags += '-DHAVE_BPF_RSS' + ext_deps += libbpf + sources += tap_rss_skel_h +endif -# input array for meson symbol search: -# [ "MACRO to define if found", "header for the search", -# "enum/define", "symbol to search" ] -# -args = [ - [ 'HAVE_TC_FLOWER', 'linux/pkt_cls.h', 'TCA_FLOWER_UNSPEC' ], - [ 'HAVE_TC_VLAN_ID', 'linux/pkt_cls.h', 'TCA_FLOWER_KEY_VLAN_PRIO' ], - [ 'HAVE_TC_BPF', 'linux/pkt_cls.h', 'TCA_BPF_UNSPEC' ], - [ 'HAVE_TC_BPF_FD', 'linux/pkt_cls.h', 'TCA_BPF_FD' ], - [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ], - [ 'HAVE_TC_ACT_BPF_FD', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_FD' ], -] -config = configuration_data() -foreach arg:args - config.set(arg[0], cc.has_header_symbol(arg[1], arg[2])) -endforeach -configure_file(output : 'tap_autoconf.h', configuration : config) +deps = ['bus_vdev', 'gso', 'hash'] require_iova_in_mbuf = false
drivers/net/tap/rte_eth_tap.c +2 -0
@@ -1138,6 +1138,7 @@ tap_dev_close(struct rte_eth_dev *dev)tap_flow_implicit_flush (internals,NULL );tap_nl_final (internals->nlsk_fd); internals->nlsk_fd =-1 ; +tap_flow_bpf_destroy (internals); }for (i =0 ; i <RTE_PMD_TAP_MAX_QUEUES ; i++) {
@@ -1959,6 +1960,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,strlcpy (pmd->name, tap_name,sizeof (pmd->name)); pmd->type = type; pmd->ka_fd =-1 ; + pmd->rss =NULL ; pmd->nlsk_fd =-1 ; pmd->gso_ctx_mp =NULL ;
drivers/net/tap/rte_eth_tap.h +4 -5
@@ -79,12 +79,11 @@ struct pmd_internals {int flow_isolate;/* 1 if flow isolation is enabled */ int flower_support;/* 1 if kernel supports, else 0 */ int flower_vlan_support;/* 1 if kernel supports, else 0 */ -int rss_enabled;/* 1 if RSS is enabled, else 0 */ int persist;/* 1 if keep link up, else 0 */ -/* implicit rules set when RSS is enabled */ -int map_fd;/* BPF RSS map fd */ -int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */ - LIST_HEAD(tap_rss_flows, rte_flow) rss_flows; + +struct tap_rss *rss;/* BPF program */ +uint16_t bpf_flowid;/* next BPF class id */ + LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */ LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
drivers/net/tap/tap_flow.c +95 -286
525 lines not on this page · raw message
drivers/net/tap/tap_flow.h +6 -10
@@ -9,7 +9,11 @@#include <rte_flow.h> #include <rte_flow_driver.h> #include <rte_eth_tap.h> -#include <tap_autoconf.h> + +/** +* Mask of unsupported RSS types +*/ +#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP))/** * In TC, priority 0 means we require the kernel to allocate one for us.
@@ -41,10 +45,6 @@ enum implicit_rule_index { TAP_REMOTE_MAX_IDX, }; -enum bpf_fd_idx { -SEC_L3_L4 , -SEC_MAX , -};int tap_dev_flow_ops_get (struct rte_eth_dev *dev,const struct rte_flow_ops **ops);
@@ -57,10 +57,6 @@ int tap_flow_implicit_destroy(struct pmd_internals *pmd,int tap_flow_implicit_flush (struct pmd_internals *pmd,struct rte_flow_error *error); -int tap_flow_bpf_cls_q (__u32 queue_idx); -int tap_flow_bpf_calc_l3_l4_hash (__u32 key_idx,int map_fd); -int tap_flow_bpf_rss_map_create (unsigned int key_size,unsigned int value_size, -unsigned int max_entries); -int tap_flow_bpf_update_rss_elem (int fd,void *key,void *value); +void tap_flow_bpf_destroy (struct pmd_internals *pmd);#endif /* _TAP_FLOW_H_ */
drivers/net/tap/tap_rss.h +4 -6
@@ -5,16 +5,14 @@#ifndef _TAP_RSS_H_#define _TAP_RSS_H_ -#ifndef TAP_MAX_QUEUES -#define TAP_MAX_QUEUES 16 +/* Size of the map from BPF classid to queue table */ +#ifndef TAP_RSS_MAX +#define TAP_RSS_MAX 32#endif -/* Fixed RSS hash key size in bytes. */ +/* Standard Toeplitz hash key size */ #define TAP_RSS_HASH_KEY_SIZE 40 -/* Supported RSS */ -#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP)) -/* hashed fields for RSS */ enum hash_field { HASH_FIELD_IPV4_L3, /* IPv4 src/dst addr */
drivers/net/tap/tap_tcmsgs.h +1 -3
@@ -6,7 +6,6 @@#ifndef _TAP_TCMSGS_H_#define _TAP_TCMSGS_H_ -#include <tap_autoconf.h> #include <linux/if_ether.h> #include <linux/rtnetlink.h> #include <linux/pkt_sched.h>
@@ -14,9 +13,8 @@#include <linux/tc_act/tc_mirred.h> #include <linux/tc_act/tc_gact.h> #include <linux/tc_act/tc_skbedit.h> -#ifdef HAVE_TC_ACT_BPF #include <linux/tc_act/tc_bpf.h> -#endif +#include <inttypes.h> #include <rte_ether.h>
Signature · 1 line
2.43.0
Re: [PATCH v4 5/7] net/tap: use libbpf to load new BPF program
Quoted 11 lines · On Thu, 8 Feb 2024 11:05:53 -0800 Stephen Hemminger…
There were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.
Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.
Quoted 8 lines
The new BPF program only needs a single action.
No need for action and re-classification step.It alsow fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.Signed-off-by Stephen Hemminger <[email protected]>
Note: this patch introduces a optional dependency on bpftool to get the RSS to work. If bpftool is not present, then RSS is not built, and attempts to use rte_flow_action_queue will fail with not supported.
It looks like the CI build environment is missing bpftool, so all the builds just skip that code. This works but CI build environments need to change to get bpftool. Not sure how to make that happen.
PATCH v4 6/7 net/tap: remove no longer used files
In reply to Stephen HemmingerThe BPF api was replaced by use of libbpf.
And the BPF instruction header was replaced by the skeleton.
--- drivers/net/tap/tap_bpf_api.c | 196 ---- drivers/net/tap/tap_bpf_insns.h | 1742 ------------------------------- 2 files changed, 1938 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h
drivers/net/tap/tap_bpf_api.c deleted +0 -196
@@ -1,196 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright 2017 Mellanox Technologies, Ltd -*/ - -#include <unistd.h> -#include <syscall.h> -#include <linux/bpf.h> - -#include <tap_flow.h> -#include <tap_autoconf.h> - -#include <tap_bpf_insns.h> - - -static int bpf_load (enum bpf_prog_type type,const struct bpf_insn *insns, -size_t insns_cnt,const char *license); - -/** -* Load BPF program (section cls_q) into the kernel and return a bpf fd -* -* @param queue_idx -* Queue index matching packet cb -* -* @return -* -1 if the BPF program couldn't be loaded. An fd (int) otherwise. -*/ -int tap_flow_bpf_cls_q (__u32 queue_idx) -{ - cls_q_insns[1 ].imm = queue_idx; - -return bpf_load (BPF_PROG_TYPE_SCHED_CLS , - (struct bpf_insn *)cls_q_insns, -RTE_DIM (cls_q_insns), -"Dual BSD/GPL" ); -} - -/** -* Load BPF program (section l3_l4) into the kernel and return a bpf fd. -* -* @param[in] key_idx -* RSS MAP key index -* -* @param[in] map_fd -* BPF RSS map file descriptor -* -* @return -* -1 if the BPF program couldn't be loaded. An fd (int) otherwise. -*/ -int tap_flow_bpf_calc_l3_l4_hash (__u32 key_idx,int map_fd) -{ - l3_l4_hash_insns[4 ].imm = key_idx; - l3_l4_hash_insns[9 ].imm = map_fd; - -return bpf_load (BPF_PROG_TYPE_SCHED_ACT , - (struct bpf_insn *)l3_l4_hash_insns, -RTE_DIM (l3_l4_hash_insns), -"Dual BSD/GPL" ); -} - -/** -* Helper function to convert a pointer to unsigned 64 bits -* -* @param[in] ptr -* pointer to address -* -* @return -* 64 bit unsigned long type of pointer address -*/ -static inline __u64 ptr_to_u64 (const void *ptr) -{ -return (__u64 )(unsigned long )ptr; -} - -/** -* Call BPF system call -* -* @param[in] cmd -* BPF command for program loading, map creation, map entry update, etc -* -* @param[in] attr -* System call attributes relevant to system call command -* -* @param[in] size -* size of attr parameter -* -* @return -* -1 if BPF system call failed, 0 otherwise -*/ -static inline int sys_bpf (enum bpf_cmd cmd,union bpf_attr *attr, -unsigned int size) -{ -#ifdef __NR_bpf -return syscall (__NR_bpf, cmd, attr, size); -#else -TAP_LOG (ERR ,"No bpf syscall, kernel headers too old?\n" ); - errno =ENOSYS ; -return -1 ; -#endif -} - -/** -* Load BPF instructions to kernel -* -* @param[in] type -* BPF program type: classifier or action -* -* @param[in] insns -* Array of BPF instructions (equivalent to BPF instructions) -* -* @param[in] insns_cnt -* Number of BPF instructions (size of array) -* -* @param[in] license -* License string that must be acknowledged by the kernel -* -* @return -* -1 if the BPF program couldn't be loaded, fd (file descriptor) otherwise -*/ -static int bpf_load (enum bpf_prog_type type, -const struct bpf_insn *insns, -size_t insns_cnt, -const char *license) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - attr.prog_type = type; - attr.insn_cnt = (__u32 )insns_cnt; - attr.insns =ptr_to_u64 (insns); - attr.license =ptr_to_u64 (license); - attr.log_buf =ptr_to_u64 (NULL ); - attr.log_level =0 ; - attr.kern_version =0 ; - -return sys_bpf (BPF_PROG_LOAD , &attr,sizeof (attr)); -} - -/** -* Create BPF map for RSS rules -* -* @param[in] key_size -* map RSS key size -* -* @param[in] value_size -* Map RSS value size -* -* @param[in] max_entries -* Map max number of RSS entries (limit on max RSS rules) -* -* @return -* -1 if BPF map couldn't be created, map fd otherwise -*/ -int tap_flow_bpf_rss_map_create (unsigned int key_size, -unsigned int value_size, -unsigned int max_entries) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - attr.map_type =BPF_MAP_TYPE_HASH ; - attr.key_size = key_size; - attr.value_size = value_size; - attr.max_entries = max_entries; - -return sys_bpf (BPF_MAP_CREATE , &attr,sizeof (attr)); -} - -/** -* Update RSS entry in BPF map -* -* @param[in] fd -* RSS map fd -* -* @param[in] key -* Pointer to RSS key whose entry is updated -* -* @param[in] value -* Pointer to RSS new updated value -* -* @return -* -1 if RSS entry failed to be updated, 0 otherwise -*/ -int tap_flow_bpf_update_rss_elem (int fd,void *key,void *value) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - - attr.map_type =BPF_MAP_TYPE_HASH ; - attr.map_fd = fd; - attr.key =ptr_to_u64 (key); - attr.value =ptr_to_u64 (value); - attr.flags =BPF_ANY ; - -return sys_bpf (BPF_MAP_UPDATE_ELEM , &attr,sizeof (attr)); -}
drivers/net/tap/tap_bpf_insns.h deleted +0 -1742
1,742 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v4 7/7 MAINTAINERS: add maintainer for TAP device
In reply to Stephen HemmingerAdd myself as maintainer for TAP device.
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -1015,6 +1015,7 @@ F: doc/guides/nics/pcap_ring.rst F: doc/guides/nics/features/pcap.ini Tap PMD +M: Stephen Hemminger <[email protected]> F: drivers/net/tap/ F: doc/guides/nics/tap.rst F: doc/guides/nics/features/tap.ini
Signature · 1 line
2.43.0
Re: [PATCH v4 0/7] net/tap: queue flow action RSS using BPF redo
In reply to Stephen HemmingerQuoted 12 lines · On Thu, 8 Feb 2024 11:05:48 -0800 Stephen Hemminger…
The support of doing RSS for
rte_flow_actionwas a cool idea but it has been broken for several releases of DPDK as the kernel and BPF infrastructure changed.This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF toolchain.
The result should be easier to read and maintain. The build process checks for the required components and if not there will stub out to not supported.
Quoted 7 lines
This patch series is mostly the same as the original RFC, most of the changes are to split it up and always build the BPF from source.
v4 - remove accidental inclusion of tap_bpf_program.o
split number of queues from the number of RSS queue flows define number of queues one place
Please hold this until after 24.03 release. Would like to get some tests and documentation in place.
v5 cover net/tap: cleanups and fix BPF flow
In reply to Stephen HemmingerThe support of doing RSS for rte_flow_action was a cool idea but it has been broken for several releases of DPDK as the kernel and BPF infrastructure changed.
This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF toolchain.
The result should be easier to read and maintain. The build process checks for the required componen
Stephen Hemminger (8):
net/tap: do not duplicate fd's
doc: fix the requirements and building of TAP flow net/tap: remove unused RSS hash types net/tap: validate and setup parameters for BPF RSS net/tap: stop "vendoring" linux bpf headers net/tap: rewrite the RSS BPF program net/tap: use libbpf to load new BPF program net/tap: remove no longer used files
.gitignore | 3 - doc/guides/linux_gsg/sys_reqs.rst | 3 + doc/guides/nics/tap.rst | 95 +- drivers/net/tap/bpf/Makefile | 19 - drivers/net/tap/bpf/README | 38 + drivers/net/tap/bpf/bpf_api.h | 276 ---- drivers/net/tap/bpf/bpf_elf.h | 53 - drivers/net/tap/bpf/bpf_extract.py | 86 -- drivers/net/tap/bpf/meson.build | 91 ++ drivers/net/tap/bpf/tap_bpf_program.c | 255 ---- drivers/net/tap/bpf/tap_rss.c | 264 ++++ drivers/net/tap/meson.build | 29 +- drivers/net/tap/rte_eth_tap.c | 199 ++- drivers/net/tap/rte_eth_tap.h | 12 +- drivers/net/tap/tap_bpf.h | 121 -- drivers/net/tap/tap_bpf_api.c | 190 --- drivers/net/tap/tap_bpf_insns.h | 1743 ------------------------- drivers/net/tap/tap_flow.c | 549 ++------ drivers/net/tap/tap_flow.h | 16 +- drivers/net/tap/tap_intr.c | 7 +- drivers/net/tap/tap_rss.h | 21 +- drivers/net/tap/tap_tcmsgs.h | 4 +- 22 files changed, 680 insertions(+), 3394 deletions(-) delete mode 100644 drivers/net/tap/bpf/Makefile create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py create mode 100644 drivers/net/tap/bpf/meson.build delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c delete mode 100644 drivers/net/tap/tap_bpf.h delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h
Signature · 1 line
2.43.0
PATCH v5 1/8 net/tap: do not duplicate fd's
The TAP device can use same file descriptopr for both rx and tx queues. This allows up to 8 queues (versus 4).
--- drivers/net/tap/meson.build | 2 +- drivers/net/tap/rte_eth_tap.c | 197 +++++++++++++++------------------- drivers/net/tap/rte_eth_tap.h | 3 +- drivers/net/tap/tap_flow.c | 3 +- drivers/net/tap/tap_intr.c | 7 +- 5 files changed, 92 insertions(+), 120 deletions(-)
drivers/net/tap/meson.build +1 -1
@@ -16,7 +16,7 @@ sources = files( deps = ['bus_vdev', 'gso', 'hash'] -cflags += '-DTAP_MAX_QUEUES=16' +cflags += '-DTAP_MAX_QUEUES=8' # input array for meson symbol search: # [ "MACRO to define if found", "header for the search",
drivers/net/tap/rte_eth_tap.c +84 -113
343 lines not on this page · raw message
drivers/net/tap/rte_eth_tap.h +1 -2
@@ -96,8 +96,7 @@ struct pmd_internals { };struct pmd_process_private { -int rxq_fds[RTE_PMD_TAP_MAX_QUEUES ]; -int txq_fds[RTE_PMD_TAP_MAX_QUEUES ]; +int fds[RTE_PMD_TAP_MAX_QUEUES ]; };/* tap_intr.c */
drivers/net/tap/tap_flow.c +2 -1
@@ -1595,8 +1595,9 @@ tap_flow_isolate(struct rte_eth_dev *dev,* If netdevice is there, setup appropriate flow rules immediately. * Otherwise it will be set when bringing up the netdevice (tun_alloc). */ -if (!process_private->rxq_fds[0 ]) +if (process_private->fds[0 ] ==-1 )return 0 ; +if (set) {struct rte_flow *remote_flow;
drivers/net/tap/tap_intr.c +4 -3
@@ -68,9 +68,11 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev) }for (i =0 ; i < n; i++) {struct rx_queue *rxq = pmd->dev->data->rx_queues[i]; +int fd = process_private->fds[i];/* Skip queues that cannot request interrupts. */ -if (!rxq || process_private->rxq_fds[i] ==-1 ) { +if (!rxq || fd ==-1 ) { +/* Use invalid intr_vec[] index to disable entry. */ /* Use invalid intr_vec[] index to disable entry. */ if (rte_intr_vec_list_index_set (intr_handle, i,RTE_INTR_VEC_RXTX_OFFSET +RTE_MAX_RXTX_INTR_VEC_ID ))
@@ -80,8 +82,7 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev)if (rte_intr_vec_list_index_set (intr_handle, i,RTE_INTR_VEC_RXTX_OFFSET + count))return -rte_errno; -if (rte_intr_efds_index_set (intr_handle, count, - process_private->rxq_fds[i])) +if (rte_intr_efds_index_set (intr_handle, count, fd))return -rte_errno; count++; }
Signature · 1 line
2.43.0
PATCH v5 2/8 doc: fix the requirements and building of TAP flow
In reply to Stephen HemmingerThe build process for TAP eBPF RSS is now changed, so documentation needs to be updated.
Since kernel 4.19 is the oldest current LTS supported kernel, the TAP documentation can be simplified. Any complaints about flow not working means the kernel is out of scope of current DPDK.
--- doc/guides/linux_gsg/sys_reqs.rst | 3 + doc/guides/nics/tap.rst | 95 ++++++++----------------------- 2 files changed, 28 insertions(+), 70 deletions(-)
doc/guides/linux_gsg/sys_reqs.rst +3 -0
@@ -101,6 +101,9 @@ Running DPDK Applications To run a DPDK application, some customization may be required on the target machine. +.. _linux_gsg_kernel_version: + + System Software ~~~~~~~~~~~~~~~
doc/guides/nics/tap.rst +25 -70
125 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v5 3/8 net/tap: remove unused RSS hash types
In reply to Stephen HemmingerThe driver doesn't support these other hash types, and there is no reason to implement these in future.
--- drivers/net/tap/tap_rss.h | 6 ------ 1 file changed, 6 deletions(-)
drivers/net/tap/tap_rss.h +0 -6
@@ -21,12 +21,6 @@ enum hash_field {HASH_FIELD_IPV4_L3_L4 ,/* IPv4 src/dst addr + L4 src/dst ports */ HASH_FIELD_IPV6_L3 ,/* IPv6 src/dst addr */ HASH_FIELD_IPV6_L3_L4, /* IPv6 src/dst addr + L4 src/dst ports */ -HASH_FIELD_L2_SRC ,/* Ethernet src addr */ -HASH_FIELD_L2_DST ,/* Ethernet dst addr */ -HASH_FIELD_L3_SRC ,/* L3 src addr */ -HASH_FIELD_L3_DST ,/* L3 dst addr */ -HASH_FIELD_L4_SRC ,/* TCP/UDP src ports */ - HASH_FIELD_L4_DST, /* TCP/UDP dst ports */ }; struct rss_key {
Signature · 1 line
2.43.0
PATCH v5 4/8 net/tap: validate and setup parameters for BPF RSS
In reply to Stephen HemmingerThe flow RSS support via BPF was not using the key, or hash type parameters. Which is good because they were never properly setup.
Fix the setup and validate the flow parameters, the BPF side gets fixed later.
--- drivers/net/tap/tap_flow.c | 65 +++++++++++++++++++++++++++++++++++--- drivers/net/tap/tap_rss.h | 5 ++- 2 files changed, 62 insertions(+), 8 deletions(-)
drivers/net/tap/tap_flow.c +60 -5
@@ -11,9 +11,11 @@#include <rte_byteorder.h> #include <rte_jhash.h> +#include <rte_thash.h> #include <rte_random.h> #include <rte_malloc.h> #include <rte_eth_tap.h> +#include <tap_flow.h> #include <tap_autoconf.h> #include <tap_tcmsgs.h>
@@ -2062,6 +2064,21 @@ static int bpf_rss_key(enum bpf_rss_key_e cmd, __u32 *key_idx)return err; } + +/* Default RSS hash key also used by mlx devices */ +static const uint8_t rss_hash_default_key[] = { +0x2c ,0xc6 ,0x81 ,0xd1 , +0x5b ,0xdb ,0xf4 ,0xf7 , +0xfc ,0xa2 ,0x83 ,0x19 , +0xdb ,0x1a ,0x3e ,0x94 , +0x6b ,0x9e ,0x38 ,0xd9 , +0x2c ,0x9c ,0x03 ,0xd1 , +0xad ,0x99 ,0x44 ,0xa7 , +0xd9 ,0x56 ,0x3d ,0x59 , +0x06 ,0x3c ,0x25 ,0xf3 , +0xfc ,0x1f ,0xdc ,0x2a , +}; +/** * Add RSS hash calculations and queue selection *
@@ -2080,11 +2097,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,const struct rte_flow_action_rss *rss, struct rte_flow_error *error) { -/* 4096 is the maximum number of instructions for a BPF program */ + struct rss_key rss_entry = { }; +const uint8_t *key_in; +uint32_t hash_type =0 ;unsigned int i;int err; -struct rss_key rss_entry = { .hash_fields =0 , - .key_size =0 };/* Check supported RSS features */ if (rss->func !=RTE_ETH_HASH_FUNCTION_DEFAULT )
@@ -2096,6 +2113,41 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, (error,ENOTSUP ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL ,"a nonzero RSS encapsulation level is not supported" ); +if (rss->queue_num ==0 || rss->queue_num >=TAP_MAX_QUEUES ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL , +"invalid number of queues" ); + +/* allow RSS key_len 0 in case of NULL (default) RSS key. */ +if (rss->key_len ==0 ) { +if (rss->key !=NULL ) +return rte_flow_error_set (error,ENOTSUP , +RTE_FLOW_ERROR_TYPE_ACTION_CONF , + &rss->key_len,"RSS hash key length 0" ); + key_in = rss_hash_default_key; + }else { +if (rss->key_len !=TAP_RSS_HASH_KEY_SIZE ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"RSS hash invalid key length" ); +if (rss->key ==NULL ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"RSS hash key is NULL" ); + key_in = rss->key; + } + +if (rss->types &TAP_RSS_HF_MASK ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"RSS hash type not supported" ); + +if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV4_UDP |RTE_ETH_RSS_NONFRAG_IPV4_TCP )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV4_L3_L4 ); +else if (rss->types & (RTE_ETH_RSS_IPV4 |RTE_ETH_RSS_FRAG_IPV4 )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV4_L3 ); + +if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV6_UDP |RTE_ETH_RSS_NONFRAG_IPV6_TCP )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV6_L3_L4 ); +else if (rss->types & (RTE_ETH_RSS_IPV6 |RTE_ETH_RSS_FRAG_IPV6 |RTE_ETH_RSS_IPV6_EX )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV6_L3 ); +/* Get a new map key for a new RSS rule */ err =bpf_rss_key (KEY_CMD_GET , &flow->key_idx);if (err <0 ) {
@@ -2110,8 +2162,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, rss_entry.nb_queues = rss->queue_num;for (i =0 ; i < rss->queue_num; i++) rss_entry.queues[i] = rss->queue[i]; - rss_entry.hash_fields = - (1 <<HASH_FIELD_IPV4_L3_L4 ) | (1 <<HASH_FIELD_IPV6_L3_L4 ); + + rss_entry.hash_fields = hash_type; +rte_convert_rss_key ((const uint32_t *)key_in, (uint32_t *)rss_entry.key, +TAP_RSS_HASH_KEY_SIZE ); +/* Add this RSS entry to map */ err = tap_flow_bpf_update_rss_elem(pmd->map_fd,
drivers/net/tap/tap_rss.h +2 -3
@@ -24,11 +24,10 @@ enum hash_field { };struct rss_key { -__u8 key[128 ];__u32 hash_fields; -__u32 key_size; -__u32 queues[TAP_MAX_QUEUES ]; +__u8 key[TAP_RSS_HASH_KEY_SIZE ];__u32 nb_queues; +__u32 queues[TAP_MAX_QUEUES ]; } __attribute__((packed));#endif /* _TAP_RSS_H_ */
Signature · 1 line
2.43.0
PATCH v5 5/8 net/tap: stop "vendoring" linux bpf headers
In reply to Stephen HemmingerThe proper place for finding bpf structures and functions is in linux/bpf.h. The original version was trying to workaround the case where the build environment was running on old pre BPF version of Glibc, but the target environment had BPF. This is not a supportable build method, and not how rest of DPDK works.
Having own private (and divergent) version headers leads to future problems when BPF definitions evolve.
Since DPDK officially supports only LTS or later kernel there is no need for the #ifdef workarounds in the TAP flow code. Cloning headers leads to problems and no longer needed.
--- drivers/net/tap/bpf/bpf_extract.py | 1 - drivers/net/tap/tap_bpf.h | 121 ----------------------------- drivers/net/tap/tap_bpf_api.c | 20 +++-- drivers/net/tap/tap_flow.c | 89 --------------------- 4 files changed, 13 insertions(+), 218 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf.h
drivers/net/tap/bpf/bpf_extract.py +0 -1
@@ -65,7 +65,6 @@ def write_header(out, source): print(f' * Auto-generated from {source}', file=out) print(" * This not the original source file. Do NOT edit it.", file=out) print(" */\n", file=out) - print("#include <tap_bpf.h>", file=out) def main():
drivers/net/tap/tap_bpf.h deleted +0 -121
121 lines not on this page · raw message
drivers/net/tap/tap_bpf_api.c +13 -7
@@ -2,19 +2,19 @@* Copyright 2017 Mellanox Technologies, Ltd */ -#include <errno.h> -#include <string.h> #include <unistd.h> -#include <sys/queue.h> +#include <syscall.h> +#include <linux/bpf.h> -#include <rte_malloc.h> -#include <rte_eth_tap.h> #include <tap_flow.h> #include <tap_autoconf.h> -#include <tap_tcmsgs.h> -#include <tap_bpf.h> +#include <tap_bpf_insns.h> + +static int bpf_load (enum bpf_prog_type type,const struct bpf_insn *insns, +size_t insns_cnt,const char *license); +/** * Load BPF program (section cls_q) into the kernel and return a bpf fd *
@@ -89,7 +89,13 @@ static inline __u64 ptr_to_u64(const void *ptr)static inline int sys_bpf (enum bpf_cmd cmd,union bpf_attr *attr,unsigned int size) { +#ifdef __NR_bpfreturn syscall (__NR_bpf, cmd, attr, size); +#else +TAP_LOG (ERR ,"No bpf syscall, kernel headers too old?\n" ); + errno =ENOSYS ; +return -1 ; +#endif }/**
drivers/net/tap/tap_flow.c +0 -89
95 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v5 6/8 net/tap: rewrite the RSS BPF program
In reply to Stephen HemmingerRewrite the BPF program used to do queue based RSS. Important changes:
- uses newer BPF map format BTF
- accepts key as parameter rather than constant default
- can do L3 or L4 hashing
- supports IPv4 options
- supports IPv6 extension headers
- restructured for readability
The usage of BPF is different as well:
- the incoming configuration is looked up based on class parameters rather than patching the BPF.
- the resulting queue is placed in skb rather than requiring a second pass through classifier step.
Note: This version only works with later patch to enable it on the DPDK driver side. It is submitted as an incremental patch to allow for easier review. Bisection still works because the old instruction are still present for now.
--- .gitignore | 3 - drivers/net/tap/bpf/Makefile | 19 -- drivers/net/tap/bpf/README | 38 ++++ drivers/net/tap/bpf/bpf_api.h | 276 -------------------------- drivers/net/tap/bpf/bpf_elf.h | 53 ----- drivers/net/tap/bpf/bpf_extract.py | 85 -------- drivers/net/tap/bpf/meson.build | 81 ++++++++ drivers/net/tap/bpf/tap_bpf_program.c | 255 ------------------------ drivers/net/tap/bpf/tap_rss.c | 264 ++++++++++++++++++++++++ 9 files changed, 383 insertions(+), 691 deletions(-) delete mode 100644 drivers/net/tap/bpf/Makefile create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py create mode 100644 drivers/net/tap/bpf/meson.build delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c
.gitignore +0 -3
@@ -36,9 +36,6 @@ TAGS # ignore python bytecode files *.pyc -# ignore BPF programs -drivers/net/tap/bpf/tap_bpf_program.o - # DTS results dts/output
drivers/net/tap/bpf/Makefile deleted +0 -19
@@ -1,19 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# This file is not built as part of normal DPDK build. -# It is used to generate the eBPF code for TAP RSS. - -CLANG=clang -CLANG_OPTS=-O2 -TARGET=../tap_bpf_insns.h - -all: $(TARGET) - -clean: - rm tap_bpf_program.o $(TARGET) - -tap_bpf_program.o: tap_bpf_program.c - $(CLANG) $(CLANG_OPTS) -emit-llvm -c $< -o - | \ - llc -march=bpf -filetype=obj -o $@ - -$(TARGET): tap_bpf_program.o - python3 bpf_extract.py -stap_bpf_program.c -o $@ $<
drivers/net/tap/bpf/README new file +38 -0
@@ -0,0 +1,38 @@ +This is the BPF program used to implement the RSS across queues flow action. +The program is loaded when first RSS flow rule is created and is never unloaded. + +Each flow rule creates a unique key (handle) and this is used as the key +for finding the RSS information for that flow rule. + +This version is built the BPF Compile Once — Run Everywhere (CO-RE) +framework and uses libbpf and bpftool. + +Limitations +----------- +- requires libbpf to run +- rebuilding the BPF requires Clang and bpftool. + Some older versions of Ubuntu do not have working bpftool package. + Need a version of Clang that can compile to BPF. +- only standard Toeplitz hash with standard 40 byte key is supported +- the number of flow rules using RSS is limited to 32 + +Building +-------- +During the DPDK build process the meson build file checks that +libbpf, bpftool, and clang are not available. If everything is +there then BPF RSS is enabled. + +1. Using clang to compile tap_rss.c the tap_rss.bpf.o file. + +2. Using bpftool generate a skeleton header file tap_rss.skel.h from tap_rss.bpf.o. + This skeleton header is an large byte array which contains the + BPF binary and wrappers to load and use it. + +3. The tap flow code then compiles that BPF byte array into the PMD object. + +4. When needed the BPF array is loaded by libbpf. + +References +---------- +BPF and XDP reference guide +https://docs.cilium.io/en/latest/bpf/progtypes/
drivers/net/tap/bpf/bpf_api.h deleted +0 -276
276 lines not on this page · raw message
drivers/net/tap/bpf/bpf_elf.h deleted +0 -53
53 lines not on this page · raw message
drivers/net/tap/bpf/bpf_extract.py deleted +0 -85
85 lines not on this page · raw message
drivers/net/tap/bpf/meson.build new file +81 -0
81 lines not on this page · raw message
drivers/net/tap/bpf/tap_bpf_program.c deleted +0 -255
255 lines not on this page · raw message
drivers/net/tap/bpf/tap_rss.c new file +264 -0
264 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v5 7/8 net/tap: use libbpf to load new BPF program
In reply to Stephen HemmingerThere were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.
Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.
The new BPF program only needs a single action.
No need for action and re-classification step.
It alsow fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.
--- drivers/net/tap/bpf/meson.build | 14 +- drivers/net/tap/meson.build | 29 +-- drivers/net/tap/rte_eth_tap.c | 2 + drivers/net/tap/rte_eth_tap.h | 9 +- drivers/net/tap/tap_flow.c | 410 +++++++------------------------- drivers/net/tap/tap_flow.h | 16 +- drivers/net/tap/tap_rss.h | 10 +- drivers/net/tap/tap_tcmsgs.h | 4 +- 8 files changed, 127 insertions(+), 367 deletions(-)
drivers/net/tap/bpf/meson.build +12 -2
@@ -3,15 +3,24 @@ enable_tap_rss = false +# Loading BPF requires libbpf libbpf = dependency('libbpf', required: false, method: 'pkg-config') if not libbpf.found() message('net/tap: no RSS support missing libbpf') subdir_done() endif +# Making skeleton needs bpftool # Debian install this in /usr/sbin which is not in $PATH -bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false, version: '>= 5.6.0') -if not bpftool.found() +bpftool_supports_skel = false +bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false) +if bpftool.found() + # Some Ubuntu has non-functional bpftool + bpftool_supports_skel = run_command(bpftool, 'gen', 'help', + check:false).returncode() == 0 +endif + +if not bpftool_supports_skel message('net/tap: no RSS support missing bpftool') subdir_done() endif
@@ -42,6 +51,7 @@ clang_flags = [ '-O2', '-Wall', '-Wextra', + max_queues, '-target', 'bpf', '-g',
drivers/net/tap/meson.build +9 -20
@@ -7,33 +7,22 @@ if not is_linux endif sources = files( 'rte_eth_tap.c', - 'tap_bpf_api.c', 'tap_flow.c', 'tap_intr.c', 'tap_netlink.c', 'tap_tcmsgs.c', ) -deps = ['bus_vdev', 'gso', 'hash'] +max_queues = '-DTAP_MAX_QUEUES=16' +cflags += max_queues -cflags += '-DTAP_MAX_QUEUES=8' +subdir('bpf') +if enable_tap_rss + cflags += '-DHAVE_BPF_RSS' + ext_deps += libbpf + sources += tap_rss_skel_h +endif -# input array for meson symbol search: -# [ "MACRO to define if found", "header for the search", -# "enum/define", "symbol to search" ] -# -args = [ - [ 'HAVE_TC_FLOWER', 'linux/pkt_cls.h', 'TCA_FLOWER_UNSPEC' ], - [ 'HAVE_TC_VLAN_ID', 'linux/pkt_cls.h', 'TCA_FLOWER_KEY_VLAN_PRIO' ], - [ 'HAVE_TC_BPF', 'linux/pkt_cls.h', 'TCA_BPF_UNSPEC' ], - [ 'HAVE_TC_BPF_FD', 'linux/pkt_cls.h', 'TCA_BPF_FD' ], - [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ], - [ 'HAVE_TC_ACT_BPF_FD', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_FD' ], -] -config = configuration_data() -foreach arg:args - config.set(arg[0], cc.has_header_symbol(arg[1], arg[2])) -endforeach -configure_file(output : 'tap_autoconf.h', configuration : config) +deps = ['bus_vdev', 'gso', 'hash'] require_iova_in_mbuf = false
drivers/net/tap/rte_eth_tap.c +2 -0
@@ -1129,6 +1129,7 @@ tap_dev_close(struct rte_eth_dev *dev)tap_flow_implicit_flush (internals,NULL );tap_nl_final (internals->nlsk_fd); internals->nlsk_fd =-1 ; +tap_flow_bpf_destroy (internals); }for (i =0 ; i <RTE_PMD_TAP_MAX_QUEUES ; i++) {
@@ -1941,6 +1942,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,strlcpy (pmd->name, tap_name,sizeof (pmd->name)); pmd->type = type; pmd->ka_fd =-1 ; + pmd->rss =NULL ; pmd->nlsk_fd =-1 ; pmd->gso_ctx_mp =NULL ;
drivers/net/tap/rte_eth_tap.h +4 -5
@@ -79,12 +79,11 @@ struct pmd_internals {int flow_isolate;/* 1 if flow isolation is enabled */ int flower_support;/* 1 if kernel supports, else 0 */ int flower_vlan_support;/* 1 if kernel supports, else 0 */ -int rss_enabled;/* 1 if RSS is enabled, else 0 */ int persist;/* 1 if keep link up, else 0 */ -/* implicit rules set when RSS is enabled */ -int map_fd;/* BPF RSS map fd */ -int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */ - LIST_HEAD(tap_rss_flows, rte_flow) rss_flows; + +struct tap_rss *rss;/* BPF program */ +uint16_t bpf_flowid;/* next BPF class id */ + LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */ LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
drivers/net/tap/tap_flow.c +89 -321
538 lines not on this page · raw message
drivers/net/tap/tap_flow.h +6 -10
@@ -9,7 +9,11 @@#include <rte_flow.h> #include <rte_flow_driver.h> #include <rte_eth_tap.h> -#include <tap_autoconf.h> + +/** +* Mask of unsupported RSS types +*/ +#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP))/** * In TC, priority 0 means we require the kernel to allocate one for us.
@@ -41,10 +45,6 @@ enum implicit_rule_index { TAP_REMOTE_MAX_IDX, }; -enum bpf_fd_idx { -SEC_L3_L4 , -SEC_MAX , -};int tap_dev_flow_ops_get (struct rte_eth_dev *dev,const struct rte_flow_ops **ops);
@@ -57,10 +57,6 @@ int tap_flow_implicit_destroy(struct pmd_internals *pmd,int tap_flow_implicit_flush (struct pmd_internals *pmd,struct rte_flow_error *error); -int tap_flow_bpf_cls_q (__u32 queue_idx); -int tap_flow_bpf_calc_l3_l4_hash (__u32 key_idx,int map_fd); -int tap_flow_bpf_rss_map_create (unsigned int key_size,unsigned int value_size, -unsigned int max_entries); -int tap_flow_bpf_update_rss_elem (int fd,void *key,void *value); +void tap_flow_bpf_destroy (struct pmd_internals *pmd);#endif /* _TAP_FLOW_H_ */
drivers/net/tap/tap_rss.h +4 -6
@@ -5,16 +5,14 @@#ifndef _TAP_RSS_H_#define _TAP_RSS_H_ -#ifndef TAP_MAX_QUEUES -#define TAP_MAX_QUEUES 16 +/* Size of the map from BPF classid to queue table */ +#ifndef TAP_RSS_MAX +#define TAP_RSS_MAX 32#endif -/* Fixed RSS hash key size in bytes. */ +/* Standard Toeplitz hash key size */ #define TAP_RSS_HASH_KEY_SIZE 40 -/* Supported RSS */ -#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP)) -/* hashed fields for RSS */ enum hash_field { HASH_FIELD_IPV4_L3, /* IPv4 src/dst addr */
drivers/net/tap/tap_tcmsgs.h +1 -3
@@ -6,7 +6,6 @@#ifndef _TAP_TCMSGS_H_#define _TAP_TCMSGS_H_ -#include <tap_autoconf.h> #include <linux/if_ether.h> #include <linux/rtnetlink.h> #include <linux/pkt_sched.h>
@@ -14,9 +13,8 @@#include <linux/tc_act/tc_mirred.h> #include <linux/tc_act/tc_gact.h> #include <linux/tc_act/tc_skbedit.h> -#ifdef HAVE_TC_ACT_BPF #include <linux/tc_act/tc_bpf.h> -#endif +#include <inttypes.h> #include <rte_ether.h>
Signature · 1 line
2.43.0
Re: [PATCH v5 7/8] net/tap: use libbpf to load new BPF program
Quoted 46 lines · Stephen Hemminger
There were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.
Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.The new BPF program only needs a single action.
No need for action and re-classification step.It alsow fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.Signed-off-by Stephen Hemminger <[email protected]>--- drivers/net/tap/bpf/meson.build | 14 +- drivers/net/tap/meson.build | 29 +-- drivers/net/tap/rte_eth_tap.c | 2 + drivers/net/tap/rte_eth_tap.h | 9 +- drivers/net/tap/tap_flow.c | 410 +++++++------------------------- drivers/net/tap/tap_flow.h | 16 +- drivers/net/tap/tap_rss.h | 10 +- drivers/net/tap/tap_tcmsgs.h | 4 +- 8 files changed, 127 insertions(+), 367 deletions(-)drivers/net/tap/bpf/meson.build +2
-0@@ -3,15 +3,24 @@ enable_tap_rss = false +# Loading BPF requires libbpf libbpf = dependency('libbpf', required: false, method: 'pkg-config') if not libbpf.found() message('net/tap: no RSS support missing libbpf') subdir_done() endif +# Making skeleton needs bpftool
drivers/net/tap/bpf/meson.build line 21
Quoted 10 lines
drivers/net/tap/bpf/meson.build +7
-2# Debian install this in /usr/sbin which is not in $PATH -bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false, version: '>= 5.6.0') -if not bpftool.found() +bpftool_supports_skel = false +bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false) +if bpftool.found() + # Some Ubuntu has non-functional bpftool + bpftool_supports_skel = run_command(bpftool, 'gen', 'help', + check:false).returncode() == 0 +endif
Using bpftool to generate the header at build time is a bit icky, because it will look at sysfs on the build system, which is from the running kernel. But a build system's kernel might be some ancient LTS, and even be a completely different kconfig/build/distro from the actual runtime one.
We have ran in the same problem in systemd recently, and the solution is to have distros publish the vmlinux.h together with the kernel image/headers, that way we can rely on the fact that by build-depending on the right kernel package we get exactly the generated vmlinux.h that we want. This has already happened in Centos, Debian, Fedora and Arch, and I am trying to get Ubuntu onboard too.
The annoying thing is that every distro packages differently, so the path needs to be configurable with a meson option.
Feel free to pilfer the systemd meson glue:
https://github.com/systemd/systemd/pull/26826/commits/d917079e7e320aa281fc4ad6f8073b0814b9cb13
It's of course file to go to the runtime kernel if no vmlinux.h is specified, as a fallback, which is going to be useful for developers machines.
Signature · 2 lines
Kind regards, Luca Boccassi
Re: [PATCH v5 7/8] net/tap: use libbpf to load new BPF program
Quoted 55 lines · On Wed, 03 Apr 2024 12:50:35 +0100 Luca Boccassi <[email protected]> wrote:
Quoted 54 lines · Stephen Hemminger
There were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.
Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.The new BPF program only needs a single action.
No need for action and re-classification step.It alsow fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.Signed-off-by Stephen Hemminger <[email protected]>--- drivers/net/tap/bpf/meson.build | 14 +- drivers/net/tap/meson.build | 29 +-- drivers/net/tap/rte_eth_tap.c | 2 + drivers/net/tap/rte_eth_tap.h | 9 +- drivers/net/tap/tap_flow.c | 410 +++++++------------------------- drivers/net/tap/tap_flow.h | 16 +- drivers/net/tap/tap_rss.h | 10 +- drivers/net/tap/tap_tcmsgs.h | 4 +- 8 files changed, 127 insertions(+), 367 deletions(-)drivers/net/tap/bpf/meson.build +7
-2@@ -3,15 +3,24 @@ enable_tap_rss = false +# Loading BPF requires libbpf libbpf = dependency('libbpf', required: false, method: 'pkg-config') if not libbpf.found() message('net/tap: no RSS support missing libbpf') subdir_done() endif +# Making skeleton needs bpftool # Debian install this in /usr/sbin which is not in $PATH -bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false, version: '>= 5.6.0') -if not bpftool.found() +bpftool_supports_skel = false +bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false) +if bpftool.found() + # Some Ubuntu has non-functional bpftool + bpftool_supports_skel = run_command(bpftool, 'gen', 'help',
Quoted 8 lines
drivers/net/tap/bpf/meson.build line 21
Quoted 2 lines
drivers/net/tap/bpf/meson.build +2
-0+ check:false).returncode() == 0 +endifUsing bpftool to generate the header at build time is a bit icky, because it will look at sysfs on the build system, which is from the running kernel. But a build system's kernel might be some ancient LTS, and even be a completely different kconfig/build/distro from the actual runtime one.
I wish there was a better way to get bpf compiled to an array to load. The other alternative is to embed the object but then the ickiness of decoding ELF headers ends up in the driver.
This method seems to be the BPF way now.
Quoted 7 lines
We have ran in the same problem in systemd recently, and the solution is to have distros publish the
vmlinux.htogether with the kernel image/headers, that way we can rely on the fact that by build-depending on the right kernel package we get exactly the generatedvmlinux.hthat we want. This has already happened in Centos, Debian, Fedora and Arch, and I am trying to get Ubuntu onboard too.
Not sure how much it matters for the TAP BPF bits. Unlike other kernel BPF this program only really depends on layout of skb, and is not using system call hooks. So vmlinux.h is not referenced directly. But if layout of skb changes, then things would break.
Quoted 11 lines
The annoying thing is that every distro packages differently, so the path needs to be configurable with a meson option.
Feel free to pilfer the systemd meson glue:
https://github.com/systemd/systemd/pull/26826/commits/d917079e7e320aa281fc4ad6f8073b0814b9cb13
It's of course file to go to the runtime kernel if no
vmlinux.his specified, as a fallback, which is going to be useful for developers machines.
Re: [PATCH v5 7/8] net/tap: use libbpf to load new BPF program
In reply to Luca BoccassiQuoted 5 lines · On Wed, 03 Apr 2024 12:50:35 +0100 Luca Boccassi <[email protected]> wrote:
Using bpftool to generate the header at build time is a bit icky, because it will look at sysfs on the build system, which is from the running kernel. But a build system's kernel might be some ancient LTS, and even be a completely different kconfig/build/distro from the actual runtime one.
One other option would be to ship a pre-built skeleton file.
Which is what the method the old code did.
But that creates an implied dependency on the developers machine build environment.
Re: [PATCH v5 7/8] net/tap: use libbpf to load new BPF program
Quoted 10 lines · Stephen Hemminger
Quoted 5 lines · On Wed, 03 Apr 2024 12:50:35 +0100 Luca Boccassi <[email protected]> wrote:
Using bpftool to generate the header at build time is a bit icky, because it will look at sysfs on the build system, which is from the running kernel. But a build system's kernel might be some ancient LTS, and even be a completely different kconfig/build/distro from the actual runtime one.
Quoted 3 lines
One other option would be to ship a pre-built skeleton file.
Which is what the method the old code did.
But that creates an implied dependency on the developers machine build environment.
That's what the distro-provided vmlinux.h should help with - by #include'ing that, it should be possible to build a co-re bpf program, no other artifacts needed. You can try it out locally by generating it from the local running kernel on your dev machine:
bpftool btf dump file /sys/kernel/btf/vmlinux format c > vmlinux.h
Re: [PATCH v5 7/8] net/tap: use libbpf to load new BPF program
Quoted 16 lines · On Wed, 3 Apr 2024 22:19:20 +0100 Luca Boccassi <[email protected]> wrote:
Quoted 10 lines · Stephen Hemminger
Quoted 5 lines · On Wed, 03 Apr 2024 12:50:35 +0100 Luca Boccassi <[email protected]> wrote:
Using bpftool to generate the header at build time is a bit icky, because it will look at sysfs on the build system, which is from the running kernel. But a build system's kernel might be some ancient LTS, and even be a completely different kconfig/build/distro from the actual runtime one.
Quoted 3 lines
One other option would be to ship a pre-built skeleton file.
Which is what the method the old code did.
But that creates an implied dependency on the developers machine build environment.
Quoted 6 lines
That's what the distro-provided
vmlinux.hshould help with - by #include'ing that, it should be possible to build a co-re bpf program, no other artifacts needed. You can try it out locally by generating it from the local running kernel on your dev machine:bpftool btf dump file
/sys/kernel/btf/vmlinuxformat c >vmlinux.h
Not all distros are providing vmlinux.h.
And some like Ubuntu haven't figured out how to package bpftool and libbpf correctly.
Re: [PATCH v5 7/8] net/tap: use libbpf to load new BPF program
Quoted 25 lines · Stephen Hemminger
Quoted 21 lines · On Wed, 3 Apr 2024 22:19:20 +0100 Luca Boccassi <[email protected]> wrote:
Quoted 10 lines · Stephen Hemminger
Quoted 5 lines · On Wed, 03 Apr 2024 12:50:35 +0100 Luca Boccassi <[email protected]> wrote:
Using bpftool to generate the header at build time is a bit icky, because it will look at sysfs on the build system, which is from the running kernel. But a build system's kernel might be some ancient LTS, and even be a completely different kconfig/build/distro from the actual runtime one.
Quoted 3 lines
One other option would be to ship a pre-built skeleton file.
Which is what the method the old code did.
But that creates an implied dependency on the developers machine build environment.That's what the distro-provided
vmlinux.hshould help with - by #include'ing that, it should be possible to build a co-re bpf program, no other artifacts needed. You can try it out locally by generating it from the local running kernel on your dev machine:
Quoted 4 lines
Quoted 1 line
bpftool btf dump file
/sys/kernel/btf/vmlinuxformat c >vmlinux.hNot all distros are providing
vmlinux.h.
And some like Ubuntu haven't figured out how to package bpftool and libbpf correctly.
Yes and for those the usual pattern is a fallback to generate at build time, if no pre-prepared vmlinux.h is configured
Re: [PATCH v5 7/8] net/tap: use libbpf to load new BPF program
Quoted 27 lines · On Thu, 4 Apr 2024 01:49:56 +0100 Luca Boccassi <[email protected]> wrote:
Quoted 25 lines · Stephen Hemminger
Quoted 21 lines · On Wed, 3 Apr 2024 22:19:20 +0100 Luca Boccassi <[email protected]> wrote:
Quoted 10 lines · Stephen Hemminger
Quoted 5 lines · On Wed, 03 Apr 2024 12:50:35 +0100 Luca Boccassi <[email protected]> wrote:
Using bpftool to generate the header at build time is a bit icky, because it will look at sysfs on the build system, which is from the running kernel. But a build system's kernel might be some ancient LTS, and even be a completely different kconfig/build/distro from the actual runtime one.
Quoted 3 lines
One other option would be to ship a pre-built skeleton file.
Which is what the method the old code did.
But that creates an implied dependency on the developers machine build environment.That's what the distro-provided
vmlinux.hshould help with - by #include'ing that, it should be possible to build a co-re bpf program, no other artifacts needed. You can try it out locally by generating it from the local running kernel on your dev machine:
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
bpftool btf dump file
/sys/kernel/btf/vmlinuxformat c >vmlinux.hNot all distros are providing
vmlinux.h.
And some like Ubuntu haven't figured out how to package bpftool and libbpf correctly.Yes and for those the usual pattern is a fallback to generate at build time, if no pre-prepared
vmlinux.his configured
Looks like vmlinux.h is not setup to handle tc programs.
If vmlinux.h is included, it supersedes other kernel headers (ok). But is missing some other things like IPv6 options, ether types, and TC actions. To use it requires copy pasting from other headers to fill in the missing pieces. Thats a mess.
This little program only refers to skb and the fields that are problematic are protocol, mark, and queue_mapping.
Re: [PATCH v5 7/8] net/tap: use libbpf to load new BPF program
Quoted 41 lines · Stephen Hemminger
Quoted 27 lines · On Thu, 4 Apr 2024 01:49:56 +0100 Luca Boccassi <[email protected]> wrote:
Quoted 25 lines · Stephen Hemminger
Quoted 21 lines · On Wed, 3 Apr 2024 22:19:20 +0100 Luca Boccassi <[email protected]> wrote:
Quoted 10 lines · Stephen Hemminger
Quoted 5 lines · On Wed, 03 Apr 2024 12:50:35 +0100 Luca Boccassi <[email protected]> wrote:
Using bpftool to generate the header at build time is a bit icky, because it will look at sysfs on the build system, which is from the running kernel. But a build system's kernel might be some ancient LTS, and even be a completely different kconfig/build/distro from the actual runtime one.
Quoted 3 lines
One other option would be to ship a pre-built skeleton file.
Which is what the method the old code did.
But that creates an implied dependency on the developers machine build environment.That's what the distro-provided
vmlinux.hshould help with - by #include'ing that, it should be possible to build a co-re bpf program, no other artifacts needed. You can try it out locally by generating it from the local running kernel on your dev machine:Quoted 7 lines
Quoted 4 lines
Quoted 1 line
bpftool btf dump file
/sys/kernel/btf/vmlinuxformat c >vmlinux.hNot all distros are providing
vmlinux.h.
And some like Ubuntu haven't figured out how to package bpftool and libbpf correctly.Yes and for those the usual pattern is a fallback to generate at build time, if no pre-prepared
vmlinux.his configuredLooks like
vmlinux.his not setup to handle tc programs.
Quoted 7 lines
If
vmlinux.his included, it supersedes other kernel headers (ok). But is missing some other things like IPv6 options, ether types, and TC actions. To use it requires copy pasting from other headers to fill in the missing pieces. Thats a mess.This little program only refers to skb and the fields that are problematic are protocol, mark, and
queue_mapping.
That's not good, could you please report that to the BPF folks? Pretty sure it should get fixed in bpftool?
Re: [PATCH v5 7/8] net/tap: use libbpf to load new BPF program
In reply to Luca BoccassiQuoted 16 lines · On Wed, 3 Apr 2024 22:19:20 +0100 Luca Boccassi <[email protected]> wrote:
Quoted 10 lines · Stephen Hemminger
Quoted 5 lines · On Wed, 03 Apr 2024 12:50:35 +0100 Luca Boccassi <[email protected]> wrote:
Using bpftool to generate the header at build time is a bit icky, because it will look at sysfs on the build system, which is from the running kernel. But a build system's kernel might be some ancient LTS, and even be a completely different kconfig/build/distro from the actual runtime one.
Quoted 3 lines
One other option would be to ship a pre-built skeleton file.
Which is what the method the old code did.
But that creates an implied dependency on the developers machine build environment.
Quoted 6 lines
That's what the distro-provided
vmlinux.hshould help with - by #include'ing that, it should be possible to build a co-re bpf program, no other artifacts needed. You can try it out locally by generating it from the local running kernel on your dev machine:bpftool btf dump file
/sys/kernel/btf/vmlinuxformat c >vmlinux.h
What about Ubuntu with borked installation of bpftool?
Re: [PATCH v5 7/8] net/tap: use libbpf to load new BPF program
Quoted 20 lines · Stephen Hemminger
Quoted 16 lines · On Wed, 3 Apr 2024 22:19:20 +0100 Luca Boccassi <[email protected]> wrote:
Quoted 13 lines · Stephen Hemminger
Quoted 5 lines · On Wed, 03 Apr 2024 12:50:35 +0100 Luca Boccassi <[email protected]> wrote:
Using bpftool to generate the header at build time is a bit icky, because it will look at sysfs on the build system, which is from the running kernel. But a build system's kernel might be some ancient LTS, and even be a completely different kconfig/build/distro from the actual runtime one.
One other option would be to ship a pre-built skeleton file.
Which is what the method the old code did.
But that creates an implied dependency on the developers machine build environment.
Quoted 8 lines
Quoted 6 lines
That's what the distro-provided
vmlinux.hshould help with - by #include'ing that, it should be possible to build a co-re bpf program, no other artifacts needed. You can try it out locally by generating it from the local running kernel on your dev machine:bpftool btf dump file
/sys/kernel/btf/vmlinuxformat c >vmlinux.hWhat about Ubuntu with borked installation of bpftool?
Yeah that's a bit confusing, the way to do it is to install linux-tools-generic and then here's logic to find the right one:
https://git.launchpad.net/ubuntu/+source/xdp-tools/tree/debian/rules#n34
But I wouldn't bother with it in upstream projects, let the integrators deal with it
PATCH v5 8/8 net/tap: remove no longer used files
In reply to Stephen HemmingerThe BPF api was replaced by use of libbpf.
And the BPF instruction header was replaced by the skeleton.
--- drivers/net/tap/tap_bpf_api.c | 196 ---- drivers/net/tap/tap_bpf_insns.h | 1743 ------------------------------- 2 files changed, 1939 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h
drivers/net/tap/tap_bpf_api.c deleted +0 -196
@@ -1,196 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright 2017 Mellanox Technologies, Ltd -*/ - -#include <unistd.h> -#include <syscall.h> -#include <linux/bpf.h> - -#include <tap_flow.h> -#include <tap_autoconf.h> - -#include <tap_bpf_insns.h> - - -static int bpf_load (enum bpf_prog_type type,const struct bpf_insn *insns, -size_t insns_cnt,const char *license); - -/** -* Load BPF program (section cls_q) into the kernel and return a bpf fd -* -* @param queue_idx -* Queue index matching packet cb -* -* @return -* -1 if the BPF program couldn't be loaded. An fd (int) otherwise. -*/ -int tap_flow_bpf_cls_q (__u32 queue_idx) -{ - cls_q_insns[1 ].imm = queue_idx; - -return bpf_load (BPF_PROG_TYPE_SCHED_CLS , - (struct bpf_insn *)cls_q_insns, -RTE_DIM (cls_q_insns), -"Dual BSD/GPL" ); -} - -/** -* Load BPF program (section l3_l4) into the kernel and return a bpf fd. -* -* @param[in] key_idx -* RSS MAP key index -* -* @param[in] map_fd -* BPF RSS map file descriptor -* -* @return -* -1 if the BPF program couldn't be loaded. An fd (int) otherwise. -*/ -int tap_flow_bpf_calc_l3_l4_hash (__u32 key_idx,int map_fd) -{ - l3_l4_hash_insns[4 ].imm = key_idx; - l3_l4_hash_insns[9 ].imm = map_fd; - -return bpf_load (BPF_PROG_TYPE_SCHED_ACT , - (struct bpf_insn *)l3_l4_hash_insns, -RTE_DIM (l3_l4_hash_insns), -"Dual BSD/GPL" ); -} - -/** -* Helper function to convert a pointer to unsigned 64 bits -* -* @param[in] ptr -* pointer to address -* -* @return -* 64 bit unsigned long type of pointer address -*/ -static inline __u64 ptr_to_u64 (const void *ptr) -{ -return (__u64 )(unsigned long )ptr; -} - -/** -* Call BPF system call -* -* @param[in] cmd -* BPF command for program loading, map creation, map entry update, etc -* -* @param[in] attr -* System call attributes relevant to system call command -* -* @param[in] size -* size of attr parameter -* -* @return -* -1 if BPF system call failed, 0 otherwise -*/ -static inline int sys_bpf (enum bpf_cmd cmd,union bpf_attr *attr, -unsigned int size) -{ -#ifdef __NR_bpf -return syscall (__NR_bpf, cmd, attr, size); -#else -TAP_LOG (ERR ,"No bpf syscall, kernel headers too old?\n" ); - errno =ENOSYS ; -return -1 ; -#endif -} - -/** -* Load BPF instructions to kernel -* -* @param[in] type -* BPF program type: classifier or action -* -* @param[in] insns -* Array of BPF instructions (equivalent to BPF instructions) -* -* @param[in] insns_cnt -* Number of BPF instructions (size of array) -* -* @param[in] license -* License string that must be acknowledged by the kernel -* -* @return -* -1 if the BPF program couldn't be loaded, fd (file descriptor) otherwise -*/ -static int bpf_load (enum bpf_prog_type type, -const struct bpf_insn *insns, -size_t insns_cnt, -const char *license) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - attr.prog_type = type; - attr.insn_cnt = (__u32 )insns_cnt; - attr.insns =ptr_to_u64 (insns); - attr.license =ptr_to_u64 (license); - attr.log_buf =ptr_to_u64 (NULL ); - attr.log_level =0 ; - attr.kern_version =0 ; - -return sys_bpf (BPF_PROG_LOAD , &attr,sizeof (attr)); -} - -/** -* Create BPF map for RSS rules -* -* @param[in] key_size -* map RSS key size -* -* @param[in] value_size -* Map RSS value size -* -* @param[in] max_entries -* Map max number of RSS entries (limit on max RSS rules) -* -* @return -* -1 if BPF map couldn't be created, map fd otherwise -*/ -int tap_flow_bpf_rss_map_create (unsigned int key_size, -unsigned int value_size, -unsigned int max_entries) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - attr.map_type =BPF_MAP_TYPE_HASH ; - attr.key_size = key_size; - attr.value_size = value_size; - attr.max_entries = max_entries; - -return sys_bpf (BPF_MAP_CREATE , &attr,sizeof (attr)); -} - -/** -* Update RSS entry in BPF map -* -* @param[in] fd -* RSS map fd -* -* @param[in] key -* Pointer to RSS key whose entry is updated -* -* @param[in] value -* Pointer to RSS new updated value -* -* @return -* -1 if RSS entry failed to be updated, 0 otherwise -*/ -int tap_flow_bpf_update_rss_elem (int fd,void *key,void *value) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - - attr.map_type =BPF_MAP_TYPE_HASH ; - attr.map_fd = fd; - attr.key =ptr_to_u64 (key); - attr.value =ptr_to_u64 (value); - attr.flags =BPF_ANY ; - -return sys_bpf (BPF_MAP_UPDATE_ELEM , &attr,sizeof (attr)); -}
drivers/net/tap/tap_bpf_insns.h deleted +0 -1743
1,743 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v5 8/8] net/tap: remove no longer used files
Quoted 4 lines · On Tue, 2 Apr 2024 10:12:40 -0700 Stephen Hemminger…
The BPF api was replaced by use of libbpf.
And the BPF instruction header was replaced by the skeleton.Signed-off-by Stephen Hemminger <[email protected]>
The build for this fails on CI because CI is testing on CentOs7. RHEL/CentOs 7 is no longer supported and should be dropped. Official end of life for CentOS 7 is 30 Jun 2024 which will be before next DPDK release.
v6 cover net/tap: cleanup and fix BPF flow support
In reply to Stephen HemmingerThe support of doing RSS for rte_flow_action was a cool idea but it has been broken for several releases of DPDK as the kernel and BPF infrastructure changed.
This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF toolchain.
The result should be easier to read and maintain.
v6 - don't build if missing TC flower, a kernel that
old is not supported. But somebody will try.
Use BPF CO:RE attribute wrapper to avoid kernel header skew.
Stephen Hemminger (8):
net/tap: do not duplicate fd's
doc: fix the requirements and building of TAP flow net/tap: remove unused fields
net/tap: validate and setup parameters for BPF RSS net/tap: stop "vendoring" linux bpf headers net/tap: rewrite the RSS BPF program net/tap: use libbpf to load new BPF program net/tap: remove no longer used files
.gitignore | 3 - doc/guides/linux_gsg/sys_reqs.rst | 3 + doc/guides/nics/tap.rst | 95 +- drivers/net/tap/bpf/Makefile | 19 - drivers/net/tap/bpf/README | 38 + drivers/net/tap/bpf/bpf_api.h | 276 ---- drivers/net/tap/bpf/bpf_elf.h | 53 - drivers/net/tap/bpf/bpf_extract.py | 86 -- drivers/net/tap/bpf/meson.build | 107 ++ drivers/net/tap/bpf/tap_bpf_program.c | 255 ---- drivers/net/tap/bpf/tap_rss.c | 267 ++++ drivers/net/tap/meson.build | 39 +- drivers/net/tap/rte_eth_tap.c | 199 ++- drivers/net/tap/rte_eth_tap.h | 17 +- drivers/net/tap/tap_bpf.h | 121 -- drivers/net/tap/tap_bpf_api.c | 190 --- drivers/net/tap/tap_bpf_insns.h | 1743 ------------------------- drivers/net/tap/tap_flow.c | 549 ++------ drivers/net/tap/tap_flow.h | 17 +- drivers/net/tap/tap_intr.c | 7 +- drivers/net/tap/tap_rss.h | 21 +- drivers/net/tap/tap_tcmsgs.h | 4 +- 22 files changed, 710 insertions(+), 3399 deletions(-) delete mode 100644 drivers/net/tap/bpf/Makefile create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py create mode 100644 drivers/net/tap/bpf/meson.build delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c delete mode 100644 drivers/net/tap/tap_bpf.h delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h
Signature · 1 line
2.43.0
PATCH v6 1/8 net/tap: do not duplicate fd's
The TAP device can use same file descriptopr for both rx and tx queues. This allows up to 8 queues (versus 4).
--- drivers/net/tap/meson.build | 2 +- drivers/net/tap/rte_eth_tap.c | 197 +++++++++++++++------------------- drivers/net/tap/rte_eth_tap.h | 3 +- drivers/net/tap/tap_flow.c | 3 +- drivers/net/tap/tap_intr.c | 7 +- 5 files changed, 92 insertions(+), 120 deletions(-)
drivers/net/tap/meson.build +1 -1
@@ -16,7 +16,7 @@ sources = files( deps = ['bus_vdev', 'gso', 'hash'] -cflags += '-DTAP_MAX_QUEUES=16' +cflags += '-DTAP_MAX_QUEUES=8' # input array for meson symbol search: # [ "MACRO to define if found", "header for the search",
drivers/net/tap/rte_eth_tap.c +84 -113
343 lines not on this page · raw message
drivers/net/tap/rte_eth_tap.h +1 -2
@@ -96,8 +96,7 @@ struct pmd_internals { };struct pmd_process_private { -int rxq_fds[RTE_PMD_TAP_MAX_QUEUES ]; -int txq_fds[RTE_PMD_TAP_MAX_QUEUES ]; +int fds[RTE_PMD_TAP_MAX_QUEUES ]; };/* tap_intr.c */
drivers/net/tap/tap_flow.c +2 -1
@@ -1595,8 +1595,9 @@ tap_flow_isolate(struct rte_eth_dev *dev,* If netdevice is there, setup appropriate flow rules immediately. * Otherwise it will be set when bringing up the netdevice (tun_alloc). */ -if (!process_private->rxq_fds[0 ]) +if (process_private->fds[0 ] ==-1 )return 0 ; +if (set) {struct rte_flow *remote_flow;
drivers/net/tap/tap_intr.c +4 -3
@@ -68,9 +68,11 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev) }for (i =0 ; i < n; i++) {struct rx_queue *rxq = pmd->dev->data->rx_queues[i]; +int fd = process_private->fds[i];/* Skip queues that cannot request interrupts. */ -if (!rxq || process_private->rxq_fds[i] ==-1 ) { +if (!rxq || fd ==-1 ) { +/* Use invalid intr_vec[] index to disable entry. */ /* Use invalid intr_vec[] index to disable entry. */ if (rte_intr_vec_list_index_set (intr_handle, i,RTE_INTR_VEC_RXTX_OFFSET +RTE_MAX_RXTX_INTR_VEC_ID ))
@@ -80,8 +82,7 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev)if (rte_intr_vec_list_index_set (intr_handle, i,RTE_INTR_VEC_RXTX_OFFSET + count))return -rte_errno; -if (rte_intr_efds_index_set (intr_handle, count, - process_private->rxq_fds[i])) +if (rte_intr_efds_index_set (intr_handle, count, fd))return -rte_errno; count++; }
Signature · 1 line
2.43.0
PATCH v6 2/8 doc: fix the requirements and building of TAP flow
In reply to Stephen HemmingerThe build process for TAP eBPF RSS is now changed, so documentation needs to be updated.
Since kernel 4.19 is the oldest current LTS supported kernel, the TAP documentation can be simplified. Any complaints about flow not working means the kernel is out of scope of current DPDK.
--- doc/guides/linux_gsg/sys_reqs.rst | 3 + doc/guides/nics/tap.rst | 95 ++++++++----------------------- 2 files changed, 28 insertions(+), 70 deletions(-)
doc/guides/linux_gsg/sys_reqs.rst +3 -0
@@ -101,6 +101,9 @@ Running DPDK Applications To run a DPDK application, some customization may be required on the target machine. +.. _linux_gsg_kernel_version: + + System Software ~~~~~~~~~~~~~~~
doc/guides/nics/tap.rst +25 -70
125 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v6 3/8 net/tap: remove unused fields
In reply to Stephen HemmingerThe driver doesn't support these other hash types, and there is no reason to implement these in future. The rss_flows list was set but never used.
--- drivers/net/tap/rte_eth_tap.h | 4 +--- drivers/net/tap/tap_flow.c | 1 - drivers/net/tap/tap_rss.h | 6 ------ 3 files changed, 1 insertion(+), 10 deletions(-)
drivers/net/tap/rte_eth_tap.h +1 -3
@@ -77,14 +77,12 @@ struct pmd_internals {int ioctl_sock;/* socket for ioctl calls */ int nlsk_fd;/* Netlink socket fd */ int flow_isolate;/* 1 if flow isolation is enabled */ -int flower_support;/* 1 if kernel supports, else 0 */ -int flower_vlan_support;/* 1 if kernel supports, else 0 */ int rss_enabled;/* 1 if RSS is enabled, else 0 */ int persist;/* 1 if keep link up, else 0 */ /* implicit rules set when RSS is enabled */ int map_fd;/* BPF RSS map fd */ int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */ - LIST_HEAD(tap_rss_flows, rte_flow) rss_flows; + LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */ LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
drivers/net/tap/tap_flow.c +0 -1
@@ -1958,7 +1958,6 @@ static int rss_enable(struct pmd_internals *pmd, errno, strerror(errno));return err; } -LIST_INSERT_HEAD (&pmd->rss_flows, rss_flow, next); } pmd->rss_enabled =1 ;
drivers/net/tap/tap_rss.h +0 -6
@@ -21,12 +21,6 @@ enum hash_field {HASH_FIELD_IPV4_L3_L4 ,/* IPv4 src/dst addr + L4 src/dst ports */ HASH_FIELD_IPV6_L3 ,/* IPv6 src/dst addr */ HASH_FIELD_IPV6_L3_L4, /* IPv6 src/dst addr + L4 src/dst ports */ -HASH_FIELD_L2_SRC ,/* Ethernet src addr */ -HASH_FIELD_L2_DST ,/* Ethernet dst addr */ -HASH_FIELD_L3_SRC ,/* L3 src addr */ -HASH_FIELD_L3_DST ,/* L3 dst addr */ -HASH_FIELD_L4_SRC ,/* TCP/UDP src ports */ - HASH_FIELD_L4_DST, /* TCP/UDP dst ports */ }; struct rss_key {
Signature · 1 line
2.43.0
PATCH v6 4/8 net/tap: validate and setup parameters for BPF RSS
In reply to Stephen HemmingerThe flow RSS support via BPF was not using the key, or hash type parameters. Which is good because they were never properly setup.
Fix the setup and validate the flow parameters, the BPF side gets fixed later.
--- drivers/net/tap/tap_flow.c | 65 +++++++++++++++++++++++++++++++++++--- drivers/net/tap/tap_rss.h | 5 ++- 2 files changed, 62 insertions(+), 8 deletions(-)
drivers/net/tap/tap_flow.c +60 -5
@@ -11,9 +11,11 @@#include <rte_byteorder.h> #include <rte_jhash.h> +#include <rte_thash.h> #include <rte_random.h> #include <rte_malloc.h> #include <rte_eth_tap.h> +#include <tap_flow.h> #include <tap_autoconf.h> #include <tap_tcmsgs.h>
@@ -2061,6 +2063,21 @@ static int bpf_rss_key(enum bpf_rss_key_e cmd, __u32 *key_idx)return err; } + +/* Default RSS hash key also used by mlx devices */ +static const uint8_t rss_hash_default_key[] = { +0x2c ,0xc6 ,0x81 ,0xd1 , +0x5b ,0xdb ,0xf4 ,0xf7 , +0xfc ,0xa2 ,0x83 ,0x19 , +0xdb ,0x1a ,0x3e ,0x94 , +0x6b ,0x9e ,0x38 ,0xd9 , +0x2c ,0x9c ,0x03 ,0xd1 , +0xad ,0x99 ,0x44 ,0xa7 , +0xd9 ,0x56 ,0x3d ,0x59 , +0x06 ,0x3c ,0x25 ,0xf3 , +0xfc ,0x1f ,0xdc ,0x2a , +}; +/** * Add RSS hash calculations and queue selection *
@@ -2079,11 +2096,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,const struct rte_flow_action_rss *rss, struct rte_flow_error *error) { -/* 4096 is the maximum number of instructions for a BPF program */ + struct rss_key rss_entry = { }; +const uint8_t *key_in; +uint32_t hash_type =0 ;unsigned int i;int err; -struct rss_key rss_entry = { .hash_fields =0 , - .key_size =0 };/* Check supported RSS features */ if (rss->func !=RTE_ETH_HASH_FUNCTION_DEFAULT )
@@ -2095,6 +2112,41 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, (error,ENOTSUP ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL ,"a nonzero RSS encapsulation level is not supported" ); +if (rss->queue_num ==0 || rss->queue_num >=TAP_MAX_QUEUES ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL , +"invalid number of queues" ); + +/* allow RSS key_len 0 in case of NULL (default) RSS key. */ +if (rss->key_len ==0 ) { +if (rss->key !=NULL ) +return rte_flow_error_set (error,ENOTSUP , +RTE_FLOW_ERROR_TYPE_ACTION_CONF , + &rss->key_len,"RSS hash key length 0" ); + key_in = rss_hash_default_key; + }else { +if (rss->key_len !=TAP_RSS_HASH_KEY_SIZE ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"RSS hash invalid key length" ); +if (rss->key ==NULL ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"RSS hash key is NULL" ); + key_in = rss->key; + } + +if (rss->types &TAP_RSS_HF_MASK ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"RSS hash type not supported" ); + +if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV4_UDP |RTE_ETH_RSS_NONFRAG_IPV4_TCP )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV4_L3_L4 ); +else if (rss->types & (RTE_ETH_RSS_IPV4 |RTE_ETH_RSS_FRAG_IPV4 )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV4_L3 ); + +if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV6_UDP |RTE_ETH_RSS_NONFRAG_IPV6_TCP )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV6_L3_L4 ); +else if (rss->types & (RTE_ETH_RSS_IPV6 |RTE_ETH_RSS_FRAG_IPV6 |RTE_ETH_RSS_IPV6_EX )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV6_L3 ); +/* Get a new map key for a new RSS rule */ err =bpf_rss_key (KEY_CMD_GET , &flow->key_idx);if (err <0 ) {
@@ -2109,8 +2161,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, rss_entry.nb_queues = rss->queue_num;for (i =0 ; i < rss->queue_num; i++) rss_entry.queues[i] = rss->queue[i]; - rss_entry.hash_fields = - (1 <<HASH_FIELD_IPV4_L3_L4 ) | (1 <<HASH_FIELD_IPV6_L3_L4 ); + + rss_entry.hash_fields = hash_type; +rte_convert_rss_key ((const uint32_t *)key_in, (uint32_t *)rss_entry.key, +TAP_RSS_HASH_KEY_SIZE ); +/* Add this RSS entry to map */ err = tap_flow_bpf_update_rss_elem(pmd->map_fd,
drivers/net/tap/tap_rss.h +2 -3
@@ -24,11 +24,10 @@ enum hash_field { };struct rss_key { -__u8 key[128 ];__u32 hash_fields; -__u32 key_size; -__u32 queues[TAP_MAX_QUEUES ]; +__u8 key[TAP_RSS_HASH_KEY_SIZE ];__u32 nb_queues; +__u32 queues[TAP_MAX_QUEUES ]; } __attribute__((packed));#endif /* _TAP_RSS_H_ */
Signature · 1 line
2.43.0
PATCH v6 5/8 net/tap: stop "vendoring" linux bpf headers
In reply to Stephen HemmingerThe proper place for finding bpf structures and functions is in linux/bpf.h. The original version was trying to workaround the case where the build environment was running on old pre BPF version of Glibc, but the target environment had BPF.
Having own private (and divergent) version headers leads to future problems when BPF definitions evolve.
This also blocks tap device from building on kernels before 4.2. The oldest supported LTS kernel is currently 4.4 and the 4.1 kernel reached end of life in December 2015.
--- drivers/net/tap/bpf/bpf_extract.py | 1 - drivers/net/tap/meson.build | 13 ++-- drivers/net/tap/rte_eth_tap.c | 11 +-- drivers/net/tap/rte_eth_tap.h | 4 +- drivers/net/tap/tap_bpf.h | 121 ----------------------------- drivers/net/tap/tap_bpf_api.c | 20 +++-- drivers/net/tap/tap_bpf_insns.h | 2 - drivers/net/tap/tap_flow.c | 90 --------------------- 8 files changed, 30 insertions(+), 232 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf.h
drivers/net/tap/bpf/bpf_extract.py +0 -1
@@ -65,7 +65,6 @@ def write_header(out, source): print(f' * Auto-generated from {source}', file=out) print(" * This not the original source file. Do NOT edit it.", file=out) print(" */\n", file=out) - print("#include <tap_bpf.h>", file=out) def main():
drivers/net/tap/meson.build +8 -5
@@ -5,6 +5,14 @@ if not is_linux build = false reason = 'only supported on Linux' endif + +# The flower classifier was introduced in Linux 4.2 +# any kernel older than that is outside current DPDK support +if not cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT') + build = false + reason = 'does not support TC flower' +endif + sources = files( 'rte_eth_tap.c', 'tap_bpf_api.c',
@@ -23,12 +31,7 @@ cflags += '-DTAP_MAX_QUEUES=8' # "enum/define", "symbol to search" ] # args = [ - [ 'HAVE_TC_FLOWER', 'linux/pkt_cls.h', 'TCA_FLOWER_UNSPEC' ], - [ 'HAVE_TC_VLAN_ID', 'linux/pkt_cls.h', 'TCA_FLOWER_KEY_VLAN_PRIO' ], - [ 'HAVE_TC_BPF', 'linux/pkt_cls.h', 'TCA_BPF_UNSPEC' ], - [ 'HAVE_TC_BPF_FD', 'linux/pkt_cls.h', 'TCA_BPF_FD' ], [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ], - [ 'HAVE_TC_ACT_BPF_FD', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_FD' ], ] config = configuration_data() foreach arg:args
drivers/net/tap/rte_eth_tap.c +6 -5
@@ -2021,6 +2021,12 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,/* Make network device persist after application exit */ pmd->persist = persist; + pmd->if_index =if_nametoindex (pmd->name); +if (!pmd->if_index) { +TAP_LOG (ERR ,"%s: failed to get if_index." , pmd->name); + goto disable_rte_flow; + } +/* * Set up everything related to rte_flow: * - netlink socket
@@ -2035,11 +2041,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, pmd->name); goto disable_rte_flow; } - pmd->if_index =if_nametoindex (pmd->name); -if (!pmd->if_index) { -TAP_LOG (ERR ,"%s: failed to get if_index." , pmd->name); - goto disable_rte_flow; - }if (qdisc_create_multiq (pmd->nlsk_fd, pmd->if_index) <0 ) {TAP_LOG (ERR ,"%s: failed to create multiq qdisc." , pmd->name);
drivers/net/tap/rte_eth_tap.h +3 -1
@@ -16,6 +16,7 @@#include <ethdev_driver.h> #include <rte_ether.h> #include <rte_gso.h> +#include "tap_log.h" #ifdef IFF_MULTI_QUEUE
@@ -70,6 +71,7 @@ struct pmd_internals {char remote_iface[RTE_ETH_NAME_MAX_LEN ];/* Remote netdevice name */ char name[RTE_ETH_NAME_MAX_LEN ];/* Internal Tap device name */ int type;/* Type field - TUN|TAP */ +int persist;/* 1 if keep link up, else 0 */ struct rte_ether_addr eth_addr;/* Mac address of the device port */ struct ifreq remote_initial_flags;/* Remote netdevice flags on init */ int remote_if_index;/* remote netdevice IF_INDEX */
@@ -78,7 +80,6 @@ struct pmd_internals {int nlsk_fd;/* Netlink socket fd */ int flow_isolate;/* 1 if flow isolation is enabled */ int rss_enabled;/* 1 if RSS is enabled, else 0 */ -int persist;/* 1 if keep link up, else 0 */ /* implicit rules set when RSS is enabled */ int map_fd;/* BPF RSS map fd */ int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */
@@ -86,6 +87,7 @@ struct pmd_internals { LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */ LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows; +struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES ];/* List of RX queues */ struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES ];/* List of TX queues */ struct rte_intr_handle *intr_handle;/* LSC interrupt handle. */
drivers/net/tap/tap_bpf.h deleted +0 -121
121 lines not on this page · raw message
drivers/net/tap/tap_bpf_api.c +13 -7
@@ -2,19 +2,19 @@* Copyright 2017 Mellanox Technologies, Ltd */ -#include <errno.h> -#include <string.h> #include <unistd.h> -#include <sys/queue.h> +#include <syscall.h> +#include <linux/bpf.h> -#include <rte_malloc.h> -#include <rte_eth_tap.h> #include <tap_flow.h> #include <tap_autoconf.h> -#include <tap_tcmsgs.h> -#include <tap_bpf.h> +#include <tap_bpf_insns.h> + +static int bpf_load (enum bpf_prog_type type,const struct bpf_insn *insns, +size_t insns_cnt,const char *license); +/** * Load BPF program (section cls_q) into the kernel and return a bpf fd *
@@ -89,7 +89,13 @@ static inline __u64 ptr_to_u64(const void *ptr)static inline int sys_bpf (enum bpf_cmd cmd,union bpf_attr *attr,unsigned int size) { +#ifdef __NR_bpfreturn syscall (__NR_bpf, cmd, attr, size); +#else +TAP_LOG (ERR ,"No bpf syscall, kernel headers too old?\n" ); + errno =ENOSYS ; +return -1 ; +#endif }/**
drivers/net/tap/tap_bpf_insns.h +0 -2
@@ -3,8 +3,6 @@* This not the original source file. Do NOT edit it. */ -#include <tap_bpf.h> -static struct bpf_insn cls_q_insns[] = { {0x61 ,2 ,1 ,52 ,0x00000000 }, {0x18 ,3 ,0 ,0 ,0xdeadbeef },
drivers/net/tap/tap_flow.c +0 -90
96 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v6 6/8 net/tap: rewrite the RSS BPF program
In reply to Stephen HemmingerRewrite the BPF program used to do queue based RSS. Important changes:
- uses newer BPF map format BTF
- accepts key as parameter rather than constant default
- can do L3 or L4 hashing
- supports IPv4 options
- supports IPv6 extension headers
- restructured for readability
The usage of BPF is different as well:
- the incoming configuration is looked up based on class parameters rather than patching the BPF.
- the resulting queue is placed in skb rather than requiring a second pass through classifier step.
Note: This version only works with later patch to enable it on the DPDK driver side. It is submitted as an incremental patch to allow for easier review. Bisection still works because the old instruction are still present for now.
--- .gitignore | 3 - drivers/net/tap/bpf/Makefile | 19 -- drivers/net/tap/bpf/README | 38 ++++ drivers/net/tap/bpf/bpf_api.h | 276 -------------------------- drivers/net/tap/bpf/bpf_elf.h | 53 ----- drivers/net/tap/bpf/bpf_extract.py | 85 -------- drivers/net/tap/bpf/meson.build | 81 ++++++++ drivers/net/tap/bpf/tap_bpf_program.c | 255 ------------------------ drivers/net/tap/bpf/tap_rss.c | 264 ++++++++++++++++++++++++ 9 files changed, 383 insertions(+), 691 deletions(-) delete mode 100644 drivers/net/tap/bpf/Makefile create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py create mode 100644 drivers/net/tap/bpf/meson.build delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c
.gitignore +0 -3
@@ -36,9 +36,6 @@ TAGS # ignore python bytecode files *.pyc -# ignore BPF programs -drivers/net/tap/bpf/tap_bpf_program.o - # DTS results dts/output
drivers/net/tap/bpf/Makefile deleted +0 -19
@@ -1,19 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# This file is not built as part of normal DPDK build. -# It is used to generate the eBPF code for TAP RSS. - -CLANG=clang -CLANG_OPTS=-O2 -TARGET=../tap_bpf_insns.h - -all: $(TARGET) - -clean: - rm tap_bpf_program.o $(TARGET) - -tap_bpf_program.o: tap_bpf_program.c - $(CLANG) $(CLANG_OPTS) -emit-llvm -c $< -o - | \ - llc -march=bpf -filetype=obj -o $@ - -$(TARGET): tap_bpf_program.o - python3 bpf_extract.py -stap_bpf_program.c -o $@ $<
drivers/net/tap/bpf/README new file +38 -0
@@ -0,0 +1,38 @@ +This is the BPF program used to implement the RSS across queues flow action. +The program is loaded when first RSS flow rule is created and is never unloaded. + +Each flow rule creates a unique key (handle) and this is used as the key +for finding the RSS information for that flow rule. + +This version is built the BPF Compile Once — Run Everywhere (CO-RE) +framework and uses libbpf and bpftool. + +Limitations +----------- +- requires libbpf to run +- rebuilding the BPF requires Clang and bpftool. + Some older versions of Ubuntu do not have working bpftool package. + Need a version of Clang that can compile to BPF. +- only standard Toeplitz hash with standard 40 byte key is supported +- the number of flow rules using RSS is limited to 32 + +Building +-------- +During the DPDK build process the meson build file checks that +libbpf, bpftool, and clang are not available. If everything is +there then BPF RSS is enabled. + +1. Using clang to compile tap_rss.c the tap_rss.bpf.o file. + +2. Using bpftool generate a skeleton header file tap_rss.skel.h from tap_rss.bpf.o. + This skeleton header is an large byte array which contains the + BPF binary and wrappers to load and use it. + +3. The tap flow code then compiles that BPF byte array into the PMD object. + +4. When needed the BPF array is loaded by libbpf. + +References +---------- +BPF and XDP reference guide +https://docs.cilium.io/en/latest/bpf/progtypes/
drivers/net/tap/bpf/bpf_api.h deleted +0 -276
276 lines not on this page · raw message
drivers/net/tap/bpf/bpf_elf.h deleted +0 -53
53 lines not on this page · raw message
drivers/net/tap/bpf/bpf_extract.py deleted +0 -85
85 lines not on this page · raw message
drivers/net/tap/bpf/meson.build new file +81 -0
81 lines not on this page · raw message
drivers/net/tap/bpf/tap_bpf_program.c deleted +0 -255
255 lines not on this page · raw message
drivers/net/tap/bpf/tap_rss.c new file +264 -0
264 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v6 7/8 net/tap: use libbpf to load new BPF program
In reply to Stephen HemmingerThere were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.
Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.
The new BPF program only needs a single action.
No need for action and re-classification step.
It also fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.
--- drivers/net/tap/bpf/meson.build | 30 ++- drivers/net/tap/bpf/tap_rss.c | 45 ++-- drivers/net/tap/meson.build | 26 +- drivers/net/tap/rte_eth_tap.c | 13 +- drivers/net/tap/rte_eth_tap.h | 6 +- drivers/net/tap/tap_flow.c | 408 +++++++------------------------- drivers/net/tap/tap_flow.h | 17 +- drivers/net/tap/tap_rss.h | 10 +- drivers/net/tap/tap_tcmsgs.h | 4 +- 9 files changed, 171 insertions(+), 388 deletions(-)
drivers/net/tap/bpf/meson.build +28 -2
@@ -3,15 +3,24 @@ enable_tap_rss = false +# Loading BPF requires libbpf libbpf = dependency('libbpf', required: false, method: 'pkg-config') if not libbpf.found() message('net/tap: no RSS support missing libbpf') subdir_done() endif +# Making skeleton needs bpftool # Debian install this in /usr/sbin which is not in $PATH -bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false, version: '>= 5.6.0') -if not bpftool.found() +bpftool_supports_skel = false +bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false) +if bpftool.found() + # Some Ubuntu has non-functional bpftool + bpftool_supports_skel = run_command(bpftool, 'gen', 'help', + check:false).returncode() == 0 +endif + +if not bpftool_supports_skel message('net/tap: no RSS support missing bpftool') subdir_done() endif
@@ -42,6 +51,7 @@ clang_flags = [ '-O2', '-Wall', '-Wextra', + max_queues, '-target', 'bpf', '-g',
@@ -67,6 +77,22 @@ skel_h_cmd = [ '@INPUT@' ] +vmlinux_h_cmd = [ + bpftool, + 'btf', + 'dump', + 'file', + '/sys/kernel/btf/vmlinux', + 'format', + 'c' +] + +vmlinux_h = custom_target( + 'vmlinux.h', + output: 'vmlinux.h', + command: vmlinux_h_cmd, + capture: true) + tap_rss_o = custom_target( 'tap_rss.bpf.o', input: 'tap_rss.c',
drivers/net/tap/bpf/tap_rss.c +24 -21
67 lines not on this page · raw message
drivers/net/tap/meson.build +10 -16
@@ -15,28 +15,22 @@ endif sources = files( 'rte_eth_tap.c', - 'tap_bpf_api.c', 'tap_flow.c', 'tap_intr.c', 'tap_netlink.c', 'tap_tcmsgs.c', -) + ) deps = ['bus_vdev', 'gso', 'hash'] -cflags += '-DTAP_MAX_QUEUES=8' - -# input array for meson symbol search: -# [ "MACRO to define if found", "header for the search", -# "enum/define", "symbol to search" ] -# -args = [ - [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ], -] -config = configuration_data() -foreach arg:args - config.set(arg[0], cc.has_header_symbol(arg[1], arg[2])) -endforeach -configure_file(output : 'tap_autoconf.h', configuration : config) +max_queues = '-DTAP_MAX_QUEUES=16' +cflags += max_queues require_iova_in_mbuf = false + +subdir('bpf') +if enable_tap_rss + cflags += '-DHAVE_BPF_RSS' + ext_deps += libbpf + sources += tap_rss_skel_h +endif
drivers/net/tap/rte_eth_tap.c +7 -6
@@ -1129,6 +1129,7 @@ tap_dev_close(struct rte_eth_dev *dev)tap_flow_implicit_flush (internals,NULL );tap_nl_final (internals->nlsk_fd); internals->nlsk_fd =-1 ; +tap_flow_bpf_destroy (internals); }for (i =0 ; i <RTE_PMD_TAP_MAX_QUEUES ; i++) {
@@ -1941,6 +1942,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,strlcpy (pmd->name, tap_name,sizeof (pmd->name)); pmd->type = type; pmd->ka_fd =-1 ; + pmd->rss =NULL ; pmd->nlsk_fd =-1 ; pmd->gso_ctx_mp =NULL ;
@@ -2021,12 +2023,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,/* Make network device persist after application exit */ pmd->persist = persist; - pmd->if_index =if_nametoindex (pmd->name); -if (!pmd->if_index) { -TAP_LOG (ERR ,"%s: failed to get if_index." , pmd->name); - goto disable_rte_flow; - } -/* * Set up everything related to rte_flow: * - netlink socket
@@ -2041,6 +2037,11 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, pmd->name); goto disable_rte_flow; } + pmd->if_index =if_nametoindex (pmd->name); +if (!pmd->if_index) { +TAP_LOG (ERR ,"%s: failed to get if_index." , pmd->name); + goto disable_rte_flow; + }if (qdisc_create_multiq (pmd->nlsk_fd, pmd->if_index) <0 ) {TAP_LOG (ERR ,"%s: failed to create multiq qdisc." , pmd->name);
drivers/net/tap/rte_eth_tap.h +2 -4
@@ -79,10 +79,8 @@ struct pmd_internals {int ioctl_sock;/* socket for ioctl calls */ int nlsk_fd;/* Netlink socket fd */ int flow_isolate;/* 1 if flow isolation is enabled */ -int rss_enabled;/* 1 if RSS is enabled, else 0 */ -/* implicit rules set when RSS is enabled */ -int map_fd;/* BPF RSS map fd */ -int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */ + +struct tap_rss *rss;/* BPF program */ LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */
drivers/net/tap/tap_flow.c +89 -319
536 lines not on this page · raw message
drivers/net/tap/tap_flow.h +6 -11
@@ -9,7 +9,11 @@#include <rte_flow.h> #include <rte_flow_driver.h> #include <rte_eth_tap.h> -#include <tap_autoconf.h> + +/** +* Mask of unsupported RSS types +*/ +#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP))/** * In TC, priority 0 means we require the kernel to allocate one for us.
@@ -41,11 +45,6 @@ enum implicit_rule_index { TAP_REMOTE_MAX_IDX, }; -enum bpf_fd_idx { -SEC_L3_L4 , -SEC_MAX , -}; -int tap_dev_flow_ops_get (struct rte_eth_dev *dev,const struct rte_flow_ops **ops);int tap_flow_flush (struct rte_eth_dev *dev,struct rte_flow_error *error);
@@ -57,10 +56,6 @@ int tap_flow_implicit_destroy(struct pmd_internals *pmd,int tap_flow_implicit_flush (struct pmd_internals *pmd,struct rte_flow_error *error); -int tap_flow_bpf_cls_q (__u32 queue_idx); -int tap_flow_bpf_calc_l3_l4_hash (__u32 key_idx,int map_fd); -int tap_flow_bpf_rss_map_create (unsigned int key_size,unsigned int value_size, -unsigned int max_entries); -int tap_flow_bpf_update_rss_elem (int fd,void *key,void *value); +void tap_flow_bpf_destroy (struct pmd_internals *pmd);#endif /* _TAP_FLOW_H_ */
drivers/net/tap/tap_rss.h +4 -6
@@ -5,16 +5,14 @@#ifndef _TAP_RSS_H_#define _TAP_RSS_H_ -#ifndef TAP_MAX_QUEUES -#define TAP_MAX_QUEUES 16 +/* Size of the map from BPF classid to queue table */ +#ifndef TAP_RSS_MAX +#define TAP_RSS_MAX 32#endif -/* Fixed RSS hash key size in bytes. */ +/* Standard Toeplitz hash key size */ #define TAP_RSS_HASH_KEY_SIZE 40 -/* Supported RSS */ -#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP)) -/* hashed fields for RSS */ enum hash_field { HASH_FIELD_IPV4_L3, /* IPv4 src/dst addr */
drivers/net/tap/tap_tcmsgs.h +1 -3
@@ -6,7 +6,6 @@#ifndef _TAP_TCMSGS_H_#define _TAP_TCMSGS_H_ -#include <tap_autoconf.h> #include <linux/if_ether.h> #include <linux/rtnetlink.h> #include <linux/pkt_sched.h>
@@ -14,9 +13,8 @@#include <linux/tc_act/tc_mirred.h> #include <linux/tc_act/tc_gact.h> #include <linux/tc_act/tc_skbedit.h> -#ifdef HAVE_TC_ACT_BPF #include <linux/tc_act/tc_bpf.h> -#endif +#include <inttypes.h> #include <rte_ether.h>
Signature · 1 line
2.43.0
PATCH v6 8/8 net/tap: remove no longer used files
In reply to Stephen HemmingerThe BPF api was replaced by use of libbpf.
And the BPF instruction header was replaced by the skeleton.
--- drivers/net/tap/tap_bpf_api.c | 196 ---- drivers/net/tap/tap_bpf_insns.h | 1741 ------------------------------- 2 files changed, 1937 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h
drivers/net/tap/tap_bpf_api.c deleted +0 -196
@@ -1,196 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright 2017 Mellanox Technologies, Ltd -*/ - -#include <unistd.h> -#include <syscall.h> -#include <linux/bpf.h> - -#include <tap_flow.h> -#include <tap_autoconf.h> - -#include <tap_bpf_insns.h> - - -static int bpf_load (enum bpf_prog_type type,const struct bpf_insn *insns, -size_t insns_cnt,const char *license); - -/** -* Load BPF program (section cls_q) into the kernel and return a bpf fd -* -* @param queue_idx -* Queue index matching packet cb -* -* @return -* -1 if the BPF program couldn't be loaded. An fd (int) otherwise. -*/ -int tap_flow_bpf_cls_q (__u32 queue_idx) -{ - cls_q_insns[1 ].imm = queue_idx; - -return bpf_load (BPF_PROG_TYPE_SCHED_CLS , - (struct bpf_insn *)cls_q_insns, -RTE_DIM (cls_q_insns), -"Dual BSD/GPL" ); -} - -/** -* Load BPF program (section l3_l4) into the kernel and return a bpf fd. -* -* @param[in] key_idx -* RSS MAP key index -* -* @param[in] map_fd -* BPF RSS map file descriptor -* -* @return -* -1 if the BPF program couldn't be loaded. An fd (int) otherwise. -*/ -int tap_flow_bpf_calc_l3_l4_hash (__u32 key_idx,int map_fd) -{ - l3_l4_hash_insns[4 ].imm = key_idx; - l3_l4_hash_insns[9 ].imm = map_fd; - -return bpf_load (BPF_PROG_TYPE_SCHED_ACT , - (struct bpf_insn *)l3_l4_hash_insns, -RTE_DIM (l3_l4_hash_insns), -"Dual BSD/GPL" ); -} - -/** -* Helper function to convert a pointer to unsigned 64 bits -* -* @param[in] ptr -* pointer to address -* -* @return -* 64 bit unsigned long type of pointer address -*/ -static inline __u64 ptr_to_u64 (const void *ptr) -{ -return (__u64 )(unsigned long )ptr; -} - -/** -* Call BPF system call -* -* @param[in] cmd -* BPF command for program loading, map creation, map entry update, etc -* -* @param[in] attr -* System call attributes relevant to system call command -* -* @param[in] size -* size of attr parameter -* -* @return -* -1 if BPF system call failed, 0 otherwise -*/ -static inline int sys_bpf (enum bpf_cmd cmd,union bpf_attr *attr, -unsigned int size) -{ -#ifdef __NR_bpf -return syscall (__NR_bpf, cmd, attr, size); -#else -TAP_LOG (ERR ,"No bpf syscall, kernel headers too old?\n" ); - errno =ENOSYS ; -return -1 ; -#endif -} - -/** -* Load BPF instructions to kernel -* -* @param[in] type -* BPF program type: classifier or action -* -* @param[in] insns -* Array of BPF instructions (equivalent to BPF instructions) -* -* @param[in] insns_cnt -* Number of BPF instructions (size of array) -* -* @param[in] license -* License string that must be acknowledged by the kernel -* -* @return -* -1 if the BPF program couldn't be loaded, fd (file descriptor) otherwise -*/ -static int bpf_load (enum bpf_prog_type type, -const struct bpf_insn *insns, -size_t insns_cnt, -const char *license) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - attr.prog_type = type; - attr.insn_cnt = (__u32 )insns_cnt; - attr.insns =ptr_to_u64 (insns); - attr.license =ptr_to_u64 (license); - attr.log_buf =ptr_to_u64 (NULL ); - attr.log_level =0 ; - attr.kern_version =0 ; - -return sys_bpf (BPF_PROG_LOAD , &attr,sizeof (attr)); -} - -/** -* Create BPF map for RSS rules -* -* @param[in] key_size -* map RSS key size -* -* @param[in] value_size -* Map RSS value size -* -* @param[in] max_entries -* Map max number of RSS entries (limit on max RSS rules) -* -* @return -* -1 if BPF map couldn't be created, map fd otherwise -*/ -int tap_flow_bpf_rss_map_create (unsigned int key_size, -unsigned int value_size, -unsigned int max_entries) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - attr.map_type =BPF_MAP_TYPE_HASH ; - attr.key_size = key_size; - attr.value_size = value_size; - attr.max_entries = max_entries; - -return sys_bpf (BPF_MAP_CREATE , &attr,sizeof (attr)); -} - -/** -* Update RSS entry in BPF map -* -* @param[in] fd -* RSS map fd -* -* @param[in] key -* Pointer to RSS key whose entry is updated -* -* @param[in] value -* Pointer to RSS new updated value -* -* @return -* -1 if RSS entry failed to be updated, 0 otherwise -*/ -int tap_flow_bpf_update_rss_elem (int fd,void *key,void *value) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - - attr.map_type =BPF_MAP_TYPE_HASH ; - attr.map_fd = fd; - attr.key =ptr_to_u64 (key); - attr.value =ptr_to_u64 (value); - attr.flags =BPF_ANY ; - -return sys_bpf (BPF_MAP_UPDATE_ELEM , &attr,sizeof (attr)); -}
drivers/net/tap/tap_bpf_insns.h deleted +0 -1741
1,741 lines not on this page · raw message
Signature · 1 line
2.43.0
v7 cover net/tap: cleanups and fix BPF support
In reply to Stephen HemmingerThe support of doing RSS for rte_flow_action was a cool idea but it has been broken for several releases of DPDK as the kernel and BPF infrastructure changed.
This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF toolchain.
The result should be easier to read and maintain.
v7 - use BPF CO:RE to handle build vs runtime in skb offsets.
- update documentation
- workaround for older distributions where support for
TC flower won't work. No flower == No flow support
Stephen Hemminger (8):
net/tap: do not duplicate fd's
net/tap: remove unused fields
net/tap: validate and setup parameters for BPF RSS net/tap: do not build flow support if header is out of date net/tap: rewrite the RSS BPF program
net/tap: use libbpf to load new BPF program net/tap: remove no longer used files
doc: update documentation of TAP PMD
.gitignore | 3 - doc/guides/linux_gsg/sys_reqs.rst | 3 + doc/guides/nics/tap.rst | 268 +--- drivers/net/tap/bpf/Makefile | 19 - drivers/net/tap/bpf/README | 38 + drivers/net/tap/bpf/bpf_api.h | 276 ---- drivers/net/tap/bpf/bpf_elf.h | 53 - drivers/net/tap/bpf/bpf_extract.py | 86 -- drivers/net/tap/bpf/meson.build | 109 ++ drivers/net/tap/bpf/tap_bpf_program.c | 255 ---- drivers/net/tap/bpf/tap_rss.c | 267 ++++ drivers/net/tap/meson.build | 40 +- drivers/net/tap/rte_eth_tap.c | 225 ++-- drivers/net/tap/rte_eth_tap.h | 20 +- drivers/net/tap/tap_bpf.h | 121 -- drivers/net/tap/tap_bpf_api.c | 190 --- drivers/net/tap/tap_bpf_insns.h | 1743 ------------------------- drivers/net/tap/tap_flow.c | 549 ++------ drivers/net/tap/tap_flow.h | 17 +- drivers/net/tap/tap_intr.c | 7 +- drivers/net/tap/tap_rss.h | 21 +- drivers/net/tap/tap_tcmsgs.h | 4 +- 22 files changed, 786 insertions(+), 3528 deletions(-) delete mode 100644 drivers/net/tap/bpf/Makefile create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py create mode 100644 drivers/net/tap/bpf/meson.build delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c delete mode 100644 drivers/net/tap/tap_bpf.h delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h
Signature · 1 line
2.43.0
PATCH v7 1/8 net/tap: do not duplicate fd's
The TAP device can use same file descriptopr for both rx and tx queues. This allows up to 8 queues (versus 4).
--- drivers/net/tap/meson.build | 2 +- drivers/net/tap/rte_eth_tap.c | 197 +++++++++++++++------------------- drivers/net/tap/rte_eth_tap.h | 3 +- drivers/net/tap/tap_flow.c | 3 +- drivers/net/tap/tap_intr.c | 7 +- 5 files changed, 92 insertions(+), 120 deletions(-)
drivers/net/tap/meson.build +1 -1
@@ -16,7 +16,7 @@ sources = files( deps = ['bus_vdev', 'gso', 'hash'] -cflags += '-DTAP_MAX_QUEUES=16' +cflags += '-DTAP_MAX_QUEUES=8' # input array for meson symbol search: # [ "MACRO to define if found", "header for the search",
drivers/net/tap/rte_eth_tap.c +84 -113
343 lines not on this page · raw message
drivers/net/tap/rte_eth_tap.h +1 -2
@@ -96,8 +96,7 @@ struct pmd_internals { };struct pmd_process_private { -int rxq_fds[RTE_PMD_TAP_MAX_QUEUES ]; -int txq_fds[RTE_PMD_TAP_MAX_QUEUES ]; +int fds[RTE_PMD_TAP_MAX_QUEUES ]; };/* tap_intr.c */
drivers/net/tap/tap_flow.c +2 -1
@@ -1595,8 +1595,9 @@ tap_flow_isolate(struct rte_eth_dev *dev,* If netdevice is there, setup appropriate flow rules immediately. * Otherwise it will be set when bringing up the netdevice (tun_alloc). */ -if (!process_private->rxq_fds[0 ]) +if (process_private->fds[0 ] ==-1 )return 0 ; +if (set) {struct rte_flow *remote_flow;
drivers/net/tap/tap_intr.c +4 -3
@@ -68,9 +68,11 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev) }for (i =0 ; i < n; i++) {struct rx_queue *rxq = pmd->dev->data->rx_queues[i]; +int fd = process_private->fds[i];/* Skip queues that cannot request interrupts. */ -if (!rxq || process_private->rxq_fds[i] ==-1 ) { +if (!rxq || fd ==-1 ) { +/* Use invalid intr_vec[] index to disable entry. */ /* Use invalid intr_vec[] index to disable entry. */ if (rte_intr_vec_list_index_set (intr_handle, i,RTE_INTR_VEC_RXTX_OFFSET +RTE_MAX_RXTX_INTR_VEC_ID ))
@@ -80,8 +82,7 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev)if (rte_intr_vec_list_index_set (intr_handle, i,RTE_INTR_VEC_RXTX_OFFSET + count))return -rte_errno; -if (rte_intr_efds_index_set (intr_handle, count, - process_private->rxq_fds[i])) +if (rte_intr_efds_index_set (intr_handle, count, fd))return -rte_errno; count++; }
Signature · 1 line
2.43.0
PATCH v7 2/8 net/tap: remove unused fields
In reply to Stephen HemmingerThe driver doesn't support these other hash types, and there is no reason to implement these in future. The rss_flows list was set but never used.
--- drivers/net/tap/rte_eth_tap.h | 4 +--- drivers/net/tap/tap_flow.c | 1 - drivers/net/tap/tap_rss.h | 6 ------ 3 files changed, 1 insertion(+), 10 deletions(-)
drivers/net/tap/rte_eth_tap.h +1 -3
@@ -77,14 +77,12 @@ struct pmd_internals {int ioctl_sock;/* socket for ioctl calls */ int nlsk_fd;/* Netlink socket fd */ int flow_isolate;/* 1 if flow isolation is enabled */ -int flower_support;/* 1 if kernel supports, else 0 */ -int flower_vlan_support;/* 1 if kernel supports, else 0 */ int rss_enabled;/* 1 if RSS is enabled, else 0 */ int persist;/* 1 if keep link up, else 0 */ /* implicit rules set when RSS is enabled */ int map_fd;/* BPF RSS map fd */ int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */ - LIST_HEAD(tap_rss_flows, rte_flow) rss_flows; + LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */ LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
drivers/net/tap/tap_flow.c +0 -1
@@ -1958,7 +1958,6 @@ static int rss_enable(struct pmd_internals *pmd, errno, strerror(errno));return err; } -LIST_INSERT_HEAD (&pmd->rss_flows, rss_flow, next); } pmd->rss_enabled =1 ;
drivers/net/tap/tap_rss.h +0 -6
@@ -21,12 +21,6 @@ enum hash_field {HASH_FIELD_IPV4_L3_L4 ,/* IPv4 src/dst addr + L4 src/dst ports */ HASH_FIELD_IPV6_L3 ,/* IPv6 src/dst addr */ HASH_FIELD_IPV6_L3_L4, /* IPv6 src/dst addr + L4 src/dst ports */ -HASH_FIELD_L2_SRC ,/* Ethernet src addr */ -HASH_FIELD_L2_DST ,/* Ethernet dst addr */ -HASH_FIELD_L3_SRC ,/* L3 src addr */ -HASH_FIELD_L3_DST ,/* L3 dst addr */ -HASH_FIELD_L4_SRC ,/* TCP/UDP src ports */ - HASH_FIELD_L4_DST, /* TCP/UDP dst ports */ }; struct rss_key {
Signature · 1 line
2.43.0
PATCH v7 3/8 net/tap: validate and setup parameters for BPF RSS
In reply to Stephen HemmingerThe flow RSS support via BPF was not using the key, or hash type parameters. Which is good because they were never properly setup.
Fix the setup and validate the flow parameters, the BPF side gets fixed later.
--- drivers/net/tap/tap_flow.c | 65 +++++++++++++++++++++++++++++++++++--- drivers/net/tap/tap_rss.h | 5 ++- 2 files changed, 62 insertions(+), 8 deletions(-)
drivers/net/tap/tap_flow.c +60 -5
@@ -11,9 +11,11 @@#include <rte_byteorder.h> #include <rte_jhash.h> +#include <rte_thash.h> #include <rte_random.h> #include <rte_malloc.h> #include <rte_eth_tap.h> +#include <tap_flow.h> #include <tap_autoconf.h> #include <tap_tcmsgs.h>
@@ -2061,6 +2063,21 @@ static int bpf_rss_key(enum bpf_rss_key_e cmd, __u32 *key_idx)return err; } + +/* Default RSS hash key also used by mlx devices */ +static const uint8_t rss_hash_default_key[] = { +0x2c ,0xc6 ,0x81 ,0xd1 , +0x5b ,0xdb ,0xf4 ,0xf7 , +0xfc ,0xa2 ,0x83 ,0x19 , +0xdb ,0x1a ,0x3e ,0x94 , +0x6b ,0x9e ,0x38 ,0xd9 , +0x2c ,0x9c ,0x03 ,0xd1 , +0xad ,0x99 ,0x44 ,0xa7 , +0xd9 ,0x56 ,0x3d ,0x59 , +0x06 ,0x3c ,0x25 ,0xf3 , +0xfc ,0x1f ,0xdc ,0x2a , +}; +/** * Add RSS hash calculations and queue selection *
@@ -2079,11 +2096,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,const struct rte_flow_action_rss *rss, struct rte_flow_error *error) { -/* 4096 is the maximum number of instructions for a BPF program */ + struct rss_key rss_entry = { }; +const uint8_t *key_in; +uint32_t hash_type =0 ;unsigned int i;int err; -struct rss_key rss_entry = { .hash_fields =0 , - .key_size =0 };/* Check supported RSS features */ if (rss->func !=RTE_ETH_HASH_FUNCTION_DEFAULT )
@@ -2095,6 +2112,41 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, (error,ENOTSUP ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL ,"a nonzero RSS encapsulation level is not supported" ); +if (rss->queue_num ==0 || rss->queue_num >=TAP_MAX_QUEUES ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL , +"invalid number of queues" ); + +/* allow RSS key_len 0 in case of NULL (default) RSS key. */ +if (rss->key_len ==0 ) { +if (rss->key !=NULL ) +return rte_flow_error_set (error,ENOTSUP , +RTE_FLOW_ERROR_TYPE_ACTION_CONF , + &rss->key_len,"RSS hash key length 0" ); + key_in = rss_hash_default_key; + }else { +if (rss->key_len !=TAP_RSS_HASH_KEY_SIZE ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"RSS hash invalid key length" ); +if (rss->key ==NULL ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"RSS hash key is NULL" ); + key_in = rss->key; + } + +if (rss->types &TAP_RSS_HF_MASK ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"RSS hash type not supported" ); + +if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV4_UDP |RTE_ETH_RSS_NONFRAG_IPV4_TCP )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV4_L3_L4 ); +else if (rss->types & (RTE_ETH_RSS_IPV4 |RTE_ETH_RSS_FRAG_IPV4 )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV4_L3 ); + +if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV6_UDP |RTE_ETH_RSS_NONFRAG_IPV6_TCP )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV6_L3_L4 ); +else if (rss->types & (RTE_ETH_RSS_IPV6 |RTE_ETH_RSS_FRAG_IPV6 |RTE_ETH_RSS_IPV6_EX )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV6_L3 ); +/* Get a new map key for a new RSS rule */ err =bpf_rss_key (KEY_CMD_GET , &flow->key_idx);if (err <0 ) {
@@ -2109,8 +2161,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, rss_entry.nb_queues = rss->queue_num;for (i =0 ; i < rss->queue_num; i++) rss_entry.queues[i] = rss->queue[i]; - rss_entry.hash_fields = - (1 <<HASH_FIELD_IPV4_L3_L4 ) | (1 <<HASH_FIELD_IPV6_L3_L4 ); + + rss_entry.hash_fields = hash_type; +rte_convert_rss_key ((const uint32_t *)key_in, (uint32_t *)rss_entry.key, +TAP_RSS_HASH_KEY_SIZE ); +/* Add this RSS entry to map */ err = tap_flow_bpf_update_rss_elem(pmd->map_fd,
drivers/net/tap/tap_rss.h +2 -3
@@ -24,11 +24,10 @@ enum hash_field { };struct rss_key { -__u8 key[128 ];__u32 hash_fields; -__u32 key_size; -__u32 queues[TAP_MAX_QUEUES ]; +__u8 key[TAP_RSS_HASH_KEY_SIZE ];__u32 nb_queues; +__u32 queues[TAP_MAX_QUEUES ]; } __attribute__((packed));#endif /* _TAP_RSS_H_ */
Signature · 1 line
2.43.0
PATCH v7 4/8 net/tap: do not build flow support if header is out of date
In reply to Stephen HemmingerThe proper place for finding bpf structures and functions is in linux/bpf.h. The original version was trying to workaround the case where the build environment was running on old pre BPF version of Glibc, but the target environment had BPF.
Having own private (and divergent) version headers leads to future problems when BPF definitions evolve.
If the build infrastructure is so old that TC flower is not supported, then the TAP device will build without any flow support.
--- drivers/net/tap/bpf/bpf_extract.py | 1 - drivers/net/tap/meson.build | 17 ++-- drivers/net/tap/rte_eth_tap.c | 38 +++++++-- drivers/net/tap/rte_eth_tap.h | 7 +- drivers/net/tap/tap_bpf.h | 121 ----------------------------- drivers/net/tap/tap_bpf_api.c | 20 +++-- drivers/net/tap/tap_bpf_insns.h | 2 - drivers/net/tap/tap_flow.c | 90 --------------------- 8 files changed, 60 insertions(+), 236 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf.h
drivers/net/tap/bpf/bpf_extract.py +0 -1
@@ -65,7 +65,6 @@ def write_header(out, source): print(f' * Auto-generated from {source}', file=out) print(" * This not the original source file. Do NOT edit it.", file=out) print(" */\n", file=out) - print("#include <tap_bpf.h>", file=out) def main():
drivers/net/tap/meson.build +9 -8
@@ -7,13 +7,19 @@ if not is_linux endif sources = files( 'rte_eth_tap.c', - 'tap_bpf_api.c', - 'tap_flow.c', 'tap_intr.c', 'tap_netlink.c', - 'tap_tcmsgs.c', ) +if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT') + cflags += '-DHAVE_TCA_FLOWER' + sources += files( + 'tap_bpf_api.c', + 'tap_flow.c', + 'tap_tcmsgs.c', + ) +endif + deps = ['bus_vdev', 'gso', 'hash'] cflags += '-DTAP_MAX_QUEUES=8'
@@ -23,12 +29,7 @@ cflags += '-DTAP_MAX_QUEUES=8' # "enum/define", "symbol to search" ] # args = [ - [ 'HAVE_TC_FLOWER', 'linux/pkt_cls.h', 'TCA_FLOWER_UNSPEC' ], - [ 'HAVE_TC_VLAN_ID', 'linux/pkt_cls.h', 'TCA_FLOWER_KEY_VLAN_PRIO' ], - [ 'HAVE_TC_BPF', 'linux/pkt_cls.h', 'TCA_BPF_UNSPEC' ], - [ 'HAVE_TC_BPF_FD', 'linux/pkt_cls.h', 'TCA_BPF_FD' ], [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ], - [ 'HAVE_TC_ACT_BPF_FD', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_FD' ], ] config = configuration_data() foreach arg:args
drivers/net/tap/rte_eth_tap.c +32 -6
@@ -1124,12 +1124,15 @@ tap_dev_close(struct rte_eth_dev *dev)if (!internals->persist)tap_link_set_down (dev); + +#ifdef HAVE_TCA_FLOWER if (internals->nlsk_fd !=-1 ) {tap_flow_flush (dev,NULL );tap_flow_implicit_flush (internals,NULL );tap_nl_final (internals->nlsk_fd); internals->nlsk_fd =-1 ; } +#endif for (i =0 ; i <RTE_PMD_TAP_MAX_QUEUES ; i++) {struct rx_queue *rxq = &internals->rxq[i];
@@ -1265,6 +1268,7 @@ tap_promisc_enable(struct rte_eth_dev *dev)if (ret !=0 )return ret; +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) { dev->data->promiscuous =1 ; ret =tap_flow_implicit_create (pmd,TAP_REMOTE_PROMISC );
@@ -1278,7 +1282,7 @@ tap_promisc_enable(struct rte_eth_dev *dev) return ret; } } - +#endif return 0 ; }
@@ -1293,6 +1297,7 @@ tap_promisc_disable(struct rte_eth_dev *dev)if (ret !=0 )return ret; +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) { dev->data->promiscuous =0 ; ret =tap_flow_implicit_destroy (pmd,TAP_REMOTE_PROMISC );
@@ -1306,6 +1311,7 @@ tap_promisc_disable(struct rte_eth_dev *dev) return ret; } } +#endif return 0 ; }
@@ -1321,6 +1327,7 @@ tap_allmulti_enable(struct rte_eth_dev *dev)if (ret !=0 )return ret; +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) { dev->data->all_multicast =1 ; ret =tap_flow_implicit_create (pmd,TAP_REMOTE_ALLMULTI );
@@ -1334,6 +1341,7 @@ tap_allmulti_enable(struct rte_eth_dev *dev) return ret; } } +#endif return 0 ; }
@@ -1349,6 +1357,7 @@ tap_allmulti_disable(struct rte_eth_dev *dev)if (ret !=0 )return ret; +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) { dev->data->all_multicast =0 ; ret =tap_flow_implicit_destroy (pmd,TAP_REMOTE_ALLMULTI );
@@ -1362,6 +1371,7 @@ tap_allmulti_disable(struct rte_eth_dev *dev) return ret; } } +#endif return 0 ; }
@@ -1407,6 +1417,8 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)if (ret <0 )return ret;rte_memcpy (&pmd->eth_addr, mac_addr,RTE_ETHER_ADDR_LEN ); + +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) {/* Replace MAC redirection rule after a MAC change */ ret =tap_flow_implicit_destroy (pmd,TAP_REMOTE_LOCAL_MAC );
@@ -1424,6 +1436,7 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr) return ret; } } +#endif return 0 ; }
@@ -1901,7 +1914,9 @@ static const struct eth_dev_ops ops = { .stats_reset = tap_stats_reset, .dev_supported_ptypes_get = tap_dev_supported_ptypes_get, .rss_hash_update = tap_rss_hash_update, +#ifdef HAVE_TCA_FLOWER .flow_ops_get = tap_dev_flow_ops_get, +#endif }; static int
@@ -1941,7 +1956,9 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,strlcpy (pmd->name, tap_name,sizeof (pmd->name)); pmd->type = type; pmd->ka_fd =-1 ; +#ifdef HAVE_TCA_FLOWER pmd->nlsk_fd =-1 ; +#endif pmd->gso_ctx_mp =NULL ; pmd->ioctl_sock =socket (AF_INET ,SOCK_DGRAM ,0 );
@@ -2021,6 +2038,14 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,/* Make network device persist after application exit */ pmd->persist = persist; + pmd->if_index =if_nametoindex (pmd->name); +if (!pmd->if_index) { +TAP_LOG (ERR ,"%s: failed to get if_index." , pmd->name); + goto disable_rte_flow; + } + + +#ifdef HAVE_TCA_FLOWER /* * Set up everything related to rte_flow: * - netlink socket
@@ -2035,11 +2060,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, pmd->name); goto disable_rte_flow; } - pmd->if_index =if_nametoindex (pmd->name); -if (!pmd->if_index) { -TAP_LOG (ERR ,"%s: failed to get if_index." , pmd->name); - goto disable_rte_flow; - }if (qdisc_create_multiq (pmd->nlsk_fd, pmd->if_index) <0 ) {TAP_LOG (ERR ,"%s: failed to create multiq qdisc." , pmd->name);
@@ -2050,6 +2070,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, pmd->name); goto disable_rte_flow; } +LIST_INIT (&pmd->flows);if (strlen (remote_iface)) {
@@ -2102,6 +2123,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, goto error_remote; } } +#endif rte_eth_dev_probing_finish (dev);return 0 ;
@@ -2116,14 +2138,18 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,rte_eth_dev_probing_finish (dev);return 0 ; +#ifdef HAVE_TCA_FLOWER error_remote:TAP_LOG (ERR ," Can't set up remote feature: %s(%d)" ,strerror (errno), errno);tap_flow_implicit_flush (pmd,NULL ); +#endif error_exit: +#ifdef HAVE_TCA_FLOWER if (pmd->nlsk_fd !=-1 )close (pmd->nlsk_fd); +#endif if (pmd->ka_fd !=-1 )close (pmd->ka_fd);if (pmd->ioctl_sock !=-1 )
drivers/net/tap/rte_eth_tap.h +6 -1
@@ -16,6 +16,7 @@#include <ethdev_driver.h> #include <rte_ether.h> #include <rte_gso.h> +#include "tap_log.h" #ifdef IFF_MULTI_QUEUE
@@ -70,15 +71,17 @@ struct pmd_internals {char remote_iface[RTE_ETH_NAME_MAX_LEN ];/* Remote netdevice name */ char name[RTE_ETH_NAME_MAX_LEN ];/* Internal Tap device name */ int type;/* Type field - TUN|TAP */ +int persist;/* 1 if keep link up, else 0 */ struct rte_ether_addr eth_addr;/* Mac address of the device port */ struct ifreq remote_initial_flags;/* Remote netdevice flags on init */ int remote_if_index;/* remote netdevice IF_INDEX */ int if_index;/* IF_INDEX for the port */ int ioctl_sock;/* socket for ioctl calls */ + +#ifdef HAVE_TCA_FLOWER int nlsk_fd;/* Netlink socket fd */ int flow_isolate;/* 1 if flow isolation is enabled */ int rss_enabled;/* 1 if RSS is enabled, else 0 */ -int persist;/* 1 if keep link up, else 0 */ /* implicit rules set when RSS is enabled */ int map_fd;/* BPF RSS map fd */ int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */
@@ -86,6 +89,8 @@ struct pmd_internals { LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */ LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows; +#endif +struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES ];/* List of RX queues */ struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES ];/* List of TX queues */ struct rte_intr_handle *intr_handle;/* LSC interrupt handle. */
drivers/net/tap/tap_bpf.h deleted +0 -121
121 lines not on this page · raw message
drivers/net/tap/tap_bpf_api.c +13 -7
@@ -2,19 +2,19 @@* Copyright 2017 Mellanox Technologies, Ltd */ -#include <errno.h> -#include <string.h> #include <unistd.h> -#include <sys/queue.h> +#include <syscall.h> +#include <linux/bpf.h> -#include <rte_malloc.h> -#include <rte_eth_tap.h> #include <tap_flow.h> #include <tap_autoconf.h> -#include <tap_tcmsgs.h> -#include <tap_bpf.h> +#include <tap_bpf_insns.h> + +static int bpf_load (enum bpf_prog_type type,const struct bpf_insn *insns, +size_t insns_cnt,const char *license); +/** * Load BPF program (section cls_q) into the kernel and return a bpf fd *
@@ -89,7 +89,13 @@ static inline __u64 ptr_to_u64(const void *ptr)static inline int sys_bpf (enum bpf_cmd cmd,union bpf_attr *attr,unsigned int size) { +#ifdef __NR_bpfreturn syscall (__NR_bpf, cmd, attr, size); +#else +TAP_LOG (ERR ,"No bpf syscall, kernel headers too old?\n" ); + errno =ENOSYS ; +return -1 ; +#endif }/**
drivers/net/tap/tap_bpf_insns.h +0 -2
@@ -3,8 +3,6 @@* This not the original source file. Do NOT edit it. */ -#include <tap_bpf.h> -static struct bpf_insn cls_q_insns[] = { {0x61 ,2 ,1 ,52 ,0x00000000 }, {0x18 ,3 ,0 ,0 ,0xdeadbeef },
drivers/net/tap/tap_flow.c +0 -90
96 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v7 5/8 net/tap: rewrite the RSS BPF program
In reply to Stephen HemmingerRewrite the BPF program used to do queue based RSS. Important changes:
- uses newer BPF map format BTF
- accepts key as parameter rather than constant default
- can do L3 or L4 hashing
- supports IPv4 options
- supports IPv6 extension headers
- restructured for readability
The usage of BPF is different as well:
- the incoming configuration is looked up based on class parameters rather than patching the BPF.
- the resulting queue is placed in skb rather than requiring a second pass through classifier step.
Note: This version only works with later patch to enable it on the DPDK driver side. It is submitted as an incremental patch to allow for easier review. Bisection still works because the old instruction are still present for now.
--- .gitignore | 3 - drivers/net/tap/bpf/Makefile | 19 -- drivers/net/tap/bpf/README | 38 ++++ drivers/net/tap/bpf/bpf_api.h | 276 -------------------------- drivers/net/tap/bpf/bpf_elf.h | 53 ----- drivers/net/tap/bpf/bpf_extract.py | 85 -------- drivers/net/tap/bpf/meson.build | 81 ++++++++ drivers/net/tap/bpf/tap_bpf_program.c | 255 ------------------------ drivers/net/tap/bpf/tap_rss.c | 264 ++++++++++++++++++++++++ 9 files changed, 383 insertions(+), 691 deletions(-) delete mode 100644 drivers/net/tap/bpf/Makefile create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py create mode 100644 drivers/net/tap/bpf/meson.build delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c
.gitignore +0 -3
@@ -36,9 +36,6 @@ TAGS # ignore python bytecode files *.pyc -# ignore BPF programs -drivers/net/tap/bpf/tap_bpf_program.o - # DTS results dts/output
drivers/net/tap/bpf/Makefile deleted +0 -19
@@ -1,19 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# This file is not built as part of normal DPDK build. -# It is used to generate the eBPF code for TAP RSS. - -CLANG=clang -CLANG_OPTS=-O2 -TARGET=../tap_bpf_insns.h - -all: $(TARGET) - -clean: - rm tap_bpf_program.o $(TARGET) - -tap_bpf_program.o: tap_bpf_program.c - $(CLANG) $(CLANG_OPTS) -emit-llvm -c $< -o - | \ - llc -march=bpf -filetype=obj -o $@ - -$(TARGET): tap_bpf_program.o - python3 bpf_extract.py -stap_bpf_program.c -o $@ $<
drivers/net/tap/bpf/README new file +38 -0
@@ -0,0 +1,38 @@ +This is the BPF program used to implement the RSS across queues flow action. +The program is loaded when first RSS flow rule is created and is never unloaded. + +Each flow rule creates a unique key (handle) and this is used as the key +for finding the RSS information for that flow rule. + +This version is built the BPF Compile Once — Run Everywhere (CO-RE) +framework and uses libbpf and bpftool. + +Limitations +----------- +- requires libbpf to run +- rebuilding the BPF requires Clang and bpftool. + Some older versions of Ubuntu do not have working bpftool package. + Need a version of Clang that can compile to BPF. +- only standard Toeplitz hash with standard 40 byte key is supported +- the number of flow rules using RSS is limited to 32 + +Building +-------- +During the DPDK build process the meson build file checks that +libbpf, bpftool, and clang are not available. If everything is +there then BPF RSS is enabled. + +1. Using clang to compile tap_rss.c the tap_rss.bpf.o file. + +2. Using bpftool generate a skeleton header file tap_rss.skel.h from tap_rss.bpf.o. + This skeleton header is an large byte array which contains the + BPF binary and wrappers to load and use it. + +3. The tap flow code then compiles that BPF byte array into the PMD object. + +4. When needed the BPF array is loaded by libbpf. + +References +---------- +BPF and XDP reference guide +https://docs.cilium.io/en/latest/bpf/progtypes/
drivers/net/tap/bpf/bpf_api.h deleted +0 -276
276 lines not on this page · raw message
drivers/net/tap/bpf/bpf_elf.h deleted +0 -53
53 lines not on this page · raw message
drivers/net/tap/bpf/bpf_extract.py deleted +0 -85
85 lines not on this page · raw message
drivers/net/tap/bpf/meson.build new file +81 -0
81 lines not on this page · raw message
drivers/net/tap/bpf/tap_bpf_program.c deleted +0 -255
255 lines not on this page · raw message
drivers/net/tap/bpf/tap_rss.c new file +264 -0
264 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v7 6/8 net/tap: use libbpf to load new BPF program
In reply to Stephen HemmingerThere were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.
Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.
The new BPF program only needs a single action.
No need for action and re-classification step.
It also fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.
--- drivers/net/tap/bpf/meson.build | 34 ++- drivers/net/tap/bpf/tap_rss.c | 45 ++-- drivers/net/tap/meson.build | 35 ++- drivers/net/tap/rte_eth_tap.c | 14 +- drivers/net/tap/rte_eth_tap.h | 6 +- drivers/net/tap/tap_flow.c | 408 +++++++------------------------- drivers/net/tap/tap_flow.h | 17 +- drivers/net/tap/tap_rss.h | 10 +- drivers/net/tap/tap_tcmsgs.h | 4 +- 9 files changed, 179 insertions(+), 394 deletions(-)
drivers/net/tap/bpf/meson.build +31 -3
@@ -3,15 +3,26 @@ enable_tap_rss = false -libbpf = dependency('libbpf', required: false, method: 'pkg-config') +# Loading BPF requires libbpf +# and the bpf_map__XXX API's were introduced in 0.8.0 +libbpf = dependency('libbpf', version: '>= 1.0', + required: false, method: 'pkg-config') if not libbpf.found() message('net/tap: no RSS support missing libbpf') subdir_done() endif +# Making skeleton needs bpftool # Debian install this in /usr/sbin which is not in $PATH -bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false, version: '>= 5.6.0') -if not bpftool.found() +bpftool_supports_skel = false +bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false) +if bpftool.found() + # Some Ubuntu has non-functional bpftool + bpftool_supports_skel = run_command(bpftool, 'gen', 'help', + check:false).returncode() == 0 +endif + +if not bpftool_supports_skel message('net/tap: no RSS support missing bpftool') subdir_done() endif
@@ -42,6 +53,7 @@ clang_flags = [ '-O2', '-Wall', '-Wextra', + max_queues, '-target', 'bpf', '-g',
@@ -67,6 +79,22 @@ skel_h_cmd = [ '@INPUT@' ] +vmlinux_h_cmd = [ + bpftool, + 'btf', + 'dump', + 'file', + '/sys/kernel/btf/vmlinux', + 'format', + 'c' +] + +vmlinux_h = custom_target( + 'vmlinux.h', + output: 'vmlinux.h', + command: vmlinux_h_cmd, + capture: true) + tap_rss_o = custom_target( 'tap_rss.bpf.o', input: 'tap_rss.c',
drivers/net/tap/bpf/tap_rss.c +24 -21
67 lines not on this page · raw message
drivers/net/tap/meson.build +15 -20
@@ -5,36 +5,31 @@ if not is_linux build = false reason = 'only supported on Linux' endif + sources = files( 'rte_eth_tap.c', 'tap_intr.c', 'tap_netlink.c', ) +deps = ['bus_vdev', 'gso', 'hash'] + +max_queues = '-DTAP_MAX_QUEUES=16' +cflags += max_queues + +require_iova_in_mbuf = false + if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT') cflags += '-DHAVE_TCA_FLOWER' sources += files( - 'tap_bpf_api.c', 'tap_flow.c', 'tap_tcmsgs.c', ) -endif -deps = ['bus_vdev', 'gso', 'hash'] - -cflags += '-DTAP_MAX_QUEUES=8' - -# input array for meson symbol search: -# [ "MACRO to define if found", "header for the search", -# "enum/define", "symbol to search" ] -# -args = [ - [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ], -] -config = configuration_data() -foreach arg:args - config.set(arg[0], cc.has_header_symbol(arg[1], arg[2])) -endforeach -configure_file(output : 'tap_autoconf.h', configuration : config) - -require_iova_in_mbuf = false + subdir('bpf') + if enable_tap_rss + cflags += '-DHAVE_BPF_RSS' + ext_deps += libbpf + sources += tap_rss_skel_h + endif +endif
drivers/net/tap/rte_eth_tap.c +7 -7
@@ -1131,6 +1131,7 @@ tap_dev_close(struct rte_eth_dev *dev)tap_flow_implicit_flush (internals,NULL );tap_nl_final (internals->nlsk_fd); internals->nlsk_fd =-1 ; + tap_flow_bpf_destroy(internals); }#endif
@@ -1956,6 +1957,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,strlcpy (pmd->name, tap_name,sizeof (pmd->name)); pmd->type = type; pmd->ka_fd =-1 ; +#ifdef HAVE_TCA_FLOWER pmd->nlsk_fd =-1 ;#endif
@@ -2038,13 +2040,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,/* Make network device persist after application exit */ pmd->persist = persist; - pmd->if_index =if_nametoindex (pmd->name); -if (!pmd->if_index) { -TAP_LOG (ERR ,"%s: failed to get if_index." , pmd->name); - goto disable_rte_flow; - } - -#ifdef HAVE_TCA_FLOWER /* * Set up everything related to rte_flow:
@@ -2060,6 +2055,11 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, pmd->name); goto disable_rte_flow; } + pmd->if_index =if_nametoindex (pmd->name); +if (!pmd->if_index) { +TAP_LOG (ERR ,"%s: failed to get if_index." , pmd->name); + goto disable_rte_flow; + }if (qdisc_create_multiq (pmd->nlsk_fd, pmd->if_index) <0 ) {TAP_LOG (ERR ,"%s: failed to create multiq qdisc." , pmd->name);
drivers/net/tap/rte_eth_tap.h +2 -4
@@ -81,10 +81,8 @@ struct pmd_internals {#ifdef HAVE_TCA_FLOWER int nlsk_fd;/* Netlink socket fd */ int flow_isolate;/* 1 if flow isolation is enabled */ -int rss_enabled;/* 1 if RSS is enabled, else 0 */ -/* implicit rules set when RSS is enabled */ -int map_fd;/* BPF RSS map fd */ -int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */ + +struct tap_rss *rss;/* BPF program */ LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */
drivers/net/tap/tap_flow.c +89 -319
536 lines not on this page · raw message
drivers/net/tap/tap_flow.h +6 -11
@@ -9,7 +9,11 @@#include <rte_flow.h> #include <rte_flow_driver.h> #include <rte_eth_tap.h> -#include <tap_autoconf.h> + +/** +* Mask of unsupported RSS types +*/ +#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP))/** * In TC, priority 0 means we require the kernel to allocate one for us.
@@ -41,11 +45,6 @@ enum implicit_rule_index { TAP_REMOTE_MAX_IDX, }; -enum bpf_fd_idx { -SEC_L3_L4 , -SEC_MAX , -}; -int tap_dev_flow_ops_get (struct rte_eth_dev *dev,const struct rte_flow_ops **ops);int tap_flow_flush (struct rte_eth_dev *dev,struct rte_flow_error *error);
@@ -57,10 +56,6 @@ int tap_flow_implicit_destroy(struct pmd_internals *pmd,int tap_flow_implicit_flush (struct pmd_internals *pmd,struct rte_flow_error *error); -int tap_flow_bpf_cls_q (__u32 queue_idx); -int tap_flow_bpf_calc_l3_l4_hash (__u32 key_idx,int map_fd); -int tap_flow_bpf_rss_map_create (unsigned int key_size,unsigned int value_size, -unsigned int max_entries); -int tap_flow_bpf_update_rss_elem (int fd,void *key,void *value); +void tap_flow_bpf_destroy (struct pmd_internals *pmd);#endif /* _TAP_FLOW_H_ */
drivers/net/tap/tap_rss.h +4 -6
@@ -5,16 +5,14 @@#ifndef _TAP_RSS_H_#define _TAP_RSS_H_ -#ifndef TAP_MAX_QUEUES -#define TAP_MAX_QUEUES 16 +/* Size of the map from BPF classid to queue table */ +#ifndef TAP_RSS_MAX +#define TAP_RSS_MAX 32#endif -/* Fixed RSS hash key size in bytes. */ +/* Standard Toeplitz hash key size */ #define TAP_RSS_HASH_KEY_SIZE 40 -/* Supported RSS */ -#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP)) -/* hashed fields for RSS */ enum hash_field { HASH_FIELD_IPV4_L3, /* IPv4 src/dst addr */
drivers/net/tap/tap_tcmsgs.h +1 -3
@@ -6,7 +6,6 @@#ifndef _TAP_TCMSGS_H_#define _TAP_TCMSGS_H_ -#include <tap_autoconf.h> #include <linux/if_ether.h> #include <linux/rtnetlink.h> #include <linux/pkt_sched.h>
@@ -14,9 +13,8 @@#include <linux/tc_act/tc_mirred.h> #include <linux/tc_act/tc_gact.h> #include <linux/tc_act/tc_skbedit.h> -#ifdef HAVE_TC_ACT_BPF #include <linux/tc_act/tc_bpf.h> -#endif +#include <inttypes.h> #include <rte_ether.h>
Signature · 1 line
2.43.0
PATCH v7 7/8 net/tap: remove no longer used files
In reply to Stephen HemmingerThe BPF api was replaced by use of libbpf.
And the BPF instruction header was replaced by the skeleton.
--- drivers/net/tap/tap_bpf_api.c | 196 ---- drivers/net/tap/tap_bpf_insns.h | 1741 ------------------------------- 2 files changed, 1937 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h
drivers/net/tap/tap_bpf_api.c deleted +0 -196
@@ -1,196 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright 2017 Mellanox Technologies, Ltd -*/ - -#include <unistd.h> -#include <syscall.h> -#include <linux/bpf.h> - -#include <tap_flow.h> -#include <tap_autoconf.h> - -#include <tap_bpf_insns.h> - - -static int bpf_load (enum bpf_prog_type type,const struct bpf_insn *insns, -size_t insns_cnt,const char *license); - -/** -* Load BPF program (section cls_q) into the kernel and return a bpf fd -* -* @param queue_idx -* Queue index matching packet cb -* -* @return -* -1 if the BPF program couldn't be loaded. An fd (int) otherwise. -*/ -int tap_flow_bpf_cls_q (__u32 queue_idx) -{ - cls_q_insns[1 ].imm = queue_idx; - -return bpf_load (BPF_PROG_TYPE_SCHED_CLS , - (struct bpf_insn *)cls_q_insns, -RTE_DIM (cls_q_insns), -"Dual BSD/GPL" ); -} - -/** -* Load BPF program (section l3_l4) into the kernel and return a bpf fd. -* -* @param[in] key_idx -* RSS MAP key index -* -* @param[in] map_fd -* BPF RSS map file descriptor -* -* @return -* -1 if the BPF program couldn't be loaded. An fd (int) otherwise. -*/ -int tap_flow_bpf_calc_l3_l4_hash (__u32 key_idx,int map_fd) -{ - l3_l4_hash_insns[4 ].imm = key_idx; - l3_l4_hash_insns[9 ].imm = map_fd; - -return bpf_load (BPF_PROG_TYPE_SCHED_ACT , - (struct bpf_insn *)l3_l4_hash_insns, -RTE_DIM (l3_l4_hash_insns), -"Dual BSD/GPL" ); -} - -/** -* Helper function to convert a pointer to unsigned 64 bits -* -* @param[in] ptr -* pointer to address -* -* @return -* 64 bit unsigned long type of pointer address -*/ -static inline __u64 ptr_to_u64 (const void *ptr) -{ -return (__u64 )(unsigned long )ptr; -} - -/** -* Call BPF system call -* -* @param[in] cmd -* BPF command for program loading, map creation, map entry update, etc -* -* @param[in] attr -* System call attributes relevant to system call command -* -* @param[in] size -* size of attr parameter -* -* @return -* -1 if BPF system call failed, 0 otherwise -*/ -static inline int sys_bpf (enum bpf_cmd cmd,union bpf_attr *attr, -unsigned int size) -{ -#ifdef __NR_bpf -return syscall (__NR_bpf, cmd, attr, size); -#else -TAP_LOG (ERR ,"No bpf syscall, kernel headers too old?\n" ); - errno =ENOSYS ; -return -1 ; -#endif -} - -/** -* Load BPF instructions to kernel -* -* @param[in] type -* BPF program type: classifier or action -* -* @param[in] insns -* Array of BPF instructions (equivalent to BPF instructions) -* -* @param[in] insns_cnt -* Number of BPF instructions (size of array) -* -* @param[in] license -* License string that must be acknowledged by the kernel -* -* @return -* -1 if the BPF program couldn't be loaded, fd (file descriptor) otherwise -*/ -static int bpf_load (enum bpf_prog_type type, -const struct bpf_insn *insns, -size_t insns_cnt, -const char *license) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - attr.prog_type = type; - attr.insn_cnt = (__u32 )insns_cnt; - attr.insns =ptr_to_u64 (insns); - attr.license =ptr_to_u64 (license); - attr.log_buf =ptr_to_u64 (NULL ); - attr.log_level =0 ; - attr.kern_version =0 ; - -return sys_bpf (BPF_PROG_LOAD , &attr,sizeof (attr)); -} - -/** -* Create BPF map for RSS rules -* -* @param[in] key_size -* map RSS key size -* -* @param[in] value_size -* Map RSS value size -* -* @param[in] max_entries -* Map max number of RSS entries (limit on max RSS rules) -* -* @return -* -1 if BPF map couldn't be created, map fd otherwise -*/ -int tap_flow_bpf_rss_map_create (unsigned int key_size, -unsigned int value_size, -unsigned int max_entries) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - attr.map_type =BPF_MAP_TYPE_HASH ; - attr.key_size = key_size; - attr.value_size = value_size; - attr.max_entries = max_entries; - -return sys_bpf (BPF_MAP_CREATE , &attr,sizeof (attr)); -} - -/** -* Update RSS entry in BPF map -* -* @param[in] fd -* RSS map fd -* -* @param[in] key -* Pointer to RSS key whose entry is updated -* -* @param[in] value -* Pointer to RSS new updated value -* -* @return -* -1 if RSS entry failed to be updated, 0 otherwise -*/ -int tap_flow_bpf_update_rss_elem (int fd,void *key,void *value) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - - attr.map_type =BPF_MAP_TYPE_HASH ; - attr.map_fd = fd; - attr.key =ptr_to_u64 (key); - attr.value =ptr_to_u64 (value); - attr.flags =BPF_ANY ; - -return sys_bpf (BPF_MAP_UPDATE_ELEM , &attr,sizeof (attr)); -}
drivers/net/tap/tap_bpf_insns.h deleted +0 -1741
1,741 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v7 8/8 doc: update documentation of TAP PMD
In reply to Stephen HemmingerThe driver support of flows has changed and the wording in the guide was awkward.
Drop references to DPDK pktgen in this documentation since it is not required and confusing.
--- doc/guides/linux_gsg/sys_reqs.rst | 3 + doc/guides/nics/tap.rst | 268 ++++++++---------------------- 2 files changed, 74 insertions(+), 197 deletions(-)
doc/guides/linux_gsg/sys_reqs.rst +3 -0
@@ -101,6 +101,9 @@ Running DPDK Applications To run a DPDK application, some customization may be required on the target machine. +.. _linux_gsg_kernel_version: + + System Software ~~~~~~~~~~~~~~~
doc/guides/nics/tap.rst +71 -197
327 lines not on this page · raw message
Signature · 1 line
2.43.0
v8 cover net/tap: cleanups and fix BPF support
In reply to Stephen HemmingerThe support of doing RSS for rte_flow_action was a cool idea but it has been broken for several releases of DPDK as the kernel and BPF infrastructure changed.
This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF toolchain.
The result should be easier to read and maintain.
Stephen Hemminger (8):
net/tap: do not duplicate fd's
net/tap: remove unused fields
net/tap: validate and setup parameters for BPF RSS net/tap: do not build flow support if header is out of date net/tap: rewrite the RSS BPF program
net/tap: use libbpf to load new BPF program net/tap: remove no longer used files
doc: update documentation of TAP PMD
v8 - fix build with CentOS 7. Although CentOS will soon
be unsupported in DPDK.
.gitignore | 3 - doc/guides/linux_gsg/sys_reqs.rst | 3 + doc/guides/nics/tap.rst | 274 ++-- drivers/net/tap/bpf/Makefile | 19 - drivers/net/tap/bpf/README | 38 + drivers/net/tap/bpf/bpf_api.h | 276 ---- drivers/net/tap/bpf/bpf_elf.h | 53 - drivers/net/tap/bpf/bpf_extract.py | 86 -- drivers/net/tap/bpf/meson.build | 107 ++ drivers/net/tap/bpf/tap_bpf_program.c | 255 ---- drivers/net/tap/bpf/tap_rss.c | 267 ++++ drivers/net/tap/meson.build | 42 +- drivers/net/tap/rte_eth_tap.c | 225 ++-- drivers/net/tap/rte_eth_tap.h | 20 +- drivers/net/tap/tap_bpf.h | 121 -- drivers/net/tap/tap_bpf_api.c | 190 --- drivers/net/tap/tap_bpf_insns.h | 1743 ------------------------- drivers/net/tap/tap_flow.c | 559 +++----- drivers/net/tap/tap_flow.h | 17 +- drivers/net/tap/tap_intr.c | 7 +- drivers/net/tap/tap_rss.h | 21 +- drivers/net/tap/tap_tcmsgs.h | 4 +- 22 files changed, 801 insertions(+), 3529 deletions(-) delete mode 100644 drivers/net/tap/bpf/Makefile create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py create mode 100644 drivers/net/tap/bpf/meson.build delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c delete mode 100644 drivers/net/tap/tap_bpf.h delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h
Signature · 1 line
2.43.0
PATCH v8 1/8 net/tap: do not duplicate fd's
The TAP device can use same file descriptopr for both rx and tx queues. This allows up to 8 queues (versus 4).
--- drivers/net/tap/meson.build | 2 +- drivers/net/tap/rte_eth_tap.c | 197 +++++++++++++++------------------- drivers/net/tap/rte_eth_tap.h | 3 +- drivers/net/tap/tap_flow.c | 3 +- drivers/net/tap/tap_intr.c | 7 +- 5 files changed, 92 insertions(+), 120 deletions(-)
drivers/net/tap/meson.build +1 -1
@@ -16,7 +16,7 @@ sources = files( deps = ['bus_vdev', 'gso', 'hash'] -cflags += '-DTAP_MAX_QUEUES=16' +cflags += '-DTAP_MAX_QUEUES=8' # input array for meson symbol search: # [ "MACRO to define if found", "header for the search",
drivers/net/tap/rte_eth_tap.c +84 -113
343 lines not on this page · raw message
drivers/net/tap/rte_eth_tap.h +1 -2
@@ -96,8 +96,7 @@ struct pmd_internals { };struct pmd_process_private { -int rxq_fds[RTE_PMD_TAP_MAX_QUEUES ]; -int txq_fds[RTE_PMD_TAP_MAX_QUEUES ]; +int fds[RTE_PMD_TAP_MAX_QUEUES ]; };/* tap_intr.c */
drivers/net/tap/tap_flow.c +2 -1
@@ -1595,8 +1595,9 @@ tap_flow_isolate(struct rte_eth_dev *dev,* If netdevice is there, setup appropriate flow rules immediately. * Otherwise it will be set when bringing up the netdevice (tun_alloc). */ -if (!process_private->rxq_fds[0 ]) +if (process_private->fds[0 ] ==-1 )return 0 ; +if (set) {struct rte_flow *remote_flow;
drivers/net/tap/tap_intr.c +4 -3
@@ -68,9 +68,11 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev) }for (i =0 ; i < n; i++) {struct rx_queue *rxq = pmd->dev->data->rx_queues[i]; +int fd = process_private->fds[i];/* Skip queues that cannot request interrupts. */ -if (!rxq || process_private->rxq_fds[i] ==-1 ) { +if (!rxq || fd ==-1 ) { +/* Use invalid intr_vec[] index to disable entry. */ /* Use invalid intr_vec[] index to disable entry. */ if (rte_intr_vec_list_index_set (intr_handle, i,RTE_INTR_VEC_RXTX_OFFSET +RTE_MAX_RXTX_INTR_VEC_ID ))
@@ -80,8 +82,7 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev)if (rte_intr_vec_list_index_set (intr_handle, i,RTE_INTR_VEC_RXTX_OFFSET + count))return -rte_errno; -if (rte_intr_efds_index_set (intr_handle, count, - process_private->rxq_fds[i])) +if (rte_intr_efds_index_set (intr_handle, count, fd))return -rte_errno; count++; }
Signature · 1 line
2.43.0
PATCH v8 2/8 net/tap: remove unused fields
In reply to Stephen HemmingerThe driver doesn't support these other hash types, and there is no reason to implement these in future. The rss_flows list was set but never used.
--- drivers/net/tap/rte_eth_tap.h | 4 +--- drivers/net/tap/tap_flow.c | 1 - drivers/net/tap/tap_rss.h | 6 ------ 3 files changed, 1 insertion(+), 10 deletions(-)
drivers/net/tap/rte_eth_tap.h +1 -3
@@ -77,14 +77,12 @@ struct pmd_internals {int ioctl_sock;/* socket for ioctl calls */ int nlsk_fd;/* Netlink socket fd */ int flow_isolate;/* 1 if flow isolation is enabled */ -int flower_support;/* 1 if kernel supports, else 0 */ -int flower_vlan_support;/* 1 if kernel supports, else 0 */ int rss_enabled;/* 1 if RSS is enabled, else 0 */ int persist;/* 1 if keep link up, else 0 */ /* implicit rules set when RSS is enabled */ int map_fd;/* BPF RSS map fd */ int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */ - LIST_HEAD(tap_rss_flows, rte_flow) rss_flows; + LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */ LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
drivers/net/tap/tap_flow.c +0 -1
@@ -1958,7 +1958,6 @@ static int rss_enable(struct pmd_internals *pmd, errno, strerror(errno));return err; } -LIST_INSERT_HEAD (&pmd->rss_flows, rss_flow, next); } pmd->rss_enabled =1 ;
drivers/net/tap/tap_rss.h +0 -6
@@ -21,12 +21,6 @@ enum hash_field {HASH_FIELD_IPV4_L3_L4 ,/* IPv4 src/dst addr + L4 src/dst ports */ HASH_FIELD_IPV6_L3 ,/* IPv6 src/dst addr */ HASH_FIELD_IPV6_L3_L4, /* IPv6 src/dst addr + L4 src/dst ports */ -HASH_FIELD_L2_SRC ,/* Ethernet src addr */ -HASH_FIELD_L2_DST ,/* Ethernet dst addr */ -HASH_FIELD_L3_SRC ,/* L3 src addr */ -HASH_FIELD_L3_DST ,/* L3 dst addr */ -HASH_FIELD_L4_SRC ,/* TCP/UDP src ports */ - HASH_FIELD_L4_DST, /* TCP/UDP dst ports */ }; struct rss_key {
Signature · 1 line
2.43.0
PATCH v8 3/8 net/tap: validate and setup parameters for BPF RSS
In reply to Stephen HemmingerThe flow RSS support via BPF was not using the key, or hash type parameters. Which is good because they were never properly setup.
Fix the setup and validate the flow parameters, the BPF side gets fixed later.
--- drivers/net/tap/tap_flow.c | 65 +++++++++++++++++++++++++++++++++++--- drivers/net/tap/tap_rss.h | 5 ++- 2 files changed, 62 insertions(+), 8 deletions(-)
drivers/net/tap/tap_flow.c +60 -5
@@ -11,9 +11,11 @@#include <rte_byteorder.h> #include <rte_jhash.h> +#include <rte_thash.h> #include <rte_random.h> #include <rte_malloc.h> #include <rte_eth_tap.h> +#include <tap_flow.h> #include <tap_autoconf.h> #include <tap_tcmsgs.h>
@@ -2061,6 +2063,21 @@ static int bpf_rss_key(enum bpf_rss_key_e cmd, __u32 *key_idx)return err; } + +/* Default RSS hash key also used by mlx devices */ +static const uint8_t rss_hash_default_key[] = { +0x2c ,0xc6 ,0x81 ,0xd1 , +0x5b ,0xdb ,0xf4 ,0xf7 , +0xfc ,0xa2 ,0x83 ,0x19 , +0xdb ,0x1a ,0x3e ,0x94 , +0x6b ,0x9e ,0x38 ,0xd9 , +0x2c ,0x9c ,0x03 ,0xd1 , +0xad ,0x99 ,0x44 ,0xa7 , +0xd9 ,0x56 ,0x3d ,0x59 , +0x06 ,0x3c ,0x25 ,0xf3 , +0xfc ,0x1f ,0xdc ,0x2a , +}; +/** * Add RSS hash calculations and queue selection *
@@ -2079,11 +2096,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,const struct rte_flow_action_rss *rss, struct rte_flow_error *error) { -/* 4096 is the maximum number of instructions for a BPF program */ + struct rss_key rss_entry = { }; +const uint8_t *key_in; +uint32_t hash_type =0 ;unsigned int i;int err; -struct rss_key rss_entry = { .hash_fields =0 , - .key_size =0 };/* Check supported RSS features */ if (rss->func !=RTE_ETH_HASH_FUNCTION_DEFAULT )
@@ -2095,6 +2112,41 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, (error,ENOTSUP ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL ,"a nonzero RSS encapsulation level is not supported" ); +if (rss->queue_num ==0 || rss->queue_num >=TAP_MAX_QUEUES ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL , +"invalid number of queues" ); + +/* allow RSS key_len 0 in case of NULL (default) RSS key. */ +if (rss->key_len ==0 ) { +if (rss->key !=NULL ) +return rte_flow_error_set (error,ENOTSUP , +RTE_FLOW_ERROR_TYPE_ACTION_CONF , + &rss->key_len,"RSS hash key length 0" ); + key_in = rss_hash_default_key; + }else { +if (rss->key_len !=TAP_RSS_HASH_KEY_SIZE ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"RSS hash invalid key length" ); +if (rss->key ==NULL ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"RSS hash key is NULL" ); + key_in = rss->key; + } + +if (rss->types &TAP_RSS_HF_MASK ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"RSS hash type not supported" ); + +if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV4_UDP |RTE_ETH_RSS_NONFRAG_IPV4_TCP )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV4_L3_L4 ); +else if (rss->types & (RTE_ETH_RSS_IPV4 |RTE_ETH_RSS_FRAG_IPV4 )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV4_L3 ); + +if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV6_UDP |RTE_ETH_RSS_NONFRAG_IPV6_TCP )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV6_L3_L4 ); +else if (rss->types & (RTE_ETH_RSS_IPV6 |RTE_ETH_RSS_FRAG_IPV6 |RTE_ETH_RSS_IPV6_EX )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV6_L3 ); +/* Get a new map key for a new RSS rule */ err =bpf_rss_key (KEY_CMD_GET , &flow->key_idx);if (err <0 ) {
@@ -2109,8 +2161,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, rss_entry.nb_queues = rss->queue_num;for (i =0 ; i < rss->queue_num; i++) rss_entry.queues[i] = rss->queue[i]; - rss_entry.hash_fields = - (1 <<HASH_FIELD_IPV4_L3_L4 ) | (1 <<HASH_FIELD_IPV6_L3_L4 ); + + rss_entry.hash_fields = hash_type; +rte_convert_rss_key ((const uint32_t *)key_in, (uint32_t *)rss_entry.key, +TAP_RSS_HASH_KEY_SIZE ); +/* Add this RSS entry to map */ err = tap_flow_bpf_update_rss_elem(pmd->map_fd,
drivers/net/tap/tap_rss.h +2 -3
@@ -24,11 +24,10 @@ enum hash_field { };struct rss_key { -__u8 key[128 ];__u32 hash_fields; -__u32 key_size; -__u32 queues[TAP_MAX_QUEUES ]; +__u8 key[TAP_RSS_HASH_KEY_SIZE ];__u32 nb_queues; +__u32 queues[TAP_MAX_QUEUES ]; } __attribute__((packed));#endif /* _TAP_RSS_H_ */
Signature · 1 line
2.43.0
PATCH v8 4/8 net/tap: do not build flow support if header is out of date
In reply to Stephen HemmingerThe proper place for finding bpf structures and functions is in linux/bpf.h. The original version was trying to workaround the case where the build environment was running on old pre BPF version of Glibc, but the target environment had BPF.
Having own private (and divergent) version headers leads to future problems when BPF definitions evolve.
If the build infrastructure is so old that TC flower is not supported, then the TAP device will build without any flow support.
--- drivers/net/tap/bpf/bpf_extract.py | 1 - drivers/net/tap/meson.build | 17 ++-- drivers/net/tap/rte_eth_tap.c | 38 +++++++-- drivers/net/tap/rte_eth_tap.h | 7 +- drivers/net/tap/tap_bpf.h | 121 ----------------------------- drivers/net/tap/tap_bpf_api.c | 20 +++-- drivers/net/tap/tap_bpf_insns.h | 2 - drivers/net/tap/tap_flow.c | 90 --------------------- 8 files changed, 60 insertions(+), 236 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf.h
drivers/net/tap/bpf/bpf_extract.py +0 -1
@@ -65,7 +65,6 @@ def write_header(out, source): print(f' * Auto-generated from {source}', file=out) print(" * This not the original source file. Do NOT edit it.", file=out) print(" */\n", file=out) - print("#include <tap_bpf.h>", file=out) def main():
drivers/net/tap/meson.build +9 -8
@@ -7,13 +7,19 @@ if not is_linux endif sources = files( 'rte_eth_tap.c', - 'tap_bpf_api.c', - 'tap_flow.c', 'tap_intr.c', 'tap_netlink.c', - 'tap_tcmsgs.c', ) +if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT') + cflags += '-DHAVE_TCA_FLOWER' + sources += files( + 'tap_bpf_api.c', + 'tap_flow.c', + 'tap_tcmsgs.c', + ) +endif + deps = ['bus_vdev', 'gso', 'hash'] cflags += '-DTAP_MAX_QUEUES=8'
@@ -23,12 +29,7 @@ cflags += '-DTAP_MAX_QUEUES=8' # "enum/define", "symbol to search" ] # args = [ - [ 'HAVE_TC_FLOWER', 'linux/pkt_cls.h', 'TCA_FLOWER_UNSPEC' ], - [ 'HAVE_TC_VLAN_ID', 'linux/pkt_cls.h', 'TCA_FLOWER_KEY_VLAN_PRIO' ], - [ 'HAVE_TC_BPF', 'linux/pkt_cls.h', 'TCA_BPF_UNSPEC' ], - [ 'HAVE_TC_BPF_FD', 'linux/pkt_cls.h', 'TCA_BPF_FD' ], [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ], - [ 'HAVE_TC_ACT_BPF_FD', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_FD' ], ] config = configuration_data() foreach arg:args
drivers/net/tap/rte_eth_tap.c +32 -6
@@ -1124,12 +1124,15 @@ tap_dev_close(struct rte_eth_dev *dev)if (!internals->persist)tap_link_set_down (dev); + +#ifdef HAVE_TCA_FLOWER if (internals->nlsk_fd !=-1 ) {tap_flow_flush (dev,NULL );tap_flow_implicit_flush (internals,NULL );tap_nl_final (internals->nlsk_fd); internals->nlsk_fd =-1 ; } +#endif for (i =0 ; i <RTE_PMD_TAP_MAX_QUEUES ; i++) {struct rx_queue *rxq = &internals->rxq[i];
@@ -1265,6 +1268,7 @@ tap_promisc_enable(struct rte_eth_dev *dev)if (ret !=0 )return ret; +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) { dev->data->promiscuous =1 ; ret =tap_flow_implicit_create (pmd,TAP_REMOTE_PROMISC );
@@ -1278,7 +1282,7 @@ tap_promisc_enable(struct rte_eth_dev *dev) return ret; } } - +#endif return 0 ; }
@@ -1293,6 +1297,7 @@ tap_promisc_disable(struct rte_eth_dev *dev)if (ret !=0 )return ret; +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) { dev->data->promiscuous =0 ; ret =tap_flow_implicit_destroy (pmd,TAP_REMOTE_PROMISC );
@@ -1306,6 +1311,7 @@ tap_promisc_disable(struct rte_eth_dev *dev) return ret; } } +#endif return 0 ; }
@@ -1321,6 +1327,7 @@ tap_allmulti_enable(struct rte_eth_dev *dev)if (ret !=0 )return ret; +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) { dev->data->all_multicast =1 ; ret =tap_flow_implicit_create (pmd,TAP_REMOTE_ALLMULTI );
@@ -1334,6 +1341,7 @@ tap_allmulti_enable(struct rte_eth_dev *dev) return ret; } } +#endif return 0 ; }
@@ -1349,6 +1357,7 @@ tap_allmulti_disable(struct rte_eth_dev *dev)if (ret !=0 )return ret; +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) { dev->data->all_multicast =0 ; ret =tap_flow_implicit_destroy (pmd,TAP_REMOTE_ALLMULTI );
@@ -1362,6 +1371,7 @@ tap_allmulti_disable(struct rte_eth_dev *dev) return ret; } } +#endif return 0 ; }
@@ -1407,6 +1417,8 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)if (ret <0 )return ret;rte_memcpy (&pmd->eth_addr, mac_addr,RTE_ETHER_ADDR_LEN ); + +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) {/* Replace MAC redirection rule after a MAC change */ ret =tap_flow_implicit_destroy (pmd,TAP_REMOTE_LOCAL_MAC );
@@ -1424,6 +1436,7 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr) return ret; } } +#endif return 0 ; }
@@ -1901,7 +1914,9 @@ static const struct eth_dev_ops ops = { .stats_reset = tap_stats_reset, .dev_supported_ptypes_get = tap_dev_supported_ptypes_get, .rss_hash_update = tap_rss_hash_update, +#ifdef HAVE_TCA_FLOWER .flow_ops_get = tap_dev_flow_ops_get, +#endif }; static int
@@ -1941,7 +1956,9 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,strlcpy (pmd->name, tap_name,sizeof (pmd->name)); pmd->type = type; pmd->ka_fd =-1 ; +#ifdef HAVE_TCA_FLOWER pmd->nlsk_fd =-1 ; +#endif pmd->gso_ctx_mp =NULL ; pmd->ioctl_sock =socket (AF_INET ,SOCK_DGRAM ,0 );
@@ -2021,6 +2038,14 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,/* Make network device persist after application exit */ pmd->persist = persist; + pmd->if_index =if_nametoindex (pmd->name); +if (!pmd->if_index) { +TAP_LOG (ERR ,"%s: failed to get if_index." , pmd->name); + goto disable_rte_flow; + } + + +#ifdef HAVE_TCA_FLOWER /* * Set up everything related to rte_flow: * - netlink socket
@@ -2035,11 +2060,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, pmd->name); goto disable_rte_flow; } - pmd->if_index =if_nametoindex (pmd->name); -if (!pmd->if_index) { -TAP_LOG (ERR ,"%s: failed to get if_index." , pmd->name); - goto disable_rte_flow; - }if (qdisc_create_multiq (pmd->nlsk_fd, pmd->if_index) <0 ) {TAP_LOG (ERR ,"%s: failed to create multiq qdisc." , pmd->name);
@@ -2050,6 +2070,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, pmd->name); goto disable_rte_flow; } +LIST_INIT (&pmd->flows);if (strlen (remote_iface)) {
@@ -2102,6 +2123,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, goto error_remote; } } +#endif rte_eth_dev_probing_finish (dev);return 0 ;
@@ -2116,14 +2138,18 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,rte_eth_dev_probing_finish (dev);return 0 ; +#ifdef HAVE_TCA_FLOWER error_remote:TAP_LOG (ERR ," Can't set up remote feature: %s(%d)" ,strerror (errno), errno);tap_flow_implicit_flush (pmd,NULL ); +#endif error_exit: +#ifdef HAVE_TCA_FLOWER if (pmd->nlsk_fd !=-1 )close (pmd->nlsk_fd); +#endif if (pmd->ka_fd !=-1 )close (pmd->ka_fd);if (pmd->ioctl_sock !=-1 )
drivers/net/tap/rte_eth_tap.h +6 -1
@@ -16,6 +16,7 @@#include <ethdev_driver.h> #include <rte_ether.h> #include <rte_gso.h> +#include "tap_log.h" #ifdef IFF_MULTI_QUEUE
@@ -70,15 +71,17 @@ struct pmd_internals {char remote_iface[RTE_ETH_NAME_MAX_LEN ];/* Remote netdevice name */ char name[RTE_ETH_NAME_MAX_LEN ];/* Internal Tap device name */ int type;/* Type field - TUN|TAP */ +int persist;/* 1 if keep link up, else 0 */ struct rte_ether_addr eth_addr;/* Mac address of the device port */ struct ifreq remote_initial_flags;/* Remote netdevice flags on init */ int remote_if_index;/* remote netdevice IF_INDEX */ int if_index;/* IF_INDEX for the port */ int ioctl_sock;/* socket for ioctl calls */ + +#ifdef HAVE_TCA_FLOWER int nlsk_fd;/* Netlink socket fd */ int flow_isolate;/* 1 if flow isolation is enabled */ int rss_enabled;/* 1 if RSS is enabled, else 0 */ -int persist;/* 1 if keep link up, else 0 */ /* implicit rules set when RSS is enabled */ int map_fd;/* BPF RSS map fd */ int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */
@@ -86,6 +89,8 @@ struct pmd_internals { LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */ LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows; +#endif +struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES ];/* List of RX queues */ struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES ];/* List of TX queues */ struct rte_intr_handle *intr_handle;/* LSC interrupt handle. */
drivers/net/tap/tap_bpf.h deleted +0 -121
121 lines not on this page · raw message
drivers/net/tap/tap_bpf_api.c +13 -7
@@ -2,19 +2,19 @@* Copyright 2017 Mellanox Technologies, Ltd */ -#include <errno.h> -#include <string.h> #include <unistd.h> -#include <sys/queue.h> +#include <syscall.h> +#include <linux/bpf.h> -#include <rte_malloc.h> -#include <rte_eth_tap.h> #include <tap_flow.h> #include <tap_autoconf.h> -#include <tap_tcmsgs.h> -#include <tap_bpf.h> +#include <tap_bpf_insns.h> + +static int bpf_load (enum bpf_prog_type type,const struct bpf_insn *insns, +size_t insns_cnt,const char *license); +/** * Load BPF program (section cls_q) into the kernel and return a bpf fd *
@@ -89,7 +89,13 @@ static inline __u64 ptr_to_u64(const void *ptr)static inline int sys_bpf (enum bpf_cmd cmd,union bpf_attr *attr,unsigned int size) { +#ifdef __NR_bpfreturn syscall (__NR_bpf, cmd, attr, size); +#else +TAP_LOG (ERR ,"No bpf syscall, kernel headers too old?\n" ); + errno =ENOSYS ; +return -1 ; +#endif }/**
drivers/net/tap/tap_bpf_insns.h +0 -2
@@ -3,8 +3,6 @@* This not the original source file. Do NOT edit it. */ -#include <tap_bpf.h> -static struct bpf_insn cls_q_insns[] = { {0x61 ,2 ,1 ,52 ,0x00000000 }, {0x18 ,3 ,0 ,0 ,0xdeadbeef },
drivers/net/tap/tap_flow.c +0 -90
96 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v8 5/8 net/tap: rewrite the RSS BPF program
In reply to Stephen HemmingerRewrite the BPF program used to do queue based RSS. Important changes:
- uses newer BPF map format BTF
- accepts key as parameter rather than constant default
- can do L3 or L4 hashing
- supports IPv4 options
- supports IPv6 extension headers
- restructured for readability
The usage of BPF is different as well:
- the incoming configuration is looked up based on class parameters rather than patching the BPF.
- the resulting queue is placed in skb rather than requiring a second pass through classifier step.
Note: This version only works with later patch to enable it on the DPDK driver side. It is submitted as an incremental patch to allow for easier review. Bisection still works because the old instruction are still present for now.
--- .gitignore | 3 - drivers/net/tap/bpf/Makefile | 19 -- drivers/net/tap/bpf/README | 38 ++++ drivers/net/tap/bpf/bpf_api.h | 276 -------------------------- drivers/net/tap/bpf/bpf_elf.h | 53 ----- drivers/net/tap/bpf/bpf_extract.py | 85 -------- drivers/net/tap/bpf/meson.build | 81 ++++++++ drivers/net/tap/bpf/tap_bpf_program.c | 255 ------------------------ drivers/net/tap/bpf/tap_rss.c | 264 ++++++++++++++++++++++++ 9 files changed, 383 insertions(+), 691 deletions(-) delete mode 100644 drivers/net/tap/bpf/Makefile create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py create mode 100644 drivers/net/tap/bpf/meson.build delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c
.gitignore +0 -3
@@ -36,9 +36,6 @@ TAGS # ignore python bytecode files *.pyc -# ignore BPF programs -drivers/net/tap/bpf/tap_bpf_program.o - # DTS results dts/output
drivers/net/tap/bpf/Makefile deleted +0 -19
@@ -1,19 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# This file is not built as part of normal DPDK build. -# It is used to generate the eBPF code for TAP RSS. - -CLANG=clang -CLANG_OPTS=-O2 -TARGET=../tap_bpf_insns.h - -all: $(TARGET) - -clean: - rm tap_bpf_program.o $(TARGET) - -tap_bpf_program.o: tap_bpf_program.c - $(CLANG) $(CLANG_OPTS) -emit-llvm -c $< -o - | \ - llc -march=bpf -filetype=obj -o $@ - -$(TARGET): tap_bpf_program.o - python3 bpf_extract.py -stap_bpf_program.c -o $@ $<
drivers/net/tap/bpf/README new file +38 -0
@@ -0,0 +1,38 @@ +This is the BPF program used to implement the RSS across queues flow action. +The program is loaded when first RSS flow rule is created and is never unloaded. + +Each flow rule creates a unique key (handle) and this is used as the key +for finding the RSS information for that flow rule. + +This version is built the BPF Compile Once — Run Everywhere (CO-RE) +framework and uses libbpf and bpftool. + +Limitations +----------- +- requires libbpf to run +- rebuilding the BPF requires Clang and bpftool. + Some older versions of Ubuntu do not have working bpftool package. + Need a version of Clang that can compile to BPF. +- only standard Toeplitz hash with standard 40 byte key is supported +- the number of flow rules using RSS is limited to 32 + +Building +-------- +During the DPDK build process the meson build file checks that +libbpf, bpftool, and clang are not available. If everything is +there then BPF RSS is enabled. + +1. Using clang to compile tap_rss.c the tap_rss.bpf.o file. + +2. Using bpftool generate a skeleton header file tap_rss.skel.h from tap_rss.bpf.o. + This skeleton header is an large byte array which contains the + BPF binary and wrappers to load and use it. + +3. The tap flow code then compiles that BPF byte array into the PMD object. + +4. When needed the BPF array is loaded by libbpf. + +References +---------- +BPF and XDP reference guide +https://docs.cilium.io/en/latest/bpf/progtypes/
drivers/net/tap/bpf/bpf_api.h deleted +0 -276
276 lines not on this page · raw message
drivers/net/tap/bpf/bpf_elf.h deleted +0 -53
53 lines not on this page · raw message
drivers/net/tap/bpf/bpf_extract.py deleted +0 -85
85 lines not on this page · raw message
drivers/net/tap/bpf/meson.build new file +81 -0
81 lines not on this page · raw message
drivers/net/tap/bpf/tap_bpf_program.c deleted +0 -255
255 lines not on this page · raw message
drivers/net/tap/bpf/tap_rss.c new file +264 -0
264 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v8 6/8 net/tap: use libbpf to load new BPF program
In reply to Stephen HemmingerThere were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.
Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.
The new BPF program only needs a single action.
No need for action and re-classification step.
It also fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.
--- drivers/net/tap/bpf/meson.build | 36 ++- drivers/net/tap/bpf/tap_rss.c | 45 ++-- drivers/net/tap/meson.build | 35 ++- drivers/net/tap/rte_eth_tap.c | 14 +- drivers/net/tap/rte_eth_tap.h | 6 +- drivers/net/tap/tap_flow.c | 418 ++++++++------------------------ drivers/net/tap/tap_flow.h | 17 +- drivers/net/tap/tap_rss.h | 10 +- drivers/net/tap/tap_tcmsgs.h | 4 +- 9 files changed, 189 insertions(+), 396 deletions(-)
drivers/net/tap/bpf/meson.build +31 -5
@@ -1,17 +1,26 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright 2024 Stephen Hemminger <[email protected]> -enable_tap_rss = false - -libbpf = dependency('libbpf', required: false, method: 'pkg-config') +# Loading BPF requires libbpf +# and the bpf_map__XXX API's were introduced in 0.8.0 +libbpf = dependency('libbpf', version: '>= 1.0', + required: false, method: 'pkg-config') if not libbpf.found() message('net/tap: no RSS support missing libbpf') subdir_done() endif +# Making skeleton needs bpftool # Debian install this in /usr/sbin which is not in $PATH -bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false, version: '>= 5.6.0') -if not bpftool.found() +bpftool_supports_skel = false +bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false) +if bpftool.found() + # Some Ubuntu versions have non-functional bpftool + bpftool_supports_skel = run_command(bpftool, 'gen', 'help', + check:false).returncode() == 0 +endif + +if not bpftool_supports_skel message('net/tap: no RSS support missing bpftool') subdir_done() endif
@@ -42,6 +51,7 @@ clang_flags = [ '-O2', '-Wall', '-Wextra', + max_queues, '-target', 'bpf', '-g',
@@ -67,6 +77,22 @@ skel_h_cmd = [ '@INPUT@' ] +vmlinux_h_cmd = [ + bpftool, + 'btf', + 'dump', + 'file', + '/sys/kernel/btf/vmlinux', + 'format', + 'c' +] + +vmlinux_h = custom_target( + 'vmlinux.h', + output: 'vmlinux.h', + command: vmlinux_h_cmd, + capture: true) + tap_rss_o = custom_target( 'tap_rss.bpf.o', input: 'tap_rss.c',
drivers/net/tap/bpf/tap_rss.c +24 -21
67 lines not on this page · raw message
drivers/net/tap/meson.build +16 -19
@@ -5,36 +5,33 @@ if not is_linux build = false reason = 'only supported on Linux' endif + sources = files( 'rte_eth_tap.c', 'tap_intr.c', 'tap_netlink.c', ) +deps = ['bus_vdev', 'gso', 'hash'] + +max_queues = '-DTAP_MAX_QUEUES=16' +cflags += max_queues + +require_iova_in_mbuf = false + if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT') cflags += '-DHAVE_TCA_FLOWER' sources += files( - 'tap_bpf_api.c', 'tap_flow.c', 'tap_tcmsgs.c', ) -endif - -deps = ['bus_vdev', 'gso', 'hash'] -cflags += '-DTAP_MAX_QUEUES=8' - -# input array for meson symbol search: -# [ "MACRO to define if found", "header for the search", -# "enum/define", "symbol to search" ] -# -args = [ - [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ], -] -config = configuration_data() -foreach arg:args - config.set(arg[0], cc.has_header_symbol(arg[1], arg[2])) -endforeach -configure_file(output : 'tap_autoconf.h', configuration : config) + enable_tap_rss = false -require_iova_in_mbuf = false + subdir('bpf') + if enable_tap_rss + cflags += '-DHAVE_BPF_RSS' + ext_deps += libbpf + sources += tap_rss_skel_h + endif +endif
drivers/net/tap/rte_eth_tap.c +7 -7
@@ -1131,6 +1131,7 @@ tap_dev_close(struct rte_eth_dev *dev)tap_flow_implicit_flush (internals,NULL );tap_nl_final (internals->nlsk_fd); internals->nlsk_fd =-1 ; + tap_flow_bpf_destroy(internals); }#endif
@@ -1956,6 +1957,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,strlcpy (pmd->name, tap_name,sizeof (pmd->name)); pmd->type = type; pmd->ka_fd =-1 ; +#ifdef HAVE_TCA_FLOWER pmd->nlsk_fd =-1 ;#endif
@@ -2038,13 +2040,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,/* Make network device persist after application exit */ pmd->persist = persist; - pmd->if_index =if_nametoindex (pmd->name); -if (!pmd->if_index) { -TAP_LOG (ERR ,"%s: failed to get if_index." , pmd->name); - goto disable_rte_flow; - } - -#ifdef HAVE_TCA_FLOWER /* * Set up everything related to rte_flow:
@@ -2060,6 +2055,11 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, pmd->name); goto disable_rte_flow; } + pmd->if_index =if_nametoindex (pmd->name); +if (!pmd->if_index) { +TAP_LOG (ERR ,"%s: failed to get if_index." , pmd->name); + goto disable_rte_flow; + }if (qdisc_create_multiq (pmd->nlsk_fd, pmd->if_index) <0 ) {TAP_LOG (ERR ,"%s: failed to create multiq qdisc." , pmd->name);
drivers/net/tap/rte_eth_tap.h +2 -4
@@ -81,10 +81,8 @@ struct pmd_internals {#ifdef HAVE_TCA_FLOWER int nlsk_fd;/* Netlink socket fd */ int flow_isolate;/* 1 if flow isolation is enabled */ -int rss_enabled;/* 1 if RSS is enabled, else 0 */ -/* implicit rules set when RSS is enabled */ -int map_fd;/* BPF RSS map fd */ -int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */ + +struct tap_rss *rss;/* BPF program */ LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */
drivers/net/tap/tap_flow.c +97 -321
555 lines not on this page · raw message
drivers/net/tap/tap_flow.h +6 -11
@@ -9,7 +9,11 @@#include <rte_flow.h> #include <rte_flow_driver.h> #include <rte_eth_tap.h> -#include <tap_autoconf.h> + +/** +* Mask of unsupported RSS types +*/ +#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP))/** * In TC, priority 0 means we require the kernel to allocate one for us.
@@ -41,11 +45,6 @@ enum implicit_rule_index { TAP_REMOTE_MAX_IDX, }; -enum bpf_fd_idx { -SEC_L3_L4 , -SEC_MAX , -}; -int tap_dev_flow_ops_get (struct rte_eth_dev *dev,const struct rte_flow_ops **ops);int tap_flow_flush (struct rte_eth_dev *dev,struct rte_flow_error *error);
@@ -57,10 +56,6 @@ int tap_flow_implicit_destroy(struct pmd_internals *pmd,int tap_flow_implicit_flush (struct pmd_internals *pmd,struct rte_flow_error *error); -int tap_flow_bpf_cls_q (__u32 queue_idx); -int tap_flow_bpf_calc_l3_l4_hash (__u32 key_idx,int map_fd); -int tap_flow_bpf_rss_map_create (unsigned int key_size,unsigned int value_size, -unsigned int max_entries); -int tap_flow_bpf_update_rss_elem (int fd,void *key,void *value); +void tap_flow_bpf_destroy (struct pmd_internals *pmd);#endif /* _TAP_FLOW_H_ */
drivers/net/tap/tap_rss.h +4 -6
@@ -5,16 +5,14 @@#ifndef _TAP_RSS_H_#define _TAP_RSS_H_ -#ifndef TAP_MAX_QUEUES -#define TAP_MAX_QUEUES 16 +/* Size of the map from BPF classid to queue table */ +#ifndef TAP_RSS_MAX +#define TAP_RSS_MAX 32#endif -/* Fixed RSS hash key size in bytes. */ +/* Standard Toeplitz hash key size */ #define TAP_RSS_HASH_KEY_SIZE 40 -/* Supported RSS */ -#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP)) -/* hashed fields for RSS */ enum hash_field { HASH_FIELD_IPV4_L3, /* IPv4 src/dst addr */
drivers/net/tap/tap_tcmsgs.h +2 -2
@@ -6,7 +6,6 @@#ifndef _TAP_TCMSGS_H_#define _TAP_TCMSGS_H_ -#include <tap_autoconf.h> #include <linux/if_ether.h> #include <linux/rtnetlink.h> #include <linux/pkt_sched.h>
@@ -14,9 +13,10 @@#include <linux/tc_act/tc_mirred.h> #include <linux/tc_act/tc_gact.h> #include <linux/tc_act/tc_skbedit.h> -#ifdef HAVE_TC_ACT_BPF +#ifdef HAVE_BPF_RSS #include <linux/tc_act/tc_bpf.h> #endif +#include <inttypes.h> #include <rte_ether.h>
Signature · 1 line
2.43.0
PATCH v8 7/8 net/tap: remove no longer used files
In reply to Stephen HemmingerThe BPF api was replaced by use of libbpf.
And the BPF instruction header was replaced by the skeleton.
--- drivers/net/tap/tap_bpf_api.c | 196 ---- drivers/net/tap/tap_bpf_insns.h | 1741 ------------------------------- 2 files changed, 1937 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h
drivers/net/tap/tap_bpf_api.c deleted +0 -196
@@ -1,196 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright 2017 Mellanox Technologies, Ltd -*/ - -#include <unistd.h> -#include <syscall.h> -#include <linux/bpf.h> - -#include <tap_flow.h> -#include <tap_autoconf.h> - -#include <tap_bpf_insns.h> - - -static int bpf_load (enum bpf_prog_type type,const struct bpf_insn *insns, -size_t insns_cnt,const char *license); - -/** -* Load BPF program (section cls_q) into the kernel and return a bpf fd -* -* @param queue_idx -* Queue index matching packet cb -* -* @return -* -1 if the BPF program couldn't be loaded. An fd (int) otherwise. -*/ -int tap_flow_bpf_cls_q (__u32 queue_idx) -{ - cls_q_insns[1 ].imm = queue_idx; - -return bpf_load (BPF_PROG_TYPE_SCHED_CLS , - (struct bpf_insn *)cls_q_insns, -RTE_DIM (cls_q_insns), -"Dual BSD/GPL" ); -} - -/** -* Load BPF program (section l3_l4) into the kernel and return a bpf fd. -* -* @param[in] key_idx -* RSS MAP key index -* -* @param[in] map_fd -* BPF RSS map file descriptor -* -* @return -* -1 if the BPF program couldn't be loaded. An fd (int) otherwise. -*/ -int tap_flow_bpf_calc_l3_l4_hash (__u32 key_idx,int map_fd) -{ - l3_l4_hash_insns[4 ].imm = key_idx; - l3_l4_hash_insns[9 ].imm = map_fd; - -return bpf_load (BPF_PROG_TYPE_SCHED_ACT , - (struct bpf_insn *)l3_l4_hash_insns, -RTE_DIM (l3_l4_hash_insns), -"Dual BSD/GPL" ); -} - -/** -* Helper function to convert a pointer to unsigned 64 bits -* -* @param[in] ptr -* pointer to address -* -* @return -* 64 bit unsigned long type of pointer address -*/ -static inline __u64 ptr_to_u64 (const void *ptr) -{ -return (__u64 )(unsigned long )ptr; -} - -/** -* Call BPF system call -* -* @param[in] cmd -* BPF command for program loading, map creation, map entry update, etc -* -* @param[in] attr -* System call attributes relevant to system call command -* -* @param[in] size -* size of attr parameter -* -* @return -* -1 if BPF system call failed, 0 otherwise -*/ -static inline int sys_bpf (enum bpf_cmd cmd,union bpf_attr *attr, -unsigned int size) -{ -#ifdef __NR_bpf -return syscall (__NR_bpf, cmd, attr, size); -#else -TAP_LOG (ERR ,"No bpf syscall, kernel headers too old?\n" ); - errno =ENOSYS ; -return -1 ; -#endif -} - -/** -* Load BPF instructions to kernel -* -* @param[in] type -* BPF program type: classifier or action -* -* @param[in] insns -* Array of BPF instructions (equivalent to BPF instructions) -* -* @param[in] insns_cnt -* Number of BPF instructions (size of array) -* -* @param[in] license -* License string that must be acknowledged by the kernel -* -* @return -* -1 if the BPF program couldn't be loaded, fd (file descriptor) otherwise -*/ -static int bpf_load (enum bpf_prog_type type, -const struct bpf_insn *insns, -size_t insns_cnt, -const char *license) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - attr.prog_type = type; - attr.insn_cnt = (__u32 )insns_cnt; - attr.insns =ptr_to_u64 (insns); - attr.license =ptr_to_u64 (license); - attr.log_buf =ptr_to_u64 (NULL ); - attr.log_level =0 ; - attr.kern_version =0 ; - -return sys_bpf (BPF_PROG_LOAD , &attr,sizeof (attr)); -} - -/** -* Create BPF map for RSS rules -* -* @param[in] key_size -* map RSS key size -* -* @param[in] value_size -* Map RSS value size -* -* @param[in] max_entries -* Map max number of RSS entries (limit on max RSS rules) -* -* @return -* -1 if BPF map couldn't be created, map fd otherwise -*/ -int tap_flow_bpf_rss_map_create (unsigned int key_size, -unsigned int value_size, -unsigned int max_entries) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - attr.map_type =BPF_MAP_TYPE_HASH ; - attr.key_size = key_size; - attr.value_size = value_size; - attr.max_entries = max_entries; - -return sys_bpf (BPF_MAP_CREATE , &attr,sizeof (attr)); -} - -/** -* Update RSS entry in BPF map -* -* @param[in] fd -* RSS map fd -* -* @param[in] key -* Pointer to RSS key whose entry is updated -* -* @param[in] value -* Pointer to RSS new updated value -* -* @return -* -1 if RSS entry failed to be updated, 0 otherwise -*/ -int tap_flow_bpf_update_rss_elem (int fd,void *key,void *value) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - - attr.map_type =BPF_MAP_TYPE_HASH ; - attr.map_fd = fd; - attr.key =ptr_to_u64 (key); - attr.value =ptr_to_u64 (value); - attr.flags =BPF_ANY ; - -return sys_bpf (BPF_MAP_UPDATE_ELEM , &attr,sizeof (attr)); -}
drivers/net/tap/tap_bpf_insns.h deleted +0 -1741
1,741 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v8 8/8 doc: update documentation of TAP PMD
In reply to Stephen HemmingerThe driver support of flows has changed and the wording in the guide was awkward.
Drop references to DPDK pktgen in this documentation since it is not required and confusing.
--- doc/guides/linux_gsg/sys_reqs.rst | 3 + doc/guides/nics/tap.rst | 274 +++++++++--------------------- 2 files changed, 80 insertions(+), 197 deletions(-)
doc/guides/linux_gsg/sys_reqs.rst +3 -0
@@ -101,6 +101,9 @@ Running DPDK Applications To run a DPDK application, some customization may be required on the target machine. +.. _linux_gsg_kernel_version: + + System Software ~~~~~~~~~~~~~~~
doc/guides/nics/tap.rst +77 -197
333 lines not on this page · raw message
Signature · 1 line
2.43.0
v9 cover net/tap: fix RSS (BPF) support
In reply to Stephen HemmingerThe support of doing RSS for rte_flow_action was a cool idea but it has been broken for several releases of DPDK as the kernel and BPF infrastructure changed.
This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF toolchain.
The result should be easier to read and maintain. I do not intend to support backporting this to stable releases due to lack of demand and dealing with older distros.
v9 - rebase and keep max queues at 16
Stephen Hemminger (9):
net/tap: do not duplicate fd's
net/tap: remove unused fields
net/tap: validate and setup parameters for BPF RSS net/tap: do not build flow support if header is out of date net/tap: rewrite the RSS BPF program
net/tap: use libbpf to load new BPF program net/tap: remove no longer used files
doc: update documentation of TAP PMD
net/tap: simplify the internal structure
.gitignore | 3 - doc/guides/linux_gsg/sys_reqs.rst | 3 + doc/guides/nics/tap.rst | 274 ++-- drivers/net/tap/bpf/Makefile | 19 - drivers/net/tap/bpf/README | 38 + drivers/net/tap/bpf/bpf_api.h | 276 ---- drivers/net/tap/bpf/bpf_elf.h | 53 - drivers/net/tap/bpf/bpf_extract.py | 86 -- drivers/net/tap/bpf/meson.build | 107 ++ drivers/net/tap/bpf/tap_bpf_program.c | 255 ---- drivers/net/tap/bpf/tap_rss.c | 267 ++++ drivers/net/tap/meson.build | 42 +- drivers/net/tap/rte_eth_tap.c | 267 ++-- drivers/net/tap/rte_eth_tap.h | 32 +- drivers/net/tap/tap_bpf.h | 121 -- drivers/net/tap/tap_bpf_api.c | 190 --- drivers/net/tap/tap_bpf_insns.h | 1743 ------------------------- drivers/net/tap/tap_flow.c | 559 +++----- drivers/net/tap/tap_flow.h | 17 +- drivers/net/tap/tap_intr.c | 7 +- drivers/net/tap/tap_rss.h | 21 +- drivers/net/tap/tap_tcmsgs.h | 4 +- 22 files changed, 833 insertions(+), 3551 deletions(-) delete mode 100644 drivers/net/tap/bpf/Makefile create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py create mode 100644 drivers/net/tap/bpf/meson.build delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c delete mode 100644 drivers/net/tap/tap_bpf.h delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h
Signature · 1 line
2.43.0
PATCH v9 1/9 net/tap: do not duplicate fd's
The TAP device can use same file descriptopr for both rx and tx queues. This allows up to 8 queues (versus 4) to be used with secondary process.
--- drivers/net/tap/rte_eth_tap.c | 197 +++++++++++++++------------------- drivers/net/tap/rte_eth_tap.h | 3 +- drivers/net/tap/tap_flow.c | 3 +- drivers/net/tap/tap_intr.c | 7 +- 4 files changed, 91 insertions(+), 119 deletions(-)
drivers/net/tap/rte_eth_tap.c +84 -113
@@ -124,8 +124,7 @@ enum ioctl_mode {/* Message header to synchronize queues via IPC */ struct ipc_queues {char port_name[RTE_DEV_NAME_MAX_LEN ]; -int rxq_count; -int txq_count; +int q_count;/* * The file descriptors are in the dedicated part * of the Unix message to be translated by the kernel.
@@ -446,7 +445,7 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)uint16_t data_off =rte_pktmbuf_headroom (mbuf);int len; - len =readv (process_private->rxq_fds[rxq->queue_id], + len =readv (process_private->fds[rxq->queue_id], *rxq->iovecs,1 + (rxq->rxmode->offloads &RTE_ETH_RX_OFFLOAD_SCATTER ? rxq->nb_rx_desc :1 ));
@@ -643,7 +642,7 @@ tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs, }/* copy the tx frame data */ - n =writev (process_private->txq_fds[txq->queue_id], iovecs, k); + n =writev (process_private->fds[txq->queue_id], iovecs, k);if (n <=0 )return -1 ;
@@ -851,7 +850,6 @@ tap_mp_req_on_rxtx(struct rte_eth_dev *dev)struct rte_mp_msg msg;struct ipc_queues *request_param = (struct ipc_queues *)msg.param;int err; -int fd_iterator =0 ;struct pmd_process_private *process_private = dev->process_private;int i;
@@ -859,16 +857,13 @@ tap_mp_req_on_rxtx(struct rte_eth_dev *dev)strlcpy (msg.name,TAP_MP_REQ_START_RXTX ,sizeof (msg.name));strlcpy (request_param->port_name, dev->data->name,sizeof (request_param->port_name)); msg.len_param =sizeof (*request_param); -for (i =0 ; i < dev->data->nb_tx_queues; i++) { - msg.fds[fd_iterator++] = process_private->txq_fds[i]; - msg.num_fds++; - request_param->txq_count++; - } -for (i =0 ; i < dev->data->nb_rx_queues; i++) { - msg.fds[fd_iterator++] = process_private->rxq_fds[i]; - msg.num_fds++; - request_param->rxq_count++; - } + +/* rx and tx share file descriptors and nb_tx_queues == nb_rx_queues */ +for (i =0 ; i < dev->data->nb_rx_queues; i++) + msg.fds[i] = process_private->fds[i]; + + request_param->q_count = dev->data->nb_rx_queues; + msg.num_fds = dev->data->nb_rx_queues; err =rte_mp_sendmsg (&msg);if (err <0 ) {
@@ -910,8 +905,6 @@ tap_mp_req_start_rxtx(const struct rte_mp_msg *request, __rte_unused const voidstruct rte_eth_dev *dev;const struct ipc_queues *request_param = (const struct ipc_queues *)request->param; -int fd_iterator; -int queue;struct pmd_process_private *process_private; dev =rte_eth_dev_get_by_name (request_param->port_name);
@@ -920,14 +913,13 @@ tap_mp_req_start_rxtx(const struct rte_mp_msg *request, __rte_unused const void request_param->port_name);return -1 ; } + process_private = dev->process_private; - fd_iterator =0 ; -TAP_LOG (DEBUG ,"tap_attach rx_q:%d tx_q:%d\n" , request_param->rxq_count, - request_param->txq_count); -for (queue =0 ; queue < request_param->txq_count; queue++) - process_private->txq_fds[queue] = request->fds[fd_iterator++]; -for (queue =0 ; queue < request_param->rxq_count; queue++) - process_private->rxq_fds[queue] = request->fds[fd_iterator++]; +TAP_LOG (DEBUG ,"tap_attach q:%d\n" , request_param->q_count); + +for (int q =0 ; q < request_param->q_count; q++) + process_private->fds[q] = request->fds[q]; +return 0 ; }
@@ -1121,7 +1113,6 @@ tap_dev_close(struct rte_eth_dev *dev)int i;struct pmd_internals *internals = dev->data->dev_private;struct pmd_process_private *process_private = dev->process_private; -struct rx_queue *rxq;if (rte_eal_process_type () !=RTE_PROC_PRIMARY ) {rte_free (dev->process_private);
@@ -1141,19 +1132,18 @@ tap_dev_close(struct rte_eth_dev *dev) }for (i =0 ; i <RTE_PMD_TAP_MAX_QUEUES ; i++) { -if (process_private->rxq_fds[i] !=-1 ) { - rxq = &internals->rxq[i]; -close (process_private->rxq_fds[i]); - process_private->rxq_fds[i] =-1 ; -tap_rxq_pool_free (rxq->pool); -rte_free (rxq->iovecs); - rxq->pool =NULL ; - rxq->iovecs =NULL ; - } -if (process_private->txq_fds[i] !=-1 ) { -close (process_private->txq_fds[i]); - process_private->txq_fds[i] =-1 ; - } +struct rx_queue *rxq = &internals->rxq[i]; + +if (process_private->fds[i] ==-1 ) +continue ; + +close (process_private->fds[i]); + process_private->fds[i] =-1 ; + +tap_rxq_pool_free (rxq->pool); +rte_free (rxq->iovecs); + rxq->pool =NULL ; + rxq->iovecs =NULL ; }if (internals->remote_if_index) {
@@ -1198,6 +1188,15 @@ tap_dev_close(struct rte_eth_dev *dev)return 0 ; } +static void +tap_queue_close (struct pmd_process_private *process_private,uint16_t qid) +{ +if (process_private->fds[qid] !=-1 ) { +close (process_private->fds[qid]); + process_private->fds[qid] =-1 ; + } +} +static void tap_rx_queue_release (struct rte_eth_dev *dev,uint16_t qid) {
@@ -1206,15 +1205,16 @@ tap_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)if (!rxq)return ; + process_private = rte_eth_devices[rxq->in_port].process_private; -if (process_private->rxq_fds[rxq->queue_id] !=-1 ) { -close (process_private->rxq_fds[rxq->queue_id]); - process_private->rxq_fds[rxq->queue_id] =-1 ; -tap_rxq_pool_free (rxq->pool); -rte_free (rxq->iovecs); - rxq->pool =NULL ; - rxq->iovecs =NULL ; - } + +tap_rxq_pool_free (rxq->pool); +rte_free (rxq->iovecs); + rxq->pool =NULL ; + rxq->iovecs =NULL ; + +if (dev->data->tx_queues[qid] ==NULL ) +tap_queue_close (process_private, qid); } static void
@@ -1225,12 +1225,10 @@ tap_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)if (!txq)return ; - process_private = rte_eth_devices[txq->out_port].process_private; -if (process_private->txq_fds[txq->queue_id] !=-1 ) { -close (process_private->txq_fds[txq->queue_id]); - process_private->txq_fds[txq->queue_id] =-1 ; - } + process_private = rte_eth_devices[txq->out_port].process_private; +if (dev->data->rx_queues[qid] ==NULL ) +tap_queue_close (process_private, qid); } static int
@@ -1482,52 +1480,34 @@ tap_setup_queue(struct rte_eth_dev *dev,uint16_t qid, int is_rx) { - int ret; -int *fd; -int *other_fd; -const char *dir; + int fd, ret;struct pmd_internals *pmd = dev->data->dev_private;struct pmd_process_private *process_private = dev->process_private;struct rx_queue *rx = &internals->rxq[qid];struct tx_queue *tx = &internals->txq[qid]; -struct rte_gso_ctx *gso_ctx; +struct rte_gso_ctx *gso_ctx =NULL ; +const char *dir = is_rx ?"rx" :"tx" ; -if (is_rx) { - fd = &process_private->rxq_fds[qid]; - other_fd = &process_private->txq_fds[qid]; - dir ="rx" ; - gso_ctx =NULL ; - }else { - fd = &process_private->txq_fds[qid]; - other_fd = &process_private->rxq_fds[qid]; - dir ="tx" ; +if (is_rx) gso_ctx = &tx->gso_ctx; - } -if (*fd !=-1 ) { + + fd = process_private->fds[qid]; +if (fd !=-1 ) {/* fd for this queue already exists */ TAP_LOG (DEBUG ,"%s: fd %d for %s queue qid %d exists" , - pmd->name, *fd, dir, qid); + pmd->name, fd, dir, qid); gso_ctx =NULL ; - }else if (*other_fd !=-1 ) { -/* Only other_fd exists. dup it */ - *fd =dup (*other_fd); -if (*fd <0 ) { - *fd =-1 ; -TAP_LOG (ERR ,"%s: dup() failed." , pmd->name); -return -1 ; - } -TAP_LOG (DEBUG ,"%s: dup fd %d for %s queue qid %d (%d)" , - pmd->name, *other_fd, dir, qid, *fd); }else { -/* Both RX and TX fds do not exist (equal -1). Create fd */ - *fd =tun_alloc (pmd,0 ,0 ); -if (*fd <0 ) { - *fd =-1 ;/* restore original value */ + fd =tun_alloc (pmd,0 ,0 ); +if (fd <0 ) {TAP_LOG (ERR ,"%s: tun_alloc() failed." , pmd->name);return -1 ; } +TAP_LOG (DEBUG ,"%s: add %s queue for qid %d fd %d" , - pmd->name, dir, qid, *fd); + pmd->name, dir, qid, fd); + + process_private->fds[qid] = fd; } tx->mtu = &dev->data->mtu;
@@ -1540,7 +1520,7 @@ tap_setup_queue(struct rte_eth_dev *dev, tx->type = pmd->type; -return *fd; +return fd; } static int
@@ -1620,7 +1600,7 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,TAP_LOG (DEBUG ," RX TUNTAP device name %s, qid %d on fd %d" , internals->name, rx_queue_id, - process_private->rxq_fds[rx_queue_id]); + process_private->fds[rx_queue_id]);return 0 ;
@@ -1664,7 +1644,7 @@ tap_tx_queue_setup(struct rte_eth_dev *dev,TAP_LOG (DEBUG ," TX TUNTAP device name %s, qid %d on fd %d csum %s" , internals->name, tx_queue_id, - process_private->txq_fds[tx_queue_id], + process_private->fds[tx_queue_id], txq->csum ?"on" :"off" );return 0 ;
@@ -2001,10 +1981,9 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, dev->intr_handle = pmd->intr_handle;/* Presetup the fds to -1 as being not valid */ -for (i =0 ; i <RTE_PMD_TAP_MAX_QUEUES ; i++) { - process_private->rxq_fds[i] =-1 ; - process_private->txq_fds[i] =-1 ; - } +for (i =0 ; i <RTE_PMD_TAP_MAX_QUEUES ; i++) + process_private->fds[i] =-1 ; +if (pmd->type ==ETH_TUNTAP_TYPE_TAP ) {if (rte_is_zero_ether_addr (mac_addr))
@@ -2332,7 +2311,6 @@ tap_mp_attach_queues(const char *port_name, struct rte_eth_dev *dev)struct ipc_queues *request_param = (struct ipc_queues *)request.param;struct ipc_queues *reply_param;struct pmd_process_private *process_private = dev->process_private; -int queue, fd_iterator;/* Prepare the request */ memset (&request,0 ,sizeof (request));
@@ -2352,18 +2330,17 @@ tap_mp_attach_queues(const char *port_name, struct rte_eth_dev *dev)TAP_LOG (DEBUG ,"Received IPC reply for %s" , reply_param->port_name);/* Attach the queues from received file descriptors */ -if (reply_param->rxq_count + reply_param->txq_count != reply->num_fds) { +if (reply_param->q_count != reply->num_fds) {TAP_LOG (ERR ,"Unexpected number of fds received" );return -1 ; } - dev->data->nb_rx_queues = reply_param->rxq_count; - dev->data->nb_tx_queues = reply_param->txq_count; - fd_iterator =0 ; -for (queue =0 ; queue < reply_param->rxq_count; queue++) - process_private->rxq_fds[queue] = reply->fds[fd_iterator++]; -for (queue =0 ; queue < reply_param->txq_count; queue++) - process_private->txq_fds[queue] = reply->fds[fd_iterator++]; + dev->data->nb_rx_queues = reply_param->q_count; + dev->data->nb_tx_queues = reply_param->q_count; + +for (int q =0 ; q < reply_param->q_count; q++) + process_private->fds[q] = reply->fds[q]; +free (reply);return 0 ; }
@@ -2393,25 +2370,19 @@ tap_mp_sync_queues(const struct rte_mp_msg *request, const void *peer)/* Fill file descriptors for all queues */ reply.num_fds =0 ; - reply_param->rxq_count =0 ; -if (dev->data->nb_rx_queues + dev->data->nb_tx_queues > -RTE_MP_MAX_FD_NUM ){ -TAP_LOG (ERR ,"Number of rx/tx queues exceeds max number of fds" ); + reply_param->q_count =0 ; + +RTE_ASSERT (dev->data->nb_rx_queues == dev->data->nb_tx_queues); +if (dev->data->nb_rx_queues >RTE_MP_MAX_FD_NUM ) { +TAP_LOG (ERR ,"Number of rx/tx queues %u exceeds max number of fds %u" , + dev->data->nb_rx_queues,RTE_MP_MAX_FD_NUM );return -1 ; }for (queue =0 ; queue < dev->data->nb_rx_queues; queue++) { - reply.fds[reply.num_fds++] = process_private->rxq_fds[queue]; - reply_param->rxq_count++; - } -RTE_ASSERT (reply_param->rxq_count == dev->data->nb_rx_queues); - - reply_param->txq_count =0 ; -for (queue =0 ; queue < dev->data->nb_tx_queues; queue++) { - reply.fds[reply.num_fds++] = process_private->txq_fds[queue]; - reply_param->txq_count++; + reply.fds[reply.num_fds++] = process_private->fds[queue]; + reply_param->q_count++; } -RTE_ASSERT (reply_param->txq_count == dev->data->nb_tx_queues);/* Send reply */ strlcpy (reply.name, request->name,sizeof (reply.name));
drivers/net/tap/rte_eth_tap.h +1 -2
@@ -96,8 +96,7 @@ struct pmd_internals { };struct pmd_process_private { -int rxq_fds[RTE_PMD_TAP_MAX_QUEUES ]; -int txq_fds[RTE_PMD_TAP_MAX_QUEUES ]; +int fds[RTE_PMD_TAP_MAX_QUEUES ]; };/* tap_intr.c */
drivers/net/tap/tap_flow.c +2 -1
@@ -1595,8 +1595,9 @@ tap_flow_isolate(struct rte_eth_dev *dev,* If netdevice is there, setup appropriate flow rules immediately. * Otherwise it will be set when bringing up the netdevice (tun_alloc). */ -if (!process_private->rxq_fds[0 ]) +if (process_private->fds[0 ] ==-1 )return 0 ; +if (set) {struct rte_flow *remote_flow;
drivers/net/tap/tap_intr.c +4 -3
@@ -68,9 +68,11 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev) }for (i =0 ; i < n; i++) {struct rx_queue *rxq = pmd->dev->data->rx_queues[i]; +int fd = process_private->fds[i];/* Skip queues that cannot request interrupts. */ -if (!rxq || process_private->rxq_fds[i] ==-1 ) { +if (!rxq || fd ==-1 ) { +/* Use invalid intr_vec[] index to disable entry. */ /* Use invalid intr_vec[] index to disable entry. */ if (rte_intr_vec_list_index_set (intr_handle, i,RTE_INTR_VEC_RXTX_OFFSET +RTE_MAX_RXTX_INTR_VEC_ID ))
@@ -80,8 +82,7 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev)if (rte_intr_vec_list_index_set (intr_handle, i,RTE_INTR_VEC_RXTX_OFFSET + count))return -rte_errno; -if (rte_intr_efds_index_set (intr_handle, count, - process_private->rxq_fds[i])) +if (rte_intr_efds_index_set (intr_handle, count, fd))return -rte_errno; count++; }
Signature · 1 line
2.43.0
Re: [PATCH v9 1/9] net/tap: do not duplicate fd's
Quoted 2 lines · Stephen Hemminger
The TAP device can use same file descriptopr for both rx and tx queues.
s/descriptopr/descriptor/
Quoted 3 lines
This allows up to 8 queues (versus 4) to be used with secondary process.
Signed-off-by Stephen Hemminger <[email protected]>
<...>
Quoted 15 lines
drivers/net/tap/rte_eth_tap.c +0
-11@@ -1141,19 +1132,18 @@ tap_dev_close(struct rte_eth_dev *dev) }for (i =0 ; i <RTE_PMD_TAP_MAX_QUEUES ; i++) { -if (process_private->rxq_fds[i] !=-1 ) { - rxq = &internals->rxq[i]; -close (process_private->rxq_fds[i]); - process_private->rxq_fds[i] =-1 ; -tap_rxq_pool_free (rxq->pool); -rte_free (rxq->iovecs); - rxq->pool =NULL ; - rxq->iovecs =NULL ; - } -if (process_private->txq_fds[i] !=-1 ) { -close (process_private->txq_fds[i]);
drivers/net/tap/rte_eth_tap.c tap_dev_close(struct rte_eth_dev *dev) · line 1142
Quoted 10 lines
drivers/net/tap/rte_eth_tap.c +7
-2- process_private->txq_fds[i] =-1 ; - } +struct rx_queue *rxq = &internals->rxq[i]; + +if (process_private->fds[i] ==-1 ) +continue ; + +close (process_private->fds[i]); + process_private->fds[i] =-1 ;
can 'tap_queue_close()' be used here? (probably with slight change)
<...>
Quoted 19 lines
drivers/net/tap/rte_eth_tap.c +3
-7@@ -1482,52 +1480,34 @@ tap_setup_queue(struct rte_eth_dev *dev,uint16_t qid, int is_rx) { - int ret; -int *fd; -int *other_fd; -const char *dir; + int fd, ret;struct pmd_internals *pmd = dev->data->dev_private;struct pmd_process_private *process_private = dev->process_private;struct rx_queue *rx = &internals->rxq[qid];struct tx_queue *tx = &internals->txq[qid]; -struct rte_gso_ctx *gso_ctx; +struct rte_gso_ctx *gso_ctx =NULL ; +const char *dir = is_rx ?"rx" :"tx" ; -if (is_rx) { - fd = &process_private->rxq_fds[qid];
drivers/net/tap/rte_eth_tap.c tap_setup_queue(struct rte_eth_dev *dev, · line 1493
Quoted 10 lines
drivers/net/tap/rte_eth_tap.c +1
-7- other_fd = &process_private->txq_fds[qid]; - dir ="rx" ; - gso_ctx =NULL ; - }else { - fd = &process_private->txq_fds[qid]; - other_fd = &process_private->rxq_fds[qid]; - dir ="tx" ; +if (is_rx) gso_ctx = &tx->gso_ctx;
As commented on other version of this patch, shouldn't this be:if (!is_rx)
<...>
drivers/net/tap/tap_flow.c tap_flow_isolate(struct rte_eth_dev *dev, · line 1599
Quoted 11 lines
drivers/net/tap/tap_flow.c +1
-1@@ -1595,8 +1595,9 @@ tap_flow_isolate(struct rte_eth_dev *dev,* If netdevice is there, setup appropriate flow rules immediately. * Otherwise it will be set when bringing up the netdevice (tun_alloc). */ -if (!process_private->rxq_fds[0 ]) +if (process_private->fds[0 ] ==-1 )
change in the condition looks reasonable but not directly related with the change, does it require its own patch?
Re: [PATCH v9 1/9] net/tap: do not duplicate fd's
Quoted 6 lines · On Wed, 1 May 2024 12:13:45 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 6 lines
drivers/net/tap/tap_flow.c +0
-0@@ -1595,8 +1595,9 @@ tap_flow_isolate(struct rte_eth_dev *dev,* If netdevice is there, setup appropriate flow rules immediately.
Quoted 8 lines
drivers/net/tap/tap_flow.c tap_flow_isolate(struct rte_eth_dev *dev, · line 1603
Quoted 5 lines
drivers/net/tap/tap_flow.c +1
-1* Otherwise it will be set when bringing up the netdevice (tun_alloc). */ -if (!process_private->rxq_fds[0 ]) +if (process_private->fds[0 ] ==-1 )change in the condition looks reasonable but not directly related with the change, does it require its own patch?
In this case, the array of fds is moving from the rxq to being global. The old code worked because rxq_fds[] was initialized to zero. With shared fd's the fds are now initialized to -1.
Using zero as sentinel fd is bad practice, because it is a valid fd; but POSIX says it always is stdin.
Re: [PATCH v9 1/9] net/tap: do not duplicate fd's
Quoted 18 lines · Stephen Hemminger
Quoted 6 lines · On Wed, 1 May 2024 12:13:45 +0100 Ferruh Yigit <[email protected]> wrote:
Quoted 6 lines
drivers/net/tap/tap_flow.c +0
-0@@ -1595,8 +1595,9 @@ tap_flow_isolate(struct rte_eth_dev *dev,* If netdevice is there, setup appropriate flow rules immediately. Quoted 8 lines
drivers/net/tap/tap_flow.c tap_flow_isolate(struct rte_eth_dev *dev, · line 1603
Quoted 5 lines
drivers/net/tap/tap_flow.c +1
-1* Otherwise it will be set when bringing up the netdevice (tun_alloc). */ -if (!process_private->rxq_fds[0 ]) +if (process_private->fds[0 ] ==-1 )change in the condition looks reasonable but not directly related with the change, does it require its own patch?
Quoted 7 lines
In this case, the array of fds is moving from the rxq to being global. The old code worked because rxq_fds[] was initialized to zero. With shared fd's the fds are now initialized to -1.
Using zero as sentinel fd is bad practice, because it is a valid fd; but POSIX says it always is stdin.
I agree on the fix, only I don't think it belongs to this patch.
As far as I can see 'rxq_fds' was already initialized to '-1' and original code was already wrong.
This patch merges 'rxq_fds' & 'txq_fds' to 'fds', but this patch doesn't do anything that requires updating the above condition, or if I missing it please show me.
I think better to fix condition first in a separate patch.
Re: [PATCH v9 1/9] net/tap: do not duplicate fd's
Quoted 10 lines · On Thu, 2 May 2024 15:51:43 +0100 Ferruh Yigit <[email protected]> wrote:
I agree on the fix, only I don't think it belongs to this patch.
As far as I can see '
rxq_fds' was already initialized to '-1' and original code was already wrong.This patch merges '
rxq_fds' & 'txq_fds' to 'fds', but this patch doesn't do anything that requires updating the above condition, or if I missing it please show me.I think better to fix condition first in a separate patch.
Your right rxq_fds was not checked correctly in original code. Let me split out that one.
PATCH v9 2/9 net/tap: remove unused fields
In reply to Stephen HemmingerThe driver doesn't support these other hash types, and there is no reason to implement these in future. The rss_flows list was set but never used.
--- drivers/net/tap/rte_eth_tap.h | 4 +--- drivers/net/tap/tap_flow.c | 1 - drivers/net/tap/tap_rss.h | 6 ------ 3 files changed, 1 insertion(+), 10 deletions(-)
drivers/net/tap/rte_eth_tap.h +1 -3
@@ -77,14 +77,12 @@ struct pmd_internals {int ioctl_sock;/* socket for ioctl calls */ int nlsk_fd;/* Netlink socket fd */ int flow_isolate;/* 1 if flow isolation is enabled */ -int flower_support;/* 1 if kernel supports, else 0 */ -int flower_vlan_support;/* 1 if kernel supports, else 0 */ int rss_enabled;/* 1 if RSS is enabled, else 0 */ int persist;/* 1 if keep link up, else 0 */ /* implicit rules set when RSS is enabled */ int map_fd;/* BPF RSS map fd */ int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */ - LIST_HEAD(tap_rss_flows, rte_flow) rss_flows; + LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */ LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
drivers/net/tap/tap_flow.c +0 -1
@@ -1958,7 +1958,6 @@ static int rss_enable(struct pmd_internals *pmd, errno, strerror(errno));return err; } -LIST_INSERT_HEAD (&pmd->rss_flows, rss_flow, next); } pmd->rss_enabled =1 ;
drivers/net/tap/tap_rss.h +0 -6
@@ -21,12 +21,6 @@ enum hash_field {HASH_FIELD_IPV4_L3_L4 ,/* IPv4 src/dst addr + L4 src/dst ports */ HASH_FIELD_IPV6_L3 ,/* IPv6 src/dst addr */ HASH_FIELD_IPV6_L3_L4, /* IPv6 src/dst addr + L4 src/dst ports */ -HASH_FIELD_L2_SRC ,/* Ethernet src addr */ -HASH_FIELD_L2_DST ,/* Ethernet dst addr */ -HASH_FIELD_L3_SRC ,/* L3 src addr */ -HASH_FIELD_L3_DST ,/* L3 dst addr */ -HASH_FIELD_L4_SRC ,/* TCP/UDP src ports */ - HASH_FIELD_L4_DST, /* TCP/UDP dst ports */ }; struct rss_key {
Signature · 1 line
2.43.0
PATCH v9 3/9 net/tap: validate and setup parameters for BPF RSS
In reply to Stephen HemmingerThe flow RSS support via BPF was not using the key, or hash type parameters. Which is good because they were never properly setup.
Fix the setup and validate the flow parameters, the BPF side gets fixed later.
--- drivers/net/tap/tap_flow.c | 65 +++++++++++++++++++++++++++++++++++--- drivers/net/tap/tap_rss.h | 5 ++- 2 files changed, 62 insertions(+), 8 deletions(-)
drivers/net/tap/tap_flow.c +60 -5
@@ -11,9 +11,11 @@#include <rte_byteorder.h> #include <rte_jhash.h> +#include <rte_thash.h> #include <rte_random.h> #include <rte_malloc.h> #include <rte_eth_tap.h> +#include <tap_flow.h> #include <tap_autoconf.h> #include <tap_tcmsgs.h>
@@ -2061,6 +2063,21 @@ static int bpf_rss_key(enum bpf_rss_key_e cmd, __u32 *key_idx)return err; } + +/* Default RSS hash key also used by mlx devices */ +static const uint8_t rss_hash_default_key[] = { +0x2c ,0xc6 ,0x81 ,0xd1 , +0x5b ,0xdb ,0xf4 ,0xf7 , +0xfc ,0xa2 ,0x83 ,0x19 , +0xdb ,0x1a ,0x3e ,0x94 , +0x6b ,0x9e ,0x38 ,0xd9 , +0x2c ,0x9c ,0x03 ,0xd1 , +0xad ,0x99 ,0x44 ,0xa7 , +0xd9 ,0x56 ,0x3d ,0x59 , +0x06 ,0x3c ,0x25 ,0xf3 , +0xfc ,0x1f ,0xdc ,0x2a , +}; +/** * Add RSS hash calculations and queue selection *
@@ -2079,11 +2096,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,const struct rte_flow_action_rss *rss, struct rte_flow_error *error) { -/* 4096 is the maximum number of instructions for a BPF program */ + struct rss_key rss_entry = { }; +const uint8_t *key_in; +uint32_t hash_type =0 ;unsigned int i;int err; -struct rss_key rss_entry = { .hash_fields =0 , - .key_size =0 };/* Check supported RSS features */ if (rss->func !=RTE_ETH_HASH_FUNCTION_DEFAULT )
@@ -2095,6 +2112,41 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, (error,ENOTSUP ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL ,"a nonzero RSS encapsulation level is not supported" ); +if (rss->queue_num ==0 || rss->queue_num >=TAP_MAX_QUEUES ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL , +"invalid number of queues" ); + +/* allow RSS key_len 0 in case of NULL (default) RSS key. */ +if (rss->key_len ==0 ) { +if (rss->key !=NULL ) +return rte_flow_error_set (error,ENOTSUP , +RTE_FLOW_ERROR_TYPE_ACTION_CONF , + &rss->key_len,"RSS hash key length 0" ); + key_in = rss_hash_default_key; + }else { +if (rss->key_len !=TAP_RSS_HASH_KEY_SIZE ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"RSS hash invalid key length" ); +if (rss->key ==NULL ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"RSS hash key is NULL" ); + key_in = rss->key; + } + +if (rss->types &TAP_RSS_HF_MASK ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"RSS hash type not supported" ); + +if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV4_UDP |RTE_ETH_RSS_NONFRAG_IPV4_TCP )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV4_L3_L4 ); +else if (rss->types & (RTE_ETH_RSS_IPV4 |RTE_ETH_RSS_FRAG_IPV4 )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV4_L3 ); + +if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV6_UDP |RTE_ETH_RSS_NONFRAG_IPV6_TCP )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV6_L3_L4 ); +else if (rss->types & (RTE_ETH_RSS_IPV6 |RTE_ETH_RSS_FRAG_IPV6 |RTE_ETH_RSS_IPV6_EX )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV6_L3 ); +/* Get a new map key for a new RSS rule */ err =bpf_rss_key (KEY_CMD_GET , &flow->key_idx);if (err <0 ) {
@@ -2109,8 +2161,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, rss_entry.nb_queues = rss->queue_num;for (i =0 ; i < rss->queue_num; i++) rss_entry.queues[i] = rss->queue[i]; - rss_entry.hash_fields = - (1 <<HASH_FIELD_IPV4_L3_L4 ) | (1 <<HASH_FIELD_IPV6_L3_L4 ); + + rss_entry.hash_fields = hash_type; +rte_convert_rss_key ((const uint32_t *)key_in, (uint32_t *)rss_entry.key, +TAP_RSS_HASH_KEY_SIZE ); +/* Add this RSS entry to map */ err = tap_flow_bpf_update_rss_elem(pmd->map_fd,
drivers/net/tap/tap_rss.h +2 -3
@@ -24,11 +24,10 @@ enum hash_field { };struct rss_key { -__u8 key[128 ];__u32 hash_fields; -__u32 key_size; -__u32 queues[TAP_MAX_QUEUES ]; +__u8 key[TAP_RSS_HASH_KEY_SIZE ];__u32 nb_queues; +__u32 queues[TAP_MAX_QUEUES ]; } __attribute__((packed));#endif /* _TAP_RSS_H_ */
Signature · 1 line
2.43.0
PATCH v9 4/9 net/tap: do not build flow support if header is out of date
In reply to Stephen HemmingerThe proper place for finding bpf structures and functions is in linux/bpf.h. The original version was trying to workaround the case where the build environment was running on old pre BPF version of Glibc, but the target environment had BPF.
Having own private (and divergent) version headers leads to future problems when BPF definitions evolve.
If the build infrastructure is so old that TC flower is not supported, then the TAP device will build without any flow support.
--- drivers/net/tap/bpf/bpf_extract.py | 1 - drivers/net/tap/meson.build | 17 ++-- drivers/net/tap/rte_eth_tap.c | 38 +++++++-- drivers/net/tap/rte_eth_tap.h | 7 +- drivers/net/tap/tap_bpf.h | 121 ----------------------------- drivers/net/tap/tap_bpf_api.c | 20 +++-- drivers/net/tap/tap_bpf_insns.h | 2 - drivers/net/tap/tap_flow.c | 90 --------------------- 8 files changed, 60 insertions(+), 236 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf.h
drivers/net/tap/bpf/bpf_extract.py +0 -1
@@ -65,7 +65,6 @@ def write_header(out, source): print(f' * Auto-generated from {source}', file=out) print(" * This not the original source file. Do NOT edit it.", file=out) print(" */\n", file=out) - print("#include <tap_bpf.h>", file=out) def main():
drivers/net/tap/meson.build +9 -8
@@ -7,13 +7,19 @@ if not is_linux endif sources = files( 'rte_eth_tap.c', - 'tap_bpf_api.c', - 'tap_flow.c', 'tap_intr.c', 'tap_netlink.c', - 'tap_tcmsgs.c', ) +if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT') + cflags += '-DHAVE_TCA_FLOWER' + sources += files( + 'tap_bpf_api.c', + 'tap_flow.c', + 'tap_tcmsgs.c', + ) +endif + deps = ['bus_vdev', 'gso', 'hash'] cflags += '-DTAP_MAX_QUEUES=16'
@@ -23,12 +29,7 @@ cflags += '-DTAP_MAX_QUEUES=16' # "enum/define", "symbol to search" ] # args = [ - [ 'HAVE_TC_FLOWER', 'linux/pkt_cls.h', 'TCA_FLOWER_UNSPEC' ], - [ 'HAVE_TC_VLAN_ID', 'linux/pkt_cls.h', 'TCA_FLOWER_KEY_VLAN_PRIO' ], - [ 'HAVE_TC_BPF', 'linux/pkt_cls.h', 'TCA_BPF_UNSPEC' ], - [ 'HAVE_TC_BPF_FD', 'linux/pkt_cls.h', 'TCA_BPF_FD' ], [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ], - [ 'HAVE_TC_ACT_BPF_FD', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_FD' ], ] config = configuration_data() foreach arg:args
drivers/net/tap/rte_eth_tap.c +32 -6
@@ -1124,12 +1124,15 @@ tap_dev_close(struct rte_eth_dev *dev)if (!internals->persist)tap_link_set_down (dev); + +#ifdef HAVE_TCA_FLOWER if (internals->nlsk_fd !=-1 ) {tap_flow_flush (dev,NULL );tap_flow_implicit_flush (internals,NULL );tap_nl_final (internals->nlsk_fd); internals->nlsk_fd =-1 ; } +#endif for (i =0 ; i <RTE_PMD_TAP_MAX_QUEUES ; i++) {struct rx_queue *rxq = &internals->rxq[i];
@@ -1265,6 +1268,7 @@ tap_promisc_enable(struct rte_eth_dev *dev)if (ret !=0 )return ret; +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) { dev->data->promiscuous =1 ; ret =tap_flow_implicit_create (pmd,TAP_REMOTE_PROMISC );
@@ -1278,7 +1282,7 @@ tap_promisc_enable(struct rte_eth_dev *dev) return ret; } } - +#endif return 0 ; }
@@ -1293,6 +1297,7 @@ tap_promisc_disable(struct rte_eth_dev *dev)if (ret !=0 )return ret; +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) { dev->data->promiscuous =0 ; ret =tap_flow_implicit_destroy (pmd,TAP_REMOTE_PROMISC );
@@ -1306,6 +1311,7 @@ tap_promisc_disable(struct rte_eth_dev *dev) return ret; } } +#endif return 0 ; }
@@ -1321,6 +1327,7 @@ tap_allmulti_enable(struct rte_eth_dev *dev)if (ret !=0 )return ret; +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) { dev->data->all_multicast =1 ; ret =tap_flow_implicit_create (pmd,TAP_REMOTE_ALLMULTI );
@@ -1334,6 +1341,7 @@ tap_allmulti_enable(struct rte_eth_dev *dev) return ret; } } +#endif return 0 ; }
@@ -1349,6 +1357,7 @@ tap_allmulti_disable(struct rte_eth_dev *dev)if (ret !=0 )return ret; +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) { dev->data->all_multicast =0 ; ret =tap_flow_implicit_destroy (pmd,TAP_REMOTE_ALLMULTI );
@@ -1362,6 +1371,7 @@ tap_allmulti_disable(struct rte_eth_dev *dev) return ret; } } +#endif return 0 ; }
@@ -1407,6 +1417,8 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)if (ret <0 )return ret;rte_memcpy (&pmd->eth_addr, mac_addr,RTE_ETHER_ADDR_LEN ); + +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) {/* Replace MAC redirection rule after a MAC change */ ret =tap_flow_implicit_destroy (pmd,TAP_REMOTE_LOCAL_MAC );
@@ -1424,6 +1436,7 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr) return ret; } } +#endif return 0 ; }
@@ -1901,7 +1914,9 @@ static const struct eth_dev_ops ops = { .stats_reset = tap_stats_reset, .dev_supported_ptypes_get = tap_dev_supported_ptypes_get, .rss_hash_update = tap_rss_hash_update, +#ifdef HAVE_TCA_FLOWER .flow_ops_get = tap_dev_flow_ops_get, +#endif }; static int
@@ -1941,7 +1956,9 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,strlcpy (pmd->name, tap_name,sizeof (pmd->name)); pmd->type = type; pmd->ka_fd =-1 ; +#ifdef HAVE_TCA_FLOWER pmd->nlsk_fd =-1 ; +#endif pmd->gso_ctx_mp =NULL ; pmd->ioctl_sock =socket (AF_INET ,SOCK_DGRAM ,0 );
@@ -2021,6 +2038,14 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,/* Make network device persist after application exit */ pmd->persist = persist; + pmd->if_index =if_nametoindex (pmd->name); +if (!pmd->if_index) { +TAP_LOG (ERR ,"%s: failed to get if_index." , pmd->name); + goto disable_rte_flow; + } + + +#ifdef HAVE_TCA_FLOWER /* * Set up everything related to rte_flow: * - netlink socket
@@ -2035,11 +2060,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, pmd->name); goto disable_rte_flow; } - pmd->if_index =if_nametoindex (pmd->name); -if (!pmd->if_index) { -TAP_LOG (ERR ,"%s: failed to get if_index." , pmd->name); - goto disable_rte_flow; - }if (qdisc_create_multiq (pmd->nlsk_fd, pmd->if_index) <0 ) {TAP_LOG (ERR ,"%s: failed to create multiq qdisc." , pmd->name);
@@ -2050,6 +2070,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, pmd->name); goto disable_rte_flow; } +LIST_INIT (&pmd->flows);if (strlen (remote_iface)) {
@@ -2102,6 +2123,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, goto error_remote; } } +#endif rte_eth_dev_probing_finish (dev);return 0 ;
@@ -2116,14 +2138,18 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,rte_eth_dev_probing_finish (dev);return 0 ; +#ifdef HAVE_TCA_FLOWER error_remote:TAP_LOG (ERR ," Can't set up remote feature: %s(%d)" ,strerror (errno), errno);tap_flow_implicit_flush (pmd,NULL ); +#endif error_exit: +#ifdef HAVE_TCA_FLOWER if (pmd->nlsk_fd !=-1 )close (pmd->nlsk_fd); +#endif if (pmd->ka_fd !=-1 )close (pmd->ka_fd);if (pmd->ioctl_sock !=-1 )
drivers/net/tap/rte_eth_tap.h +6 -1
@@ -16,6 +16,7 @@#include <ethdev_driver.h> #include <rte_ether.h> #include <rte_gso.h> +#include "tap_log.h" #ifdef IFF_MULTI_QUEUE
@@ -70,15 +71,17 @@ struct pmd_internals {char remote_iface[RTE_ETH_NAME_MAX_LEN ];/* Remote netdevice name */ char name[RTE_ETH_NAME_MAX_LEN ];/* Internal Tap device name */ int type;/* Type field - TUN|TAP */ +int persist;/* 1 if keep link up, else 0 */ struct rte_ether_addr eth_addr;/* Mac address of the device port */ struct ifreq remote_initial_flags;/* Remote netdevice flags on init */ int remote_if_index;/* remote netdevice IF_INDEX */ int if_index;/* IF_INDEX for the port */ int ioctl_sock;/* socket for ioctl calls */ + +#ifdef HAVE_TCA_FLOWER int nlsk_fd;/* Netlink socket fd */ int flow_isolate;/* 1 if flow isolation is enabled */ int rss_enabled;/* 1 if RSS is enabled, else 0 */ -int persist;/* 1 if keep link up, else 0 */ /* implicit rules set when RSS is enabled */ int map_fd;/* BPF RSS map fd */ int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */
@@ -86,6 +89,8 @@ struct pmd_internals { LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */ LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows; +#endif +struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES ];/* List of RX queues */ struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES ];/* List of TX queues */ struct rte_intr_handle *intr_handle;/* LSC interrupt handle. */
drivers/net/tap/tap_bpf.h deleted +0 -121
121 lines not on this page · raw message
drivers/net/tap/tap_bpf_api.c +13 -7
@@ -2,19 +2,19 @@* Copyright 2017 Mellanox Technologies, Ltd */ -#include <errno.h> -#include <string.h> #include <unistd.h> -#include <sys/queue.h> +#include <syscall.h> +#include <linux/bpf.h> -#include <rte_malloc.h> -#include <rte_eth_tap.h> #include <tap_flow.h> #include <tap_autoconf.h> -#include <tap_tcmsgs.h> -#include <tap_bpf.h> +#include <tap_bpf_insns.h> + +static int bpf_load (enum bpf_prog_type type,const struct bpf_insn *insns, +size_t insns_cnt,const char *license); +/** * Load BPF program (section cls_q) into the kernel and return a bpf fd *
@@ -89,7 +89,13 @@ static inline __u64 ptr_to_u64(const void *ptr)static inline int sys_bpf (enum bpf_cmd cmd,union bpf_attr *attr,unsigned int size) { +#ifdef __NR_bpfreturn syscall (__NR_bpf, cmd, attr, size); +#else +TAP_LOG (ERR ,"No bpf syscall, kernel headers too old?\n" ); + errno =ENOSYS ; +return -1 ; +#endif }/**
drivers/net/tap/tap_bpf_insns.h +0 -2
@@ -3,8 +3,6 @@* This not the original source file. Do NOT edit it. */ -#include <tap_bpf.h> -static struct bpf_insn cls_q_insns[] = { {0x61 ,2 ,1 ,52 ,0x00000000 }, {0x18 ,3 ,0 ,0 ,0xdeadbeef },
drivers/net/tap/tap_flow.c +0 -90
96 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v9 5/9 net/tap: rewrite the RSS BPF program
In reply to Stephen HemmingerRewrite the BPF program used to do queue based RSS. Important changes:
- uses newer BPF map format BTF
- accepts key as parameter rather than constant default
- can do L3 or L4 hashing
- supports IPv4 options
- supports IPv6 extension headers
- restructured for readability
The usage of BPF is different as well:
- the incoming configuration is looked up based on class parameters rather than patching the BPF.
- the resulting queue is placed in skb rather than requiring a second pass through classifier step.
Note: This version only works with later patch to enable it on the DPDK driver side. It is submitted as an incremental patch to allow for easier review. Bisection still works because the old instruction are still present for now.
--- .gitignore | 3 - drivers/net/tap/bpf/Makefile | 19 -- drivers/net/tap/bpf/README | 38 ++++ drivers/net/tap/bpf/bpf_api.h | 276 -------------------------- drivers/net/tap/bpf/bpf_elf.h | 53 ----- drivers/net/tap/bpf/bpf_extract.py | 85 -------- drivers/net/tap/bpf/meson.build | 81 ++++++++ drivers/net/tap/bpf/tap_bpf_program.c | 255 ------------------------ drivers/net/tap/bpf/tap_rss.c | 264 ++++++++++++++++++++++++ 9 files changed, 383 insertions(+), 691 deletions(-) delete mode 100644 drivers/net/tap/bpf/Makefile create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py create mode 100644 drivers/net/tap/bpf/meson.build delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c
.gitignore +0 -3
@@ -36,9 +36,6 @@ TAGS # ignore python bytecode files *.pyc -# ignore BPF programs -drivers/net/tap/bpf/tap_bpf_program.o - # DTS results dts/output
drivers/net/tap/bpf/Makefile deleted +0 -19
@@ -1,19 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# This file is not built as part of normal DPDK build. -# It is used to generate the eBPF code for TAP RSS. - -CLANG=clang -CLANG_OPTS=-O2 -TARGET=../tap_bpf_insns.h - -all: $(TARGET) - -clean: - rm tap_bpf_program.o $(TARGET) - -tap_bpf_program.o: tap_bpf_program.c - $(CLANG) $(CLANG_OPTS) -emit-llvm -c $< -o - | \ - llc -march=bpf -filetype=obj -o $@ - -$(TARGET): tap_bpf_program.o - python3 bpf_extract.py -stap_bpf_program.c -o $@ $<
drivers/net/tap/bpf/README new file +38 -0
@@ -0,0 +1,38 @@ +This is the BPF program used to implement the RSS across queues flow action. +The program is loaded when first RSS flow rule is created and is never unloaded. + +Each flow rule creates a unique key (handle) and this is used as the key +for finding the RSS information for that flow rule. + +This version is built the BPF Compile Once — Run Everywhere (CO-RE) +framework and uses libbpf and bpftool. + +Limitations +----------- +- requires libbpf to run +- rebuilding the BPF requires Clang and bpftool. + Some older versions of Ubuntu do not have working bpftool package. + Need a version of Clang that can compile to BPF. +- only standard Toeplitz hash with standard 40 byte key is supported +- the number of flow rules using RSS is limited to 32 + +Building +-------- +During the DPDK build process the meson build file checks that +libbpf, bpftool, and clang are not available. If everything is +there then BPF RSS is enabled. + +1. Using clang to compile tap_rss.c the tap_rss.bpf.o file. + +2. Using bpftool generate a skeleton header file tap_rss.skel.h from tap_rss.bpf.o. + This skeleton header is an large byte array which contains the + BPF binary and wrappers to load and use it. + +3. The tap flow code then compiles that BPF byte array into the PMD object. + +4. When needed the BPF array is loaded by libbpf. + +References +---------- +BPF and XDP reference guide +https://docs.cilium.io/en/latest/bpf/progtypes/
drivers/net/tap/bpf/bpf_api.h deleted +0 -276
276 lines not on this page · raw message
drivers/net/tap/bpf/bpf_elf.h deleted +0 -53
53 lines not on this page · raw message
drivers/net/tap/bpf/bpf_extract.py deleted +0 -85
85 lines not on this page · raw message
drivers/net/tap/bpf/meson.build new file +81 -0
81 lines not on this page · raw message
drivers/net/tap/bpf/tap_bpf_program.c deleted +0 -255
255 lines not on this page · raw message
drivers/net/tap/bpf/tap_rss.c new file +264 -0
264 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v9 5/9] net/tap: rewrite the RSS BPF program
Quoted 21 lines · Stephen Hemminger
Rewrite the BPF program used to do queue based RSS. Important changes:
- uses newer BPF map format BTF
- accepts key as parameter rather than constant default
- can do L3 or L4 hashing
- supports IPv4 options
- supports IPv6 extension headers
- restructured for readabilityThe usage of BPF is different as well:
- the incoming configuration is looked up based on class parameters rather than patching the BPF.
- the resulting queue is placed in skb rather than requiring a second pass through classifier step.Note: This version only works with later patch to enable it on the DPDK driver side. It is submitted as an incremental patch to allow for easier review. Bisection still works because the old instruction are still present for now.
Signed-off-by Stephen Hemminger <[email protected]>
<...>
Quoted 14 lines
drivers/net/tap/bpf/README new file +12
-0@@ -0,0 +1,38 @@ +This is the BPF program used to implement the RSS across queues flow action. +The program is loaded when first RSS flow rule is created and is never unloaded. + +Each flow rule creates a unique key (handle) and this is used as the key +for finding the RSS information for that flow rule. + +This version is built the BPF Compile Once — Run Everywhere (CO-RE) +framework and uses libbpf and bpftool. + +Limitations +----------- +- requires libbpf to run
drivers/net/tap/bpf/README line 22
Quoted 10 lines
drivers/net/tap/bpf/README new file +10
-0+- rebuilding the BPF requires Clang and bpftool. + Some older versions of Ubuntu do not have working bpftool package. + Need a version of Clang that can compile to BPF. +- only standard Toeplitz hash with standard 40 byte key is supported +- the number of flow rules using RSS is limited to 32 + +Building +-------- +During the DPDK build process the meson build file checks that +libbpf, bpftool, and clang are not available. If everything is
s/and clang are *not* available./and clang are available./ ?
PATCH v9 6/9 net/tap: use libbpf to load new BPF program
In reply to Stephen HemmingerThere were multiple issues in the RSS queue support in the TAP driver. This required extensive rework of the BPF support.
Change the BPF loading to use bpftool to
create a skeleton header file, and load with libbpf. The BPF is always compiled from source so less chance that source and instructions diverge. Also resolves issue where libbpf and source get out of sync. The program
is only loaded once, so if multiple rules are created only one BPF program is loaded in kernel.
The new BPF program only needs a single action.
No need for action and re-classification step.
It also fixes the missing bits from the original.
- supports setting RSS key per flow
- level of hash can be L3 or L3/L4.
--- drivers/net/tap/bpf/meson.build | 36 ++- drivers/net/tap/bpf/tap_rss.c | 45 ++-- drivers/net/tap/meson.build | 35 ++- drivers/net/tap/rte_eth_tap.c | 14 +- drivers/net/tap/rte_eth_tap.h | 6 +- drivers/net/tap/tap_flow.c | 418 ++++++++------------------------ drivers/net/tap/tap_flow.h | 17 +- drivers/net/tap/tap_rss.h | 10 +- drivers/net/tap/tap_tcmsgs.h | 4 +- 9 files changed, 189 insertions(+), 396 deletions(-)
drivers/net/tap/bpf/meson.build +31 -5
@@ -1,17 +1,26 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright 2024 Stephen Hemminger <[email protected]> -enable_tap_rss = false - -libbpf = dependency('libbpf', required: false, method: 'pkg-config') +# Loading BPF requires libbpf +# and the bpf_map__XXX API's were introduced in 0.8.0 +libbpf = dependency('libbpf', version: '>= 1.0', + required: false, method: 'pkg-config') if not libbpf.found() message('net/tap: no RSS support missing libbpf') subdir_done() endif +# Making skeleton needs bpftool # Debian install this in /usr/sbin which is not in $PATH -bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false, version: '>= 5.6.0') -if not bpftool.found() +bpftool_supports_skel = false +bpftool = find_program('bpftool', '/usr/sbin/bpftool', required: false) +if bpftool.found() + # Some Ubuntu versions have non-functional bpftool + bpftool_supports_skel = run_command(bpftool, 'gen', 'help', + check:false).returncode() == 0 +endif + +if not bpftool_supports_skel message('net/tap: no RSS support missing bpftool') subdir_done() endif
@@ -42,6 +51,7 @@ clang_flags = [ '-O2', '-Wall', '-Wextra', + max_queues, '-target', 'bpf', '-g',
@@ -67,6 +77,22 @@ skel_h_cmd = [ '@INPUT@' ] +vmlinux_h_cmd = [ + bpftool, + 'btf', + 'dump', + 'file', + '/sys/kernel/btf/vmlinux', + 'format', + 'c' +] + +vmlinux_h = custom_target( + 'vmlinux.h', + output: 'vmlinux.h', + command: vmlinux_h_cmd, + capture: true) + tap_rss_o = custom_target( 'tap_rss.bpf.o', input: 'tap_rss.c',
drivers/net/tap/bpf/tap_rss.c +24 -21
67 lines not on this page · raw message
drivers/net/tap/meson.build +16 -19
@@ -5,36 +5,33 @@ if not is_linux build = false reason = 'only supported on Linux' endif + sources = files( 'rte_eth_tap.c', 'tap_intr.c', 'tap_netlink.c', ) +deps = ['bus_vdev', 'gso', 'hash'] + +max_queues = '-DTAP_MAX_QUEUES=16' +cflags += max_queues + +require_iova_in_mbuf = false + if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT') cflags += '-DHAVE_TCA_FLOWER' sources += files( - 'tap_bpf_api.c', 'tap_flow.c', 'tap_tcmsgs.c', ) -endif - -deps = ['bus_vdev', 'gso', 'hash'] -cflags += '-DTAP_MAX_QUEUES=16' - -# input array for meson symbol search: -# [ "MACRO to define if found", "header for the search", -# "enum/define", "symbol to search" ] -# -args = [ - [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ], -] -config = configuration_data() -foreach arg:args - config.set(arg[0], cc.has_header_symbol(arg[1], arg[2])) -endforeach -configure_file(output : 'tap_autoconf.h', configuration : config) + enable_tap_rss = false -require_iova_in_mbuf = false + subdir('bpf') + if enable_tap_rss + cflags += '-DHAVE_BPF_RSS' + ext_deps += libbpf + sources += tap_rss_skel_h + endif +endif
drivers/net/tap/rte_eth_tap.c +7 -7
@@ -1131,6 +1131,7 @@ tap_dev_close(struct rte_eth_dev *dev)tap_flow_implicit_flush (internals,NULL );tap_nl_final (internals->nlsk_fd); internals->nlsk_fd =-1 ; + tap_flow_bpf_destroy(internals); }#endif
@@ -1956,6 +1957,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,strlcpy (pmd->name, tap_name,sizeof (pmd->name)); pmd->type = type; pmd->ka_fd =-1 ; +#ifdef HAVE_TCA_FLOWER pmd->nlsk_fd =-1 ;#endif
@@ -2038,13 +2040,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,/* Make network device persist after application exit */ pmd->persist = persist; - pmd->if_index =if_nametoindex (pmd->name); -if (!pmd->if_index) { -TAP_LOG (ERR ,"%s: failed to get if_index." , pmd->name); - goto disable_rte_flow; - } - -#ifdef HAVE_TCA_FLOWER /* * Set up everything related to rte_flow:
@@ -2060,6 +2055,11 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, pmd->name); goto disable_rte_flow; } + pmd->if_index =if_nametoindex (pmd->name); +if (!pmd->if_index) { +TAP_LOG (ERR ,"%s: failed to get if_index." , pmd->name); + goto disable_rte_flow; + }if (qdisc_create_multiq (pmd->nlsk_fd, pmd->if_index) <0 ) {TAP_LOG (ERR ,"%s: failed to create multiq qdisc." , pmd->name);
drivers/net/tap/rte_eth_tap.h +2 -4
@@ -81,10 +81,8 @@ struct pmd_internals {#ifdef HAVE_TCA_FLOWER int nlsk_fd;/* Netlink socket fd */ int flow_isolate;/* 1 if flow isolation is enabled */ -int rss_enabled;/* 1 if RSS is enabled, else 0 */ -/* implicit rules set when RSS is enabled */ -int map_fd;/* BPF RSS map fd */ -int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */ + +struct tap_rss *rss;/* BPF program */ LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */
drivers/net/tap/tap_flow.c +97 -321
555 lines not on this page · raw message
drivers/net/tap/tap_flow.h +6 -11
@@ -9,7 +9,11 @@#include <rte_flow.h> #include <rte_flow_driver.h> #include <rte_eth_tap.h> -#include <tap_autoconf.h> + +/** +* Mask of unsupported RSS types +*/ +#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP))/** * In TC, priority 0 means we require the kernel to allocate one for us.
@@ -41,11 +45,6 @@ enum implicit_rule_index { TAP_REMOTE_MAX_IDX, }; -enum bpf_fd_idx { -SEC_L3_L4 , -SEC_MAX , -}; -int tap_dev_flow_ops_get (struct rte_eth_dev *dev,const struct rte_flow_ops **ops);int tap_flow_flush (struct rte_eth_dev *dev,struct rte_flow_error *error);
@@ -57,10 +56,6 @@ int tap_flow_implicit_destroy(struct pmd_internals *pmd,int tap_flow_implicit_flush (struct pmd_internals *pmd,struct rte_flow_error *error); -int tap_flow_bpf_cls_q (__u32 queue_idx); -int tap_flow_bpf_calc_l3_l4_hash (__u32 key_idx,int map_fd); -int tap_flow_bpf_rss_map_create (unsigned int key_size,unsigned int value_size, -unsigned int max_entries); -int tap_flow_bpf_update_rss_elem (int fd,void *key,void *value); +void tap_flow_bpf_destroy (struct pmd_internals *pmd);#endif /* _TAP_FLOW_H_ */
drivers/net/tap/tap_rss.h +4 -6
@@ -5,16 +5,14 @@#ifndef _TAP_RSS_H_#define _TAP_RSS_H_ -#ifndef TAP_MAX_QUEUES -#define TAP_MAX_QUEUES 16 +/* Size of the map from BPF classid to queue table */ +#ifndef TAP_RSS_MAX +#define TAP_RSS_MAX 32#endif -/* Fixed RSS hash key size in bytes. */ +/* Standard Toeplitz hash key size */ #define TAP_RSS_HASH_KEY_SIZE 40 -/* Supported RSS */ -#define TAP_RSS_HF_MASK (~(RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP)) -/* hashed fields for RSS */ enum hash_field { HASH_FIELD_IPV4_L3, /* IPv4 src/dst addr */
drivers/net/tap/tap_tcmsgs.h +2 -2
@@ -6,7 +6,6 @@#ifndef _TAP_TCMSGS_H_#define _TAP_TCMSGS_H_ -#include <tap_autoconf.h> #include <linux/if_ether.h> #include <linux/rtnetlink.h> #include <linux/pkt_sched.h>
@@ -14,9 +13,10 @@#include <linux/tc_act/tc_mirred.h> #include <linux/tc_act/tc_gact.h> #include <linux/tc_act/tc_skbedit.h> -#ifdef HAVE_TC_ACT_BPF +#ifdef HAVE_BPF_RSS #include <linux/tc_act/tc_bpf.h> #endif +#include <inttypes.h> #include <rte_ether.h>
Signature · 1 line
2.43.0
PATCH v9 7/9 net/tap: remove no longer used files
In reply to Stephen HemmingerThe BPF api was replaced by use of libbpf.
And the BPF instruction header was replaced by the skeleton.
--- drivers/net/tap/tap_bpf_api.c | 196 ---- drivers/net/tap/tap_bpf_insns.h | 1741 ------------------------------- 2 files changed, 1937 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h
drivers/net/tap/tap_bpf_api.c deleted +0 -196
@@ -1,196 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause -* Copyright 2017 Mellanox Technologies, Ltd -*/ - -#include <unistd.h> -#include <syscall.h> -#include <linux/bpf.h> - -#include <tap_flow.h> -#include <tap_autoconf.h> - -#include <tap_bpf_insns.h> - - -static int bpf_load (enum bpf_prog_type type,const struct bpf_insn *insns, -size_t insns_cnt,const char *license); - -/** -* Load BPF program (section cls_q) into the kernel and return a bpf fd -* -* @param queue_idx -* Queue index matching packet cb -* -* @return -* -1 if the BPF program couldn't be loaded. An fd (int) otherwise. -*/ -int tap_flow_bpf_cls_q (__u32 queue_idx) -{ - cls_q_insns[1 ].imm = queue_idx; - -return bpf_load (BPF_PROG_TYPE_SCHED_CLS , - (struct bpf_insn *)cls_q_insns, -RTE_DIM (cls_q_insns), -"Dual BSD/GPL" ); -} - -/** -* Load BPF program (section l3_l4) into the kernel and return a bpf fd. -* -* @param[in] key_idx -* RSS MAP key index -* -* @param[in] map_fd -* BPF RSS map file descriptor -* -* @return -* -1 if the BPF program couldn't be loaded. An fd (int) otherwise. -*/ -int tap_flow_bpf_calc_l3_l4_hash (__u32 key_idx,int map_fd) -{ - l3_l4_hash_insns[4 ].imm = key_idx; - l3_l4_hash_insns[9 ].imm = map_fd; - -return bpf_load (BPF_PROG_TYPE_SCHED_ACT , - (struct bpf_insn *)l3_l4_hash_insns, -RTE_DIM (l3_l4_hash_insns), -"Dual BSD/GPL" ); -} - -/** -* Helper function to convert a pointer to unsigned 64 bits -* -* @param[in] ptr -* pointer to address -* -* @return -* 64 bit unsigned long type of pointer address -*/ -static inline __u64 ptr_to_u64 (const void *ptr) -{ -return (__u64 )(unsigned long )ptr; -} - -/** -* Call BPF system call -* -* @param[in] cmd -* BPF command for program loading, map creation, map entry update, etc -* -* @param[in] attr -* System call attributes relevant to system call command -* -* @param[in] size -* size of attr parameter -* -* @return -* -1 if BPF system call failed, 0 otherwise -*/ -static inline int sys_bpf (enum bpf_cmd cmd,union bpf_attr *attr, -unsigned int size) -{ -#ifdef __NR_bpf -return syscall (__NR_bpf, cmd, attr, size); -#else -TAP_LOG (ERR ,"No bpf syscall, kernel headers too old?\n" ); - errno =ENOSYS ; -return -1 ; -#endif -} - -/** -* Load BPF instructions to kernel -* -* @param[in] type -* BPF program type: classifier or action -* -* @param[in] insns -* Array of BPF instructions (equivalent to BPF instructions) -* -* @param[in] insns_cnt -* Number of BPF instructions (size of array) -* -* @param[in] license -* License string that must be acknowledged by the kernel -* -* @return -* -1 if the BPF program couldn't be loaded, fd (file descriptor) otherwise -*/ -static int bpf_load (enum bpf_prog_type type, -const struct bpf_insn *insns, -size_t insns_cnt, -const char *license) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - attr.prog_type = type; - attr.insn_cnt = (__u32 )insns_cnt; - attr.insns =ptr_to_u64 (insns); - attr.license =ptr_to_u64 (license); - attr.log_buf =ptr_to_u64 (NULL ); - attr.log_level =0 ; - attr.kern_version =0 ; - -return sys_bpf (BPF_PROG_LOAD , &attr,sizeof (attr)); -} - -/** -* Create BPF map for RSS rules -* -* @param[in] key_size -* map RSS key size -* -* @param[in] value_size -* Map RSS value size -* -* @param[in] max_entries -* Map max number of RSS entries (limit on max RSS rules) -* -* @return -* -1 if BPF map couldn't be created, map fd otherwise -*/ -int tap_flow_bpf_rss_map_create (unsigned int key_size, -unsigned int value_size, -unsigned int max_entries) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - attr.map_type =BPF_MAP_TYPE_HASH ; - attr.key_size = key_size; - attr.value_size = value_size; - attr.max_entries = max_entries; - -return sys_bpf (BPF_MAP_CREATE , &attr,sizeof (attr)); -} - -/** -* Update RSS entry in BPF map -* -* @param[in] fd -* RSS map fd -* -* @param[in] key -* Pointer to RSS key whose entry is updated -* -* @param[in] value -* Pointer to RSS new updated value -* -* @return -* -1 if RSS entry failed to be updated, 0 otherwise -*/ -int tap_flow_bpf_update_rss_elem (int fd,void *key,void *value) -{ -union bpf_attr attr = {}; - -bzero (&attr,sizeof (attr)); - - attr.map_type =BPF_MAP_TYPE_HASH ; - attr.map_fd = fd; - attr.key =ptr_to_u64 (key); - attr.value =ptr_to_u64 (value); - attr.flags =BPF_ANY ; - -return sys_bpf (BPF_MAP_UPDATE_ELEM , &attr,sizeof (attr)); -}
drivers/net/tap/tap_bpf_insns.h deleted +0 -1741
1,741 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v9 8/9 doc: update documentation of TAP PMD
In reply to Stephen HemmingerThe driver support of flows has changed and the wording in the guide was awkward.
Drop references to DPDK pktgen in this documentation since it is not required and confusing.
--- doc/guides/linux_gsg/sys_reqs.rst | 3 + doc/guides/nics/tap.rst | 274 +++++++++--------------------- 2 files changed, 80 insertions(+), 197 deletions(-)
doc/guides/linux_gsg/sys_reqs.rst +3 -0
@@ -101,6 +101,9 @@ Running DPDK Applications To run a DPDK application, some customization may be required on the target machine. +.. _linux_gsg_kernel_version: + + System Software ~~~~~~~~~~~~~~~
doc/guides/nics/tap.rst +77 -197
333 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v9 8/9] doc: update documentation of TAP PMD
Quoted 17 lines · Stephen Hemminger
The driver support of flows has changed and the wording in the guide was awkward.
Drop references to DPDK pktgen in this documentation since it is not required and confusing.
Signed-off-by Stephen Hemminger <[email protected]>--- doc/guides/linux_gsg/sys_reqs.rst | 3 + doc/guides/nics/tap.rst | 274 +++++++++--------------------- 2 files changed, 80 insertions(+), 197 deletions(-)doc/guides/linux_gsg/sys_reqs.rst +0
-0
doc/guides/linux_gsg/sys_reqs.rst Running DPDK Applications · line 107
Quoted 7 lines
doc/guides/linux_gsg/sys_reqs.rst +3
-0@@ -101,6 +101,9 @@ Running DPDK Applications To run a DPDK application, some customization may be required on the target machine. +.. _linux_gsg_kernel_version: + +
I guess there was an intention to use this document as reference, but I don't see the link. Perhaps anchor is no more required?
Quoted 335 lines
doc/guides/linux_gsg/sys_reqs.rst +0
-0System Software ~~~~~~~~~~~~~~~doc/guides/nics/tap.rst +72
-196@@ -1,47 +1,51 @@ .. SPDX-License-Identifier: BSD-3-Clause Copyright(c) 2016 Intel Corporation. -Tun|Tap Poll Mode Driver -======================== +TAP Poll Mode Driver +==================== -The ``rte_eth_tap.c`` PMD creates a device using TAP interfaces on the -local host. The PMD allows for DPDK and the host to communicate using a raw -device interface on the host and in the DPDK application. +The TAP Poll Mode Driver (PMD) is a virtual device for injecting packets to be processed +by the Linux kernel. This PMD is useful when writing DPDK application +for offloading network functionality (such as tunneling) from the kernel. -The device created is a TAP device, which sends/receives packet in a raw -format with a L2 header. The usage for a TAP PMD is for connectivity to the -local host using a TAP interface. When the TAP PMD is initialized it will -create a number of tap devices in the host accessed via ``ifconfig -a`` or -``ip`` command. The commands can be used to assign and query the virtual like -device. +From the kernel point of view, the TAP device looks like a regular network interface. +The network device can be managed by standard tools such as ``ip`` and ``ethtool`` commands. +It is also possible to use existing packet tools such as ``wireshark`` or ``tcpdump``. -These TAP interfaces can be used with Wireshark or tcpdump or Pktgen-DPDK -along with being able to be used as a network connection to the DPDK -application. The method enable one or more interfaces is to use the -``--vdev=net_tap0`` option on the DPDK application command line. Each -``--vdev=net_tap1`` option given will create an interface named dtap0, dtap1, -and so on. +From the DPDK application, the TAP device looks like a DPDK ethdev. +Packets are sent and received in L2 (Ethernet) format. The standare DPDK +API's to query for information, statistics and send and receive packets +work as expected. -The interface name can be changed by adding the ``iface=foo0``, for example:: +Requirements +~~~~~~~~~~~~ + +The TAP PMD requires kernel support for multiple queues in TAP device as +well as the multi-queue ``multiq`` and incoming ``ingress`` queue disciplines. +These are standard kernel features in most Linux distributions. + +Arguments +--------- + +TAP devices are created with the command line +``--vdev=net_tap0`` option. This option maybe specified more the once by repeating +with a different ``net_tapX`` device. + +By default, the Linux interfaces are named ``dtap0``, ``dtap1``, etc. +The interface name can be specified by adding the ``iface=foo0``, for example:: --vdev=net_tap0,iface=foo0 --vdev=net_tap1,iface=foo1, ... -Normally the PMD will generate a random MAC address, but when testing or with -a static configuration the developer may need a fixed MAC address style. -Using the option ``mac=fixed`` you can create a fixed known MAC address:: +Normally the PMD will generate a random MAC address. +If a static address is desired instead, the ``mac=fixed`` can be used. --vdev=net_tap0,mac=fixed -The MAC address will have a fixed value with the last octet incrementing by one -for each interface string containing ``mac=fixed``. The MAC address is formatted -as 02:'d':'t':'a':'p':[00-FF]. Convert the characters to hex and you get the -actual MAC address: ``02:64:74:61:70:[00-FF]``. - - --vdev=net_tap0,mac="02:64:74:61:70:11" +With the fixed option, the MAC address will have the first octets: +as 02:'d':'t':'a':'p':[00-FF] and the last octets are the interface number. -The MAC address will have a user value passed as string. The MAC address is in -format with delimiter ``:``. The string is byte converted to hex and you get -the actual MAC address: ``02:64:74:61:70:11``. +To specify a specific MAC address use the conventional representation. +The string is byte converted to hex, the result is MAC address: ``02:64:74:61:70:11``. It is possible to specify a remote netdevice to capture packets from by adding ``remote=foo1``, for example::@@ -59,40 +63,20 @@ netdevice that has no support in the DPDK. It is possible to add explicit rte_flow rules on the tap PMD to capture specific traffic (see next section for examples). -After the DPDK application is started you can send and receive packets on the -interface using the standard rx_burst/tx_burst APIs in DPDK. From the host -point of view you can use any host tool like tcpdump, Wireshark, ping, Pktgen -and others to communicate with the DPDK application. The DPDK application may -not understand network protocols like IPv4/6, UDP or TCP unless the -application has been written to understand these protocols. - -If you need the interface as a real network interface meaning running and has -a valid IP address then you can do this with the following commands:: - - sudo ip link set dtap0 up; sudo ip addr add 192.168.0.250/24 dev dtap0 - sudo ip link set dtap1 up; sudo ip addr add 192.168.1.250/24 dev dtap1 - -Please change the IP addresses as you see fit. - -If routing is enabled on the host you can also communicate with the DPDK App -over the internet via a standard socket layer application as long as you -account for the protocol handling in the application. - -If you have a Network Stack in your DPDK application or something like it you -can utilize that stack to handle the network protocols. Plus you would be able -to address the interface using an IP address assigned to the internal -interface. - Normally, when the DPDK application exits, the TAP device is marked down and is removed. -But this behaviour can be overridden by the use of the persist flag, example:: +But this behavior can be overridden by the use of the persist flag, example:: --vdev=net_tap0,iface=tap0,persist ... -The TUN PMD allows user to create a TUN device on host. The PMD allows user -to transmit and receive packets via DPDK API calls with L3 header and payload. -The devices in host can be accessed via ``ifconfig`` or ``ip`` command. TUN -interfaces are passed to DPDK ``rte_eal_init`` arguments as ``--vdev=net_tunX``, +TUN devices +----------- + +The TAP device can be used an L3 tunnel only device (TUN). +This type of device does not include the Ethernet (L2) header; all packets +are sent and received as IP packets. + +TUN devices are created with the command line arguments ``--vdev=net_tunX``, where X stands for unique id, example:: --vdev=net_tun0 --vdev=net_tun1,iface=foo1, ...@@ -103,27 +87,33 @@ options. Default interface name is ``dtunX``, where X stands for unique id. Flow API support ---------------- -The tap PMD supports major flow API pattern items and actions, when running on -linux kernels above 4.2 ("Flower" classifier required). -The kernel support can be checked with this command:: +The TAP PMD supports major flow API pattern items and actions. + +Requirements +~~~~~~~~~~~~ - zcat /proc/config.gz | ( grep 'CLS_FLOWER=' || echo 'not supported' ) | - tee -a /dev/stderr | grep -q '=m' && - lsmod | ( grep cls_flower || echo 'try modprobe cls_flower' ) +Flow support in TAP driver requires the Linux kernel support of flow based +traffic control filter ``flower``. This was added in Linux 4.3 kernel. -Supported items: +The implementation of RSS action uses an eBPF module that requires additional +libraries and tools. Building the RSS support requires the ``clang`` +compiler to compile the C code to BPF target; ``bpftool`` to convert the +compiled BPF object to a header file; and ``libbpf`` to load the eBPF +action into the kernel. -- eth: src and dst (with variable masks), and eth_type (0xffff mask). -- vlan: vid, pcp, but not eid. (requires kernel 4.9) -- ipv4/6: src and dst (with variable masks), and ip_proto (0xffff mask). -- udp/tcp: src and dst port (0xffff) mask. +Supported match items: + + - eth: src and dst (with variable masks), and eth_type (0xffff mask). + - vlan: vid, pcp, but not eid. (requires kernel 4.9) + - ipv4/6: src and dst (with variable masks), and ip_proto (0xffff mask). + - udp/tcp: src and dst port (0xffff) mask. Supported actions: - DROP - QUEUE - PASSTHRU -- RSS (requires kernel 4.9) +- RSS It is generally not possible to provide a "last" item. However, if the "last" item, once masked, is identical to the masked spec, then it is supported.@@ -133,7 +123,7 @@ full mask (exact match). As rules are translated to TC, it is possible to show them with something like:: - tc -s filter show dev tap1 parent 1: + tc -s filter show dev dtap1 parent 1: Examples of testpmd flow rules ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~@@ -174,135 +164,25 @@ The IPC synchronization of Rx/Tx queues is currently limited: - Maximum 8 queues shared - Synchronized on probing, but not on later port update -Example -------- - -The following is a simple example of using the TAP PMD with the Pktgen -packet generator. It requires that the ``socat`` utility is installed on the -test system. - -Build DPDK, then pull down Pktgen and build pktgen using the DPDK SDK/Target -used to build the dpdk you pulled down. - -Run pktgen from the pktgen directory in a terminal with a commandline like the -following:: - - sudo ./app/app/x86_64-native-linux-gcc/app/pktgen -l 1-5 -n 4 \ - --proc-type auto --log-level debug --socket-mem 512,512 --file-prefix pg \ - --vdev=net_tap0 --vdev=net_tap1 -b 05:00.0 -b 05:00.1 \ - -b 04:00.0 -b 04:00.1 -b 04:00.2 -b 04:00.3 \ - -b 81:00.0 -b 81:00.1 -b 81:00.2 -b 81:00.3 \ - -b 82:00.0 -b 83:00.0 -- -T -P -m [2:3].0 -m [4:5].1 \ - -f themes/black-yellow.theme - -.. Note: - - Change the ``-b`` options to exclude all of your physical ports. The - following command line is all one line. - - Also, ``-f themes/black-yellow.theme`` is optional if the default colors - work on your system configuration. See the Pktgen docs for more - information. - -Verify with ``ifconfig -a`` command in a different xterm window, should have a -``dtap0`` and ``dtap1`` interfaces created. - -Next set the links for the two interfaces to up via the commands below:: - - sudo ip link set dtap0 up; sudo ip addr add 192.168.0.250/24 dev dtap0 - sudo ip link set dtap1 up; sudo ip addr add 192.168.1.250/24 dev dtap1 - -Then use socat to create a loopback for the two interfaces:: - - sudo socat interface:dtap0 interface:dtap1 - -Then on the Pktgen command line interface you can start sending packets using -the commands ``start 0`` and ``start 1`` or you can start both at the same -time with ``start all``. The command ``str`` is an alias for ``start all`` and -``stp`` is an alias for ``stop all``. - -While running you should see the 64 byte counters increasing to verify the -traffic is being looped back. You can use ``set all size XXX`` to change the -size of the packets after you stop the traffic. Use pktgen ``help`` -command to see a list of all commands. You can also use the ``-f`` option to -load commands at startup in command line or Lua script in pktgen. RSS specifics ------------- -Packet distribution in TAP is done by the kernel which has a default -distribution. This feature is adding RSS distribution based on eBPF code. -The default eBPF code calculates RSS hash based on Toeplitz algorithm for -a fixed RSS key. It is calculated on fixed packet offsets. For IPv4 and IPv6 it -is calculated over src/dst addresses (8 or 32 bytes for IPv4 or IPv6 -respectively) and src/dst TCP/UDP ports (4 bytes). - -The RSS algorithm is written in file ``tap_bpf_program.c`` which -does not take part in TAP PMD compilation. Instead this file is compiled -in advance to eBPF object file. The eBPF object file is then parsed and -translated into eBPF byte code in the format of C arrays of eBPF -instructions. The C array of eBPF instructions is part of TAP PMD tree and -is taking part in TAP PMD compilation. At run time the C arrays are uploaded to -the kernel via BPF system calls and the RSS hash is calculated by the -kernel. - -It is possible to support different RSS hash algorithms by updating file -``tap_bpf_program.c`` In order to add a new RSS hash algorithm follow these -steps: - -#. Write the new RSS implementation in file ``tap_bpf_program.c`` - - BPF programs which are uploaded to the kernel correspond to - C functions under different ELF sections. - -#. Install ``LLVM`` library and ``clang`` compiler versions 3.7 and above - -#. Use make to compile `tap_bpf_program.c`` via ``LLVM`` into an object file - and extract the resulting instructions into ``tap_bpf_insn.h``:: - - cd bpf; make - -#. Recompile the TAP PMD. - -The C arrays are uploaded to the kernel using BPF system calls. - -``tc`` (traffic control) is a well known user space utility program used to -configure the Linux kernel packet scheduler. It is usually packaged as -part of the ``iproute2`` package. -Since commit 11c39b5e9 ("tc: add eBPF support to f_bpf") ``tc`` can be used -to uploads eBPF code to the kernel and can be patched in order to print the -C arrays of eBPF instructions just before calling the BPF system call. -Please refer to ``iproute2`` package file ``lib/bpf.c`` function -``bpf_prog_load()``. - -An example utility for eBPF instruction generation in the format of C arrays will -be added in next releases - -TAP reports on supported RSS functions as part of dev_infos_get callback: -``RTE_ETH_RSS_IP``, ``RTE_ETH_RSS_UDP`` and ``RTE_ETH_RSS_TCP``. -**Known limitation:** TAP supports all of the above hash functions together -and not in partial combinations. - -Systems supporting flow API ---------------------------- - -- "tc flower" classifier requires linux kernel above 4.2 -- eBPF/RSS requires linux kernel above 4.9 - -+--------------------+-----------------------+ -| RH7.3 | No flow rule support | -+--------------------+-----------------------+ -| RH7.4 | No RSS action support | -+--------------------+-----------------------+ -| RH7.5 | No RSS action support | -+--------------------+-----------------------+ -| SLES 15, | No limitation | -| kernel 4.12 | | -+--------------------+-----------------------+ -| Azure Ubuntu 16.04,| No limitation | -| kernel 4.13 | | -+--------------------+-----------------------+ +The default packet distribution in TAP without flow rules is done by the +kernel which has a default flow based distribution. +When flow rules are used to distribute packets across a set of queues +an eBPF program is used to calculate the RSS based on Toeplitz algorithm for +with the given key. + +The hash is calculated for IPv4 and IPv6, over src/dst addresses +(8 or 32 bytes for IPv4 or IPv6 respectively) and +optionally the src/dst TCP/UDP ports (4 bytes). +
doc/guides/nics/tap.rst The IPC synchronization of Rx/Tx queues is currently limited: · line 188
Quoted 10 lines
doc/guides/nics/tap.rst +5
-1Limitations ----------- -* Rx/Tx must have the same number of queues. +- Since TAP device uses a file descriptors to talk to the kernel. + The same number of queues must be specified for receive and transmit. + +- The RSS algorithm only support L3 or L4 functions. It does not support + finer grain selections (for example: only IPV6 packets with extension headers).
Section headers in the document seems mixed up, it is currently as following, I don't think this was the intention:
TAP
Requirements
Arguments
TUN devices
Flow API support
Requirements
Examples of testpmd flow rules
Multi-process sharing
RSS specifics
Limitations
PATCH v9 9/9 net/tap: simplify the internal structure
In reply to Stephen HemmingerThe names of Linux network devices are IFNAMSIZ(16) not the same as DPDK which has up to 64 characters. Don't need to hold onto the whole ifreq to save the remote interface flags.
Rearrange internal structure for locality.
--- drivers/net/tap/rte_eth_tap.c | 42 ++++++++++++++++++++++------------- drivers/net/tap/rte_eth_tap.h | 12 +++++----- 2 files changed, 32 insertions(+), 22 deletions(-)
drivers/net/tap/rte_eth_tap.c +26 -16
@@ -212,7 +212,7 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent)* and need to find the resulting device. */ TAP_LOG (DEBUG ,"Device name is '%s'" , ifr.ifr_name); -strlcpy (pmd->name, ifr.ifr_name,RTE_ETH_NAME_MAX_LEN ); +strlcpy (pmd->name, ifr.ifr_name,IFNAMSIZ );if (is_keepalive) {/*
@@ -1151,9 +1151,13 @@ tap_dev_close(struct rte_eth_dev *dev) }if (internals->remote_if_index) { +struct ifreq remote_ifr; + +strlcpy (remote_ifr.ifr_name, internals->remote_iface,IFNAMSIZ ); + remote_ifr.ifr_flags = internals->remote_flags; +/* Restore initial remote state */ -int ret =ioctl (internals->ioctl_sock,SIOCSIFFLAGS , - &internals->remote_initial_flags); +int ret =ioctl (internals->ioctl_sock,SIOCSIFFLAGS , &remote_ifr);if (ret)TAP_LOG (ERR ,"restore remote state failed: %d" , ret);
@@ -2074,16 +2078,22 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,LIST_INIT (&pmd->flows);if (strlen (remote_iface)) { +struct ifreq remote_ifr; + pmd->remote_if_index =if_nametoindex (remote_iface);if (!pmd->remote_if_index) {TAP_LOG (ERR ,"%s: failed to get %s if_index." , pmd->name, remote_iface); goto error_remote; } -strlcpy (pmd->remote_iface, remote_iface,RTE_ETH_NAME_MAX_LEN ); +strlcpy (pmd->remote_iface, remote_iface,IFNAMSIZ ); + +memset (&remote_ifr,0 ,sizeof (ifr)); +strlcpy (remote_ifr.ifr_name, remote_iface,IFNAMSIZ );/* Save state of remote device */ -tap_ioctl (pmd,SIOCGIFFLAGS , &pmd->remote_initial_flags,0 ,REMOTE_ONLY ); +tap_ioctl (pmd,SIOCGIFFLAGS , &remote_ifr,0 ,REMOTE_ONLY ); + pmd->remote_flags = remote_ifr.ifr_flags;/* Replicate remote MAC address */ if (tap_ioctl (pmd,SIOCGIFHWADDR , &ifr,0 ,REMOTE_ONLY ) <0 ) {
@@ -2197,10 +2207,10 @@ set_interface_name(const char *key __rte_unused, value);return -1 ; } -strlcpy (name, value,RTE_ETH_NAME_MAX_LEN ); +strlcpy (name, value,IFNAMSIZ ); }else {/* use tap%d which causes kernel to choose next available */ -strlcpy (name,DEFAULT_TAP_NAME "%d" ,RTE_ETH_NAME_MAX_LEN ); +strlcpy (name,DEFAULT_TAP_NAME "%d" ,IFNAMSIZ ); }return 0 ; }
@@ -2218,7 +2228,7 @@ set_remote_iface(const char *key __rte_unused, value);return -1 ; } -strlcpy (name, value,RTE_ETH_NAME_MAX_LEN ); +strlcpy (name, value,IFNAMSIZ ); }return 0 ;
@@ -2269,13 +2279,13 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)const char *name, *params;int ret;struct rte_kvargs *kvlist =NULL ; -char tun_name[RTE_ETH_NAME_MAX_LEN ]; -char remote_iface[RTE_ETH_NAME_MAX_LEN ]; +char tun_name[IFNAMSIZ ]; +char remote_iface[IFNAMSIZ ];struct rte_eth_dev *eth_dev; name =rte_vdev_device_name (dev); params =rte_vdev_device_args (dev); -memset (remote_iface,0 ,RTE_ETH_NAME_MAX_LEN ); +memset (remote_iface,0 ,IFNAMSIZ );if (rte_eal_process_type () ==RTE_PROC_SECONDARY &&strlen (params) ==0 ) {
@@ -2291,7 +2301,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) }/* use tun%d which causes kernel to choose next available */ -strlcpy (tun_name,DEFAULT_TUN_NAME "%d" ,RTE_ETH_NAME_MAX_LEN ); +strlcpy (tun_name,DEFAULT_TUN_NAME "%d" ,IFNAMSIZ );if (params && (params[0 ] !='\0' )) {TAP_LOG (DEBUG ,"parameters (%s)" , params);
@@ -2431,8 +2441,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)int ret;struct rte_kvargs *kvlist =NULL ;int speed; -char tap_name[RTE_ETH_NAME_MAX_LEN ]; -char remote_iface[RTE_ETH_NAME_MAX_LEN ]; +char tap_name[IFNAMSIZ ]; +char remote_iface[IFNAMSIZ ];struct rte_ether_addr user_mac = { .addr_bytes = {0 } };struct rte_eth_dev *eth_dev;int tap_devices_count_increased =0 ;
@@ -2486,8 +2496,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) speed =RTE_ETH_SPEED_NUM_10G ;/* use tap%d which causes kernel to choose next available */ -strlcpy (tap_name,DEFAULT_TAP_NAME "%d" ,RTE_ETH_NAME_MAX_LEN ); -memset (remote_iface,0 ,RTE_ETH_NAME_MAX_LEN ); +strlcpy (tap_name,DEFAULT_TAP_NAME "%d" ,IFNAMSIZ ); +memset (remote_iface,0 ,IFNAMSIZ );if (params && (params[0 ] !='\0' )) {TAP_LOG (DEBUG ,"parameters (%s)" , params);
drivers/net/tap/rte_eth_tap.h +6 -6
@@ -68,15 +68,16 @@ struct tx_queue {struct pmd_internals {struct rte_eth_dev *dev;/* Ethernet device. */ -char remote_iface[RTE_ETH_NAME_MAX_LEN ];/* Remote netdevice name */ -char name[RTE_ETH_NAME_MAX_LEN ];/* Internal Tap device name */ +char remote_iface[IFNAMSIZ ];/* Remote netdevice name */ +char name[IFNAMSIZ ];/* Internal Tap device name */ int type;/* Type field - TUN|TAP */ int persist;/* 1 if keep link up, else 0 */ struct rte_ether_addr eth_addr;/* Mac address of the device port */ -struct ifreq remote_initial_flags;/* Remote netdevice flags on init */ +uint16_t remote_flags;/* Remote netdevice flags on init */ int remote_if_index;/* remote netdevice IF_INDEX */ int if_index;/* IF_INDEX for the port */ int ioctl_sock;/* socket for ioctl calls */ +int ka_fd;/* keep-alive file descriptor */ #ifdef HAVE_TCA_FLOWER int nlsk_fd;/* Netlink socket fd */
@@ -88,12 +89,11 @@ struct pmd_internals {/* implicit rte_flow rules set when a remote device is active */ LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;#endif +struct rte_intr_handle *intr_handle;/* LSC interrupt handle. */ +struct rte_mempool *gso_ctx_mp;/* Mempool for GSO packets */ struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES ];/* List of RX queues */ struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES ];/* List of TX queues */ -struct rte_intr_handle *intr_handle;/* LSC interrupt handle. */ -int ka_fd;/* keep-alive file descriptor */ -struct rte_mempool *gso_ctx_mp;/* Mempool for GSO packets */ };struct pmd_process_private {
Signature · 1 line
2.43.0
Re: [PATCH v9 0/9] net/tap: fix RSS (BPF) support
In reply to Stephen HemmingerQuoted 14 lines · Stephen Hemminger
The support of doing RSS for
rte_flow_actionwas a cool idea but it has been broken for several releases of DPDK as the kernel and BPF infrastructure changed.This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF toolchain.
The result should be easier to read and maintain. I do not intend to support backporting this to stable releases due to lack of demand and dealing with older distros.
v9 - rebase and keep max queues at 16
Quoted 11 lines
Stephen Hemminger (9):
net/tap: do not duplicate fd's
net/tap: remove unused fields
net/tap: validate and setup parameters for BPF RSS net/tap: do not build flow support if header is out of date net/tap: rewrite the RSS BPF program
net/tap: use libbpf to load new BPF program net/tap: remove no longer used files
doc: update documentation of TAP PMD
net/tap: simplify the internal structure
Thanks for reviving tap eBPF support, I am for merging this set (as early as possible).
But I have two concerns,
1. Build environment header file dependencies and external library dependency version changed. Not sure if this will impact users. What do you think at least to update release notes to notify users?
2. We need this to be tested, either by users or test teams. I will bring the issue in next release status meeting to see if we have anyone testing tap eBPF support.
Thanks,
ferruh
Re: [PATCH v9 0/9] net/tap: fix RSS (BPF) support
Quoted 7 lines · On Wed, 1 May 2024 12:18:16 +0100 Ferruh Yigit <[email protected]> wrote:
Thanks for reviving tap eBPF support, I am for merging this set (as early as possible).
But I have two concerns,
1. Build environment header file dependencies and external library dependency version changed. Not sure if this will impact users. What do you think at least to update release notes to notify users?
Added a short note in release notes.
Quoted 4 lines
2. We need this to be tested, either by users or test teams. I will bring the issue in next release status meeting to see if we have anyone testing tap eBPF support.
Agreed. I ended up doing lots of manual tests. That is how it was discovered that > 1 flow rule never worked with TAP.
There is a bigger issue here. There is no basic test suite for PMD's. I see lots of differences creeping in with statistics etc.
And there is no test suite for rte_flow. Lots of untested code paths and driver differences. Testing actual flows is hard, but basic functional tests should be possible. Like:
- try all possible flow rules and actions
- make sure that any supported flow rule accepts a valid parameter. and for those supported flow rules pass invalid data (like queue > nrx queue).
- make sure validate and create work the same.
- make sure that validate doesn't actually create state in hw/sw. should be possible to validate same rule 10,000 times without leaks blowing up.
v10 cover net/tap: fix RSS (BPF) flow support
In reply to Stephen HemmingerThe support of doing RSS for rte_flow_action was a cool idea but it has been broken for several releases of DPDK as the kernel and BPF infrastructure changed.
This series cleans up the BPF program, implements several features that were never completed in the original code and changes to use the current BPF toolchain.
The result should be easier to read and maintain. I do not intend to support backporting this to stable releases due to lack of demand and dealing with older distros.
v10 - add some cleanups to stats and name sizes
- update documentation from review
Stephen Hemminger (9):
net/tap: do not duplicate fd's
net/tap: remove unused fields
net/tap: validate and setup parameters for BPF RSS net/tap: do not build flow support if header is out of date net/tap: rewrite the RSS BPF program
net/tap: use libbpf to load new BPF program net/tap: remove no longer used files
net/tap: simplify internals
net/tap: update documentation
.gitignore | 3 - doc/guides/nics/tap.rst | 274 ++-- doc/guides/rel_notes/release_24_07.rst | 7 + drivers/net/tap/bpf/Makefile | 19 - drivers/net/tap/bpf/README | 49 + drivers/net/tap/bpf/bpf_api.h | 276 ---- drivers/net/tap/bpf/bpf_elf.h | 53 - drivers/net/tap/bpf/bpf_extract.py | 86 -- drivers/net/tap/bpf/meson.build | 107 ++ drivers/net/tap/bpf/tap_bpf_program.c | 255 ---- drivers/net/tap/bpf/tap_rss.c | 267 ++++ drivers/net/tap/meson.build | 42 +- drivers/net/tap/rte_eth_tap.c | 339 ++--- drivers/net/tap/rte_eth_tap.h | 32 +- drivers/net/tap/tap_bpf.h | 121 -- drivers/net/tap/tap_bpf_api.c | 190 --- drivers/net/tap/tap_bpf_insns.h | 1743 ------------------------ drivers/net/tap/tap_flow.c | 559 ++------ drivers/net/tap/tap_flow.h | 17 +- drivers/net/tap/tap_intr.c | 7 +- drivers/net/tap/tap_rss.h | 21 +- drivers/net/tap/tap_tcmsgs.h | 4 +- 22 files changed, 887 insertions(+), 3584 deletions(-) delete mode 100644 drivers/net/tap/bpf/Makefile create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py create mode 100644 drivers/net/tap/bpf/meson.build delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c delete mode 100644 drivers/net/tap/tap_bpf.h delete mode 100644 drivers/net/tap/tap_bpf_api.c delete mode 100644 drivers/net/tap/tap_bpf_insns.h
Signature · 1 line
2.43.0
PATCH v10 1/9 net/tap: do not duplicate fd's
The TAP device can use same file descriptor for both rx and tx queues. This allows up to 8 queues (versus 4) to be used with secondary process.
--- drivers/net/tap/rte_eth_tap.c | 197 +++++++++++++++------------------- drivers/net/tap/rte_eth_tap.h | 3 +- drivers/net/tap/tap_flow.c | 3 +- drivers/net/tap/tap_intr.c | 7 +- 4 files changed, 91 insertions(+), 119 deletions(-)
drivers/net/tap/rte_eth_tap.c +84 -113
@@ -124,8 +124,7 @@ enum ioctl_mode {/* Message header to synchronize queues via IPC */ struct ipc_queues {char port_name[RTE_DEV_NAME_MAX_LEN ]; -int rxq_count; -int txq_count; +int q_count;/* * The file descriptors are in the dedicated part * of the Unix message to be translated by the kernel.
@@ -446,7 +445,7 @@ pmd_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)uint16_t data_off =rte_pktmbuf_headroom (mbuf);int len; - len =readv (process_private->rxq_fds[rxq->queue_id], + len =readv (process_private->fds[rxq->queue_id], *rxq->iovecs,1 + (rxq->rxmode->offloads &RTE_ETH_RX_OFFLOAD_SCATTER ? rxq->nb_rx_desc :1 ));
@@ -643,7 +642,7 @@ tap_write_mbufs(struct tx_queue *txq, uint16_t num_mbufs, }/* copy the tx frame data */ - n =writev (process_private->txq_fds[txq->queue_id], iovecs, k); + n =writev (process_private->fds[txq->queue_id], iovecs, k);if (n <=0 )return -1 ;
@@ -851,7 +850,6 @@ tap_mp_req_on_rxtx(struct rte_eth_dev *dev)struct rte_mp_msg msg;struct ipc_queues *request_param = (struct ipc_queues *)msg.param;int err; -int fd_iterator =0 ;struct pmd_process_private *process_private = dev->process_private;int i;
@@ -859,16 +857,13 @@ tap_mp_req_on_rxtx(struct rte_eth_dev *dev)strlcpy (msg.name,TAP_MP_REQ_START_RXTX ,sizeof (msg.name));strlcpy (request_param->port_name, dev->data->name,sizeof (request_param->port_name)); msg.len_param =sizeof (*request_param); -for (i =0 ; i < dev->data->nb_tx_queues; i++) { - msg.fds[fd_iterator++] = process_private->txq_fds[i]; - msg.num_fds++; - request_param->txq_count++; - } -for (i =0 ; i < dev->data->nb_rx_queues; i++) { - msg.fds[fd_iterator++] = process_private->rxq_fds[i]; - msg.num_fds++; - request_param->rxq_count++; - } + +/* rx and tx share file descriptors and nb_tx_queues == nb_rx_queues */ +for (i =0 ; i < dev->data->nb_rx_queues; i++) + msg.fds[i] = process_private->fds[i]; + + request_param->q_count = dev->data->nb_rx_queues; + msg.num_fds = dev->data->nb_rx_queues; err =rte_mp_sendmsg (&msg);if (err <0 ) {
@@ -910,8 +905,6 @@ tap_mp_req_start_rxtx(const struct rte_mp_msg *request, __rte_unused const voidstruct rte_eth_dev *dev;const struct ipc_queues *request_param = (const struct ipc_queues *)request->param; -int fd_iterator; -int queue;struct pmd_process_private *process_private; dev =rte_eth_dev_get_by_name (request_param->port_name);
@@ -920,14 +913,13 @@ tap_mp_req_start_rxtx(const struct rte_mp_msg *request, __rte_unused const void request_param->port_name);return -1 ; } + process_private = dev->process_private; - fd_iterator =0 ; -TAP_LOG (DEBUG ,"tap_attach rx_q:%d tx_q:%d\n" , request_param->rxq_count, - request_param->txq_count); -for (queue =0 ; queue < request_param->txq_count; queue++) - process_private->txq_fds[queue] = request->fds[fd_iterator++]; -for (queue =0 ; queue < request_param->rxq_count; queue++) - process_private->rxq_fds[queue] = request->fds[fd_iterator++]; +TAP_LOG (DEBUG ,"tap_attach q:%d\n" , request_param->q_count); + +for (int q =0 ; q < request_param->q_count; q++) + process_private->fds[q] = request->fds[q]; +return 0 ; }
@@ -1121,7 +1113,6 @@ tap_dev_close(struct rte_eth_dev *dev)int i;struct pmd_internals *internals = dev->data->dev_private;struct pmd_process_private *process_private = dev->process_private; -struct rx_queue *rxq;if (rte_eal_process_type () !=RTE_PROC_PRIMARY ) {rte_free (dev->process_private);
@@ -1141,19 +1132,18 @@ tap_dev_close(struct rte_eth_dev *dev) }for (i =0 ; i <RTE_PMD_TAP_MAX_QUEUES ; i++) { -if (process_private->rxq_fds[i] !=-1 ) { - rxq = &internals->rxq[i]; -close (process_private->rxq_fds[i]); - process_private->rxq_fds[i] =-1 ; -tap_rxq_pool_free (rxq->pool); -rte_free (rxq->iovecs); - rxq->pool =NULL ; - rxq->iovecs =NULL ; - } -if (process_private->txq_fds[i] !=-1 ) { -close (process_private->txq_fds[i]); - process_private->txq_fds[i] =-1 ; - } +struct rx_queue *rxq = &internals->rxq[i]; + +if (process_private->fds[i] ==-1 ) +continue ; + +close (process_private->fds[i]); + process_private->fds[i] =-1 ; + +tap_rxq_pool_free (rxq->pool); +rte_free (rxq->iovecs); + rxq->pool =NULL ; + rxq->iovecs =NULL ; }if (internals->remote_if_index) {
@@ -1198,6 +1188,15 @@ tap_dev_close(struct rte_eth_dev *dev)return 0 ; } +static void +tap_queue_close (struct pmd_process_private *process_private,uint16_t qid) +{ +if (process_private->fds[qid] !=-1 ) { +close (process_private->fds[qid]); + process_private->fds[qid] =-1 ; + } +} +static void tap_rx_queue_release (struct rte_eth_dev *dev,uint16_t qid) {
@@ -1206,15 +1205,16 @@ tap_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)if (!rxq)return ; + process_private = rte_eth_devices[rxq->in_port].process_private; -if (process_private->rxq_fds[rxq->queue_id] !=-1 ) { -close (process_private->rxq_fds[rxq->queue_id]); - process_private->rxq_fds[rxq->queue_id] =-1 ; -tap_rxq_pool_free (rxq->pool); -rte_free (rxq->iovecs); - rxq->pool =NULL ; - rxq->iovecs =NULL ; - } + +tap_rxq_pool_free (rxq->pool); +rte_free (rxq->iovecs); + rxq->pool =NULL ; + rxq->iovecs =NULL ; + +if (dev->data->tx_queues[qid] ==NULL ) +tap_queue_close (process_private, qid); } static void
@@ -1225,12 +1225,10 @@ tap_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)if (!txq)return ; - process_private = rte_eth_devices[txq->out_port].process_private; -if (process_private->txq_fds[txq->queue_id] !=-1 ) { -close (process_private->txq_fds[txq->queue_id]); - process_private->txq_fds[txq->queue_id] =-1 ; - } + process_private = rte_eth_devices[txq->out_port].process_private; +if (dev->data->rx_queues[qid] ==NULL ) +tap_queue_close (process_private, qid); } static int
@@ -1482,52 +1480,34 @@ tap_setup_queue(struct rte_eth_dev *dev,uint16_t qid, int is_rx) { - int ret; -int *fd; -int *other_fd; -const char *dir; + int fd, ret;struct pmd_internals *pmd = dev->data->dev_private;struct pmd_process_private *process_private = dev->process_private;struct rx_queue *rx = &internals->rxq[qid];struct tx_queue *tx = &internals->txq[qid]; -struct rte_gso_ctx *gso_ctx; +struct rte_gso_ctx *gso_ctx =NULL ; +const char *dir = is_rx ?"rx" :"tx" ; -if (is_rx) { - fd = &process_private->rxq_fds[qid]; - other_fd = &process_private->txq_fds[qid]; - dir ="rx" ; - gso_ctx =NULL ; - }else { - fd = &process_private->txq_fds[qid]; - other_fd = &process_private->rxq_fds[qid]; - dir ="tx" ; +if (is_rx) gso_ctx = &tx->gso_ctx; - } -if (*fd !=-1 ) { + + fd = process_private->fds[qid]; +if (fd !=-1 ) {/* fd for this queue already exists */ TAP_LOG (DEBUG ,"%s: fd %d for %s queue qid %d exists" , - pmd->name, *fd, dir, qid); + pmd->name, fd, dir, qid); gso_ctx =NULL ; - }else if (*other_fd !=-1 ) { -/* Only other_fd exists. dup it */ - *fd =dup (*other_fd); -if (*fd <0 ) { - *fd =-1 ; -TAP_LOG (ERR ,"%s: dup() failed." , pmd->name); -return -1 ; - } -TAP_LOG (DEBUG ,"%s: dup fd %d for %s queue qid %d (%d)" , - pmd->name, *other_fd, dir, qid, *fd); }else { -/* Both RX and TX fds do not exist (equal -1). Create fd */ - *fd =tun_alloc (pmd,0 ,0 ); -if (*fd <0 ) { - *fd =-1 ;/* restore original value */ + fd =tun_alloc (pmd,0 ,0 ); +if (fd <0 ) {TAP_LOG (ERR ,"%s: tun_alloc() failed." , pmd->name);return -1 ; } +TAP_LOG (DEBUG ,"%s: add %s queue for qid %d fd %d" , - pmd->name, dir, qid, *fd); + pmd->name, dir, qid, fd); + + process_private->fds[qid] = fd; } tx->mtu = &dev->data->mtu;
@@ -1540,7 +1520,7 @@ tap_setup_queue(struct rte_eth_dev *dev, tx->type = pmd->type; -return *fd; +return fd; } static int
@@ -1620,7 +1600,7 @@ tap_rx_queue_setup(struct rte_eth_dev *dev,TAP_LOG (DEBUG ," RX TUNTAP device name %s, qid %d on fd %d" , internals->name, rx_queue_id, - process_private->rxq_fds[rx_queue_id]); + process_private->fds[rx_queue_id]);return 0 ;
@@ -1664,7 +1644,7 @@ tap_tx_queue_setup(struct rte_eth_dev *dev,TAP_LOG (DEBUG ," TX TUNTAP device name %s, qid %d on fd %d csum %s" , internals->name, tx_queue_id, - process_private->txq_fds[tx_queue_id], + process_private->fds[tx_queue_id], txq->csum ?"on" :"off" );return 0 ;
@@ -2001,10 +1981,9 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, dev->intr_handle = pmd->intr_handle;/* Presetup the fds to -1 as being not valid */ -for (i =0 ; i <RTE_PMD_TAP_MAX_QUEUES ; i++) { - process_private->rxq_fds[i] =-1 ; - process_private->txq_fds[i] =-1 ; - } +for (i =0 ; i <RTE_PMD_TAP_MAX_QUEUES ; i++) + process_private->fds[i] =-1 ; +if (pmd->type ==ETH_TUNTAP_TYPE_TAP ) {if (rte_is_zero_ether_addr (mac_addr))
@@ -2332,7 +2311,6 @@ tap_mp_attach_queues(const char *port_name, struct rte_eth_dev *dev)struct ipc_queues *request_param = (struct ipc_queues *)request.param;struct ipc_queues *reply_param;struct pmd_process_private *process_private = dev->process_private; -int queue, fd_iterator;/* Prepare the request */ memset (&request,0 ,sizeof (request));
@@ -2352,18 +2330,17 @@ tap_mp_attach_queues(const char *port_name, struct rte_eth_dev *dev)TAP_LOG (DEBUG ,"Received IPC reply for %s" , reply_param->port_name);/* Attach the queues from received file descriptors */ -if (reply_param->rxq_count + reply_param->txq_count != reply->num_fds) { +if (reply_param->q_count != reply->num_fds) {TAP_LOG (ERR ,"Unexpected number of fds received" );return -1 ; } - dev->data->nb_rx_queues = reply_param->rxq_count; - dev->data->nb_tx_queues = reply_param->txq_count; - fd_iterator =0 ; -for (queue =0 ; queue < reply_param->rxq_count; queue++) - process_private->rxq_fds[queue] = reply->fds[fd_iterator++]; -for (queue =0 ; queue < reply_param->txq_count; queue++) - process_private->txq_fds[queue] = reply->fds[fd_iterator++]; + dev->data->nb_rx_queues = reply_param->q_count; + dev->data->nb_tx_queues = reply_param->q_count; + +for (int q =0 ; q < reply_param->q_count; q++) + process_private->fds[q] = reply->fds[q]; +free (reply);return 0 ; }
@@ -2393,25 +2370,19 @@ tap_mp_sync_queues(const struct rte_mp_msg *request, const void *peer)/* Fill file descriptors for all queues */ reply.num_fds =0 ; - reply_param->rxq_count =0 ; -if (dev->data->nb_rx_queues + dev->data->nb_tx_queues > -RTE_MP_MAX_FD_NUM ){ -TAP_LOG (ERR ,"Number of rx/tx queues exceeds max number of fds" ); + reply_param->q_count =0 ; + +RTE_ASSERT (dev->data->nb_rx_queues == dev->data->nb_tx_queues); +if (dev->data->nb_rx_queues >RTE_MP_MAX_FD_NUM ) { +TAP_LOG (ERR ,"Number of rx/tx queues %u exceeds max number of fds %u" , + dev->data->nb_rx_queues,RTE_MP_MAX_FD_NUM );return -1 ; }for (queue =0 ; queue < dev->data->nb_rx_queues; queue++) { - reply.fds[reply.num_fds++] = process_private->rxq_fds[queue]; - reply_param->rxq_count++; - } -RTE_ASSERT (reply_param->rxq_count == dev->data->nb_rx_queues); - - reply_param->txq_count =0 ; -for (queue =0 ; queue < dev->data->nb_tx_queues; queue++) { - reply.fds[reply.num_fds++] = process_private->txq_fds[queue]; - reply_param->txq_count++; + reply.fds[reply.num_fds++] = process_private->fds[queue]; + reply_param->q_count++; } -RTE_ASSERT (reply_param->txq_count == dev->data->nb_tx_queues);/* Send reply */ strlcpy (reply.name, request->name,sizeof (reply.name));
drivers/net/tap/rte_eth_tap.h +1 -2
@@ -96,8 +96,7 @@ struct pmd_internals { };struct pmd_process_private { -int rxq_fds[RTE_PMD_TAP_MAX_QUEUES ]; -int txq_fds[RTE_PMD_TAP_MAX_QUEUES ]; +int fds[RTE_PMD_TAP_MAX_QUEUES ]; };/* tap_intr.c */
drivers/net/tap/tap_flow.c +2 -1
@@ -1595,8 +1595,9 @@ tap_flow_isolate(struct rte_eth_dev *dev,* If netdevice is there, setup appropriate flow rules immediately. * Otherwise it will be set when bringing up the netdevice (tun_alloc). */ -if (!process_private->rxq_fds[0 ]) +if (process_private->fds[0 ] ==-1 )return 0 ; +if (set) {struct rte_flow *remote_flow;
drivers/net/tap/tap_intr.c +4 -3
@@ -68,9 +68,11 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev) }for (i =0 ; i < n; i++) {struct rx_queue *rxq = pmd->dev->data->rx_queues[i]; +int fd = process_private->fds[i];/* Skip queues that cannot request interrupts. */ -if (!rxq || process_private->rxq_fds[i] ==-1 ) { +if (!rxq || fd ==-1 ) { +/* Use invalid intr_vec[] index to disable entry. */ /* Use invalid intr_vec[] index to disable entry. */ if (rte_intr_vec_list_index_set (intr_handle, i,RTE_INTR_VEC_RXTX_OFFSET +RTE_MAX_RXTX_INTR_VEC_ID ))
@@ -80,8 +82,7 @@ tap_rx_intr_vec_install(struct rte_eth_dev *dev)if (rte_intr_vec_list_index_set (intr_handle, i,RTE_INTR_VEC_RXTX_OFFSET + count))return -rte_errno; -if (rte_intr_efds_index_set (intr_handle, count, - process_private->rxq_fds[i])) +if (rte_intr_efds_index_set (intr_handle, count, fd))return -rte_errno; count++; }
Signature · 1 line
2.43.0
PATCH v10 2/9 net/tap: remove unused fields
In reply to Stephen HemmingerThe driver doesn't support these other hash types, and there is no reason to implement these in future. The rss_flows list was set but never used.
--- drivers/net/tap/rte_eth_tap.h | 4 +--- drivers/net/tap/tap_flow.c | 1 - drivers/net/tap/tap_rss.h | 6 ------ 3 files changed, 1 insertion(+), 10 deletions(-)
drivers/net/tap/rte_eth_tap.h +1 -3
@@ -77,14 +77,12 @@ struct pmd_internals {int ioctl_sock;/* socket for ioctl calls */ int nlsk_fd;/* Netlink socket fd */ int flow_isolate;/* 1 if flow isolation is enabled */ -int flower_support;/* 1 if kernel supports, else 0 */ -int flower_vlan_support;/* 1 if kernel supports, else 0 */ int rss_enabled;/* 1 if RSS is enabled, else 0 */ int persist;/* 1 if keep link up, else 0 */ /* implicit rules set when RSS is enabled */ int map_fd;/* BPF RSS map fd */ int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */ - LIST_HEAD(tap_rss_flows, rte_flow) rss_flows; + LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */ LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
drivers/net/tap/tap_flow.c +0 -1
@@ -1958,7 +1958,6 @@ static int rss_enable(struct pmd_internals *pmd, errno, strerror(errno));return err; } -LIST_INSERT_HEAD (&pmd->rss_flows, rss_flow, next); } pmd->rss_enabled =1 ;
drivers/net/tap/tap_rss.h +0 -6
@@ -21,12 +21,6 @@ enum hash_field {HASH_FIELD_IPV4_L3_L4 ,/* IPv4 src/dst addr + L4 src/dst ports */ HASH_FIELD_IPV6_L3 ,/* IPv6 src/dst addr */ HASH_FIELD_IPV6_L3_L4, /* IPv6 src/dst addr + L4 src/dst ports */ -HASH_FIELD_L2_SRC ,/* Ethernet src addr */ -HASH_FIELD_L2_DST ,/* Ethernet dst addr */ -HASH_FIELD_L3_SRC ,/* L3 src addr */ -HASH_FIELD_L3_DST ,/* L3 dst addr */ -HASH_FIELD_L4_SRC ,/* TCP/UDP src ports */ - HASH_FIELD_L4_DST, /* TCP/UDP dst ports */ }; struct rss_key {
Signature · 1 line
2.43.0
PATCH v10 3/9 net/tap: validate and setup parameters for BPF RSS
In reply to Stephen HemmingerThe flow RSS support via BPF was not using the key, or hash type parameters. Which is good because they were never properly setup.
Fix the setup and validate the flow parameters, the BPF side gets fixed later.
--- drivers/net/tap/tap_flow.c | 65 +++++++++++++++++++++++++++++++++++--- drivers/net/tap/tap_rss.h | 5 ++- 2 files changed, 62 insertions(+), 8 deletions(-)
drivers/net/tap/tap_flow.c +60 -5
@@ -11,9 +11,11 @@#include <rte_byteorder.h> #include <rte_jhash.h> +#include <rte_thash.h> #include <rte_random.h> #include <rte_malloc.h> #include <rte_eth_tap.h> +#include <tap_flow.h> #include <tap_autoconf.h> #include <tap_tcmsgs.h>
@@ -2061,6 +2063,21 @@ static int bpf_rss_key(enum bpf_rss_key_e cmd, __u32 *key_idx)return err; } + +/* Default RSS hash key also used by mlx devices */ +static const uint8_t rss_hash_default_key[] = { +0x2c ,0xc6 ,0x81 ,0xd1 , +0x5b ,0xdb ,0xf4 ,0xf7 , +0xfc ,0xa2 ,0x83 ,0x19 , +0xdb ,0x1a ,0x3e ,0x94 , +0x6b ,0x9e ,0x38 ,0xd9 , +0x2c ,0x9c ,0x03 ,0xd1 , +0xad ,0x99 ,0x44 ,0xa7 , +0xd9 ,0x56 ,0x3d ,0x59 , +0x06 ,0x3c ,0x25 ,0xf3 , +0xfc ,0x1f ,0xdc ,0x2a , +}; +/** * Add RSS hash calculations and queue selection *
@@ -2079,11 +2096,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd,const struct rte_flow_action_rss *rss, struct rte_flow_error *error) { -/* 4096 is the maximum number of instructions for a BPF program */ + struct rss_key rss_entry = { }; +const uint8_t *key_in; +uint32_t hash_type =0 ;unsigned int i;int err; -struct rss_key rss_entry = { .hash_fields =0 , - .key_size =0 };/* Check supported RSS features */ if (rss->func !=RTE_ETH_HASH_FUNCTION_DEFAULT )
@@ -2095,6 +2112,41 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, (error,ENOTSUP ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL ,"a nonzero RSS encapsulation level is not supported" ); +if (rss->queue_num ==0 || rss->queue_num >=TAP_MAX_QUEUES ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL , +"invalid number of queues" ); + +/* allow RSS key_len 0 in case of NULL (default) RSS key. */ +if (rss->key_len ==0 ) { +if (rss->key !=NULL ) +return rte_flow_error_set (error,ENOTSUP , +RTE_FLOW_ERROR_TYPE_ACTION_CONF , + &rss->key_len,"RSS hash key length 0" ); + key_in = rss_hash_default_key; + }else { +if (rss->key_len !=TAP_RSS_HASH_KEY_SIZE ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"RSS hash invalid key length" ); +if (rss->key ==NULL ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"RSS hash key is NULL" ); + key_in = rss->key; + } + +if (rss->types &TAP_RSS_HF_MASK ) +return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"RSS hash type not supported" ); + +if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV4_UDP |RTE_ETH_RSS_NONFRAG_IPV4_TCP )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV4_L3_L4 ); +else if (rss->types & (RTE_ETH_RSS_IPV4 |RTE_ETH_RSS_FRAG_IPV4 )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV4_L3 ); + +if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV6_UDP |RTE_ETH_RSS_NONFRAG_IPV6_TCP )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV6_L3_L4 ); +else if (rss->types & (RTE_ETH_RSS_IPV6 |RTE_ETH_RSS_FRAG_IPV6 |RTE_ETH_RSS_IPV6_EX )) + hash_type |=RTE_BIT32 (HASH_FIELD_IPV6_L3 ); +/* Get a new map key for a new RSS rule */ err =bpf_rss_key (KEY_CMD_GET , &flow->key_idx);if (err <0 ) {
@@ -2109,8 +2161,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, rss_entry.nb_queues = rss->queue_num;for (i =0 ; i < rss->queue_num; i++) rss_entry.queues[i] = rss->queue[i]; - rss_entry.hash_fields = - (1 <<HASH_FIELD_IPV4_L3_L4 ) | (1 <<HASH_FIELD_IPV6_L3_L4 ); + + rss_entry.hash_fields = hash_type; +rte_convert_rss_key ((const uint32_t *)key_in, (uint32_t *)rss_entry.key, +TAP_RSS_HASH_KEY_SIZE ); +/* Add this RSS entry to map */ err = tap_flow_bpf_update_rss_elem(pmd->map_fd,
drivers/net/tap/tap_rss.h +2 -3
@@ -24,11 +24,10 @@ enum hash_field { };struct rss_key { -__u8 key[128 ];__u32 hash_fields; -__u32 key_size; -__u32 queues[TAP_MAX_QUEUES ]; +__u8 key[TAP_RSS_HASH_KEY_SIZE ];__u32 nb_queues; +__u32 queues[TAP_MAX_QUEUES ]; } __attribute__((packed));#endif /* _TAP_RSS_H_ */
Signature · 1 line
2.43.0
PATCH v10 4/9 net/tap: do not build flow support if header is out of date
In reply to Stephen HemmingerThe proper place for finding bpf structures and functions is in linux/bpf.h. The original version was trying to workaround the case where the build environment was running on old pre BPF version of Glibc, but the target environment had BPF.
Having own private (and divergent) version headers leads to future problems when BPF definitions evolve.
If the build infrastructure is so old that TC flower is not supported, then the TAP device will build without any flow support.
--- drivers/net/tap/bpf/bpf_extract.py | 1 - drivers/net/tap/meson.build | 17 ++-- drivers/net/tap/rte_eth_tap.c | 38 +++++++-- drivers/net/tap/rte_eth_tap.h | 7 +- drivers/net/tap/tap_bpf.h | 121 ----------------------------- drivers/net/tap/tap_bpf_api.c | 20 +++-- drivers/net/tap/tap_bpf_insns.h | 2 - drivers/net/tap/tap_flow.c | 90 --------------------- 8 files changed, 60 insertions(+), 236 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf.h
drivers/net/tap/bpf/bpf_extract.py +0 -1
@@ -65,7 +65,6 @@ def write_header(out, source): print(f' * Auto-generated from {source}', file=out) print(" * This not the original source file. Do NOT edit it.", file=out) print(" */\n", file=out) - print("#include <tap_bpf.h>", file=out) def main():
drivers/net/tap/meson.build +9 -8
@@ -7,13 +7,19 @@ if not is_linux endif sources = files( 'rte_eth_tap.c', - 'tap_bpf_api.c', - 'tap_flow.c', 'tap_intr.c', 'tap_netlink.c', - 'tap_tcmsgs.c', ) +if cc.has_header_symbol('linux/pkt_cls.h', 'TCA_FLOWER_ACT') + cflags += '-DHAVE_TCA_FLOWER' + sources += files( + 'tap_bpf_api.c', + 'tap_flow.c', + 'tap_tcmsgs.c', + ) +endif + deps = ['bus_vdev', 'gso', 'hash'] cflags += '-DTAP_MAX_QUEUES=16'
@@ -23,12 +29,7 @@ cflags += '-DTAP_MAX_QUEUES=16' # "enum/define", "symbol to search" ] # args = [ - [ 'HAVE_TC_FLOWER', 'linux/pkt_cls.h', 'TCA_FLOWER_UNSPEC' ], - [ 'HAVE_TC_VLAN_ID', 'linux/pkt_cls.h', 'TCA_FLOWER_KEY_VLAN_PRIO' ], - [ 'HAVE_TC_BPF', 'linux/pkt_cls.h', 'TCA_BPF_UNSPEC' ], - [ 'HAVE_TC_BPF_FD', 'linux/pkt_cls.h', 'TCA_BPF_FD' ], [ 'HAVE_TC_ACT_BPF', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_UNSPEC' ], - [ 'HAVE_TC_ACT_BPF_FD', 'linux/tc_act/tc_bpf.h', 'TCA_ACT_BPF_FD' ], ] config = configuration_data() foreach arg:args
drivers/net/tap/rte_eth_tap.c +32 -6
@@ -1124,12 +1124,15 @@ tap_dev_close(struct rte_eth_dev *dev)if (!internals->persist)tap_link_set_down (dev); + +#ifdef HAVE_TCA_FLOWER if (internals->nlsk_fd !=-1 ) {tap_flow_flush (dev,NULL );tap_flow_implicit_flush (internals,NULL );tap_nl_final (internals->nlsk_fd); internals->nlsk_fd =-1 ; } +#endif for (i =0 ; i <RTE_PMD_TAP_MAX_QUEUES ; i++) {struct rx_queue *rxq = &internals->rxq[i];
@@ -1265,6 +1268,7 @@ tap_promisc_enable(struct rte_eth_dev *dev)if (ret !=0 )return ret; +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) { dev->data->promiscuous =1 ; ret =tap_flow_implicit_create (pmd,TAP_REMOTE_PROMISC );
@@ -1278,7 +1282,7 @@ tap_promisc_enable(struct rte_eth_dev *dev) return ret; } } - +#endif return 0 ; }
@@ -1293,6 +1297,7 @@ tap_promisc_disable(struct rte_eth_dev *dev)if (ret !=0 )return ret; +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) { dev->data->promiscuous =0 ; ret =tap_flow_implicit_destroy (pmd,TAP_REMOTE_PROMISC );
@@ -1306,6 +1311,7 @@ tap_promisc_disable(struct rte_eth_dev *dev) return ret; } } +#endif return 0 ; }
@@ -1321,6 +1327,7 @@ tap_allmulti_enable(struct rte_eth_dev *dev)if (ret !=0 )return ret; +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) { dev->data->all_multicast =1 ; ret =tap_flow_implicit_create (pmd,TAP_REMOTE_ALLMULTI );
@@ -1334,6 +1341,7 @@ tap_allmulti_enable(struct rte_eth_dev *dev) return ret; } } +#endif return 0 ; }
@@ -1349,6 +1357,7 @@ tap_allmulti_disable(struct rte_eth_dev *dev)if (ret !=0 )return ret; +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) { dev->data->all_multicast =0 ; ret =tap_flow_implicit_destroy (pmd,TAP_REMOTE_ALLMULTI );
@@ -1362,6 +1371,7 @@ tap_allmulti_disable(struct rte_eth_dev *dev) return ret; } } +#endif return 0 ; }
@@ -1407,6 +1417,8 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)if (ret <0 )return ret;rte_memcpy (&pmd->eth_addr, mac_addr,RTE_ETHER_ADDR_LEN ); + +#ifdef HAVE_TCA_FLOWER if (pmd->remote_if_index && !pmd->flow_isolate) {/* Replace MAC redirection rule after a MAC change */ ret =tap_flow_implicit_destroy (pmd,TAP_REMOTE_LOCAL_MAC );
@@ -1424,6 +1436,7 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr) return ret; } } +#endif return 0 ; }
@@ -1901,7 +1914,9 @@ static const struct eth_dev_ops ops = { .stats_reset = tap_stats_reset, .dev_supported_ptypes_get = tap_dev_supported_ptypes_get, .rss_hash_update = tap_rss_hash_update, +#ifdef HAVE_TCA_FLOWER .flow_ops_get = tap_dev_flow_ops_get, +#endif }; static int
@@ -1941,7 +1956,9 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,strlcpy (pmd->name, tap_name,sizeof (pmd->name)); pmd->type = type; pmd->ka_fd =-1 ; +#ifdef HAVE_TCA_FLOWER pmd->nlsk_fd =-1 ; +#endif pmd->gso_ctx_mp =NULL ; pmd->ioctl_sock =socket (AF_INET ,SOCK_DGRAM ,0 );
@@ -2021,6 +2038,14 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,/* Make network device persist after application exit */ pmd->persist = persist; + pmd->if_index =if_nametoindex (pmd->name); +if (!pmd->if_index) { +TAP_LOG (ERR ,"%s: failed to get if_index." , pmd->name); + goto disable_rte_flow; + } + + +#ifdef HAVE_TCA_FLOWER /* * Set up everything related to rte_flow: * - netlink socket
@@ -2035,11 +2060,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, pmd->name); goto disable_rte_flow; } - pmd->if_index =if_nametoindex (pmd->name); -if (!pmd->if_index) { -TAP_LOG (ERR ,"%s: failed to get if_index." , pmd->name); - goto disable_rte_flow; - }if (qdisc_create_multiq (pmd->nlsk_fd, pmd->if_index) <0 ) {TAP_LOG (ERR ,"%s: failed to create multiq qdisc." , pmd->name);
@@ -2050,6 +2070,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, pmd->name); goto disable_rte_flow; } +LIST_INIT (&pmd->flows);if (strlen (remote_iface)) {
@@ -2102,6 +2123,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, goto error_remote; } } +#endif rte_eth_dev_probing_finish (dev);return 0 ;
@@ -2116,14 +2138,18 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name,rte_eth_dev_probing_finish (dev);return 0 ; +#ifdef HAVE_TCA_FLOWER error_remote:TAP_LOG (ERR ," Can't set up remote feature: %s(%d)" ,strerror (errno), errno);tap_flow_implicit_flush (pmd,NULL ); +#endif error_exit: +#ifdef HAVE_TCA_FLOWER if (pmd->nlsk_fd !=-1 )close (pmd->nlsk_fd); +#endif if (pmd->ka_fd !=-1 )close (pmd->ka_fd);if (pmd->ioctl_sock !=-1 )
drivers/net/tap/rte_eth_tap.h +6 -1
@@ -16,6 +16,7 @@#include <ethdev_driver.h> #include <rte_ether.h> #include <rte_gso.h> +#include "tap_log.h" #ifdef IFF_MULTI_QUEUE
@@ -70,15 +71,17 @@ struct pmd_internals {char remote_iface[RTE_ETH_NAME_MAX_LEN ];/* Remote netdevice name */ char name[RTE_ETH_NAME_MAX_LEN ];/* Internal Tap device name */ int type;/* Type field - TUN|TAP */ +int persist;/* 1 if keep link up, else 0 */ struct rte_ether_addr eth_addr;/* Mac address of the device port */ struct ifreq remote_initial_flags;/* Remote netdevice flags on init */ int remote_if_index;/* remote netdevice IF_INDEX */ int if_index;/* IF_INDEX for the port */ int ioctl_sock;/* socket for ioctl calls */ + +#ifdef HAVE_TCA_FLOWER int nlsk_fd;/* Netlink socket fd */ int flow_isolate;/* 1 if flow isolation is enabled */ int rss_enabled;/* 1 if RSS is enabled, else 0 */ -int persist;/* 1 if keep link up, else 0 */ /* implicit rules set when RSS is enabled */ int map_fd;/* BPF RSS map fd */ int bpf_fd[RTE_PMD_TAP_MAX_QUEUES ];/* List of bpf fds per queue */
@@ -86,6 +89,8 @@ struct pmd_internals { LIST_HEAD(tap_flows, rte_flow) flows; /* rte_flow rules *//* implicit rte_flow rules set when a remote device is active */ LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows; +#endif +struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES ];/* List of RX queues */ struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES ];/* List of TX queues */ struct rte_intr_handle *intr_handle;/* LSC interrupt handle. */
drivers/net/tap/tap_bpf.h deleted +0 -121
121 lines not on this page · raw message
drivers/net/tap/tap_bpf_api.c +13 -7
@@ -2,19 +2,19 @@* Copyright 2017 Mellanox Technologies, Ltd */ -#include <errno.h> -#include <string.h> #include <unistd.h> -#include <sys/queue.h> +#include <syscall.h> +#include <linux/bpf.h> -#include <rte_malloc.h> -#include <rte_eth_tap.h> #include <tap_flow.h> #include <tap_autoconf.h> -#include <tap_tcmsgs.h> -#include <tap_bpf.h> +#include <tap_bpf_insns.h> + +static int bpf_load (enum bpf_prog_type type,const struct bpf_insn *insns, +size_t insns_cnt,const char *license); +/** * Load BPF program (section cls_q) into the kernel and return a bpf fd *
@@ -89,7 +89,13 @@ static inline __u64 ptr_to_u64(const void *ptr)static inline int sys_bpf (enum bpf_cmd cmd,union bpf_attr *attr,unsigned int size) { +#ifdef __NR_bpfreturn syscall (__NR_bpf, cmd, attr, size); +#else +TAP_LOG (ERR ,"No bpf syscall, kernel headers too old?\n" ); + errno =ENOSYS ; +return -1 ; +#endif }/**
drivers/net/tap/tap_bpf_insns.h +0 -2
@@ -3,8 +3,6 @@* This not the original source file. Do NOT edit it. */ -#include <tap_bpf.h> -static struct bpf_insn cls_q_insns[] = { {0x61 ,2 ,1 ,52 ,0x00000000 }, {0x18 ,3 ,0 ,0 ,0xdeadbeef },
drivers/net/tap/tap_flow.c +0 -90
96 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v10 5/9 net/tap: rewrite the RSS BPF program
In reply to Stephen HemmingerRewrite of the BPF program used to do queue based RSS.
Important changes:
- uses newer BPF map format BTF
- accepts key as parameter rather than constant default
- can do L3 or L4 hashing
- supports IPv4 options
- supports IPv6 extension headers
- restructured for readability
The usage of BPF is different as well:
- the incoming configuration is looked up based on class parameters rather than patching the BPF code.
- the resulting queue is placed in skb by using skb mark than requiring a second pass through classifier step.
Note: This version only works with later patch to enable it on the DPDK driver side. It is submitted as an incremental patch to allow for easier review. Bisection still works because the old instruction are still present for now.
--- .gitignore | 3 - drivers/net/tap/bpf/Makefile | 19 -- drivers/net/tap/bpf/README | 49 +++++ drivers/net/tap/bpf/bpf_api.h | 276 -------------------------- drivers/net/tap/bpf/bpf_elf.h | 53 ----- drivers/net/tap/bpf/bpf_extract.py | 85 -------- drivers/net/tap/bpf/meson.build | 81 ++++++++ drivers/net/tap/bpf/tap_bpf_program.c | 255 ------------------------ drivers/net/tap/bpf/tap_rss.c | 264 ++++++++++++++++++++++++ 9 files changed, 394 insertions(+), 691 deletions(-) delete mode 100644 drivers/net/tap/bpf/Makefile create mode 100644 drivers/net/tap/bpf/README delete mode 100644 drivers/net/tap/bpf/bpf_api.h delete mode 100644 drivers/net/tap/bpf/bpf_elf.h delete mode 100644 drivers/net/tap/bpf/bpf_extract.py create mode 100644 drivers/net/tap/bpf/meson.build delete mode 100644 drivers/net/tap/bpf/tap_bpf_program.c create mode 100644 drivers/net/tap/bpf/tap_rss.c
.gitignore +0 -3
@@ -36,9 +36,6 @@ TAGS # ignore python bytecode files *.pyc -# ignore BPF programs -drivers/net/tap/bpf/tap_bpf_program.o - # DTS results dts/output
drivers/net/tap/bpf/Makefile deleted +0 -19
@@ -1,19 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# This file is not built as part of normal DPDK build. -# It is used to generate the eBPF code for TAP RSS. - -CLANG=clang -CLANG_OPTS=-O2 -TARGET=../tap_bpf_insns.h - -all: $(TARGET) - -clean: - rm tap_bpf_program.o $(TARGET) - -tap_bpf_program.o: tap_bpf_program.c - $(CLANG) $(CLANG_OPTS) -emit-llvm -c $< -o - | \ - llc -march=bpf -filetype=obj -o $@ - -$(TARGET): tap_bpf_program.o - python3 bpf_extract.py -stap_bpf_program.c -o $@ $<
drivers/net/tap/bpf/README new file +49 -0
49 lines not on this page · raw message
drivers/net/tap/bpf/bpf_api.h deleted +0 -276
276 lines not on this page · raw message
drivers/net/tap/bpf/bpf_elf.h deleted +0 -53
53 lines not on this page · raw message
drivers/net/tap/bpf/bpf_extract.py deleted +0 -85
85 lines not on this page · raw message
drivers/net/tap/bpf/meson.build new file +81 -0
81 lines not on this page · raw message
drivers/net/tap/bpf/tap_bpf_program.c deleted +0 -255
255 lines not on this page · raw message
drivers/net/tap/bpf/tap_rss.c new file +264 -0
264 lines not on this page · raw message
Signature · 1 line
2.43.0