Skip to content
  1. Mar 14, 2020
    • Jiri Olsa's avatar
      x86/mm: Rename is_kernel_text to __is_kernel_text · b56cd05c
      Jiri Olsa authored
      
      
      The kbuild test robot reported compile issue on x86 in one of
      the following patches that adds <linux/kallsyms.h> include into
      <linux/bpf.h>, which is picked up by init_32.c object.
      
      The problem is that <linux/kallsyms.h> defines global function
      is_kernel_text which colides with the static function of the
      same name defined in init_32.c:
      
        $ make ARCH=i386
        ...
        >> arch/x86/mm/init_32.c:241:19: error: redefinition of 'is_kernel_text'
          static inline int is_kernel_text(unsigned long addr)
                            ^~~~~~~~~~~~~~
         In file included from include/linux/bpf.h:21:0,
                          from include/linux/bpf-cgroup.h:5,
                          from include/linux/cgroup-defs.h:22,
                          from include/linux/cgroup.h:28,
                          from include/linux/hugetlb.h:9,
                          from arch/x86/mm/init_32.c:18:
         include/linux/kallsyms.h:31:19: note: previous definition of 'is_kernel_text' was here
          static inline int is_kernel_text(unsigned long addr)
      
      Renaming the init_32.c is_kernel_text function to __is_kernel_text.
      
      Reported-by: default avatarkbuild test robot <lkp@intel.com>
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarSong Liu <songliubraving@fb.com>
      Link: https://lore.kernel.org/bpf/20200312195610.346362-2-jolsa@kernel.org
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      b56cd05c
    • Andrii Nakryiko's avatar
      bpf: Abstract away entire bpf_link clean up procedure · 98868668
      Andrii Nakryiko authored
      
      
      Instead of requiring users to do three steps for cleaning up bpf_link, its
      anon_inode file, and unused fd, abstract that away into bpf_link_cleanup()
      helper. bpf_link_defunct() is removed, as it shouldn't be needed as an
      individual operation anymore.
      
      v1->v2:
      - keep bpf_link_cleanup() static for now (Daniel).
      
      Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Link: https://lore.kernel.org/bpf/20200313002128.2028680-1-andriin@fb.com
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      98868668
    • Andrii Nakryiko's avatar
      selftests/bpf: Make tcp_rtt test more robust to failures · 4cd729fa
      Andrii Nakryiko authored
      Switch to non-blocking accept and wait for server thread to exit before
      proceeding. I noticed that sometimes tcp_rtt server thread failure would
      "spill over" into other tests (that would run after tcp_rtt), probably just
      because server thread exits much later and tcp_rtt doesn't wait for it.
      
      v1->v2:
        - add usleep() while waiting on initial non-blocking accept() (Stanislav);
      
      Fixes: 8a03222f
      
       ("selftests/bpf: test_progs: fix client/server race in tcp_rtt")
      Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Reviewed-by: default avatarStanislav Fomichev <sdf@google.com>
      Link: https://lore.kernel.org/bpf/20200311222749.458015-1-andriin@fb.com
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      4cd729fa
    • Andrii Nakryiko's avatar
      selftests/bpf: Guarantee that useep() calls nanosleep() syscall · 2b5cf9fb
      Andrii Nakryiko authored
      
      
      Some implementations of C runtime library won't call nanosleep() syscall from
      usleep(). But a bunch of kprobe/tracepoint selftests rely on nanosleep being
      called to trigger them. To make this more reliable, "override" usleep
      implementation and call nanosleep explicitly.
      
      Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Cc: Julia Kartseva <hex@fb.com>
      Link: https://lore.kernel.org/bpf/20200311185345.3874602-1-andriin@fb.com
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      2b5cf9fb
    • Quentin Monnet's avatar
      tools: bpftool: Restore message on failure to guess program type · 6ae32b29
      Quentin Monnet authored
      In commit 4a3d6c6a
      
       ("libbpf: Reduce log level for custom section
      names"), log level for messages for libbpf_attach_type_by_name() and
      libbpf_prog_type_by_name() was downgraded from "info" to "debug". The
      latter function, in particular, is used by bpftool when attempting to
      load programs, and this change caused bpftool to exit with no hint or
      error message when it fails to detect the type of the program to load
      (unless "-d" option was provided).
      
      To help users understand why bpftool fails to load the program, let's do
      a second run of the function with log level in "debug" mode in case of
      failure.
      
      Before:
      
          # bpftool prog load sample_ret0.o /sys/fs/bpf/sample_ret0
          # echo $?
          255
      
      Or really verbose with -d flag:
      
          # bpftool -d prog load sample_ret0.o /sys/fs/bpf/sample_ret0
          libbpf: loading sample_ret0.o
          libbpf: section(1) .strtab, size 134, link 0, flags 0, type=3
          libbpf: skip section(1) .strtab
          libbpf: section(2) .text, size 16, link 0, flags 6, type=1
          libbpf: found program .text
          libbpf: section(3) .debug_abbrev, size 55, link 0, flags 0, type=1
          libbpf: skip section(3) .debug_abbrev
          libbpf: section(4) .debug_info, size 75, link 0, flags 0, type=1
          libbpf: skip section(4) .debug_info
          libbpf: section(5) .rel.debug_info, size 32, link 14, flags 0, type=9
          libbpf: skip relo .rel.debug_info(5) for section(4)
          libbpf: section(6) .debug_str, size 150, link 0, flags 30, type=1
          libbpf: skip section(6) .debug_str
          libbpf: section(7) .BTF, size 155, link 0, flags 0, type=1
          libbpf: section(8) .BTF.ext, size 80, link 0, flags 0, type=1
          libbpf: section(9) .rel.BTF.ext, size 32, link 14, flags 0, type=9
          libbpf: skip relo .rel.BTF.ext(9) for section(8)
          libbpf: section(10) .debug_frame, size 40, link 0, flags 0, type=1
          libbpf: skip section(10) .debug_frame
          libbpf: section(11) .rel.debug_frame, size 16, link 14, flags 0, type=9
          libbpf: skip relo .rel.debug_frame(11) for section(10)
          libbpf: section(12) .debug_line, size 74, link 0, flags 0, type=1
          libbpf: skip section(12) .debug_line
          libbpf: section(13) .rel.debug_line, size 16, link 14, flags 0, type=9
          libbpf: skip relo .rel.debug_line(13) for section(12)
          libbpf: section(14) .symtab, size 96, link 1, flags 0, type=2
          libbpf: looking for externs among 4 symbols...
          libbpf: collected 0 externs total
          libbpf: failed to guess program type from ELF section '.text'
          libbpf: supported section(type) names are: socket sk_reuseport kprobe/ [...]
      
      After:
      
          # bpftool prog load sample_ret0.o /sys/fs/bpf/sample_ret0
          libbpf: failed to guess program type from ELF section '.text'
          libbpf: supported section(type) names are: socket sk_reuseport kprobe/ [...]
      
      Signed-off-by: default avatarQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
      Link: https://lore.kernel.org/bpf/20200311021205.9755-1-quentin@isovalent.com
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      6ae32b29
  2. Mar 13, 2020
  3. Mar 12, 2020
    • Tobias Klauser's avatar
      bpftool: Use linux/types.h from source tree for profiler build · fe4eb069
      Tobias Klauser authored
      
      
      When compiling bpftool on a system where the /usr/include/asm symlink
      doesn't exist (e.g. on an Ubuntu system without gcc-multilib installed),
      the build fails with:
      
          CLANG    skeleton/profiler.bpf.o
        In file included from skeleton/profiler.bpf.c:4:
        In file included from /usr/include/linux/bpf.h:11:
        /usr/include/linux/types.h:5:10: fatal error: 'asm/types.h' file not found
        #include <asm/types.h>
                 ^~~~~~~~~~~~~
        1 error generated.
        make: *** [Makefile:123: skeleton/profiler.bpf.o] Error 1
      
      This indicates that the build is using linux/types.h from system headers
      instead of source tree headers.
      
      To fix this, adjust the clang search path to include the necessary
      headers from tools/testing/selftests/bpf/include/uapi and
      tools/include/uapi. Also use __bitwise__ instead of __bitwise in
      skeleton/profiler.h to avoid clashing with the definition in
      tools/testing/selftests/bpf/include/uapi/linux/types.h.
      
      Signed-off-by: default avatarTobias Klauser <tklauser@distanz.ch>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Reviewed-by: default avatarQuentin Monnet <quentin@isovalent.com>
      Link: https://lore.kernel.org/bpf/20200312130330.32239-1-tklauser@distanz.ch
      fe4eb069
  4. Mar 11, 2020
    • Andrii Nakryiko's avatar
      tools/runqslower: Add BPF_F_CURRENT_CPU for running selftest on older kernels · 37ccc12b
      Andrii Nakryiko authored
      Libbpf compiles and runs subset of selftests on each PR in its Github mirror
      repository. To allow still building up-to-date selftests against outdated
      kernel images, add back BPF_F_CURRENT_CPU definitions back.
      
      N.B. BCC's runqslower version ([0]) doesn't need BPF_F_CURRENT_CPU due to use of
      locally checked in vmlinux.h, generated against kernel with 1aae4bdd ("bpf:
      Switch BPF UAPI #define constants used from BPF program side to enums")
      applied.
      
        [0] https://github.com/iovisor/bcc/pull/2809
      
      Fixes: 367d82f1
      
       (" tools/runqslower: Drop copy/pasted BPF_F_CURRENT_CPU definiton")
      Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20200311043010.530620-1-andriin@fb.com
      37ccc12b
    • Alexei Starovoitov's avatar
      bpf: Fix trampoline generation for fmod_ret programs · 13fac1d8
      Alexei Starovoitov authored
      fmod_ret progs are emitted as:
      
      start = __bpf_prog_enter();
      call fmod_ret
      *(u64 *)(rbp - 8) = rax
      __bpf_prog_exit(, start);
      test eax, eax
      jne do_fexit
      
      That 'test eax, eax' is working by accident. The compiler is free to use rax
      inside __bpf_prog_exit() or inside functions that __bpf_prog_exit() is calling.
      Which caused "test_progs -t modify_return" to sporadically fail depending on
      compiler version and kconfig. Fix it by using 'cmp [rbp - 8], 0' instead of
      'test eax, eax'.
      
      Fixes: ae240823
      
       ("bpf: Introduce BPF_MODIFY_RETURN")
      Reported-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Acked-by: default avatarKP Singh <kpsingh@google.com>
      Link: https://lore.kernel.org/bpf/20200311003906.3643037-1-ast@kernel.org
      13fac1d8
    • Andrii Nakryiko's avatar
      bpf: Add bpf_link_new_file that doesn't install FD · babf3164
      Andrii Nakryiko authored
      
      
      Add bpf_link_new_file() API for cases when we need to ensure anon_inode is
      successfully created before we proceed with expensive BPF program attachment
      procedure, which will require equally (if not more so) expensive and
      potentially failing compensation detachment procedure just because anon_inode
      creation failed. This API allows to simplify code by ensuring first that
      anon_inode is created and after BPF program is attached proceed with
      fd_install() that can't fail.
      
      After anon_inode file is created, link can't be just kfree()'d anymore,
      because its destruction will be performed by deferred file_operations->release
      call. For this, bpf_link API required specifying two separate operations:
      release() and dealloc(), former performing detachment only, while the latter
      frees memory used by bpf_link itself. dealloc() needs to be specified, because
      struct bpf_link is frequently embedded into link type-specific container
      struct (e.g., struct bpf_raw_tp_link), so bpf_link itself doesn't know how to
      properly free the memory. In case when anon_inode file was successfully
      created, but subsequent BPF attachment failed, bpf_link needs to be marked as
      "defunct", so that file's release() callback will perform only memory
      deallocation, but no detachment.
      
      Convert raw tracepoint and tracing attachment to new API and eliminate
      detachment from error handling path.
      
      Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
      Link: https://lore.kernel.org/bpf/20200309231051.1270337-1-andriin@fb.com
      babf3164
  5. Mar 10, 2020
  6. Mar 06, 2020
  7. Mar 05, 2020