From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753241AbdKLH3V (ORCPT ); Sun, 12 Nov 2017 02:29:21 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:43324 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751902AbdKLH2j (ORCPT ); Sun, 12 Nov 2017 02:28:39 -0500 X-Google-Smtp-Source: AGs4zMaaqp2JBJb1O4y8iJwgW6rrB5MskUMEO6OBf72uQD9RqOwGj8+EWQ+hRfNRov31dXVyMb29/g== 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 Message-Id: <1510471708-12729-3-git-send-email-yupeng0921@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510471708-12729-1-git-send-email-yupeng0921@gmail.com> References: <1510471708-12729-1-git-send-email-yupeng0921@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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