netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/4] Minor BPF updates
@ 2015-07-30 10:42 Daniel Borkmann
  2015-07-30 10:42 ` [PATCH net-next 1/4] test_bpf: assign type to native eBPF test cases Daniel Borkmann
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Daniel Borkmann @ 2015-07-30 10:42 UTC (permalink / raw)
  To: davem; +Cc: ast, holzheu, netdev, Daniel Borkmann

Various minor misc updates.

Thanks!

Daniel Borkmann (4):
  test_bpf: assign type to native eBPF test cases
  bpf: provide helper that indicates eBPF was migrated
  bpf, x86/sparc: show actual number of passes in bpf_jit_dump
  bpf: also show process name/pid in bpf_jit_dump

 arch/s390/net/bpf_jit_comp.c  |  2 +-
 arch/sparc/net/bpf_jit_comp.c |  2 +-
 arch/x86/net/bpf_jit_comp.c   |  2 +-
 include/linux/filter.h        | 16 ++++++++++++++--
 lib/test_bpf.c                |  2 ++
 5 files changed, 19 insertions(+), 5 deletions(-)

-- 
1.9.3

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH net-next 1/4] test_bpf: assign type to native eBPF test cases
  2015-07-30 10:42 [PATCH net-next 0/4] Minor BPF updates Daniel Borkmann
@ 2015-07-30 10:42 ` Daniel Borkmann
  2015-07-30 17:14   ` Alexei Starovoitov
  2015-07-30 10:42 ` [PATCH net-next 2/4] bpf: provide helper that indicates eBPF was migrated Daniel Borkmann
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Daniel Borkmann @ 2015-07-30 10:42 UTC (permalink / raw)
  To: davem; +Cc: ast, holzheu, netdev, Daniel Borkmann

As JITs start to perform optimizations whether to clear A and X on eBPF
programs in the prologue, we should actually assign a program type to the
native eBPF test cases. It doesn't really matter which program type, as
these instructions don't go through the verifier, but it needs to be a
type != BPF_PROG_TYPE_UNSPEC. This reflects eBPF programs loaded via bpf(2)
system call (!= type unspec) vs. classic BPF to eBPF migrations (== type
unspec).

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Cc: Michael Holzheu <holzheu@linux.vnet.ibm.com>
---
 lib/test_bpf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index 8b5e66f..3afddf2 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -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);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net-next 2/4] bpf: provide helper that indicates eBPF was migrated
  2015-07-30 10:42 [PATCH net-next 0/4] Minor BPF updates Daniel Borkmann
  2015-07-30 10:42 ` [PATCH net-next 1/4] test_bpf: assign type to native eBPF test cases Daniel Borkmann
@ 2015-07-30 10:42 ` Daniel Borkmann
  2015-07-30 17:15   ` Alexei Starovoitov
  2015-07-30 10:42 ` [PATCH net-next 3/4] bpf, x86/sparc: show actual number of passes in bpf_jit_dump Daniel Borkmann
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Daniel Borkmann @ 2015-07-30 10:42 UTC (permalink / raw)
  To: davem; +Cc: ast, holzheu, netdev, Daniel Borkmann

During recent discussions we had with Michael, we found that it would
be useful to have an indicator that tells the JIT that an eBPF program
had been migrated from classic instructions into eBPF instructions, as
only in that case A and X need to be cleared in the prologue. Such eBPF
programs do not set a particular type, but all have BPF_PROG_TYPE_UNSPEC.
Thus, introduce a small helper for cde66c2d88da ("s390/bpf: Only clear
A and X for converted BPF programs") and possibly others in future.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Cc: Michael Holzheu <holzheu@linux.vnet.ibm.com>
---
 arch/s390/net/bpf_jit_comp.c |  2 +-
 include/linux/filter.h       | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
index bbbac6d..9f4bbc0 100644
--- a/arch/s390/net/bpf_jit_comp.c
+++ b/arch/s390/net/bpf_jit_comp.c
@@ -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)
diff --git a/include/linux/filter.h b/include/linux/filter.h
index 69d0055..6b02549 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -354,6 +354,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
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net-next 3/4] bpf, x86/sparc: show actual number of passes in bpf_jit_dump
  2015-07-30 10:42 [PATCH net-next 0/4] Minor BPF updates Daniel Borkmann
  2015-07-30 10:42 ` [PATCH net-next 1/4] test_bpf: assign type to native eBPF test cases Daniel Borkmann
  2015-07-30 10:42 ` [PATCH net-next 2/4] bpf: provide helper that indicates eBPF was migrated Daniel Borkmann
@ 2015-07-30 10:42 ` Daniel Borkmann
  2015-07-30 17:15   ` Alexei Starovoitov
  2015-07-30 10:42 ` [PATCH net-next 4/4] bpf: also show process name/pid " Daniel Borkmann
  2015-07-30 18:13 ` [PATCH net-next 0/4] Minor BPF updates David Miller
  4 siblings, 1 reply; 10+ messages in thread
From: Daniel Borkmann @ 2015-07-30 10:42 UTC (permalink / raw)
  To: davem; +Cc: ast, holzheu, netdev, Daniel Borkmann

When bpf_jit_compile() got split into two functions via commit
f3c2af7ba17a ("net: filter: x86: split bpf_jit_compile()"), bpf_jit_dump()
was changed to always show 0 as number of compiler passes. Change it to
dump the actual number. Also on sparc, we count passes starting from 0,
so add 1 for the debug dump as well.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
---
 arch/sparc/net/bpf_jit_comp.c | 2 +-
 arch/x86/net/bpf_jit_comp.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/sparc/net/bpf_jit_comp.c b/arch/sparc/net/bpf_jit_comp.c
index 7931eee..f8b9f71 100644
--- a/arch/sparc/net/bpf_jit_comp.c
+++ b/arch/sparc/net/bpf_jit_comp.c
@@ -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);
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 6c335a8..c08000b 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -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);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net-next 4/4] bpf: also show process name/pid in bpf_jit_dump
  2015-07-30 10:42 [PATCH net-next 0/4] Minor BPF updates Daniel Borkmann
                   ` (2 preceding siblings ...)
  2015-07-30 10:42 ` [PATCH net-next 3/4] bpf, x86/sparc: show actual number of passes in bpf_jit_dump Daniel Borkmann
@ 2015-07-30 10:42 ` Daniel Borkmann
  2015-07-30 17:18   ` Alexei Starovoitov
  2015-07-30 18:13 ` [PATCH net-next 0/4] Minor BPF updates David Miller
  4 siblings, 1 reply; 10+ messages in thread
From: Daniel Borkmann @ 2015-07-30 10:42 UTC (permalink / raw)
  To: davem; +Cc: ast, holzheu, netdev, Daniel Borkmann

It can be useful for testing to see the actual process/pid who is loading
a given filter. I was running some BPF test program and noticed unusual
filter loads from time to time, triggered by some other application in the
background. bpf_jit_disasm is still working after this change.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
---
 include/linux/filter.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/linux/filter.h b/include/linux/filter.h
index 6b02549..fa2cab9 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -12,6 +12,7 @@
 #include <linux/linkage.h>
 #include <linux/printk.h>
 #include <linux/workqueue.h>
+#include <linux/sched.h>
 
 #include <asm/cacheflush.h>
 
@@ -438,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);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next 1/4] test_bpf: assign type to native eBPF test cases
  2015-07-30 10:42 ` [PATCH net-next 1/4] test_bpf: assign type to native eBPF test cases Daniel Borkmann
@ 2015-07-30 17:14   ` Alexei Starovoitov
  0 siblings, 0 replies; 10+ messages in thread
From: Alexei Starovoitov @ 2015-07-30 17:14 UTC (permalink / raw)
  To: Daniel Borkmann, davem; +Cc: holzheu, netdev

On 7/30/15 3:42 AM, Daniel Borkmann wrote:
> As JITs start to perform optimizations whether to clear A and X on eBPF
> programs in the prologue, we should actually assign a program type to the
> native eBPF test cases. It doesn't really matter which program type, as
> these instructions don't go through the verifier, but it needs to be a
> type != BPF_PROG_TYPE_UNSPEC. This reflects eBPF programs loaded via bpf(2)
> system call (!= type unspec) vs. classic BPF to eBPF migrations (== type
> unspec).
>
> Signed-off-by: Daniel Borkmann<daniel@iogearbox.net>
> Cc: Michael Holzheu<holzheu@linux.vnet.ibm.com>

Acked-by: Alexei Starovoitov <ast@plumgrid.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next 2/4] bpf: provide helper that indicates eBPF was migrated
  2015-07-30 10:42 ` [PATCH net-next 2/4] bpf: provide helper that indicates eBPF was migrated Daniel Borkmann
@ 2015-07-30 17:15   ` Alexei Starovoitov
  0 siblings, 0 replies; 10+ messages in thread
From: Alexei Starovoitov @ 2015-07-30 17:15 UTC (permalink / raw)
  To: Daniel Borkmann, davem; +Cc: holzheu, netdev

On 7/30/15 3:42 AM, Daniel Borkmann wrote:
> During recent discussions we had with Michael, we found that it would
> be useful to have an indicator that tells the JIT that an eBPF program
> had been migrated from classic instructions into eBPF instructions, as
> only in that case A and X need to be cleared in the prologue. Such eBPF
> programs do not set a particular type, but all have BPF_PROG_TYPE_UNSPEC.
> Thus, introduce a small helper for cde66c2d88da ("s390/bpf: Only clear
> A and X for converted BPF programs") and possibly others in future.
>
> Signed-off-by: Daniel Borkmann<daniel@iogearbox.net>
> Cc: Michael Holzheu<holzheu@linux.vnet.ibm.com>

Acked-by: Alexei Starovoitov <ast@plumgrid.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next 3/4] bpf, x86/sparc: show actual number of passes in bpf_jit_dump
  2015-07-30 10:42 ` [PATCH net-next 3/4] bpf, x86/sparc: show actual number of passes in bpf_jit_dump Daniel Borkmann
@ 2015-07-30 17:15   ` Alexei Starovoitov
  0 siblings, 0 replies; 10+ messages in thread
From: Alexei Starovoitov @ 2015-07-30 17:15 UTC (permalink / raw)
  To: Daniel Borkmann, davem; +Cc: holzheu, netdev

On 7/30/15 3:42 AM, Daniel Borkmann wrote:
> When bpf_jit_compile() got split into two functions via commit
> f3c2af7ba17a ("net: filter: x86: split bpf_jit_compile()"), bpf_jit_dump()
> was changed to always show 0 as number of compiler passes. Change it to
> dump the actual number. Also on sparc, we count passes starting from 0,
> so add 1 for the debug dump as well.
>
> Signed-off-by: Daniel Borkmann<daniel@iogearbox.net>

Acked-by: Alexei Starovoitov <ast@plumgrid.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next 4/4] bpf: also show process name/pid in bpf_jit_dump
  2015-07-30 10:42 ` [PATCH net-next 4/4] bpf: also show process name/pid " Daniel Borkmann
@ 2015-07-30 17:18   ` Alexei Starovoitov
  0 siblings, 0 replies; 10+ messages in thread
From: Alexei Starovoitov @ 2015-07-30 17:18 UTC (permalink / raw)
  To: Daniel Borkmann, davem; +Cc: holzheu, netdev

On 7/30/15 3:42 AM, Daniel Borkmann wrote:
> It can be useful for testing to see the actual process/pid who is loading
> a given filter. I was running some BPF test program and noticed unusual
> filter loads from time to time, triggered by some other application in the
> background. bpf_jit_disasm is still working after this change.
>
> Signed-off-by: Daniel Borkmann<daniel@iogearbox.net>

Acked-by: Alexei Starovoitov <ast@plumgrid.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next 0/4] Minor BPF updates
  2015-07-30 10:42 [PATCH net-next 0/4] Minor BPF updates Daniel Borkmann
                   ` (3 preceding siblings ...)
  2015-07-30 10:42 ` [PATCH net-next 4/4] bpf: also show process name/pid " Daniel Borkmann
@ 2015-07-30 18:13 ` David Miller
  4 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2015-07-30 18:13 UTC (permalink / raw)
  To: daniel; +Cc: ast, holzheu, netdev

From: Daniel Borkmann <daniel@iogearbox.net>
Date: Thu, 30 Jul 2015 12:42:45 +0200

> Various minor misc updates.

Series applied, thanks Daniel.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-07-30 18:13 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-30 10:42 [PATCH net-next 0/4] Minor BPF updates Daniel Borkmann
2015-07-30 10:42 ` [PATCH net-next 1/4] test_bpf: assign type to native eBPF test cases Daniel Borkmann
2015-07-30 17:14   ` Alexei Starovoitov
2015-07-30 10:42 ` [PATCH net-next 2/4] bpf: provide helper that indicates eBPF was migrated Daniel Borkmann
2015-07-30 17:15   ` Alexei Starovoitov
2015-07-30 10:42 ` [PATCH net-next 3/4] bpf, x86/sparc: show actual number of passes in bpf_jit_dump Daniel Borkmann
2015-07-30 17:15   ` Alexei Starovoitov
2015-07-30 10:42 ` [PATCH net-next 4/4] bpf: also show process name/pid " Daniel Borkmann
2015-07-30 17:18   ` Alexei Starovoitov
2015-07-30 18:13 ` [PATCH net-next 0/4] Minor BPF updates David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).