From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752794AbcFZLYw (ORCPT ); Sun, 26 Jun 2016 07:24:52 -0400 Received: from szxga04-in.huawei.com ([58.251.152.52]:21852 "EHLO szxga04-in.huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752509AbcFZLWL (ORCPT ); Sun, 26 Jun 2016 07:22:11 -0400 From: He Kuang To: , , , , , , , , CC: Subject: [RFC PATCH v2 24/26] perf bpf: Fillup bpf jmp_call handler Date: Sun, 26 Jun 2016 11:21:16 +0000 Message-ID: <1466940078-65581-25-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.0A090204.576FBAD6.0084,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: 9ffbab72bbd1ed418deddee76e03cf5b Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Let ubpf invoke function calls. The function index is stored in insns->imm, use it to fetch the corresponding functions in libbpf and make the function call. Signed-off-by: He Kuang --- tools/perf/util/bpf-vm.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/bpf-vm.c b/tools/perf/util/bpf-vm.c index 191ed42..bbe58be 100644 --- a/tools/perf/util/bpf-vm.c +++ b/tools/perf/util/bpf-vm.c @@ -4,13 +4,33 @@ #include "bpf-vm.h" #include "debug.h" #include +#include "bpf/libbpf.h" +#include + +#define BPF_R0 regs[BPF_REG_0] +#define BPF_R1 regs[BPF_REG_1] +#define BPF_R2 regs[BPF_REG_2] +#define BPF_R3 regs[BPF_REG_3] +#define BPF_R4 regs[BPF_REG_4] +#define BPF_R5 regs[BPF_REG_5] #define DST regs[insn->dst_reg] #define SRC regs[insn->src_reg] static inline void -bpf_vm_jmp_call_handler(u64 *regs __maybe_unused, void *ctx __maybe_unused, - const struct bpf_insn *insn __maybe_unused) {} +bpf_vm_jmp_call_handler(u64 *regs, void *ctx __maybe_unused, + const struct bpf_insn *insn) +{ + const void *xfunc; + u64 (*func)(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5); + + xfunc = libbpf_get_ubpf_func(insn->imm); + if (xfunc) { + func = xfunc; + BPF_R0 = func(BPF_R1, BPF_R2, BPF_R3, + BPF_R4, BPF_R5); + } +} static inline int bpf_vm_jmp_tail_call_handler(u64 *regs __maybe_unused, -- 1.8.5.2