bpf: move bpf_prog to bpf.h
authorDelyan Kratunov <delyank@fb.com>
Tue, 14 Jun 2022 23:10:42 +0000 (23:10 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 17 Jun 2022 02:27:29 +0000 (19:27 -0700)
In order to add a version of bpf_prog_run_array which accesses the
bpf_prog->aux member, bpf_prog needs to be more than a forward
declaration inside bpf.h.

Given that filter.h already includes bpf.h, this merely reorders
the type declarations for filter.h users. bpf.h users now have access to
bpf_prog internals.

Signed-off-by: Delyan Kratunov <delyank@fb.com>
Link: https://lore.kernel.org/r/3ed7824e3948f22d84583649ccac0ff0d38b6b58.1655248076.git.delyank@fb.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/bpf.h
include/linux/filter.h

index 8e6092d..69106ae 100644 (file)
@@ -5,6 +5,7 @@
 #define _LINUX_BPF_H 1
 
 #include <uapi/linux/bpf.h>
+#include <uapi/linux/filter.h>
 
 #include <linux/workqueue.h>
 #include <linux/file.h>
@@ -22,6 +23,7 @@
 #include <linux/sched/mm.h>
 #include <linux/slab.h>
 #include <linux/percpu-refcount.h>
+#include <linux/stddef.h>
 #include <linux/bpfptr.h>
 #include <linux/btf.h>
 
@@ -1084,6 +1086,40 @@ struct bpf_prog_aux {
        };
 };
 
+struct bpf_prog {
+       u16                     pages;          /* Number of allocated pages */
+       u16                     jited:1,        /* Is our filter JIT'ed? */
+                               jit_requested:1,/* archs need to JIT the prog */
+                               gpl_compatible:1, /* Is filter GPL compatible? */
+                               cb_access:1,    /* Is control block accessed? */
+                               dst_needed:1,   /* Do we need dst entry? */
+                               blinding_requested:1, /* needs constant blinding */
+                               blinded:1,      /* Was blinded */
+                               is_func:1,      /* program is a bpf function */
+                               kprobe_override:1, /* Do we override a kprobe? */
+                               has_callchain_buf:1, /* callchain buffer allocated? */
+                               enforce_expected_attach_type:1, /* Enforce expected_attach_type checking at attach time */
+                               call_get_stack:1, /* Do we call bpf_get_stack() or bpf_get_stackid() */
+                               call_get_func_ip:1, /* Do we call get_func_ip() */
+                               tstamp_type_access:1; /* Accessed __sk_buff->tstamp_type */
+       enum bpf_prog_type      type;           /* Type of BPF program */
+       enum bpf_attach_type    expected_attach_type; /* For some prog types */
+       u32                     len;            /* Number of filter blocks */
+       u32                     jited_len;      /* Size of jited insns in bytes */
+       u8                      tag[BPF_TAG_SIZE];
+       struct bpf_prog_stats __percpu *stats;
+       int __percpu            *active;
+       unsigned int            (*bpf_func)(const void *ctx,
+                                           const struct bpf_insn *insn);
+       struct bpf_prog_aux     *aux;           /* Auxiliary fields */
+       struct sock_fprog_kern  *orig_prog;     /* Original BPF program */
+       /* Instructions for interpreter */
+       union {
+               DECLARE_FLEX_ARRAY(struct sock_filter, insns);
+               DECLARE_FLEX_ARRAY(struct bpf_insn, insnsi);
+       };
+};
+
 struct bpf_array_aux {
        /* Programs with direct jumps into programs part of this array. */
        struct list_head poke_progs;
index ed0c0ff..d0cbb31 100644 (file)
@@ -559,40 +559,6 @@ struct bpf_prog_stats {
        struct u64_stats_sync syncp;
 } __aligned(2 * sizeof(u64));
 
-struct bpf_prog {
-       u16                     pages;          /* Number of allocated pages */
-       u16                     jited:1,        /* Is our filter JIT'ed? */
-                               jit_requested:1,/* archs need to JIT the prog */
-                               gpl_compatible:1, /* Is filter GPL compatible? */
-                               cb_access:1,    /* Is control block accessed? */
-                               dst_needed:1,   /* Do we need dst entry? */
-                               blinding_requested:1, /* needs constant blinding */
-                               blinded:1,      /* Was blinded */
-                               is_func:1,      /* program is a bpf function */
-                               kprobe_override:1, /* Do we override a kprobe? */
-                               has_callchain_buf:1, /* callchain buffer allocated? */
-                               enforce_expected_attach_type:1, /* Enforce expected_attach_type checking at attach time */
-                               call_get_stack:1, /* Do we call bpf_get_stack() or bpf_get_stackid() */
-                               call_get_func_ip:1, /* Do we call get_func_ip() */
-                               tstamp_type_access:1; /* Accessed __sk_buff->tstamp_type */
-       enum bpf_prog_type      type;           /* Type of BPF program */
-       enum bpf_attach_type    expected_attach_type; /* For some prog types */
-       u32                     len;            /* Number of filter blocks */
-       u32                     jited_len;      /* Size of jited insns in bytes */
-       u8                      tag[BPF_TAG_SIZE];
-       struct bpf_prog_stats __percpu *stats;
-       int __percpu            *active;
-       unsigned int            (*bpf_func)(const void *ctx,
-                                           const struct bpf_insn *insn);
-       struct bpf_prog_aux     *aux;           /* Auxiliary fields */
-       struct sock_fprog_kern  *orig_prog;     /* Original BPF program */
-       /* Instructions for interpreter */
-       union {
-               DECLARE_FLEX_ARRAY(struct sock_filter, insns);
-               DECLARE_FLEX_ARRAY(struct bpf_insn, insnsi);
-       };
-};
-
 struct sk_filter {
        refcount_t      refcnt;
        struct rcu_head rcu;