From: "Björn Töpel" <bjorn.topel@gmail.com>
To: netdev@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net
Cc: "Björn Töpel" <bjorn.topel@intel.com>,
bpf@vger.kernel.org, magnus.karlsson@gmail.com,
magnus.karlsson@intel.com, jonathan.lemon@gmail.com
Subject: [RFC PATCH bpf-next 3/4] xdp: introduce xdp_call
Date: Wed, 13 Nov 2019 21:47:36 +0100 [thread overview]
Message-ID: <20191113204737.31623-4-bjorn.topel@gmail.com> (raw)
In-Reply-To: <20191113204737.31623-1-bjorn.topel@gmail.com>
From: Björn Töpel <bjorn.topel@intel.com>
The xdp_call.h header wraps a more user-friendly API around the BPF
dispatcher. A user adds a trampoline/XDP caller using the
DEFINE_XDP_CALL macro, and updates the BPF dispatcher via
xdp_call_update(). The actual dispatch is done via xdp_call().
The next commit will show-case how the i40e uses xdp_call.
When static_call, especially the inlined version, is upstreamed it
will be used by xdp_call.h.
Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
---
include/linux/xdp_call.h | 49 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
create mode 100644 include/linux/xdp_call.h
diff --git a/include/linux/xdp_call.h b/include/linux/xdp_call.h
new file mode 100644
index 000000000000..e736a4d3c961
--- /dev/null
+++ b/include/linux/xdp_call.h
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2019 Intel Corporation. */
+#ifndef _LINUX_XDP_CALL_H
+#define _LINUX_XDP_CALL_H
+
+#include <linux/filter.h>
+
+#if defined(CONFIG_BPF_JIT) && defined(CONFIG_RETPOLINE)
+
+void bpf_dispatcher_change_prog(void *func, struct bpf_prog *from,
+ struct bpf_prog *to);
+
+#define XDP_CALL_TRAMP(name) ____xdp_call_##name##_tramp
+
+#define DEFINE_XDP_CALL(name) \
+ unsigned int XDP_CALL_TRAMP(name)( \
+ const void *xdp_ctx, \
+ const struct bpf_insn *insnsi, \
+ unsigned int (*bpf_func)(const void *, \
+ const struct bpf_insn *)) \
+ { \
+ return bpf_func(xdp_ctx, insnsi); \
+ }
+
+#define DECLARE_XDP_CALL(name) \
+ unsigned int XDP_CALL_TRAMP(name)( \
+ const void *xdp_ctx, \
+ const struct bpf_insn *insnsi, \
+ unsigned int (*bpf_func)(const void *, \
+ const struct bpf_insn *))
+
+#define xdp_call_run(name, xdp_prog, xdp) \
+ XDP_CALL_TRAMP(name)(xdp, xdp_prog->insnsi, \
+ xdp_prog->bpf_func)
+
+#define xdp_call_update(name, from_xdp_prog, to_xdp_prog) \
+ bpf_dispatcher_change_prog(&XDP_CALL_TRAMP(name), \
+ from_xdp_prog, \
+ to_xdp_prog)
+
+#else /* !defined(CONFIG_BPF_JIT) || !defined(CONFIG_RETPOLINE) */
+
+#define DEFINE_XDP_CALL(name)
+#define DECLARE_XDP_CALL(name)
+#define xdp_call_run(name, xdp_prog, xdp) bpf_prog_run_xdp(xdp_prog, xdp)
+#define xdp_call_update(name, from_xdp_prog, to_xdp_prog)
+
+#endif /* defined(CONFIG_BPF_JIT) && defined(CONFIG_RETPOLINE) */
+#endif /* _LINUX_XDP_CALL_H */
--
2.20.1
next prev parent reply other threads:[~2019-11-13 20:48 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-13 20:47 [RFC PATCH bpf-next 0/4] Introduce xdp_call.h and the BPF dispatcher Björn Töpel
2019-11-13 20:47 ` [RFC PATCH bpf-next 1/4] bpf: teach bpf_arch_text_poke() jumps Björn Töpel
2019-11-13 20:47 ` [RFC PATCH bpf-next 2/4] bpf: introduce BPF dispatcher Björn Töpel
2019-11-13 21:40 ` Edward Cree
2019-11-14 6:29 ` Björn Töpel
2019-11-14 10:18 ` Edward Cree
2019-11-14 11:21 ` Björn Töpel
2019-11-14 13:58 ` Peter Zijlstra
2019-11-14 12:31 ` Toke Høiland-Jørgensen
2019-11-14 13:03 ` Daniel Borkmann
2019-11-14 13:09 ` Toke Høiland-Jørgensen
2019-11-14 13:56 ` Björn Töpel
2019-11-14 14:55 ` Toke Høiland-Jørgensen
2019-11-14 15:03 ` Björn Töpel
2019-11-14 15:12 ` Toke Høiland-Jørgensen
2019-11-15 0:30 ` Alexei Starovoitov
2019-11-15 7:56 ` Björn Töpel
2019-11-15 21:58 ` Alexei Starovoitov
2019-11-18 10:03 ` Björn Töpel
2019-11-18 19:36 ` Andrii Nakryiko
2019-11-18 20:11 ` Björn Töpel
2019-11-13 20:47 ` Björn Töpel [this message]
2019-11-13 20:47 ` [RFC PATCH bpf-next 4/4] i40e: start using xdp_call.h Björn Töpel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191113204737.31623-4-bjorn.topel@gmail.com \
--to=bjorn.topel@gmail.com \
--cc=ast@kernel.org \
--cc=bjorn.topel@intel.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jonathan.lemon@gmail.com \
--cc=magnus.karlsson@gmail.com \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).