1. 21 Jul, 2020 19 commits
    • Yonghong Song's avatar
      bpf: Make btf_sock_ids global · fce557bc
      Yonghong Song authored
      tcp and udp bpf_iter can reuse some socket ids in
      btf_sock_ids, so make it global.
      
      I put the extern definition in btf_ids.h as a central
      place so it can be easily discovered by developers.
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20200720163402.1393427-1-yhs@fb.com
      fce557bc
    • Yonghong Song's avatar
      bpf: Add BTF_ID_LIST_GLOBAL in btf_ids.h · 0f12e584
      Yonghong Song authored
      Existing BTF_ID_LIST used a local static variable
      to store btf_ids. This patch provided a new macro
      BTF_ID_LIST_GLOBAL to store btf_ids in a global
      variable which can be shared among multiple files.
      
      The existing BTF_ID_LIST is still retained.
      Two reasons. First, BTF_ID_LIST is also used to build
      btf_ids for helper arguments which typically
      is an array of 5. Since typically different
      helpers have different signature, it makes
      little sense to share them. Second, some
      current computed btf_ids are indeed local.
      If later those btf_ids are shared between
      different files, they can use BTF_ID_LIST_GLOBAL then.
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
      Link: https://lore.kernel.org/bpf/20200720163401.1393159-1-yhs@fb.com
      0f12e584
    • Yonghong Song's avatar
      tools/bpf: Sync btf_ids.h to tools · d8dfe5bf
      Yonghong Song authored
      Sync kernel header btf_ids.h to tools directory.
      Also define macro CONFIG_DEBUG_INFO_BTF before
      including btf_ids.h in prog_tests/resolve_btfids.c
      since non-stub definitions for BTF_ID_LIST etc. macros
      are defined under CONFIG_DEBUG_INFO_BTF. This
      prevented test_progs from failing.
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20200720163359.1393079-1-yhs@fb.com
      d8dfe5bf
    • Yonghong Song's avatar
      bpf: Compute bpf_skc_to_*() helper socket btf ids at build time · bc4f0548
      Yonghong Song authored
      Currently, socket types (struct tcp_sock, udp_sock, etc.)
      used by bpf_skc_to_*() helpers are computed when vmlinux_btf
      is first built in the kernel.
      
      Commit 5a2798ab
      ("bpf: Add BTF_ID_LIST/BTF_ID/BTF_ID_UNUSED macros")
      implemented a mechanism to compute btf_ids at kernel build
      time which can simplify kernel implementation and reduce
      runtime overhead by removing in-kernel btf_id calculation.
      This patch did exactly this, removing in-kernel btf_id
      computation and utilizing build-time btf_id computation.
      
      If CONFIG_DEBUG_INFO_BTF is not defined, BTF_ID_LIST will
      define an array with size of 5, which is not enough for
      btf_sock_ids. So define its own static array if
      CONFIG_DEBUG_INFO_BTF is not defined.
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20200720163358.1393023-1-yhs@fb.com
      bc4f0548
    • Ilya Leoshkevich's avatar
      samples/bpf, selftests/bpf: Use bpf_probe_read_kernel · e4d9c232
      Ilya Leoshkevich authored
      A handful of samples and selftests fail to build on s390, because
      after commit 0ebeea8c ("bpf: Restrict bpf_probe_read{, str}()
      only to archs where they work") bpf_probe_read is not available
      anymore.
      
      Fix by using bpf_probe_read_kernel.
      Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20200720114806.88823-1-iii@linux.ibm.com
      e4d9c232
    • Ilya Leoshkevich's avatar
      selftests/bpf: Fix test_lwt_seg6local.sh hangs · 6bd55727
      Ilya Leoshkevich authored
      OpenBSD netcat (Debian patchlevel 1.195-2) does not seem to react to
      SIGINT for whatever reason, causing prefix.pl to hang after
      test_lwt_seg6local.sh exits due to netcat inheriting
      test_lwt_seg6local.sh's file descriptors.
      
      Fix by using SIGTERM instead.
      Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20200720101810.84299-1-iii@linux.ibm.com
      6bd55727
    • Alexei Starovoitov's avatar
      Merge branch 'compressed-JITed-insn' · 495436c1
      Alexei Starovoitov authored
      Luke Nelson says:
      
      ====================
      his patch series enables using compressed riscv (RVC) instructions
      in the rv64 BPF JIT.
      
      RVC is a standard riscv extension that adds a set of compressed,
      2-byte instructions that can replace some regular 4-byte instructions
      for improved code density.
      
      This series first modifies the JIT to support using 2-byte instructions
      (e.g., in jump offset computations), then adds RVC encoding and
      helper functions, and finally uses the helper functions to optimize
      the rv64 JIT.
      
      I used our formal verification framework, Serval, to verify the
      correctness of the RVC encodings and their uses in the rv64 JIT.
      
      The JIT continues to pass all tests in lib/test_bpf.c, and introduces
      no new failures to test_verifier; both with and without RVC being enabled.
      
      The following are examples of the JITed code for the verifier selftest
      "direct packet read test#3 for CGROUP_SKB OK", without and with RVC
      enabled, respectively. The former uses 178 bytes, and the latter uses 112,
      for a ~37% reduction in code size for this example.
      
      Without RVC:
      
         0: 02000813    addi  a6,zero,32
         4: fd010113    addi  sp,sp,-48
         8: 02813423    sd    s0,40(sp)
         c: 02913023    sd    s1,32(sp)
        10: 01213c23    sd    s2,24(sp)
        14: 01313823    sd    s3,16(sp)
        18: 01413423    sd    s4,8(sp)
        1c: 03010413    addi  s0,sp,48
        20: 03056683    lwu   a3,48(a0)
        24: 02069693    slli  a3,a3,0x20
        28: 0206d693    srli  a3,a3,0x20
        2c: 03456703    lwu   a4,52(a0)
        30: 02071713    slli  a4,a4,0x20
        34: 02075713    srli  a4,a4,0x20
        38: 03856483    lwu   s1,56(a0)
        3c: 02049493    slli  s1,s1,0x20
        40: 0204d493    srli  s1,s1,0x20
        44: 03c56903    lwu   s2,60(a0)
        48: 02091913    slli  s2,s2,0x20
        4c: 02095913    srli  s2,s2,0x20
        50: 04056983    lwu   s3,64(a0)
        54: 02099993    slli  s3,s3,0x20
        58: 0209d993    srli  s3,s3,0x20
        5c: 09056a03    lwu   s4,144(a0)
        60: 020a1a13    slli  s4,s4,0x20
        64: 020a5a13    srli  s4,s4,0x20
        68: 00900313    addi  t1,zero,9
        6c: 006a7463    bgeu  s4,t1,0x74
        70: 00000a13    addi  s4,zero,0
        74: 02d52823    sw    a3,48(a0)
        78: 02e52a23    sw    a4,52(a0)
        7c: 02952c23    sw    s1,56(a0)
        80: 03252e23    sw    s2,60(a0)
        84: 05352023    sw    s3,64(a0)
        88: 00000793    addi  a5,zero,0
        8c: 02813403    ld    s0,40(sp)
        90: 02013483    ld    s1,32(sp)
        94: 01813903    ld    s2,24(sp)
        98: 01013983    ld    s3,16(sp)
        9c: 00813a03    ld    s4,8(sp)
        a0: 03010113    addi  sp,sp,48
        a4: 00078513    addi  a0,a5,0
        a8: 00008067    jalr  zero,0(ra)
      
      With RVC:
      
         0:   02000813    addi    a6,zero,32
         4:   7179        c.addi16sp  sp,-48
         6:   f422        c.sdsp  s0,40(sp)
         8:   f026        c.sdsp  s1,32(sp)
         a:   ec4a        c.sdsp  s2,24(sp)
         c:   e84e        c.sdsp  s3,16(sp)
         e:   e452        c.sdsp  s4,8(sp)
        10:   1800        c.addi4spn  s0,sp,48
        12:   03056683    lwu     a3,48(a0)
        16:   1682        c.slli  a3,0x20
        18:   9281        c.srli  a3,0x20
        1a:   03456703    lwu     a4,52(a0)
        1e:   1702        c.slli  a4,0x20
        20:   9301        c.srli  a4,0x20
        22:   03856483    lwu     s1,56(a0)
        26:   1482        c.slli  s1,0x20
        28:   9081        c.srli  s1,0x20
        2a:   03c56903    lwu     s2,60(a0)
        2e:   1902        c.slli  s2,0x20
        30:   02095913    srli    s2,s2,0x20
        34:   04056983    lwu     s3,64(a0)
        38:   1982        c.slli  s3,0x20
        3a:   0209d993    srli    s3,s3,0x20
        3e:   09056a03    lwu     s4,144(a0)
        42:   1a02        c.slli  s4,0x20
        44:   020a5a13    srli    s4,s4,0x20
        48:   4325        c.li    t1,9
        4a:   006a7363    bgeu    s4,t1,0x50
        4e:   4a01        c.li    s4,0
        50:   d914        c.sw    a3,48(a0)
        52:   d958        c.sw    a4,52(a0)
        54:   dd04        c.sw    s1,56(a0)
        56:   03252e23    sw      s2,60(a0)
        5a:   05352023    sw      s3,64(a0)
        5e:   4781        c.li    a5,0
        60:   7422        c.ldsp  s0,40(sp)
        62:   7482        c.ldsp  s1,32(sp)
        64:   6962        c.ldsp  s2,24(sp)
        66:   69c2        c.ldsp  s3,16(sp)
        68:   6a22        c.ldsp  s4,8(sp)
        6a:   6145        c.addi16sp  sp,48
        6c:   853e        c.mv    a0,a5
        6e:   8082        c.jr    ra
      
      RFC -> v1:
        - From Björn Töpel:
          * Changed RVOFF macro to static inline "ninsns_rvoff".
          * Changed return type of rvc_ functions from u32 to u16.
          * Changed sizeof(u16) to sizeof(*ctx->insns).
        * Factored unsigned immediate checks into helper functions
          (is_8b_uint, etc.)
        * Changed to use IS_ENABLED instead of #ifdef to check if RVC is
          enabled.
        * Changed type of immediate arguments to rvc_* encoding to u32
          to avoid issues from promotion of u16 to signed int.
        * Cleaned up RVC checks in emit_{addi,slli,srli,srai}.
          + Wrapped lines at 100 instead of 80 columns for increased clarity.
      	+ Move !imm checks into each branch instead of checking
      	  separately.
      	+ Strengthed checks for c.{slli,srli,srai} to check that
      	  imm < XLEN. Otherwise, imm could be non-zero but the lower
      	  XLEN bits could all be zero, leading to invalid RVC encoding.
        * Changed emit_imm to sign-extend the 12-bit value in "lower"
          + The immediate checks for emit_{addiw,li,addi} use signed
      	  comparisons, so this enables the RVC variants to be used
      	  more often (e.g., if val == -1, then lower should be -1
      	  as opposed to 4095).
      ====================
      Reviewed-by: default avatarBjörn Töpel <bjorn.topel@gmail.com>
      Acked-by: default avatarBjörn Töpel <bjorn.topel@gmail.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      495436c1
    • YueHaibing's avatar
      tools/bpftool: Fix error handing in do_skeleton() · 956fcfcd
      YueHaibing authored
      Fix pass 0 to PTR_ERR, also dump more err info using
      libbpf_strerror.
      
      Fixes: 5dc7a8b2 ("bpftool, selftests/bpf: Embed object file inside skeleton")
      Signed-off-by: default avatarYueHaibing <yuehaibing@huawei.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Reviewed-by: default avatarQuentin Monnet <quentin@isovalent.com>
      Link: https://lore.kernel.org/bpf/20200717123059.29624-1-yuehaibing@huawei.com
      956fcfcd
    • Luke Nelson's avatar
      bpf, riscv: Use compressed instructions in the rv64 JIT · 18a4d8c9
      Luke Nelson authored
      This patch uses the RVC support and encodings from bpf_jit.h to optimize
      the rv64 jit.
      
      The optimizations work by replacing emit(rv_X(...)) with a call to a
      helper function emit_X, which will emit a compressed version of the
      instruction when possible, and when RVC is enabled.
      
      The JIT continues to pass all tests in lib/test_bpf.c, and introduces
      no new failures to test_verifier; both with and without RVC being enabled.
      
      Most changes are straightforward replacements of emit(rv_X(...), ctx)
      with emit_X(..., ctx), with the following exceptions bearing mention;
      
      * Change emit_imm to sign-extend the value in "lower", since the
      checks for RVC (and the instructions themselves) treat the value as
      signed. Otherwise, small negative immediates will not be recognized as
      encodable using an RVC instruction. For example, without this change,
      emit_imm(rd, -1, ctx) would cause lower to become 4095, which is not a
      6b int even though a "c.li rd, -1" instruction suffices.
      
      * For {BPF_MOV,BPF_ADD} BPF_X, drop using addiw,addw in the 32-bit
      cases since the values are zero-extended into the upper 32 bits in
      the following instructions anyways, and the addition commutes with
      zero-extension. (BPF_SUB BPF_X must still use subw since subtraction
      does not commute with zero-extension.)
      
      This patch avoids optimizing branches and jumps to use RVC instructions
      since surrounding code often makes assumptions about the sizes of
      emitted instructions. Optimizing these will require changing these
      functions (e.g., emit_branch) to dynamically compute jump offsets.
      
      The following are examples of the JITed code for the verifier selftest
      "direct packet read test#3 for CGROUP_SKB OK", without and with RVC
      enabled, respectively. The former uses 178 bytes, and the latter uses 112,
      for a ~37% reduction in code size for this example.
      
      Without RVC:
      
         0: 02000813    addi  a6,zero,32
         4: fd010113    addi  sp,sp,-48
         8: 02813423    sd    s0,40(sp)
         c: 02913023    sd    s1,32(sp)
        10: 01213c23    sd    s2,24(sp)
        14: 01313823    sd    s3,16(sp)
        18: 01413423    sd    s4,8(sp)
        1c: 03010413    addi  s0,sp,48
        20: 03056683    lwu   a3,48(a0)
        24: 02069693    slli  a3,a3,0x20
        28: 0206d693    srli  a3,a3,0x20
        2c: 03456703    lwu   a4,52(a0)
        30: 02071713    slli  a4,a4,0x20
        34: 02075713    srli  a4,a4,0x20
        38: 03856483    lwu   s1,56(a0)
        3c: 02049493    slli  s1,s1,0x20
        40: 0204d493    srli  s1,s1,0x20
        44: 03c56903    lwu   s2,60(a0)
        48: 02091913    slli  s2,s2,0x20
        4c: 02095913    srli  s2,s2,0x20
        50: 04056983    lwu   s3,64(a0)
        54: 02099993    slli  s3,s3,0x20
        58: 0209d993    srli  s3,s3,0x20
        5c: 09056a03    lwu   s4,144(a0)
        60: 020a1a13    slli  s4,s4,0x20
        64: 020a5a13    srli  s4,s4,0x20
        68: 00900313    addi  t1,zero,9
        6c: 006a7463    bgeu  s4,t1,0x74
        70: 00000a13    addi  s4,zero,0
        74: 02d52823    sw    a3,48(a0)
        78: 02e52a23    sw    a4,52(a0)
        7c: 02952c23    sw    s1,56(a0)
        80: 03252e23    sw    s2,60(a0)
        84: 05352023    sw    s3,64(a0)
        88: 00000793    addi  a5,zero,0
        8c: 02813403    ld    s0,40(sp)
        90: 02013483    ld    s1,32(sp)
        94: 01813903    ld    s2,24(sp)
        98: 01013983    ld    s3,16(sp)
        9c: 00813a03    ld    s4,8(sp)
        a0: 03010113    addi  sp,sp,48
        a4: 00078513    addi  a0,a5,0
        a8: 00008067    jalr  zero,0(ra)
      
      With RVC:
      
         0:   02000813    addi    a6,zero,32
         4:   7179        c.addi16sp  sp,-48
         6:   f422        c.sdsp  s0,40(sp)
         8:   f026        c.sdsp  s1,32(sp)
         a:   ec4a        c.sdsp  s2,24(sp)
         c:   e84e        c.sdsp  s3,16(sp)
         e:   e452        c.sdsp  s4,8(sp)
        10:   1800        c.addi4spn  s0,sp,48
        12:   03056683    lwu     a3,48(a0)
        16:   1682        c.slli  a3,0x20
        18:   9281        c.srli  a3,0x20
        1a:   03456703    lwu     a4,52(a0)
        1e:   1702        c.slli  a4,0x20
        20:   9301        c.srli  a4,0x20
        22:   03856483    lwu     s1,56(a0)
        26:   1482        c.slli  s1,0x20
        28:   9081        c.srli  s1,0x20
        2a:   03c56903    lwu     s2,60(a0)
        2e:   1902        c.slli  s2,0x20
        30:   02095913    srli    s2,s2,0x20
        34:   04056983    lwu     s3,64(a0)
        38:   1982        c.slli  s3,0x20
        3a:   0209d993    srli    s3,s3,0x20
        3e:   09056a03    lwu     s4,144(a0)
        42:   1a02        c.slli  s4,0x20
        44:   020a5a13    srli    s4,s4,0x20
        48:   4325        c.li    t1,9
        4a:   006a7363    bgeu    s4,t1,0x50
        4e:   4a01        c.li    s4,0
        50:   d914        c.sw    a3,48(a0)
        52:   d958        c.sw    a4,52(a0)
        54:   dd04        c.sw    s1,56(a0)
        56:   03252e23    sw      s2,60(a0)
        5a:   05352023    sw      s3,64(a0)
        5e:   4781        c.li    a5,0
        60:   7422        c.ldsp  s0,40(sp)
        62:   7482        c.ldsp  s1,32(sp)
        64:   6962        c.ldsp  s2,24(sp)
        66:   69c2        c.ldsp  s3,16(sp)
        68:   6a22        c.ldsp  s4,8(sp)
        6a:   6145        c.addi16sp  sp,48
        6c:   853e        c.mv    a0,a5
        6e:   8082        c.jr    ra
      Signed-off-by: default avatarLuke Nelson <luke.r.nels@gmail.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Cc: Björn Töpel <bjorn.topel@gmail.com>
      Link: https://lore.kernel.org/bpf/20200721025241.8077-4-luke.r.nels@gmail.com
      18a4d8c9
    • Ian Rogers's avatar
      libbpf bpf_helpers: Use __builtin_offsetof for offsetof · da7a3506
      Ian Rogers authored
      The non-builtin route for offsetof has a dependency on size_t from
      stdlib.h/stdint.h that is undeclared and may break targets.
      The offsetof macro in bpf_helpers may disable the same macro in other
      headers that have a #ifdef offsetof guard. Rather than add additional
      dependencies improve the offsetof macro declared here to use the
      builtin that is available since llvm 3.7 (the first with a BPF backend).
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Link: https://lore.kernel.org/bpf/20200720061741.1514673-1-irogers@google.com
      da7a3506
    • Luke Nelson's avatar
      bpf, riscv: Add encodings for compressed instructions · 804ec72c
      Luke Nelson authored
      This patch adds functions for encoding and emitting compressed riscv
      (RVC) instructions to the BPF JIT.
      
      Some regular riscv instructions can be compressed into an RVC instruction
      if the instruction fields meet some requirements. For example, "add rd,
      rs1, rs2" can be compressed into "c.add rd, rs2" when rd == rs1.
      
      To make using RVC encodings simpler, this patch also adds helper
      functions that selectively emit either a regular instruction or a
      compressed instruction if possible.
      
      For example, emit_add will produce a "c.add" if possible and regular
      "add" otherwise.
      Signed-off-by: default avatarLuke Nelson <luke.r.nels@gmail.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20200721025241.8077-3-luke.r.nels@gmail.com
      804ec72c
    • Ilya Leoshkevich's avatar
      s390/bpf: Use bpf_skip() in bpf_jit_prologue() · 94ad428d
      Ilya Leoshkevich authored
      Now that we have bpf_skip() for emitting nops, use it in
      bpf_jit_prologue() in order to reduce code duplication.
      Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20200717165326.6786-6-iii@linux.ibm.com
      94ad428d
    • Luke Nelson's avatar
      bpf, riscv: Modify JIT ctx to support compressed instructions · bfabff3c
      Luke Nelson authored
      This patch makes the necessary changes to struct rv_jit_context and to
      bpf_int_jit_compile to support compressed riscv (RVC) instructions in
      the BPF JIT.
      
      It changes the JIT image to be u16 instead of u32, since RVC instructions
      are 2 bytes as opposed to 4.
      
      It also changes ctx->offset and ctx->ninsns to refer to 2-byte
      instructions rather than 4-byte ones. The riscv PC is required to be
      16-bit aligned with or without RVC, so this is sufficient to refer to
      any valid riscv offset.
      
      The code for computing jump offsets in bytes is updated accordingly,
      and factored into a new "ninsns_rvoff" function to simplify the code.
      Signed-off-by: default avatarLuke Nelson <luke.r.nels@gmail.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20200721025241.8077-2-luke.r.nels@gmail.com
      bfabff3c
    • Ilya Leoshkevich's avatar
      s390/bpf: Tolerate not converging code shrinking · 1491b733
      Ilya Leoshkevich authored
      "BPF_MAXINSNS: Maximum possible literals" unnecessarily falls back to
      the interpreter because of failing sanity check in bpf_set_addr. The
      problem is that there are a lot of branches that can be shrunk, and
      doing so opens up the possibility to shrink even more. This process
      does not converge after 3 passes, causing code offsets to change during
      the codegen pass, which must never happen.
      
      Fix by inserting nops during codegen pass in order to preserve code
      offets.
      
      Fixes: 4e9b4a68 ("s390/bpf: Use relative long branches")
      Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20200717165326.6786-5-iii@linux.ibm.com
      1491b733
    • Ilya Leoshkevich's avatar
      s390/bpf: Use brcl for jumping to exit_ip if necessary · 5fa69744
      Ilya Leoshkevich authored
      "BPF_MAXINSNS: Maximum possible literals" test causes panic with
      bpf_jit_harden = 2. The reason is that BPF_JMP | BPF_EXIT is always
      emitted as brc, however, after removal of JITed image size
      limitations, brcl might be required.
      
      Fix by using brcl when necessary.
      
      Fixes: 4e9b4a68 ("s390/bpf: Use relative long branches")
      Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20200717165326.6786-4-iii@linux.ibm.com
      5fa69744
    • Ilya Leoshkevich's avatar
      s390/bpf: Fix sign extension in branch_ku · 7477d43b
      Ilya Leoshkevich authored
      Both signed and unsigned variants of BPF_JMP | BPF_K require
      sign-extending the immediate. JIT emits cgfi for the signed case,
      which is correct, and clgfi for the unsigned case, which is not
      correct: clgfi zero-extends the immediate.
      
      s390 does not provide an instruction that does sign-extension and
      unsigned comparison at the same time. Therefore, fix by first loading
      the sign-extended immediate into work register REG_1 and proceeding
      as if it's BPF_X.
      
      Fixes: 4e9b4a68 ("s390/bpf: Use relative long branches")
      Reported-by: default avatarSeth Forshee <seth.forshee@canonical.com>
      Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Tested-by: default avatarSeth Forshee <seth.forshee@canonical.com>
      Link: https://lore.kernel.org/bpf/20200717165326.6786-3-iii@linux.ibm.com
      7477d43b
    • Ilya Leoshkevich's avatar
      selftests: bpf: test_kmod.sh: Fix running out of srctree · 2ea48598
      Ilya Leoshkevich authored
      When running out of srctree, relative path to lib/test_bpf.ko is
      different than when running in srctree. Check $building_out_of_srctree
      environment variable and use a different relative path if needed.
      Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20200717165326.6786-2-iii@linux.ibm.com
      2ea48598
    • Lorenzo Bianconi's avatar
      bpf: cpumap: Fix possible rcpu kthread hung · c576b9c7
      Lorenzo Bianconi authored
      Fix the following cpumap kthread hung. The issue is currently occurring
      when __cpu_map_load_bpf_program fails (e.g if the bpf prog has not
      BPF_XDP_CPUMAP as expected_attach_type)
      
      $./test_progs -n 101
      101/1 cpumap_with_progs:OK
      101 xdp_cpumap_attach:OK
      Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED
      [  369.996478] INFO: task cpumap/0/map:7:205 blocked for more than 122 seconds.
      [  369.998463]       Not tainted 5.8.0-rc4-01472-ge57892f5 #212
      [  370.000102] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
      [  370.001918] cpumap/0/map:7  D    0   205      2 0x00004000
      [  370.003228] Call Trace:
      [  370.003930]  __schedule+0x5c7/0xf50
      [  370.004901]  ? io_schedule_timeout+0xb0/0xb0
      [  370.005934]  ? static_obj+0x31/0x80
      [  370.006788]  ? mark_held_locks+0x24/0x90
      [  370.007752]  ? cpu_map_bpf_prog_run_xdp+0x6c0/0x6c0
      [  370.008930]  schedule+0x6f/0x160
      [  370.009728]  schedule_preempt_disabled+0x14/0x20
      [  370.010829]  kthread+0x17b/0x240
      [  370.011433]  ? kthread_create_worker_on_cpu+0xd0/0xd0
      [  370.011944]  ret_from_fork+0x1f/0x30
      [  370.012348]
                     Showing all locks held in the system:
      [  370.013025] 1 lock held by khungtaskd/33:
      [  370.013432]  #0: ffffffff82b24720 (rcu_read_lock){....}-{1:2}, at: debug_show_all_locks+0x28/0x1c3
      
      [  370.014461] =============================================
      
      Fixes: 92164774 ("bpf: cpumap: Add the possibility to attach an eBPF program to cpumap")
      Reported-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
      Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Tested-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
      Reviewed-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
      Link: https://lore.kernel.org/bpf/e54f2aabf959f298939e5507b09c48f8c2e380be.1595170625.git.lorenzo@kernel.org
      c576b9c7
    • Jakub Sitnicki's avatar
      bpf, netns: Fix build without CONFIG_INET · 343ead28
      Jakub Sitnicki authored
      When CONFIG_NET is set but CONFIG_INET isn't, build fails with:
      
        ld: kernel/bpf/net_namespace.o: in function `netns_bpf_attach_type_unneed':
        kernel/bpf/net_namespace.c:32: undefined reference to `bpf_sk_lookup_enabled'
        ld: kernel/bpf/net_namespace.o: in function `netns_bpf_attach_type_need':
        kernel/bpf/net_namespace.c:43: undefined reference to `bpf_sk_lookup_enabled'
      
      This is because without CONFIG_INET bpf_sk_lookup_enabled symbol is not
      available. Wrap references to bpf_sk_lookup_enabled with preprocessor
      conditionals.
      
      Fixes: 1559b4aa ("inet: Run SK_LOOKUP BPF program on socket lookup")
      Reported-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Reported-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
      Signed-off-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested
      Link: https://lore.kernel.org/bpf/20200721100716.720477-1-jakub@cloudflare.com
      343ead28
  2. 18 Jul, 2020 16 commits
  3. 16 Jul, 2020 5 commits