[dpdk-dev] [PATCH v1 1/5] bpf: add BPF loading and execution framework
Jerin Jacob
jerin.jacob at caviumnetworks.com
Tue Mar 13 14:24:34 CET 2018
-----Original Message-----
> Date: Fri, 9 Mar 2018 16:42:01 +0000
> From: Konstantin Ananyev <konstantin.ananyev at intel.com>
> To: dev at dpdk.org
> CC: Konstantin Ananyev <konstantin.ananyev at intel.com>
> Subject: [dpdk-dev] [PATCH v1 1/5] bpf: add BPF loading and execution
> framework
> X-Mailer: git-send-email 1.7.0.7
>
> librte_bpf provides a framework to load and execute eBPF bytecode
> inside user-space dpdk based applications.
> It supports basic set of features from eBPF spec
> (https://www.kernel.org/doc/Documentation/networking/filter.txt).
>
> Not currently supported features:
> - JIT
> - cBPF
> - tail-pointer call
> - eBPF MAP
> - skb
>
> It also adds dependency on libelf.
>
> Signed-off-by: Konstantin Ananyev <konstantin.ananyev at intel.com>
> ---
> config/common_base | 5 +
> config/common_linuxapp | 1 +
> lib/Makefile | 2 +
> lib/librte_bpf/Makefile | 30 +++
> lib/librte_bpf/bpf.c | 48 ++++
> lib/librte_bpf/bpf_exec.c | 452 +++++++++++++++++++++++++++++++++++++
> lib/librte_bpf/bpf_impl.h | 37 +++
> lib/librte_bpf/bpf_load.c | 380 +++++++++++++++++++++++++++++++
> lib/librte_bpf/bpf_validate.c | 55 +++++
> lib/librte_bpf/rte_bpf.h | 158 +++++++++++++
> lib/librte_bpf/rte_bpf_version.map | 12 +
> mk/rte.app.mk | 2 +
> 12 files changed, 1182 insertions(+)
> create mode 100644 lib/librte_bpf/Makefile
> create mode 100644 lib/librte_bpf/bpf.c
> create mode 100644 lib/librte_bpf/bpf_exec.c
> create mode 100644 lib/librte_bpf/bpf_impl.h
> create mode 100644 lib/librte_bpf/bpf_load.c
> create mode 100644 lib/librte_bpf/bpf_validate.c
> create mode 100644 lib/librte_bpf/rte_bpf.h
> create mode 100644 lib/librte_bpf/rte_bpf_version.map
>
> diff --git a/config/common_base b/config/common_base
> index ad03cf433..2205b684f 100644
> --- a/config/common_base
> +++ b/config/common_base
> @@ -823,3 +823,8 @@ CONFIG_RTE_APP_CRYPTO_PERF=y
> # Compile the eventdev application
> #
> CONFIG_RTE_APP_EVENTDEV=y
> +
> +#
> +# Compile librte_bpf
> +#
> +CONFIG_RTE_LIBRTE_BPF=n
> diff --git a/config/common_linuxapp b/config/common_linuxapp
> index ff98f2355..7b4a0ce7d 100644
> --- a/config/common_linuxapp
> +++ b/config/common_linuxapp
> @@ -10,6 +10,7 @@ CONFIG_RTE_EAL_NUMA_AWARE_HUGEPAGES=y
> CONFIG_RTE_EAL_IGB_UIO=y
> CONFIG_RTE_EAL_VFIO=y
> CONFIG_RTE_KNI_KMOD=y
> +CONFIG_RTE_LIBRTE_BPF=y
> CONFIG_RTE_LIBRTE_KNI=y
> CONFIG_RTE_LIBRTE_PMD_KNI=y
> CONFIG_RTE_LIBRTE_VHOST=y
> diff --git a/lib/Makefile b/lib/Makefile
> index ec965a606..a4a2329f9 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -97,6 +97,8 @@ DEPDIRS-librte_pdump := librte_eal librte_mempool librte_mbuf librte_ether
> DIRS-$(CONFIG_RTE_LIBRTE_GSO) += librte_gso
> DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net
> DEPDIRS-librte_gso += librte_mempool
> +DIRS-$(CONFIG_RTE_LIBRTE_BPF) += librte_bpf
> +DEPDIRS-librte_bpf := librte_eal librte_mempool librte_mbuf librte_ether
>
> ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
> DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni
> diff --git a/lib/librte_bpf/Makefile b/lib/librte_bpf/Makefile
> new file mode 100644
> index 000000000..e0f434e77
> --- /dev/null
> +++ b/lib/librte_bpf/Makefile
> @@ -0,0 +1,30 @@
> +# SPDX-License-Identifier: BSD-3-Clause
> +# Copyright(c) 2018 Intel Corporation
> +
> +include $(RTE_SDK)/mk/rte.vars.mk
> +
> +# library name
> +LIB = librte_bpf.a
> +
> +CFLAGS += -O3
> +CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR)
> +CFLAGS += -DALLOW_EXPERIMENTAL_API
> +LDLIBS += -lrte_net -lrte_eal
> +LDLIBS += -lrte_mempool -lrte_ring
> +LDLIBS += -lrte_mbuf -lrte_ethdev
> +LDLIBS += -lelf
> +
> +EXPORT_MAP := rte_bpf_version.map
> +
> +LIBABIVER := 1
> +
> +# all source are stored in SRCS-y
> +SRCS-$(CONFIG_RTE_LIBRTE_BPF) += bpf.c
> +SRCS-$(CONFIG_RTE_LIBRTE_BPF) += bpf_exec.c
> +SRCS-$(CONFIG_RTE_LIBRTE_BPF) += bpf_load.c
> +SRCS-$(CONFIG_RTE_LIBRTE_BPF) += bpf_validate.c
> +
> +# install header files
> +SYMLINK-$(CONFIG_RTE_LIBRTE_BPF)-include += rte_bpf.h
> +
> +include $(RTE_SDK)/mk/rte.lib.mk
> diff --git a/lib/librte_bpf/bpf.c b/lib/librte_bpf/bpf.c
> new file mode 100644
> index 000000000..4727d2251
> --- /dev/null
> +++ b/lib/librte_bpf/bpf.c
> @@ -0,0 +1,48 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2018 Intel Corporation
> + */
> +
> +#include <stdarg.h>
> +#include <stdio.h>
> +#include <string.h>
> +#include <errno.h>
> +#include <stdint.h>
> +#include <inttypes.h>
> +
> +#include <rte_common.h>
> +#include <rte_eal.h>
> +
> +#include "bpf_impl.h"
> +
> +__rte_experimental void
> +rte_bpf_destroy(struct rte_bpf *bpf)
> +{
> + if (bpf != NULL) {
> + if (bpf->jit.func != NULL)
> + munmap(bpf->jit.func, bpf->jit.sz);
> + munmap(bpf, bpf->sz);
Any specific reason to not use this memory from huge page using rte_zmalloc
to avoid normal TLB misses?
> + }
> +}
> +
> +__rte_experimental int
> +rte_bpf_get_jit(const struct rte_bpf *bpf, struct rte_bpf_jit *jit)
> +{
> + if (bpf == NULL || jit == NULL)
> + return -EINVAL;
> +
> + jit[0] = bpf->jit;
> + return 0;
> +}
> +
> +int
> +bpf_jit(struct rte_bpf *bpf)
> +{
> + int32_t rc;
> +
> + rc = -ENOTSUP;
> +
> + if (rc != 0)
> + RTE_LOG(WARNING, USER1, "%s(%p) failed, error code: %d;\n",
> + __func__, bpf, rc);
How about using new dynamic logging option for this library?
> + return rc;
More information about the dev
mailing list