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>,
John Fastabend <john.fastabend@gmail.com>
Subject: [PATCH v2 bpf-next 2/8] libbpf: split feature detectors definitions from cached results
Date: Tue, 12 Dec 2023 10:25:41 -0800 [thread overview]
Message-ID: <20231212182547.1873811-3-andrii@kernel.org> (raw)
In-Reply-To: <20231212182547.1873811-1-andrii@kernel.org>
Split a list of supported feature detectors with their corresponding
callbacks from actual cached supported/missing values. This will allow
to have more flexible per-token or per-object feature detectors in
subsequent refactorings.
Acked-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/lib/bpf/libbpf.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index ac54ebc0629f..d2828a26b011 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -4999,12 +4999,17 @@ enum kern_feature_result {
FEAT_MISSING = 2,
};
+struct kern_feature_cache {
+ enum kern_feature_result res[__FEAT_CNT];
+};
+
typedef int (*feature_probe_fn)(void);
+static struct kern_feature_cache feature_cache;
+
static struct kern_feature_desc {
const char *desc;
feature_probe_fn probe;
- enum kern_feature_result res;
} feature_probes[__FEAT_CNT] = {
[FEAT_PROG_NAME] = {
"BPF program name", probe_kern_prog_name,
@@ -5072,6 +5077,7 @@ static struct kern_feature_desc {
bool kernel_supports(const struct bpf_object *obj, enum kern_feature_id feat_id)
{
struct kern_feature_desc *feat = &feature_probes[feat_id];
+ struct kern_feature_cache *cache = &feature_cache;
int ret;
if (obj && obj->gen_loader)
@@ -5080,19 +5086,19 @@ bool kernel_supports(const struct bpf_object *obj, enum kern_feature_id feat_id)
*/
return true;
- if (READ_ONCE(feat->res) == FEAT_UNKNOWN) {
+ if (READ_ONCE(cache->res[feat_id]) == FEAT_UNKNOWN) {
ret = feat->probe();
if (ret > 0) {
- WRITE_ONCE(feat->res, FEAT_SUPPORTED);
+ WRITE_ONCE(cache->res[feat_id], FEAT_SUPPORTED);
} else if (ret == 0) {
- WRITE_ONCE(feat->res, FEAT_MISSING);
+ WRITE_ONCE(cache->res[feat_id], FEAT_MISSING);
} else {
pr_warn("Detection of kernel %s support failed: %d\n", feat->desc, ret);
- WRITE_ONCE(feat->res, FEAT_MISSING);
+ WRITE_ONCE(cache->res[feat_id], FEAT_MISSING);
}
}
- return READ_ONCE(feat->res) == FEAT_SUPPORTED;
+ return READ_ONCE(cache->res[feat_id]) == FEAT_SUPPORTED;
}
static bool map_is_reuse_compat(const struct bpf_map *map, int map_fd)
--
2.34.1
next prev parent reply other threads:[~2023-12-12 18:26 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-12 18:25 [PATCH v2 bpf-next 0/8] BPF token support in libbpf's BPF object Andrii Nakryiko
2023-12-12 18:25 ` [PATCH v2 bpf-next 1/8] bpf: fail BPF_TOKEN_CREATE if no delegation option was set on BPF FS Andrii Nakryiko
2023-12-12 18:25 ` Andrii Nakryiko [this message]
2023-12-12 18:25 ` [PATCH v2 bpf-next 3/8] libbpf: further decouple feature checking logic from bpf_object Andrii Nakryiko
2023-12-12 18:25 ` [PATCH v2 bpf-next 4/8] libbpf: move feature detection code into its own file Andrii Nakryiko
2023-12-12 18:25 ` [PATCH v2 bpf-next 5/8] libbpf: wire up token_fd into feature probing logic Andrii Nakryiko
2023-12-13 4:00 ` Alexei Starovoitov
2023-12-13 17:33 ` Andrii Nakryiko
2023-12-12 18:25 ` [PATCH v2 bpf-next 6/8] libbpf: wire up BPF token support at BPF object level Andrii Nakryiko
2023-12-13 4:12 ` Alexei Starovoitov
2023-12-13 17:39 ` Andrii Nakryiko
2023-12-12 18:25 ` [PATCH v2 bpf-next 7/8] selftests/bpf: add BPF object loading tests with explicit token passing Andrii Nakryiko
2023-12-12 18:25 ` [PATCH v2 bpf-next 8/8] selftests/bpf: add tests for BPF object load with implicit token Andrii Nakryiko
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=20231212182547.1873811-3-andrii@kernel.org \
--to=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--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