In order to allow use of BPF in the mirror code in ethdev. Need to switch so that ethdev library depends on BPF library.
Since meson doesn't allow co-dependency, move the BPF ethdev callback portion into the ethdev lib. And cleanup usage of VLA in that code. Signed-off-by: Stephen Hemminger <step...@networkplumber.org> --- app/test/meson.build | 6 ++-- lib/bpf/meson.build | 9 ++---- lib/{bpf/bpf_pkt.c => ethdev/ethdev_bpf.c} | 35 ++++++++++++---------- lib/ethdev/meson.build | 6 ++++ lib/{bpf => ethdev}/rte_bpf_ethdev.h | 0 lib/meson.build | 4 +-- 6 files changed, 33 insertions(+), 27 deletions(-) rename lib/{bpf/bpf_pkt.c => ethdev/ethdev_bpf.c} (95%) rename lib/{bpf => ethdev}/rte_bpf_ethdev.h (100%) diff --git a/app/test/meson.build b/app/test/meson.build index 7d38f51918..ae947c4cbd 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -51,7 +51,7 @@ source_file_deps = { 'test_compressdev.c': ['compressdev'], 'test_cpuflags.c': [], 'test_crc.c': ['net'], - 'test_cryptodev.c': test_cryptodev_deps, + 'test_cryptodev.c': ['ethdev'] + test_cryptodev_deps, 'test_cryptodev_asym.c': ['bus_vdev'] + test_cryptodev_deps, 'test_cryptodev_blockcipher.c': test_cryptodev_deps, 'test_cryptodev_crosscheck.c': test_cryptodev_deps, @@ -60,7 +60,7 @@ source_file_deps = { 'test_cryptodev_security_tls_record.c': ['cryptodev', 'security'], 'test_cycles.c': [], 'test_debug.c': [], - 'test_devargs.c': ['kvargs'], + 'test_devargs.c': ['ethdev', 'kvargs'], 'test_dispatcher.c': ['dispatcher'], 'test_distributor.c': ['distributor'], 'test_distributor_perf.c': ['distributor'], @@ -80,7 +80,7 @@ source_file_deps = { 'test_event_ring.c': ['eventdev'], 'test_event_timer_adapter.c': ['ethdev', 'eventdev', 'bus_vdev'], 'test_event_vector_adapter.c': ['eventdev', 'bus_vdev'], - 'test_eventdev.c': ['eventdev', 'bus_vdev'], + 'test_eventdev.c': ['ethdev', 'eventdev', 'bus_vdev'], 'test_external_mem.c': [], 'test_fbarray.c': [], 'test_fib.c': ['net', 'fib'], diff --git a/lib/bpf/meson.build b/lib/bpf/meson.build index 28df7f469a..bc76cc7209 100644 --- a/lib/bpf/meson.build +++ b/lib/bpf/meson.build @@ -7,8 +7,6 @@ if is_windows subdir_done() endif -cflags += no_wvla_cflag - if arch_subdir == 'x86' and dpdk_conf.get('RTE_ARCH_32') build = false reason = 'not supported on 32-bit x86' @@ -19,7 +17,6 @@ sources = files('bpf.c', 'bpf_dump.c', 'bpf_exec.c', 'bpf_load.c', - 'bpf_pkt.c', 'bpf_stub.c', 'bpf_validate.c') @@ -29,11 +26,9 @@ elif dpdk_conf.has('RTE_ARCH_ARM64') sources += files('bpf_jit_arm64.c') endif -headers = files('bpf_def.h', - 'rte_bpf.h', - 'rte_bpf_ethdev.h') +headers = files('bpf_def.h', 'rte_bpf.h') -deps += ['mbuf', 'net', 'ethdev'] +deps += ['mbuf', 'net'] dep = dependency('libelf', required: false, method: 'pkg-config') if dep.found() diff --git a/lib/bpf/bpf_pkt.c b/lib/ethdev/ethdev_bpf.c similarity index 95% rename from lib/bpf/bpf_pkt.c rename to lib/ethdev/ethdev_bpf.c index 01f813c56b..712afdc3df 100644 --- a/lib/bpf/bpf_pkt.c +++ b/lib/ethdev/ethdev_bpf.c @@ -6,19 +6,23 @@ #include <string.h> #include <errno.h> #include <stdint.h> +#include <stdlib.h> #include <sys/queue.h> #include <eal_export.h> +#include <rte_atomic.h> +#include <rte_bpf.h> +#include <rte_bpf_ethdev.h> #include <rte_common.h> -#include <rte_malloc.h> +#include <rte_config.h> +#include <rte_errno.h> +#include <rte_ethdev.h> #include <rte_log.h> -#include <rte_atomic.h> +#include <rte_malloc.h> #include <rte_mbuf.h> -#include <rte_ethdev.h> - -#include <rte_bpf_ethdev.h> -#include "bpf_impl.h" +#include <rte_spinlock.h> +#include <rte_stdatomic.h> /* * information about installed BPF rx/tx callback @@ -163,10 +167,11 @@ apply_filter(struct rte_mbuf *mb[], const uint64_t rc[], uint32_t num, uint32_t drop) { uint32_t i, j, k; - struct rte_mbuf *dr[num]; + struct rte_mbuf **dr; - for (i = 0, j = 0, k = 0; i != num; i++) { + dr = alloca(sizeof(struct rte_mbuf *) * num); + for (i = 0, j = 0, k = 0; i != num; i++) { /* filter matches */ if (rc[i] != 0) mb[j++] = mb[i]; @@ -193,8 +198,8 @@ pkt_filter_vm(const struct rte_bpf *bpf, struct rte_mbuf *mb[], uint32_t num, uint32_t drop) { uint32_t i; - void *dp[num]; - uint64_t rc[num]; + void **dp = alloca(sizeof(void *) * num); + uint64_t *rc = alloca(sizeof(uint64_t) * num); for (i = 0; i != num; i++) dp[i] = rte_pktmbuf_mtod(mb[i], void *); @@ -209,7 +214,7 @@ pkt_filter_jit(const struct rte_bpf_jit *jit, struct rte_mbuf *mb[], { uint32_t i, n; void *dp; - uint64_t rc[num]; + uint64_t *rc = alloca(sizeof(uint64_t) * num); n = 0; for (i = 0; i != num; i++) { @@ -228,7 +233,7 @@ static inline uint32_t pkt_filter_mb_vm(const struct rte_bpf *bpf, struct rte_mbuf *mb[], uint32_t num, uint32_t drop) { - uint64_t rc[num]; + uint64_t *rc = alloca(sizeof(uint64_t) * num); rte_bpf_exec_burst(bpf, (void **)mb, rc, num); return apply_filter(mb, rc, num, drop); @@ -239,7 +244,7 @@ pkt_filter_mb_jit(const struct rte_bpf_jit *jit, struct rte_mbuf *mb[], uint32_t num, uint32_t drop) { uint32_t i, n; - uint64_t rc[num]; + uint64_t *rc = alloca(sizeof(uint64_t) * num); n = 0; for (i = 0; i != num; i++) { @@ -515,7 +520,7 @@ bpf_eth_elf_load(struct bpf_eth_cbh *cbh, uint16_t port, uint16_t queue, ftx = select_tx_callback(prm->prog_arg.type, flags); if (frx == NULL && ftx == NULL) { - RTE_BPF_LOG_LINE(ERR, "%s(%u, %u): no callback selected;", + RTE_ETHDEV_LOG_LINE(ERR, "%s(%u, %u): no callback selected;", __func__, port, queue); return -EINVAL; } @@ -527,7 +532,7 @@ bpf_eth_elf_load(struct bpf_eth_cbh *cbh, uint16_t port, uint16_t queue, rte_bpf_get_jit(bpf, &jit); if ((flags & RTE_BPF_ETH_F_JIT) != 0 && jit.func == NULL) { - RTE_BPF_LOG_LINE(ERR, "%s(%u, %u): no JIT generated;", + RTE_ETHDEV_LOG_LINE(ERR, "%s(%u, %u): no JIT generated;", __func__, port, queue); rte_bpf_destroy(bpf); return -ENOTSUP; diff --git a/lib/ethdev/meson.build b/lib/ethdev/meson.build index f1d2586591..1d68d5348c 100644 --- a/lib/ethdev/meson.build +++ b/lib/ethdev/meson.build @@ -55,6 +55,12 @@ endif deps += ['net', 'kvargs', 'meter', 'telemetry'] +if dpdk_conf.has('RTE_LIB_BPF') + deps += ['bpf'] + headers += files('rte_bpf_ethdev.h') + sources += files('ethdev_bpf.c') +endif + if is_freebsd annotate_locks = false endif diff --git a/lib/bpf/rte_bpf_ethdev.h b/lib/ethdev/rte_bpf_ethdev.h similarity index 100% rename from lib/bpf/rte_bpf_ethdev.h rename to lib/ethdev/rte_bpf_ethdev.h diff --git a/lib/meson.build b/lib/meson.build index 0d56b2083b..8b68aa0356 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -22,7 +22,8 @@ libraries = [ 'mbuf', 'net', 'meter', - 'ethdev', + 'bpf', + 'ethdev', # ethdev depends on bpf 'pci', # core 'cmdline', 'metrics', # bitrate/latency stats depends on this @@ -31,7 +32,6 @@ libraries = [ 'acl', 'bbdev', 'bitratestats', - 'bpf', 'cfgfile', 'compressdev', 'cryptodev', -- 2.47.2