* [PATCH net-next] bpf: introduce bpf_get_current_task() helper
@ 2016-07-07 5:38 Alexei Starovoitov
2016-07-09 4:00 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Alexei Starovoitov @ 2016-07-07 5:38 UTC (permalink / raw)
To: David S . Miller; +Cc: Daniel Borkmann, Brendan Gregg, netdev, kernel-team
over time there were multiple requests to access different data
structures and fields of task_struct current, so finally add
the helper to access 'current' as-is. Tracing bpf programs will do
the rest of walking the pointers via bpf_probe_read().
Note that current can be null and bpf program has to deal it with,
but even dumb passing null into bpf_probe_read() is still safe.
Suggested-by: Brendan Gregg <brendan.d.gregg@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
---
requests for different helpers that can be addressed by walking 'current':
https://github.com/iovisor/bcc/issues/220
https://github.com/iovisor/bcc/issues/237
https://github.com/iovisor/bcc/issues/364
---
include/uapi/linux/bpf.h | 7 +++++++
kernel/trace/bpf_trace.c | 13 +++++++++++++
2 files changed, 20 insertions(+)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index c14ca1cd6297..262a7e883b19 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -357,6 +357,13 @@ enum bpf_func_id {
*/
BPF_FUNC_get_hash_recalc,
+ /**
+ * u64 bpf_get_current_task(void)
+ * Returns current task_struct
+ * Return: current
+ */
+ BPF_FUNC_get_current_task,
+
__BPF_FUNC_MAX_ID,
};
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 19c5b4a5c3eb..094c716154ed 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -312,6 +312,17 @@ const struct bpf_func_proto *bpf_get_event_output_proto(void)
return &bpf_event_output_proto;
}
+static u64 bpf_get_current_task(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
+{
+ return (long) current;
+}
+
+static const struct bpf_func_proto bpf_get_current_task_proto = {
+ .func = bpf_get_current_task,
+ .gpl_only = true,
+ .ret_type = RET_INTEGER,
+};
+
static const struct bpf_func_proto *tracing_func_proto(enum bpf_func_id func_id)
{
switch (func_id) {
@@ -329,6 +340,8 @@ static const struct bpf_func_proto *tracing_func_proto(enum bpf_func_id func_id)
return &bpf_tail_call_proto;
case BPF_FUNC_get_current_pid_tgid:
return &bpf_get_current_pid_tgid_proto;
+ case BPF_FUNC_get_current_task:
+ return &bpf_get_current_task_proto;
case BPF_FUNC_get_current_uid_gid:
return &bpf_get_current_uid_gid_proto;
case BPF_FUNC_get_current_comm:
--
2.8.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] bpf: introduce bpf_get_current_task() helper
2016-07-07 5:38 [PATCH net-next] bpf: introduce bpf_get_current_task() helper Alexei Starovoitov
@ 2016-07-09 4:00 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2016-07-09 4:00 UTC (permalink / raw)
To: ast; +Cc: daniel, brendan.d.gregg, netdev, kernel-team
From: Alexei Starovoitov <ast@fb.com>
Date: Wed, 6 Jul 2016 22:38:36 -0700
> over time there were multiple requests to access different data
> structures and fields of task_struct current, so finally add
> the helper to access 'current' as-is. Tracing bpf programs will do
> the rest of walking the pointers via bpf_probe_read().
> Note that current can be null and bpf program has to deal it with,
> but even dumb passing null into bpf_probe_read() is still safe.
>
> Suggested-by: Brendan Gregg <brendan.d.gregg@gmail.com>
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Applied.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-07-09 4:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-07 5:38 [PATCH net-next] bpf: introduce bpf_get_current_task() helper Alexei Starovoitov
2016-07-09 4:00 ` David Miller
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.