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 2/7] libbpf: Open code low level bpf commands.
Date: Mon, 31 Jan 2022 14:05:23 -0800	[thread overview]
Message-ID: <20220131220528.98088-3-alexei.starovoitov@gmail.com> (raw)
In-Reply-To: <20220131220528.98088-1-alexei.starovoitov@gmail.com>

From: Alexei Starovoitov <ast@kernel.org>

Open code low level bpf commands used by light skeleton to
be able to avoid full libbpf eventually.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
 tools/lib/bpf/skel_internal.h | 44 +++++++++++++++++++++++++++++++++--
 1 file changed, 42 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/skel_internal.h b/tools/lib/bpf/skel_internal.h
index 0b84d8e6b72a..57507f1c1934 100644
--- a/tools/lib/bpf/skel_internal.h
+++ b/tools/lib/bpf/skel_internal.h
@@ -70,19 +70,59 @@ static inline int skel_closenz(int fd)
 	return -EINVAL;
 }
 
+#ifndef offsetofend
+#define offsetofend(TYPE, MEMBER) \
+	(offsetof(TYPE, MEMBER)	+ sizeof((((TYPE *)0)->MEMBER)))
+#endif
+
+static inline int skel_map_create(enum bpf_map_type map_type,
+				  const char *map_name,
+				  __u32 key_size,
+				  __u32 value_size,
+				  __u32 max_entries)
+{
+	const size_t attr_sz = offsetofend(union bpf_attr, map_extra);
+	union bpf_attr attr;
+
+	memset(&attr, 0, attr_sz);
+
+	attr.map_type = map_type;
+	strncpy(attr.map_name, map_name, sizeof(attr.map_name));
+	attr.key_size = key_size;
+	attr.value_size = value_size;
+	attr.max_entries = max_entries;
+
+	return skel_sys_bpf(BPF_MAP_CREATE, &attr, attr_sz);
+}
+
+static inline int skel_map_update_elem(int fd, const void *key,
+				       const void *value, __u64 flags)
+{
+	const size_t attr_sz = offsetofend(union bpf_attr, flags);
+	union bpf_attr attr;
+
+	memset(&attr, 0, attr_sz);
+	attr.map_fd = fd;
+	attr.key = (long) key;
+	attr.value = (long) value;
+	attr.flags = flags;
+
+	return skel_sys_bpf(BPF_MAP_UPDATE_ELEM, &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;
 	union bpf_attr attr;
 
-	map_fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, "__loader.map", 4, opts->data_sz, 1, NULL);
+	map_fd = skel_map_create(BPF_MAP_TYPE_ARRAY, "__loader.map", 4, opts->data_sz, 1);
 	if (map_fd < 0) {
 		opts->errstr = "failed to create loader map";
 		err = -errno;
 		goto out;
 	}
 
-	err = bpf_map_update_elem(map_fd, &key, opts->data, 0);
+	err = skel_map_update_elem(map_fd, &key, opts->data, 0);
 	if (err < 0) {
 		opts->errstr = "failed to update loader map";
 		err = -errno;
-- 
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 ` Alexei Starovoitov [this message]
2022-02-01 18:52   ` [PATCH bpf-next 2/7] libbpf: Open code low level bpf commands Martin KaFai Lau
2022-01-31 22:05 ` [PATCH bpf-next 3/7] libbpf: Open code raw_tp_open and link_create commands Alexei Starovoitov
2022-02-01 19:07   ` 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-3-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.