mbox series

[net-next,v3,0/2] bpf/tracing: allow user space to query prog array on the same tp

Message ID 20171206220746.4038383-1-yhs@fb.com
Headers show
Series bpf/tracing: allow user space to query prog array on the same tp | expand

Message

Yonghong Song Dec. 6, 2017, 10:07 p.m. UTC
Commit e87c6bc3852b ("bpf: permit multiple bpf attachments
for a single perf event") added support to attach multiple
bpf programs to a single perf event. Given a perf event
(kprobe, uprobe, or kernel tracepoint), the perf ioctl interface
is used to query bpf programs attached to the same trace event.

There already exists a BPF_PROG_QUERY command for introspection
currently used by cgroup+bpf. We did have an implementation for
querying tracepoint+bpf through the same interface. However, it
looks cleaner to use ioctl() style of api here, since attaching
bpf prog to tracepoint/kuprobe is also done via ioctl.

Patch #1 had the core implementation and patch #2 added
a test case in tools bpf selftests suite.

Changelogs:
v2 -> v3:
  - Change uapi structure perf_event_query_bpf to be more
    clearer based on Peter's suggestion, and adjust
    other codes accordingly.
v1 -> v2:
  - Rebase on top of net-next.
  - Use existing bpf_prog_array_length function instead of
    implementing the same functionality in function
    bpf_prog_array_copy_info.

Yonghong Song (2):
  bpf/tracing: allow user space to query prog array on the same tp
  bpf/tracing: add a bpf test for new ioctl query interface

 include/linux/bpf.h                           |   4 +
 include/uapi/linux/perf_event.h               |  22 +++++
 kernel/bpf/core.c                             |  21 ++++
 kernel/events/core.c                          |   3 +
 kernel/trace/bpf_trace.c                      |  23 +++++
 tools/include/uapi/linux/perf_event.h         |  22 +++++
 tools/testing/selftests/bpf/Makefile          |   2 +-
 tools/testing/selftests/bpf/test_progs.c      | 134 ++++++++++++++++++++++++++
 tools/testing/selftests/bpf/test_tracepoint.c |  26 +++++
 9 files changed, 256 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/bpf/test_tracepoint.c

Comments

Alexei Starovoitov Dec. 9, 2017, 9:21 p.m. UTC | #1
On Wed, Dec 06, 2017 at 02:07:44PM -0800, Yonghong Song wrote:
> Commit e87c6bc3852b ("bpf: permit multiple bpf attachments
> for a single perf event") added support to attach multiple
> bpf programs to a single perf event. Given a perf event
> (kprobe, uprobe, or kernel tracepoint), the perf ioctl interface
> is used to query bpf programs attached to the same trace event.
> 
> There already exists a BPF_PROG_QUERY command for introspection
> currently used by cgroup+bpf. We did have an implementation for
> querying tracepoint+bpf through the same interface. However, it
> looks cleaner to use ioctl() style of api here, since attaching
> bpf prog to tracepoint/kuprobe is also done via ioctl.
> 
> Patch #1 had the core implementation and patch #2 added
> a test case in tools bpf selftests suite.
> 
> Changelogs:
> v2 -> v3:
>   - Change uapi structure perf_event_query_bpf to be more
>     clearer based on Peter's suggestion, and adjust
>     other codes accordingly.

Peter,
could you please ack the patch 1 ?
We'd like to route the set via bpf-next -> net-next trees.
Daniel Borkmann Dec. 11, 2017, 1:15 p.m. UTC | #2
Hey Yonghong,

On 12/06/2017 11:07 PM, Yonghong Song wrote:
> Commit e87c6bc3852b ("bpf: permit multiple bpf attachments
> for a single perf event") added support to attach multiple
> bpf programs to a single perf event. Given a perf event
> (kprobe, uprobe, or kernel tracepoint), the perf ioctl interface
> is used to query bpf programs attached to the same trace event.
> 
> There already exists a BPF_PROG_QUERY command for introspection
> currently used by cgroup+bpf. We did have an implementation for
> querying tracepoint+bpf through the same interface. However, it
> looks cleaner to use ioctl() style of api here, since attaching
> bpf prog to tracepoint/kuprobe is also done via ioctl.
> 
> Patch #1 had the core implementation and patch #2 added
> a test case in tools bpf selftests suite.
> 
> Changelogs:
> v2 -> v3:
>   - Change uapi structure perf_event_query_bpf to be more
>     clearer based on Peter's suggestion, and adjust
>     other codes accordingly.
> v1 -> v2:
>   - Rebase on top of net-next.
>   - Use existing bpf_prog_array_length function instead of
>     implementing the same functionality in function
>     bpf_prog_array_copy_info.
> 
> Yonghong Song (2):
>   bpf/tracing: allow user space to query prog array on the same tp
>   bpf/tracing: add a bpf test for new ioctl query interface

v3 doesn't build cleanly, could you take a look & fix?

Thanks,
Daniel

$ make -j4 kernel/trace/
  CHK     include/config/kernel.release
  HOSTCC  scripts/basic/fixdep
  CHK     include/generated/uapi/linux/version.h
  DESCEND  objtool
  CHK     include/generated/utsrelease.h
  HOSTCC   /home/darkstar/trees/bpf-next/tools/objtool/fixdep.o
  HOSTCC  scripts/basic/bin2c
  HOSTLD   /home/darkstar/trees/bpf-next/tools/objtool/fixdep-in.o
  LINK     /home/darkstar/trees/bpf-next/tools/objtool/fixdep
  CC       /home/darkstar/trees/bpf-next/tools/objtool/builtin-check.o
  CC       /home/darkstar/trees/bpf-next/tools/objtool/arch/x86/decode.o
  CC       /home/darkstar/trees/bpf-next/tools/objtool/builtin-orc.o
  CC       /home/darkstar/trees/bpf-next/tools/objtool/exec-cmd.o
  CC       /home/darkstar/trees/bpf-next/tools/objtool/help.o
  CC       /home/darkstar/trees/bpf-next/tools/objtool/pager.o
  CC       /home/darkstar/trees/bpf-next/tools/objtool/parse-options.o
  CC       /home/darkstar/trees/bpf-next/tools/objtool/run-command.o
  CC       /home/darkstar/trees/bpf-next/tools/objtool/sigchain.o
  CC       /home/darkstar/trees/bpf-next/tools/objtool/subcmd-config.o
  LD       /home/darkstar/trees/bpf-next/tools/objtool/arch/x86/objtool-in.o
  CC       /home/darkstar/trees/bpf-next/tools/objtool/check.o
  HOSTCC  arch/x86/tools/relocs_32.o
  HOSTCC  arch/x86/tools/relocs_64.o
  CC       /home/darkstar/trees/bpf-next/tools/objtool/orc_gen.o
  HOSTCC  arch/x86/tools/relocs_common.o
  LD       /home/darkstar/trees/bpf-next/tools/objtool/libsubcmd-in.o
  AR       /home/darkstar/trees/bpf-next/tools/objtool/libsubcmd.a
  HOSTLD  arch/x86/tools/relocs
  CC       /home/darkstar/trees/bpf-next/tools/objtool/orc_dump.o
  CC      scripts/mod/empty.o
  HOSTCC  scripts/mod/mk_elfconfig
  CC      arch/x86/purgatory/purgatory.o
  AS      arch/x86/purgatory/stack.o
  CC      scripts/mod/devicetable-offsets.s
  AS      arch/x86/purgatory/setup-x86_64.o
  HOSTCC  scripts/kallsyms
  CC      arch/x86/purgatory/sha256.o
  MKELF   scripts/mod/elfconfig.h
  CHK     scripts/mod/devicetable-offsets.h
  HOSTCC  scripts/mod/sumversion.o
  HOSTCC  scripts/pnmtologo
  HOSTCC  scripts/mod/modpost.o
  AS      arch/x86/purgatory/entry64.o
  CC      arch/x86/purgatory/string.o
  CC       /home/darkstar/trees/bpf-next/tools/objtool/elf.o
  LD      arch/x86/purgatory/purgatory.ro
  HOSTCC  scripts/conmakehash
  BIN2C   arch/x86/purgatory/kexec-purgatory.c
  CC      kernel/bounds.s
  CHK     include/generated/timeconst.h
  CHK     include/generated/bounds.h
  CC      arch/x86/kernel/asm-offsets.s
  HOSTCC  scripts/recordmcount
  CC       /home/darkstar/trees/bpf-next/tools/objtool/special.o
  CC       /home/darkstar/trees/bpf-next/tools/objtool/objtool.o
  CC       /home/darkstar/trees/bpf-next/tools/objtool/libstring.o
  CC       /home/darkstar/trees/bpf-next/tools/objtool/str_error_r.o
  LD       /home/darkstar/trees/bpf-next/tools/objtool/objtool-in.o
  HOSTCC  scripts/mod/file2alias.o
Warning: synced file at 'tools/objtool/arch/x86/lib/x86-opcode-map.txt' differs from latest kernel version at 'arch/x86/lib/x86-opcode-map.txt'
  LINK     /home/darkstar/trees/bpf-next/tools/objtool/objtool
  HOSTCC  scripts/sortextable
  CHK     include/generated/asm-offsets.h
  HOSTCC  scripts/asn1_compiler
  CALL    scripts/checksyscalls.sh
  HOSTCC  scripts/sign-file
  HOSTCC  scripts/extract-cert
  HOSTLD  scripts/mod/modpost
  CC      kernel/trace/trace_clock.o
  CC      kernel/trace/ftrace.o
  CC      kernel/trace/ring_buffer.o
  CC      kernel/trace/trace.o
  CC      kernel/trace/trace_output.o
  CC      kernel/trace/trace_seq.o
  CC      kernel/trace/trace_stat.o
  CC      kernel/trace/trace_printk.o
  CC      kernel/trace/trace_sched_switch.o
  CC      kernel/trace/trace_functions.o
  CC      kernel/trace/trace_nop.o
  CC      kernel/trace/trace_functions_graph.o
  CC      kernel/trace/blktrace.o
  CC      kernel/trace/trace_events.o
  CC      kernel/trace/trace_export.o
  CC      kernel/trace/trace_syscalls.o
  CC      kernel/trace/trace_event_perf.o
  CC      kernel/trace/trace_events_filter.o
  CC      kernel/trace/trace_events_trigger.o
  CC      kernel/trace/bpf_trace.o
  CC      kernel/trace/trace_kprobe.o
kernel/trace/bpf_trace.c: In function ‘bpf_event_query_prog_array’:
kernel/trace/bpf_trace.c:839:12: error: passing argument 2 of ‘bpf_prog_array_copy_info’ from incompatible pointer type [-Werror=incompatible-pointer-types]
            &uquery->ids,
            ^
In file included from kernel/trace/bpf_trace.c:11:0:
./include/linux/bpf.h:289:5: note: expected ‘__u32 * {aka unsigned int *}’ but argument is of type ‘__u32 (*)[]’
 int bpf_prog_array_copy_info(struct bpf_prog_array __rcu *array,
     ^~~~~~~~~~~~~~~~~~~~~~~~
  CC      kernel/trace/power-traces.o
  CC      kernel/trace/rpm-traces.o
cc1: some warnings being treated as errors
scripts/Makefile.build:310: recipe for target 'kernel/trace/bpf_trace.o' failed
make[1]: *** [kernel/trace/bpf_trace.o] Error 1
make[1]: *** Waiting for unfinished jobs....
Makefile:1674: recipe for target 'kernel/trace/' failed
make: *** [kernel/trace/] Error 2