Re: [PATCH net] bpf: fix samples to add fake KBUILD_MODNAME

2016-10-29 Thread David Miller
From: Daniel Borkmann 
Date: Wed, 26 Oct 2016 00:37:53 +0200

> Some of the sample files are causing issues when they are loaded with tc
> and cls_bpf, meaning tc bails out while trying to parse the resulting ELF
> file as program/map/etc sections are not present, which can be easily
> spotted with readelf(1).
> 
> Currently, BPF samples are including some of the kernel headers and mid
> term we should change them to refrain from this, really. When dynamic
> debugging is enabled, we bail out due to undeclared KBUILD_MODNAME, which
> is easily overlooked in the build as clang spills this along with other
> noisy warnings from various header includes, and llc still generates an
> ELF file with mentioned characteristics. For just playing around with BPF
> examples, this can be a bit of a hurdle to take.
> 
> Just add a fake KBUILD_MODNAME as a band-aid to fix the issue, same is
> done in xdp*_kern samples already.
> 
> Fixes: 65d472fb007d ("samples/bpf: add 'pointer to packet' tests")
> Fixes: 6afb1e28b859 ("samples/bpf: Add tunnel set/get tests.")
> Fixes: a3f74617340b ("cgroup: bpf: Add an example to do cgroup checking in 
> BPF")
> Reported-by: Chandrasekar Kannan 
> Signed-off-by: Daniel Borkmann 

Applied.


Re: [PATCH net] bpf: fix samples to add fake KBUILD_MODNAME

2016-10-26 Thread Alexei Starovoitov
On Wed, Oct 26, 2016 at 09:01:48AM +0200, Daniel Borkmann wrote:
> On 10/26/2016 03:17 AM, Alexei Starovoitov wrote:
> >On Wed, Oct 26, 2016 at 12:37:53AM +0200, Daniel Borkmann wrote:
> >>Some of the sample files are causing issues when they are loaded with tc
> >>and cls_bpf, meaning tc bails out while trying to parse the resulting ELF
> >>file as program/map/etc sections are not present, which can be easily
> >>spotted with readelf(1).
> >>
> >>Currently, BPF samples are including some of the kernel headers and mid
> >>term we should change them to refrain from this, really. When dynamic
> >>debugging is enabled, we bail out due to undeclared KBUILD_MODNAME, which
> >>is easily overlooked in the build as clang spills this along with other
> >>noisy warnings from various header includes, and llc still generates an
> >>ELF file with mentioned characteristics. For just playing around with BPF
> >>examples, this can be a bit of a hurdle to take.
> >>
> >>Just add a fake KBUILD_MODNAME as a band-aid to fix the issue, same is
> >>done in xdp*_kern samples already.
> >>
> >>Fixes: 65d472fb007d ("samples/bpf: add 'pointer to packet' tests")
> >>Fixes: 6afb1e28b859 ("samples/bpf: Add tunnel set/get tests.")
> >>Fixes: a3f74617340b ("cgroup: bpf: Add an example to do cgroup checking in 
> >>BPF")
> >>Reported-by: Chandrasekar Kannan 
> >>Signed-off-by: Daniel Borkmann 
> >>---
> >>  samples/bpf/parse_ldabs.c| 1 +
> >>  samples/bpf/parse_simple.c   | 1 +
> >>  samples/bpf/parse_varlen.c   | 1 +
> >>  samples/bpf/tcbpf1_kern.c| 1 +
> >>  samples/bpf/tcbpf2_kern.c| 1 +
> >>  samples/bpf/test_cgrp2_tc_kern.c | 1 +
> >>  6 files changed, 6 insertions(+)
> >
> >It's also needed for all of tracex*_kern.c, right?
> 
> Rest compiles just fine for me and readelf output looks good on all
> tracex*_kern.o, too.
> 
> I see just warnings coming from various kernel header inclusions (see
> log), but no errors anymore.

ahh. good to know. I guess networking examples include some header
with dynamic debug that tracing examples don't.
Thanks for checking.

> ./include/linux/cgroup-defs.h:322:16: warning: field 'cgrp' with variable 
> sized type 'struct cgroup' not at the end of a struct or class is a GNU 
> extension [-Wgnu-variable-sized-type-not-at-end]
> struct cgroup cgrp;
>   ^
> 2 warnings generated.

this cgroup warning is crazy annoying and would have to be fixed anyway
for kernel to be compiled with clang.



Re: [PATCH net] bpf: fix samples to add fake KBUILD_MODNAME

2016-10-26 Thread Daniel Borkmann

On 10/26/2016 03:17 AM, Alexei Starovoitov wrote:

On Wed, Oct 26, 2016 at 12:37:53AM +0200, Daniel Borkmann wrote:

Some of the sample files are causing issues when they are loaded with tc
and cls_bpf, meaning tc bails out while trying to parse the resulting ELF
file as program/map/etc sections are not present, which can be easily
spotted with readelf(1).

Currently, BPF samples are including some of the kernel headers and mid
term we should change them to refrain from this, really. When dynamic
debugging is enabled, we bail out due to undeclared KBUILD_MODNAME, which
is easily overlooked in the build as clang spills this along with other
noisy warnings from various header includes, and llc still generates an
ELF file with mentioned characteristics. For just playing around with BPF
examples, this can be a bit of a hurdle to take.

Just add a fake KBUILD_MODNAME as a band-aid to fix the issue, same is
done in xdp*_kern samples already.

Fixes: 65d472fb007d ("samples/bpf: add 'pointer to packet' tests")
Fixes: 6afb1e28b859 ("samples/bpf: Add tunnel set/get tests.")
Fixes: a3f74617340b ("cgroup: bpf: Add an example to do cgroup checking in BPF")
Reported-by: Chandrasekar Kannan 
Signed-off-by: Daniel Borkmann 
---
  samples/bpf/parse_ldabs.c| 1 +
  samples/bpf/parse_simple.c   | 1 +
  samples/bpf/parse_varlen.c   | 1 +
  samples/bpf/tcbpf1_kern.c| 1 +
  samples/bpf/tcbpf2_kern.c| 1 +
  samples/bpf/test_cgrp2_tc_kern.c | 1 +
  6 files changed, 6 insertions(+)


It's also needed for all of tracex*_kern.c, right?


Rest compiles just fine for me and readelf output looks good on all
tracex*_kern.o, too.

I see just warnings coming from various kernel header inclusions (see
log), but no errors anymore.
/home/darkstar/net/samples/bpf/trace_output_user.c:64:6: warning: no previous 
prototype for ‘perf_event_read’ [-Wmissing-prototypes]
 void perf_event_read(print_fn fn)
  ^
In file included from /home/darkstar/net/samples/bpf/sockex2_kern.c:8:
In file included from ./include/uapi/linux/if_tunnel.h:6:
In file included from ./include/linux/ip.h:20:
In file included from ./include/linux/skbuff.h:29:
In file included from ./include/linux/net.h:28:
./include/linux/fs.h:2693:9: warning: comparison of unsigned enum expression < 
0 is always false [-Wtautological-compare]
if (id < 0 || id >= READING_MAX_ID)
~~ ^ ~
In file included from /home/darkstar/net/samples/bpf/sockex2_kern.c:8:
In file included from ./include/uapi/linux/if_tunnel.h:6:
In file included from ./include/linux/ip.h:20:
In file included from ./include/linux/skbuff.h:30:
In file included from ./include/linux/textsearch.h:8:
In file included from ./include/linux/slab.h:118:
In file included from ./include/linux/kasan.h:4:
In file included from ./include/linux/sched.h:61:
./include/linux/cgroup-defs.h:322:16: warning: field 'cgrp' with variable sized 
type 'struct cgroup' not at the end of a struct or class is a GNU extension 
[-Wgnu-variable-sized-type-not-at-end]
struct cgroup cgrp;
  ^
2 warnings generated.
In file included from /home/darkstar/net/samples/bpf/sockex3_kern.c:14:
In file included from ./include/uapi/linux/if_tunnel.h:6:
In file included from ./include/linux/ip.h:20:
In file included from ./include/linux/skbuff.h:29:
In file included from ./include/linux/net.h:28:
./include/linux/fs.h:2693:9: warning: comparison of unsigned enum expression < 
0 is always false [-Wtautological-compare]
if (id < 0 || id >= READING_MAX_ID)
~~ ^ ~
In file included from /home/darkstar/net/samples/bpf/sockex3_kern.c:14:
In file included from ./include/uapi/linux/if_tunnel.h:6:
In file included from ./include/linux/ip.h:20:
In file included from ./include/linux/skbuff.h:30:
In file included from ./include/linux/textsearch.h:8:
In file included from ./include/linux/slab.h:118:
In file included from ./include/linux/kasan.h:4:
In file included from ./include/linux/sched.h:61:
./include/linux/cgroup-defs.h:322:16: warning: field 'cgrp' with variable sized 
type 'struct cgroup' not at the end of a struct or class is a GNU extension 
[-Wgnu-variable-sized-type-not-at-end]
struct cgroup cgrp;
  ^
2 warnings generated.
In file included from /home/darkstar/net/samples/bpf/tracex1_kern.c:7:
In file included from ./include/linux/skbuff.h:29:
In file included from ./include/linux/net.h:28:
./include/linux/fs.h:2693:9: warning: comparison of unsigned enum expression < 
0 is always false [-Wtautological-compare]
if (id < 0 || id >= READING_MAX_ID)
~~ ^ ~
In file included from /home/darkstar/net/samples/bpf/tracex1_kern.c:7:
In file included from ./include/linux/skbuff.h:30:
In file included from ./include/linux/textsearch.h:8:
In file included from ./include/linux/slab.h:118:
In file included from ./include/linux/kasan.h:4:
In file included from ./include/linux/sched.h:61:

Re: [PATCH net] bpf: fix samples to add fake KBUILD_MODNAME

2016-10-25 Thread Alexei Starovoitov
On Wed, Oct 26, 2016 at 12:37:53AM +0200, Daniel Borkmann wrote:
> Some of the sample files are causing issues when they are loaded with tc
> and cls_bpf, meaning tc bails out while trying to parse the resulting ELF
> file as program/map/etc sections are not present, which can be easily
> spotted with readelf(1).
> 
> Currently, BPF samples are including some of the kernel headers and mid
> term we should change them to refrain from this, really. When dynamic
> debugging is enabled, we bail out due to undeclared KBUILD_MODNAME, which
> is easily overlooked in the build as clang spills this along with other
> noisy warnings from various header includes, and llc still generates an
> ELF file with mentioned characteristics. For just playing around with BPF
> examples, this can be a bit of a hurdle to take.
> 
> Just add a fake KBUILD_MODNAME as a band-aid to fix the issue, same is
> done in xdp*_kern samples already.
> 
> Fixes: 65d472fb007d ("samples/bpf: add 'pointer to packet' tests")
> Fixes: 6afb1e28b859 ("samples/bpf: Add tunnel set/get tests.")
> Fixes: a3f74617340b ("cgroup: bpf: Add an example to do cgroup checking in 
> BPF")
> Reported-by: Chandrasekar Kannan 
> Signed-off-by: Daniel Borkmann 
> ---
>  samples/bpf/parse_ldabs.c| 1 +
>  samples/bpf/parse_simple.c   | 1 +
>  samples/bpf/parse_varlen.c   | 1 +
>  samples/bpf/tcbpf1_kern.c| 1 +
>  samples/bpf/tcbpf2_kern.c| 1 +
>  samples/bpf/test_cgrp2_tc_kern.c | 1 +
>  6 files changed, 6 insertions(+)

It's also needed for all of tracex*_kern.c, right?

For networking samlpes we probably should get rid of kernel headers.
I guess they were there by copy-paste mistake from tracing, since
tracing samples actually need to include them, since they do bpf_probe_read
into kernel data structures.
For this patch in the mean time:
Acked-by: Alexei Starovoitov