From: He Kuang <hekuang@huawei.com>
To: <paulus@samba.org>, <a.p.zijlstra@chello.nl>, <mingo@redhat.com>,
<acme@kernel.org>, <namhyung@kernel.org>, <jolsa@kernel.org>,
<dsahern@gmail.com>, <ast@plumgrid.com>, <daniel@iogearbox.net>,
<brendan.d.gregg@gmail.com>, <masami.hiramatsu.pt@hitachi.com>
Cc: <wangnan0@huawei.com>, <lizefan@huawei.com>,
<linux-kernel@vger.kernel.org>, <pi3orama@163.com>
Subject: [RFC PATCH 3/5] bpf: Add helper function for fetching variables at probe point
Date: Mon, 18 May 2015 05:30:45 +0000 [thread overview]
Message-ID: <1431927047-35144-4-git-send-email-hekuang@huawei.com> (raw)
In-Reply-To: <1431927047-35144-1-git-send-email-hekuang@huawei.com>
This helper function uses kernel structure trace_probe and related fetch
functions for fetching variables described in 'SEC' to bpf stack.
Signed-off-by: He Kuang <hekuang@huawei.com>
---
include/uapi/linux/bpf.h | 1 +
kernel/trace/bpf_trace.c | 38 ++++++++++++++++++++++++++++++++++++++
samples/bpf/bpf_helpers.h | 2 ++
3 files changed, 41 insertions(+)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index a9ebdf5..b1a7685 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -210,6 +210,7 @@ enum bpf_func_id {
* Return: 0 on success
*/
BPF_FUNC_l4_csum_replace,
+ BPF_FUNC_fetch_args,
__BPF_FUNC_MAX_ID,
};
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 2d56ce5..ba601da 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -12,6 +12,7 @@
#include <linux/uaccess.h>
#include <linux/ctype.h>
#include "trace.h"
+#include "trace_probe.h"
static DEFINE_PER_CPU(int, bpf_prog_active);
@@ -159,6 +160,39 @@ static const struct bpf_func_proto bpf_trace_printk_proto = {
.arg2_type = ARG_CONST_STACK_SIZE,
};
+/* Store the value of each argument */
+static void
+bpf_store_trace_args(struct pt_regs *regs, struct trace_probe *tp,
+ u8 *data)
+{
+ int i;
+
+ for (i = 0; i < tp->nr_args; i++) {
+ /* Just fetching data normally */
+ call_fetch(&tp->args[i].fetch, regs,
+ data + tp->args[i].offset);
+ }
+}
+
+static u64 bpf_fetch_args(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
+{
+ struct pt_regs *regs = (struct pt_regs *)(long)r1;
+ struct trace_probe *tp = ((struct bpf_pt_regs *)regs)->tp;
+ void *data = (void *)(long)r2;
+
+ bpf_store_trace_args(regs, tp, data);
+
+ return 0;
+}
+
+static const struct bpf_func_proto bpf_fetch_args_proto = {
+ .func = bpf_fetch_args,
+ .gpl_only = true,
+ .ret_type = RET_INTEGER,
+ .arg1_type = ARG_PTR_TO_CTX,
+ .arg2_type = ARG_PTR_TO_STACK,
+};
+
static const struct bpf_func_proto *kprobe_prog_func_proto(enum bpf_func_id func_id)
{
switch (func_id) {
@@ -181,6 +215,10 @@ static const struct bpf_func_proto *kprobe_prog_func_proto(enum bpf_func_id func
trace_printk_init_buffers();
return &bpf_trace_printk_proto;
+
+ case BPF_FUNC_fetch_args:
+ return &bpf_fetch_args_proto;
+
default:
return NULL;
}
diff --git a/samples/bpf/bpf_helpers.h b/samples/bpf/bpf_helpers.h
index f960b5f..578a8e3 100644
--- a/samples/bpf/bpf_helpers.h
+++ b/samples/bpf/bpf_helpers.h
@@ -21,6 +21,8 @@ static unsigned long long (*bpf_ktime_get_ns)(void) =
(void *) BPF_FUNC_ktime_get_ns;
static int (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) =
(void *) BPF_FUNC_trace_printk;
+static int (*bpf_fetch_args)(void *ctx, void *data) =
+ (void *) BPF_FUNC_fetch_args;
/* llvm builtin functions that eBPF C program may use to
* emit BPF_LD_ABS and BPF_LD_IND instructions
--
1.8.5.2
next prev parent reply other threads:[~2015-05-18 5:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-18 5:30 [RFC PATCH 0/5] Fetching local variables for bpf prog He Kuang
2015-05-18 5:30 ` [RFC PATCH 1/5] perf bpf: Add -k option for testing convenience He Kuang
2015-05-18 5:30 ` [RFC PATCH 2/5] bpf: Pass trace_probe to bpf_prog for variable fetching He Kuang
2015-05-18 19:43 ` Alexei Starovoitov
2015-05-18 5:30 ` He Kuang [this message]
2015-05-18 19:53 ` [RFC PATCH 3/5] bpf: Add helper function for fetching variables at probe point Alexei Starovoitov
2015-05-18 5:30 ` [RFC PATCH 4/5] samples/bpf: Add proper prefix to objects in Makefile He Kuang
2015-05-18 19:59 ` Alexei Starovoitov
2015-05-18 5:30 ` [RFC PATCH 5/5] samples/bpf: Add sample for testing bpf fetch args He Kuang
2015-05-18 23:08 ` [RFC PATCH 0/5] Fetching local variables for bpf prog Masami Hiramatsu
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=1431927047-35144-4-git-send-email-hekuang@huawei.com \
--to=hekuang@huawei.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=ast@plumgrid.com \
--cc=brendan.d.gregg@gmail.com \
--cc=daniel@iogearbox.net \
--cc=dsahern@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=paulus@samba.org \
--cc=pi3orama@163.com \
--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®