Message ID | 616c50d61de26eacd49fbb641d3122a85ca478fc.1651532419.git.delyank@fb.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | BPF |
Headers | show |
Series | sleepable uprobe support | expand |
On Mon, May 02, 2022 at 11:09:38PM +0000, Delyan Kratunov wrote: > In order to add a version of bpf_prog_run_array which accesses the > bpf_prog->aux member, we need bpf_prog 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> > --- > include/linux/bpf.h | 36 ++++++++++++++++++++++++++++++++++++ > include/linux/filter.h | 34 ---------------------------------- > 2 files changed, 36 insertions(+), 34 deletions(-) > > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > index be94833d390a..57ec619cf729 100644 > --- a/include/linux/bpf.h > +++ b/include/linux/bpf.h > @@ -5,6 +5,7 @@ > #define _LINUX_BPF_H 1 > > #include <uapi/linux/bpf.h> > +#include <uapi/linux/filter.h> because of struct sock_filter ? Pls fwd declare it instead. > #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> > > @@ -1068,6 +1070,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; > diff --git a/include/linux/filter.h b/include/linux/filter.h > index ed0c0ff42ad5..d0cbb31b1b4d 100644 > --- a/include/linux/filter.h > +++ b/include/linux/filter.h > @@ -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; > -- > 2.35.1
On Mon, 2022-05-09 at 20:04 -0700, Alexei Starovoitov wrote: > On Mon, May 02, 2022 at 11:09:38PM +0000, Delyan Kratunov wrote: > > In order to add a version of bpf_prog_run_array which accesses the > > bpf_prog->aux member, we need bpf_prog 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> > > --- > > include/linux/bpf.h | 36 ++++++++++++++++++++++++++++++++++++ > > include/linux/filter.h | 34 ---------------------------------- > > 2 files changed, 36 insertions(+), 34 deletions(-) > > > > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > > index be94833d390a..57ec619cf729 100644 > > --- a/include/linux/bpf.h > > +++ b/include/linux/bpf.h > > @@ -5,6 +5,7 @@ > > #define _LINUX_BPF_H 1 > > > > #include <uapi/linux/bpf.h> > > +#include <uapi/linux/filter.h> > > because of struct sock_filter ? > Pls fwd declare it instead. Yes but you can't forward declare it in this context. It's used as within DECLARE_FLEX_ARRAY, so a forward declaration leads to: ./include/linux/bpf.h:1107:56: error: array type has incomplete element type ‘struct sock_filter’ 1107 | DECLARE_FLEX_ARRAY(struct sock_filter, insns); > > > #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> > > > > @@ -1068,6 +1070,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; > > diff --git a/include/linux/filter.h b/include/linux/filter.h > > index ed0c0ff42ad5..d0cbb31b1b4d 100644 > > --- a/include/linux/filter.h > > +++ b/include/linux/filter.h > > @@ -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; > > -- > > 2.35.1
diff --git a/include/linux/bpf.h b/include/linux/bpf.h index be94833d390a..57ec619cf729 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -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> @@ -1068,6 +1070,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; diff --git a/include/linux/filter.h b/include/linux/filter.h index ed0c0ff42ad5..d0cbb31b1b4d 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -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;
In order to add a version of bpf_prog_run_array which accesses the bpf_prog->aux member, we need bpf_prog 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> --- include/linux/bpf.h | 36 ++++++++++++++++++++++++++++++++++++ include/linux/filter.h | 34 ---------------------------------- 2 files changed, 36 insertions(+), 34 deletions(-)