All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Quentin Monnet <quentin.monnet@netronome.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	netdev@vger.kernel.org, oss-drivers@netronome.com,
	Jesper Dangaard Brouer <brouer@redhat.com>,
	Stanislav Fomichev <sdf@google.com>
Subject: Debugging eBPF was: Re: [PATCH bpf-next 0/8] tools: bpftool: add probes for system and device
Date: Thu, 13 Dec 2018 10:49:09 -0300	[thread overview]
Message-ID: <20181213134909.GK21027@kernel.org> (raw)
In-Reply-To: <20181213130359.GG21027@kernel.org>

Em Thu, Dec 13, 2018 at 10:03:59AM -0300, Arnaldo Carvalho de Melo escreveu:
> libbpf: failed to load program 'raw_syscalls:sys_enter'
> libbpf: failed to load object 'tools/perf/examples/bpf/augmented_raw_syscalls.c'
> bpf: load objects failed: err=-4009: (Incorrect kernel version)
> event syntax error: 'tools/perf/examples/bpf/augmented_raw_syscalls.c'
>                      \___ Failed to load program for unknown reason
> 
> (add -v to see detail)
> Run 'perf list' for a list of valid events
> 
>  Usage: perf trace [<options>] [<command>]
>     or: perf trace [<options>] -- <command> [<options>]
>     or: perf trace record [<options>] [<command>]
>     or: perf trace record [<options>] -- <command> [<options>]
> 
>     -e, --event <event>   event/syscall selector. use 'perf list' to list available events
> [acme@quaco perf]$ 
> 
> Ok, out to figure this out :-)

I've changed the subject to better reflect the change in discussion,
which I think is worth as it was another topic discussed at LPC, how to
debug when somthing goes awry:

So I first tried with:

$ strace -e bpf perf trace -v -a -e open*,tools/perf/examples/bpf/augmented_raw_syscalls.o
<SNIP>
bpf: config program 'raw_syscalls:sys_enter'
bpf: config program 'raw_syscalls:sys_exit'
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERF_EVENT_ARRAY, key_size=4, value_size=4, max_entries=8, map_flags=0, inner_map_fd=0, map_name="__bpf_stdout__", map_ifindex=0}, 72) = 3
libbpf: create map __bpf_stdout__: fd=3
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERF_EVENT_ARRAY, key_size=4, value_size=4, max_entries=8, map_flags=0, inner_map_fd=0, map_name="__augmented_sys", map_ifindex=0}, 72) = 4
libbpf: create map __augmented_syscalls__: fd=4
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_ARRAY, key_size=4, value_size=1, max_entries=512, map_flags=0, inner_map_fd=0, map_name="syscalls", map_ifindex=0}, 72) = 5
libbpf: create map syscalls: fd=5
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_HASH, key_size=4, value_size=1, max_entries=64, map_flags=0, inner_map_fd=0, map_name="pids_filtered", map_ifindex=0}, 72) = 6
libbpf: create map pids_filtered: fd=6
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_TRACEPOINT, insn_cnt=55, insns=0x11ec6e0, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(4, 20, 0), prog_flags=0, prog_name="sys_enter", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS}, 72) = -1 EPERM (Operation not permitted)
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_TRACEPOINT, insn_cnt=55, insns=0x11ec6e0, license="GPL", log_level=1, log_size=262144, log_buf="", kern_version=KERNEL_VERSION(4, 20, 0), prog_flags=0, prog_name="sys_enter", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS}, 72) = -1 EPERM (Operation not permitted)
libbpf: load bpf program failed: Operation not permitted
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_KPROBE, insn_cnt=55, insns=0x11ec6e0, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(4, 20, 0), prog_flags=0, prog_name="sys_enter", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS}, 72) = -1 EPERM (Operation not permitted)
libbpf: failed to load program 'raw_syscalls:sys_enter'
libbpf: failed to load object 'tools/perf/examples/bpf/augmented_raw_syscalls.o'
bpf: load objects failed: err=-4009: (Incorrect kernel version)
event syntax error: 'tools/perf/examples/bpf/augmented_raw_syscalls.o'
                     \___ Failed to load program for unknown reason


So it can create the maps, but not attach the programs to tracepoints,
ok, now lets switch to what is happening in the kernel side:

[acme@quaco perf]$ perf ftrace -G bpf_prog_load perf trace -v -a -e open*,tools/perf/examples/bpf/augmented_raw_syscalls.o
ftrace only works for root!
[acme@quaco perf]$

Oops, so lets try as root, doing it system wide, then start the 'perf
trace' part:

[root@quaco ~]# perf ftrace -G bpf_prog_load -a
 5)               |  bpf_prog_load() {
 5)               |    __check_object_size() {
 5)   0.110 us    |      __virt_addr_valid();
 5)   0.111 us    |      check_stack_object();
 5)   0.534 us    |    }
 5)               |    capable() {
 5)               |      ns_capable_common() {
 5)               |        security_capable() {
 5)   0.102 us    |          cap_capable();
 5)   0.336 us    |        }
 5)   0.773 us    |      }
 5)   0.989 us    |    }
 5) + 18.444 us   |  }
 5)               |  bpf_prog_load() {
 5)               |    __check_object_size() {
 5)   0.117 us    |      __virt_addr_valid();
 5)   0.116 us    |      check_stack_object();
 5)   0.575 us    |    }
 5)               |    capable() {
 5)               |      ns_capable_common() {
 5)               |        security_capable() {
 5)   0.104 us    |          cap_capable();
 5)   0.318 us    |        }
 5)   0.519 us    |      }
 5)   0.722 us    |    }
 5)   1.671 us    |  }
 5)               |  bpf_prog_load() {
 5)               |    __check_object_size() {
 5)   0.105 us    |      __virt_addr_valid();
 5)   0.103 us    |      check_stack_object();
 5)   0.527 us    |    }
 5)               |    capable() {
 5)               |      ns_capable_common() {
 5)               |        security_capable() {
 5)   0.099 us    |          cap_capable();
 5)   0.315 us    |        }
 5)   0.520 us    |      }
 5)   0.715 us    |    }
 5)   5.111 us    |  }
 
 Ok, not that helpful, but should be this one:

         if (type != BPF_PROG_TYPE_SOCKET_FILTER &&
             type != BPF_PROG_TYPE_CGROUP_SKB &&
            !capable(CAP_SYS_ADMIN))
                return -EPERM;

I'll update the error message accordingly :-/

Only root can attach eBPF programs to tracepoints.

Would be really good if we could have a more restricted program type to
attach to tracepoints, one that would be able to run only in the context
of their threads and access only the pointers in the tracepoints, that
way the 'perf trace' augmented syscalls code would be usable for
non-root users just like the other 'perf' commands are, allowing us to,
as with root, to copy the pointer arguments, like:

[root@quaco ~]# cd ~acme/git/perf/tools/perf/examples/bpf
[root@quaco bpf]# perf trace -e open*,augmented_raw_syscalls.o cat /etc/passwd > /dev/null
     0.000 ( 0.007 ms): cat/29941 openat(dfd: CWD, filename: /etc/ld.so.cache, flags: CLOEXEC           ) = 3
     0.018 ( 0.004 ms): cat/29941 openat(dfd: CWD, filename: /lib64/libc.so.6, flags: CLOEXEC           ) = 3
     0.185 ( 0.005 ms): cat/29941 openat(dfd: CWD, filename: /usr/lib/locale/locale-archive, flags: CLOEXEC) = 3
     0.223 ( 0.047 ms): cat/29941 openat(dfd: CWD, filename: /etc/passwd                                ) = 3

Without that we are back to just what is present in the tracepoints, the
pointers:

[root@quaco bpf]# perf trace -e open* cat /etc/passwd > /dev/null
     0.000 ( 0.006 ms): cat/29946 openat(dfd: CWD, filename: 0xa354e8b3, flags: CLOEXEC                 ) = 3
     0.017 ( 0.004 ms): cat/29946 openat(dfd: CWD, filename: 0xa3558d00, flags: CLOEXEC                 ) = 3
     0.217 ( 0.005 ms): cat/29946 openat(dfd: CWD, filename: 0xa34d6a20, flags: CLOEXEC                 ) = 3
     0.260 ( 0.003 ms): cat/29946 openat(dfd: CWD, filename: 0xcd70cd69                                 ) = 3
[root@quaco bpf]# file augmented_raw_syscalls.o
augmented_raw_syscalls.o: ELF 64-bit LSB relocatable, eBPF, version 1 (SYSV), not stripped
[root@quaco bpf]#

- Arnaldo

  reply	other threads:[~2018-12-13 13:49 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-13 12:19 [PATCH bpf-next 0/8] tools: bpftool: add probes for system and device Quentin Monnet
2018-12-13 12:19 ` [PATCH bpf-next 1/8] tools: bpftool: add basic probe capability, probe syscall and kversion Quentin Monnet
2018-12-14  2:50   ` Stanislav Fomichev
2018-12-14 11:27     ` Quentin Monnet
2018-12-14 18:45       ` Stanislav Fomichev
2018-12-15  3:31         ` Quentin Monnet
2018-12-14 23:35   ` Daniel Borkmann
2018-12-15  3:31     ` Quentin Monnet
2018-12-13 12:19 ` [PATCH bpf-next 2/8] tools: bpftool: add probes for /proc/ eBPF parameters Quentin Monnet
2018-12-14  2:58   ` Stanislav Fomichev
2018-12-14 11:27     ` Quentin Monnet
2018-12-14 23:40   ` Daniel Borkmann
2018-12-15  3:31     ` Quentin Monnet
2018-12-16  0:14       ` Daniel Borkmann
2018-12-17 10:44         ` Quentin Monnet
2018-12-17 11:11           ` Daniel Borkmann
2018-12-13 12:19 ` [PATCH bpf-next 3/8] tools: bpftool: add probes for kernel configuration options Quentin Monnet
2018-12-14 23:56   ` Daniel Borkmann
2018-12-15  3:32     ` Quentin Monnet
2018-12-19 18:49       ` Quentin Monnet
2018-12-13 12:19 ` [PATCH bpf-next 4/8] tools: bpftool: add probes for eBPF program types Quentin Monnet
2018-12-13 12:19 ` [PATCH bpf-next 5/8] tools: bpftool: add probes for eBPF map types Quentin Monnet
2018-12-13 12:19 ` [PATCH bpf-next 6/8] tools: bpftool: add probes for eBPF helper functions Quentin Monnet
2018-12-15  0:08   ` Daniel Borkmann
2018-12-15  3:32     ` Quentin Monnet
2018-12-15 23:57       ` Daniel Borkmann
2018-12-17 10:18         ` Quentin Monnet
2018-12-18  0:42           ` Daniel Borkmann
2018-12-19 19:02             ` Quentin Monnet
2018-12-13 12:19 ` [PATCH bpf-next 7/8] tools: bpftool: add probes for a network device Quentin Monnet
2018-12-13 12:19 ` [PATCH bpf-next 8/8] tools: bpftool: add bash completion for bpftool probes Quentin Monnet
2018-12-13 13:03 ` [PATCH bpf-next 0/8] tools: bpftool: add probes for system and device Arnaldo Carvalho de Melo
2018-12-13 13:49   ` Arnaldo Carvalho de Melo [this message]
2018-12-13 20:55     ` Debugging eBPF was: " Alexei Starovoitov
2018-12-14 13:39       ` Arnaldo Carvalho de Melo
2018-12-14 11:53 ` Quentin Monnet
2018-12-14 18:21   ` Stanislav Fomichev
2018-12-14 18:41     ` [oss-drivers] " Quentin Monnet
2018-12-14 14:00 ` Arnaldo Carvalho de Melo
2018-12-14 14:56   ` Quentin Monnet
2018-12-14 17:26     ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181213134909.GK21027@kernel.org \
    --to=acme@kernel.org \
    --cc=ast@kernel.org \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@netronome.com \
    --cc=quentin.monnet@netronome.com \
    --cc=sdf@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.