[RFC: add openvswitch actions using BPF 0/9]
Subsystems (4)
cover [RFC: add openvswitch actions using BPF 0/9]
User space changes of BPF OVS action agains curret OVS master.
Andy Zhou (9):
hack: Do not compile datapath
odp: add a new ODP action: OVS_ACTION_ATTR_BPF_PROG
tests: add a OVS_ACTION_ATTR_BPF_PROG ation unit test case
autoconf: support -with-llc options
bpf: add the first BPF program.
lib: import into libbpf to ovs/lib
ofproto-dpif: Add eBPF program loader and runtime infrasturcure.
ofproto-dpif: Add datapath eBPF support detection
ofproto-dpif-xlate: generate BPF output action (Hack)
INSTALL.BPF.md | 42 ++ Makefile.am | 5 +- acinclude.m4 | 18 +- bpf/automake.mk | 27 ++ bpf/bpf-shared.h | 12 + bpf/ovs-actions.c | 13 + bpf/ovs-bpf-helpers.h | 35 ++ configure.ac | 2 + datapath/linux/compat/include/linux/openvswitch.h | 29 +- lib/automake.mk | 22 ++ lib/dpif-netdev.c | 1 + lib/dpif.c | 1 + lib/libbpf.c | 100 +++++ lib/libbpf.h | 185 +++++++++ lib/odp-execute.c | 1 + lib/odp-util.c | 33 ++ ofproto/automake.mk | 2 + ofproto/ofproto-dpif-bpf.c | 454 ++++++++++++++++++++++ ofproto/ofproto-dpif-bpf.h | 42 ++ ofproto/ofproto-dpif-xlate.c | 18 +- ofproto/ofproto-dpif.c | 21 + tests/odp.at | 1 + vswitchd/automake.mk | 5 + 23 files changed, 1064 insertions(+), 5 deletions(-) create mode 100644 INSTALL.BPF.md create mode 100644 bpf/automake.mk create mode 100644 bpf/bpf-shared.h create mode 100644 bpf/ovs-actions.c create mode 100644 bpf/ovs-bpf-helpers.h create mode 100644 lib/libbpf.c create mode 100644 lib/libbpf.h create mode 100644 ofproto/ofproto-dpif-bpf.c create mode 100644 ofproto/ofproto-dpif-bpf.h
Signature · 6 lines
1.9.1 _______________________________________________ dev mailing list [email protected] http://openvswitch.org/mailman/listinfo/dev
A message that is not in the archive (sent off-list or not yet received): 1423090163-19902-1-git-send-email-azhou-l0M0P4e3n4LQT0dZR+AlfA@public.gmane.org
RFC 1/9 hack: Do not compile datapath
The OVS eBPF patch sets are developed against master 'net-next' tree, which is currently targeting for kernel version 3.19.
The datapath in OVS mater does not currently support 3.19 kernel. But we should not really using OVS datapath, The changes in the follow patches are only changes in user space programs, which should work with the kernel module built from the 'net-next' tree.
This patch disables building of the datapath and disables the configuration time kernel version check.
--- Makefile.am | 3 ++- acinclude.m4 | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
Makefile.am +2 -1
@@ -7,7 +7,8 @@ AUTOMAKE_OPTIONS = foreign subdir-objects ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = datapath +# SUBDIRS = datapath +SUBDIRS = AM_CPPFLAGS = $(SSL_CFLAGS) AM_LDFLAGS = $(SSL_LDFLAGS)
acinclude.m4 +1 -1
@@ -134,7 +134,7 @@ AC_DEFUN([OVS_CHECK_LINUX], [ AC_MSG_RESULT([$kversion]) if test "$version" -ge 3; then - if test "$version" = 3 && test "$patchlevel" -le 18; then + if test "$version" = 3 && test "$patchlevel" -le 19; then : # Linux 3.x else AC_ERROR([Linux kernel in $KBUILD is version $kversion, but version newer than 3.18.x is not supported (please refer to the FAQ for advice)])
Signature · 6 lines
1.9.1 _______________________________________________ dev mailing list [email protected] http://openvswitch.org/mailman/listinfo/dev
Re: [ovs-dev] [RFC: add openvswitch actions using BPF 1/9] hack: Do not compile datapath
Quoted 8 lines · Andy Zhou
The OVS eBPF patch sets are developed against master 'net-next' tree, which is currently targeting for kernel version 3.19.
The datapath in OVS mater does not currently support 3.19 kernel. But we should not really using OVS datapath, The changes in the follow patches are only changes in user space programs, which should work with the kernel module built from the 'net-next' tree.
Quoted 4 lines
This patch disables building of the datapath and disables the configuration time kernel version check.
Signed-off-by Andy Zhou <[email protected]>
You can drop this when the datapath sync series is fully merged.
A message that is not in the archive (sent off-list or not yet received): 20150205134454.GA5546-4EA/[email protected]
Re: [RFC: add openvswitch actions using BPF 1/9] hack: Do not compile datapath
Yes. That's the plan.
Quoted 9 lines · Thomas Graf
Quoted 8 lines · Andy Zhou
The OVS eBPF patch sets are developed against master 'net-next' tree, which is currently targeting for kernel version 3.19.
The datapath in OVS mater does not currently support 3.19 kernel. But we should not really using OVS datapath, The changes in the follow patches are only changes in user space programs, which should work with the kernel module built from the 'net-next' tree.
Quoted 6 lines
Quoted 4 lines
This patch disables building of the datapath and disables the configuration time kernel version check.
Signed-off-by Andy Zhou <[email protected]>You can drop this when the datapath sync series is fully merged.
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev
[RFC: add openvswitch actions using BPF 2/9] odp: add a new ODP action: OVS_ACTION_ATTR_BPF_PROG
In reply to a message not in the archiveAdd a new ODP action and implements the corresponding Netlink message handling of this new attribute.
--- datapath/linux/compat/include/linux/openvswitch.h | 29 +++++++++++++++++++- lib/dpif-netdev.c | 1 + lib/dpif.c | 1 + lib/odp-execute.c | 1 + lib/odp-util.c | 33 +++++++++++++++++++++++ 5 files changed, 64 insertions(+), 1 deletion(-)
datapath/linux/compat/include/linux/openvswitch.h +28 -1
@@ -569,6 +569,18 @@ struct ovs_action_push_mpls { };/** +* struct ovs_action_bpf_prog - %OVS_ACTION_ATTR_BPF_PROG action argument. +* +* XXX provides bpf program id and execution context. +* +*/ +struct ovs_action_bpf_prog { +__be32 prog_fd; +__be32 arg0; +__be32 arg1; +}; + +/** * struct ovs_action_push_vlan - %OVS_ACTION_ATTR_PUSH_VLAN action argument. * @vlan_tpid: Tag protocol identifier (TPID) to push. * @vlan_tci: Tag control identifier (TCI) to push. The CFI bit must be set
@@ -685,7 +697,7 @@ enum ovs_action_attr {* data immediately followed by a mask. * The data must be zero for the unmasked * bits. */ - + OVS_ACTION_ATTR_BPF_PROG, /* struct ovs_action_bpf_prog. */#ifndef __KERNEL__OVS_ACTION_ATTR_TUNNEL_PUSH ,/* struct ovs_action_push_tnl*/ OVS_ACTION_ATTR_TUNNEL_POP, /* u32 port number. */
@@ -695,4 +707,19 @@ enum ovs_action_attr {#define OVS_ACTION_ATTR_MAX (__OVS_ACTION_ATTR_MAX - 1) +/* integer value in 'imm' field of BPF_CALL instruction selects which OVS helper +* function eBPF program intends to call +*/ +enum ovs_bpf_func_id { + OVS_BPF_FUNC_unspec, + OVS_BPF_FUNC_output,/* int ovs_bpf_output(ctxt) */ + __OVS_BPF_FUNC_MAX_ID, +}; + +struct ovs_bpf_action_ctxt { +void *skb; +uint32_t arg0; +uint32_t arg1; +}; +#endif /* _LINUX_OPENVSWITCH_H */
lib/dpif-netdev.c +1 -0
@@ -3240,6 +3240,7 @@ dp_execute_cb(void *aux_, struct dpif_packet **packets, int cnt,case OVS_ACTION_ATTR_SAMPLE :case OVS_ACTION_ATTR_HASH :case OVS_ACTION_ATTR_UNSPEC : +case OVS_ACTION_ATTR_BPF_PROG :case __OVS_ACTION_ATTR_MAX:OVS_NOT_REACHED (); }
lib/dpif.c +1 -0
@@ -1132,6 +1132,7 @@ dpif_execute_helper_cb(void *aux_, struct dpif_packet **packets, int cnt,case OVS_ACTION_ATTR_SET_MASKED :case OVS_ACTION_ATTR_SAMPLE :case OVS_ACTION_ATTR_UNSPEC : +case OVS_ACTION_ATTR_BPF_PROG :case __OVS_ACTION_ATTR_MAX:OVS_NOT_REACHED (); }
lib/odp-execute.c +1 -0
@@ -591,6 +591,7 @@ odp_execute_actions(void *dp, struct dpif_packet **packets, int cnt, bool steal,break ;case OVS_ACTION_ATTR_UNSPEC : +case OVS_ACTION_ATTR_BPF_PROG :case __OVS_ACTION_ATTR_MAX:OVS_NOT_REACHED (); }
lib/odp-util.c +33 -0
@@ -88,6 +88,7 @@ odp_action_len(uint16_t type)case OVS_ACTION_ATTR_SET :return -2 ;case OVS_ACTION_ATTR_SET_MASKED :return -2 ;case OVS_ACTION_ATTR_SAMPLE :return -2 ; +case OVS_ACTION_ATTR_BPF_PROG :return sizeof (struct ovs_action_bpf_prog );case OVS_ACTION_ATTR_UNSPEC :case __OVS_ACTION_ATTR_MAX:
@@ -185,6 +186,17 @@ format_odp_sample_action(struct ds *ds, const struct nlattr *attr)ds_put_format (ds,"))" ); } +static void +format_bpf_prog_action (struct ds *ds,const struct nlattr *a) +{ +struct ovs_action_bpf_prog *bpf_act = (struct ovs_action_bpf_prog *) +nl_attr_get (a); + +ds_put_cstr (ds,"bpf" ); +ds_put_format (ds,"(%u,%u,%u)" ,ntohl (bpf_act->prog_fd), +ntohl (bpf_act->arg0),ntohl (bpf_act->arg1)); +} +static const char *slow_path_reason_to_string (uint32_t reason) {
@@ -682,6 +694,9 @@ format_odp_action(struct ds *ds, const struct nlattr *a)case OVS_ACTION_ATTR_SAMPLE :format_odp_sample_action (ds, a);break ; +case OVS_ACTION_ATTR_BPF_PROG : +format_bpf_prog_action (ds, a); +break ;case OVS_ACTION_ATTR_UNSPEC :case __OVS_ACTION_ATTR_MAX:default :
@@ -1006,6 +1021,24 @@ parse_odp_action(const char *s, const struct simap *port_names,return parse_odp_userspace_action (s, actions); } + { +struct ovs_action_bpf_prog act_bpf; +uint32_t fd; +uint32_t arg0, arg1; +int n =-1 ; + +if (ovs_scan (s,"bpf(%" PRIu32",%" PRIu32",%" PRIu32")%n" , &fd, &arg0, + &arg1, &n)) { +memset (&act_bpf,0 ,sizeof (act_bpf)); + act_bpf.prog_fd =htonl (fd); + act_bpf.arg0 =htonl (arg0); + act_bpf.arg1 =htonl (arg1); +nl_msg_put_unspec (actions,OVS_ACTION_ATTR_BPF_PROG , + &act_bpf,sizeof (act_bpf)); +return n; + } + } +if (!strncmp (s,"set(" ,4 )) {size_t start_ofs;int retval;
Signature · 6 lines
1.9.1 _______________________________________________ dev mailing list [email protected] http://openvswitch.org/mailman/listinfo/dev
Re: [ovs-dev] [RFC: add openvswitch actions using BPF 2/9] odp: add a new ODP action: OVS_ACTION_ATTR_BPF_PROG
datapath/linux/compat/include/linux/openvswitch.h struct ovs_action_push_mpls { · line 581
Quoted 11 lines · Andy Zhou
/**
+ * structovs_action_bpf_prog- %OVS_ACTION_ATTR_BPF_PROG action argument.
+ *
+ * XXX provides bpf program id and execution context.
+ *
+ */datapath/linux/compat/include/linux/openvswitch.h +5
-0+struct ovs_action_bpf_prog { +__be32 prog_fd; +__be32 arg0; +__be32 arg1; +};
I assume you intend to replace this with a nested Netlink attribute with a series of U32 attributes to carry args in the future?
datapath/linux/compat/include/linux/openvswitch.h enum ovs_action_attr { · line 717
Quoted 5 lines
datapath/linux/compat/include/linux/openvswitch.h +5
-0+enum ovs_bpf_func_id { + OVS_BPF_FUNC_unspec, + OVS_BPF_FUNC_output,/* int ovs_bpf_output(ctxt) */ + __OVS_BPF_FUNC_MAX_ID, +};
The mix of cap / no-cap looks a bit weird.
lib/odp-util.c format_odp_sample_action(struct ds *ds, const struct nlattr *attr) · line 198
Quoted 10 lines
lib/odp-util.c +10
-0+static void +format_bpf_prog_action (struct ds *ds,const struct nlattr *a) +{ +struct ovs_action_bpf_prog *bpf_act = (struct ovs_action_bpf_prog *) +nl_attr_get (a); + +ds_put_cstr (ds,"bpf" ); +ds_put_format (ds,"(%u,%u,%u)" ,ntohl (bpf_act->prog_fd), +ntohl (bpf_act->arg0),ntohl (bpf_act->arg1)); +}
Maybe ds_put_format(ds, "bpf(... ?
Re: [ovs-dev] [RFC: add openvswitch actions using BPF 2/9] odp: add a new ODP action: OVS_ACTION_ATTR_BPF_PROG
In reply to Andy Zhoudatapath/linux/compat/include/linux/openvswitch.h struct ovs_action_push_mpls { · line 581
Quoted 5 lines · Andy Zhou
datapath/linux/compat/include/linux/openvswitch.h +5
-0+struct ovs_action_bpf_prog { +__be32 prog_fd; +__be32 arg0; +__be32 arg1; +};
Given the 64 bit registers of BPF. Should we have all args in the Netlink message be 64 bit as well?
RFC 3/9 tests: add a OVS_ACTION_ATTR_BPF_PROG ation unit test case
In reply to a message not in the archiveTest parsing and formating of the newly added action.
--- tests/odp.at | 1 + 1 file changed, 1 insertion(+)
tests/odp.at +1 -0
@@ -282,6 +282,7 @@ tnl_pop(4) tnl_push(tnl_port(4),header(size=42,type=3,eth(dst=f8:bc:12:44:34:b6,src=f8:bc:12:46:58:e0,dl_type=0x0800),ipv4(src=1.1.2.88,dst=1.1.2.92,proto=47,tos=0,ttl=64,frag=0x40),gre((flags=0x20,proto=0x6558),key=0x1e241)),out_port(1)) tnl_push(tnl_port(4),header(size=46,type=3,eth(dst=f8:bc:12:44:34:b6,src=f8:bc:12:46:58:e0,dl_type=0x0800),ipv4(src=1.1.2.88,dst=1.1.2.92,proto=47,tos=0,ttl=64,frag=0x40),gre((flags=0xa0,proto=0x6558),csum=0x0,key=0x1e241)),out_port(1)) tnl_push(tnl_port(6),header(size=50,type=4,eth(dst=f8:bc:12:44:34:b6,src=f8:bc:12:46:58:e0,dl_type=0x0800),ipv4(src=1.1.2.88,dst=1.1.2.92,proto=17,tos=0,ttl=64,frag=0x40),udp(src=0,dst=4789),vxlan(flags=0x8000000,vni=0x1c700)),out_port(1)) +bpf(1,1,1) ]) AT_CHECK_UNQUOTED([ovstest test-odp parse-actions < actions.txt], [0], [`cat actions.txt`
Signature · 6 lines
1.9.1 _______________________________________________ dev mailing list [email protected] http://openvswitch.org/mailman/listinfo/dev
RFC 4/9 autoconf: support -with-llc options
In reply to a message not in the archiveAdd a configuration option to allow specifing the LLVM backend module for compiling BPF C source code into BPF instruction sets.
See INSTALL.BPF.md for usgae information.
--- INSTALL.BPF.md | 42 ++++++++++++++++++++++++++++++++++++++++++ Makefile.am | 1 + acinclude.m4 | 16 ++++++++++++++++ configure.ac | 2 ++ 4 files changed, 61 insertions(+) create mode 100644 INSTALL.BPF.md
INSTALL.BPF.md new file +42 -0
@@ -0,0 +1,42 @@ +# Dependencies + +- Need Clang + llvm-dev version 3.X for any (2 <= X <= 4) +- http://llvm.org/apt/ + +apt-get install libelf-dev clang-3.4 llvm-3.4-dev + +# Build LLVM plugin + +*[Upstream] git://git.kernel.org/pub/scm/linux/kernel/git/ast/bpf* + +git clone git://github.com/joestringer/linux +NN=$PWD/linux + +cd $NN/tools/bpf/llvm/bld +make LLVM_CONFIG=`which llvm-config-3.4` + +# Configure OVS to use BPF LLC + +OVS=/path/to/openvswitch +cd $OVS +./configure --with-llc=$NN/tools/bpf/llvm/bld/Debug+Asserts/bin/llc + +# Build OVS and BPF module + +make +cd datapath/bpf +make + +# Load BPF module + +cd $NN/ +make M=samples/bpf +samples/bpf/simple_load $OVS/datapath/bpf/simple.bpf + +Note down which fd was used for the program. This will be used in next step. + +# Install flow to use BPF + +$OVS/utilities/ovs-dpctl add-flow "eth(src=00:00:00:00:00:00,dst=00:00:00:00:00:00)" "bpf(<FD>, 0)" + +Success?
Makefile.am +1 -0
@@ -71,6 +71,7 @@ docs = \ DESIGN.md \ FAQ.md \ INSTALL.md \ + INSTALL.BPF.md \ INSTALL.Debian.md \ INSTALL.Docker.md \ INSTALL.DPDK.md \
acinclude.m4 +16 -0
@@ -157,6 +157,22 @@ AC_DEFUN([OVS_CHECK_LINUX], [ AM_CONDITIONAL(LINUX_ENABLED, test -n "$KBUILD") ]) +dnl OVS_CHECK_BPF +dnl +dnl Check clang set ups for compiling BPF +AC_DEFUN([OVS_CHECK_LLC], [ + AC_ARG_WITH([llc], + [AC_HELP_STRING([--with-llc=/path/to/llc], + [Specify the bpf clang backend binrary])]) + + if (test X"$with_llc" != X); then + LLC=$with_llc + if (test ! -x $LLC); then + AC_MSG_ERROR([BPF llc backend is configured but not found ]) + fi + fi +]) + dnl OVS_CHECK_DPDK dnl dnl Configure DPDK source tree
configure.ac +2 -0
@@ -160,8 +160,10 @@ OVS_ENABLE_SPARSE AC_ARG_VAR(KARCH, [Kernel Architecture String]) AC_SUBST(KARCH) +AC_ARG_VAR(LLC, [LLVM bpf backend processor]) OVS_CHECK_LINUX OVS_CHECK_DPDK +OVS_CHECK_LLC OVS_CHECK_PRAGMA_MESSAGE AC_SUBST([OVS_CFLAGS]) AC_SUBST([OVS_LDFLAGS])
Signature · 6 lines
1.9.1 _______________________________________________ dev mailing list [email protected] http://openvswitch.org/mailman/listinfo/dev
Re: [RFC: add openvswitch actions using BPF 4/9] autoconf: support -with-llc options
Quoted 33 lines · Andy Zhou
Add a configuration option to allow specifing the LLVM backend module for compiling BPF C source code into BPF instruction sets.
See INSTALL.BPF.md for usgae information.
Signed-off-by Joe Stringer <[email protected]>Signed-off-by Andy Zhou <[email protected]>--- INSTALL.BPF.md | 42 ++++++++++++++++++++++++++++++++++++++++++ Makefile.am | 1 + acinclude.m4 | 16 ++++++++++++++++ configure.ac | 2 ++ 4 files changed, 61 insertions(+) create mode 100644 INSTALL.BPF.mdINSTALL.BPF.md new file +12
-0@@ -0,0 +1,42 @@ +# Dependencies + +- Need Clang + llvm-dev version 3.X for any (2 <= X <= 4) +- http://llvm.org/apt/ + +apt-get install libelf-dev clang-3.4 llvm-3.4-dev + +# Build LLVM plugin + +*[Upstream] git://git.kernel.org/pub/scm/linux/kernel/git/ast/bpf* + +git clone git://github.com/joestringer/linux
INSTALL.BPF.md line 22
Quoted 10 lines
INSTALL.BPF.md new file +10
-0+NN=$PWD/linux + +cd $NN/tools/bpf/llvm/bld +make LLVM_CONFIG=`which llvm-config-3.4` + +# Configure OVS to use BPF LLC + +OVS=/path/to/openvswitch +cd $OVS +./configure --with-llc=$NN/tools/bpf/llvm/bld/Debug+Asserts/bin/llc
Naturally we'd need to update these instructions, this becomes much simpler if we just require clang-3.7.
RFC 5/9 bpf: add the first BPF program.
In reply to a message not in the archiveAdded a BPF implementation of output action. The intention is to have all OVS related BPF programs live under the 'bpf' folder.
--- Makefile.am | 1 + bpf/automake.mk | 27 +++++++++++++++++++++++++++ bpf/bpf-shared.h | 12 ++++++++++++ bpf/ovs-actions.c | 13 +++++++++++++ bpf/ovs-bpf-helpers.h | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+) create mode 100644 bpf/automake.mk create mode 100644 bpf/bpf-shared.h create mode 100644 bpf/ovs-actions.c create mode 100644 bpf/ovs-bpf-helpers.h
Makefile.am +1 -0
@@ -354,6 +354,7 @@ dist-docs: include m4/automake.mk include lib/automake.mk +include bpf/automake.mk include ofproto/automake.mk include utilities/automake.mk include tests/automake.mk
bpf/automake.mk new file +27 -0
@@ -0,0 +1,27 @@ +# Copyright (C) 2015 Nicira, Inc. +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. This file is offered as-is, +# without warranty of any kind. + +if LINUX +sbin_PROGRAMS += bpf/ovs-actions.bpf + + +EXTRA_DIST += $(srcdir)/bpf/ovs-bpf-helpers.h \ + $(srcdir)/bpf/bpf-shared.h \ + $(srcdir)/bpf/ovs-actions.c + +DEP_FILES = $(srcdir)/bpf/ovs-bpf-helpers.h \ + $(srcdir)/bpf/bpf-shared.h \ + $(srcdir)/datapath/linux/compat/include/linux/openvswitch.h + +BPF_INCLUDES=-I. -I$(srcdir)/datapath/linux/compat/include -I/usr/include + +bpf/ovs-actions.bpf: $(srcdir)/bpf/ovs-actions.c $(DEP_FILES) + $(AM_V_GEN)clang -DHAVE_CONFIG_H $(BPF_INCLUDES) $(NOSTDINC_FLAGS) \ + $(AM_CFLAGS) $(EXTRA_CFLAGS) -Wno-unused-value -Wno-pointer-sign \ + -O2 -emit-llvm -c $< -o -| $(LLC) -filetype=obj -o $@ + +endif
bpf/bpf-shared.h new file +12 -0
@@ -0,0 +1,12 @@ + +/* Shared data structures between bpf and C programs. */ + +/* a helper structure used by eBPF C program +* to describe map attributes to elf_bpf loader +*/ +struct bpf_map_def { +unsigned int type; +unsigned int key_size; +unsigned int value_size; +unsigned int max_entries; +};
bpf/ovs-actions.c new file +13 -0
@@ -0,0 +1,13 @@ +#include <config.h> +#include "ovs-bpf-helpers.h" + +int output_action (struct ovs_bpf_action_ctxt *ctxt); + +SEC("ovs/output") +int +output_action (struct ovs_bpf_action_ctxt *ctxt) +{ +return ovs_bpf_helper_output (ctxt->skb, ctxt->arg0); +} + +char _license[] SEC("license") = "GPL";
bpf/ovs-bpf-helpers.h new file +35 -0
@@ -0,0 +1,35 @@ +#ifndef __OVS_BPF_HELPERS_H +#define __OVS_BPF_HELPERS_H + +#include <stdint.h> +#include <linux/openvswitch.h> +struct sk_buff ; + +/* helper macro to place programs, maps, license in +* different sections in elf_bpf file. Section names +* are interpreted by elf_bpf loader +*/ +#define SEC (NAME ) __attribute__((section(NAME), used)) + +/* helper functions called from eBPF programs written in C */ +static void *(*bpf_map_lookup_elem)(void *map,void *key) = + (void *) OVS_BPF_FUNC_map_lookup_elem; +static int (*bpf_map_update_elem)(void *map,void *key,void *value, +unsigned long long flags) = + (void *) OVS_BPF_FUNC_map_update_elem; +static int (*bpf_map_delete_elem)(void *map,void *key) = + (void *) OVS_BPF_FUNC_map_delete_elem; +static int (*ovs_bpf_helper_output)(struct sk_buff *skb,uint32_t out_port) = + (void *) OVS_BPF_FUNC_output; + +/* llvm builtin functions that eBPF C program may use to +* emit BPF_LD_ABS and BPF_LD_IND instructions +*/ +unsigned long long load_byte (void *skb, +unsigned long long off) asm("llvm.bpf.load.byte" ); +unsigned long long load_half (void *skb, +unsigned long long off) asm("llvm.bpf.load.half" ); +unsigned long long load_word (void *skb, +unsigned long long off) asm("llvm.bpf.load.word" ); + +#endif
Signature · 6 lines
1.9.1 _______________________________________________ dev mailing list [email protected] http://openvswitch.org/mailman/listinfo/dev
Re: [ovs-dev] [RFC: add openvswitch actions using BPF 5/9] bpf: add the first BPF program.
First of all, I *love* this. I have some questions on versioning of helpers in the kernel. I will put comments in the respective kernel patches directly.
bpf/automake.mk line 18
Quoted 7 lines · Andy Zhou
bpf/automake.mk new file +7
-0+EXTRA_DIST += $(srcdir)/bpf/ovs-bpf-helpers.h \ + $(srcdir)/bpf/bpf-shared.h \ + $(srcdir)/bpf/ovs-actions.c + +DEP_FILES = $(srcdir)/bpf/ovs-bpf-helpers.h \ + $(srcdir)/bpf/bpf-shared.h \ + $(srcdir)/datapath/linux/compat/include/linux/openvswitch.h
Some tab / space mixing here.
bpf/automake.mk line 25
Quoted 4 lines
bpf/automake.mk new file +4
-0+bpf/ovs-actions.bpf: $(srcdir)/bpf/ovs-actions.c $(DEP_FILES) + $(AM_V_GEN)clang -DHAVE_CONFIG_H $(BPF_INCLUDES) $(NOSTDINC_FLAGS) \ + $(AM_CFLAGS) $(EXTRA_CFLAGS) -Wno-unused-value -Wno-pointer-sign \ + -O2 -emit-llvm -c $< -o -| $(LLC) -filetype=obj -o $@
I assume you will convert this to a Makefile template
Re: [ovs-dev] [RFC: add openvswitch actions using BPF 5/9] bpf: add the first BPF program.
Quoted 4 lines · Thomas Graf
First of all, I *love* this. I have some questions on versioning of helpers in the kernel. I will put comments in the respective kernel patches directly.
Thanks for the feedbacks.
Quoted 10 lines · Andy Zhou
bpf/automake.mk line 18
Quoted 7 lines
bpf/automake.mk new file +7
-0+EXTRA_DIST += $(srcdir)/bpf/ovs-bpf-helpers.h \ + $(srcdir)/bpf/bpf-shared.h \ + $(srcdir)/bpf/ovs-actions.c + +DEP_FILES = $(srcdir)/bpf/ovs-bpf-helpers.h \ + $(srcdir)/bpf/bpf-shared.h \ + $(srcdir)/datapath/linux/compat/include/linux/openvswitch.hSome tab / space mixing here.
Will fix.
Quoted 7 lines
bpf/automake.mk line 25
Quoted 5 lines
bpf/automake.mk new file +4
-0+bpf/ovs-actions.bpf: $(srcdir)/bpf/ovs-actions.c $(DEP_FILES) + $(AM_V_GEN)clang -DHAVE_CONFIG_H $(BPF_INCLUDES) $(NOSTDINC_FLAGS) \ + $(AM_CFLAGS) $(EXTRA_CFLAGS) -Wno-unused-value -Wno-pointer-sign \ + -O2 -emit-llvm -c $< -o -| $(LLC) -filetype=obj -o $@I assume you will convert this to a
Makefiletemplate
Yes. It needs to be addressed. Not sure if additional changes are required now that
BPF backend is merged into LLVM upstream,
RFC 6/9 lib: import into libbpf to ovs/lib
In reply to Andy ZhouThose files are basically imported from 'net-next: sample/bpf' directory. This is a stop gap measure unil libbpf is upstreamed.
--- lib/automake.mk | 22 +++++++ lib/libbpf.c | 100 ++++++++++++++++++++++++++++++ lib/libbpf.h | 185 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 307 insertions(+) create mode 100644 lib/libbpf.c create mode 100644 lib/libbpf.h
lib/automake.mk +22 -0
@@ -317,6 +317,28 @@ lib_libsflow_la_CFLAGS += -Wno-unused-parameter endif if LINUX +lib_LTLIBRARIES += lib/libbpf.la +lib_libbpf_la_LDFLAGS = \ + -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \ + -Wl,--version-script=$(top_builddir)/lib/libbpf.sym \ + $(AM_LDFLAGS) +lib_libbpf_la_SOURCES = \ + lib/libbpf.h \ + lib/libbpf.c +lib_libbpf_la_CPPFLAGS = $(AM_CPPFLAGS) +# GCC Bug 60784 affects both GCC 4.8 and GCC 4.9. -Wmissing-field-initializers will +# give spurious warning when compiling libbpf. Turn it off for now. +lib_libbpf_la_CFLAGS = $(filter-out -Wmissing-field-initializers, $(AM_CFLAGS)) +lib_libbpf_la_CFLAGS += -Wno-missing-field-initializers +if HAVE_WNO_UNUSED +lib_libbpf_la_CFLAGS += -Wno-unused +endif +if HAVE_WNO_UNUSED_PARAMETER +lib_libbpf_la_CFLAGS += -Wno-unused-parameter +endif +endif + +if LINUX lib_libopenvswitch_la_SOURCES += \ lib/dpif-netlink.c \ lib/dpif-netlink.h \
lib/libbpf.c new file +100 -0
100 lines not on this page · raw message
lib/libbpf.h new file +185 -0
185 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC 7/9 ofproto-dpif: Add eBPF program loader and runtime infrasturcure.
In reply to Andy ZhouAdded a eBPF program loader in ofproto-dpif layer. It only loades the OVS programs.
--- ofproto/automake.mk | 2 + ofproto/ofproto-dpif-bpf.c | 454 +++++++++++++++++++++++++++++++++++++++++++++ ofproto/ofproto-dpif-bpf.h | 42 +++++ vswitchd/automake.mk | 5 + 4 files changed, 503 insertions(+) create mode 100644 ofproto/ofproto-dpif-bpf.c create mode 100644 ofproto/ofproto-dpif-bpf.h
ofproto/automake.mk +2 -0
@@ -28,6 +28,8 @@ ofproto_libofproto_la_SOURCES = \ ofproto/ofproto.h \ ofproto/ofproto-dpif.c \ ofproto/ofproto-dpif.h \ + ofproto/ofproto-dpif-bpf.c \ + ofproto/ofproto-dpif-bpf.h \ ofproto/ofproto-dpif-ipfix.c \ ofproto/ofproto-dpif-ipfix.h \ ofproto/ofproto-dpif-mirror.c \
ofproto/ofproto-dpif-bpf.c new file +454 -0
454 lines not on this page · raw message
ofproto/ofproto-dpif-bpf.h new file +42 -0
42 lines not on this page · raw message
vswitchd/automake.mk +5 -0
@@ -19,6 +19,11 @@ vswitchd_ovs_vswitchd_LDFLAGS = $(AM_LDFLAGS) $(DPDK_vswitchd_LDFLAGS) EXTRA_DIST += vswitchd/INTERNALS MAN_ROOTS += vswitchd/ovs-vswitchd.8.in +if LINUX +vswitchd_ovs_vswitchd_LDADD += lib/libbpf.la +vswitchd_ovs_vswitchd_LDADD += -lelf +endif + # vswitch schema and IDL EXTRA_DIST += vswitchd/vswitch.ovsschema pkgdata_DATA += vswitchd/vswitch.ovsschema
Signature · 1 line
1.9.1
Re: [RFC: add openvswitch actions using BPF 7/9] ofproto-dpif: Add eBPF program loader and runtime infrasturcure.
Quoted 5 lines · Andy Zhou
Added a eBPF program loader in ofproto-dpif layer. It only loades the OVS programs.
Signed-off-by Andy Zhou <[email protected]>---
A little more precise: It only loads BPF programs with sections that begin with the 'ovs' prefix.
There's a few scattered OVS style things like using ovs_scan(), removing commented lines.
ofproto/ofproto-dpif-bpf.c line 64
Quoted 2 lines
ofproto/ofproto-dpif-bpf.c new file +2
-0+#define BPF_UNIXCTL_CHECK (conn) \ + if (bpf_unixctl_check_enable(conn) == -1) return
It seems unusual for OVS code to skimp on some "if(foo()) return" logic by using a macro.
ofproto/ofproto-dpif-bpf.c line 77
Quoted 2 lines
ofproto/ofproto-dpif-bpf.c new file +2
-0+static int +bpf_unixctl_check_enable (struct unixctl_conn *conn)
Another minor style thing here, I think "check_enable" is ambiguous. It's actually checking for datapath support for the feature. (I realise there are other places in OVS that we do this, and I've been meaning to clean them up).
vswitchd/automake.mk vswitchd_ovs_vswitchd_LDFLAGS = $(AM_LDFLAGS) $(DPDK_vswitchd_LDFLAGS) · line 26
Quoted 13 lines
vswitchd/automake.mk +5
-0@@ -19,6 +19,11 @@ vswitchd_ovs_vswitchd_LDFLAGS = $(AM_LDFLAGS) $(DPDK_vswitchd_LDFLAGS) EXTRA_DIST += vswitchd/INTERNALS MAN_ROOTS += vswitchd/ovs-vswitchd.8.in +if LINUX +vswitchd_ovs_vswitchd_LDADD += lib/libbpf.la +vswitchd_ovs_vswitchd_LDADD += -lelf +endif +
Do we perform a check for the libelf dev headers and library anywhere in the build process?
RFC 8/9 ofproto-dpif: Add datapath eBPF support detection
In reply to Andy ZhouFirst cut in added datpath eBPF support detector. This feature has not been fully developed. The stub implementation simply assumes the datpath support eBPF.
----
Current interface only support 'yes' or 'no' detection. Should we consider 'support level'?
--- ofproto/ofproto-dpif.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
ofproto/ofproto-dpif.c +21 -0
@@ -58,6 +58,7 @@#include "ofproto-dpif-sflow.h" #include "ofproto-dpif-upcall.h" #include "ofproto-dpif-xlate.h" +#include "ofproto-dpif-bpf.h" #include "poll-loop.h" #include "ovs-rcu.h" #include "ovs-router.h"
@@ -293,6 +294,9 @@ struct dpif_backer {* actions. */ bool masked_set_action; +/* True if the datapath supports bpf actions */ +bool enable_bpf_action; +/* Maximum number of MPLS label stack entries that the datapath supports * in a match */ size_t max_mpls_depth;
@@ -909,6 +913,7 @@ static bool check_variable_length_userdata(struct dpif_backer *backer);static size_t check_max_mpls_depth (struct dpif_backer *backer);static bool check_recirc (struct dpif_backer *backer);static bool check_ufid (struct dpif_backer *backer); +static bool check_bpf_actions (struct dpif_backer *backer);static bool check_masked_set_action (struct dpif_backer *backer); static int
@@ -1007,6 +1012,7 @@ open_dpif_backer(const char *type, struct dpif_backer **backerp) backer->max_mpls_depth =check_max_mpls_depth (backer); backer->masked_set_action =check_masked_set_action (backer); backer->enable_ufid =check_ufid (backer); + backer->enable_bpf_action =check_bpf_actions (backer); backer->rid_pool =recirc_id_pool_create ();ovs_mutex_init (&backer->recirc_mutex);cmap_init (&backer->recirc_map);
@@ -1032,6 +1038,9 @@ open_dpif_backer(const char *type, struct dpif_backer **backerp) backer->variable_length_userdata =check_variable_length_userdata (backer); backer->dp_version_string =dpif_get_dp_version (backer->dpif); +/* Load eBPF actions if datapath supports it. */ + error =ofproto_dpif_bpf_init (backer->enable_bpf_action); +return error; }
@@ -1110,7 +1119,19 @@ check_ufid(struct dpif_backer *backer)return enable_ufid; } +/* Tests whether 'dpif' supports eBPF base flow actions. +* +* Returns true if 'dpif' supports eBPF based actions. +*/ +static bool +check_bpf_actions( struct dpif_backer *backer OVS_UNUSED) +{ +/* XXX */ +return true; +} +/* Tests whether 'backer''s datapath supports variable-length +* * OVS_USERSPACE_ATTR_USERDATA in OVS_ACTION_ATTR_USERSPACE actions. We need * to disable some features on older datapaths that don't support this * feature.
Signature · 1 line
1.9.1
RFC 9/9 ofproto-dpif-xlate: generate BPF output action (Hack)
In reply to Andy ZhouThis is a hack in xlate code to always generate both BPF output and the original output action. Since the currnet BPF output 'action' simply generate a kenrel log message about the output port number.
With this patch, Every time datapath output a packet, it also generate log about the port number in the kernel log.
--- ofproto/ofproto-dpif-xlate.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
ofproto/ofproto-dpif-xlate.c +16 -2
@@ -15,6 +15,7 @@#include <config.h> #include "ofproto/ofproto-dpif-xlate.h" +#include "ofproto/ofproto-dpif-bpf.h" #include <errno.h> #include <arpa/inet.h>
@@ -2833,14 +2834,27 @@ compose_output_action__(struct xlate_ctx *ctx, ofp_port_t ofp_port,OVS_ACTION_ATTR_TUNNEL_POP , odp_tnl_port); }else { +int fd; +struct ovs_action_bpf_prog bpf_output; + + fd =ofproto_dpif_bpf_lookup ("ovs/output" ); + +if (fd >0 ) { + bpf_output.prog_fd =htonl (fd); + bpf_output.arg0 =htonl (out_port); + bpf_output.arg1 =htonl (0 ); +nl_msg_push_unspec (ctx->xout->odp_actions, +OVS_ACTION_ATTR_BPF_PROG , + &bpf_output,sizeof (bpf_output)); + }/* Tunnel push-pop action is not compatible with * IPFIX action. */ add_ipfix_output_action (ctx, out_port);nl_msg_put_odp_port (ctx->xout->odp_actions,OVS_ACTION_ATTR_OUTPUT , out_port); - } - } + } + } } ctx->sflow_odp_port = odp_port;
Signature · 1 line
1.9.1
Re: [ovs-dev] [RFC: add openvswitch actions using BPF 9/9] ofproto-dpif-xlate: generate BPF output action (Hack)
Quoted 6 lines · Andy Zhou
This is a hack in xlate code to always generate both BPF output and the original output action. Since the currnet BPF output 'action' simply generate a kenrel log message about the output port number.
With this patch, Every time datapath output a packet, it also generate log about the port number in the kernel log.
This sounds great. Having the possibility the overwrite existing datapath actions with BPF programs sounds like an excellent first step towards BPF usage in the datapath.