Skip to content

Commit

Permalink
Merge branch 'bpf-next'
Browse files Browse the repository at this point in the history
Daniel Borkmann says:

====================
Minor BPF updates

Various minor misc updates.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Jul 30, 2015
2 parents ce7fa78 + b13138e commit 951debb
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion arch/s390/net/bpf_jit_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ static int bpf_jit_prog(struct bpf_jit *jit, struct bpf_prog *fp)
jit->lit = jit->lit_start;
jit->prg = 0;

bpf_jit_prologue(jit, fp->type == BPF_PROG_TYPE_UNSPEC);
bpf_jit_prologue(jit, bpf_prog_was_classic(fp));
for (i = 0; i < fp->len; i += insn_count) {
insn_count = bpf_jit_insn(jit, fp, i);
if (insn_count < 0)
Expand Down
2 changes: 1 addition & 1 deletion arch/sparc/net/bpf_jit_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ cond_branch: f_offset = addrs[i + filter[i].jf];
}

if (bpf_jit_enable > 1)
bpf_jit_dump(flen, proglen, pass, image);
bpf_jit_dump(flen, proglen, pass + 1, image);

if (image) {
bpf_flush_icache(image, image + proglen);
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/net/bpf_jit_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
}

if (bpf_jit_enable > 1)
bpf_jit_dump(prog->len, proglen, 0, image);
bpf_jit_dump(prog->len, proglen, pass + 1, image);

if (image) {
bpf_flush_icache(header, image + proglen);
Expand Down
16 changes: 14 additions & 2 deletions include/linux/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <linux/linkage.h>
#include <linux/printk.h>
#include <linux/workqueue.h>
#include <linux/sched.h>

#include <asm/cacheflush.h>

Expand Down Expand Up @@ -354,6 +355,16 @@ static inline unsigned int bpf_prog_size(unsigned int proglen)
offsetof(struct bpf_prog, insns[proglen]));
}

static inline bool bpf_prog_was_classic(const struct bpf_prog *prog)
{
/* When classic BPF programs have been loaded and the arch
* does not have a classic BPF JIT (anymore), they have been
* converted via bpf_migrate_filter() to eBPF and thus always
* have an unspec program type.
*/
return prog->type == BPF_PROG_TYPE_UNSPEC;
}

#define bpf_classic_proglen(fprog) (fprog->len * sizeof(fprog->filter[0]))

#ifdef CONFIG_DEBUG_SET_MODULE_RONX
Expand Down Expand Up @@ -428,8 +439,9 @@ void bpf_jit_free(struct bpf_prog *fp);
static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen,
u32 pass, void *image)
{
pr_err("flen=%u proglen=%u pass=%u image=%pK\n",
flen, proglen, pass, image);
pr_err("flen=%u proglen=%u pass=%u image=%pK from=%s pid=%d\n", flen,
proglen, pass, image, current->comm, task_pid_nr(current));

if (image)
print_hex_dump(KERN_ERR, "JIT code: ", DUMP_PREFIX_OFFSET,
16, 1, image, proglen, false);
Expand Down
2 changes: 2 additions & 0 deletions lib/test_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -4613,6 +4613,8 @@ static struct bpf_prog *generate_filter(int which, int *err)
}

fp->len = flen;
/* Type doesn't really matter here as long as it's not unspec. */
fp->type = BPF_PROG_TYPE_SOCKET_FILTER;
memcpy(fp->insnsi, fptr, fp->len * sizeof(struct bpf_insn));

bpf_prog_select_runtime(fp);
Expand Down

0 comments on commit 951debb

Please sign in to comment.