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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxx>
> ---
>  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



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux