From: yupeng0921@gmail.com
To: linux-kernel@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, rostedt@goodmis.org,
mingo@redhat.com, yupeng0921@gmail.com
Subject: [ftrace-bpf 3/5] add bpf prog filter for graph trace
Date: Sun, 12 Nov 2017 07:28:26 +0000 [thread overview]
Message-ID: <1510471708-12729-3-git-send-email-yupeng0921@gmail.com> (raw)
In-Reply-To: <1510471708-12729-1-git-send-email-yupeng0921@gmail.com>
When set a bpf prog through set_bpf_filter, graph trace will check
whether it should trace the function depend on the bpf prog return
value. It passes the parameters of the function to bpf prog, let bpf
prog determine whether this function should be traced. It only makes
sense if the user set only one function in set_graph_function, because
bpf prog is hard to distinguish different functions.
Signed-off-by: yupeng0921@gmail.com
---
kernel/trace/trace_functions_graph.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
index 23c0b0c..5894439b2 100644
--- a/kernel/trace/trace_functions_graph.c
+++ b/kernel/trace/trace_functions_graph.c
@@ -372,6 +372,24 @@ static inline int ftrace_graph_ignore_irqs(void)
return in_irq();
}
+#ifdef FTRACE_BPF_FILTER
+static inline int ftrace_graph_bpf_filter(
+ struct trace_array *tr, struct ftrace_graph_ent *trace)
+{
+ struct bpf_prog *prog;
+ int ret = 1;
+
+ if (!ftrace_graph_addr(trace->func))
+ return ret;
+ rcu_read_lock();
+ prog = rcu_dereference(tr->prog);
+ if (prog)
+ ret = trace_call_bpf(prog, trace->ctx);
+ rcu_read_unlock();
+ return ret;
+}
+#endif
+
int trace_graph_entry(struct ftrace_graph_ent *trace)
{
struct trace_array *tr = graph_array;
@@ -391,6 +409,11 @@ int trace_graph_entry(struct ftrace_graph_ent *trace)
if (ftrace_graph_ignore_irqs())
return 0;
+#ifdef FTRACE_BPF_FILTER
+ if (!ftrace_graph_bpf_filter(tr, trace))
+ return 0;
+#endif
+
/*
* Do not trace a function if it's filtered by set_graph_notrace.
* Make the index of ret stack negative to indicate that it should
--
2.7.4
next prev parent reply other threads:[~2017-11-12 7:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-12 7:28 [ftrace-bpf 1/5] add BPF_PROG_TYPE_FTRACE to bpf yupeng0921
2017-11-12 7:28 ` [ftrace-bpf 2/5] add bpf prog interface for ftrace yupeng0921
2017-11-12 7:28 ` yupeng0921 [this message]
2017-11-12 7:28 ` [ftrace-bpf 4/5] enable bpf filter for graph trace in x86-64 arch yupeng0921
2017-11-12 7:28 ` [ftrace-bpf 5/5] add BPF_PROG_TYPE_FTRACE support for samples/bpf yupeng0921
2017-11-13 1:02 ` [ftrace-bpf 1/5] add BPF_PROG_TYPE_FTRACE to bpf Alexei Starovoitov
2017-11-13 8:06 ` peng yu
2017-11-17 23:48 ` Alexei Starovoitov
2017-11-14 17:47 ` kbuild test robot
2017-11-14 21:01 ` kbuild test robot
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=1510471708-12729-3-git-send-email-yupeng0921@gmail.com \
--to=yupeng0921@gmail.com \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.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
all inboxes | Powered by JetHome®