diff mbox series

[bpf-next,v2,1/5] bpf: move bpf_prog to bpf.h

Message ID 616c50d61de26eacd49fbb641d3122a85ca478fc.1651532419.git.delyank@fb.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series sleepable uprobe support | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
netdev/tree_selection success Clearly marked for bpf-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1467 this patch: 1467
netdev/cc_maintainers warning 6 maintainers not CCed: songliubraving@fb.com netdev@vger.kernel.org kafai@fb.com yhs@fb.com john.fastabend@gmail.com kpsingh@kernel.org
netdev/build_clang success Errors and warnings before: 174 this patch: 174
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1474 this patch: 1474
netdev/checkpatch warning WARNING: line length of 103 exceeds 80 columns WARNING: line length of 122 exceeds 80 columns WARNING: line length of 81 exceeds 80 columns WARNING: line length of 82 exceeds 80 columns WARNING: line length of 83 exceeds 80 columns WARNING: line length of 86 exceeds 80 columns WARNING: line length of 91 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-1 success Logs for Kernel LATEST on ubuntu-latest + selftests
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Kernel LATEST on z15 + selftests

Commit Message

Delyan Kratunov May 2, 2022, 11:09 p.m. UTC
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(-)

Comments

Alexei Starovoitov May 10, 2022, 3:04 a.m. UTC | #1
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
Delyan Kratunov May 13, 2022, 1:22 a.m. UTC | #2
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 mbox series

Patch

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;