]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: add bpf_features enum
authorEduard Zingerman <eddyz87@gmail.com>
Wed, 25 Jun 2025 18:24:12 +0000 (11:24 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 25 Jun 2025 22:13:15 +0000 (15:13 -0700)
This commit adds a kernel side enum for use in conjucntion with BTF
CO-RE bpf_core_enum_value_exists. The goal of the enum is to assist
with available BPF features detection. Intended usage looks as
follows:

  if (bpf_core_enum_value_exists(enum bpf_features, BPF_FEAT_<f>))
     ... use feature f ...

Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20250625182414.30659-2-eddyz87@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c

index 2ff22ef423480b87ce21eaefb36b18d15dcc45cd..527fa80be4291dab2fbe286679ee12a50b9c381d 100644 (file)
@@ -44,6 +44,10 @@ static const struct bpf_verifier_ops * const bpf_verifier_ops[] = {
 #undef BPF_LINK_TYPE
 };
 
+enum bpf_features {
+       __MAX_BPF_FEAT,
+};
+
 struct bpf_mem_alloc bpf_global_percpu_ma;
 static bool bpf_global_percpu_ma_set;
 
@@ -24439,6 +24443,8 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, __u3
        u32 log_true_size;
        bool is_priv;
 
+       BTF_TYPE_EMIT(enum bpf_features);
+
        /* no program is valid */
        if (ARRAY_SIZE(bpf_verifier_ops) == 0)
                return -EINVAL;