From: Kenny Ho <Kenny.Ho@amd.com>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>, Tejun Heo <tj@kernel.org>,
Zefan Li <lizefan.x@bytedance.com>,
"Johannes Weiner" <hannes@cmpxchg.org>,
Peter Zijlstra <peterz@infradead.org>,
"Ingo Molnar" <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
"Mark Rutland" <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@redhat.com>,
"Namhyung Kim" <namhyung@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>, <netdev@vger.kernel.org>,
<bpf@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<cgroups@vger.kernel.org>, <linux-perf-users@vger.kernel.org>,
<y2kenny@gmail.com>, <Kenny.Ho@amd.com>,
<amd-gfx@lists.freedesktop.org>
Subject: [PATCH RFC 2/4] bpf, perf: add ability to attach complete array of bpf prog to perf event
Date: Thu, 18 Nov 2021 15:28:38 -0500 [thread overview]
Message-ID: <20211118202840.1001787-3-Kenny.Ho@amd.com> (raw)
In-Reply-To: <20211118202840.1001787-1-Kenny.Ho@amd.com>
Change-Id: Ie2580c3a71e2a5116551879358cb5304b04d3838
Signed-off-by: Kenny Ho <Kenny.Ho@amd.com>
---
include/linux/trace_events.h | 9 +++++++++
kernel/trace/bpf_trace.c | 28 ++++++++++++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index 3e475eeb5a99..5cfe3d08966c 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -725,6 +725,8 @@ trace_trigger_soft_disabled(struct trace_event_file *file)
#ifdef CONFIG_BPF_EVENTS
unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx);
+int perf_event_attach_bpf_prog_array(struct perf_event *event,
+ struct bpf_prog_array *new_array);
int perf_event_attach_bpf_prog(struct perf_event *event, struct bpf_prog *prog, u64 bpf_cookie);
void perf_event_detach_bpf_prog(struct perf_event *event);
int perf_event_query_prog_array(struct perf_event *event, void __user *info);
@@ -741,6 +743,13 @@ static inline unsigned int trace_call_bpf(struct trace_event_call *call, void *c
return 1;
}
+static inline int
+int perf_event_attach_bpf_prog_array(struct perf_event *event,
+ struct bpf_prog_array *new_array)
+{
+ return -EOPNOTSUPP;
+}
+
static inline int
perf_event_attach_bpf_prog(struct perf_event *event, struct bpf_prog *prog, u64 bpf_cookie)
{
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 6b3153841a33..8addd10202c2 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -1802,6 +1802,34 @@ static DEFINE_MUTEX(bpf_event_mutex);
#define BPF_TRACE_MAX_PROGS 64
+int perf_event_attach_bpf_prog_array(struct perf_event *event,
+ struct bpf_prog_array *new_array)
+{
+ struct bpf_prog_array_item *item;
+ struct bpf_prog_array *old_array;
+
+ if (!new_array)
+ return -EINVAL;
+
+ if (bpf_prog_array_length(new_array) >= BPF_TRACE_MAX_PROGS)
+ return -E2BIG;
+
+ if (!trace_kprobe_on_func_entry(event->tp_event) ||
+ !trace_kprobe_error_injectable(event->tp_event))
+ for (item = new_array->items; item->prog; item++)
+ if (item->prog->kprobe_override)
+ return -EINVAL;
+
+ mutex_lock(&bpf_event_mutex);
+
+ old_array = bpf_event_rcu_dereference(event->tp_event->prog_array);
+ rcu_assign_pointer(event->tp_event->prog_array, new_array);
+ bpf_prog_array_free(old_array);
+
+ mutex_unlock(&bpf_event_mutex);
+ return 0;
+}
+
int perf_event_attach_bpf_prog(struct perf_event *event,
struct bpf_prog *prog,
u64 bpf_cookie)
--
2.25.1
next prev parent reply other threads:[~2021-11-18 20:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-18 20:28 [PATCH RFC 0/4] Add ability to attach bpf programs to a tracepoint inside a cgroup Kenny Ho
2021-11-18 20:28 ` [PATCH RFC 1/4] cgroup, perf: Add ability to connect to perf cgroup from other cgroup controller Kenny Ho
2021-11-18 20:28 ` Kenny Ho [this message]
2021-11-18 20:28 ` [PATCH RFC 3/4] bpf,cgroup,tracing: add new BPF_PROG_TYPE_CGROUP_TRACEPOINT Kenny Ho
2021-11-18 20:28 ` [PATCH RFC 4/4] bpf,cgroup,perf: extend bpf-cgroup to support tracepoint attachment Kenny Ho
2021-11-19 4:33 ` Alexei Starovoitov
2021-11-19 6:01 ` Kenny Ho
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=20211118202840.1001787-3-Kenny.Ho@amd.com \
--to=kenny.ho@amd.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=hannes@cmpxchg.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@redhat.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=lizefan.x@bytedance.com \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=songliubraving@fb.com \
--cc=tj@kernel.org \
--cc=y2kenny@gmail.com \
--cc=yhs@fb.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