Skip to content

Commit

Permalink
Merge branch 'filter-next'
Browse files Browse the repository at this point in the history
Alexei Starovoitov says:

====================
net: filter: split sk_filter into socket and bpf, cleanup names

The main goal of the series is to split 'struct sk_filter' into socket and
bpf parts and cleanup names 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:
isdn, ppp, team, seccomp, ptp, xt_bpf, cls_bpf, test_bpf
which don't need refcnt/rcu fields.

It's a follow up to the rcu cleanup started by Pablo in
commit 34c5bd6 ("net: filter: don't release unattached filter through call_rcu()")

Patch 1 - cleans up socket memory charging and makes it possible for functions
  sk(bpf)_migrate_filter(), sk(bpf)_prepare_filter() to be socket independent
Patches 2-4 - trivial renames
Patch 5 - sk_filter split and renames of related sk_*() functions
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Aug 2, 2014
2 parents 4330487 + 7ae457c commit e339756
Show file tree
Hide file tree
Showing 22 changed files with 243 additions and 238 deletions.
12 changes: 6 additions & 6 deletions Documentation/networking/filter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -586,12 +586,12 @@ team driver's classifier for its load-balancing mode, netfilter's xt_bpf
extension, PTP dissector/classifier, and much more. They are all internally
converted by the kernel into the new instruction set representation and run
in the eBPF interpreter. For in-kernel handlers, this all works transparently
by using sk_unattached_filter_create() for setting up the filter, resp.
sk_unattached_filter_destroy() for destroying it. The macro
SK_RUN_FILTER(filter, ctx) transparently invokes eBPF interpreter or JITed
code to run the filter. 'filter' is a pointer to struct sk_filter that we
got from sk_unattached_filter_create(), and 'ctx' the given context (e.g.
skb pointer). All constraints and restrictions from sk_chk_filter() apply
by using bpf_prog_create() for setting up the filter, resp.
bpf_prog_destroy() for destroying it. The macro
BPF_PROG_RUN(filter, ctx) transparently invokes eBPF interpreter or JITed
code to run the filter. 'filter' is a pointer to struct bpf_prog that we
got from bpf_prog_create(), and 'ctx' the given context (e.g.
skb pointer). All constraints and restrictions from bpf_check_classic() apply
before a conversion to the new layout is being done behind the scenes!

Currently, the classic BPF format is being used for JITing on most of the
Expand Down
8 changes: 4 additions & 4 deletions arch/arm/net/bpf_jit_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#define FLAG_NEED_X_RESET (1 << 0)

struct jit_ctx {
const struct sk_filter *skf;
const struct bpf_prog *skf;
unsigned idx;
unsigned prologue_bytes;
int ret0_fp_idx;
Expand Down Expand Up @@ -465,7 +465,7 @@ static inline void update_on_xread(struct jit_ctx *ctx)
static int build_body(struct jit_ctx *ctx)
{
void *load_func[] = {jit_get_skb_b, jit_get_skb_h, jit_get_skb_w};
const struct sk_filter *prog = ctx->skf;
const struct bpf_prog *prog = ctx->skf;
const struct sock_filter *inst;
unsigned i, load_order, off, condt;
int imm12;
Expand Down Expand Up @@ -857,7 +857,7 @@ static int build_body(struct jit_ctx *ctx)
}


void bpf_jit_compile(struct sk_filter *fp)
void bpf_jit_compile(struct bpf_prog *fp)
{
struct jit_ctx ctx;
unsigned tmp_idx;
Expand Down Expand Up @@ -926,7 +926,7 @@ void bpf_jit_compile(struct sk_filter *fp)
return;
}

void bpf_jit_free(struct sk_filter *fp)
void bpf_jit_free(struct bpf_prog *fp)
{
if (fp->jited)
module_free(NULL, fp->bpf_func);
Expand Down
8 changes: 4 additions & 4 deletions arch/mips/net/bpf_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
* @target: Memory location for the compiled filter
*/
struct jit_ctx {
const struct sk_filter *skf;
const struct bpf_prog *skf;
unsigned int prologue_bytes;
u32 idx;
u32 flags;
Expand Down Expand Up @@ -789,7 +789,7 @@ static int pkt_type_offset(void)
static int build_body(struct jit_ctx *ctx)
{
void *load_func[] = {jit_get_skb_b, jit_get_skb_h, jit_get_skb_w};
const struct sk_filter *prog = ctx->skf;
const struct bpf_prog *prog = ctx->skf;
const struct sock_filter *inst;
unsigned int i, off, load_order, condt;
u32 k, b_off __maybe_unused;
Expand Down Expand Up @@ -1369,7 +1369,7 @@ static int build_body(struct jit_ctx *ctx)

int bpf_jit_enable __read_mostly;

void bpf_jit_compile(struct sk_filter *fp)
void bpf_jit_compile(struct bpf_prog *fp)
{
struct jit_ctx ctx;
unsigned int alloc_size, tmp_idx;
Expand Down Expand Up @@ -1423,7 +1423,7 @@ void bpf_jit_compile(struct sk_filter *fp)
kfree(ctx.offsets);
}

void bpf_jit_free(struct sk_filter *fp)
void bpf_jit_free(struct bpf_prog *fp)
{
if (fp->jited)
module_free(NULL, fp->bpf_func);
Expand Down
8 changes: 4 additions & 4 deletions arch/powerpc/net/bpf_jit_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static inline void bpf_flush_icache(void *start, void *end)
flush_icache_range((unsigned long)start, (unsigned long)end);
}

static void bpf_jit_build_prologue(struct sk_filter *fp, u32 *image,
static void bpf_jit_build_prologue(struct bpf_prog *fp, u32 *image,
struct codegen_context *ctx)
{
int i;
Expand Down Expand Up @@ -121,7 +121,7 @@ static void bpf_jit_build_epilogue(u32 *image, struct codegen_context *ctx)
((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)

/* Assemble the body code between the prologue & epilogue. */
static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
struct codegen_context *ctx,
unsigned int *addrs)
{
Expand Down Expand Up @@ -569,7 +569,7 @@ static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
return 0;
}

void bpf_jit_compile(struct sk_filter *fp)
void bpf_jit_compile(struct bpf_prog *fp)
{
unsigned int proglen;
unsigned int alloclen;
Expand Down Expand Up @@ -693,7 +693,7 @@ void bpf_jit_compile(struct sk_filter *fp)
return;
}

void bpf_jit_free(struct sk_filter *fp)
void bpf_jit_free(struct bpf_prog *fp)
{
if (fp->jited)
module_free(NULL, fp->bpf_func);
Expand Down
4 changes: 2 additions & 2 deletions arch/s390/net/bpf_jit_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ static struct bpf_binary_header *bpf_alloc_binary(unsigned int bpfsize,
return header;
}

void bpf_jit_compile(struct sk_filter *fp)
void bpf_jit_compile(struct bpf_prog *fp)
{
struct bpf_binary_header *header = NULL;
unsigned long size, prg_len, lit_len;
Expand Down Expand Up @@ -875,7 +875,7 @@ void bpf_jit_compile(struct sk_filter *fp)
kfree(addrs);
}

void bpf_jit_free(struct sk_filter *fp)
void bpf_jit_free(struct bpf_prog *fp)
{
unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
struct bpf_binary_header *header = (void *)addr;
Expand Down
4 changes: 2 additions & 2 deletions arch/sparc/net/bpf_jit_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ do { *prog++ = BR_OPC | WDISP22(OFF); \
* emit_jump() calls with adjusted offsets.
*/

void bpf_jit_compile(struct sk_filter *fp)
void bpf_jit_compile(struct bpf_prog *fp)
{
unsigned int cleanup_addr, proglen, oldproglen = 0;
u32 temp[8], *prog, *func, seen = 0, pass;
Expand Down Expand Up @@ -808,7 +808,7 @@ cond_branch: f_offset = addrs[i + filter[i].jf];
return;
}

void bpf_jit_free(struct sk_filter *fp)
void bpf_jit_free(struct bpf_prog *fp)
{
if (fp->jited)
module_free(NULL, fp->bpf_func);
Expand Down
14 changes: 7 additions & 7 deletions arch/x86/net/bpf_jit_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ struct jit_context {
bool seen_ld_abs;
};

static int do_jit(struct sk_filter *bpf_prog, int *addrs, u8 *image,
static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image,
int oldproglen, struct jit_context *ctx)
{
struct bpf_insn *insn = bpf_prog->insnsi;
Expand All @@ -235,7 +235,7 @@ static int do_jit(struct sk_filter *bpf_prog, int *addrs, u8 *image,
/* mov qword ptr [rbp-X],rbx */
EMIT3_off32(0x48, 0x89, 0x9D, -stacksize);

/* sk_convert_filter() maps classic BPF register X to R7 and uses R8
/* bpf_convert_filter() maps classic BPF register X to R7 and uses R8
* as temporary, so all tcpdump filters need to spill/fill R7(r13) and
* R8(r14). R9(r15) spill could be made conditional, but there is only
* one 'bpf_error' return path out of helper functions inside bpf_jit.S
Expand Down Expand Up @@ -841,7 +841,7 @@ common_load: ctx->seen_ld_abs = true;
/* By design x64 JIT should support all BPF instructions
* This error will be seen if new instruction was added
* to interpreter, but not to JIT
* or if there is junk in sk_filter
* or if there is junk in bpf_prog
*/
pr_err("bpf_jit: unknown opcode %02x\n", insn->code);
return -EINVAL;
Expand All @@ -862,11 +862,11 @@ common_load: ctx->seen_ld_abs = true;
return proglen;
}

void bpf_jit_compile(struct sk_filter *prog)
void bpf_jit_compile(struct bpf_prog *prog)
{
}

void bpf_int_jit_compile(struct sk_filter *prog)
void bpf_int_jit_compile(struct bpf_prog *prog)
{
struct bpf_binary_header *header = NULL;
int proglen, oldproglen = 0;
Expand Down Expand Up @@ -932,7 +932,7 @@ void bpf_int_jit_compile(struct sk_filter *prog)

static void bpf_jit_free_deferred(struct work_struct *work)
{
struct sk_filter *fp = container_of(work, struct sk_filter, work);
struct bpf_prog *fp = container_of(work, struct bpf_prog, work);
unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
struct bpf_binary_header *header = (void *)addr;

Expand All @@ -941,7 +941,7 @@ static void bpf_jit_free_deferred(struct work_struct *work)
kfree(fp);
}

void bpf_jit_free(struct sk_filter *fp)
void bpf_jit_free(struct bpf_prog *fp)
{
if (fp->jited) {
INIT_WORK(&fp->work, bpf_jit_free_deferred);
Expand Down
26 changes: 12 additions & 14 deletions drivers/isdn/i4l/isdn_ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,12 @@ isdn_ppp_release(int min, struct file *file)
#endif
#ifdef CONFIG_IPPP_FILTER
if (is->pass_filter) {
sk_unattached_filter_destroy(is->pass_filter);
bpf_prog_destroy(is->pass_filter);
is->pass_filter = NULL;
}

if (is->active_filter) {
sk_unattached_filter_destroy(is->active_filter);
bpf_prog_destroy(is->active_filter);
is->active_filter = NULL;
}
#endif
Expand Down Expand Up @@ -639,12 +639,11 @@ isdn_ppp_ioctl(int min, struct file *file, unsigned int cmd, unsigned long arg)
fprog.filter = code;

if (is->pass_filter) {
sk_unattached_filter_destroy(is->pass_filter);
bpf_prog_destroy(is->pass_filter);
is->pass_filter = NULL;
}
if (fprog.filter != NULL)
err = sk_unattached_filter_create(&is->pass_filter,
&fprog);
err = bpf_prog_create(&is->pass_filter, &fprog);
else
err = 0;
kfree(code);
Expand All @@ -664,12 +663,11 @@ isdn_ppp_ioctl(int min, struct file *file, unsigned int cmd, unsigned long arg)
fprog.filter = code;

if (is->active_filter) {
sk_unattached_filter_destroy(is->active_filter);
bpf_prog_destroy(is->active_filter);
is->active_filter = NULL;
}
if (fprog.filter != NULL)
err = sk_unattached_filter_create(&is->active_filter,
&fprog);
err = bpf_prog_create(&is->active_filter, &fprog);
else
err = 0;
kfree(code);
Expand Down Expand Up @@ -1174,14 +1172,14 @@ isdn_ppp_push_higher(isdn_net_dev *net_dev, isdn_net_local *lp, struct sk_buff *
}

if (is->pass_filter
&& SK_RUN_FILTER(is->pass_filter, skb) == 0) {
&& BPF_PROG_RUN(is->pass_filter, skb) == 0) {
if (is->debug & 0x2)
printk(KERN_DEBUG "IPPP: inbound frame filtered.\n");
kfree_skb(skb);
return;
}
if (!(is->active_filter
&& SK_RUN_FILTER(is->active_filter, skb) == 0)) {
&& BPF_PROG_RUN(is->active_filter, skb) == 0)) {
if (is->debug & 0x2)
printk(KERN_DEBUG "IPPP: link-active filter: resetting huptimer.\n");
lp->huptimer = 0;
Expand Down Expand Up @@ -1320,14 +1318,14 @@ isdn_ppp_xmit(struct sk_buff *skb, struct net_device *netdev)
}

if (ipt->pass_filter
&& SK_RUN_FILTER(ipt->pass_filter, skb) == 0) {
&& BPF_PROG_RUN(ipt->pass_filter, skb) == 0) {
if (ipt->debug & 0x4)
printk(KERN_DEBUG "IPPP: outbound frame filtered.\n");
kfree_skb(skb);
goto unlock;
}
if (!(ipt->active_filter
&& SK_RUN_FILTER(ipt->active_filter, skb) == 0)) {
&& BPF_PROG_RUN(ipt->active_filter, skb) == 0)) {
if (ipt->debug & 0x4)
printk(KERN_DEBUG "IPPP: link-active filter: resetting huptimer.\n");
lp->huptimer = 0;
Expand Down Expand Up @@ -1517,9 +1515,9 @@ int isdn_ppp_autodial_filter(struct sk_buff *skb, isdn_net_local *lp)
}

drop |= is->pass_filter
&& SK_RUN_FILTER(is->pass_filter, skb) == 0;
&& BPF_PROG_RUN(is->pass_filter, skb) == 0;
drop |= is->active_filter
&& SK_RUN_FILTER(is->active_filter, skb) == 0;
&& BPF_PROG_RUN(is->active_filter, skb) == 0;

skb_push(skb, IPPP_MAX_HEADER - 4);
return drop;
Expand Down
Loading

0 comments on commit e339756

Please sign in to comment.