All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: davem@davemloft.net
Cc: daniel@iogearbox.net, andrii@kernel.org, bpf@vger.kernel.org,
	kernel-team@fb.com
Subject: [PATCH bpf-next 3/7] libbpf: Open code raw_tp_open and link_create commands.
Date: Mon, 31 Jan 2022 14:05:24 -0800	[thread overview]
Message-ID: <20220131220528.98088-4-alexei.starovoitov@gmail.com> (raw)
In-Reply-To: <20220131220528.98088-1-alexei.starovoitov@gmail.com>

From: Alexei Starovoitov <ast@kernel.org>

Open code raw_tracepoint_open and link_create used by light skeleton
to be able to avoid full libbpf eventually.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
 tools/bpf/bpftool/gen.c       |  6 +++---
 tools/lib/bpf/skel_internal.h | 26 ++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index 8eacfc79ec43..eacfc6a2060d 100644
--- a/tools/bpf/bpftool/gen.c
+++ b/tools/bpf/bpftool/gen.c
@@ -381,13 +381,13 @@ static void codegen_attach_detach(struct bpf_object *obj, const char *obj_name)
 		switch (bpf_program__type(prog)) {
 		case BPF_PROG_TYPE_RAW_TRACEPOINT:
 			tp_name = strchr(bpf_program__section_name(prog), '/') + 1;
-			printf("\tint fd = bpf_raw_tracepoint_open(\"%s\", prog_fd);\n", tp_name);
+			printf("\tint fd = skel_raw_tracepoint_open(\"%s\", prog_fd);\n", tp_name);
 			break;
 		case BPF_PROG_TYPE_TRACING:
 			if (bpf_program__expected_attach_type(prog) == BPF_TRACE_ITER)
-				printf("\tint fd = bpf_link_create(prog_fd, 0, BPF_TRACE_ITER, NULL);\n");
+				printf("\tint fd = skel_link_create(prog_fd, 0, BPF_TRACE_ITER);\n");
 			else
-				printf("\tint fd = bpf_raw_tracepoint_open(NULL, prog_fd);\n");
+				printf("\tint fd = skel_raw_tracepoint_open(NULL, prog_fd);\n");
 			break;
 		default:
 			printf("\tint fd = ((void)prog_fd, 0); /* auto-attach not supported */\n");
diff --git a/tools/lib/bpf/skel_internal.h b/tools/lib/bpf/skel_internal.h
index 57507f1c1934..dcd3336512d4 100644
--- a/tools/lib/bpf/skel_internal.h
+++ b/tools/lib/bpf/skel_internal.h
@@ -110,6 +110,32 @@ static inline int skel_map_update_elem(int fd, const void *key,
 	return skel_sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, attr_sz);
 }
 
+static inline int skel_raw_tracepoint_open(const char *name, int prog_fd)
+{
+	const size_t attr_sz = offsetofend(union bpf_attr, raw_tracepoint.prog_fd);
+	union bpf_attr attr;
+
+	memset(&attr, 0, attr_sz);
+	attr.raw_tracepoint.name = (long) name;
+	attr.raw_tracepoint.prog_fd = prog_fd;
+
+	return skel_sys_bpf(BPF_RAW_TRACEPOINT_OPEN, &attr, attr_sz);
+}
+
+static inline int skel_link_create(int prog_fd, int target_fd,
+				   enum bpf_attach_type attach_type)
+{
+	const size_t attr_sz = offsetofend(union bpf_attr, link_create.iter_info_len);
+	union bpf_attr attr;
+
+	memset(&attr, 0, attr_sz);
+	attr.link_create.prog_fd = prog_fd;
+	attr.link_create.target_fd = target_fd;
+	attr.link_create.attach_type = attach_type;
+
+	return skel_sys_bpf(BPF_LINK_CREATE, &attr, attr_sz);
+}
+
 static inline int bpf_load_and_run(struct bpf_load_and_run_opts *opts)
 {
 	int map_fd = -1, prog_fd = -1, key = 0, err;
-- 
2.30.2


  parent reply	other threads:[~2022-01-31 22:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-31 22:05 [PATCH bpf-next 0/7] bpf: drop libbpf from bpf preload Alexei Starovoitov
2022-01-31 22:05 ` [PATCH bpf-next 1/7] libbpf: Add support for bpf iter in light skeleton Alexei Starovoitov
2022-02-01 18:40   ` Martin KaFai Lau
2022-01-31 22:05 ` [PATCH bpf-next 2/7] libbpf: Open code low level bpf commands Alexei Starovoitov
2022-02-01 18:52   ` Martin KaFai Lau
2022-01-31 22:05 ` Alexei Starovoitov [this message]
2022-02-01 19:07   ` [PATCH bpf-next 3/7] libbpf: Open code raw_tp_open and link_create commands Martin KaFai Lau
2022-01-31 22:05 ` [PATCH bpf-next 4/7] bpf: Remove unnecessary setrlimit from bpf preload Alexei Starovoitov
2022-02-01 19:09   ` Martin KaFai Lau
2022-01-31 22:05 ` [PATCH bpf-next 5/7] bpf: Convert bpf preload to light skeleton Alexei Starovoitov
2022-02-01 19:18   ` Martin KaFai Lau
2022-01-31 22:05 ` [PATCH bpf-next 6/7] bpf: Open code obj_get_info_by_fd in bpf preload Alexei Starovoitov
2022-02-01 19:26   ` Martin KaFai Lau
2022-01-31 22:05 ` [PATCH bpf-next 7/7] bpf: Drop libbpf, libelf, libz dependency from " Alexei Starovoitov
2022-02-01 19:27   ` Martin KaFai Lau
2022-02-01 23:00 ` [PATCH bpf-next 0/7] bpf: drop libbpf " patchwork-bot+netdevbpf

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=20220131220528.98088-4-alexei.starovoitov@gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=kernel-team@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 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.