1. 06 Feb, 2019 10 commits
  2. 05 Feb, 2019 10 commits
    • Daniel Borkmann's avatar
      Merge branch 'bpf-riscv-jit' · 90d304b7
      Daniel Borkmann authored
      Björn Töpel says:
      
      ====================
      This v2 series adds an RV64G BPF JIT to the kernel.
      
      At the moment the RISC-V Linux port does not support
      CONFIG_HAVE_KPROBES (Patrick Stählin sent out an RFC last year), which
      means that CONFIG_BPF_EVENTS is not supported. Thus, no tests
      involving BPF_PROG_TYPE_TRACEPOINT, BPF_PROG_TYPE_PERF_EVENT,
      BPF_PROG_TYPE_KPROBE and BPF_PROG_TYPE_RAW_TRACEPOINT passes.
      
      The implementation does not support "far branching" (>4KiB).
      
      Test results:
        # modprobe test_bpf
        test_bpf: Summary: 378 PASSED, 0 FAILED, [366/366 JIT'ed]
      
        # echo 1 > /proc/sys/kernel/unprivileged_bpf_disabled
        # ./test_verifier
        ...
        Summary: 761 PASSED, 507 SKIPPED, 2 FAILED
      
      Note that "test_verifier" was run with one build with
      CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=y and one without, otherwise
      many of the the tests that require unaligned access were skipped.
      
      CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=y:
        # echo 1 > /proc/sys/kernel/unprivileged_bpf_disabled
        # ./test_verifier | grep -c 'NOTE.*unknown align'
        0
      
      No CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS:
        # echo 1 > /proc/sys/kernel/unprivileged_bpf_disabled
        # ./test_verifier | grep -c 'NOTE.*unknown align'
        59
      
      The two failing test_verifier tests are:
        "ld_abs: vlan + abs, test 1"
        "ld_abs: jump around ld_abs"
      
      This is due to that "far branching" involved in those tests.
      All tests where done on QEMU emulator version 3.1.50
      (v3.1.0-688-g8ae951fbc106). I'll test it on real hardware, when I get
      access to it.
      
      I'm routing this patch via bpf-next/netdev mailing list (after a
      conversation with Palmer at FOSDEM), mainly because the other JITs
      went that path.
      
      Again, thanks for all the comments!
      
      Cheers,
      Björn
      
      v1 -> v2:
      * Added JMP32 support. (Daniel)
      * Add RISC-V to Documentation/sysctl/net.txt. (Daniel)
      * Fixed seen_call() asymmetry. (Daniel)
      * Fixed broken bpf_flush_icache() range. (Daniel)
      * Added alignment annotations to some selftests.
      
      RFCv1 -> v1:
      * Cleaned up the Kconfig and net/Makefile. (Christoph)
      * Removed the entry-stub and squashed the build/config changes to be
        part of the JIT implementation. (Christoph)
      * Simplified the register tracking code. (Daniel)
      * Removed unused macros. (Daniel)
      * Added myself as maintainer and updated documentation. (Daniel)
      * Removed HAVE_EFFICIENT_UNALIGNED_ACCESS. (Christoph, Palmer)
      * Added tail-calls and cleaned up the code.
      ====================
      Acked-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      90d304b7
    • Björn Töpel's avatar
      selftests/bpf: add "any alignment" annotation for some tests · e2c6f50e
      Björn Töpel authored
      RISC-V does, in-general, not have "efficient unaligned access". When
      testing the RISC-V BPF JIT, some selftests failed in the verification
      due to misaligned access. Annotate these tests with the
      F_NEEDS_EFFICIENT_UNALIGNED_ACCESS flag.
      Signed-off-by: default avatarBjörn Töpel <bjorn.topel@gmail.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      e2c6f50e
    • Björn Töpel's avatar
      bpf, doc: add RISC-V JIT to BPF documentation · e8cb0167
      Björn Töpel authored
      Update Documentation/networking/filter.txt and
      Documentation/sysctl/net.txt to mention RISC-V.
      Signed-off-by: default avatarBjörn Töpel <bjorn.topel@gmail.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      e8cb0167
    • Björn Töpel's avatar
      MAINTAINERS: add RISC-V BPF JIT maintainer · 8a9e0aff
      Björn Töpel authored
      Add Björn Töpel as RISC-V BPF JIT maintainer.
      Signed-off-by: default avatarBjörn Töpel <bjorn.topel@gmail.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      8a9e0aff
    • Björn Töpel's avatar
      bpf, riscv: add BPF JIT for RV64G · 2353ecc6
      Björn Töpel authored
      This commit adds a BPF JIT for RV64G.
      
      The JIT is a two-pass JIT, and has a dynamic prolog/epilogue (similar
      to the MIPS64 BPF JIT) instead of static ones (e.g. x86_64).
      
      At the moment the RISC-V Linux port does not support
      CONFIG_HAVE_KPROBES, which means that CONFIG_BPF_EVENTS is not
      supported. Thus, no tests involving BPF_PROG_TYPE_TRACEPOINT,
      BPF_PROG_TYPE_PERF_EVENT, BPF_PROG_TYPE_KPROBE and
      BPF_PROG_TYPE_RAW_TRACEPOINT passes.
      
      The implementation does not support "far branching" (>4KiB).
      
      Test results:
        # modprobe test_bpf
        test_bpf: Summary: 378 PASSED, 0 FAILED, [366/366 JIT'ed]
      
        # echo 1 > /proc/sys/kernel/unprivileged_bpf_disabled
        # ./test_verifier
        ...
        Summary: 761 PASSED, 507 SKIPPED, 2 FAILED
      
      Note that "test_verifier" was run with one build with
      CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=y and one without, otherwise
      many of the the tests that require unaligned access were skipped.
      
      CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=y:
        # echo 1 > /proc/sys/kernel/unprivileged_bpf_disabled
        # ./test_verifier | grep -c 'NOTE.*unknown align'
        0
      
      No CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS:
        # echo 1 > /proc/sys/kernel/unprivileged_bpf_disabled
        # ./test_verifier | grep -c 'NOTE.*unknown align'
        59
      
      The two failing test_verifier tests are:
        "ld_abs: vlan + abs, test 1"
        "ld_abs: jump around ld_abs"
      
      This is due to that "far branching" involved in those tests.
      
      All tests where done on QEMU (QEMU emulator version 3.1.50
      (v3.1.0-688-g8ae951fbc106)).
      Signed-off-by: default avatarBjörn Töpel <bjorn.topel@gmail.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      2353ecc6
    • Daniel Borkmann's avatar
      Merge branch 'bpf-btf-dedup' · 31de3897
      Daniel Borkmann authored
      Andrii Nakryiko says:
      
      ====================
      This patch series adds BTF deduplication algorithm to libbpf. This algorithm
      allows to take BTF type information containing duplicate per-compilation unit
      information and reduce it to equivalent set of BTF types with no duplication without
      loss of information. It also deduplicates strings and removes those strings that
      are not referenced from any BTF type (and line information in .BTF.ext section,
      if any).
      
      Algorithm also resolves struct/union forward declarations into concrete BTF types
      across multiple compilation units to facilitate better deduplication ratio. If
      undesired, this resolution can be disabled through specifying corresponding options.
      
      When applied to BTF data emitted by pahole's DWARF->BTF converter, it reduces
      the overall size of .BTF section by about 65x, from about 112MB to 1.75MB, leaving
      only 29247 out of initial 3073497 BTF type descriptors.
      
      Algorithm with minor differences and preliminary results before FUNC/FUNC_PROTO
      support is also described more verbosely at:
      
      https://facebookmicrosites.github.io/bpf/blog/2018/11/14/btf-enhancement.html
      
      v1->v2:
      - rebase on latest bpf-next
      - err_log/elog -> pr_debug
      - btf__dedup, btf__get_strings, btf__get_nr_types listed under 0.0.2 version
      ====================
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      31de3897
    • Andrii Nakryiko's avatar
      selftests/btf: add initial BTF dedup tests · 9c651127
      Andrii Nakryiko authored
      This patch sets up a new kind of tests (BTF dedup tests) and tests few aspects of
      BTF dedup algorithm. More complete set of tests will come in follow up patches.
      Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      9c651127
    • Andrii Nakryiko's avatar
      btf: add BTF types deduplication algorithm · d5caef5b
      Andrii Nakryiko authored
      This patch implements BTF types deduplication algorithm. It allows to
      greatly compress typical output of pahole's DWARF-to-BTF conversion or
      LLVM's compilation output by detecting and collapsing identical types emitted in
      isolation per compilation unit. Algorithm also resolves struct/union forward
      declarations into concrete BTF types representing referenced struct/union. If
      undesired, this resolution can be disabled through specifying corresponding options.
      
      Algorithm itself and its application to Linux kernel's BTF types is
      described in details at:
      https://facebookmicrosites.github.io/bpf/blog/2018/11/14/btf-enhancement.htmlSigned-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      d5caef5b
    • Andrii Nakryiko's avatar
      btf: extract BTF type size calculation · 69eaab04
      Andrii Nakryiko authored
      This pre-patch extracts calculation of amount of space taken by BTF type descriptor
      for later reuse by btf_dedup functionality.
      Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      69eaab04
    • Stanislav Fomichev's avatar
      libbpf: fix libbpf_print · a8a1f7d0
      Stanislav Fomichev authored
      With the recent print rework we now have the following problem:
      pr_{warning,info,debug} expand to __pr which calls libbpf_print.
      libbpf_print does va_start and calls __libbpf_pr with va_list argument.
      In __base_pr we again do va_start. Because the next argument is a
      va_list, we don't get correct pointer to the argument (and print noting
      in my case, I don't know why it doesn't crash tbh).
      
      Fix this by changing libbpf_print_fn_t signature to accept va_list and
      remove unneeded calls to va_start in the existing users.
      
      Alternatively, this can we solved by exporting __libbpf_pr and
      changing __pr macro to (and killing libbpf_print):
      {
      	if (__libbpf_pr)
      		__libbpf_pr(level, "libbpf: " fmt, ##__VA_ARGS__)
      }
      Signed-off-by: default avatarStanislav Fomichev <sdf@google.com>
      Acked-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      a8a1f7d0
  3. 04 Feb, 2019 13 commits
    • Alexei Starovoitov's avatar
      Merge branch 'libbpf-btf_ext' · 1728b111
      Alexei Starovoitov authored
      Yonghong Song says:
      
      ====================
      This patch set exposed a few functions in libbpf.
      All these newly added API functions are helpful for
      JIT based bpf compilation where .BTF and .BTF.ext
      are available as in-memory data blobs.
      
      Patch #1 exposed several btf_ext__* API functions which
      are used to handle .BTF.ext ELF sections.
      Patch #2 refactored the function bpf_map_find_btf_info()
      and exposed API function btf__get_map_kv_tids() to
      retrieve the map key/value type id's generated by
      bpf program through BPF_ANNOTATE_KV_PAIR macro.
      ====================
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      1728b111
    • Yonghong Song's avatar
      tools/bpf: implement libbpf btf__get_map_kv_tids() API function · 96408c43
      Yonghong Song authored
      Currently, to get map key/value type id's, the macro
        BPF_ANNOTATE_KV_PAIR(<map_name>, <key_type>, <value_type>)
      needs to be defined in the bpf program for the
      corresponding map.
      
      During program/map loading time,
      the local static function bpf_map_find_btf_info()
      in libbpf.c is implemented to retrieve the key/value
      type ids given the map name.
      
      The patch refactored function bpf_map_find_btf_info()
      to create an API btf__get_map_kv_tids() which includes
      the bulk of implementation for the original function.
      The API btf__get_map_kv_tids() can be used by bcc,
      a JIT based bpf compilation system, which uses the
      same BPF_ANNOTATE_KV_PAIR to record map key/value types.
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      96408c43
    • Yonghong Song's avatar
      tools/bpf: expose functions btf_ext__* as API functions · b8dcf8d1
      Yonghong Song authored
      The following set of functions, which manipulates .BTF.ext
      section, are exposed as API functions:
        . btf_ext__new
        . btf_ext__free
        . btf_ext__reloc_func_info
        . btf_ext__reloc_line_info
        . btf_ext__func_info_rec_size
        . btf_ext__line_info_rec_size
      
      These functions are useful for JIT based bpf codegen, e.g.,
      bcc, to manipulate in-memory .BTF.ext sections.
      
      The signature of function btf_ext__reloc_func_info()
      is also changed to be the same as its definition in btf.c.
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      b8dcf8d1
    • Stanislav Fomichev's avatar
      selftests/bpf: use localhost in tcp_{server,client}.py · 7e8a5903
      Stanislav Fomichev authored
      Bind and connect to localhost. There is no reason for this test to
      use non-localhost interface. This lets us run this test in a network
      namespace.
      Signed-off-by: default avatarStanislav Fomichev <sdf@google.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      7e8a5903
    • Heiko Carstens's avatar
      s390: bpf: fix JMP32 code-gen · ecc15f11
      Heiko Carstens authored
      Commit 626a5f66 ("s390: bpf: implement jitting of JMP32") added
      JMP32 code-gen support for s390. However it triggers the warning below
      due to some unusual gotos in the original s390 bpf jit code.
      
      Add a couple of additional "is_jmp32" initializations to fix this.
      Also fix the wrong opcode for the "llilf" instruction that was
      introduced with the same commit.
      
      arch/s390/net/bpf_jit_comp.c: In function 'bpf_jit_insn':
      arch/s390/net/bpf_jit_comp.c:248:55: warning: 'is_jmp32' may be used uninitialized in this function [-Wmaybe-uninitialized]
        _EMIT6(op1 | reg(b1, b2) << 16 | (rel & 0xffff), op2 | mask); \
                                                             ^
      arch/s390/net/bpf_jit_comp.c:1211:8: note: 'is_jmp32' was declared here
         bool is_jmp32 = BPF_CLASS(insn->code) == BPF_JMP32;
      
      Fixes: 626a5f66 ("s390: bpf: implement jitting of JMP32")
      Cc: Jiong Wang <jiong.wang@netronome.com>
      Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
      Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
      Acked-by: default avatarJiong Wang <jiong.wang@netronome.com>
      Acked-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      ecc15f11
    • Alexei Starovoitov's avatar
      Merge branch 'change-libbpf-print-api' · 9fa3b473
      Alexei Starovoitov authored
      Yonghong Song says:
      
      ====================
      These are patches responding to my comments for
      Magnus's patch (https://patchwork.ozlabs.org/patch/1032848/).
      The goal is to make pr_* macros available to other C files
      than libbpf.c, and to simplify API function libbpf_set_print().
      
      Specifically, Patch #1 used global functions
      to facilitate pr_* macros in the header files so they
      are available in different C files.
      Patch #2 removes the global function libbpf_print_level_available()
      which is added in Patch 1.
      Patch #3 simplified libbpf_set_print() which takes only one print
      function with a debug level argument among others.
      
      Changelogs:
       v3 -> v4:
         . rename libbpf internal header util.h to libbpf_util.h
         . rename libbpf internal function libbpf_debug_print() to libbpf_print()
       v2 -> v3:
         . bailed out earlier in libbpf_debug_print() if __libbpf_pr is NULL
         . added missing LIBBPF_DEBUG level check in libbpf.c __base_pr().
       v1 -> v2:
         . Renamed global function libbpf_dprint() to libbpf_debug_print()
           to be more expressive.
         . Removed libbpf_dprint_level_available() as it is used only
           once in btf.c and we can remove it by optimizing for common cases.
      ====================
      Acked-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      9fa3b473
    • Yonghong Song's avatar
      tools/bpf: simplify libbpf API function libbpf_set_print() · 6f1ae8b6
      Yonghong Song authored
      Currently, the libbpf API function libbpf_set_print()
      takes three function pointer parameters for warning, info
      and debug printout respectively.
      
      This patch changes the API to have just one function pointer
      parameter and the function pointer has one additional
      parameter "debugging level". So if in the future, if
      the debug level is increased, the function signature
      won't change.
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      6f1ae8b6
    • Yonghong Song's avatar
      tools/bpf: print out btf log at LIBBPF_WARN level · 9d100a19
      Yonghong Song authored
      Currently, the btf log is allocated and printed out in case
      of error at LIBBPF_DEBUG level.
      Such logs from kernel are very important for debugging.
      For example, bpf syscall BPF_PROG_LOAD command can get
      verifier logs back to user space. In function load_program()
      of libbpf.c, the log buffer is allocated unconditionally
      and printed out at pr_warning() level.
      
      Let us do the similar thing here for btf. Allocate buffer
      unconditionally and print out error logs at pr_warning() level.
      This can reduce one global function and
      optimize for common situations where pr_warning()
      is activated either by default or by user supplied
      debug output function.
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      9d100a19
    • Yonghong Song's avatar
      tools/bpf: move libbpf pr_* debug print functions to headers · 8461ef8b
      Yonghong Song authored
      A global function libbpf_print, which is invisible
      outside the shared library, is defined to print based
      on levels. The pr_warning, pr_info and pr_debug
      macros are moved into the newly created header
      common.h. So any .c file including common.h can
      use these macros directly.
      
      Currently btf__new and btf_ext__new API has an argument getting
      __pr_debug function pointer into btf.c so the debugging information
      can be printed there. This patch removed this parameter
      from btf__new and btf_ext__new and directly using pr_debug in btf.c.
      
      Another global function libbpf_print_level_available, also
      invisible outside the shared library, can test
      whether a particular level debug printing is
      available or not. It is used in btf.c to
      test whether DEBUG level debug printing is availabl or not,
      based on which the log buffer will be allocated when loading
      btf to the kernel.
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      8461ef8b
    • Stephen Rothwell's avatar
      socket: fix for Add SO_TIMESTAMP[NS]_NEW · cc733578
      Stephen Rothwell authored
      Fixes: 887feae3 ("socket: Add SO_TIMESTAMP[NS]_NEW")
      Signed-off-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      cc733578
    • Joe Perches's avatar
      netdevice.h: Add __cold to netdev_<level> logging functions · ce3fdb69
      Joe Perches authored
      Add __cold to the netdev_<level> logging functions similar to
      the use of __cold in the generic printk function.
      
      Using __cold moves all the netdev_<level> logging functions
      out-of-line possibly improving code locality and runtime
      performance.
      Signed-off-by: default avatarJoe Perches <joe@perches.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      ce3fdb69
    • David S. Miller's avatar
      net: Fix fall through warning in y2038 tstamp changes. · ff7653f9
      David S. Miller authored
      net/core/sock.c: In function 'sock_setsockopt':
      net/core/sock.c:914:3: warning: this statement may fall through [-Wimplicit-fallthrough=]
         sock_set_flag(sk, SOCK_TSTAMP_NEW);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      net/core/sock.c:915:2: note: here
        case SO_TIMESTAMPING_OLD:
        ^~~~
      
      Fixes: 9718475e ("socket: Add SO_TIMESTAMPING_NEW")
      Reported-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      ff7653f9
    • Masahiro Yamada's avatar
      bpfilter: remove extra header search paths for bpfilter_umh · 303a339f
      Masahiro Yamada authored
      Currently, the header search paths -Itools/include and
      -Itools/include/uapi are not used. Let's drop the unused code.
      
      We can remove -I. too by fixing up one C file.
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      303a339f
  4. 03 Feb, 2019 7 commits