From: Andrii Nakryiko <andrii@kernel.org>
To: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
martin.lau@kernel.org
Cc: andrii@kernel.org, kernel-team@meta.com
Subject: [PATCH v2 bpf-next 3/3] libbpf: improve old BPF skeleton handling for map auto-attach
Date: Mon, 8 Jul 2024 13:45:40 -0700 [thread overview]
Message-ID: <20240708204540.4188946-4-andrii@kernel.org> (raw)
In-Reply-To: <20240708204540.4188946-1-andrii@kernel.org>
Improve how we handle old BPF skeletons when it comes to BPF map
auto-attachment. Emit one warn-level message per each struct_ops map
that could have been auto-attached, if user provided recent enough BPF
skeleton version. Don't spam log if there are no relevant struct_ops
maps, though.
This should help users realize that they probably need to regenerate BPF
skeleton header with more recent bpftool/libbpf-cargo (or whatever other
means of BPF skeleton generation).
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/lib/bpf/libbpf.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 8625c948f60a..a3be6f8fac09 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -13967,32 +13967,34 @@ int bpf_object__attach_skeleton(struct bpf_object_skeleton *s)
*/
}
- /* Skeleton is created with earlier version of bpftool
- * which does not support auto-attachment
- */
- if (s->map_skel_sz < sizeof(struct bpf_map_skeleton))
- return 0;
for (i = 0; i < s->map_cnt; i++) {
struct bpf_map_skeleton *map_skel = (void *)s->maps + i * s->map_skel_sz;
struct bpf_map *map = *map_skel->map;
- struct bpf_link **link = map_skel->link;
+ struct bpf_link **link;
if (!map->autocreate || !map->autoattach)
continue;
- if (*link)
- continue;
-
/* only struct_ops maps can be attached */
if (!bpf_map__is_struct_ops(map))
continue;
- *link = bpf_map__attach_struct_ops(map);
+ /* skeleton is created with earlier version of bpftool, notify user */
+ if (s->map_skel_sz < offsetofend(struct bpf_map_skeleton, link)) {
+ pr_warn("map '%s': BPF skeleton version is old, skipping map auto-attachment...\n",
+ bpf_map__name(map));
+ continue;
+ }
+
+ link = map_skel->link;
+ if (*link)
+ continue;
+
+ *link = bpf_map__attach_struct_ops(map);
if (!*link) {
err = -errno;
- pr_warn("map '%s': failed to auto-attach: %d\n",
- bpf_map__name(map), err);
+ pr_warn("map '%s': failed to auto-attach: %d\n", bpf_map__name(map), err);
return libbpf_err(err);
}
}
--
2.43.0
next prev parent reply other threads:[~2024-07-08 20:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-08 20:45 [PATCH v2 bpf-next 0/3] Fix libbpf BPF skeleton forward/backward compat Andrii Nakryiko
2024-07-08 20:45 ` [PATCH v2 bpf-next 1/3] bpftool: improve skeleton backwards compat with old buggy libbpfs Andrii Nakryiko
2024-07-08 22:16 ` Eduard Zingerman
2024-07-08 22:54 ` Eduard Zingerman
2024-07-08 23:20 ` Andrii Nakryiko
2024-07-08 20:45 ` [PATCH v2 bpf-next 2/3] libbpf: fix BPF skeleton forward/backward compat handling Andrii Nakryiko
2024-07-08 20:45 ` Andrii Nakryiko [this message]
2024-07-08 23:09 ` [PATCH v2 bpf-next 3/3] libbpf: improve old BPF skeleton handling for map auto-attach Eduard Zingerman
2024-07-10 2:10 ` [PATCH v2 bpf-next 0/3] Fix libbpf BPF skeleton forward/backward compat 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=20240708204540.4188946-4-andrii@kernel.org \
--to=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@meta.com \
--cc=martin.lau@kernel.org \
/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