Thread (20 messages) read the whole thread 20 messages, 2 authors, 2020-09-15

Re: [PATCH RESEND bpf-next v3 7/9] libbpf: add support for supplying target to bpf_raw_tracepoint_open()

From: Andrii Nakryiko <hidden>
Date: 2020-09-11 21:21:23
Also in: bpf

On Fri, Sep 11, 2020 at 3:00 AM Toke Høiland-Jørgensen [off-list ref] wrote:
quoted hunk ↗ jump to hunk
From: Toke Høiland-Jørgensen <redacted>

This adds support for supplying a target fd and btf ID for the
raw_tracepoint_open() BPF operation, using a new bpf_raw_tracepoint_opts
structure. This can be used for attaching freplace programs to multiple
destinations.

Signed-off-by: Toke Høiland-Jørgensen <redacted>
---
 tools/lib/bpf/bpf.c      |   13 ++++++++++++-
 tools/lib/bpf/bpf.h      |    9 +++++++++
 tools/lib/bpf/libbpf.map |    1 +
 3 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 82b983ff6569..25c62993c406 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -804,17 +804,28 @@ int bpf_obj_get_info_by_fd(int bpf_fd, void *info, __u32 *info_len)
        return err;
 }

-int bpf_raw_tracepoint_open(const char *name, int prog_fd)
+int bpf_raw_tracepoint_open_opts(const char *name, int prog_fd,
We've had discussion around naming low-level APIs with options and
agreed with Andrey Ignatov that we'll follow the _xattr suffix naming
for low-level APIs. So let's keep it consistent, I suppose...

Please also add bpf_program__attach_trace_opts() for high-level API.
+                                struct bpf_raw_tracepoint_opts *opts)
 {
        union bpf_attr attr;

+       if (!OPTS_VALID(opts, bpf_raw_tracepoint_opts))
+               return -EINVAL;
+
        memset(&attr, 0, sizeof(attr));
        attr.raw_tracepoint.name = ptr_to_u64(name);
        attr.raw_tracepoint.prog_fd = prog_fd;
+       attr.raw_tracepoint.tgt_prog_fd = OPTS_GET(opts, tgt_prog_fd, 0);
+       attr.raw_tracepoint.tgt_btf_id = OPTS_GET(opts, tgt_btf_id, 0);

        return sys_bpf(BPF_RAW_TRACEPOINT_OPEN, &attr, sizeof(attr));
 }
[...]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help