1. 21 3月, 2022 2 次提交
  2. 18 3月, 2022 5 次提交
  3. 06 3月, 2022 2 次提交
    • A
      libbpf: Support custom SEC() handlers · 697f104d
      Andrii Nakryiko 提交于
      Allow registering and unregistering custom handlers for BPF program.
      This allows user applications and libraries to plug into libbpf's
      declarative SEC() definition handling logic. This allows to offload
      complex and intricate custom logic into external libraries, but still
      provide a great user experience.
      
      One such example is USDT handling library, which has a lot of code and
      complexity which doesn't make sense to put into libbpf directly, but it
      would be really great for users to be able to specify BPF programs with
      something like SEC("usdt/<path-to-binary>:<usdt_provider>:<usdt_name>")
      and have correct BPF program type set (BPF_PROGRAM_TYPE_KPROBE, as it is
      uprobe) and even support BPF skeleton's auto-attach logic.
      
      In some cases, it might be even good idea to override libbpf's default
      handling, like for SEC("perf_event") programs. With custom library, it's
      possible to extend logic to support specifying perf event specification
      right there in SEC() definition without burdening libbpf with lots of
      custom logic or extra library dependecies (e.g., libpfm4). With current
      patch it's possible to override libbpf's SEC("perf_event") handling and
      specify a completely custom ones.
      
      Further, it's possible to specify a generic fallback handling for any
      SEC() that doesn't match any other custom or standard libbpf handlers.
      This allows to accommodate whatever legacy use cases there might be, if
      necessary.
      
      See doc comments for libbpf_register_prog_handler() and
      libbpf_unregister_prog_handler() for detailed semantics.
      
      This patch also bumps libbpf development version to v0.8 and adds new
      APIs there.
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Tested-by: NAlan Maguire <alan.maguire@oracle.com>
      Reviewed-by: NAlan Maguire <alan.maguire@oracle.com>
      Link: https://lore.kernel.org/bpf/20220305010129.1549719-3-andrii@kernel.org
      697f104d
    • A
      libbpf: Allow BPF program auto-attach handlers to bail out · 4fa5bcfe
      Andrii Nakryiko 提交于
      Allow some BPF program types to support auto-attach only in subste of
      cases. Currently, if some BPF program type specifies attach callback, it
      is assumed that during skeleton attach operation all such programs
      either successfully attach or entire skeleton attachment fails. If some
      program doesn't support auto-attachment from skeleton, such BPF program
      types shouldn't have attach callback specified.
      
      This is limiting for cases when, depending on how full the SEC("")
      definition is, there could either be enough details to support
      auto-attach or there might not be and user has to use some specific API
      to provide more details at runtime.
      
      One specific example of such desired behavior might be SEC("uprobe"). If
      it's specified as just uprobe auto-attach isn't possible. But if it's
      SEC("uprobe/<some_binary>:<some_func>") then there are enough details to
      support auto-attach. Note that there is a somewhat subtle difference
      between auto-attach behavior of BPF skeleton and using "generic"
      bpf_program__attach(prog) (which uses the same attach handlers under the
      cover). Skeleton allow some programs within bpf_object to not have
      auto-attach implemented and doesn't treat that as an error. Instead such
      BPF programs are just skipped during skeleton's (optional) attach step.
      bpf_program__attach(), on the other hand, is called when user *expects*
      auto-attach to work, so if specified program doesn't implement or
      doesn't support auto-attach functionality, that will be treated as an
      error.
      
      Another improvement to the way libbpf is handling SEC()s would be to not
      require providing dummy kernel function name for kprobe. Currently,
      SEC("kprobe/whatever") is necessary even if actual kernel function is
      determined by user at runtime and bpf_program__attach_kprobe() is used
      to specify it. With changes in this patch, it's possible to support both
      SEC("kprobe") and SEC("kprobe/<actual_kernel_function"), while only in
      the latter case auto-attach will be performed. In the former one, such
      kprobe will be skipped during skeleton attach operation.
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Tested-by: NAlan Maguire <alan.maguire@oracle.com>
      Reviewed-by: NAlan Maguire <alan.maguire@oracle.com>
      Link: https://lore.kernel.org/bpf/20220305010129.1549719-2-andrii@kernel.org
      4fa5bcfe
  4. 03 3月, 2022 1 次提交
  5. 01 3月, 2022 1 次提交
  6. 24 2月, 2022 1 次提交
  7. 23 2月, 2022 1 次提交
  8. 17 2月, 2022 2 次提交
  9. 08 2月, 2022 1 次提交
  10. 04 2月, 2022 1 次提交
  11. 03 2月, 2022 1 次提交
  12. 02 2月, 2022 1 次提交
  13. 26 1月, 2022 1 次提交
  14. 25 1月, 2022 2 次提交
  15. 22 1月, 2022 1 次提交
  16. 21 1月, 2022 1 次提交
    • A
      libbpf: deprecate legacy BPF map definitions · 93b8952d
      Andrii Nakryiko 提交于
      Enact deprecation of legacy BPF map definition in SEC("maps") ([0]). For
      the definitions themselves introduce LIBBPF_STRICT_MAP_DEFINITIONS flag
      for libbpf strict mode. If it is set, error out on any struct
      bpf_map_def-based map definition. If not set, libbpf will print out
      a warning for each legacy BPF map to raise awareness that it goes away.
      
      For any use of BPF_ANNOTATE_KV_PAIR() macro providing a legacy way to
      associate BTF key/value type information with legacy BPF map definition,
      warn through libbpf's pr_warn() error message (but don't fail BPF object
      open).
      
      BPF-side struct bpf_map_def is marked as deprecated. User-space struct
      bpf_map_def has to be used internally in libbpf, so it is left
      untouched. It should be enough for bpf_map__def() to be marked
      deprecated to raise awareness that it goes away.
      
      bpftool is an interesting case that utilizes libbpf to open BPF ELF
      object to generate skeleton. As such, even though bpftool itself uses
      full on strict libbpf mode (LIBBPF_STRICT_ALL), it has to relax it a bit
      for BPF map definition handling to minimize unnecessary disruptions. So
      opt-out of LIBBPF_STRICT_MAP_DEFINITIONS for bpftool. User's code that
      will later use generated skeleton will make its own decision whether to
      enforce LIBBPF_STRICT_MAP_DEFINITIONS or not.
      
      There are few tests in selftests/bpf that are consciously using legacy
      BPF map definitions to test libbpf functionality. For those, temporary
      opt out of LIBBPF_STRICT_MAP_DEFINITIONS mode for the duration of those
      tests.
      
        [0] Closes: https://github.com/libbpf/libbpf/issues/272Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/r/20220120060529.1890907-4-andrii@kernel.orgSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
      93b8952d
  17. 13 1月, 2022 1 次提交
  18. 06 1月, 2022 3 次提交
  19. 29 12月, 2021 1 次提交
  20. 15 12月, 2021 2 次提交
    • A
      libbpf: Avoid reading past ELF data section end when copying license · f9798239
      Andrii Nakryiko 提交于
      Fix possible read beyond ELF "license" data section if the license
      string is not properly zero-terminated. Use the fact that libbpf_strlcpy
      never accesses the (N-1)st byte of the source string because it's
      replaced with '\0' anyways.
      
      If this happens, it's a violation of contract between libbpf and a user,
      but not handling this more robustly upsets CIFuzz, so given the fix is
      trivial, let's fix the potential issue.
      
      Fixes: 9fc205b4 ("libbpf: Add sane strncpy alternative and use it internally")
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20211214232054.3458774-1-andrii@kernel.org
      f9798239
    • A
      libbpf: Auto-bump RLIMIT_MEMLOCK if kernel needs it for BPF · e542f2c4
      Andrii Nakryiko 提交于
      The need to increase RLIMIT_MEMLOCK to do anything useful with BPF is
      one of the first extremely frustrating gotchas that all new BPF users go
      through and in some cases have to learn it a very hard way.
      
      Luckily, starting with upstream Linux kernel version 5.11, BPF subsystem
      dropped the dependency on memlock and uses memcg-based memory accounting
      instead. Unfortunately, detecting memcg-based BPF memory accounting is
      far from trivial (as can be evidenced by this patch), so in practice
      most BPF applications still do unconditional RLIMIT_MEMLOCK increase.
      
      As we move towards libbpf 1.0, it would be good to allow users to forget
      about RLIMIT_MEMLOCK vs memcg and let libbpf do the sensible adjustment
      automatically. This patch paves the way forward in this matter. Libbpf
      will do feature detection of memcg-based accounting, and if detected,
      will do nothing. But if the kernel is too old, just like BCC, libbpf
      will automatically increase RLIMIT_MEMLOCK on behalf of user
      application ([0]).
      
      As this is technically a breaking change, during the transition period
      applications have to opt into libbpf 1.0 mode by setting
      LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK bit when calling
      libbpf_set_strict_mode().
      
      Libbpf allows to control the exact amount of set RLIMIT_MEMLOCK limit
      with libbpf_set_memlock_rlim_max() API. Passing 0 will make libbpf do
      nothing with RLIMIT_MEMLOCK. libbpf_set_memlock_rlim_max() has to be
      called before the first bpf_prog_load(), bpf_btf_load(), or
      bpf_object__load() call, otherwise it has no effect and will return
      -EBUSY.
      
        [0] Closes: https://github.com/libbpf/libbpf/issues/369Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20211214195904.1785155-2-andrii@kernel.org
      e542f2c4
  21. 14 12月, 2021 1 次提交
  22. 11 12月, 2021 6 次提交
  23. 04 12月, 2021 1 次提交
  24. 03 12月, 2021 1 次提交