From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752487AbcFZLWI (ORCPT ); Sun, 26 Jun 2016 07:22:08 -0400 Received: from szxga04-in.huawei.com ([58.251.152.52]:21228 "EHLO szxga04-in.huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752438AbcFZLWF (ORCPT ); Sun, 26 Jun 2016 07:22:05 -0400 From: He Kuang To: , , , , , , , , CC: 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 Message-ID: <1466940078-65581-10-git-send-email-hekuang@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1466940078-65581-1-git-send-email-hekuang@huawei.com> References: <1466940078-65581-1-git-send-email-hekuang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.193.250] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090206.576FBACF.002E,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 629b632bf240bd986f5adec8f0c03786 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: He Kuang --- 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 +#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