From: He Kuang <hekuang@huawei.com>
To: <acme@kernel.org>, <peterz@infradead.org>, <mingo@redhat.com>,
<jolsa@redhat.com>, <brendan.d.gregg@gmail.com>, <ast@kernel.org>,
<alexander.shishkin@linux.intel.com>, <wangnan0@huawei.com>,
<hekuang@huawei.com>
Cc: <linux-kernel@vger.kernel.org>
Subject: [RFC PATCH v2 09/26] perf bpf: Implement empty instruction handler and build bpf-vm
Date: Sun, 26 Jun 2016 11:21:01 +0000 [thread overview]
Message-ID: <1466940078-65581-10-git-send-email-hekuang@huawei.com> (raw)
In-Reply-To: <1466940078-65581-1-git-send-email-hekuang@huawei.com>
This patch includes the existing code in "kernel/bpf/vm.c", and uses
empty handlers for building the userspace version of bpf-vm
code. Userspace bpf programs won't deal with 'struct skb' data so an
empty bpf_load_pointer() is placed here to help save us from including
too much kernel structures and headers.
CFLAGS are modified for supressing warnings of the existing bpf code.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Signed-off-by: He Kuang <hekuang@huawei.com>
---
tools/perf/util/Build | 2 ++
tools/perf/util/bpf-vm.c | 34 ++++++++++++++++++++++++++++++++++
tools/perf/util/bpf-vm.h | 7 +++++++
3 files changed, 43 insertions(+)
create mode 100644 tools/perf/util/bpf-vm.c
create mode 100644 tools/perf/util/bpf-vm.h
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index fced833..1d24d94 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -90,6 +90,7 @@ libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
libperf-$(CONFIG_LIBELF) += symbol-elf.o
libperf-$(CONFIG_LIBELF) += probe-file.o
libperf-$(CONFIG_LIBELF) += probe-event.o
+libperf-$(CONFIG_UBPF) += bpf-vm.o
ifndef CONFIG_LIBELF
libperf-y += symbol-minimal.o
@@ -152,6 +153,7 @@ CFLAGS_rbtree.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ET
CFLAGS_libstring.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
CFLAGS_hweight.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
CFLAGS_parse-events.o += -Wno-redundant-decls
+CFLAGS_bpf-vm.o += -Wno-override-init -Wno-switch-default -Wno-sign-compare
$(OUTPUT)util/kallsyms.o: ../lib/symbol/kallsyms.c FORCE
$(call rule_mkdir)
diff --git a/tools/perf/util/bpf-vm.c b/tools/perf/util/bpf-vm.c
new file mode 100644
index 0000000..23ac784
--- /dev/null
+++ b/tools/perf/util/bpf-vm.c
@@ -0,0 +1,34 @@
+#include <linux/atomic.h>
+#include "util.h"
+#include "tools/be_byteshift.h"
+#include "bpf-vm.h"
+
+static inline void
+bpf_vm_jmp_call_handler(u64 *regs __maybe_unused, void *ctx __maybe_unused,
+ const struct bpf_insn *insn __maybe_unused) {}
+
+static inline int
+bpf_vm_jmp_tail_call_handler(u64 *regs __maybe_unused,
+ u32 *p_tail_call_cnt __maybe_unused,
+ const struct bpf_insn **p_insn __maybe_unused) {
+ return 0;
+}
+
+static inline void
+bpf_vm_default_label_handler(void *ctx __maybe_unused,
+ const struct bpf_insn *insn __maybe_unused) {}
+
+/* instructions for dealing with socket data use this function,
+ * userspace bpf don't use it now so leave it blank here, which saves
+ * us from including too much kernel structures.
+ */
+static inline void *bpf_load_pointer(const void *skb __maybe_unused,
+ int k __maybe_unused,
+ unsigned int size __maybe_unused,
+ void *buffer __maybe_unused)
+{
+ return NULL;
+}
+
+#define UBPF_BUILD
+#include <../../../kernel/bpf/vm.c>
diff --git a/tools/perf/util/bpf-vm.h b/tools/perf/util/bpf-vm.h
new file mode 100644
index 0000000..bf96caa
--- /dev/null
+++ b/tools/perf/util/bpf-vm.h
@@ -0,0 +1,7 @@
+#ifndef _BPF_VM_H
+#define _BPF_VM_H
+
+struct bpf_insn;
+unsigned int __bpf_prog_run(void *ctx, const struct bpf_insn *insn);
+
+#endif /* _BPF_VM_H */
--
1.8.5.2
next prev parent reply other threads:[~2016-06-26 11:22 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-26 11:20 [RFC PATCH v2 00/26] perf tools: Support uBPF script He Kuang
2016-06-26 11:20 ` [RFC PATCH v2 01/26] tools include: Adopt byte ordering macros from byteorder/generic.h He Kuang
2016-06-26 11:20 ` [RFC PATCH v2 02/26] tools include: Fix wrong macro definitions for cpu_to_le* for big endian He Kuang
2016-06-26 11:20 ` [RFC PATCH v2 03/26] bpf: split __bpf_prog_run code into new file He Kuang
2016-06-26 11:20 ` [RFC PATCH v2 04/26] bpf: extract jmp and default handler and introduce UBPF_BUILD flag He Kuang
2016-06-26 11:20 ` [RFC PATCH v2 05/26] tools include: Sync math64.h and div64.h He Kuang
2016-06-26 21:08 ` Nilay Vaish
2016-06-27 2:21 ` Hekuang
2016-06-27 18:13 ` Arnaldo Carvalho de Melo
2016-06-26 11:20 ` [RFC PATCH v2 06/26] tools include: Add (atomic|atomic64)_add implementation from the kernel sources He Kuang
2016-06-26 11:20 ` [RFC PATCH v2 07/26] perf bpf: Add map related BPF helper He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 08/26] perf bpf: Add UBPF flags and makefile options He Kuang
2016-06-26 11:21 ` He Kuang [this message]
2016-06-26 11:21 ` [RFC PATCH v2 10/26] perf bpf: Remove unused code in libbpf He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 11/26] perf bpf: Store arbitrary entries instread fd array in bpf_program He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 12/26] perf bpf: Add libbpf-internal.h header file He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 13/26] perf bpf: Add abstraction for bpf program methods He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 14/26] perf bpf: Add -Wextra to cflags for more warnings and fix them He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 15/26] perf bpf: Introduce the entity and engine for userspace bpf He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 16/26] perf bpf: Add method for fetching nth ubpf vm He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 17/26] perf bpf: Add methods to set/check ubpf engine for bpf programs He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 18/26] perf bpf: Add ubpf helper function slots and set/get methods He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 19/26] perf tools: Register basic uBPF helpers He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 20/26] perf bpf: Accept uBPF programs He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 21/26] bpf: Support bpf load/store boundary check for ubpf He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 22/26] perf bpf: Implement boundary check code in ubpf He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 23/26] perf record: Add uBPF hooks at beginning and end of perf record He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 24/26] perf bpf: Fillup bpf jmp_call handler He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 25/26] perf bpf: Implement run_ubpf_program He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 26/26] perf tests: Add uBPF test case He Kuang
2016-06-26 20:48 ` [RFC PATCH v2 00/26] perf tools: Support uBPF script Alexei Starovoitov
2016-06-27 2:10 ` Hekuang
2016-06-28 11:47 ` Hekuang
2016-06-28 14:57 ` Alexei Starovoitov
2016-06-29 10:15 ` Hekuang
2016-06-29 10:35 ` Wangnan (F)
2016-06-29 12:37 ` Alexei Starovoitov
2016-06-29 13:03 ` pi3orama
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=1466940078-65581-10-git-send-email-hekuang@huawei.com \
--to=hekuang@huawei.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=ast@kernel.org \
--cc=brendan.d.gregg@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=wangnan0@huawei.com \
/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
all inboxes | Powered by JetHome®