aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@plumgrid.com>2014-07-30 23:34:16 -0400
committerDavid S. Miller <davem@davemloft.net>2014-08-02 18:03:58 -0400
commit7ae457c1e5b45a1b826fad9d62b32191d2bdcfdb (patch)
treedcb1aba57530e6c9426a81758173ca146ffafcaf
parent8fb575ca396bc31d9fa99c26336e2432b41d1bfc (diff)
net: filter: split 'struct sk_filter' into socket and bpf parts
clean up names related to socket filtering and bpf in the following way: - everything that deals with sockets keeps 'sk_*' prefix - everything that is pure BPF is changed to 'bpf_*' prefix split 'struct sk_filter' into struct sk_filter { atomic_t refcnt; struct rcu_head rcu; struct bpf_prog *prog; }; and struct bpf_prog { u32 jited:1, len:31; struct sock_fprog_kern *orig_prog; unsigned int (*bpf_func)(const struct sk_buff *skb, const struct bpf_insn *filter); union { struct sock_filter insns[0]; struct bpf_insn insnsi[0]; struct work_struct work; }; }; so that 'struct bpf_prog' can be used independent of sockets and cleans up 'unattached' bpf use cases split SK_RUN_FILTER macro into: SK_RUN_FILTER to be used with 'struct sk_filter *' and BPF_PROG_RUN to be used with 'struct bpf_prog *' __sk_filter_release(struct sk_filter *) gains __bpf_prog_release(struct bpf_prog *) helper function also perform related renames for the functions that work with 'struct bpf_prog *', since they're on the same lines: sk_filter_size -> bpf_prog_size sk_filter_select_runtime -> bpf_prog_select_runtime sk_filter_free -> bpf_prog_free sk_unattached_filter_create -> bpf_prog_create sk_unattached_filter_destroy -> bpf_prog_destroy sk_store_orig_filter -> bpf_prog_store_orig_filter sk_release_orig_filter -> bpf_release_orig_filter __sk_migrate_filter -> bpf_migrate_filter __sk_prepare_filter -> bpf_prepare_filter API for attaching classic BPF to a socket stays the same: sk_attach_filter(prog, struct sock *)/sk_detach_filter(struct sock *) and SK_RUN_FILTER(struct sk_filter *, ctx) to execute a program which is used by sockets, tun, af_packet API for 'unattached' BPF programs becomes: bpf_prog_create(struct bpf_prog **)/bpf_prog_destroy(struct bpf_prog *) and BPF_PROG_RUN(struct bpf_prog *, ctx) to execute a program which is used by isdn, ppp, team, seccomp, ptp, xt_bpf, cls_bpf, test_bpf Signed-off-by: Alexei Starovoitov <ast@plumgrid.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--Documentation/networking/filter.txt10
-rw-r--r--arch/arm/net/bpf_jit_32.c8
-rw-r--r--arch/mips/net/bpf_jit.c8
-rw-r--r--arch/powerpc/net/bpf_jit_comp.c8
-rw-r--r--arch/s390/net/bpf_jit_comp.c4
-rw-r--r--arch/sparc/net/bpf_jit_comp.c4
-rw-r--r--arch/x86/net/bpf_jit_comp.c12
-rw-r--r--drivers/isdn/i4l/isdn_ppp.c26
-rw-r--r--drivers/net/ppp/ppp_generic.c28
-rw-r--r--drivers/net/team/team_mode_loadbalance.c14
-rw-r--r--include/linux/filter.h40
-rw-r--r--include/linux/isdn_ppp.h4
-rw-r--r--include/uapi/linux/netfilter/xt_bpf.h4
-rw-r--r--kernel/bpf/core.c30
-rw-r--r--kernel/seccomp.c10
-rw-r--r--lib/test_bpf.c24
-rw-r--r--net/core/filter.c92
-rw-r--r--net/core/ptp_classifier.c6
-rw-r--r--net/core/sock_diag.c2
-rw-r--r--net/netfilter/xt_bpf.c6
-rw-r--r--net/sched/cls_bpf.c12
21 files changed, 183 insertions, 169 deletions
diff --git a/Documentation/networking/filter.txt b/Documentation/networking/filter.txt
index 712068be8171..c48a9704bda8 100644
--- a/Documentation/networking/filter.txt
+++ b/Documentation/networking/filter.txt
@@ -586,11 +586,11 @@ team driver's classifier for its load-balancing mode, netfilter's xt_bpf
586extension, PTP dissector/classifier, and much more. They are all internally 586extension, PTP dissector/classifier, and much more. They are all internally
587converted by the kernel into the new instruction set representation and run 587converted by the kernel into the new instruction set representation and run
588in the eBPF interpreter. For in-kernel handlers, this all works transparently 588in the eBPF interpreter. For in-kernel handlers, this all works transparently
589by using sk_unattached_filter_create() for setting up the filter, resp. 589by using bpf_prog_create() for setting up the filter, resp.
590sk_unattached_filter_destroy() for destroying it. The macro 590bpf_prog_destroy() for destroying it. The macro
591SK_RUN_FILTER(filter, ctx) transparently invokes eBPF interpreter or JITed 591BPF_PROG_RUN(filter, ctx) transparently invokes eBPF interpreter or JITed
592code to run the filter. 'filter' is a pointer to struct sk_filter that we 592code to run the filter. 'filter' is a pointer to struct bpf_prog that we
593got from sk_unattached_filter_create(), and 'ctx' the given context (e.g. 593got from bpf_prog_create(), and 'ctx' the given context (e.g.
594skb pointer). All constraints and restrictions from bpf_check_classic() apply 594skb pointer). All constraints and restrictions from bpf_check_classic() apply
595before a conversion to the new layout is being done behind the scenes! 595before a conversion to the new layout is being done behind the scenes!
596 596
diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
index fb5503ce016f..a37b989a2f91 100644
--- a/arch/arm/net/bpf_jit_32.c
+++ b/arch/arm/net/bpf_jit_32.c
@@ -56,7 +56,7 @@
56#define FLAG_NEED_X_RESET (1 << 0) 56#define FLAG_NEED_X_RESET (1 << 0)
57 57
58struct jit_ctx { 58struct jit_ctx {
59 const struct sk_filter *skf; 59 const struct bpf_prog *skf;
60 unsigned idx; 60 unsigned idx;
61 unsigned prologue_bytes; 61 unsigned prologue_bytes;
62 int ret0_fp_idx; 62 int ret0_fp_idx;
@@ -465,7 +465,7 @@ static inline void update_on_xread(struct jit_ctx *ctx)
465static int build_body(struct jit_ctx *ctx) 465static int build_body(struct jit_ctx *ctx)
466{ 466{
467 void *load_func[] = {jit_get_skb_b, jit_get_skb_h, jit_get_skb_w}; 467 void *load_func[] = {jit_get_skb_b, jit_get_skb_h, jit_get_skb_w};
468 const struct sk_filter *prog = ctx->skf; 468 const struct bpf_prog *prog = ctx->skf;
469 const struct sock_filter *inst; 469 const struct sock_filter *inst;
470 unsigned i, load_order, off, condt; 470 unsigned i, load_order, off, condt;
471 int imm12; 471 int imm12;
@@ -857,7 +857,7 @@ b_epilogue:
857} 857}
858 858
859 859
860void bpf_jit_compile(struct sk_filter *fp) 860void bpf_jit_compile(struct bpf_prog *fp)
861{ 861{
862 struct jit_ctx ctx; 862 struct jit_ctx ctx;
863 unsigned tmp_idx; 863 unsigned tmp_idx;
@@ -926,7 +926,7 @@ out:
926 return; 926 return;
927} 927}
928 928
929void bpf_jit_free(struct sk_filter *fp) 929void bpf_jit_free(struct bpf_prog *fp)
930{ 930{
931 if (fp->jited) 931 if (fp->jited)
932 module_free(NULL, fp->bpf_func); 932 module_free(NULL, fp->bpf_func);
diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c
index b87390a56a2f..05a56619ece2 100644
--- a/arch/mips/net/bpf_jit.c
+++ b/arch/mips/net/bpf_jit.c
@@ -131,7 +131,7 @@
131 * @target: Memory location for the compiled filter 131 * @target: Memory location for the compiled filter
132 */ 132 */
133struct jit_ctx { 133struct jit_ctx {
134 const struct sk_filter *skf; 134 const struct bpf_prog *skf;
135 unsigned int prologue_bytes; 135 unsigned int prologue_bytes;
136 u32 idx; 136 u32 idx;
137 u32 flags; 137 u32 flags;
@@ -789,7 +789,7 @@ static int pkt_type_offset(void)
789static int build_body(struct jit_ctx *ctx) 789static int build_body(struct jit_ctx *ctx)
790{ 790{
791 void *load_func[] = {jit_get_skb_b, jit_get_skb_h, jit_get_skb_w}; 791 void *load_func[] = {jit_get_skb_b, jit_get_skb_h, jit_get_skb_w};
792 const struct sk_filter *prog = ctx->skf; 792 const struct bpf_prog *prog = ctx->skf;
793 const struct sock_filter *inst; 793 const struct sock_filter *inst;
794 unsigned int i, off, load_order, condt; 794 unsigned int i, off, load_order, condt;
795 u32 k, b_off __maybe_unused; 795 u32 k, b_off __maybe_unused;
@@ -1369,7 +1369,7 @@ jmp_cmp:
1369 1369
1370int bpf_jit_enable __read_mostly; 1370int bpf_jit_enable __read_mostly;
1371 1371
1372void bpf_jit_compile(struct sk_filter *fp) 1372void bpf_jit_compile(struct bpf_prog *fp)
1373{ 1373{
1374 struct jit_ctx ctx; 1374 struct jit_ctx ctx;
1375 unsigned int alloc_size, tmp_idx; 1375 unsigned int alloc_size, tmp_idx;
@@ -1423,7 +1423,7 @@ out:
1423 kfree(ctx.offsets); 1423 kfree(ctx.offsets);
1424} 1424}
1425 1425
1426void bpf_jit_free(struct sk_filter *fp) 1426void bpf_jit_free(struct bpf_prog *fp)
1427{ 1427{
1428 if (fp->jited) 1428 if (fp->jited)
1429 module_free(NULL, fp->bpf_func); 1429 module_free(NULL, fp->bpf_func);
diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
index 82e82cadcde5..3afa6f4c1957 100644
--- a/arch/powerpc/net/bpf_jit_comp.c
+++ b/arch/powerpc/net/bpf_jit_comp.c
@@ -25,7 +25,7 @@ static inline void bpf_flush_icache(void *start, void *end)
25 flush_icache_range((unsigned long)start, (unsigned long)end); 25 flush_icache_range((unsigned long)start, (unsigned long)end);
26} 26}
27 27
28static void bpf_jit_build_prologue(struct sk_filter *fp, u32 *image, 28static void bpf_jit_build_prologue(struct bpf_prog *fp, u32 *image,
29 struct codegen_context *ctx) 29 struct codegen_context *ctx)
30{ 30{
31 int i; 31 int i;
@@ -121,7 +121,7 @@ static void bpf_jit_build_epilogue(u32 *image, struct codegen_context *ctx)
121 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset) 121 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
122 122
123/* Assemble the body code between the prologue & epilogue. */ 123/* Assemble the body code between the prologue & epilogue. */
124static int bpf_jit_build_body(struct sk_filter *fp, u32 *image, 124static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
125 struct codegen_context *ctx, 125 struct codegen_context *ctx,
126 unsigned int *addrs) 126 unsigned int *addrs)
127{ 127{
@@ -569,7 +569,7 @@ static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
569 return 0; 569 return 0;
570} 570}
571 571
572void bpf_jit_compile(struct sk_filter *fp) 572void bpf_jit_compile(struct bpf_prog *fp)
573{ 573{
574 unsigned int proglen; 574 unsigned int proglen;