1. Mar 28, 2020
  2. Mar 27, 2020
  3. Mar 26, 2020
    • John Fastabend's avatar
      bpf: Test_verifier, #70 error message updates for 32-bit right shift · aa131ed4
      John Fastabend authored
      
      
      After changes to add update_reg_bounds after ALU ops and adding ALU32
      bounds tracking the error message is changed in the 32-bit right shift
      tests.
      
      Test "#70/u bounds check after 32-bit right shift with 64-bit input FAIL"
      now fails with,
      
      Unexpected error message!
      	EXP: R0 invalid mem access
      	RES: func#0 @0
      
      7: (b7) r1 = 2
      8: R0_w=map_value(id=0,off=0,ks=8,vs=8,imm=0) R1_w=invP2 R10=fp0 fp-8_w=mmmmmmmm
      8: (67) r1 <<= 31
      9: R0_w=map_value(id=0,off=0,ks=8,vs=8,imm=0) R1_w=invP4294967296 R10=fp0 fp-8_w=mmmmmmmm
      9: (74) w1 >>= 31
      10: R0_w=map_value(id=0,off=0,ks=8,vs=8,imm=0) R1_w=invP0 R10=fp0 fp-8_w=mmmmmmmm
      10: (14) w1 -= 2
      11: R0_w=map_value(id=0,off=0,ks=8,vs=8,imm=0) R1_w=invP4294967294 R10=fp0 fp-8_w=mmmmmmmm
      11: (0f) r0 += r1
      math between map_value pointer and 4294967294 is not allowed
      
      And test "#70/p bounds check after 32-bit right shift with 64-bit input
      FAIL" now fails with,
      
      Unexpected error message!
      	EXP: R0 invalid mem access
      	RES: func#0 @0
      
      7: (b7) r1 = 2
      8: R0_w=map_value(id=0,off=0,ks=8,vs=8,imm=0) R1_w=inv2 R10=fp0 fp-8_w=mmmmmmmm
      8: (67) r1 <<= 31
      9: R0_w=map_value(id=0,off=0,ks=8,vs=8,imm=0) R1_w=inv4294967296 R10=fp0 fp-8_w=mmmmmmmm
      9: (74) w1 >>= 31
      10: R0_w=map_value(id=0,off=0,ks=8,vs=8,imm=0) R1_w=inv0 R10=fp0 fp-8_w=mmmmmmmm
      10: (14) w1 -= 2
      11: R0_w=map_value(id=0,off=0,ks=8,vs=8,imm=0) R1_w=inv4294967294 R10=fp0 fp-8_w=mmmmmmmm
      11: (0f) r0 += r1
      last_idx 11 first_idx 0
      regs=2 stack=0 before 10: (14) w1 -= 2
      regs=2 stack=0 before 9: (74) w1 >>= 31
      regs=2 stack=0 before 8: (67) r1 <<= 31
      regs=2 stack=0 before 7: (b7) r1 = 2
      math between map_value pointer and 4294967294 is not allowed
      
      Before this series we did not trip the "math between map_value pointer..."
      error because check_reg_sane_offset is never called in
      adjust_ptr_min_max_vals(). Instead we have a register state that looks
      like this at line 11*,
      
      11: R0_w=map_value(id=0,off=0,ks=8,vs=8,
                         smin_value=0,smax_value=0,
                         umin_value=0,umax_value=0,
                         var_off=(0x0; 0x0))
          R1_w=invP(id=0,
                    smin_value=0,smax_value=4294967295,
                    umin_value=0,umax_value=4294967295,
                    var_off=(0xfffffffe; 0x0))
          R10=fp(id=0,off=0,
                 smin_value=0,smax_value=0,
                 umin_value=0,umax_value=0,
                 var_off=(0x0; 0x0)) fp-8_w=mmmmmmmm
      11: (0f) r0 += r1
      
      In R1 'smin_val != smax_val' yet we have a tnum_const as seen
      by 'var_off(0xfffffffe; 0x0))' with a 0x0 mask. So we hit this check
      in adjust_ptr_min_max_vals()
      
       if ((known && (smin_val != smax_val || umin_val != umax_val)) ||
            smin_val > smax_val || umin_val > umax_val) {
             /* Taint dst register if offset had invalid bounds derived from
              * e.g. dead branches.
              */
             __mark_reg_unknown(env, dst_reg);
             return 0;
       }
      
      So we don't throw an error here and instead only throw an error
      later in the verification when the memory access is made.
      
      The root cause in verifier without alu32 bounds tracking is having
      'umin_value = 0' and 'umax_value = U64_MAX' from BPF_SUB which we set
      when 'umin_value < umax_val' here,
      
       if (dst_reg->umin_value < umax_val) {
          /* Overflow possible, we know nothing */
          dst_reg->umin_value = 0;
          dst_reg->umax_value = U64_MAX;
       } else { ...}
      
      Later in adjust_calar_min_max_vals we previously did a
      coerce_reg_to_size() which will clamp the U64_MAX to U32_MAX by
      truncating to 32bits. But either way without a call to update_reg_bounds
      the less precise bounds tracking will fall out of the alu op
      verification.
      
      After latest changes we now exit adjust_scalar_min_max_vals with the
      more precise umin value, due to zero extension propogating bounds from
      alu32 bounds into alu64 bounds and then calling update_reg_bounds.
      This then causes the verifier to trigger an earlier error and we get
      the error in the output above.
      
      This patch updates tests to reflect new error message.
      
      * I have a local patch to print entire verifier state regardless if we
       believe it is a constant so we can get a full picture of the state.
       Usually if tnum_is_const() then bounds are also smin=smax, etc. but
       this is not always true and is a bit subtle. Being able to see these
       states helps understand dataflow imo. Let me know if we want something
       similar upstream.
      
      Signed-off-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/158507161475.15666.3061518385241144063.stgit@john-Precision-5820-Tower
      aa131ed4
    • John Fastabend's avatar
      bpf: Verifer, adjust_scalar_min_max_vals to always call update_reg_bounds() · 294f2fc6
      John Fastabend authored
      
      
      Currently, for all op verification we call __red_deduce_bounds() and
      __red_bound_offset() but we only call __update_reg_bounds() in bitwise
      ops. However, we could benefit from calling __update_reg_bounds() in
      BPF_ADD, BPF_SUB, and BPF_MUL cases as well.
      
      For example, a register with state 'R1_w=invP0' when we subtract from
      it,
      
       w1 -= 2
      
      Before coerce we will now have an smin_value=S64_MIN, smax_value=U64_MAX
      and unsigned bounds umin_value=0, umax_value=U64_MAX. These will then
      be clamped to S32_MIN, U32_MAX values by coerce in the case of alu32 op
      as done in above example. However tnum will be a constant because the
      ALU op is done on a constant.
      
      Without update_reg_bounds() we have a scenario where tnum is a const
      but our unsigned bounds do not reflect this. By calling update_reg_bounds
      after coerce to 32bit we further refine the umin_value to U64_MAX in the
      alu64 case or U32_MAX in the alu32 case above.
      
      Signed-off-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/158507151689.15666.566796274289413203.stgit@john-Precision-5820-Tower
      294f2fc6
    • John Fastabend's avatar
      bpf: Verifer, refactor adjust_scalar_min_max_vals · 07cd2631
      John Fastabend authored
      
      
      Pull per op ALU logic into individual functions. We are about to add
      u32 versions of each of these by pull them out the code gets a bit
      more readable here and nicer in the next patch.
      
      Signed-off-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/158507149518.15666.15672349629329072411.stgit@john-Precision-5820-Tower
      07cd2631
    • Stanislav Fomichev's avatar
      libbpf: Don't allocate 16M for log buffer by default · 8395f320
      Stanislav Fomichev authored
      
      
      For each prog/btf load we allocate and free 16 megs of verifier buffer.
      On production systems it doesn't really make sense because the
      programs/btf have gone through extensive testing and (mostly) guaranteed
      to successfully load.
      
      Let's assume successful case by default and skip buffer allocation
      on the first try. If there is an error, start with BPF_LOG_BUF_SIZE
      and double it on each ENOSPC iteration.
      
      v3:
      * Return -ENOMEM when can't allocate log buffer (Andrii Nakryiko)
      
      v2:
      * Don't allocate the buffer at all on the first try (Andrii Nakryiko)
      
      Signed-off-by: default avatarStanislav Fomichev <sdf@google.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Link: https://lore.kernel.org/bpf/20200325195521.112210-1-sdf@google.com
      8395f320
    • Tobias Klauser's avatar
      libbpf: Remove unused parameter `def` to get_map_field_int · 9fc9aad9
      Tobias Klauser authored
      Has been unused since commit ef99b02b
      
       ("libbpf: capture value in BTF
      type info for BTF-defined map defs").
      
      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>
      Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Link: https://lore.kernel.org/bpf/20200325113655.19341-1-tklauser@distanz.ch
      9fc9aad9
    • Andrey Ignatov's avatar
      bpf: Document bpf_inspect drgn tool · 8c061865
      Andrey Ignatov authored
      It's a follow-up for discussion in [1].
      
      drgn tool bpf_inspect.py was merged to drgn repo in [2]. Document it
      in kernel tree to make BPF developers aware that the tool exists and
      can help with getting BPF state unavailable via UAPI.
      
      For now it's just one tool but the doc is written in a way that allows
      to cover more tools in the future if needed.
      
      Please refer to the doc itself for more details.
      
      The patch was tested by `make htmldocs` and sanity-checking that
      resulting html looks good.
      
      v2 -> v3:
        - two sections: "Description" and "Getting started" (Daniel);
        - add examples in "Getting started" section (Daniel);
        - add "Customization" section to show how tool can be customized.
      
      v1 -> v2:
        - better "BPF drgn tools" section (Alexei)
      
        [1] https://lore.kernel.org/bpf/20200228201514.GB51456@rdna-mbp/T/#mefed65e8a98116bd5d07d09a570a3eac46724951
        [2] https://github.com/osandov/drgn/pull/49
      
      
      
      Signed-off-by: default avatarAndrey Ignatov <rdna@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20200324185135.1431038-1-rdna@fb.com
      8c061865
  4. Mar 24, 2020
  5. Mar 21, 2020
  6. Mar 20, 2020
  7. Mar 19, 2020
    • Fangrui Song's avatar
      bpf: Support llvm-objcopy for vmlinux BTF · 90ceddcb
      Fangrui Song authored
      Simplify gen_btf logic to make it work with llvm-objcopy. The existing
      'file format' and 'architecture' parsing logic is brittle and does not
      work with llvm-objcopy/llvm-objdump.
      
      'file format' output of llvm-objdump>=11 will match GNU objdump, but
      'architecture' (bfdarch) may not.
      
      .BTF in .tmp_vmlinux.btf is non-SHF_ALLOC. Add the SHF_ALLOC flag
      because it is part of vmlinux image used for introspection. C code
      can reference the section via linker script defined __start_BTF and
      __stop_BTF. This fixes a small problem that previous .BTF had the
      SHF_WRITE flag (objcopy -I binary -O elf* synthesized .data).
      
      Additionally, `objcopy -I binary` synthesized symbols
      _binary__btf_vmlinux_bin_start and _binary__btf_vmlinux_bin_stop (not
      used elsewhere) are replaced with more commonplace __start_BTF and
      __stop_BTF.
      
      Add 2>/dev/null because GNU objcopy (but not llvm-objcopy) warns
      "empty loadable segment detected at vaddr=0xffffffff81000000, is this intentional?"
      
      We use a d...
      90ceddcb
  8. Mar 18, 2020
  9. Mar 17, 2020
    • Jesper Dangaard Brouer's avatar
      sfc: fix XDP-redirect in this driver · 86e85bf6
      Jesper Dangaard Brouer authored
      XDP-redirect is broken in this driver sfc. XDP_REDIRECT requires
      tailroom for skb_shared_info when creating an SKB based on the
      redirected xdp_frame (both in cpumap and veth).
      
      The fix requires some initial explaining. The driver uses RX page-split
      when possible. It reserves the top 64 bytes in the RX-page for storing
      dma_addr (struct efx_rx_page_state). It also have the XDP recommended
      headroom of XDP_PACKET_HEADROOM (256 bytes). As it doesn't reserve any
      tailroom, it can still fit two standard MTU (1500) frames into one page.
      
      The sizeof struct skb_shared_info in 320 bytes. Thus drivers like ixgbe
      and i40e, reduce their XDP headroom to 192 bytes, which allows them to
      fit two frames with max 1536 bytes into a 4K page (192+1536+320=2048).
      
      The fix is to reduce this drivers headroom to 128 bytes and add the 320
      bytes tailroom. This account for reserved top 64 bytes in the page, and
      still fit two frame in a page for normal MTUs.
      
      We must never go below 128 bytes of headroom for XDP, as one cacheline
      is for xdp_frame area and next cacheline is reserved for metadata area.
      
      Fixes: eb9a36be
      
       ("sfc: perform XDP processing on received packets")
      Signed-off-by: default avatarJesper Dangaard Brouer <brouer@redhat.com>
      Acked-by: default avatarEdward Cree <ecree@solarflare.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      86e85bf6
    • Alex Elder's avatar
      remoteproc: clean up notification config · 5e0ef51b
      Alex Elder authored
      
      
      Rearrange the config files for remoteproc and IPA to fix their
      interdependencies.
      
      First, have CONFIG_QCOM_Q6V5_MSS select QCOM_Q6V5_IPA_NOTIFY so the
      notification code is built regardless of whether IPA needs it.
      
      Next, represent QCOM_IPA as being dependent on QCOM_Q6V5_MSS rather
      than setting its value to match QCOM_Q6V5_COMMON (which is selected
      by QCOM_Q6V5_MSS).
      
      Drop all dependencies from QCOM_Q6V5_IPA_NOTIFY.  The notification
      code will be built whenever QCOM_Q6V5_MSS is set, and it has no other
      dependencies.
      
      Signed-off-by: default avatarAlex Elder <elder@linaro.org>
      Reviewed-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      5e0ef51b
    • Madhuparna Bhowmik's avatar
      net: kcm: kcmproc.c: Fix RCU list suspicious usage warning · 1963507e
      Madhuparna Bhowmik authored
      
      
      This path fixes the suspicious RCU usage warning reported by
      kernel test robot.
      
      net/kcm/kcmproc.c:#RCU-list_traversed_in_non-reader_section
      
      There is no need to use list_for_each_entry_rcu() in
      kcm_stats_seq_show() as the list is always traversed under
      knet->mutex held.
      
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Signed-off-by: default avatarMadhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      1963507e
    • Zheng Zengkai's avatar
      qede: remove some unused code in function qede_selftest_receive_traffic · 10ee4b87
      Zheng Zengkai authored
      
      
      Remove set but not used variables 'sw_comp_cons' and 'hw_comp_cons'
      to fix gcc '-Wunused-but-set-variable' warning:
      
      drivers/net/ethernet/qlogic/qede/qede_ethtool.c: In function qede_selftest_receive_traffic:
      drivers/net/ethernet/qlogic/qede/qede_ethtool.c:1569:20:
       warning: variable sw_comp_cons set but not used [-Wunused-but-set-variable]
      drivers/net/ethernet/qlogic/qede/qede_ethtool.c: In function qede_selftest_receive_traffic:
      drivers/net/ethernet/qlogic/qede/qede_ethtool.c:1569:6:
       warning: variable hw_comp_cons set but not used [-Wunused-but-set-variable]
      
      After removing 'hw_comp_cons',the memory barrier 'rmb()' and its comments become useless,
      so remove them as well.
      
      Reported-by: default avatarHulk Robot <hulkci@huawei.com>
      Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      10ee4b87
  10. Mar 16, 2020