summaryrefslogtreecommitdiff
path: root/tools/lib
diff options
context:
space:
mode:
authorAndrii Nakryiko <andrii@kernel.org>2023-12-13 11:08:34 -0800
committerAlexei Starovoitov <ast@kernel.org>2023-12-13 15:47:04 -0800
commitc6c5be3eee975ae640966844db66d404c1de79b1 (patch)
tree192b7deee31859e25e5c398eeba69b76fecde9ab /tools/lib
parentf5fdb51fb980077a4c6c78f3f775821f611fb38b (diff)
libbpf: split feature detectors definitions from cached results
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> Link: https://lore.kernel.org/r/20231213190842.3844987-3-andrii@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/bpf/libbpf.c18
1 files 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)